hexsha stringlengths 40 40 | size int64 5 1.05M | ext stringclasses 588
values | lang stringclasses 305
values | max_stars_repo_path stringlengths 3 363 | max_stars_repo_name stringlengths 5 118 | max_stars_repo_head_hexsha stringlengths 40 40 | max_stars_repo_licenses listlengths 1 10 | max_stars_count float64 1 191k ⌀ | max_stars_repo_stars_event_min_datetime stringdate 2015-01-01 00:00:35 2022-03-31 23:43:49 ⌀ | max_stars_repo_stars_event_max_datetime stringdate 2015-01-01 12:37:38 2022-03-31 23:59:52 ⌀ | max_issues_repo_path stringlengths 3 363 | max_issues_repo_name stringlengths 5 118 | max_issues_repo_head_hexsha stringlengths 40 40 | max_issues_repo_licenses listlengths 1 10 | max_issues_count float64 1 134k ⌀ | max_issues_repo_issues_event_min_datetime stringlengths 24 24 ⌀ | max_issues_repo_issues_event_max_datetime stringlengths 24 24 ⌀ | max_forks_repo_path stringlengths 3 363 | max_forks_repo_name stringlengths 5 135 | max_forks_repo_head_hexsha stringlengths 40 40 | max_forks_repo_licenses listlengths 1 10 | max_forks_count float64 1 105k ⌀ | max_forks_repo_forks_event_min_datetime stringdate 2015-01-01 00:01:02 2022-03-31 23:27:27 ⌀ | max_forks_repo_forks_event_max_datetime stringdate 2015-01-03 08:55:07 2022-03-31 23:59:24 ⌀ | content stringlengths 5 1.05M | avg_line_length float64 1.13 1.04M | max_line_length int64 1 1.05M | alphanum_fraction float64 0 1 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
47aff786bbdc076d01ac9b176f1c772257482f70 | 2,059 | c | C | c_os2/ex1/ex2.c | christosmarg/uni-assignments | bd3fdb78daf038d3a1f6ac1d7c4aad09e19bb795 | [
"MIT"
] | null | null | null | c_os2/ex1/ex2.c | christosmarg/uni-assignments | bd3fdb78daf038d3a1f6ac1d7c4aad09e19bb795 | [
"MIT"
] | 1 | 2021-06-03T22:25:48.000Z | 2021-06-03T22:25:48.000Z | c_os2/ex1/ex2.c | christosmarg/uni-assignments | bd3fdb78daf038d3a1f6ac1d7c4aad09e19bb795 | [
"MIT"
] | 1 | 2021-06-03T10:36:57.000Z | 2021-06-03T10:36:57.000Z | #include <sys/wait.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/*
* Εργαστήριο ΛΣ2 (Δ6) / Εργασία 1: Άσκηση 2 / 2020-2021
* Ονοματεπώνυμο: Χρήστος Μαργιώλης
* ΑΜ: 19390133
* Τρόπος μεταγλώττισης: `cc ex2.c -o ex2`
*/
/*
* Print a process' info. `n` indicates which process is being
* printed -- for example `printproc(2)` will print P2.
*/
static void
printproc(int n)
{
printf("p: %d\tpid: %d\tppid: %d\n", n, getpid(), getppid());
}
int
main(int argc, char *argv[])
{
char buf[32]; /* Message buffer */
int fd[2]; /* Pipe(2) file descriptors */
int n; /* Bytes returned from read(2) */
int i = 3; /* P2 will create 3 child procs */
/* Create pipe */
if (pipe(fd) < 0)
err(1, "pipe");
printproc(0);
/* Create P1 */
switch (fork()) {
case -1:
err(1, "fork");
case 0:
printproc(1);
(void)strcpy(buf, "Hello from your first child\n");
/* Close the read fd and send message to P0 */
(void)close(fd[0]);
if (write(fd[1], buf, sizeof(buf)) != sizeof(buf))
err(1, "write");
exit(EXIT_SUCCESS);
default:
/* Close the write fd and receive message from P1 */
(void)close(fd[1]);
if ((n = read(fd[0], buf, sizeof(buf))) != sizeof(buf))
err(1, "read");
/* Print the message to stdout */
if (write(STDOUT_FILENO, buf, n) != n)
err(1, "write");
if (wait(NULL) < 0)
err(1, "wait");
/* Create P2 */
switch (fork()) {
case -1:
err(1, "fork");
case 0:
printproc(2);
/* create P3, P4 and P5 */
while (i--) {
switch (fork()) {
case -1:
err(1, "fork");
case 0:
printproc(2 + i + 1);
exit(EXIT_SUCCESS);
default:
/* Wait for all children to exit first */
if (wait(NULL) < 0)
err(1, "wait");
}
}
exit(EXIT_SUCCESS);
default:
/* wait for P2 to exit */
if (wait(NULL) < 0)
err(1, "wait");
}
/*
* Finally, the parent process executes ps(1) after
* everything else has exited
*/
if (execl("/bin/ps", "ps", NULL) < 0)
err(1, "execl");
}
return 0;
}
| 21.010204 | 62 | 0.571151 |
fe9a0c4c799a256ea862a55d1451ac9b8675b239 | 1,078 | h | C | PrivateFrameworks/ViewBridge/ViewBridgeUtilities.h | phatblat/macOSPrivateFrameworks | 9047371eb80f925642c8a7c4f1e00095aec66044 | [
"MIT"
] | 17 | 2018-11-13T04:02:58.000Z | 2022-01-20T09:27:13.000Z | PrivateFrameworks/ViewBridge/ViewBridgeUtilities.h | phatblat/macOSPrivateFrameworks | 9047371eb80f925642c8a7c4f1e00095aec66044 | [
"MIT"
] | 3 | 2018-04-06T02:02:27.000Z | 2018-10-02T01:12:10.000Z | PrivateFrameworks/ViewBridge/ViewBridgeUtilities.h | phatblat/macOSPrivateFrameworks | 9047371eb80f925642c8a7c4f1e00095aec66044 | [
"MIT"
] | 1 | 2018-09-28T13:54:23.000Z | 2018-09-28T13:54:23.000Z | //
// Generated by class-dump 3.5 (64 bit).
//
// class-dump is Copyright (C) 1997-1998, 2000-2001, 2004-2013 by Steve Nygard.
//
#import "NSObject.h"
__attribute__((visibility("hidden")))
@interface ViewBridgeUtilities : NSObject
{
}
+ (void)removeResponder:(id)arg1 fromChainOf:(id)arg2;
+ (void)withAppearance:(id)arg1 perform:(CDUnknownBlockType)arg2;
+ (id)appearanceNamed:(id)arg1;
+ (void)whileHoldingLock:(struct os_unfair_lock_s *)arg1 perform:(CDUnknownBlockType)arg2;
+ (BOOL)maintainConstraintForView:(id)arg1 withIdentifier:(id)arg2 andConstant:(double)arg3 createdByMeansOf:(CDUnknownBlockType)arg4;
+ (void)flushCoreAnimationTransaction;
+ (id)informationStringForKey:(struct __CFString *)arg1 forProcess:(int)arg2;
+ (id)informationStringForKey:(struct __CFString *)arg1 forApplication:(struct __LSASN *)arg2;
+ (void)setCurrentApplicationValue:(void *)arg1 forKey:(struct __CFString *)arg2;
+ (void)setApplication:(struct __LSASN *)arg1 value:(void *)arg2 forKey:(struct __CFString *)arg3;
+ (BOOL)serviceWindowBackgroundColorIsSafe:(id)arg1;
@end
| 38.5 | 134 | 0.768089 |
2ac20b841986b6e74b52d0bb9d9ae2ba185dd3d5 | 2,837 | h | C | AST/ast_expr.h | adamjoffe/tr-lang | 4061fefe2d48016a5575c4ea27903661550468ee | [
"MIT"
] | null | null | null | AST/ast_expr.h | adamjoffe/tr-lang | 4061fefe2d48016a5575c4ea27903661550468ee | [
"MIT"
] | null | null | null | AST/ast_expr.h | adamjoffe/tr-lang | 4061fefe2d48016a5575c4ea27903661550468ee | [
"MIT"
] | null | null | null | #ifndef AST_EXPR_H
#define AST_EXPR_H
#include "../tr_types.h"
namespace TR {
/**
* Abstract Expression Class
*
* Abstract expression implements nodes that are an
* expression in the program
*/
class ASTExpr : public ASTNode {
public:
/// Remove default constructor for this
ASTExpr() = delete;
/**
* Location Constructor
*
* Constructs AST node with a location in the source code
*
* @param l Location of related symbol(s) in source code
* @param f File name of related symbol(s) in source code
*/
ASTExpr(const location& l, const std::string& f) :
ASTExpr(new GVar(), l, f) {}
/**
* Generic Variable Constructor
*
* Constructs AST node with a generic variable and location
*
* @param v Generic variable of value
* @param l Location of related symbol(s) in source code
* @param f File name of related symbol(s) in source code
*/
ASTExpr(GVar* v, const location& l, const std::string& f) :
val(v), stat_calc(false), ASTNode(l,f) {}
/**
* Location Source Code Constructor
*
* Constructs AST node with a location in the source code
*
* @param l Location of related symbol(s) in source code
* @param f File name of related symbol(s) in source code
* @param src Source code of related node
*/
ASTExpr(const location& l, const std::string& f, const std::string& src) :
ASTExpr(new GVar(), l, f, src) {}
/**
* Generic Variable Source Code Constructor
*
* Constructs AST node with a generic variable and location
*
* @param v Generic variable of value
* @param l Location of related symbol(s) in source code
* @param f File name of related symbol(s) in source code
* @param src Source code of related node
*/
ASTExpr(GVar* v, const location& l, const std::string& f, const std::string& src) :
val(v), stat_calc(false), ASTNode(l,f,src) {}
/**
* Virtual destructor
*
* Doesn't need to delete parent
*/
virtual ~ASTExpr() { delete val; }
/**
* Visit Function
*
* All nodes must implement this function
* See Visitor Pattern
*
* @param v Pointer to the visitor object
* @param n Optional pointer to AST node
* @return Optionally returns a pointer to an AST node
*/
virtual ASTNode* visit(Visitor* v, ASTNode* n) = 0;
bool stat_calc; /// if the value has been statically calculated
GVar* val;
};
}
#endif | 30.180851 | 91 | 0.556574 |
f1ac72b8d5678cad86f2ad2c6b5d0d0e640e26fc | 1,667 | h | C | erts/emulator/asmjit/arm/a64assembler.h | williamthome/otp | c4f24d6718ac56c431f0fccf240c5b15482792ed | [
"Apache-2.0"
] | null | null | null | erts/emulator/asmjit/arm/a64assembler.h | williamthome/otp | c4f24d6718ac56c431f0fccf240c5b15482792ed | [
"Apache-2.0"
] | null | null | null | erts/emulator/asmjit/arm/a64assembler.h | williamthome/otp | c4f24d6718ac56c431f0fccf240c5b15482792ed | [
"Apache-2.0"
] | 2 | 2015-10-18T22:36:46.000Z | 2022-01-26T14:01:57.000Z | // This file is part of AsmJit project <https://asmjit.com>
//
// See asmjit.h or LICENSE.md for license and copyright information
// SPDX-License-Identifier: Zlib
#ifndef ASMJIT_ARM_A64ASSEMBLER_H_INCLUDED
#define ASMJIT_ARM_A64ASSEMBLER_H_INCLUDED
#include "../core/assembler.h"
#include "../arm/a64emitter.h"
#include "../arm/a64operand.h"
ASMJIT_BEGIN_SUB_NAMESPACE(a64)
//! \addtogroup asmjit_a64
//! \{
//! AArch64 assembler implementation.
class ASMJIT_VIRTAPI Assembler
: public BaseAssembler,
public EmitterExplicitT<Assembler> {
public:
typedef BaseAssembler Base;
//! \name Construction / Destruction
//! \{
ASMJIT_API Assembler(CodeHolder* code = nullptr) noexcept;
ASMJIT_API virtual ~Assembler() noexcept;
//! \}
//! \name Accessors
//! \{
//! Gets whether the current ARM mode is THUMB (alternative to 32-bit ARM encoding).
inline bool isInThumbMode() const noexcept { return _environment.isArchThumb(); }
//! Gets the current code alignment of the current mode (ARM vs THUMB).
inline uint32_t codeAlignment() const noexcept { return isInThumbMode() ? 2 : 4; }
//! \}
//! \name Emit
//! \{
ASMJIT_API Error _emit(InstId instId, const Operand_& o0, const Operand_& o1, const Operand_& o2, const Operand_* opExt) override;
//! \}
//! \name Align
//! \{
ASMJIT_API Error align(AlignMode alignMode, uint32_t alignment) override;
//! \}
//! \name Events
//! \{
ASMJIT_API Error onAttach(CodeHolder* code) noexcept override;
ASMJIT_API Error onDetach(CodeHolder* code) noexcept override;
//! \}
};
//! \}
ASMJIT_END_SUB_NAMESPACE
#endif // ASMJIT_ARM_A64ASSEMBLER_H_INCLUDED
| 22.835616 | 132 | 0.707259 |
cc773da0944cef86d91294c25f5508257e3eed4e | 1,106 | c | C | NMEADecoder/text.c | LeandroHuff/GPS_NMEA_Decoder | e0383eb523719235b5c6327a312c70ba3fc72588 | [
"CC0-1.0"
] | null | null | null | NMEADecoder/text.c | LeandroHuff/GPS_NMEA_Decoder | e0383eb523719235b5c6327a312c70ba3fc72588 | [
"CC0-1.0"
] | null | null | null | NMEADecoder/text.c | LeandroHuff/GPS_NMEA_Decoder | e0383eb523719235b5c6327a312c70ba3fc72588 | [
"CC0-1.0"
] | null | null | null | /**
* @brief Text constant string definition to use into all source code files.
* @file text.c - Source code filename.
* @author Leandro Daniel Huff - leandrohuff@programmer.net
* @date 2022/03/15 - Source code date.
* @version 0.0.1 - Source code version.
* @copyright Creative Commons Legal Code.
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
*/
#include "../Resources/defs.h"
const char *NULL_txt = "NULL";
const char *FALSE_txt = "FALSE";
const char *TRUE_txt = "TRUE";
| 40.962963 | 86 | 0.643761 |
604651e1e07a99c1e1dcc370c1e7726a0eabddf3 | 2,220 | h | C | kernel/include/kernel.h | ucrux/ucrux | dd385038c296ed7ccaddc3227d6a57cbc826c395 | [
"MIT"
] | 2 | 2018-11-08T01:30:22.000Z | 2019-07-11T23:56:00.000Z | kernel/include/kernel.h | ucrux/ucrux | dd385038c296ed7ccaddc3227d6a57cbc826c395 | [
"MIT"
] | null | null | null | kernel/include/kernel.h | ucrux/ucrux | dd385038c296ed7ccaddc3227d6a57cbc826c395 | [
"MIT"
] | 2 | 2018-09-17T09:28:05.000Z | 2020-08-31T04:50:27.000Z | /*此文件保存一些全局变量*/
#ifndef __KERNEL_H
#define __KERNEL_H
#include "global_type.h"
/*
* 1.内核是不可重入的
* 2.在使用信号量的时候,进程被调度出去,在被调度回来的时候如何回到原点
* 3.系统调用就3个,内存分配,发送消息,接收消息
* 4.由于有消息队列,所以发送消息的时候不会被阻塞(内核是不可重入的),
* 但是接收消息的时候可能被阻塞,因为消息队列有可能是空的(这个时候进程就被阻塞在内核态了,哈哈哈,还说内核是不可重入的)
*/
// 页大小
#define __PAGE_SIZE 0x00001000U
// 页目录表项和页表项大小
#define __PTE_SIZE 0x04U
// 指向gdt_ptr结构的指针的指针
#define __GDT_PTR_ADDR 0x00007004U
// 内核主线程PCB
#define __KERNEL_PCB 0x00006000U
// 内核栈起始地址
#define __KERNEL_STACK 0x00007000U
// 指向总内存大小的指针
#define __MEM_SIZE_ADDR (__KERNEL_STACK)
// 指向页目录表的指针
#define __PAGE_DIR_TABLE_ADDR 0x00008000U
// 指向初始化页表项表的指针
#define __PAGE_INIT_ENT_TABLE_ADDR 0x00009000U
// 初始化页表时最大的线性地址(如果物理内存比1M大)
#define __PAGE_INIT_MAX_LINE_ADDR 0x00400000U
// 指向TSS任务状态段结构的指针
#define __TSS_ADDR 0x00007100U
// 内核初始化时可用内存的开始位置
#define __INIT_BEGIN_ADDR 0x00100000U
// 内核代码段选择子
#define __SELECTOR_KERNEL_CODE 0x08U
// 内核数据段选择子
#define __SELECTOR_KERNEL_DATA 0x10U
// 内核视频段选择子
#define __SELECTOR_KERNEL_VIDEO 0x18U
// 服务进程视频段选择子
#define __SELECTOR_TASK_VIDEO 0x19U
// task进程代码段选择子
#define __SELECTOR_TASK_CODE 0x29U
// task进程数据段选择子
#define __SELECTOR_TASK_DATA 0x31U
// user进程代码段选择子
#define __SELECTOR_USER_CODE 0x3BU
// user进程数据段选择子
#define __SELECTOR_USER_DATA 0x43U
// 内核最大地址空间
#define __KERNEL_MAX_ADDR 0x40000000U
// 最大虚拟地址空间
#define __VADDR_MAX 0xffffffffU
// 函数入口,用户进程函数默认入口
#define __FUNC_ENTRY 0x00000000U
// 默认的eflags值
#define __DEFAULT_EFLAGS 0x00001202U // IOPL=1, IF
// 内核最大拥有的页目录表项
#define __KERNEL_MAX_PDT_ECNT 256U
// 服务进程文件默认大小
#define __TASK_FILE_DEFAULT_SZIE (8*__PAGE_SIZE)
// video task elf 文件在硬盘中的起始扇区
#define __VIDEO_TASK_BEGIN_SEC 300
// tty task elf 文件在硬盘中的起始扇区
#define __TTY_TASK_BEGIN_SEC 400
// keyboard task elf 文件在硬盘中的起始扇区
#define __KEYBOARD_TASK_BEGIN_SEC 500
//门描述符结构体
typedef struct s_gate_desc
{
uint16_t func_offset_low ;
uint16_t cs_selector ;
uint8_t param_count ;
uint8_t gate_attr ;
uint16_t func_offset_high ;
} gate_desc_t ;
#endif | 26.428571 | 64 | 0.725676 |
44f73ee62b85175bebffc3f5e230afadd9c9b5d0 | 2,928 | c | C | Tools/CryptPasswords/CryptPasswords.c | joacimmelin/NiKom | a70e77b8339407da5a399756c44862d937b0e5d3 | [
"MIT"
] | 23 | 2015-10-27T11:08:53.000Z | 2022-01-13T20:11:52.000Z | Tools/CryptPasswords/CryptPasswords.c | joacimmelin/NiKom | a70e77b8339407da5a399756c44862d937b0e5d3 | [
"MIT"
] | 120 | 2015-08-03T17:55:52.000Z | 2021-09-23T05:39:31.000Z | Tools/CryptPasswords/CryptPasswords.c | joacimmelin/NiKom | a70e77b8339407da5a399756c44862d937b0e5d3 | [
"MIT"
] | 8 | 2015-08-11T06:03:38.000Z | 2020-03-14T17:41:09.000Z | #include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <sys/stat.h>
#include "FCrypt.h"
#define MAXMOTE 2048
#define MAXVOTE 32
struct User {
long tot_tid,forst_in,senast_in,read,skrivit,flaggor,former_textpek,brevpek,
grupper,defarea,downloadbytes,chrset,uploadbytes,reserv5,upload,download,
loggin,shell;
char namn[41],gata[41],postadress[41],land[41],telefon[21],
annan_info[61],losen[16],status,rader,protokoll,
prompt[6],motratt[MAXMOTE/8],motmed[MAXMOTE/8],vote[MAXVOTE];
};
void encryptString(char *str) {
char salt[3];
generateSalt(salt, 2);
printf("'%s' --> '%s'\n", str, crypt(str, salt));
}
void convertUser(int userId) {
char filename[40], salt[3], *encryptedPwd;
struct stat statbuf;
FILE *fp;
struct User userbuf;
sprintf(filename, "NiKom:Users/%d/%d/Data", userId / 100, userId);
if(stat(filename, &statbuf) != 0) {
printf("Can't find data for user %d\n", userId);
return;
}
if(statbuf.st_size != sizeof(struct User)) {
printf("Size of user's data file is %d, was expecting %lu.\n",
statbuf.st_size, (unsigned long)sizeof(struct User));
printf("Are you running the right version of CryptPasswords?\n");
return;
}
if(!(fp = fopen(filename, "rb+"))) {
printf("Can't open %s\n", filename);
return;
}
if(fread(&userbuf, sizeof(struct User), 1, fp) != 1) {
printf("Could not read the user's data file.\n");
fclose(fp);
return;
}
generateSalt(salt, 2);
encryptedPwd = crypt(userbuf.losen, salt);
strncpy(userbuf.losen, encryptedPwd, 16);
rewind(fp);
if(fwrite(&userbuf, sizeof(struct User), 1, fp) != 1) {
printf("Could not write the user's data file.\n");
} else {
printf("Password for user %d is encrypted.\n", userId);
}
fclose(fp);
}
void printUsage(int exitCode) {
printf("Usage: CryptPasswords -s <string> | -u <userid> | -a\n\n");
printf("-s <string> : Encrypt the given string.\n");
printf("-u <userid> : Encrypt the password for the given user.\n");
printf("-a : Encrypt the password for all users.\n");
exit(exitCode);
}
int main(int argc, char *argv[]) {
if(argc < 2 || argv[1][0] != '-') {
printUsage(0);
}
switch(argv[1][1]) {
case 's':
if(argc != 3) {
printf("Invalid number of arguments for -s\n\n");
printUsage(10);
}
encryptString(argv[2]);
break;
case 'u':
if(argc != 3) {
printf("Invalid number of arguments for -u\n\n");
printUsage(10);
}
if(!isdigit(argv[2][0])) {
printf("Invalid userid\n");
exit(10);
}
convertUser(atoi(argv[2]));
break;
case 'a':
if(argc != 2) {
printf("No argument allowed for -a\n\n");
printUsage(10);
}
printf("-a option is not implemented yet..\n");
break;
default:
printf("Invalid option.\n\n");
printUsage(10);
}
return 0;
}
| 26.378378 | 79 | 0.61373 |
1a5ac43ced66ebae8e4411354d50c2f682b76489 | 578 | h | C | client/Source/Nova/Public/RoomInfoCls.h | yjun1806/JDefence | 72456e15c574bb495df872309e2db42e45f872fa | [
"MIT"
] | null | null | null | client/Source/Nova/Public/RoomInfoCls.h | yjun1806/JDefence | 72456e15c574bb495df872309e2db42e45f872fa | [
"MIT"
] | null | null | null | client/Source/Nova/Public/RoomInfoCls.h | yjun1806/JDefence | 72456e15c574bb495df872309e2db42e45f872fa | [
"MIT"
] | null | null | null | // Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Nova.h"
#include <string>
#include "RoomUserInfoCls.h"
/**
*
*/
class NOVA_API RoomInfoCls
{
public:
RoomInfoCls();
~RoomInfoCls();
public:
std::string RoomName;
int32 RoomNumber;
int32 MaxUserNumber;
int32 CurrentUserNumber;
std::string Password;
int32 RoomOwner;
bool IsThisRoomPlayingGame;
TArray<class RoomUserInfoCls*> user_list;
int32 FountainHealth;
bool IsThisRoomLock;
bool IsGameEnd = false;
bool EndWidget = false;
bool IsGameWin = false;
};
| 17 | 78 | 0.749135 |
9e613983db829d70f0af7515396dae26b4e86a5c | 711 | h | C | Sources/AirMonetizationSDK.xcframework/ios-arm64_x86_64-simulator/AirMonetizationSDK.framework/PrivateHeaders/ARPVASTAdMediaFiles.h | airnowplatform/airnow-ios-sdk | 4756ecbe2e1f732c747ee9c62149127133808712 | [
"Apache-2.0"
] | null | null | null | Sources/AirMonetizationSDK.xcframework/ios-arm64_x86_64-simulator/AirMonetizationSDK.framework/PrivateHeaders/ARPVASTAdMediaFiles.h | airnowplatform/airnow-ios-sdk | 4756ecbe2e1f732c747ee9c62149127133808712 | [
"Apache-2.0"
] | null | null | null | Sources/AirMonetizationSDK.xcframework/ios-arm64_x86_64-simulator/AirMonetizationSDK.framework/PrivateHeaders/ARPVASTAdMediaFiles.h | airnowplatform/airnow-ios-sdk | 4756ecbe2e1f732c747ee9c62149127133808712 | [
"Apache-2.0"
] | null | null | null | //
// ARPVASTAdMediaFiles.h
// APSDK
//
// Created by Andrii Alexieiev on 6/14/18.
// Copyright © 2018 AirPush. All rights reserved.
//
#import <Foundation/Foundation.h>
struct Keys {
__unsafe_unretained NSString * const mediaFilesKey;
__unsafe_unretained NSString * const mezzanineKey;
__unsafe_unretained NSString * const interactiveCreativeFileKey;
};
extern const struct Keys ARPVASTAdMediaFilesKeys;
@interface ARPVASTAdMediaFiles : NSObject
@property (strong, nonatomic) NSString *interactiveCreativeFile;
@property (strong, nonatomic) NSString *mezzanine;
@property (strong, nonatomic) NSArray *mediaFiles;
- (instancetype)initWithDictionary: (NSDictionary *) dataDictionary;
@end
| 25.392857 | 68 | 0.773558 |
cfe3b577f3a36927484237f8d184692ad584ef47 | 21,868 | c | C | tests/csmith/small_arrays/csmith_389.c | talsewell/cerberus | c8c6d25f0cb8d4cd2672ffd0790fb0de3f2a51e3 | [
"BSD-2-Clause"
] | 12 | 2020-09-03T09:57:26.000Z | 2022-01-28T04:28:00.000Z | tests/csmith/small_arrays/csmith_389.c | talsewell/cerberus | c8c6d25f0cb8d4cd2672ffd0790fb0de3f2a51e3 | [
"BSD-2-Clause"
] | 182 | 2021-02-26T23:07:40.000Z | 2022-02-10T12:33:45.000Z | tests/csmith/small_arrays/csmith_389.c | talsewell/cerberus | c8c6d25f0cb8d4cd2672ffd0790fb0de3f2a51e3 | [
"BSD-2-Clause"
] | 4 | 2020-09-02T11:54:39.000Z | 2022-03-16T23:23:11.000Z | // Options: --no-pointers --no-structs --no-unions --argc --no-bitfields --checksum --comma-operators --compound-assignment --concise --consts --divs --embedded-assigns --pre-incr-operator --pre-decr-operator --post-incr-operator --post-decr-operator --unary-plus-operator --jumps --longlong --int8 --uint8 --no-float --main --math64 --muls --safe-math --no-packed-struct --no-paranoid --no-volatiles --no-volatile-pointers --const-pointers --no-builtins --max-array-dim 1 --max-array-len-per-dim 4 --max-block-depth 1 --max-block-size 10 --max-expr-complexity 4 --max-funcs 10 --max-pointer-depth 2 --max-struct-fields 2 --max-union-fields 2 -o csmith_389.c
#include "csmith.h"
static long __undefined;
static int16_t g_8[1] = {1L};
static uint32_t g_18[3] = {18446744073709551615UL,18446744073709551615UL,18446744073709551615UL};
static uint8_t g_62 = 0xEFL;
static uint32_t g_63[1] = {0UL};
static uint64_t g_69 = 0xDB650F83943CDC18LL;
static int32_t g_78[4] = {0xCCBB7A79L,0xCCBB7A79L,0xCCBB7A79L,0xCCBB7A79L};
static uint64_t g_88 = 1UL;
static int32_t g_91 = 0x64457BBFL;
static int16_t g_108 = 0xE8AEL;
static int16_t g_118 = (-5L);
static int8_t g_122 = 0xB0L;
static int32_t g_123[2] = {(-1L),(-1L)};
static uint8_t g_185 = 0UL;
static int32_t g_199 = 0x60D73480L;
static int32_t g_344 = 0x39FBA44AL;
static int8_t g_345 = 0xF5L;
static int64_t g_346 = (-1L);
static uint32_t g_379 = 1UL;
static int64_t g_387 = 0xB625347EE41A932FLL;
static int64_t g_388 = (-8L);
static int16_t g_389 = 6L;
static uint16_t g_390 = 1UL;
static uint16_t g_474 = 1UL;
static uint8_t func_1(void);
static int32_t func_2(uint32_t p_3, uint64_t p_4, const int64_t p_5, uint32_t p_6, uint64_t p_7);
static uint32_t func_9(int16_t p_10, int8_t p_11, int8_t p_12);
static int32_t func_21(int16_t p_22, uint64_t p_23, uint8_t p_24);
static uint16_t func_41(int32_t p_42, const int32_t p_43, int64_t p_44, uint32_t p_45, int32_t p_46);
static int64_t func_65(int32_t p_66, int32_t p_67, uint16_t p_68);
static int32_t func_73(uint16_t p_74, int32_t p_75, uint16_t p_76, uint64_t p_77);
static int16_t func_143(uint16_t p_144, int32_t p_145, uint32_t p_146, int8_t p_147);
static int32_t func_169(uint8_t p_170, int32_t p_171);
static uint8_t func_189(uint8_t p_190, int8_t p_191, int8_t p_192);
static uint8_t func_1(void)
{
int16_t l_13 = 0xD509L;
const uint16_t l_355 = 0xA6DEL;
int32_t l_408 = 0x9EF1719AL;
int32_t l_429 = 0L;
int8_t l_442 = 0x1AL;
int32_t l_470 = 0xE8A64E1BL;
int64_t l_471 = 1L;
int32_t l_472 = 7L;
int32_t l_473[4];
uint8_t l_477 = 249UL;
int i;
for (i = 0; i < 4; i++)
l_473[i] = 0x60D75D45L;
lbl_430:
l_408 ^= func_2((g_8[0] , func_9(l_13, g_8[0], g_8[0])), g_78[1], l_355, l_13, g_78[1]);
if ((safe_unary_minus_func_int16_t_s(l_408)))
{
uint16_t l_426 = 0x2057L;
int32_t l_427 = 0x3C30839EL;
g_91 &= (g_123[1] = (safe_rshift_func_uint8_t_u_u((((safe_add_func_int64_t_s_s(((((safe_lshift_func_uint16_t_u_s(((safe_mul_func_uint16_t_u_u(((g_344 == (-1L)) || (safe_mul_func_int8_t_s_s((((safe_mul_func_uint8_t_u_u((g_185--), (safe_div_func_uint8_t_u_u(((l_426 = (-6L)) , g_122), l_355)))) > g_18[0]) < g_345), l_427))), g_388)) , 0xC88DL), 12)) <= l_427) || l_13) < g_118), l_408)) , g_63[0]) , 0x5EL), 1)));
}
else
{
int32_t l_428 = (-1L);
uint64_t l_443 = 0UL;
int32_t l_450 = (-1L);
int32_t l_459[3];
int i;
for (i = 0; i < 3; i++)
l_459[i] = 1L;
l_429 |= (l_408 |= (g_199 = l_428));
if (g_199)
goto lbl_431;
lbl_431:
if (g_390)
goto lbl_430;
if (g_108)
goto lbl_468;
l_428 = (4294967295UL && (safe_div_func_uint64_t_u_u((((safe_add_func_int8_t_s_s(((safe_sub_func_int64_t_s_s((safe_rshift_func_uint16_t_u_s((safe_div_func_int8_t_s_s(((g_387 ^= ((g_78[1] >= g_390) , l_442)) || l_428), g_88)), 9)), l_443)) ^ l_355), g_199)) && g_199) , 3UL), l_428)));
lbl_469:
g_344 ^= (((safe_rshift_func_uint16_t_u_s((l_429 |= (safe_sub_func_int16_t_s_s(((safe_div_func_uint64_t_u_u((g_91 | l_443), (l_428 | l_408))) ^ g_123[0]), 6UL))), 6)) < l_355) | 0xAE8A57F9CF414FDDLL);
l_450 |= (l_429 &= (9L != l_428));
l_428 = (safe_lshift_func_uint16_t_u_u((g_345 >= g_88), (safe_mul_func_int8_t_s_s((((safe_mod_func_uint32_t_u_u(0xCA033A93L, 0x5E5EA0DFL)) , l_450) , 0xFDL), l_442))));
lbl_468:
l_459[2] = (((safe_add_func_int8_t_s_s(((((((((((((g_390--) || ((g_199 |= (g_344 = ((safe_sub_func_uint32_t_u_u((g_63[0]--), (0xAEL == ((safe_rshift_func_uint16_t_u_u((0xB1L != 0xCAL), l_355)) | 0xB9658265L)))) ^ g_123[1]))) || l_450)) , g_69) < g_123[1]) > l_443) && 0x60L) >= 1L) < 0x95A96146L) ^ l_13) > g_118) , 0xCA53L) >= 0UL), 0xF0L)) , g_390) != 0xACBAA4A0L);
if (g_108)
goto lbl_469;
}
g_474--;
++l_477;
return l_355;
}
static int32_t func_2(uint32_t p_3, uint64_t p_4, const int64_t p_5, uint32_t p_6, uint64_t p_7)
{
uint16_t l_374 = 65531UL;
int32_t l_375 = 0xB624E792L;
int32_t l_377 = 0x1C1A9024L;
int32_t l_378[1];
int64_t l_386 = (-1L);
int i;
for (i = 0; i < 1; i++)
l_378[i] = 0xB9098913L;
lbl_401:
for (g_108 = 0; (g_108 != (-1)); g_108--)
{
int64_t l_360[2];
int i;
for (i = 0; i < 2; i++)
l_360[i] = 0xBC21278764A2B4ADLL;
l_360[1] &= ((safe_lshift_func_int16_t_s_u(g_63[0], 3)) & (p_5 && g_345));
g_123[0] = (safe_div_func_int8_t_s_s(((safe_mul_func_uint16_t_u_u((safe_div_func_int64_t_s_s((safe_rshift_func_uint8_t_u_u(0xAAL, 3)), ((!(((((safe_mul_func_int16_t_s_s(((l_360[1] , (((safe_mod_func_int16_t_s_s((p_6 , g_69), g_8[0])) || p_4) && p_4)) & 0x7F55DE8AL), 0x6E83L)) || l_374) != g_199) , l_360[1]) != 0x79FDA063L)) | l_374))), 0x8C4EL)) || 0x4FB6FEA1CC2CD02ELL), g_123[0]));
return p_4;
}
l_375 = (g_346 != (0xEFL < p_5));
for (p_4 = 0; (p_4 <= 1); p_4 += 1)
{
int32_t l_376[4] = {0x96BA196CL,0x96BA196CL,0x96BA196CL,0x96BA196CL};
uint16_t l_400[1];
uint8_t l_402 = 0xCFL;
int i;
for (i = 0; i < 1; i++)
l_400[i] = 0x11E0L;
if (g_8[0])
break;
g_379++;
g_123[p_4] = ((safe_lshift_func_uint8_t_u_u((l_376[3] = 0x82L), ((((safe_div_func_int16_t_s_s(((((255UL || 0x22L) >= g_379) == 2L) > p_4), p_5)) | g_123[p_4]) | 6L) >= 1UL))) >= l_386);
l_376[3] = (((++g_390) ^ (safe_lshift_func_uint16_t_u_u(((safe_sub_func_uint32_t_u_u((+(((((g_345 | (65535UL >= (-1L))) > l_378[0]) < l_376[3]) , l_400[0]) == g_123[1])), p_7)) & (-7L)), 11))) | 0x7D12CE1CFEF05E6BLL);
if (g_199)
goto lbl_401;
--l_402;
}
for (g_118 = 0; (g_118 >= (-16)); --g_118)
{
int16_t l_407 = 2L;
l_377 = (l_407 ^= p_3);
}
return p_5;
}
static uint32_t func_9(int16_t p_10, int8_t p_11, int8_t p_12)
{
uint16_t l_15 = 0x8764L;
uint16_t l_25 = 9UL;
int32_t l_36 = 0x2AE857B1L;
int32_t l_273 = 1L;
int32_t l_275 = 5L;
int32_t l_276 = 0xFA4DCBB3L;
int32_t l_277 = (-1L);
int32_t l_278 = 0xE3F56E04L;
uint32_t l_279 = 0x7F83BBFEL;
const int32_t l_292 = 0xF8AC1A1CL;
int16_t l_293 = 9L;
int32_t l_311 = (-2L);
int32_t l_312 = 0x94950BB0L;
int32_t l_313 = (-9L);
int32_t l_314 = 0x23CEAC78L;
int32_t l_315 = 0xCB1931DEL;
int32_t l_316 = 0L;
int32_t l_317[4];
int64_t l_318 = 1L;
uint16_t l_319 = 0x27FAL;
int8_t l_325 = (-4L);
int i;
for (i = 0; i < 4; i++)
l_317[i] = 0L;
for (p_11 = 0; (p_11 >= 0); p_11 -= 1)
{
int8_t l_14[3];
int8_t l_26[2];
int32_t l_261 = (-1L);
int i;
for (i = 0; i < 3; i++)
l_14[i] = 0x5CL;
for (i = 0; i < 2; i++)
l_26[i] = (-1L);
l_15--;
g_18[0]++;
l_36 = func_21(g_8[p_11], l_25, (g_18[1] , l_26[1]));
g_63[0] = ((safe_lshift_func_uint8_t_u_s(1UL, 7)) , (+(((~(func_41(g_8[0], (((((safe_sub_func_int16_t_s_s(((g_62 ^= func_21((p_10 = ((safe_div_func_int16_t_s_s((safe_mod_func_int16_t_s_s((safe_rshift_func_int16_t_s_s(((((((((safe_mul_func_uint16_t_u_u((safe_add_func_int64_t_s_s((func_21(((((((+((safe_add_func_uint64_t_u_u((l_25 , 0x4E4A53E8AF80453DLL), g_18[0])) > g_18[2])) || p_10) < g_18[2]) <= l_14[0]) ^ 0L) , g_8[p_11]), g_18[0], g_18[2]) <= p_12), g_18[0])), l_25)) ^ l_36) < l_14[0]) , 0x37L) < 0x1CL) <= g_18[2]) && g_8[0]) != l_36), p_12)), g_8[0])), g_8[0])) , l_26[1])), p_12, p_12)) != g_18[0]), l_15)) > p_12) | p_11) | 0x54F4L) , g_8[p_11]), g_8[0], g_8[p_11], g_8[0]) <= 0xC342L)) <= 0xC2610AA4AECA2A42LL) ^ g_8[0])));
if (l_25)
continue;
l_261 &= (((safe_unary_minus_func_int64_t_s(func_65(((l_36 = (g_69--)) , p_11), (g_63[0] , (-7L)), g_63[0]))) == l_14[0]) | 1UL);
if (p_11)
continue;
if (p_11)
break;
if (p_10)
continue;
}
for (g_118 = (-2); (g_118 < (-6)); g_118--)
{
int32_t l_269 = 0x4673FFDFL;
int32_t l_270 = (-1L);
int32_t l_271 = 0xEF1AE505L;
int32_t l_272 = 9L;
int32_t l_274[3];
int i;
for (i = 0; i < 3; i++)
l_274[i] = 0L;
g_199 = ((((safe_mul_func_int16_t_s_s((3UL < (safe_lshift_func_int8_t_s_u((l_271 = (((l_270 = (((~g_185) , ((l_36 &= l_269) , g_185)) | l_269)) < p_12) <= 0xCE31F70DFA86E48CLL)), 2))), p_11)) && p_10) & g_91) == g_199);
g_123[1] = 0xCF2520F9L;
++l_279;
l_275 ^= (((safe_mod_func_uint32_t_u_u((safe_add_func_int64_t_s_s((safe_lshift_func_int8_t_s_s(((safe_mod_func_int8_t_s_s(1L, (p_11 = (safe_div_func_int64_t_s_s((0x1EL != g_122), l_292))))) && l_292), g_8[0])), l_293)), 0x5A99F62EL)) < g_18[0]) == p_12);
}
l_276 = g_18[2];
if (((((~(safe_rshift_func_int8_t_s_s(((p_10 & (safe_lshift_func_uint16_t_u_u((((g_78[1] > (l_273 == p_11)) || l_292) & 1L), 5))) > p_12), 2))) , 0L) >= g_88) | 0x86L))
{
int16_t l_299[1];
int32_t l_304 = 9L;
int32_t l_309 = 0L;
int32_t l_310[2];
int i;
for (i = 0; i < 1; i++)
l_299[i] = 0xA4B3L;
for (i = 0; i < 2; i++)
l_310[i] = 0L;
l_299[0] ^= p_12;
l_310[0] = (safe_mul_func_int16_t_s_s(((l_309 = (safe_add_func_uint8_t_u_u(((l_304 = 5UL) < (safe_mul_func_uint16_t_u_u(0x4F91L, (safe_mul_func_int8_t_s_s(l_299[0], (-1L)))))), g_123[1]))) >= 0xF1068F0AL), p_12));
if (l_279)
goto lbl_322;
++l_319;
lbl_322:
l_312 = (((g_122 , ((0x54F258C9E95FC931LL < 0xDE88E6AF5DDE9F33LL) > g_62)) & 65533UL) | g_88);
g_91 = (safe_lshift_func_int16_t_s_u(l_278, 2));
}
else
{
int16_t l_329 = (-1L);
int32_t l_348 = (-1L);
int32_t l_350 = 0L;
l_329 = (0x103FD7DEL | (l_325 || ((safe_div_func_int64_t_s_s((~(5UL < p_10)), g_118)) >= l_36)));
l_314 = ((((safe_mul_func_int16_t_s_s(g_118, (g_346 = (safe_lshift_func_int8_t_s_s(((safe_lshift_func_uint16_t_u_u(((safe_mod_func_uint64_t_u_u((safe_div_func_int16_t_s_s(((0xCDAB2235F0C6E62ELL && (safe_sub_func_uint64_t_u_u((((g_344 |= (safe_rshift_func_uint8_t_u_s((((-4L) || 0x5E22DACE22F34741LL) == 0xF57F58CEL), 4))) ^ l_329) <= 0xCBL), 0xD45781768F9B7D9BLL))) <= l_278), p_11)), g_345)) < l_329), 6)) <= 65535UL), 7))))) && g_8[0]) != 18446744073709551610UL) < l_329);
l_348 &= (+p_12);
l_350 &= ((2UL > (((+(l_348 ^= (l_317[2] = 1L))) , 0xA489C879L) | (-9L))) || p_11);
g_199 = p_10;
return l_348;
}
g_344 = ((g_123[1] |= (safe_sub_func_uint64_t_u_u(0xEC0A9045112F0B68LL, (0x618AL ^ (((safe_rshift_func_int16_t_s_s(((p_11 = l_15) < l_311), 14)) && 1L) || 0xB364L))))) != 1UL);
return p_11;
}
static int32_t func_21(int16_t p_22, uint64_t p_23, uint8_t p_24)
{
uint32_t l_29 = 0x9E71B35DL;
int32_t l_35[3];
int i;
for (i = 0; i < 3; i++)
l_35[i] = 0x15169FF4L;
for (p_22 = 6; (p_22 != 8); ++p_22)
{
uint16_t l_34 = 65535UL;
l_29++;
l_35[2] = (g_8[0] && (safe_sub_func_int64_t_s_s(((-1L) != (l_34 ^= (7L <= 0xFA97F51EF9953E80LL))), g_18[0])));
if (l_29)
continue;
if (p_22)
break;
}
return p_23;
}
static uint16_t func_41(int32_t p_42, const int32_t p_43, int64_t p_44, uint32_t p_45, int32_t p_46)
{
return p_46;
}
static int64_t func_65(int32_t p_66, int32_t p_67, uint16_t p_68)
{
int64_t l_72[3];
int32_t l_115 = 0xD808B432L;
int32_t l_120 = 0x39CAC122L;
int32_t l_121 = (-1L);
int32_t l_128 = 0x06C31128L;
int32_t l_129 = (-1L);
int32_t l_130 = 0x7493B576L;
int32_t l_131 = 0x3C38EFF2L;
int32_t l_132 = 0xDFAB60A8L;
int32_t l_133 = 0L;
int32_t l_134 = 0x91146291L;
int32_t l_135 = 1L;
int32_t l_186 = 1L;
const int64_t l_201 = (-6L);
int32_t l_219 = 0L;
int i;
for (i = 0; i < 3; i++)
l_72[i] = 0xD024CA9A92ED1608LL;
if (l_72[2])
{
int32_t l_113 = 0xA549A7EFL;
int32_t l_114 = 0x25C60408L;
int32_t l_116 = 0x0D965893L;
int32_t l_117 = 0L;
int32_t l_119 = 0x0C841BEEL;
int32_t l_124 = 0L;
int32_t l_125 = 0x0D1FC1C1L;
int32_t l_126 = 0x9D2F4757L;
int32_t l_127[4];
uint64_t l_136 = 0xC2020794590A9178LL;
int i;
for (i = 0; i < 4; i++)
l_127[i] = (-9L);
l_113 = ((func_41(p_67, g_18[1], (func_41(func_73(g_69, g_63[0], p_67, g_69), g_78[0], p_68, l_72[2], l_72[1]) & g_78[1]), g_8[0], l_113) , l_72[0]) <= g_78[1]);
--l_136;
}
else
{
int32_t l_184[1];
uint32_t l_202 = 0xC7A1140AL;
int16_t l_230 = 0x9257L;
int16_t l_233[1];
int i;
for (i = 0; i < 1; i++)
l_184[i] = 0x3A5B7F6AL;
for (i = 0; i < 1; i++)
l_233[i] = (-7L);
l_186 = (safe_mul_func_uint16_t_u_u((g_185 = (func_73(((safe_mul_func_int8_t_s_s((((l_133 != ((func_143(l_131, ((l_115 , p_68) <= 0UL), g_8[0], p_67) != 0x5D89L) != l_184[0])) , l_128) && l_131), 0x5CL)) || g_118), l_134, l_184[0], p_66) < g_63[0])), 0x74F0L));
g_91 ^= (((func_41(((((safe_div_func_int32_t_s_s(func_169(func_189(g_8[0], (safe_sub_func_int64_t_s_s(((safe_rshift_func_int8_t_s_s((safe_mod_func_int16_t_s_s(l_184[0], (p_67 && g_199))), l_129)) >= 0x869117D6L), p_66)), g_122), p_67), 0xD53C73CEL)) , g_118) , p_68) || 255UL), l_201, l_184[0], p_66, g_78[1]) ^ 0xDAF6FCE94049F96DLL) , g_78[3]) > p_68);
l_202--;
l_120 = (((l_184[0] = (g_63[0] <= (safe_div_func_uint32_t_u_u(((safe_add_func_uint8_t_u_u((~((l_115 &= ((safe_lshift_func_uint16_t_u_s((safe_mul_func_uint8_t_u_u(p_67, (safe_unary_minus_func_int32_t_s((l_128 , 0x6EA6DD21L))))), p_68)) ^ 0x62L)) ^ 0x1DA2L)), p_66)) , g_108), 0x3F7C7667L)))) <= p_67) <= p_66);
l_132 = (safe_sub_func_uint32_t_u_u((safe_mod_func_uint8_t_u_u((g_62 = (++g_185)), (safe_mod_func_uint16_t_u_u(0x838CL, (safe_lshift_func_uint16_t_u_s(((safe_div_func_int8_t_s_s((safe_div_func_int64_t_s_s((l_184[0] = (((l_120 , ((-10L) > p_68)) == (-1L)) == g_18[0])), p_68)), 3UL)) != p_66), 1)))))), l_230));
g_199 ^= ((((((((((p_68 == (((g_62 = 9UL) | 0UL) , 0xAF27L)) != 0xFDEEFCC7L) , p_68) <= g_108) ^ l_233[0]) < l_233[0]) <= g_63[0]) != 0x7F3B7B1D02B38FC1LL) == g_8[0]) ^ 0UL);
}
l_120 = ((safe_div_func_int32_t_s_s(g_122, (safe_div_func_uint8_t_u_u((((safe_unary_minus_func_uint32_t_u(((safe_rshift_func_int16_t_s_s(l_131, 5)) < (((l_132 = (safe_lshift_func_int8_t_s_s((((((safe_rshift_func_uint8_t_u_u(l_115, 3)) || 0xE5L) , l_121) <= l_132) || l_120), 2))) != p_68) , l_133)))) , 0xD4D56269L) < g_8[0]), l_72[2])))) == 0xE84A3AFCE4FDF005LL);
l_121 |= p_66;
if ((g_199 = (~(safe_mod_func_int64_t_s_s(((((((safe_rshift_func_uint16_t_u_u((safe_add_func_int8_t_s_s(((((g_78[2] <= (~((l_186 , (safe_div_func_int8_t_s_s((safe_sub_func_int8_t_s_s(p_68, g_91)), l_130))) || 0x4820B1D2C0F4AEB9LL))) < g_69) , 0x3FL) != p_68), g_62)), 8)) != g_123[1]) || p_68) || p_68) >= 0x80F3L) <= l_134), g_118)))))
{
int64_t l_257 = 9L;
return l_257;
}
else
{
uint8_t l_258 = 0x37L;
l_258--;
l_186 &= (65530UL == (0L ^ g_123[0]));
}
return l_129;
}
static int32_t func_73(uint16_t p_74, int32_t p_75, uint16_t p_76, uint64_t p_77)
{
int32_t l_79 = 0x74ECB9A7L;
int32_t l_80 = 1L;
int32_t l_81 = 0xDA268580L;
int32_t l_82 = 1L;
int32_t l_83 = 0x6C1C926AL;
int32_t l_84 = 1L;
int32_t l_85 = (-1L);
int32_t l_86 = 0x9972037CL;
int32_t l_87 = 0x41160C00L;
int32_t l_107[3];
int i;
for (i = 0; i < 3; i++)
l_107[i] = 0x7275A216L;
g_88--;
if (p_74)
{
int8_t l_96 = (-8L);
int32_t l_97 = 0x6667EE9FL;
g_91 = l_81;
p_75 = (((safe_rshift_func_uint8_t_u_u(((func_41(((((safe_sub_func_int16_t_s_s(l_96, 0x4A04L)) | p_75) , g_18[0]) == g_78[2]), p_76, p_76, l_97, g_8[0]) , (-1L)) | (-1L)), 3)) || l_97) > l_96);
g_91 = (safe_mul_func_uint8_t_u_u((safe_sub_func_uint16_t_u_u(l_97, 1L)), l_97));
g_91 = (p_75 = p_77);
}
else
{
int64_t l_106 = 0L;
g_108 |= (safe_lshift_func_int16_t_s_u(func_41((((safe_lshift_func_uint8_t_u_u((((g_78[1] && l_106) < (l_107[0] && g_91)) < g_8[0]), 3)) & l_81) == g_78[1]), p_76, l_79, l_106, l_106), 4));
g_91 ^= g_8[0];
g_91 = ((safe_mul_func_int8_t_s_s(3L, (-8L))) , (safe_lshift_func_int16_t_s_u(0x2C01L, 11)));
}
return l_81;
}
static int16_t func_143(uint16_t p_144, int32_t p_145, uint32_t p_146, int8_t p_147)
{
const int32_t l_150 = (-6L);
int32_t l_155[1];
int32_t l_156[2];
int i;
for (i = 0; i < 1; i++)
l_155[i] = 0x18C3B0D5L;
for (i = 0; i < 2; i++)
l_156[i] = 0L;
g_123[0] = ((safe_lshift_func_int16_t_s_u(l_150, g_18[2])) <= p_146);
l_156[1] = ((g_8[0] = (g_118 ^= ((safe_mod_func_uint64_t_u_u(g_63[0], (safe_lshift_func_int8_t_s_u((l_150 || ((l_155[0] = 65535UL) == g_8[0])), 5)))) , p_145))) , p_147);
l_156[0] = func_41((l_155[0] = l_155[0]), (1UL | (g_69 |= (safe_mul_func_int16_t_s_s((l_156[1] ^ g_8[0]), l_156[1])))), g_78[1], l_156[0], p_145);
if (l_155[0])
{
uint8_t l_159 = 0x03L;
uint8_t l_182[2];
int32_t l_183 = 5L;
int i;
for (i = 0; i < 2; i++)
l_182[i] = 1UL;
l_159++;
g_123[1] ^= (((((safe_mul_func_int16_t_s_s((safe_mul_func_uint16_t_u_u(func_21((safe_mul_func_uint16_t_u_u((!g_78[1]), func_73(p_147, func_169((safe_div_func_int64_t_s_s(func_73(p_144, p_144, l_159, g_62), g_122)), l_150), g_78[0], l_182[0]))), g_122, g_118), 0UL)), l_155[0])) < g_18[1]) , p_147) != 1UL) && l_159);
l_183 = 0xD81C2D92L;
return l_159;
}
else
{
return g_8[0];
}
}
static int32_t func_169(uint8_t p_170, int32_t p_171)
{
int64_t l_174 = (-1L);
int32_t l_175 = 0L;
int32_t l_176[2];
int i;
for (i = 0; i < 2; i++)
l_176[i] = 0L;
if (l_174)
{
uint32_t l_177 = 0UL;
uint16_t l_180 = 0x5D1BL;
--l_177;
l_180 |= (-5L);
return g_8[0];
}
else
{
uint64_t l_181[2];
int i;
for (i = 0; i < 2; i++)
l_181[i] = 0x488BB19F011E324BLL;
return l_181[0];
}
}
static uint8_t func_189(uint8_t p_190, int8_t p_191, int8_t p_192)
{
int32_t l_200 = (-3L);
return l_200;
}
int main (int argc, char* argv[])
{
int i;
int print_hash_value = 0;
if (argc == 2 && strcmp(argv[1], "1") == 0) print_hash_value = 1;
platform_main_begin();
crc32_gentab();
func_1();
for (i = 0; i < 1; i++)
{
transparent_crc(g_8[i], "g_8[i]", print_hash_value);
if (print_hash_value) printf("index = [%d]\n", i);
}
for (i = 0; i < 3; i++)
{
transparent_crc(g_18[i], "g_18[i]", print_hash_value);
if (print_hash_value) printf("index = [%d]\n", i);
}
transparent_crc(g_62, "g_62", print_hash_value);
for (i = 0; i < 1; i++)
{
transparent_crc(g_63[i], "g_63[i]", print_hash_value);
if (print_hash_value) printf("index = [%d]\n", i);
}
transparent_crc(g_69, "g_69", print_hash_value);
for (i = 0; i < 4; i++)
{
transparent_crc(g_78[i], "g_78[i]", print_hash_value);
if (print_hash_value) printf("index = [%d]\n", i);
}
transparent_crc(g_88, "g_88", print_hash_value);
transparent_crc(g_91, "g_91", print_hash_value);
transparent_crc(g_108, "g_108", print_hash_value);
transparent_crc(g_118, "g_118", print_hash_value);
transparent_crc(g_122, "g_122", print_hash_value);
for (i = 0; i < 2; i++)
{
transparent_crc(g_123[i], "g_123[i]", print_hash_value);
if (print_hash_value) printf("index = [%d]\n", i);
}
transparent_crc(g_185, "g_185", print_hash_value);
transparent_crc(g_199, "g_199", print_hash_value);
transparent_crc(g_344, "g_344", print_hash_value);
transparent_crc(g_345, "g_345", print_hash_value);
transparent_crc(g_346, "g_346", print_hash_value);
transparent_crc(g_379, "g_379", print_hash_value);
transparent_crc(g_387, "g_387", print_hash_value);
transparent_crc(g_388, "g_388", print_hash_value);
transparent_crc(g_389, "g_389", print_hash_value);
transparent_crc(g_390, "g_390", print_hash_value);
transparent_crc(g_474, "g_474", print_hash_value);
platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value);
return 0;
}
| 41.260377 | 744 | 0.596534 |
32070f2973a8501e633a0294e642e44f6264774d | 50,254 | c | C | projects/CodeThorn/src/tests/rers/Problem1403_opt.c | ouankou/rose | 76f2a004bd6d8036bc24be2c566a14e33ba4f825 | [
"BSD-3-Clause"
] | 488 | 2015-01-09T08:54:48.000Z | 2022-03-30T07:15:46.000Z | projects/CodeThorn/src/tests/rers/Problem1403_opt.c | sujankh/rose-matlab | 7435d4fa1941826c784ba97296c0ec55fa7d7c7e | [
"BSD-3-Clause"
] | 174 | 2015-01-28T18:41:32.000Z | 2022-03-31T16:51:05.000Z | projects/CodeThorn/src/tests/rers/Problem1403_opt.c | sujankh/rose-matlab | 7435d4fa1941826c784ba97296c0ec55fa7d7c7e | [
"BSD-3-Clause"
] | 146 | 2015-04-27T02:48:34.000Z | 2022-03-04T07:32:53.000Z | // .--------------------------------------------------------.
// | printf in functions replaced by global output variable |
// *--------------------------------------------------------*
int input;
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
//edited by script: global output variable replacing printf in functions
int output;
int a68 = 12;
int a118 = 1;
int cf = 1;
int a198 = - 3;
int a94 = 11;
int a71 = 7;
int a42 = 251;
int a171_0 = 53;
int a171_1 = 54;
int a171_2 = 55;
int a171_3 = 56;
int a171_5 = 58;
int a35 = 12;
int a74 = 68;
int a188 = 296;
int a173 = 10;
int a39_0 = 19;
int a39_1 = 20;
int a39_2 = 21;
int a39_3 = 22;
int a39_4 = 23;
int a39_5 = 24;
int a124_0 = 31;
int a124_1 = 32;
int a124_2 = 33;
int a124_3 = 34;
int a124_4 = 35;
int a124_5 = 36;
int a15_0 = 25;
int a15_1 = 26;
int a15_2 = 27;
int a15_3 = 28;
int a15_4 = 29;
int a15_5 = 30;
int a18_0 = 31;
int a18_1 = 32;
int a18_2 = 33;
int a18_3 = 34;
int a18_4 = 35;
int a18_5 = 36;
int a101_0 = 37;
int a101_1 = 38;
int a101_2 = 39;
int a101_3 = 40;
int a101_4 = 41;
int a101_5 = 42;
int a53 = 4;
int a107_0 = 9;
int a107_5 = 14;
int a107_7 = 16;
int a62 = 6;
int a187 = 4;
int a105 = - 193;
int a165_0 = 8;
int a165_2 = 10;
int a165_3 = 11;
int a165_4 = 12;
int a165_5 = 13;
int a165_6 = 14;
int a165_7 = 15;
int a80 = 216;
int a148_1 = 65;
int a148_2 = 66;
int a148_3 = 67;
int a148_4 = 68;
int a148_5 = 69;
int a127_0 = 104;
int a127_1 = 105;
int a127_4 = 108;
int a127_5 = 109;
int a49 = 379;
int a8 = 6;
int a167 = 8;
int a119 = 14;
int a182_0 = 100;
int a182_1 = 101;
int a182_2 = 102;
int a182_3 = 103;
int a182_4 = 104;
int a182_5 = 105;
int a125_0 = 88;
int a125_1 = 89;
int a125_2 = 90;
int a125_3 = 91;
int a125_4 = 92;
int a125_5 = 93;
int a193_6 = 11;
int a197_0 = 87;
int a197_1 = 88;
int a197_2 = 89;
int a197_3 = 90;
int a197_4 = 91;
int a197_5 = 92;
int a6_0 = 99;
int a6_1 = 100;
int a6_2 = 101;
int a6_3 = 102;
int a6_4 = 103;
int a6_5 = 104;
int a183_0 = 99;
int a183_1 = 100;
int a183_2 = 101;
int a183_3 = 102;
int a183_4 = 103;
int a183_5 = 104;
int a191_0 = 7;
int a191_4 = 11;
int a191_6 = 13;
int a191_7 = 14;
int a67 = 9;
int a109_2 = 3;
int a109_3 = 4;
int a109_5 = 6;
int a109_7 = 8;
int a37 = 266;
int a116 = 6;
int a73_0 = 6;
int a73_1 = 7;
int a73_3 = 9;
int a73_4 = 10;
int a73_6 = 12;
int a24_0 = 27;
int a24_1 = 28;
int a24_2 = 29;
int a24_3 = 30;
int a24_4 = 31;
int a24_5 = 32;
int a89 = 13;
int a69_0 = 0;
int a69_1 = 1;
int a69_2 = 2;
int a69_5 = 5;
int a81_3 = 9;
int a81_5 = 11;
int a31 = 7;
int a154_0 = 57;
int a154_1 = 58;
int a154_2 = 59;
int a154_3 = 60;
int a154_4 = 61;
int a154_5 = 62;
int a158 = 9;
int a45_5 = 12;
int a111 = 56;
int a104_1 = 7;
int a104_2 = 8;
int a104_3 = 9;
int a104_4 = 10;
int a104_5 = 11;
int a104_7 = 13;
int a122 = 6;
int a169_0 = 98;
int a169_1 = 99;
int a169_2 = 100;
int a169_3 = 101;
int a169_4 = 102;
int a169_5 = 103;
int a157_0 = 104;
int a157_1 = 105;
int a157_2 = 106;
int a157_3 = 107;
int a157_4 = 108;
int a157_5 = 109;
int a91_0 = 110;
int a91_1 = 111;
int a91_2 = 112;
int a91_3 = 113;
int a91_4 = 114;
int a91_5 = 115;
int a52_0 = 98;
int a52_1 = 99;
int a52_2 = 100;
int a52_3 = 101;
int a52_4 = 102;
int a52_5 = 103;
int a139_0 = 7;
int a139_2 = 9;
int a139_4 = 11;
int a139_5 = 12;
int a139_6 = 13;
int a139_7 = 14;
int a86 = 13;
int a1 = 8;
int a137_0 = 7;
int a137_1 = 8;
int a137_3 = 10;
int a137_5 = 12;
int a137_6 = 13;
int a137_7 = 14;
int a26 = 15;
int a194 = 9;
int a50 = 13;
int a176_1 = 8;
int a176_3 = 10;
int a176_6 = 13;
int main()
{
//srand((unsigned)time(NULL));
// main i/o-loop
while(1){
//edited by script: maybe no output, reset output var
output = - 1;
// read input
scanf("%d",&input);
{
cf = 1;
if (a37 <= 35 && cf == 1) {
if (cf == 1 && a188 <= - 79) {{
if (cf == 1 && (88 < a80 && 150 >= a80)) {
if (a118 == 6 && cf == 1) {{
if (cf == 1 && input == 2) {
cf = 0;
a8 = 2;
a94 = 11;
a52_0 = 104;
a52_1 = 105;
a52_2 = 106;
a52_3 = 107;
a52_4 = 108;
a52_5 = 109;
a37 = (a37 * a80 % 14999 + - 12383 - 1204) % 24 + 222;
output = 21;
}
}
}
if (a118 == 7 && cf == 1) {{
if (input == 4 && cf == 1) {
cf = 0;
a116 = 8;
a194 = 6;
a105 = (a105 * a188 % 14999 % 14900 - - 15098) * 1 - - 1;
a37 = a37 * a80 % 14999 % 81 - - 117 - - 1 - - 3600 + - 3600;
output = 20;
}
}
}
}
}
}
if (cf == 1 && (- 79 < a188 && 111 >= a188)) {{
if (cf == 1 && 33 == a101_2) {
if (cf == 1 && a122 == 2) {{
if (input == 1 && cf == 1) {
cf = 0;
a15_0 = 31;
a15_1 = 32;
a15_2 = 33;
a15_3 = 34;
a15_4 = 35;
a15_5 = 36;
a71 = 11;
a37 = (a37 * a188 % 14999 - - 1833) % 14876 - - 15123 + 1;
output = 22;
}
}
}
}
}
}
if (cf == 1 && (111 < a188 && 285 >= a188)) {{
if (a53 == 5 && cf == 1) {
if (a31 == 13 && cf == 1) {{
if (cf == 1 && input == 4) {
cf = 0;
output = 19;
}
if (cf == 1 && input == 5) {
cf = 0;
a194 = 10;
a167 = 11;
a105 = (a105 * a37 % 14999 + 10695 - 21488) * 1 % 14906 - 15093;
a37 = a37 * a188 % 14999 % 81 + 116 - 0 - 0;
output = 26;
}
if (cf == 1 && input == 1) {
cf = 0;
output = 19;
}
if (input == 2 && cf == 1) {
cf = 0;
a8 = 2;
a94 = 11;
a52_0 = 104;
a52_1 = 105;
a52_2 = 106;
a52_3 = 107;
a52_4 = 108;
a52_5 = 109;
a37 = ((a37 * a37 % 14999 % 24 - - 223) * 5 - - 10855) % 24 + 209;
output = 19;
}
if (input == 3 && cf == 1) {
cf = 0;
a158 = 10;
a94 = 15;
a52_0 = 104;
a52_1 = 105;
a52_2 = 106;
a52_3 = 107;
a52_4 = 108;
a52_5 = 109;
a37 = (a37 * a37 % 14999 - - 1772) / 5 % 24 + 223;
output = 21;
}
}
}
}
}
}
if (cf == 1 && 285 < a188) {{
if (89 == a183_2 && cf == 1) {
if (cf == 1 && a89 == 9) {{
if (cf == 1 && input == 4) {
cf = 0;
a8 = 4;
a42 = (a42 * a188 % 14999 - - 3608) % 14830 - - 15169 - - 1;
a71 = 7;
a37 = ((a37 * a188 % 14999 % 14876 - - 15123) / 5 - 16432) * - 1 / 10;
output = 23;
}
}
}
}
if (cf == 1 && 100 == a183_1) {
if (a86 == 9 && cf == 1) {{
if (cf == 1 && input == 1) {
cf = 0;
a62 = 5;
a80 = (a80 * a37 % 14999 + 189 + 12853) % 40 - - 192;
a52_0 = 98;
a52_1 = 99;
a52_2 = 100;
a52_3 = 101;
a52_4 = 102;
a52_5 = 103;
a37 = (a37 * a37 % 14999 % 24 + 223 - 1) * 1;
output = 19;
}
if (cf == 1 && input == 5) {
cf = 0;
a173 = 14;
a74 = (a74 * a188 % 14999 % 80 - - 224) / 5 / 5 + 274;
a71 = 14;
a37 = (a37 * a37 % 14999 % 14876 - - 15123) / 5 / 5 + 23499;
output = 22;
}
if (input == 4 && cf == 1) {
cf = 0;
output = 23;
}
if (input == 2 && cf == 1) {
cf = 0;
output = 23;
}
}
}
}
}
}
}
if (cf == 1 && (35 < a37 && 198 >= a37)) {
if (cf == 1 && a105 <= - 188) {{
if (a167 == 6 && cf == 1) {
if (cf == 1 && a35 == 8) {{
if (input == 1 && cf == 1) {
cf = 0;
a118 = 7;
a80 = ((a80 * a105 % 14999 % 30 - - 119) * 5 - 14866) % 30 - - 135;
a188 = a188 * a105 % 14999 % 14960 + - 15038 + - 3 - - 10502 + - 10499;
a37 = (a37 * a105 % 14999 + - 3591 + - 1641) * 1;
output = 26;
}
if (cf == 1 && input == 4) {
cf = 0;
a122 = 2;
a101_0 = 31;
a101_1 = 32;
a101_2 = 33;
a101_3 = 34;
a101_4 = 35;
a101_5 = 36;
a188 = (a188 * a105 % 14999 - 3816 + - 10670) % 94 + 15;
a37 = (a37 * a105 % 14999 - - 2989 - 6080) * 1;
output = 21;
}
}
}
}
if (cf == 1 && a167 == 7) {
if (cf == 1 && 59 == 59) {{
if (input == 3 && cf == 1) {
cf = 0;
a116 = 5;
a194 = 6;
a105 = (a105 * a105 % 14999 - - 2899 - - 6116) * 1;
output = 23;
}
if (input == 2 && cf == 1) {
cf = 0;
output = 24;
}
if (input == 4 && cf == 1) {
cf = 0;
output = 24;
}
if (cf == 1 && input == 5) {
cf = 0;
a67 = 8;
a167 = 8;
output = 26;
}
if (cf == 1 && input == 1) {
cf = 0;
output = 24;
}
}
}
}
}
}
if (cf == 1 && (- 188 < a105 && 5 >= a105)) {{
if (cf == 1 && a49 <= 153) {
if (a42 <= 71 && cf == 1) {{
if (input == 4 && cf == 1) {
cf = 0;
a31 = 13;
a53 = 5;
a188 = a188 * a37 % 14999 * 2 % 86 - - 197 + - 17826 - - 17826;
a37 = a37 * a105 % 14999 * 2 % 15017 - 14981 + - 2;
output = 19;
}
}
}
}
if (cf == 1 && (372 < a49 && 445 >= a49)) {
if (a118 == 4 && cf == 1) {{
if (input == 2 && cf == 1) {
cf = 0;
a62 = 7;
a80 = (a80 * a105 % 14999 + - 8776) / 5 % 40 + 191;
a52_0 = 98;
a52_1 = 99;
a52_2 = 100;
a52_3 = 101;
a52_4 = 102;
a52_5 = 103;
a37 = (a37 * a37 % 14999 + 3000) % 24 - - 215 + - 872 - - 871;
output = 23;
}
}
}
}
}
}
if (cf == 1 && (5 < a105 && 198 >= a105)) {{
if (70 < a74 && 142 >= a74 && cf == 1) {
if (cf == 1 && a187 == 8) {{
if (input == 3 && cf == 1) {
cf = 0;
a173 = 9;
a1 = 6;
a71 = 13;
a37 = (a37 * a74 + 1568) * 1 + 268;
output = 26;
}
if (input == 2 && cf == 1) {
cf = 0;
a122 = 5;
a35 = 8;
a52_0 = 110;
a52_1 = 111;
a52_2 = 112;
a52_3 = 113;
a52_4 = 114;
a52_5 = 115;
a37 = (a37 * a105 % 14999 - - 6360) % 24 + 210 - - 29013 - 29022;
output = 26;
}
if (cf == 1 && input == 4) {
cf = 0;
a8 = 2;
a94 = 11;
a52_0 = 104;
a52_1 = 105;
a52_2 = 106;
a52_3 = 107;
a52_4 = 108;
a52_5 = 109;
a37 = (a37 * a74 + - 2932) * 1 % 24 - - 222;
output = 26;
}
if (cf == 1 && input == 1) {
cf = 0;
a111 = (a111 * a105 % 14999 % 14852 - - 15146) / 5 + 16346;
a167 = 13;
a105 = (a105 * a74 - 30059) * 1 - - 8433 + - 7675;
output = 19;
}
if (cf == 1 && input == 5) {
cf = 0;
a198 = (a198 * a105 % 14999 + - 7209 - 713) * 1 % 79 - - 8;
a15_0 = 19;
a15_1 = 20;
a15_2 = 21;
a15_3 = 22;
a15_4 = 23;
a15_5 = 24;
a71 = 11;
a37 = (a37 * a105 % 14999 + 7260) * 1 * 1;
output = 19;
}
}
}
}
}
}
if (cf == 1 && 198 < a105) {{
if (cf == 1 && a194 == 6) {
if (a116 == 8 && cf == 1) {{
if (cf == 1 && input == 3) {
cf = 0;
a26 = 9;
a94 = 13;
a52_0 = 104;
a52_1 = 105;
a52_2 = 106;
a52_3 = 107;
a52_4 = 108;
a52_5 = 109;
a37 = (a37 * a37 % 14999 - - 4583 + - 16089 + 22684) % 24 + 212;
output = 23;
}
if (cf == 1 && input == 1) {
cf = 0;
a118 = 7;
a80 = (a80 * a37 % 14999 % 30 - - 118) * 1 + 0;
a188 = (a188 * a105 % 14999 % 14960 + - 15038) / 5 - 1714;
a37 = (a37 * a37 % 14999 + - 25480) * 1 - 234;
output = 26;
}
if (input == 2 && cf == 1) {
cf = 0;
a35 = 8;
a167 = 6;
a105 = (a105 * a105 % 14999 + - 20624) * 1 * 10 / 9;
output = 22;
}
if (cf == 1 && input == 4) {
cf = 0;
a125_0 = 100;
a125_1 = 101;
a125_2 = 102;
a125_3 = 103;
a125_4 = 104;
a125_5 = 105;
a74 = (a74 * a105 % 14999 - 13058 + 5534) % 35 + 106;
a71 = 14;
a37 = (a37 * a37 % 14999 - - 13014 - - 893) / 5;
output = 20;
}
if (cf == 1 && input == 5) {
cf = 0;
a122 = 5;
a101_0 = 31;
a101_1 = 32;
a101_2 = 33;
a101_3 = 34;
a101_4 = 35;
a101_5 = 36;
a188 = (a188 * a105 % 14999 + - 13683) % 94 + 17 + 5592 + - 5593;
a37 = (a37 * a105 % 14999 / 5 - - 12593) / - 5;
output = 26;
}
}
}
}
}
}
}
if (cf == 1 && (198 < a37 && 247 >= a37)) {
if (cf == 1 && 98 == a52_0) {{
if (cf == 1 && a80 <= 88) {
if (a119 == 7 && cf == 1) {{
if (input == 4 && cf == 1) {
cf = 0;
a122 = 5;
a35 = 8;
a52_0 = 110;
a52_1 = 111;
a52_2 = 112;
a52_3 = 113;
a52_4 = 114;
a52_5 = 115;
output = 26;
}
}
}
}
if (150 < a80 && 232 >= a80 && cf == 1) {
if (a62 == 7 && cf == 1) {{
if (cf == 1 && input == 2) {
cf = 0;
a86 = 9;
a183_0 = 99;
a183_1 = 100;
a183_2 = 101;
a183_3 = 102;
a183_4 = 103;
a183_5 = 104;
a188 = a188 * a80 % 14999 / 5 + 25434 - 27546 - - 6590;
a37 = (a37 * a80 % 14999 + - 2722 + 2736) * 1 + - 17395;
output = 23;
}
}
}
}
}
}
if (108 == a52_4 && cf == 1) {{
if (a94 == 11 && cf == 1) {
if (a8 == 2 && cf == 1) {{
if (input == 1 && cf == 1) {
cf = 0;
output = 21;
}
if (input == 5 && cf == 1) {
cf = 0;
a111 = a111 * a37 % 14999 % 14953 - 15046 - - 9546 + - 9546;
a167 = 13;
a105 = (a105 * a37 % 14999 * 2 + - 2 + 3) % 14906 + - 15093;
a37 = (a37 * a37 % 14999 % 81 + 66) * 9 / 10 * 5 % 81 + 78;
output = 24;
}
if (input == 2 && cf == 1) {
cf = 0;
output = 21;
}
if (cf == 1 && input == 3) {
cf = 0;
a158 = 5;
a94 = 15;
output = 23;
}
if (cf == 1 && input == 4) {
cf = 0;
output = 21;
}
}
}
}
}
}
if (115 == a52_5 && cf == 1) {{
if (a35 == 6 && cf == 1) {
if (cf == 1 && a50 == 9) {{
if (input == 2 && cf == 1) {
cf = 0;
a187 = 8;
a74 = (a74 * a37 % 14999 / 5 - 21879) % 35 + 116;
a105 = (a105 * a37 % 14999 + 620) % 96 + 101 + 0;
a37 = (a37 * a37 % 14999 % 81 - - 63) * 10 / 9 * 9 / 10;
output = 26;
}
}
}
}
if (a35 == 8 && cf == 1) {
if (a122 == 5 && cf == 1) {{
if (input == 2 && cf == 1) {
cf = 0;
a50 = 9;
a35 = 6;
output = 23;
}
}
}
}
}
}
}
if (cf == 1 && 247 < a37) {
if (a71 == 7 && cf == 1) {{
if (169 < a42 && 339 >= a42 && cf == 1) {
if (cf == 1 && a68 == 12) {{
if (input == 2 && cf == 1) {
cf = 0;
a119 = 7;
a80 = a80 * a37 % 14999 - 14972 - 28 - 1;
a52_0 = 98;
a52_1 = 99;
a52_2 = 100;
a52_3 = 101;
a52_4 = 102;
a52_5 = 103;
a37 = (a37 * a42 % 14999 - - 6640) * 1 % 24 + 212;
output = 19;
}
if (input == 1 && cf == 1) {
cf = 0;
a89 = 9;
a183_0 = 87;
a183_1 = 88;
a183_2 = 89;
a183_3 = 90;
a183_4 = 91;
a183_5 = 92;
a188 = a188 * a42 % 14999 / 5 - - 15466 - - 10297;
a37 = (a37 * a42 % 14999 + - 1633) / 5 * 5 - 22904;
output = 21;
}
if (cf == 1 && input == 4) {
cf = 0;
a125_0 = 100;
a125_1 = 101;
a125_2 = 102;
a125_3 = 103;
a125_4 = 104;
a125_5 = 105;
a74 = (a74 * a37 % 14999 / 5 + 17394 + 6778) % 35 - - 74;
a71 = 14;
output = 22;
}
}
}
}
if (339 < a42 && cf == 1) {
if (a8 == 4 && cf == 1) {{
if (cf == 1 && input == 2) {
cf = 0;
a42 = (a42 * a42 % 14999 + - 8520 + - 12295) * 1;
a49 = (a49 * a37 % 14999 + - 15001 + - 1) * 1;
a105 = a105 * a37 % 14999 % 96 + - 91 + 1 - 1;
a37 = (a37 * a37 % 14999 / 5 - - 14015) % 81 + 60;
output = 24;
}
if (cf == 1 && input == 1) {
cf = 0;
a119 = 11;
a68 = 13;
a71 = 10;
output = 25;
}
if (input == 3 && cf == 1) {
cf = 0;
a118 = 6;
a80 = a80 * a37 % 14999 % 30 + 119 + - 1 + 3;
a188 = (a188 * a37 % 14999 - - 488) / 5 / 5 - 24569;
a37 = a37 * a37 % 14999 - 19576 - 4282 + - 3073;
output = 26;
}
}
}
}
}
}
if (cf == 1 && a71 == 10) {{
if (cf == 1 && a68 == 13) {
if (a119 == 11 && cf == 1) {{
if (input == 1 && cf == 1) {
cf = 0;
a167 = 7;
a105 = (a105 * a37 % 14999 % 14906 - 15093) * 1 + - 1;
a37 = a37 * a37 % 14999 % 81 - - 91 - 24 + - 2685 + 2708;
output = 24;
}
}
}
}
}
}
if (cf == 1 && a71 == 11) {{
if (cf == 1 && 32 == a15_1) {
if (10 == 10 && cf == 1) {{
if (cf == 1 && input == 4) {
cf = 0;
a119 = 9;
a80 = (a80 * a37 % 14999 + - 14929) / 5 - 10615;
a52_0 = 98;
a52_1 = 99;
a52_2 = 100;
a52_3 = 101;
a52_4 = 102;
a52_5 = 103;
a37 = a37 * a37 % 14999 % 24 + 210 + 999 + 10185 + - 11183;
output = 26;
}
if (input == 3 && cf == 1) {
cf = 0;
a80 = (a80 * a37 % 14999 * 2 - 0) % 14883 + 15115;
a188 = (a188 * a37 % 14999 % 14960 - 15038 + - 1) * 1;
a37 = (a37 * a37 % 14999 / 5 - 9877) * 3;
output = 24;
}
if (input == 2 && cf == 1) {
cf = 0;
output = 22;
}
if (input == 1 && cf == 1) {
cf = 0;
output = 22;
}
if (cf == 1 && input == 5) {
cf = 0;
a86 = 10;
a183_0 = 99;
a183_1 = 100;
a183_2 = 101;
a183_3 = 102;
a183_4 = 103;
a183_5 = 104;
a188 = (a188 * a37 % 14999 + - 5931 - 6065) % 14857 + 15142;
a37 = (a37 * a37 % 14999 - - 2983 - 31207) * 1;
output = 24;
}
}
}
}
}
}
if (a71 == 14 && cf == 1) {{
if (70 < a74 && 142 >= a74 && cf == 1) {
if (102 == a125_2 && cf == 1) {{
if (input == 4 && cf == 1) {
cf = 0;
a35 = 8;
a167 = 6;
a105 = a105 * a74 % 14999 * 2 % 14906 - 15093 + - 2;
a37 = (a37 * a74 % 14999 / 5 + - 14205) % 81 + 167;
output = 22;
}
if (cf == 1 && input == 2) {
cf = 0;
a118 = 4;
a49 = a49 * a37 % 14999 * 2 / 5 % 36 + 409;
a105 = a105 * a37 % 14999 % 96 + - 91 - - 1 + - 1;
a37 = (a37 * a74 % 14999 / 5 / 5 - - 2265) % 81 + 110;
output = 26;
}
}
}
}
}
}
}
{
if (8 == 6 && 304 < a74 && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_0:
!1?((void )0) : __assert_fail("!error_0","Problem1403_mod_global_in_out.c",230,__PRETTY_FUNCTION__);
}
if (8 == 3 && a194 == 10 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_1:
!1?((void )0) : __assert_fail("!error_1","Problem1403_mod_global_in_out.c",234,__PRETTY_FUNCTION__);
}
if (a67 == 8 && a167 == 8 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_2:
!1?((void )0) : __assert_fail("!error_2","Problem1403_mod_global_in_out.c",238,__PRETTY_FUNCTION__);
}
if (a62 == 1 && (150 < a80 && 232 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_3:
!1?((void )0) : __assert_fail("!error_3","Problem1403_mod_global_in_out.c",242,__PRETTY_FUNCTION__);
}
if (11 == 7 && 41 == a101_4 && (- 79 < a188 && 111 >= a188) && a37 <= 35) {
cf = 0;
error_4:
!1?((void )0) : __assert_fail("!error_4","Problem1403_mod_global_in_out.c",246,__PRETTY_FUNCTION__);
}
if (a89 == 15 && 89 == a183_2 && 285 < a188 && a37 <= 35) {
cf = 0;
error_5:
!1?((void )0) : __assert_fail("!error_5","Problem1403_mod_global_in_out.c",250,__PRETTY_FUNCTION__);
}
if (a187 == 4 && (70 < a74 && 142 >= a74) && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_6:
!1?((void )0) : __assert_fail("!error_6","Problem1403_mod_global_in_out.c",254,__PRETTY_FUNCTION__);
}
if (25 == a101_0 && a74 <= 70 && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_7:
!1?((void )0) : __assert_fail("!error_7","Problem1403_mod_global_in_out.c",258,__PRETTY_FUNCTION__);
}
if (a119 == 12 && a68 == 13 && a71 == 10 && 247 < a37) {
cf = 0;
error_8:
!1?((void )0) : __assert_fail("!error_8","Problem1403_mod_global_in_out.c",262,__PRETTY_FUNCTION__);
}
if (a194 == 6 && a167 == 11 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_9:
!1?((void )0) : __assert_fail("!error_9","Problem1403_mod_global_in_out.c",266,__PRETTY_FUNCTION__);
}
if (a94 == 9 && 9 == 7 && a71 == 12 && 247 < a37) {
cf = 0;
error_10:
!1?((void )0) : __assert_fail("!error_10","Problem1403_mod_global_in_out.c",270,__PRETTY_FUNCTION__);
}
if (108 == a52_4 && a68 == 15 && a71 == 10 && 247 < a37) {
cf = 0;
error_11:
!1?((void )0) : __assert_fail("!error_11","Problem1403_mod_global_in_out.c",274,__PRETTY_FUNCTION__);
}
if (a194 == 9 && a167 == 11 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_12:
!1?((void )0) : __assert_fail("!error_12","Problem1403_mod_global_in_out.c",278,__PRETTY_FUNCTION__);
}
if (a68 == 10 && (169 < a42 && 339 >= a42) && a71 == 7 && 247 < a37) {
cf = 0;
error_13:
!1?((void )0) : __assert_fail("!error_13","Problem1403_mod_global_in_out.c",282,__PRETTY_FUNCTION__);
}
if (11 == 13 && 41 == a101_4 && (- 79 < a188 && 111 >= a188) && a37 <= 35) {
cf = 0;
error_14:
!1?((void )0) : __assert_fail("!error_14","Problem1403_mod_global_in_out.c",286,__PRETTY_FUNCTION__);
}
if (a68 == 13 && 9 == 11 && a71 == 12 && 247 < a37) {
cf = 0;
error_15:
!1?((void )0) : __assert_fail("!error_15","Problem1403_mod_global_in_out.c",290,__PRETTY_FUNCTION__);
}
if (a158 == 11 && a94 == 15 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_16:
!1?((void )0) : __assert_fail("!error_16","Problem1403_mod_global_in_out.c",294,__PRETTY_FUNCTION__);
}
if (a1 == 6 && (142 < a74 && 304 >= a74) && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_17:
!1?((void )0) : __assert_fail("!error_17","Problem1403_mod_global_in_out.c",298,__PRETTY_FUNCTION__);
}
if (2 == 2 && 10 == 9 && a71 == 9 && 247 < a37) {
cf = 0;
error_18:
!1?((void )0) : __assert_fail("!error_18","Problem1403_mod_global_in_out.c",302,__PRETTY_FUNCTION__);
}
if (a86 == 12 && 100 == a183_1 && 285 < a188 && a37 <= 35) {
cf = 0;
error_19:
!1?((void )0) : __assert_fail("!error_19","Problem1403_mod_global_in_out.c",306,__PRETTY_FUNCTION__);
}
if (a86 == 8 && 100 == a183_1 && 285 < a188 && a37 <= 35) {
cf = 0;
error_20:
!1?((void )0) : __assert_fail("!error_20","Problem1403_mod_global_in_out.c",310,__PRETTY_FUNCTION__);
}
if (28 == 28 && 232 < a80 && a188 <= - 79 && a37 <= 35) {
cf = 0;
error_21:
!1?((void )0) : __assert_fail("!error_21","Problem1403_mod_global_in_out.c",314,__PRETTY_FUNCTION__);
}
if (45 == 57 && a1 == 8 && a71 == 13 && 247 < a37) {
cf = 0;
error_22:
!1?((void )0) : __assert_fail("!error_22","Problem1403_mod_global_in_out.c",318,__PRETTY_FUNCTION__);
}
if (22 == 28 && a194 == 8 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_23:
!1?((void )0) : __assert_fail("!error_23","Problem1403_mod_global_in_out.c",322,__PRETTY_FUNCTION__);
}
if (9 == 7 && (88 < a80 && 150 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_24:
!1?((void )0) : __assert_fail("!error_24","Problem1403_mod_global_in_out.c",326,__PRETTY_FUNCTION__);
}
if (a74 <= 70 && (71 < a42 && 169 >= a42) && a71 == 7 && 247 < a37) {
cf = 0;
error_25:
!1?((void )0) : __assert_fail("!error_25","Problem1403_mod_global_in_out.c",330,__PRETTY_FUNCTION__);
}
if (a122 == 5 && 33 == a101_2 && (- 79 < a188 && 111 >= a188) && a37 <= 35) {
cf = 0;
error_26:
!1?((void )0) : __assert_fail("!error_26","Problem1403_mod_global_in_out.c",334,__PRETTY_FUNCTION__);
}
if (14 == 10 && 101 == 107 && a71 == 8 && 247 < a37) {
cf = 0;
error_27:
!1?((void )0) : __assert_fail("!error_27","Problem1403_mod_global_in_out.c",338,__PRETTY_FUNCTION__);
}
if (- 9 < -5 && 62 >= -5 && a1 == 10 && a71 == 13 && 247 < a37) {
cf = 0;
error_28:
!1?((void )0) : __assert_fail("!error_28","Problem1403_mod_global_in_out.c",342,__PRETTY_FUNCTION__);
}
if (9 == 13 && (88 < a80 && 150 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_29:
!1?((void )0) : __assert_fail("!error_29","Problem1403_mod_global_in_out.c",346,__PRETTY_FUNCTION__);
}
if (64 == 64 && a194 == 7 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_30:
!1?((void )0) : __assert_fail("!error_30","Problem1403_mod_global_in_out.c",350,__PRETTY_FUNCTION__);
}
if (a8 == 2 && 339 < a42 && a71 == 7 && 247 < a37) {
cf = 0;
error_31:
!1?((void )0) : __assert_fail("!error_31","Problem1403_mod_global_in_out.c",354,__PRETTY_FUNCTION__);
}
if (a68 == 15 && 9 == 11 && a71 == 12 && 247 < a37) {
cf = 0;
error_32:
!1?((void )0) : __assert_fail("!error_32","Problem1403_mod_global_in_out.c",358,__PRETTY_FUNCTION__);
}
if (383 < 64 && a167 == 12 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_33:
!1?((void )0) : __assert_fail("!error_33","Problem1403_mod_global_in_out.c",362,__PRETTY_FUNCTION__);
}
if (a94 == 8 && 9 == 7 && a71 == 12 && 247 < a37) {
cf = 0;
error_34:
!1?((void )0) : __assert_fail("!error_34","Problem1403_mod_global_in_out.c",366,__PRETTY_FUNCTION__);
}
if (a194 == 10 && a167 == 11 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_35:
!1?((void )0) : __assert_fail("!error_35","Problem1403_mod_global_in_out.c",370,__PRETTY_FUNCTION__);
}
if (89 < 98 && a94 == 10 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_36:
!1?((void )0) : __assert_fail("!error_36","Problem1403_mod_global_in_out.c",374,__PRETTY_FUNCTION__);
}
if (a86 == 10 && 100 == a183_1 && 285 < a188 && a37 <= 35) {
cf = 0;
error_37:
!1?((void )0) : __assert_fail("!error_37","Problem1403_mod_global_in_out.c",378,__PRETTY_FUNCTION__);
}
if (8 == 6 && a194 == 10 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_38:
!1?((void )0) : __assert_fail("!error_38","Problem1403_mod_global_in_out.c",382,__PRETTY_FUNCTION__);
}
if (a173 == 12 && a68 == 11 && a71 == 10 && 247 < a37) {
cf = 0;
error_39:
!1?((void )0) : __assert_fail("!error_39","Problem1403_mod_global_in_out.c",386,__PRETTY_FUNCTION__);
}
if (a50 == 11 && a35 == 12 && 115 == a52_5 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_40:
!1?((void )0) : __assert_fail("!error_40","Problem1403_mod_global_in_out.c",390,__PRETTY_FUNCTION__);
}
if (13 == 11 && a194 == 12 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_41:
!1?((void )0) : __assert_fail("!error_41","Problem1403_mod_global_in_out.c",394,__PRETTY_FUNCTION__);
}
if (a173 == 10 && a35 == 10 && 115 == a52_5 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_42:
!1?((void )0) : __assert_fail("!error_42","Problem1403_mod_global_in_out.c",398,__PRETTY_FUNCTION__);
}
if (0 == 1 && a53 == 2 && (111 < a188 && 285 >= a188) && a37 <= 35) {
cf = 0;
error_43:
!1?((void )0) : __assert_fail("!error_43","Problem1403_mod_global_in_out.c",402,__PRETTY_FUNCTION__);
}
if (294 < a111 && a167 == 13 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_44:
!1?((void )0) : __assert_fail("!error_44","Problem1403_mod_global_in_out.c",406,__PRETTY_FUNCTION__);
}
if (8 == 9 && a1 == 12 && a71 == 13 && 247 < a37) {
cf = 0;
error_45:
!1?((void )0) : __assert_fail("!error_45","Problem1403_mod_global_in_out.c",410,__PRETTY_FUNCTION__);
}
if (99 < 25 && a94 == 12 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_46:
!1?((void )0) : __assert_fail("!error_46","Problem1403_mod_global_in_out.c",414,__PRETTY_FUNCTION__);
}
if (2 == 1 && 10 == 3 && a71 == 9 && 247 < a37) {
cf = 0;
error_47:
!1?((void )0) : __assert_fail("!error_47","Problem1403_mod_global_in_out.c",418,__PRETTY_FUNCTION__);
}
if (10 < 64 && 163 >= 64 && a167 == 12 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_48:
!1?((void )0) : __assert_fail("!error_48","Problem1403_mod_global_in_out.c",422,__PRETTY_FUNCTION__);
}
if (15 == 27 && 232 < a80 && a188 <= - 79 && a37 <= 35) {
cf = 0;
error_49:
!1?((void )0) : __assert_fail("!error_49","Problem1403_mod_global_in_out.c",426,__PRETTY_FUNCTION__);
}
if (8 == 9 && a194 == 10 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_50:
!1?((void )0) : __assert_fail("!error_50","Problem1403_mod_global_in_out.c",430,__PRETTY_FUNCTION__);
}
if (a119 == 9 && a80 <= 88 && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_51:
!1?((void )0) : __assert_fail("!error_51","Problem1403_mod_global_in_out.c",434,__PRETTY_FUNCTION__);
}
if (a119 == 14 && a68 == 13 && a71 == 10 && 247 < a37) {
cf = 0;
error_52:
!1?((void )0) : __assert_fail("!error_52","Problem1403_mod_global_in_out.c",438,__PRETTY_FUNCTION__);
}
if (15 == 10 && a53 == 1 && (111 < a188 && 285 >= a188) && a37 <= 35) {
cf = 0;
error_53:
!1?((void )0) : __assert_fail("!error_53","Problem1403_mod_global_in_out.c",442,__PRETTY_FUNCTION__);
}
if (a8 == 6 && 339 < a42 && a71 == 7 && 247 < a37) {
cf = 0;
error_54:
!1?((void )0) : __assert_fail("!error_54","Problem1403_mod_global_in_out.c",446,__PRETTY_FUNCTION__);
}
if (a1 == 11 && (142 < a74 && 304 >= a74) && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_55:
!1?((void )0) : __assert_fail("!error_55","Problem1403_mod_global_in_out.c",450,__PRETTY_FUNCTION__);
}
if (a122 == 1 && a35 == 8 && 115 == a52_5 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_56:
!1?((void )0) : __assert_fail("!error_56","Problem1403_mod_global_in_out.c",454,__PRETTY_FUNCTION__);
}
if (14 == 15 && 101 == 107 && a71 == 8 && 247 < a37) {
cf = 0;
error_57:
!1?((void )0) : __assert_fail("!error_57","Problem1403_mod_global_in_out.c",458,__PRETTY_FUNCTION__);
}
if (a8 == 7 && 339 < a42 && a71 == 7 && 247 < a37) {
cf = 0;
error_58:
!1?((void )0) : __assert_fail("!error_58","Problem1403_mod_global_in_out.c",462,__PRETTY_FUNCTION__);
}
if (13 == 13 && 9 == 14 && a71 == 12 && 247 < a37) {
cf = 0;
error_59:
!1?((void )0) : __assert_fail("!error_59","Problem1403_mod_global_in_out.c",466,__PRETTY_FUNCTION__);
}
if (a122 == 7 && a35 == 8 && 115 == a52_5 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_60:
!1?((void )0) : __assert_fail("!error_60","Problem1403_mod_global_in_out.c",470,__PRETTY_FUNCTION__);
}
if (a173 == 9 && (142 < a74 && 304 >= a74) && a71 == 14 && 247 < a37) {
cf = 0;
error_61:
!1?((void )0) : __assert_fail("!error_61","Problem1403_mod_global_in_out.c",474,__PRETTY_FUNCTION__);
}
if (a35 == 13 && 106 == 106 && a71 == 8 && 247 < a37) {
cf = 0;
error_62:
!1?((void )0) : __assert_fail("!error_62","Problem1403_mod_global_in_out.c",478,__PRETTY_FUNCTION__);
}
if (a89 == 11 && 89 == a183_2 && 285 < a188 && a37 <= 35) {
cf = 0;
error_63:
!1?((void )0) : __assert_fail("!error_63","Problem1403_mod_global_in_out.c",482,__PRETTY_FUNCTION__);
}
if (- 71 < a198 && 88 >= a198 && 24 == a15_5 && a71 == 11 && 247 < a37) {
cf = 0;
error_64:
!1?((void )0) : __assert_fail("!error_64","Problem1403_mod_global_in_out.c",486,__PRETTY_FUNCTION__);
}
if (a35 == 10 && a167 == 6 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_65:
!1?((void )0) : __assert_fail("!error_65","Problem1403_mod_global_in_out.c",490,__PRETTY_FUNCTION__);
}
if (a173 == 10 && a167 == 9 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_66:
!1?((void )0) : __assert_fail("!error_66","Problem1403_mod_global_in_out.c",494,__PRETTY_FUNCTION__);
}
if (a62 == 5 && (150 < a80 && 232 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_67:
!1?((void )0) : __assert_fail("!error_67","Problem1403_mod_global_in_out.c",498,__PRETTY_FUNCTION__);
}
if (a62 == 4 && a35 == 7 && 115 == a52_5 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_68:
!1?((void )0) : __assert_fail("!error_68","Problem1403_mod_global_in_out.c",502,__PRETTY_FUNCTION__);
}
if (- 94 < a111 && 97 >= a111 && a167 == 13 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_69:
!1?((void )0) : __assert_fail("!error_69","Problem1403_mod_global_in_out.c",506,__PRETTY_FUNCTION__);
}
if (8 == 12 && 304 < a74 && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_70:
!1?((void )0) : __assert_fail("!error_70","Problem1403_mod_global_in_out.c",510,__PRETTY_FUNCTION__);
}
if (383 < 64 && 27 == a15_2 && a71 == 11 && 247 < a37) {
cf = 0;
error_71:
!1?((void )0) : __assert_fail("!error_71","Problem1403_mod_global_in_out.c",514,__PRETTY_FUNCTION__);
}
if (a173 == 15 && a68 == 11 && a71 == 10 && 247 < a37) {
cf = 0;
error_72:
!1?((void )0) : __assert_fail("!error_72","Problem1403_mod_global_in_out.c",518,__PRETTY_FUNCTION__);
}
if (13 == 10 && a194 == 5 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_73:
!1?((void )0) : __assert_fail("!error_73","Problem1403_mod_global_in_out.c",522,__PRETTY_FUNCTION__);
}
if (a173 == 9 && a1 == 6 && a71 == 13 && 247 < a37) {
cf = 0;
error_74:
!1?((void )0) : __assert_fail("!error_74","Problem1403_mod_global_in_out.c",526,__PRETTY_FUNCTION__);
}
if (9 == 8 && (88 < a80 && 150 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_75:
!1?((void )0) : __assert_fail("!error_75","Problem1403_mod_global_in_out.c",530,__PRETTY_FUNCTION__);
}
if (62 < -5 && 159 >= -5 && a1 == 10 && a71 == 13 && 247 < a37) {
cf = 0;
error_76:
!1?((void )0) : __assert_fail("!error_76","Problem1403_mod_global_in_out.c",534,__PRETTY_FUNCTION__);
}
if (13 == 8 && a194 == 5 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_77:
!1?((void )0) : __assert_fail("!error_77","Problem1403_mod_global_in_out.c",538,__PRETTY_FUNCTION__);
}
if (45 == 57 && a42 <= 71 && a71 == 7 && 247 < a37) {
cf = 0;
error_78:
!1?((void )0) : __assert_fail("!error_78","Problem1403_mod_global_in_out.c",542,__PRETTY_FUNCTION__);
}
if (a158 == 10 && a94 == 15 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_79:
!1?((void )0) : __assert_fail("!error_79","Problem1403_mod_global_in_out.c",546,__PRETTY_FUNCTION__);
}
if (a94 == 11 && 9 == 7 && a71 == 12 && 247 < a37) {
cf = 0;
error_80:
!1?((void )0) : __assert_fail("!error_80","Problem1403_mod_global_in_out.c",550,__PRETTY_FUNCTION__);
}
if (a116 == 7 && a194 == 6 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_81:
!1?((void )0) : __assert_fail("!error_81","Problem1403_mod_global_in_out.c",554,__PRETTY_FUNCTION__);
}
if (a111 <= - 94 && a167 == 13 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_82:
!1?((void )0) : __assert_fail("!error_82","Problem1403_mod_global_in_out.c",558,__PRETTY_FUNCTION__);
}
if (a118 == 3 && (88 < a80 && 150 >= a80) && a188 <= - 79 && a37 <= 35) {
cf = 0;
error_83:
!1?((void )0) : __assert_fail("!error_83","Problem1403_mod_global_in_out.c",562,__PRETTY_FUNCTION__);
}
if (2 == 7 && 10 == 9 && a71 == 9 && 247 < a37) {
cf = 0;
error_84:
!1?((void )0) : __assert_fail("!error_84","Problem1403_mod_global_in_out.c",566,__PRETTY_FUNCTION__);
}
if (a194 == 8 && a167 == 11 && a105 <= - 188 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_85:
!1?((void )0) : __assert_fail("!error_85","Problem1403_mod_global_in_out.c",570,__PRETTY_FUNCTION__);
}
if (a26 == 9 && a94 == 13 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_86:
!1?((void )0) : __assert_fail("!error_86","Problem1403_mod_global_in_out.c",574,__PRETTY_FUNCTION__);
}
if (- 94 < a111 && 97 >= a111 && 9 == 10 && a71 == 12 && 247 < a37) {
cf = 0;
error_87:
!1?((void )0) : __assert_fail("!error_87","Problem1403_mod_global_in_out.c",578,__PRETTY_FUNCTION__);
}
if (2 == 5 && 9 == 9 && a71 == 12 && 247 < a37) {
cf = 0;
error_88:
!1?((void )0) : __assert_fail("!error_88","Problem1403_mod_global_in_out.c",582,__PRETTY_FUNCTION__);
}
if (71 < a42 && 169 >= a42 && a49 <= 153 && (- 188 < a105 && 5 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_89:
!1?((void )0) : __assert_fail("!error_89","Problem1403_mod_global_in_out.c",586,__PRETTY_FUNCTION__);
}
if (a173 == 14 && (142 < a74 && 304 >= a74) && a71 == 14 && 247 < a37) {
cf = 0;
error_90:
!1?((void )0) : __assert_fail("!error_90","Problem1403_mod_global_in_out.c",590,__PRETTY_FUNCTION__);
}
if (a158 == 5 && a94 == 15 && 108 == a52_4 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_91:
!1?((void )0) : __assert_fail("!error_91","Problem1403_mod_global_in_out.c",594,__PRETTY_FUNCTION__);
}
if (62 < -5 && 159 >= -5 && 10 == 10 && a71 == 9 && 247 < a37) {
cf = 0;
error_92:
!1?((void )0) : __assert_fail("!error_92","Problem1403_mod_global_in_out.c",598,__PRETTY_FUNCTION__);
}
if (a53 == 6 && 232 < a80 && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_93:
!1?((void )0) : __assert_fail("!error_93","Problem1403_mod_global_in_out.c",602,__PRETTY_FUNCTION__);
}
if (a116 == 5 && a194 == 6 && 198 < a105 && (35 < a37 && 198 >= a37)) {
cf = 0;
error_94:
!1?((void )0) : __assert_fail("!error_94","Problem1403_mod_global_in_out.c",606,__PRETTY_FUNCTION__);
}
if (a187 == 7 && (70 < a74 && 142 >= a74) && (5 < a105 && 198 >= a105) && (35 < a37 && 198 >= a37)) {
cf = 0;
error_95:
!1?((void )0) : __assert_fail("!error_95","Problem1403_mod_global_in_out.c",610,__PRETTY_FUNCTION__);
}
if (14 == 11 && 101 == 107 && a71 == 8 && 247 < a37) {
cf = 0;
error_96:
!1?((void )0) : __assert_fail("!error_96","Problem1403_mod_global_in_out.c",614,__PRETTY_FUNCTION__);
}
if (a62 == 2 && (150 < a80 && 232 >= a80) && 98 == a52_0 && (198 < a37 && 247 >= a37)) {
cf = 0;
error_97:
!1?((void )0) : __assert_fail("!error_97","Problem1403_mod_global_in_out.c",618,__PRETTY_FUNCTION__);
}
if (0 == 7 && 10 == 5 && a71 == 9 && 247 < a37) {
cf = 0;
error_98:
!1?((void )0) : __assert_fail("!error_98","Problem1403_mod_global_in_out.c",622,__PRETTY_FUNCTION__);
}
if (13 == 8 && 9 == 14 && a71 == 12 && 247 < a37) {
cf = 0;
error_99:
!1?((void )0) : __assert_fail("!error_99","Problem1403_mod_global_in_out.c",626,__PRETTY_FUNCTION__);
}
}
if (cf == 1) {
output = - 2;
}
}
//edited by script: global output variable replacing printf in functions
if (output == - 2) {
fprintf(stderr,"Invalid input: %d\n",input);
}
else {
if (output != - 1) {
printf("%d\n",output);
}
}
}
}
| 36.601602 | 111 | 0.386258 |
9ac2be13794bc14c8e9ceaf9cfaaf56e76f8ffa9 | 1,837 | h | C | Engine/include/shader.h | julienbernat/dmri-explorer | 32639916b0a95ecc2ae7484f9e1a084f84c3035a | [
"MIT"
] | null | null | null | Engine/include/shader.h | julienbernat/dmri-explorer | 32639916b0a95ecc2ae7484f9e1a084f84c3035a | [
"MIT"
] | null | null | null | Engine/include/shader.h | julienbernat/dmri-explorer | 32639916b0a95ecc2ae7484f9e1a084f84c3035a | [
"MIT"
] | null | null | null | #pragma once
#include <glad/glad.h>
#include <string>
#include <vector>
namespace Slicer
{
namespace GPU
{
/// \brief Class describing a shader program.
///
/// Associated with a shader.
class ShaderProgram
{
public:
/// Default constructor.
ShaderProgram() = default;
/// Constructor.
/// \param[in] filepath Path to shader code.
/// \param[in] shaderType Type for the shader.
ShaderProgram(const std::string& filepath, const GLenum shaderType);
/// Shader program ID getter.
/// \return Program ID.
inline const GLuint ID() const { return mProgramID; };
/// Shader program type getter.
/// \return Shader type.
inline const GLenum Type() const { return mShaderType; };
private:
/// Program ID.
GLuint mProgramID = 0;
/// Shader type.
GLenum mShaderType = 0;
};
/// A collection of ShaderProgram describing a render pipeline.
class ProgramPipeline
{
public:
/// Default constructor.
ProgramPipeline() = default;
/// Constructor.
/// \param[in] shaderPrograms Programs making up the pipeline.
ProgramPipeline(const std::vector<ShaderProgram>& shaderPrograms);
/// Constructor.
/// \param[in] shaderProgram Program making up the pipeline.
ProgramPipeline(const ShaderProgram& shaderProgram);
/// Get the pipeline ID.
/// \return Pipeline ID.
inline const GLuint ID() const { return mPipelineID; };
/// Bind the pipeline to the GPU.
void Bind() const;
private:
/// Helper function for converting shader type to GL bit field.
/// \param[in] shaderType Type of a shader.
/// \return Corresponding GLbitfield value.
const GLbitfield convertShaderTypeToGLbitfield(const GLenum shaderType) const;
/// Pipeline identifier.
GLuint mPipelineID = 0;
};
} // namespace GPU
} // namespace Slicer
| 24.824324 | 82 | 0.676647 |
82ef207e049049f6f862349c493bd4d6794419dd | 1,300 | c | C | driver_test.c | shirishbahirat/my-uefi | 2002873ba67478c04541e52a9d3dba9516b30c0f | [
"Apache-2.0"
] | null | null | null | driver_test.c | shirishbahirat/my-uefi | 2002873ba67478c04541e52a9d3dba9516b30c0f | [
"Apache-2.0"
] | null | null | null | driver_test.c | shirishbahirat/my-uefi | 2002873ba67478c04541e52a9d3dba9516b30c0f | [
"Apache-2.0"
] | null | null | null | #include "efi.h"
#include "log.h"
EFI_STATUS EFIAPI DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);
EFI_STATUS efi_main(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable)
{
EFI_STATUS Status;
EFI_INPUT_KEY Key;
if (SystemTable != NULL)
info(SystemTable, L"System table is loaded ...\r\n");
if (SystemTable->BootServices != NULL)
info(SystemTable, L"Boot service table loaded...\r\n");
if (SystemTable->RuntimeServices != NULL)
info(SystemTable, L"Run time service table is loaded...\r\n");
DriverEntryPoint(ImageHandle,SystemTable);
/* Empty the console input buffer to flush out any keystrokes entered before this point. */
Status = SystemTable->ConIn->Reset(SystemTable->ConIn, false);
if(EFI_ERROR(Status))
return Status;
/* Wait for keypress. */
while((Status = SystemTable->ConIn->ReadKeyStroke(SystemTable->ConIn, &Key)) == EFI_NOT_READY) ;
return Status;
}
EFI_STATUS
EFIAPI
DriverEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
/* Print message. */
Status = SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Calling from test driver\n\r" MESSAGE);
if(EFI_ERROR(Status))
return Status;
return EFI_SUCCESS;
}
| 23.636364 | 106 | 0.715385 |
307a82dd38f77f8ce67181449fcf501e47f897ac | 2,214 | h | C | System/Library/PrivateFrameworks/SpeechRecognitionCommandAndControl.framework/CACTextInsertionSpecifier.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | 2 | 2021-11-02T09:23:27.000Z | 2022-03-28T08:21:57.000Z | System/Library/PrivateFrameworks/SpeechRecognitionCommandAndControl.framework/CACTextInsertionSpecifier.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/SpeechRecognitionCommandAndControl.framework/CACTextInsertionSpecifier.h | lechium/iOS1351Headers | 6bed3dada5ffc20366b27f7f2300a24a48a6284e | [
"MIT"
] | 1 | 2022-03-28T08:21:59.000Z | 2022-03-28T08:21:59.000Z | /*
* This header is generated by classdump-dyld 1.5
* on Wednesday, October 27, 2021 at 3:22:56 PM Mountain Standard Time
* Operating System: Version 13.5.1 (Build 17F80)
* Image Source: /System/Library/PrivateFrameworks/SpeechRecognitionCommandAndControl.framework/SpeechRecognitionCommandAndControl
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos. Updated by Kevin Bradley.
*/
#import <SpeechRecognitionCommandAndControl/SpeechRecognitionCommandAndControl-Structs.h>
@class NSString, AXElement, NSDictionary;
@interface CACTextInsertionSpecifier : NSObject {
NSString* _insertedString;
AXElement* _axElement;
NSString* _commandIdentifier;
NSDictionary* _recognizedParams;
NSString* _insertedCategoryID;
NSRange _insertedRange;
}
@property (retain) NSString * insertedString; //@synthesize insertedString=_insertedString - In the implementation block
@property (assign) NSRange insertedRange; //@synthesize insertedRange=_insertedRange - In the implementation block
@property (retain) AXElement * axElement; //@synthesize axElement=_axElement - In the implementation block
@property (retain) NSString * commandIdentifier; //@synthesize commandIdentifier=_commandIdentifier - In the implementation block
@property (retain) NSDictionary * recognizedParams; //@synthesize recognizedParams=_recognizedParams - In the implementation block
@property (retain) NSString * insertedCategoryID; //@synthesize insertedCategoryID=_insertedCategoryID - In the implementation block
-(AXElement *)axElement;
-(void)setCommandIdentifier:(NSString *)arg1 ;
-(NSString *)commandIdentifier;
-(NSRange)insertedRange;
-(void)setRecognizedParams:(NSDictionary *)arg1 ;
-(void)setInsertedString:(NSString *)arg1 ;
-(void)setInsertedRange:(NSRange)arg1 ;
-(void)setAxElement:(AXElement *)arg1 ;
-(void)setInsertedCategoryID:(NSString *)arg1 ;
-(NSString *)insertedString;
-(NSDictionary *)recognizedParams;
-(NSString *)insertedCategoryID;
@end
| 50.318182 | 152 | 0.716802 |
fda96fba76110b48eb66ad8a57eee19b73b443b3 | 2,668 | h | C | netbsdsrc/sys/arch/arm32/ofw/ofisa_machdep.h | tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective | 1b0172cdb78757fd17898503aaf6ce03d940ef28 | [
"Apache-1.1"
] | 46 | 2015-12-04T17:12:58.000Z | 2022-03-11T04:30:49.000Z | netbsdsrc/sys/arch/arm32/ofw/ofisa_machdep.h | tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective | 1b0172cdb78757fd17898503aaf6ce03d940ef28 | [
"Apache-1.1"
] | null | null | null | netbsdsrc/sys/arch/arm32/ofw/ofisa_machdep.h | tharindusathis/sourcecodes-of-CodeReadingTheOpenSourcePerspective | 1b0172cdb78757fd17898503aaf6ce03d940ef28 | [
"Apache-1.1"
] | 23 | 2016-10-24T09:18:14.000Z | 2022-02-25T02:11:35.000Z | /* $NetBSD$ */
/*
* Copyright 1998
* Digital Equipment Corporation. All rights reserved.
*
* This software is furnished under license and may be used and
* copied only in accordance with the following terms and conditions.
* Subject to these conditions, you may download, copy, install,
* use, modify and distribute this software in source and/or binary
* form. No title or ownership is transferred hereby.
*
* 1) Any source code used, modified or distributed must reproduce
* and retain this copyright notice and list of conditions as
* they appear in the source file.
*
* 2) No right is granted to use any trade name, trademark, or logo of
* Digital Equipment Corporation. Neither the "Digital Equipment
* Corporation" name nor any trademark or logo of Digital Equipment
* Corporation may be used to endorse or promote products derived
* from this software without the prior written permission of
* Digital Equipment Corporation.
*
* 3) This software is provided "AS-IS" and any express or implied
* warranties, including but not limited to, any implied warranties
* of merchantability, fitness for a particular purpose, or
* non-infringement are disclaimed. In no event shall DIGITAL be
* liable for any damages whatsoever, and in particular, DIGITAL
* shall not be liable for special, indirect, consequential, or
* incidental damages or damages for lost profits, loss of
* revenue or loss of use, whether such damages arise in contract,
* negligence, tort, under statute, in equity, at law or otherwise,
* even if advised of the possibility of such damage.
*/
int ofisa_get_isabus_data __P((int, struct isabus_attach_args *));
int ofisa_ignore_child __P((int pphandle, int cphandle));
#ifdef COMPAT_OLD_OFW
#define _OFISA_MD_MATCH
int ofisa_md_match __P((struct device *, struct cfdata *, void *));
#define _COM_OFISA_MD_MATCH
#define _COM_OFISA_MD_INTR_FIXUP
int com_ofisa_md_match __P((struct device *, struct cfdata *, void *));
int com_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
struct ofisa_intr_desc *, int, int));
#define _LPT_OFISA_MD_MATCH
#define _LPT_OFISA_MD_INTR_FIXUP
int lpt_ofisa_md_match __P((struct device *, struct cfdata *, void *));
int lpt_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
struct ofisa_intr_desc *, int, int));
#define _WDC_OFISA_MD_MATCH
#define _WDC_OFISA_MD_INTR_FIXUP
int wdc_ofisa_md_match __P((struct device *, struct cfdata *, void *));
int wdc_ofisa_md_intr_fixup __P((struct device *, struct device*, void *,
struct ofisa_intr_desc *, int, int));
#endif /* COMPAT_OLD_OFW */
| 42.349206 | 73 | 0.747751 |
6573476a65a83e652d26e3e4ffe99e1f6bac53db | 1,210 | h | C | tcp/tcp_switch_session.h | damuzhi/switch-proxy | 28a8f2c1389821dbe2a56501fd97966d136c1065 | [
"MIT"
] | 1 | 2020-04-01T03:37:44.000Z | 2020-04-01T03:37:44.000Z | tcp/tcp_switch_session.h | damuzhi/switch-proxy | 28a8f2c1389821dbe2a56501fd97966d136c1065 | [
"MIT"
] | null | null | null | tcp/tcp_switch_session.h | damuzhi/switch-proxy | 28a8f2c1389821dbe2a56501fd97966d136c1065 | [
"MIT"
] | null | null | null | #pragma once
#include "tcp_socket.h"
class tcp_switch_session : public std::enable_shared_from_this<tcp_switch_session>
{
public:
tcp_switch_session(boost::asio::io_service& ios);
public:
// 获得client的socket
tcp_socket& get_client_socket();
// 启动tcp代理会话
void start(const std::vector<address>& target_address_list);
private:
// 初始化目标服务socket
void init_target_socket(const std::vector<address>& target_address_list);
// 连接目标服务
bool connect_target_server();
// 异步读取client的数据
void async_read_client();
// 异步读取target的数据
void async_read_target();
// 异步读取target的数据
void async_read_target(tcp_socket& target);
// 发送数据到client
void send_to_client(tcp_socket& target, std::size_t len);
// 发送数据到target服务
void send_to_target(std::size_t len);
// 重置保活定时器
void reset_keepalive_timer();
// 关闭tcp代理会话
void close();
// 关闭target socket
void close_target_socket();
// 关闭client socket
void close_client_socket();
private:
boost::asio::io_service& ios_;
boost::asio::deadline_timer keepalive_timer_;
tcp_socket client_socket_;
std::vector<tcp_socket> target_socket_list_;
bool closed_ = false;
};
| 24.2 | 82 | 0.706612 |
10e151973c7685416f85f079e3bc0a28fb1cb90c | 244 | h | C | Project16_TumblrMenu/TumblrMenu/MainViewController.h | hayasilin/30DaysOBJC | 3f4d20a1b7bee273a1d38ed615aaa161f4804fe6 | [
"MIT"
] | 18 | 2016-09-21T02:02:56.000Z | 2022-03-09T05:55:51.000Z | Project16_TumblrMenu/TumblrMenu/MainViewController.h | hayasilin/30DaysOBJC | 3f4d20a1b7bee273a1d38ed615aaa161f4804fe6 | [
"MIT"
] | null | null | null | Project16_TumblrMenu/TumblrMenu/MainViewController.h | hayasilin/30DaysOBJC | 3f4d20a1b7bee273a1d38ed615aaa161f4804fe6 | [
"MIT"
] | 5 | 2016-09-24T03:03:06.000Z | 2022-02-19T14:19:57.000Z | //
// MainViewController.h
// TumblrMenu
//
// Created by Kuan-Wei Lin on 9/15/16.
// Copyright © 2016 Kuan-Wei Lin. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface MainViewController : UIViewController
@end
| 7.625 | 55 | 0.647541 |
341ceb99d9283281b9206ab5f1335a1a8246bb11 | 6,499 | h | C | XLsn0wPickers/XLsn0wDatePicker/XLsn0wDatePicker.h | XLsn0w/XLsn0wPicker | f9a8a4ba62a4a9be1b6574ba32ee5658c36d91b5 | [
"MIT"
] | null | null | null | XLsn0wPickers/XLsn0wDatePicker/XLsn0wDatePicker.h | XLsn0w/XLsn0wPicker | f9a8a4ba62a4a9be1b6574ba32ee5658c36d91b5 | [
"MIT"
] | null | null | null | XLsn0wPickers/XLsn0wDatePicker/XLsn0wDatePicker.h | XLsn0w/XLsn0wPicker | f9a8a4ba62a4a9be1b6574ba32ee5658c36d91b5 | [
"MIT"
] | null | null | null | /*********************************************************************************************
* __ __ _ _________ _ _ _ _________ __ _ __ *
* \ \ / / | | | _______| | | \ | | | ______ | \ \ / \ / / *
* \ \ / / | | | | | |\ \ | | | | | | \ \ / \ \ / / *
* \ \/ / | | | |______ | | \ \ | | | | | | \ \ / / \ \ / / *
* /\/\/\ | | |_______ | | | \ \| | | | | | \ \ / / \ \ / / *
* / / \ \ | |______ ______| | | | \ \ | | |_____| | \ \ / \ \ / *
* /_/ \_\ |________| |________| |_| \__| |_________| \_/ \_/ *
* *
*********************************************************************************************/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/** 1.统一的较小间距 5 */
UIKIT_EXTERN CGFloat const STMarginSmall;
/** 2.统一的间距 10 */
UIKIT_EXTERN CGFloat const STMargin;
/** 3.统一的较大间距 16 */
UIKIT_EXTERN CGFloat const STMarginBig;
/** 4.导航栏的最大的Y值 64 */
UIKIT_EXTERN CGFloat const STNavigationBarY;
/** 5.控件的系统高度 44 */
UIKIT_EXTERN CGFloat const STControlSystemHeight;
/** 6.控件的普通高度 36 */
UIKIT_EXTERN CGFloat const STControlNormalHeight;
/**
* 1.屏幕尺寸
*/
#define ScreenWidth CGRectGetWidth([UIScreen mainScreen].bounds)
#define ScreenHeight CGRectGetHeight([UIScreen mainScreen].bounds)
/**
* 2.返回一个RGBA格式的UIColor对象
*/
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
/**
* 3.返回一个RGB格式的UIColor对象
*/
#define RGB(r, g, b) RGBA(r, g, b, 1.0f)
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM (NSInteger, XLsn0wPickerButtonLocation) {
XLsn0wPickerButtonLocationBottom, // 1.选择器在视图的下方
XLsn0wPickerButtonLocationCenter // 2.选择器在视图的中间
};
@interface XLsn0wPickerButton : UIButton
/** 1.内部视图 */
@property (nonatomic, strong) UIView *contentView;
/** 2.边线,选择器和上方tool之间的边线 */
@property (nonatomic, strong)UIView *lineView;
/** 3.选择器 */
@property (nonatomic, strong)UIPickerView *pickerView;
/** 4.左边的按钮 */
@property (nonatomic, strong)UIButton *buttonLeft;
/** 5.右边的按钮 */
@property (nonatomic, strong)UIButton *buttonRight;
/** 6.标题label */
@property (nonatomic, strong)UILabel *labelTitle;
/** 7.下边线,在显示模式是STPickerContentModeCenter的时候显示 */
@property (nonatomic, strong)UIView *lineViewDown;
/** 1.标题,default is nil */
@property(nullable, nonatomic,copy) NSString *title;
/** 2.字体,default is nil (system font 17 plain) */
@property(null_resettable, nonatomic,strong) UIFont *font;
/** 3.字体颜色,default is nil (text draws black) */
@property(null_resettable, nonatomic,strong) UIColor *titleColor;
/** 4.按钮边框颜色颜色,default is RGB(205, 205, 205) */
@property(null_resettable, nonatomic,strong) UIColor *borderButtonColor;
/** 5.选择器的高度,default is 240 */
@property (nonatomic, assign)CGFloat heightPicker;
/** 6.视图的显示模式 */
@property (nonatomic, assign) XLsn0wPickerButtonLocation xlsn0wPickerButtonLocation;
/**
* 5.创建视图,初始化视图时初始数据
*/
- (void)overrideInit;
/**
* 6.确认按钮的点击事件
*/
- (void)selectedOk;
/**
* 7.显示
*/
- (void)show;
/**
* 8.移除
*/
- (void)remove;
@end
NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_BEGIN
@class XLsn0wDatePicker;
/// __weak typeof(self) weakSelf = self;
typedef void(^XLsn0wDatePickerBlock)(XLsn0wDatePicker *picker, NSInteger year, NSInteger month, NSInteger day);///推荐 !!! 注意weak self
@protocol XLsn0wPickerTimerDelegate <NSObject>///不推荐
- (void)pickerTimer:(XLsn0wDatePicker *)pickerTimer year:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
@end
@interface XLsn0wDatePicker : XLsn0wPickerButton
@property (nonatomic, copy) XLsn0wDatePickerBlock pickerBlock;
@property (nonatomic, weak) id<XLsn0wPickerTimerDelegate> xlsn0wDelegate;
/** 1.最小的年份,default is 1900 */
@property (nonatomic, assign) NSInteger yearLeast;
/** 2.显示年份数量,default is 200 */
@property (nonatomic, assign) NSInteger yearSum;
/** 3.中间选择框的高度,default is 28*/
@property (nonatomic, assign) CGFloat heightPickerComponent;
@end
NS_ASSUME_NONNULL_END
@interface NSCalendar (XLsn0wPickerTimerCalendar)
/**
* 1.当前的日期数据元件模型
*
*/
+ (NSDateComponents * _Nonnull)currentDateComponents;
/**
* 2.当前年
*/
+ (NSInteger)currentYear;
/**
* 3.当前月
*/
+ (NSInteger)currentMonth;
/**
* 4.当前天
*/
+ (NSInteger)currentDay;
/**
* 5.当前周数
*/
+ (NSInteger)currnentWeekday;
/**
* 6.获取指定年月的天数
*/
+ (NSInteger)getDaysWithYear:(NSInteger)year
month:(NSInteger)month;
/**
* 7.获取指定年月的第一天的周数
*/
+ (NSInteger)getFirstWeekdayWithYear:(NSInteger)year
month:(NSInteger)month;
/**
* 8.比较两个日期元件
*/
+ (NSComparisonResult)compareWithComponentsOne:(NSDateComponents * _Nonnull)componentsOne
componentsTwo:(NSDateComponents * _Nonnull)componentsTwo;
/**
* 9.获取两个日期元件之间的日期元件
*/
+ (NSMutableArray * _Nonnull)arrayComponentsWithComponentsOne:(NSDateComponents * _Nonnull)componentsOne
componentsTwo:(NSDateComponents * _Nonnull)componentsTwo;
/**
* 10.字符串转日期元件 字符串格式为:yy-MM-dd
*/
+ (NSDateComponents * _Nonnull)dateComponentsWithString:(NSString * _Nonnull)String;
@end
@interface UIView (XLsn0wPickerTimerView)
/**
* 1.间隔X值
*/
@property (nonatomic, assign) CGFloat x;
/**
* 2.间隔Y值
*/
@property (nonatomic, assign) CGFloat y;
/**
* 3.宽度
*/
@property (nonatomic, assign) CGFloat width;
/**
* 4.高度
*/
@property (nonatomic, assign) CGFloat height;
/**
* 5.中心点X值
*/
@property (nonatomic, assign) CGFloat centerX;
/**
* 6.中心点Y值
*/
@property (nonatomic, assign) CGFloat centerY;
/**
* 7.尺寸大小
*/
@property (nonatomic, assign) CGSize size;
/**
* 8.起始点
*/
@property (nonatomic, assign) CGPoint origin;
/**
* 9.上 < Shortcut for frame.origin.y
*/
@property (nonatomic) CGFloat top;
/**
* 10.下 < Shortcut for frame.origin.y + frame.size.height
*/
@property (nonatomic) CGFloat bottom;
/**
* 11.左 < Shortcut for frame.origin.x.
*/
@property (nonatomic) CGFloat left;
/**
* 12.右 < Shortcut for frame.origin.x + frame.size.width
*/
@property (nonatomic) CGFloat right;
/**
* 1.添加边框
*/
- (void)addBorderColor:(UIColor * _Nonnull)color;
/**
* 2.UIView 的点击事件
*
* @param target 目标
* @param action 事件
*/
- (void)addTarget:(id _Nonnull)target
action:(SEL _Nonnull)action;
@end
| 23.632727 | 132 | 0.610863 |
b77308040e59aaecb3d0f5b75b8b59fc6cb1f16e | 429 | h | C | Application/application.h | kevinsalles/FrameworkQt | b96b8751340dafa288dd80096ff71c98d731b9d2 | [
"MIT"
] | null | null | null | Application/application.h | kevinsalles/FrameworkQt | b96b8751340dafa288dd80096ff71c98d731b9d2 | [
"MIT"
] | null | null | null | Application/application.h | kevinsalles/FrameworkQt | b96b8751340dafa288dd80096ff71c98d731b9d2 | [
"MIT"
] | null | null | null | #ifndef APPLICATION_H
#define APPLICATION_H
#include <QtWidgets/QMainWindow>
#include "GeneratedFiles/ui_application.h"
#include "../FrameworkQT/Framework/IModule/imodule.h"
class Application : public QMainWindow
{
Q_OBJECT
public:
Application(QWidget *parent = 0);
~Application();
void loadModules(QList<IModule *>);
private:
Ui::ApplicationView ui;
private slots:
void changedModule();
};
#endif // APPLICATION_H
| 16.5 | 53 | 0.759907 |
b77fc7475881dd5bf3ea5b0293436b4d9c0c6736 | 41,894 | c | C | src/main/uni_hid_parser_wii.c | vcorp/esp32btpad | bcdca86671ce573210573090dc57468a3498b650 | [
"Apache-2.0"
] | null | null | null | src/main/uni_hid_parser_wii.c | vcorp/esp32btpad | bcdca86671ce573210573090dc57468a3498b650 | [
"Apache-2.0"
] | null | null | null | src/main/uni_hid_parser_wii.c | vcorp/esp32btpad | bcdca86671ce573210573090dc57468a3498b650 | [
"Apache-2.0"
] | null | null | null | /****************************************************************************
http://retro.moe/unijoysticle2
Copyright 2019 Ricardo Quesada
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.
****************************************************************************/
// Technical info taken from:
// http://wiibrew.org/wiki/Wiimote
// https://github.com/dvdhrm/xwiimote/blob/master/doc/PROTOCOL
#define ENABLE_EEPROM_DUMP 0
#if ENABLE_EEPROM_DUMP
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif // ENABLE_EEPROM_DUMP
#include "hid_usage.h"
#include "uni_debug.h"
#include "uni_gamepad.h"
#include "uni_hid_device.h"
#include "uni_hid_parser.h"
#include "uni_hid_parser_wii.h"
#if ENABLE_EEPROM_DUMP
#define WII_DUMP_ROM_DATA_SIZE 16 // Max size is 16
static const uint32_t WII_DUMP_ROM_DATA_ADDR_START = 0x0000;
static const uint32_t WII_DUMP_ROM_DATA_ADDR_END = 0x1700;
#endif // ENABLE_EEPROM_DUMP
enum wii_flags {
WII_FLAGS_NONE = 0,
WII_FLAGS_VERTICAL = 1 << 0,
WII_FLAGS_ACCEL = 1 << 1,
};
// Taken from Linux kernel: hid-wiimote.h
enum wiiproto_reqs {
WIIPROTO_REQ_NULL = 0x0,
WIIPROTO_REQ_RUMBLE = 0x10,
WIIPROTO_REQ_LED = 0x11,
WIIPROTO_REQ_DRM = 0x12,
WIIPROTO_REQ_IR1 = 0x13,
WIIPROTO_REQ_SREQ = 0x15,
WIIPROTO_REQ_WMEM = 0x16,
WIIPROTO_REQ_RMEM = 0x17,
WIIPROTO_REQ_IR2 = 0x1a,
WIIPROTO_REQ_STATUS = 0x20,
WIIPROTO_REQ_DATA = 0x21,
WIIPROTO_REQ_RETURN = 0x22,
WIIPROTO_REQ_DRM_K = 0x30,
WIIPROTO_REQ_DRM_KA = 0x31,
WIIPROTO_REQ_DRM_KE = 0x32,
WIIPROTO_REQ_DRM_KAI = 0x33,
WIIPROTO_REQ_DRM_KEE = 0x34,
WIIPROTO_REQ_DRM_KAE = 0x35,
WIIPROTO_REQ_DRM_KIE = 0x36,
WIIPROTO_REQ_DRM_KAIE = 0x37,
WIIPROTO_REQ_DRM_E = 0x3d,
WIIPROTO_REQ_DRM_SKAI1 = 0x3e,
WIIPROTO_REQ_DRM_SKAI2 = 0x3f,
WIIPROTO_REQ_MAX
};
// Supported Wii devices
enum wii_devtype {
WII_DEVTYPE_UNK,
WII_DEVTYPE_PRO_CONTROLLER, // Wii U Pro controller
WII_DEVTYPE_REMOTE, // 1st gen
WII_DEVTYPE_REMOTE_MP, // MP: motion plus (wii remote 2nd gen)
};
enum wii_exttype {
WII_EXT_NONE, // No extensions detected
WII_EXT_UNK, // Unknown extension
WII_EXT_NUNCHUK, // Nunchuk
WII_EXT_CLASSIC_CONTROLLER, // Classic Controller or Classic Controller Pro
WII_EXT_U_PRO_CONTROLLER, // Wii U Pro
};
// Required steps to determine what kind of extensions are supported.
enum wii_fsm {
WII_FSM_UNINIT, // Uninitialized
WII_FSM_SETUP, // Setup
WII_FSM_DUMP_EEPROM_IN_PROGRESS, // EEPROM dump in progress
WII_FSM_DUMP_EEPROM_FINISHED, // EEPROM dump finished
WII_FSM_DID_REQ_STATUS, // Status requested
WII_FSM_DEV_UNK, // Device unknown
WII_FSM_EXT_UNK, // Extension unknown
WII_FSM_EXT_DID_INIT, // Extension initialized
WII_FSM_EXT_DID_NO_ENCRYPTION, // Extension no encription
WII_FSM_EXT_DID_READ_REGISTER, // Extension read register
WII_FSM_DEV_GUESSED, // Device type guessed
WII_FSM_DEV_ASSIGNED, // Device type assigned
WII_FSM_LED_UPDATED, // After device was assigned, update LEDs.
// Gamepad ready to be used
};
// As defined here: http://wiibrew.org/wiki/Wiimote#0x21:_Read_Memory_Data
typedef enum wii_read_type {
WII_READ_FROM_MEM = 0,
WII_READ_FROM_REGISTERS = 0x04,
} wii_read_type_t;
// nunchuk_t represents the data provided by the Nunchuk.
typedef struct nunchuk_s {
int sx; // Analog stick X
int sy; // Analog stick Y
int ax; // Accelerometer X
int ay; // Accelerometer Y
int az; // Accelerometer Z
bool bc; // Button C
bool bz; // Button Z
} nunchuk_t;
// wii_instance_t represents data used by the Wii driver instance.
typedef struct wii_instance_s {
uint8_t state;
uint8_t register_address;
uint8_t flags;
enum wii_devtype dev_type;
enum wii_exttype ext_type;
uni_gamepad_seat_t gamepad_seat;
// Debug only
int debug_fd; // File descriptor where dump is saved
uint32_t debug_addr; // Current dump address
} wii_instance_t;
_Static_assert(sizeof(wii_instance_t) < HID_DEVICE_MAX_PARSER_DATA,
"Wii intance too big");
static void process_req_status(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_req_data(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_req_return(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_k(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_k_vertical(uni_gamepad_t* gp, const uint8_t* data);
static void process_drm_k_horizontal(uni_gamepad_t* gp, const uint8_t* data);
static void process_drm_ka(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_ke(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_kae(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_kee(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static void process_drm_e(uni_hid_device_t* d, const uint8_t* report,
uint16_t len);
static nunchuk_t process_nunchuk(const uint8_t* e, uint16_t len);
static void wii_process_fsm(uni_hid_device_t* d);
static void wii_fsm_ext_init(uni_hid_device_t* d);
static void wii_fsm_ext_encrypt_off(uni_hid_device_t* d);
static void wii_fsm_ext_read_register(uni_hid_device_t* d);
static void wii_fsm_req_status(uni_hid_device_t* d);
static void wii_fsm_assign_device(uni_hid_device_t* d);
static void wii_fsm_update_led(uni_hid_device_t* d);
static void wii_fsm_dump_eeprom(uni_hid_device_t* d);
static void wii_read_mem(uni_hid_device_t* d, wii_read_type_t t,
uint32_t offset, uint16_t size);
static wii_instance_t* get_wii_instance(uni_hid_device_t* d);
static void set_led(uni_hid_device_t* d, uni_gamepad_seat_t seat);
// process_ functions
// Defined here: http://wiibrew.org/wiki/Wiimote#0x20:_Status
static void process_req_status(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
if (len < 7) {
loge("Wii: Unexpected report lenght; got %d, want >= 7\n", len);
return;
}
wii_instance_t* ins = get_wii_instance(d);
uint8_t flags = report[3] & 0x0f; // LF (leds / flags)
if (ins->state == WII_FSM_DID_REQ_STATUS) {
if (d->product_id == 0x0306) {
// We are positive that this is a Wii Remote 1st gen
ins->state = WII_FSM_DEV_GUESSED;
ins->dev_type = WII_DEVTYPE_REMOTE;
} else if (d->product_id == 0x0330) {
// It can be either a Wii Remote 2nd gen or a Wii U Pro Controller
if ((flags & 0x02) == 0) {
// If there are no extensions, then we are sure it is a Wii Remote MP.
ins->state = WII_FSM_DEV_GUESSED;
ins->dev_type = WII_DEVTYPE_REMOTE_MP;
} else {
// Otherwise, it can be either a Wii Remote MP with a Nunchuk or a
// Wii U Pro controller.
ins->state = WII_FSM_DEV_UNK;
}
}
if ((flags & 0x02) != 0) {
// Extension detected: Nunchuk?
// Regardless of the previous FSM state, we overwrite it with "query
// extension".
logi("Wii: extension found.\n");
ins->state = WII_FSM_EXT_UNK;
ins->ext_type = WII_EXT_UNK;
} else {
logi("Wii: No extensions found.\n");
ins->ext_type = WII_EXT_NONE;
}
if (report[2] & 0x08) {
// Wii Remote only: Enter "accel mode" if "A" is pressed.
ins->flags |= WII_FLAGS_ACCEL;
} else if (report[1] & 0x10) {
// Wii Remote only: Enter "vertical mode" if "+" is pressed.
ins->flags |= WII_FLAGS_VERTICAL;
}
wii_process_fsm(d);
}
}
// Defined here: http://wiibrew.org/wiki/Wiimote#0x21:_Read_Memory_Data
static void process_req_data_read_register(uni_hid_device_t* d,
const uint8_t* report,
uint16_t len) {
uint8_t se = report[3]; // SE: size and error
uint8_t s = se >> 4; // size
uint8_t e = se & 0x0f; // error
if (e) {
loge("Wii: error reading memory: 0x%02x\n.", e);
return;
}
wii_instance_t* ins = get_wii_instance(d);
// We are expecting to read 6 bytes from 0xXX00fa
if (s == 5 && report[4] == 0x00 && report[5] == 0xfa) {
// This contains the read memory from register 0xa?00fa
// Data is in report[6]..report[11]
// Try to guess device type.
if (report[10] == 0x01 && report[11] == 0x20) {
// Pro Controller: 00 00 a4 20 01 20
ins->dev_type = WII_DEVTYPE_PRO_CONTROLLER;
ins->ext_type = WII_EXT_U_PRO_CONTROLLER;
logi("Wii: Pro Controller extension found\n");
} else if (ins->dev_type == WII_DEVTYPE_UNK) {
if (d->product_id == 0x0330) {
ins->dev_type = WII_DEVTYPE_REMOTE_MP;
logi("Wii Remote MP detected\n");
} else if (d->product_id == 0x0306) {
ins->dev_type = WII_DEVTYPE_REMOTE;
logi("Wii Remote detected\n");
} else {
loge("Wii: Unknown product id: 0x%04x\n", d->product_id);
}
}
// Try to guess extension type.
if (ins->ext_type == WII_EXT_UNK) {
if (report[10] == 0x00 && report[11] == 0x00) {
// Nunchuck: 00 00 a4 20 00 00
ins->ext_type = WII_EXT_NUNCHUK;
logi("Wii: Nunchuk extension found\n");
} else if (report[10] == 0x01 && report[11] == 0x01) {
// Classic / Classic Pro: 0? 00 a4 20 01 01
ins->ext_type = WII_EXT_CLASSIC_CONTROLLER;
logi(
"Wii: Classic Controller / Classic Controller Pro extension "
"found\n");
} else {
loge("Wii: Unknown extension\n");
printf_hexdump(report, len);
}
}
ins->state = WII_FSM_DEV_GUESSED;
wii_process_fsm(d);
} else {
loge("Wii: invalid response");
printf_hexdump(report, len);
}
}
static void process_req_data_dump_eeprom(uni_hid_device_t* d,
const uint8_t* report, uint16_t len) {
UNUSED(len);
#if ENABLE_EEPROM_DUMP
uint8_t se = report[3]; // SE: size and error
uint8_t s = (se >> 4) + 1; // size
uint8_t e = se & 0x0f; // error
if (e) {
loge("Wii: error reading memory: 0x%02x\n.", e);
return;
}
wii_instance_t* ins = get_wii_instance(d);
uint16_t addr = report[4] << 8 | report[5];
logi("Wii: dumping %d bytes at address: 0x%04x\n", s, addr);
write(ins->debug_fd, &report[6], s);
#else
UNUSED(d);
UNUSED(report);
#endif // ENABLE_EEPROM_DUMP
wii_process_fsm(d);
}
// Defined here: http://wiibrew.org/wiki/Wiimote#0x21:_Read_Memory_Data
static void process_req_data(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
logi("**** process_req_data\n");
printf_hexdump(report, len);
if (len < 22) {
loge("Wii: invalid req_data lenght: got %d, want >= 22\n", len);
printf_hexdump(report, len);
return;
}
wii_instance_t* ins = get_wii_instance(d);
switch (ins->state) {
case WII_FSM_EXT_DID_READ_REGISTER:
process_req_data_read_register(d, report, len);
break;
case WII_FSM_DUMP_EEPROM_IN_PROGRESS:
process_req_data_dump_eeprom(d, report, len);
break;
default:
loge("process_req_data. Unknown FSM state: 0x%02x\n", ins->state);
break;
}
}
// Defined here:
// http://wiibrew.org/wiki/Wiimote#0x22:_Acknowledge_output_report.2C_return_function_result
static void process_req_return(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
if (len < 5) {
loge("Invalid len report for process_req_return: got %d, want >= 5\n", len);
}
if (report[3] == WIIPROTO_REQ_WMEM) {
wii_instance_t* ins = get_wii_instance(d);
// Status != 0: Error. Probably invalid register
if (report[4] != 0) {
if (ins->register_address == 0xa6) {
loge("Failed to read registers from 0xa6... mmmm\n");
ins->state = WII_FSM_SETUP;
} else {
// If it failed to read registers with 0xa4, then try with 0xa6
// If 0xa6 works Ok, it is safe to assume it is a Wii Remote MP, but
// for the sake of finishing the "read extension" (might be useful
// in the future), we continue with it.
logi(
"Probably a Remote MP device. Switching to 0xa60000 address "
"for registers.\n");
ins->state = WII_FSM_DEV_UNK;
ins->register_address =
0xa6; // Register address used for Wii Remote MP.
}
} else {
// Status Ok. Good
}
wii_process_fsm(d);
}
}
// Used for WiiMote in Sideways and Vertical Mode.
// Defined here: http://wiibrew.org/wiki/Wiimote#0x30:_Core_Buttons
static void process_drm_k(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
/* DRM_K: BB*2 */
// Expecting something like:
// 30 00 08
if (len < 3) {
loge("wii remote drm_k: invalid report len %d\n", len);
return;
}
uni_gamepad_t* gp = &d->gamepad;
const uint8_t* data = &report[1];
wii_instance_t* ins = get_wii_instance(d);
if (ins->flags & WII_FLAGS_VERTICAL) {
process_drm_k_vertical(gp, data);
} else {
process_drm_k_horizontal(gp, data);
}
// Process misc buttons
gp->misc_buttons |=
(data[1] & 0x80) ? MISC_BUTTON_SYSTEM : 0; // Button "home"
gp->misc_buttons |= (data[0] & 0x10) ? MISC_BUTTON_HOME : 0; // Button "+"
gp->misc_buttons |= (data[1] & 0x10) ? MISC_BUTTON_BACK : 0; // Button "-"
gp->updated_states |= GAMEPAD_STATE_MISC_BUTTON_SYSTEM |
GAMEPAD_STATE_MISC_BUTTON_HOME |
GAMEPAD_STATE_MISC_BUTTON_BACK;
}
// Used for WiiMote in Sideways Mode (Directions and A/B/X/Y Buttons only).
static void process_drm_k_horizontal(uni_gamepad_t* gp, const uint8_t* data) {
// dpad
gp->dpad |= (data[0] & 0x01) ? DPAD_DOWN : 0;
gp->dpad |= (data[0] & 0x02) ? DPAD_UP : 0;
gp->dpad |= (data[0] & 0x04) ? DPAD_RIGHT : 0;
gp->dpad |= (data[0] & 0x08) ? DPAD_LEFT : 0;
gp->updated_states |= GAMEPAD_STATE_DPAD;
// buttons
gp->buttons |= (data[1] & 0x04) ? BUTTON_Y : 0; // Shoulder button
gp->buttons |= (data[1] & 0x08) ? BUTTON_X : 0; // Big button "A"
gp->buttons |= (data[1] & 0x02) ? BUTTON_A : 0; // Button "1"
gp->buttons |= (data[1] & 0x01) ? BUTTON_B : 0; // Button "2"
gp->updated_states |= GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B |
GAMEPAD_STATE_BUTTON_X | GAMEPAD_STATE_BUTTON_Y;
}
// Used for WiiMote in Vertical Mode (Directions and A/B/X/Y Buttons only).
static void process_drm_k_vertical(uni_gamepad_t* gp, const uint8_t* data) {
// dpad
gp->dpad |= (data[0] & 0x01) ? DPAD_LEFT : 0;
gp->dpad |= (data[0] & 0x02) ? DPAD_RIGHT : 0;
gp->dpad |= (data[0] & 0x04) ? DPAD_DOWN : 0;
gp->dpad |= (data[0] & 0x08) ? DPAD_UP : 0;
gp->updated_states |= GAMEPAD_STATE_DPAD;
// buttons
gp->buttons |= (data[1] & 0x04) ? BUTTON_A : 0; // Shoulder button
gp->buttons |= (data[1] & 0x08) ? BUTTON_B : 0; // Big button "A"
gp->buttons |= (data[1] & 0x02) ? BUTTON_X : 0; // Button "1"
gp->buttons |= (data[1] & 0x01) ? BUTTON_Y : 0; // Button "2"
gp->updated_states |= GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B |
GAMEPAD_STATE_BUTTON_X | GAMEPAD_STATE_BUTTON_Y;
}
// Used for WiiMote in Accelerometer Mode. Defined here:
// http://wiibrew.org/wiki/Wiimote#0x31:_Core_Buttons_and_Accelerometer
static void process_drm_ka(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
// Process Wiimote in "accelerator mode".
const int16_t accel_threshold = 32;
/* DRM_KA: BB*2 AA*3*/
// Expecting something like:
// 31 20 60 82 7F 99
if (len < 6) {
loge("wii remote drm_ka: invalid report len %d\n", len);
return;
}
uint16_t x = report[3] << 2;
uint16_t y = report[4] << 2;
// uint16_t z = report[5] << 2;
x |= (report[1] >> 5) & 0x3;
y |= (report[2] >> 4) & 0x2;
// z |= (report[2] >> 5) & 0x2;
int16_t sx = x - 0x200;
int16_t sy = y - 0x200;
// int16_t sz = z - 0x200;
// printf_hexdump(report, len);
// printf("x=%d, y=%d, z=%d\n", x, y, z);
uni_gamepad_t* gp = &d->gamepad;
if (sx < -accel_threshold) {
gp->dpad |= DPAD_LEFT;
} else if (sx > accel_threshold) {
gp->dpad |= DPAD_RIGHT;
}
if (sy < -accel_threshold) {
gp->dpad |= DPAD_UP;
} else if (sy > (accel_threshold / 2)) {
// Threshold for down is 50% because it is not as easy to tilt the
// device down as it is it to tilt it up.
gp->dpad |= DPAD_DOWN;
}
gp->updated_states |= GAMEPAD_STATE_DPAD;
gp->buttons |= (report[2] & 0x08) ? BUTTON_A : 0; // Big button "A"
gp->buttons |= (report[2] & 0x04) ? BUTTON_B : 0; // Button Shoulder
gp->buttons |= (report[2] & 0x02) ? BUTTON_X : 0; // Button "1"
gp->buttons |= (report[2] & 0x01) ? BUTTON_Y : 0; // Button "2"
gp->updated_states |= GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B |
GAMEPAD_STATE_BUTTON_X | GAMEPAD_STATE_BUTTON_Y;
gp->misc_buttons |=
(report[2] & 0x80) ? MISC_BUTTON_SYSTEM : 0; // Button "home"
gp->misc_buttons |= (report[2] & 0x10) ? MISC_BUTTON_BACK : 0; // Button "-"
gp->misc_buttons |= (report[1] & 0x10) ? MISC_BUTTON_HOME : 0; // Button "+"
gp->updated_states |= GAMEPAD_STATE_MISC_BUTTON_SYSTEM |
GAMEPAD_STATE_MISC_BUTTON_BACK |
GAMEPAD_STATE_MISC_BUTTON_HOME;
}
// Used in WiiMote + Nunchuk Mode
// Defined here:
// http://wiibrew.org/wiki/Wiimote#0x32:_Core_Buttons_with_8_Extension_bytes
static void process_drm_ke(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
// Expecting something like:
// 32 BB BB EE EE EE EE EE EE EE EE
if (len < 11) {
loge("Wii: unexpected len; got %d, want >= 11\n", len);
return;
}
wii_instance_t* ins = get_wii_instance(d);
if (ins->ext_type != WII_EXT_NUNCHUK) {
loge("Wii: unexpected Wii extension: got %d, want: %d", ins->ext_type,
WII_EXT_NUNCHUK);
return;
}
//
// Process Nunchuk
//
nunchuk_t n = process_nunchuk(&report[3], len - 3);
uni_gamepad_t* gp = &d->gamepad;
const int factor = (AXIS_NORMALIZE_RANGE / 2) / 128;
// When VERTICAL mode is enabled, Nunchuk behaves as "right" joystick,
// and the Wii remote behaves as the "left" joystick.
if (ins->flags == WII_FLAGS_VERTICAL) {
// Treat Nunchuk as "right" joypad.
gp->axis_rx = n.sx * factor;
gp->axis_ry = n.sy * factor;
gp->updated_states |= GAMEPAD_STATE_AXIS_RX | GAMEPAD_STATE_AXIS_RY;
gp->buttons |= n.bc ? BUTTON_B : 0;
gp->buttons |= n.bz ? BUTTON_SHOULDER_R : 0; // Autofire
} else {
// Treat Nunchuk as "left" joypad.
gp->axis_x = n.sx * factor;
gp->axis_y = n.sy * factor;
gp->updated_states |= GAMEPAD_STATE_AXIS_X | GAMEPAD_STATE_AXIS_Y;
gp->buttons |= n.bc ? BUTTON_A : 0;
gp->buttons |= n.bz ? BUTTON_B : 0;
}
//
// Process Wii remote
//
// dpad
gp->dpad |= (report[1] & 0x01) ? DPAD_LEFT : 0;
gp->dpad |= (report[1] & 0x02) ? DPAD_RIGHT : 0;
gp->dpad |= (report[1] & 0x04) ? DPAD_DOWN : 0;
gp->dpad |= (report[1] & 0x08) ? DPAD_UP : 0;
gp->updated_states |= GAMEPAD_STATE_DPAD;
gp->buttons |= (report[2] & 0x04) ? BUTTON_A : 0; // Shoulder button
if (ins->flags == WII_FLAGS_VERTICAL) {
gp->buttons |=
(report[2] & 0x08) ? BUTTON_SHOULDER_L : 0; // Big button "A"
} else {
// If "vertical" not enabled, update Button B as well
gp->buttons |= (report[2] & 0x08) ? BUTTON_B : 0; // Big button "A"
}
gp->buttons |= (report[2] & 0x02) ? BUTTON_X : 0; // Button "1"
gp->buttons |= (report[2] & 0x01) ? BUTTON_Y : 0; // Button "2"
gp->updated_states |= GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B |
GAMEPAD_STATE_BUTTON_X | GAMEPAD_STATE_BUTTON_Y |
GAMEPAD_STATE_BUTTON_SHOULDER_L |
GAMEPAD_STATE_BUTTON_SHOULDER_R;
gp->misc_buttons |=
(report[2] & 0x80) ? MISC_BUTTON_SYSTEM : 0; // Button "home"
gp->misc_buttons |= (report[2] & 0x10) ? MISC_BUTTON_BACK : 0; // Button "-"
gp->misc_buttons |= (report[1] & 0x10) ? MISC_BUTTON_HOME : 0; // Button "+"
gp->updated_states |= GAMEPAD_STATE_MISC_BUTTON_SYSTEM |
GAMEPAD_STATE_MISC_BUTTON_BACK |
GAMEPAD_STATE_MISC_BUTTON_HOME;
}
// Defined here:
// http://wiibrew.org/wiki/Wiimote#0x35:_Core_Buttons_and_Accelerometer_with_16_Extension_Bytes
static void process_drm_kae(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
// Expecting something like:
// (a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE
UNUSED(d);
UNUSED(report);
UNUSED(len);
loge("Wii: drm_kae not supported yet\n");
}
static nunchuk_t process_nunchuk(const uint8_t* e, uint16_t len) {
// Nunchuk format here:
// http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck
nunchuk_t n = {0};
if (len < 6) {
loge("Wii: unexpected len; got %d, want >= 6\n", len);
return n;
}
n.sx = e[0] - 0x80;
// Invert polarity to match Unijoysticle virtual gamepad.
n.sy = -(e[1] - 0x80);
n.ax = (e[2] << 2) | ((e[5] & 0b00001100) >> 2);
n.ay = (e[3] << 2) | ((e[5] & 0b00110000) >> 4);
n.az = (e[4] << 2) | ((e[5] & 0b11000000) >> 6);
n.ax -= AXIS_NORMALIZE_RANGE / 2;
n.ay -= AXIS_NORMALIZE_RANGE / 2;
n.az -= AXIS_NORMALIZE_RANGE / 2;
n.bc = !(e[5] & 0b00000010);
n.bz = !(e[5] & 0b00000001);
return n;
}
// Used for the Wii U Pro Controller
// Defined here:
// http://wiibrew.org/wiki/Wiimote#0x34:_Core_Buttons_with_19_Extension_bytes
static void process_drm_kee(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
wii_instance_t* ins = get_wii_instance(d);
if (ins->ext_type != WII_EXT_U_PRO_CONTROLLER) {
}
/* DRM_KEE: BB*2 EE*19 */
// Expecting something like:
// 34 00 00 19 08 D5 07 20 08 21 08 FF FF CF 00 00 00 00 00 00 00 00
// Doc taken from hid-wiimote-modules.c from Linux Kernel
/* Byte | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
* -----+-----+-----+-----+-----+-----+-----+-----+-----+
* 0 | LX <7:0> |
* -----+-----------------------+-----------------------+
* 1 | 0 0 0 0 | LX <11:8> |
* -----+-----------------------+-----------------------+
* 2 | RX <7:0> |
* -----+-----------------------+-----------------------+
* 3 | 0 0 0 0 | RX <11:8> |
* -----+-----------------------+-----------------------+
* 4 | LY <7:0> |
* -----+-----------------------+-----------------------+
* 5 | 0 0 0 0 | LY <11:8> |
* -----+-----------------------+-----------------------+
* 6 | RY <7:0> |
* -----+-----------------------+-----------------------+
* 7 | 0 0 0 0 | RY <11:8> |
* -----+-----+-----+-----+-----+-----+-----+-----+-----+
* 8 | BDR | BDD | BLT | B- | BH | B+ | BRT | 1 |
* -----+-----+-----+-----+-----+-----+-----+-----+-----+
* 9 | BZL | BB | BY | BA | BX | BZR | BDL | BDU |
* -----+-----+-----+-----+-----+-----+-----+-----+-----+
* 10 | 1 | BATTERY | USB |CHARG|LTHUM|RTHUM|
* -----+-----+-----------------+-----------+-----+-----+
* All buttons are low-active (0 if pressed)
* RX and RY are right analog stick
* LX and LY are left analog stick
* BLT is left trigger, BRT is right trigger.
* BDR, BDD, BDL, BDU form the D-Pad with right, down, left, up buttons
* BZL is left Z button and BZR is right Z button
* B-, BH, B+ are +, HOME and - buttons
* BB, BY, BA, BX are A, B, X, Y buttons
*
* Bits marked as 0/1 are unknown and never changed during tests.
*
* Not entirely verified:
* CHARG: 1 if uncharging, 0 if charging
* USB: 1 if not connected, 0 if connected
* BATTERY: battery capacity from 000 (empty) to 100 (full)
*/
if (len < 14) {
loge("wii remote drm_kee: invalid report len %d\n", len);
return;
}
uni_gamepad_t* gp = &d->gamepad;
const uint8_t* data = &report[3];
// Process axis
const uint16_t axis_base = 0x800;
int16_t lx = data[0] + ((data[1] & 0x0f) << 8) - axis_base;
int16_t rx = data[2] + ((data[3] & 0x0f) << 8) - axis_base;
int16_t ly = data[4] + ((data[5] & 0x0f) << 8) - axis_base;
int16_t ry = data[6] + ((data[7] & 0x0f) << 8) - axis_base;
// Axis have 12-bit of resolution, but Bluepad32 uses 10-bit for the axis.
// In theory we could just convert "from wire to bluepad32" in just one step
// using a few "shift right" operations.
// But apparently Wii U Controller doesn't use the whole range of the 12-bits.
// The max value seems to be 1280 instead of 2048.
lx = lx * 512 / 1280;
rx = rx * 512 / 1280;
ly = ly * 512 / 1280;
ry = ry * 512 / 1280;
// Y is inverted
gp->axis_x = lx;
gp->axis_y = -ly;
gp->axis_rx = rx;
gp->axis_ry = -ry;
gp->updated_states |= GAMEPAD_STATE_AXIS_X | GAMEPAD_STATE_AXIS_Y |
GAMEPAD_STATE_AXIS_RX | GAMEPAD_STATE_AXIS_RY;
// Process Dpad
gp->dpad |= !(data[8] & 0x80) ? DPAD_RIGHT : 0; // BDR
gp->dpad |= !(data[8] & 0x40) ? DPAD_DOWN : 0; // BDD
gp->dpad |= !(data[9] & 0x02) ? DPAD_LEFT : 0; // BDL
gp->dpad |= !(data[9] & 0x01) ? DPAD_UP : 0; // BDU
gp->updated_states |= GAMEPAD_STATE_DPAD;
// Process buttons. A,B -> B,A; X,Y -> Y,X; trigger <--> shoulder
gp->buttons |= !(data[9] & 0x10) ? BUTTON_B : 0; // BA
gp->buttons |= !(data[9] & 0x40) ? BUTTON_A : 0; // BB
gp->buttons |= !(data[9] & 0x08) ? BUTTON_Y : 0; // BX
gp->buttons |= !(data[9] & 0x20) ? BUTTON_X : 0; // BY
gp->buttons |= !(data[9] & 0x80) ? BUTTON_TRIGGER_L : 0; // BZL
gp->buttons |= !(data[9] & 0x04) ? BUTTON_TRIGGER_R : 0; // BZR
gp->buttons |= !(data[8] & 0x20) ? BUTTON_SHOULDER_L : 0; // BLT
gp->buttons |= !(data[8] & 0x02) ? BUTTON_SHOULDER_R : 0; // BRT
gp->buttons |= !(data[10] & 0x02) ? BUTTON_THUMB_L : 0; // LTHUM
gp->buttons |= !(data[10] & 0x01) ? BUTTON_THUMB_R : 0; // RTHUM
gp->updated_states |=
GAMEPAD_STATE_BUTTON_SHOULDER_L | GAMEPAD_STATE_BUTTON_SHOULDER_R |
GAMEPAD_STATE_BUTTON_TRIGGER_L | GAMEPAD_STATE_BUTTON_TRIGGER_R |
GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B | GAMEPAD_STATE_BUTTON_X |
GAMEPAD_STATE_BUTTON_Y | GAMEPAD_STATE_BUTTON_THUMB_L |
GAMEPAD_STATE_BUTTON_THUMB_R;
// Process misc buttons
gp->misc_buttons |= !(data[8] & 0x08) ? MISC_BUTTON_SYSTEM : 0; // BH
gp->misc_buttons |= !(data[8] & 0x04) ? MISC_BUTTON_HOME : 0; // B+
gp->misc_buttons |= !(data[8] & 0x10) ? MISC_BUTTON_BACK : 0; // B-
gp->updated_states |= GAMEPAD_STATE_MISC_BUTTON_SYSTEM |
GAMEPAD_STATE_MISC_BUTTON_HOME |
GAMEPAD_STATE_MISC_BUTTON_BACK;
}
// Used for the Wii Classic Controller (includes Pro?). Defined here:
// http://wiibrew.org/wiki/Wiimote#0x3d:_21_Extension_Bytes
static void process_drm_e(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
if (len < 22) {
loge("Wii: unexpected report lenght: got %d, want >= 22", len);
return;
}
wii_instance_t* ins = get_wii_instance(d);
// Assumes Classic Controller detected
if (ins->ext_type != WII_EXT_CLASSIC_CONTROLLER) {
loge("Wii: unexpected Wii extension: got %d, want: %d", ins->ext_type,
WII_EXT_CLASSIC_CONTROLLER);
return;
}
// Classic Controller format taken from here:
// http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Classic_Controller
const uint8_t* data = &report[1];
uni_gamepad_t* gp = &d->gamepad;
// Axis
int lx = data[0] & 0b00111111;
int ly = data[1] & 0b00111111;
int rx = (data[0] & 0b11000000) >> 3 | (data[1] & 0b11000000) >> 5 |
(data[0] & 0b10000000) >> 7;
int ry = data[2] & 0b00011111;
// Left axis has 6 bit of resolution. While right axis has only 5 bits.
lx -= 32;
ly -= 32;
rx -= 16;
ry -= 16;
lx *= (AXIS_NORMALIZE_RANGE / 2 / 32);
ly *= (AXIS_NORMALIZE_RANGE / 2 / 32);
rx *= (AXIS_NORMALIZE_RANGE / 2 / 16);
ry *= (AXIS_NORMALIZE_RANGE / 2 / 16);
gp->axis_x = lx;
gp->axis_y = -ly;
gp->axis_rx = rx;
gp->axis_ry = -ry;
gp->updated_states |= GAMEPAD_STATE_AXIS_X | GAMEPAD_STATE_AXIS_Y |
GAMEPAD_STATE_AXIS_RX | GAMEPAD_STATE_AXIS_RY;
// Accel / Brake
int lt = (data[2] & 0b01100000) >> 2 | (data[3] & 0b11100000) >> 5;
int rt = data[3] & 0b00011111;
gp->brake = lt * (AXIS_NORMALIZE_RANGE / 32);
gp->accelerator = rt * (AXIS_NORMALIZE_RANGE / 32);
gp->updated_states |= GAMEPAD_STATE_BRAKE | GAMEPAD_STATE_ACCELERATOR;
// dpad
gp->dpad |= (data[4] & 0b10000000) ? 0 : DPAD_RIGHT;
gp->dpad |= (data[4] & 0b01000000) ? 0 : DPAD_DOWN;
gp->dpad |= (data[5] & 0b00000001) ? 0 : DPAD_UP;
gp->dpad |= (data[5] & 0b00000010) ? 0 : DPAD_LEFT;
gp->updated_states |= GAMEPAD_STATE_DPAD;
// Buttons A,B,X,Y
gp->buttons |= (data[5] & 0b01000000) ? 0 : BUTTON_A;
gp->buttons |= (data[5] & 0b00010000) ? 0 : BUTTON_B;
gp->buttons |= (data[5] & 0b00100000) ? 0 : BUTTON_X;
gp->buttons |= (data[5] & 0b00001000) ? 0 : BUTTON_Y;
gp->updated_states |= GAMEPAD_STATE_BUTTON_A | GAMEPAD_STATE_BUTTON_B |
GAMEPAD_STATE_BUTTON_X | GAMEPAD_STATE_BUTTON_Y;
// Shoulder / Trigger
gp->buttons |= (data[4] & 0b00100000) ? 0 : BUTTON_SHOULDER_L; // BLT
gp->buttons |= (data[4] & 0b00000010) ? 0 : BUTTON_SHOULDER_R; // BRT
gp->buttons |= (data[5] & 0b10000000) ? 0 : BUTTON_TRIGGER_L; // BZL
gp->buttons |= (data[5] & 0b00000100) ? 0 : BUTTON_TRIGGER_R; // BZR
gp->updated_states |=
GAMEPAD_STATE_BUTTON_SHOULDER_L | GAMEPAD_STATE_BUTTON_SHOULDER_R |
GAMEPAD_STATE_BUTTON_TRIGGER_L | GAMEPAD_STATE_BUTTON_TRIGGER_R;
// Buttons Misc
gp->misc_buttons |= (data[4] & 0b00001000) ? 0 : MISC_BUTTON_SYSTEM; // Home
gp->misc_buttons |= (data[4] & 0b00000100) ? 0 : MISC_BUTTON_HOME; // +
gp->misc_buttons |= (data[4] & 0b00010000) ? 0 : MISC_BUTTON_BACK; // -
gp->updated_states |= GAMEPAD_STATE_MISC_BUTTON_SYSTEM |
GAMEPAD_STATE_MISC_BUTTON_HOME |
GAMEPAD_STATE_MISC_BUTTON_BACK;
// printf("lx=%d, ly=%d, rx=%d, ry=%d, lt=%d, rt=%d\n", lx, ly, rx, ry, lt,
// rt);
// printf_hexdump(report, len);
}
// wii_fsm_ functions
static void wii_fsm_req_status(uni_hid_device_t* d) {
logi("fsm: req_status\n");
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_DID_REQ_STATUS;
const uint8_t status[] = {0xa2, WIIPROTO_REQ_SREQ, 0x00 /* rumble off */};
uni_hid_device_send_intr_report(d, status, sizeof(status));
}
static void wii_fsm_ext_init(uni_hid_device_t* d) {
logi("fsm: ext_init\n");
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_EXT_DID_INIT;
// Init Wii
uint8_t report[] = {
// clang-format off
0xa2, WIIPROTO_REQ_WMEM,
0x04, // Control registers
0xa4, 0x00, 0xf0, // register init extension
0x01, 0x55, // # bytes, byte to write
// Padding, since at least 16 bytes must be sent
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
// clang-format on
};
report[3] = ins->register_address;
uni_hid_device_send_intr_report(d, report, sizeof(report));
}
static void wii_fsm_ext_encrypt_off(uni_hid_device_t* d) {
logi("fsm: ext_encrypt_off\n");
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_EXT_DID_NO_ENCRYPTION;
// Init Wii
uint8_t report[] = {
// clang-format off
0xa2, WIIPROTO_REQ_WMEM,
0x04, // Control registers
0xa4, 0x00, 0xfb, // register disable encryption
0x01, 0x00, // # bytes, byte to write
// Padding, since at least 16 bytes must be sent
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00,
// clang-format on
};
report[3] = ins->register_address;
uni_hid_device_send_intr_report(d, report, sizeof(report));
}
static void wii_fsm_ext_read_register(uni_hid_device_t* d) {
logi("fsm: ext_read_register\n");
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_EXT_DID_READ_REGISTER;
// Addr is either 0xA400FA or 0xA600FA
uint32_t offset = 0x0000fa | (ins->register_address << 16);
uint16_t bytes_to_read = 6;
wii_read_mem(d, WII_READ_FROM_REGISTERS, offset, bytes_to_read);
}
static void wii_fsm_assign_device(uni_hid_device_t* d) {
logi("fsm: assign_device\n");
wii_instance_t* ins = get_wii_instance(d);
uint8_t dev = ins->dev_type;
switch (dev) {
case WII_DEVTYPE_UNK:
case WII_DEVTYPE_REMOTE:
case WII_DEVTYPE_REMOTE_MP: {
if (dev == WII_DEVTYPE_REMOTE) {
logi("Wii Remote detected.\n");
} else if (dev == WII_DEVTYPE_REMOTE_MP) {
logi("Wii Remote (2nd gen) Motion Plus detected.\n");
} else {
logi("Unknown Wii device detected. Treating it as Wii Remote.\n");
}
uint8_t reportType = 0xff;
if (ins->ext_type == WII_EXT_NUNCHUK) {
// Request Nunchuk data
if (ins->flags & WII_FLAGS_ACCEL) {
// Request Core buttons + Accel + extension (nunchuk)
reportType = WIIPROTO_REQ_DRM_KAE;
logi("Wii: requesting Core buttons + Accelerometer + E (Nunchuk)\n");
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_NCHKACCEL;
} else {
// Request Core buttons + extension (nunchuk)
reportType = WIIPROTO_REQ_DRM_KE;
logi("Wii: requesting Core buttons + E (Nunchuk)\n");
if (ins->flags == WII_FLAGS_VERTICAL) {
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_NCHK2JOYS;
} else {
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_NCHK;
}
}
} else if (ins->ext_type == WII_EXT_CLASSIC_CONTROLLER) {
logi("Wii: requesting E (Classic Controller)\n");
d->controller_subtype = CONTROLLER_SUBTYPE_WII_CLASSIC;
reportType = WIIPROTO_REQ_DRM_E;
} else {
if (ins->flags & WII_FLAGS_ACCEL) {
// Request Core buttons + accel
reportType = WIIPROTO_REQ_DRM_KA;
logi("Wii: requesting Core buttons + Accelerometer\n");
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_ACCEL;
} else {
reportType = WIIPROTO_REQ_DRM_K;
logi("Wii: requesting Core buttons\n");
if (ins->flags & WII_FLAGS_VERTICAL) {
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_VERT;
} else {
d->controller_subtype = CONTROLLER_SUBTYPE_WIIMOTE_HORIZ;
}
}
}
uint8_t report[] = {0xa2, WIIPROTO_REQ_DRM, 0x00, reportType};
uni_hid_device_send_intr_report(d, report, sizeof(report));
break;
}
case WII_DEVTYPE_PRO_CONTROLLER: {
logi("Wii U Pro controller detected.\n");
d->controller_subtype = CONTROLLER_SUBTYPE_WIIUPRO;
// 0x34 WIIPROTO_REQ_DRM_KEE (present in Wii U Pro controller)
const uint8_t reportKee[] = {0xa2, WIIPROTO_REQ_DRM, 0x00,
WIIPROTO_REQ_DRM_KEE};
uni_hid_device_send_intr_report(d, reportKee, sizeof(reportKee));
break;
}
}
ins->state = WII_FSM_DEV_ASSIGNED;
wii_process_fsm(d);
}
static void wii_fsm_update_led(uni_hid_device_t* d) {
logi("fsm: upload_led\n");
wii_instance_t* ins = get_wii_instance(d);
set_led(d, ins->gamepad_seat);
ins->state = WII_FSM_LED_UPDATED;
wii_process_fsm(d);
}
static void wii_fsm_dump_eeprom(struct uni_hid_device_s* d) {
#if ENABLE_EEPROM_DUMP
wii_instance_t* ins = get_wii_instance(d);
uint32_t addr = ins->debug_addr;
ins->state = WII_FSM_DUMP_EEPROM_IN_PROGRESS;
if (addr >= WII_DUMP_ROM_DATA_ADDR_END || ins->debug_fd < 0) {
ins->state = WII_FSM_DUMP_EEPROM_FINISHED;
close(ins->debug_fd);
wii_process_fsm(d);
return;
}
wii_read_mem(d, WII_READ_FROM_MEM, ins->debug_addr, WII_DUMP_ROM_DATA_SIZE);
ins->debug_addr += WII_DUMP_ROM_DATA_SIZE;
#else
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_DUMP_EEPROM_FINISHED;
wii_process_fsm(d);
#endif // ENABLE_EEPROM_DUMP
}
static void wii_process_fsm(uni_hid_device_t* d) {
wii_instance_t* ins = get_wii_instance(d);
switch (ins->state) {
case WII_FSM_SETUP:
case WII_FSM_DUMP_EEPROM_IN_PROGRESS:
wii_fsm_dump_eeprom(d);
break;
case WII_FSM_DUMP_EEPROM_FINISHED:
wii_fsm_req_status(d);
break;
case WII_FSM_DID_REQ_STATUS:
// Do nothing
break;
case WII_FSM_DEV_UNK:
case WII_FSM_EXT_UNK:
// Query extension
wii_fsm_ext_init(d);
break;
case WII_FSM_EXT_DID_INIT:
wii_fsm_ext_encrypt_off(d);
break;
case WII_FSM_EXT_DID_NO_ENCRYPTION:
wii_fsm_ext_read_register(d);
break;
case WII_FSM_EXT_DID_READ_REGISTER:
// Do nothing
break;
case WII_FSM_DEV_GUESSED:
wii_fsm_assign_device(d);
break;
case WII_FSM_DEV_ASSIGNED:
wii_fsm_update_led(d);
break;
case WII_FSM_LED_UPDATED:
break;
}
}
// uni_hid_ exported functions
void uni_hid_parser_wii_setup(uni_hid_device_t* d) {
wii_instance_t* ins = get_wii_instance(d);
ins->state = WII_FSM_SETUP;
// Start with 0xa40000 (all Wii devices, except for the Wii Remote Plus)
// If it fails it will use 0xa60000
ins->register_address = 0xa4;
// Dump EEPROM
#if ENABLE_EEPROM_DUMP
ins->debug_addr = WII_DUMP_ROM_DATA_ADDR_START;
ins->debug_fd = open("/tmp/wii_eeprom.bin", O_CREAT | O_RDWR);
if (ins->debug_fd < 0) {
loge("Wii: failed to create dump file");
}
#endif // ENABLE_EEPROM_DUMP
wii_process_fsm(d);
}
void uni_hid_parser_wii_init_report(uni_hid_device_t* d) {
// Reset old state. Each report contains a full-state.
d->gamepad.updated_states = 0;
d->gamepad.dpad = 0;
d->gamepad.buttons = 0;
d->gamepad.misc_buttons = 0;
}
void uni_hid_parser_wii_parse_raw(uni_hid_device_t* d, const uint8_t* report,
uint16_t len) {
if (len == 0) return;
switch (report[0]) {
case WIIPROTO_REQ_STATUS:
process_req_status(d, report, len);
break;
case WIIPROTO_REQ_DRM_K:
process_drm_k(d, report, len);
break;
case WIIPROTO_REQ_DRM_KA:
process_drm_ka(d, report, len);
break;
case WIIPROTO_REQ_DRM_KE:
process_drm_ke(d, report, len);
break;
case WIIPROTO_REQ_DRM_KAE:
process_drm_kae(d, report, len);
break;
case WIIPROTO_REQ_DRM_KEE:
process_drm_kee(d, report, len);
break;
case WIIPROTO_REQ_DRM_E:
process_drm_e(d, report, len);
break;
case WIIPROTO_REQ_DATA:
process_req_data(d, report, len);
break;
case WIIPROTO_REQ_RETURN:
process_req_return(d, report, len);
break;
default:
logi("Wii parser: unknown report type: 0x%02x\n", report[0]);
printf_hexdump(report, len);
}
}
void uni_hid_parser_wii_set_player_leds(uni_hid_device_t* d, uint8_t leds) {
if (d == NULL) {
loge("Wii: ERROR: Invalid device\n");
return;
}
wii_instance_t* ins = get_wii_instance(d);
// Always update gamepad_seat regarless of the state
ins->gamepad_seat = leds;
if (ins->state < WII_FSM_LED_UPDATED) return;
set_led(d, leds);
}
//
// Helpers
//
static wii_instance_t* get_wii_instance(uni_hid_device_t* d) {
return (wii_instance_t*)&d->parser_data[0];
}
static void set_led(uni_hid_device_t* d, uni_gamepad_seat_t seat) {
wii_instance_t* ins = get_wii_instance(d);
// Set LED to 1.
uint8_t report[] = {
0xa2, WIIPROTO_REQ_LED, 0x00 /* LED */
};
uint8_t led = seat << 4;
// If vertical mode is on, enable LED 4.
if (ins->flags & WII_FLAGS_VERTICAL) {
led |= 0x80;
}
// If accelerometer enabled, enable LED 3.
if (ins->flags & WII_FLAGS_ACCEL) {
led |= 0x40;
}
report[2] = led;
uni_hid_device_send_intr_report(d, report, sizeof(report));
}
static void wii_read_mem(uni_hid_device_t* d, wii_read_type_t t,
uint32_t offset, uint16_t size) {
logi("****** read_mem: offset=0x%04x, size=%d from=%d\n", offset, size, t);
uint8_t report[] = {
// clang-format off
0xa2, WIIPROTO_REQ_RMEM,
t, // Read from registers or memory
(offset & 0xff0000) >> 16, (offset & 0xff00) >> 8, (offset & 0xff), // Offset
(size & 0xff00) >> 8, (size & 0xff), // Size in bytes
// clang-format on
};
uni_hid_device_send_intr_report(d, report, sizeof(report));
}
| 36.177893 | 95 | 0.621473 |
a26d885486fba45f65942055b8365091d988ec6e | 46,031 | c | C | linux-2.6.16-unmod/crypto/twofish.c | ut-osa/syncchar | eba20da163260b6ae1ef3e334ad2137873a8d625 | [
"BSD-3-Clause"
] | null | null | null | linux-2.6.16-unmod/crypto/twofish.c | ut-osa/syncchar | eba20da163260b6ae1ef3e334ad2137873a8d625 | [
"BSD-3-Clause"
] | null | null | null | linux-2.6.16-unmod/crypto/twofish.c | ut-osa/syncchar | eba20da163260b6ae1ef3e334ad2137873a8d625 | [
"BSD-3-Clause"
] | 1 | 2019-05-14T16:36:45.000Z | 2019-05-14T16:36:45.000Z | /*
* Twofish for CryptoAPI
*
* Originally Twofish for GPG
* By Matthew Skala <mskala@ansuz.sooke.bc.ca>, July 26, 1998
* 256-bit key length added March 20, 1999
* Some modifications to reduce the text size by Werner Koch, April, 1998
* Ported to the kerneli patch by Marc Mutz <Marc@Mutz.com>
* Ported to CryptoAPI by Colin Slater <hoho@tacomeat.net>
*
* The original author has disclaimed all copyright interest in this
* code and thus put it in the public domain. The subsequent authors
* have put this under the GNU General Public License.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* This code is a "clean room" implementation, written from the paper
* _Twofish: A 128-Bit Block Cipher_ by Bruce Schneier, John Kelsey,
* Doug Whiting, David Wagner, Chris Hall, and Niels Ferguson, available
* through http://www.counterpane.com/twofish.html
*
* For background information on multiplication in finite fields, used for
* the matrix operations in the key schedule, see the book _Contemporary
* Abstract Algebra_ by Joseph A. Gallian, especially chapter 22 in the
* Third Edition.
*/
#include <asm/byteorder.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/crypto.h>
/* The large precomputed tables for the Twofish cipher (twofish.c)
* Taken from the same source as twofish.c
* Marc Mutz <Marc@Mutz.com>
*/
/* These two tables are the q0 and q1 permutations, exactly as described in
* the Twofish paper. */
static const u8 q0[256] = {
0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 0x9A, 0x92, 0x80, 0x78,
0xE4, 0xDD, 0xD1, 0x38, 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C,
0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 0xF2, 0xD0, 0x8B, 0x30,
0x84, 0x54, 0xDF, 0x23, 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82,
0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 0xA6, 0xEB, 0xA5, 0xBE,
0x16, 0x0C, 0xE3, 0x61, 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B,
0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 0xE1, 0xE6, 0xBD, 0x45,
0xE2, 0xF4, 0xB6, 0x66, 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7,
0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 0xEA, 0x77, 0x39, 0xAF,
0x33, 0xC9, 0x62, 0x71, 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8,
0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 0xA1, 0x1D, 0xAA, 0xED,
0x06, 0x70, 0xB2, 0xD2, 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90,
0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 0x9E, 0x9C, 0x52, 0x1B,
0x5F, 0x93, 0x0A, 0xEF, 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B,
0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 0x2A, 0xCE, 0xCB, 0x2F,
0xFC, 0x97, 0x05, 0x7A, 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A,
0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 0xB8, 0xDA, 0xB0, 0x17,
0x55, 0x1F, 0x8A, 0x7D, 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72,
0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 0x6E, 0x50, 0xDE, 0x68,
0x65, 0xBC, 0xDB, 0xF8, 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4,
0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 0x6F, 0x9D, 0x36, 0x42,
0x4A, 0x5E, 0xC1, 0xE0
};
static const u8 q1[256] = {
0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 0x4A, 0xD3, 0xE6, 0x6B,
0x45, 0x7D, 0xE8, 0x4B, 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1,
0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 0x5E, 0xBA, 0xAE, 0x5B,
0x8A, 0x00, 0xBC, 0x9D, 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5,
0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 0xB2, 0x73, 0x4C, 0x54,
0x92, 0x74, 0x36, 0x51, 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96,
0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 0x13, 0x95, 0x9C, 0xC7,
0x24, 0x46, 0x3B, 0x70, 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8,
0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 0x03, 0x6F, 0x08, 0xBF,
0x40, 0xE7, 0x2B, 0xE2, 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9,
0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 0x66, 0x94, 0xA1, 0x1D,
0x3D, 0xF0, 0xDE, 0xB3, 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E,
0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 0x81, 0x88, 0xEE, 0x21,
0xC4, 0x1A, 0xEB, 0xD9, 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01,
0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 0x4F, 0xF2, 0x65, 0x8E,
0x78, 0x5C, 0x58, 0x19, 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64,
0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 0xCE, 0xE9, 0x68, 0x44,
0xE0, 0x4D, 0x43, 0x69, 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E,
0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 0x22, 0xC9, 0xC0, 0x9B,
0x89, 0xD4, 0xED, 0xAB, 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9,
0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 0x16, 0x25, 0x86, 0x56,
0x55, 0x09, 0xBE, 0x91
};
/* These MDS tables are actually tables of MDS composed with q0 and q1,
* because it is only ever used that way and we can save some time by
* precomputing. Of course the main saving comes from precomputing the
* GF(2^8) multiplication involved in the MDS matrix multiply; by looking
* things up in these tables we reduce the matrix multiply to four lookups
* and three XORs. Semi-formally, the definition of these tables is:
* mds[0][i] = MDS (q1[i] 0 0 0)^T mds[1][i] = MDS (0 q0[i] 0 0)^T
* mds[2][i] = MDS (0 0 q1[i] 0)^T mds[3][i] = MDS (0 0 0 q0[i])^T
* where ^T means "transpose", the matrix multiply is performed in GF(2^8)
* represented as GF(2)[x]/v(x) where v(x)=x^8+x^6+x^5+x^3+1 as described
* by Schneier et al, and I'm casually glossing over the byte/word
* conversion issues. */
static const u32 mds[4][256] = {
{0xBCBC3275, 0xECEC21F3, 0x202043C6, 0xB3B3C9F4, 0xDADA03DB, 0x02028B7B,
0xE2E22BFB, 0x9E9EFAC8, 0xC9C9EC4A, 0xD4D409D3, 0x18186BE6, 0x1E1E9F6B,
0x98980E45, 0xB2B2387D, 0xA6A6D2E8, 0x2626B74B, 0x3C3C57D6, 0x93938A32,
0x8282EED8, 0x525298FD, 0x7B7BD437, 0xBBBB3771, 0x5B5B97F1, 0x474783E1,
0x24243C30, 0x5151E20F, 0xBABAC6F8, 0x4A4AF31B, 0xBFBF4887, 0x0D0D70FA,
0xB0B0B306, 0x7575DE3F, 0xD2D2FD5E, 0x7D7D20BA, 0x666631AE, 0x3A3AA35B,
0x59591C8A, 0x00000000, 0xCDCD93BC, 0x1A1AE09D, 0xAEAE2C6D, 0x7F7FABC1,
0x2B2BC7B1, 0xBEBEB90E, 0xE0E0A080, 0x8A8A105D, 0x3B3B52D2, 0x6464BAD5,
0xD8D888A0, 0xE7E7A584, 0x5F5FE807, 0x1B1B1114, 0x2C2CC2B5, 0xFCFCB490,
0x3131272C, 0x808065A3, 0x73732AB2, 0x0C0C8173, 0x79795F4C, 0x6B6B4154,
0x4B4B0292, 0x53536974, 0x94948F36, 0x83831F51, 0x2A2A3638, 0xC4C49CB0,
0x2222C8BD, 0xD5D5F85A, 0xBDBDC3FC, 0x48487860, 0xFFFFCE62, 0x4C4C0796,
0x4141776C, 0xC7C7E642, 0xEBEB24F7, 0x1C1C1410, 0x5D5D637C, 0x36362228,
0x6767C027, 0xE9E9AF8C, 0x4444F913, 0x1414EA95, 0xF5F5BB9C, 0xCFCF18C7,
0x3F3F2D24, 0xC0C0E346, 0x7272DB3B, 0x54546C70, 0x29294CCA, 0xF0F035E3,
0x0808FE85, 0xC6C617CB, 0xF3F34F11, 0x8C8CE4D0, 0xA4A45993, 0xCACA96B8,
0x68683BA6, 0xB8B84D83, 0x38382820, 0xE5E52EFF, 0xADAD569F, 0x0B0B8477,
0xC8C81DC3, 0x9999FFCC, 0x5858ED03, 0x19199A6F, 0x0E0E0A08, 0x95957EBF,
0x70705040, 0xF7F730E7, 0x6E6ECF2B, 0x1F1F6EE2, 0xB5B53D79, 0x09090F0C,
0x616134AA, 0x57571682, 0x9F9F0B41, 0x9D9D803A, 0x111164EA, 0x2525CDB9,
0xAFAFDDE4, 0x4545089A, 0xDFDF8DA4, 0xA3A35C97, 0xEAEAD57E, 0x353558DA,
0xEDEDD07A, 0x4343FC17, 0xF8F8CB66, 0xFBFBB194, 0x3737D3A1, 0xFAFA401D,
0xC2C2683D, 0xB4B4CCF0, 0x32325DDE, 0x9C9C71B3, 0x5656E70B, 0xE3E3DA72,
0x878760A7, 0x15151B1C, 0xF9F93AEF, 0x6363BFD1, 0x3434A953, 0x9A9A853E,
0xB1B1428F, 0x7C7CD133, 0x88889B26, 0x3D3DA65F, 0xA1A1D7EC, 0xE4E4DF76,
0x8181942A, 0x91910149, 0x0F0FFB81, 0xEEEEAA88, 0x161661EE, 0xD7D77321,
0x9797F5C4, 0xA5A5A81A, 0xFEFE3FEB, 0x6D6DB5D9, 0x7878AEC5, 0xC5C56D39,
0x1D1DE599, 0x7676A4CD, 0x3E3EDCAD, 0xCBCB6731, 0xB6B6478B, 0xEFEF5B01,
0x12121E18, 0x6060C523, 0x6A6AB0DD, 0x4D4DF61F, 0xCECEE94E, 0xDEDE7C2D,
0x55559DF9, 0x7E7E5A48, 0x2121B24F, 0x03037AF2, 0xA0A02665, 0x5E5E198E,
0x5A5A6678, 0x65654B5C, 0x62624E58, 0xFDFD4519, 0x0606F48D, 0x404086E5,
0xF2F2BE98, 0x3333AC57, 0x17179067, 0x05058E7F, 0xE8E85E05, 0x4F4F7D64,
0x89896AAF, 0x10109563, 0x74742FB6, 0x0A0A75FE, 0x5C5C92F5, 0x9B9B74B7,
0x2D2D333C, 0x3030D6A5, 0x2E2E49CE, 0x494989E9, 0x46467268, 0x77775544,
0xA8A8D8E0, 0x9696044D, 0x2828BD43, 0xA9A92969, 0xD9D97929, 0x8686912E,
0xD1D187AC, 0xF4F44A15, 0x8D8D1559, 0xD6D682A8, 0xB9B9BC0A, 0x42420D9E,
0xF6F6C16E, 0x2F2FB847, 0xDDDD06DF, 0x23233934, 0xCCCC6235, 0xF1F1C46A,
0xC1C112CF, 0x8585EBDC, 0x8F8F9E22, 0x7171A1C9, 0x9090F0C0, 0xAAAA539B,
0x0101F189, 0x8B8BE1D4, 0x4E4E8CED, 0x8E8E6FAB, 0xABABA212, 0x6F6F3EA2,
0xE6E6540D, 0xDBDBF252, 0x92927BBB, 0xB7B7B602, 0x6969CA2F, 0x3939D9A9,
0xD3D30CD7, 0xA7A72361, 0xA2A2AD1E, 0xC3C399B4, 0x6C6C4450, 0x07070504,
0x04047FF6, 0x272746C2, 0xACACA716, 0xD0D07625, 0x50501386, 0xDCDCF756,
0x84841A55, 0xE1E15109, 0x7A7A25BE, 0x1313EF91},
{0xA9D93939, 0x67901717, 0xB3719C9C, 0xE8D2A6A6, 0x04050707, 0xFD985252,
0xA3658080, 0x76DFE4E4, 0x9A084545, 0x92024B4B, 0x80A0E0E0, 0x78665A5A,
0xE4DDAFAF, 0xDDB06A6A, 0xD1BF6363, 0x38362A2A, 0x0D54E6E6, 0xC6432020,
0x3562CCCC, 0x98BEF2F2, 0x181E1212, 0xF724EBEB, 0xECD7A1A1, 0x6C774141,
0x43BD2828, 0x7532BCBC, 0x37D47B7B, 0x269B8888, 0xFA700D0D, 0x13F94444,
0x94B1FBFB, 0x485A7E7E, 0xF27A0303, 0xD0E48C8C, 0x8B47B6B6, 0x303C2424,
0x84A5E7E7, 0x54416B6B, 0xDF06DDDD, 0x23C56060, 0x1945FDFD, 0x5BA33A3A,
0x3D68C2C2, 0x59158D8D, 0xF321ECEC, 0xAE316666, 0xA23E6F6F, 0x82165757,
0x63951010, 0x015BEFEF, 0x834DB8B8, 0x2E918686, 0xD9B56D6D, 0x511F8383,
0x9B53AAAA, 0x7C635D5D, 0xA63B6868, 0xEB3FFEFE, 0xA5D63030, 0xBE257A7A,
0x16A7ACAC, 0x0C0F0909, 0xE335F0F0, 0x6123A7A7, 0xC0F09090, 0x8CAFE9E9,
0x3A809D9D, 0xF5925C5C, 0x73810C0C, 0x2C273131, 0x2576D0D0, 0x0BE75656,
0xBB7B9292, 0x4EE9CECE, 0x89F10101, 0x6B9F1E1E, 0x53A93434, 0x6AC4F1F1,
0xB499C3C3, 0xF1975B5B, 0xE1834747, 0xE66B1818, 0xBDC82222, 0x450E9898,
0xE26E1F1F, 0xF4C9B3B3, 0xB62F7474, 0x66CBF8F8, 0xCCFF9999, 0x95EA1414,
0x03ED5858, 0x56F7DCDC, 0xD4E18B8B, 0x1C1B1515, 0x1EADA2A2, 0xD70CD3D3,
0xFB2BE2E2, 0xC31DC8C8, 0x8E195E5E, 0xB5C22C2C, 0xE9894949, 0xCF12C1C1,
0xBF7E9595, 0xBA207D7D, 0xEA641111, 0x77840B0B, 0x396DC5C5, 0xAF6A8989,
0x33D17C7C, 0xC9A17171, 0x62CEFFFF, 0x7137BBBB, 0x81FB0F0F, 0x793DB5B5,
0x0951E1E1, 0xADDC3E3E, 0x242D3F3F, 0xCDA47676, 0xF99D5555, 0xD8EE8282,
0xE5864040, 0xC5AE7878, 0xB9CD2525, 0x4D049696, 0x44557777, 0x080A0E0E,
0x86135050, 0xE730F7F7, 0xA1D33737, 0x1D40FAFA, 0xAA346161, 0xED8C4E4E,
0x06B3B0B0, 0x706C5454, 0xB22A7373, 0xD2523B3B, 0x410B9F9F, 0x7B8B0202,
0xA088D8D8, 0x114FF3F3, 0x3167CBCB, 0xC2462727, 0x27C06767, 0x90B4FCFC,
0x20283838, 0xF67F0404, 0x60784848, 0xFF2EE5E5, 0x96074C4C, 0x5C4B6565,
0xB1C72B2B, 0xAB6F8E8E, 0x9E0D4242, 0x9CBBF5F5, 0x52F2DBDB, 0x1BF34A4A,
0x5FA63D3D, 0x9359A4A4, 0x0ABCB9B9, 0xEF3AF9F9, 0x91EF1313, 0x85FE0808,
0x49019191, 0xEE611616, 0x2D7CDEDE, 0x4FB22121, 0x8F42B1B1, 0x3BDB7272,
0x47B82F2F, 0x8748BFBF, 0x6D2CAEAE, 0x46E3C0C0, 0xD6573C3C, 0x3E859A9A,
0x6929A9A9, 0x647D4F4F, 0x2A948181, 0xCE492E2E, 0xCB17C6C6, 0x2FCA6969,
0xFCC3BDBD, 0x975CA3A3, 0x055EE8E8, 0x7AD0EDED, 0xAC87D1D1, 0x7F8E0505,
0xD5BA6464, 0x1AA8A5A5, 0x4BB72626, 0x0EB9BEBE, 0xA7608787, 0x5AF8D5D5,
0x28223636, 0x14111B1B, 0x3FDE7575, 0x2979D9D9, 0x88AAEEEE, 0x3C332D2D,
0x4C5F7979, 0x02B6B7B7, 0xB896CACA, 0xDA583535, 0xB09CC4C4, 0x17FC4343,
0x551A8484, 0x1FF64D4D, 0x8A1C5959, 0x7D38B2B2, 0x57AC3333, 0xC718CFCF,
0x8DF40606, 0x74695353, 0xB7749B9B, 0xC4F59797, 0x9F56ADAD, 0x72DAE3E3,
0x7ED5EAEA, 0x154AF4F4, 0x229E8F8F, 0x12A2ABAB, 0x584E6262, 0x07E85F5F,
0x99E51D1D, 0x34392323, 0x6EC1F6F6, 0x50446C6C, 0xDE5D3232, 0x68724646,
0x6526A0A0, 0xBC93CDCD, 0xDB03DADA, 0xF8C6BABA, 0xC8FA9E9E, 0xA882D6D6,
0x2BCF6E6E, 0x40507070, 0xDCEB8585, 0xFE750A0A, 0x328A9393, 0xA48DDFDF,
0xCA4C2929, 0x10141C1C, 0x2173D7D7, 0xF0CCB4B4, 0xD309D4D4, 0x5D108A8A,
0x0FE25151, 0x00000000, 0x6F9A1919, 0x9DE01A1A, 0x368F9494, 0x42E6C7C7,
0x4AECC9C9, 0x5EFDD2D2, 0xC1AB7F7F, 0xE0D8A8A8},
{0xBC75BC32, 0xECF3EC21, 0x20C62043, 0xB3F4B3C9, 0xDADBDA03, 0x027B028B,
0xE2FBE22B, 0x9EC89EFA, 0xC94AC9EC, 0xD4D3D409, 0x18E6186B, 0x1E6B1E9F,
0x9845980E, 0xB27DB238, 0xA6E8A6D2, 0x264B26B7, 0x3CD63C57, 0x9332938A,
0x82D882EE, 0x52FD5298, 0x7B377BD4, 0xBB71BB37, 0x5BF15B97, 0x47E14783,
0x2430243C, 0x510F51E2, 0xBAF8BAC6, 0x4A1B4AF3, 0xBF87BF48, 0x0DFA0D70,
0xB006B0B3, 0x753F75DE, 0xD25ED2FD, 0x7DBA7D20, 0x66AE6631, 0x3A5B3AA3,
0x598A591C, 0x00000000, 0xCDBCCD93, 0x1A9D1AE0, 0xAE6DAE2C, 0x7FC17FAB,
0x2BB12BC7, 0xBE0EBEB9, 0xE080E0A0, 0x8A5D8A10, 0x3BD23B52, 0x64D564BA,
0xD8A0D888, 0xE784E7A5, 0x5F075FE8, 0x1B141B11, 0x2CB52CC2, 0xFC90FCB4,
0x312C3127, 0x80A38065, 0x73B2732A, 0x0C730C81, 0x794C795F, 0x6B546B41,
0x4B924B02, 0x53745369, 0x9436948F, 0x8351831F, 0x2A382A36, 0xC4B0C49C,
0x22BD22C8, 0xD55AD5F8, 0xBDFCBDC3, 0x48604878, 0xFF62FFCE, 0x4C964C07,
0x416C4177, 0xC742C7E6, 0xEBF7EB24, 0x1C101C14, 0x5D7C5D63, 0x36283622,
0x672767C0, 0xE98CE9AF, 0x441344F9, 0x149514EA, 0xF59CF5BB, 0xCFC7CF18,
0x3F243F2D, 0xC046C0E3, 0x723B72DB, 0x5470546C, 0x29CA294C, 0xF0E3F035,
0x088508FE, 0xC6CBC617, 0xF311F34F, 0x8CD08CE4, 0xA493A459, 0xCAB8CA96,
0x68A6683B, 0xB883B84D, 0x38203828, 0xE5FFE52E, 0xAD9FAD56, 0x0B770B84,
0xC8C3C81D, 0x99CC99FF, 0x580358ED, 0x196F199A, 0x0E080E0A, 0x95BF957E,
0x70407050, 0xF7E7F730, 0x6E2B6ECF, 0x1FE21F6E, 0xB579B53D, 0x090C090F,
0x61AA6134, 0x57825716, 0x9F419F0B, 0x9D3A9D80, 0x11EA1164, 0x25B925CD,
0xAFE4AFDD, 0x459A4508, 0xDFA4DF8D, 0xA397A35C, 0xEA7EEAD5, 0x35DA3558,
0xED7AEDD0, 0x431743FC, 0xF866F8CB, 0xFB94FBB1, 0x37A137D3, 0xFA1DFA40,
0xC23DC268, 0xB4F0B4CC, 0x32DE325D, 0x9CB39C71, 0x560B56E7, 0xE372E3DA,
0x87A78760, 0x151C151B, 0xF9EFF93A, 0x63D163BF, 0x345334A9, 0x9A3E9A85,
0xB18FB142, 0x7C337CD1, 0x8826889B, 0x3D5F3DA6, 0xA1ECA1D7, 0xE476E4DF,
0x812A8194, 0x91499101, 0x0F810FFB, 0xEE88EEAA, 0x16EE1661, 0xD721D773,
0x97C497F5, 0xA51AA5A8, 0xFEEBFE3F, 0x6DD96DB5, 0x78C578AE, 0xC539C56D,
0x1D991DE5, 0x76CD76A4, 0x3EAD3EDC, 0xCB31CB67, 0xB68BB647, 0xEF01EF5B,
0x1218121E, 0x602360C5, 0x6ADD6AB0, 0x4D1F4DF6, 0xCE4ECEE9, 0xDE2DDE7C,
0x55F9559D, 0x7E487E5A, 0x214F21B2, 0x03F2037A, 0xA065A026, 0x5E8E5E19,
0x5A785A66, 0x655C654B, 0x6258624E, 0xFD19FD45, 0x068D06F4, 0x40E54086,
0xF298F2BE, 0x335733AC, 0x17671790, 0x057F058E, 0xE805E85E, 0x4F644F7D,
0x89AF896A, 0x10631095, 0x74B6742F, 0x0AFE0A75, 0x5CF55C92, 0x9BB79B74,
0x2D3C2D33, 0x30A530D6, 0x2ECE2E49, 0x49E94989, 0x46684672, 0x77447755,
0xA8E0A8D8, 0x964D9604, 0x284328BD, 0xA969A929, 0xD929D979, 0x862E8691,
0xD1ACD187, 0xF415F44A, 0x8D598D15, 0xD6A8D682, 0xB90AB9BC, 0x429E420D,
0xF66EF6C1, 0x2F472FB8, 0xDDDFDD06, 0x23342339, 0xCC35CC62, 0xF16AF1C4,
0xC1CFC112, 0x85DC85EB, 0x8F228F9E, 0x71C971A1, 0x90C090F0, 0xAA9BAA53,
0x018901F1, 0x8BD48BE1, 0x4EED4E8C, 0x8EAB8E6F, 0xAB12ABA2, 0x6FA26F3E,
0xE60DE654, 0xDB52DBF2, 0x92BB927B, 0xB702B7B6, 0x692F69CA, 0x39A939D9,
0xD3D7D30C, 0xA761A723, 0xA21EA2AD, 0xC3B4C399, 0x6C506C44, 0x07040705,
0x04F6047F, 0x27C22746, 0xAC16ACA7, 0xD025D076, 0x50865013, 0xDC56DCF7,
0x8455841A, 0xE109E151, 0x7ABE7A25, 0x139113EF},
{0xD939A9D9, 0x90176790, 0x719CB371, 0xD2A6E8D2, 0x05070405, 0x9852FD98,
0x6580A365, 0xDFE476DF, 0x08459A08, 0x024B9202, 0xA0E080A0, 0x665A7866,
0xDDAFE4DD, 0xB06ADDB0, 0xBF63D1BF, 0x362A3836, 0x54E60D54, 0x4320C643,
0x62CC3562, 0xBEF298BE, 0x1E12181E, 0x24EBF724, 0xD7A1ECD7, 0x77416C77,
0xBD2843BD, 0x32BC7532, 0xD47B37D4, 0x9B88269B, 0x700DFA70, 0xF94413F9,
0xB1FB94B1, 0x5A7E485A, 0x7A03F27A, 0xE48CD0E4, 0x47B68B47, 0x3C24303C,
0xA5E784A5, 0x416B5441, 0x06DDDF06, 0xC56023C5, 0x45FD1945, 0xA33A5BA3,
0x68C23D68, 0x158D5915, 0x21ECF321, 0x3166AE31, 0x3E6FA23E, 0x16578216,
0x95106395, 0x5BEF015B, 0x4DB8834D, 0x91862E91, 0xB56DD9B5, 0x1F83511F,
0x53AA9B53, 0x635D7C63, 0x3B68A63B, 0x3FFEEB3F, 0xD630A5D6, 0x257ABE25,
0xA7AC16A7, 0x0F090C0F, 0x35F0E335, 0x23A76123, 0xF090C0F0, 0xAFE98CAF,
0x809D3A80, 0x925CF592, 0x810C7381, 0x27312C27, 0x76D02576, 0xE7560BE7,
0x7B92BB7B, 0xE9CE4EE9, 0xF10189F1, 0x9F1E6B9F, 0xA93453A9, 0xC4F16AC4,
0x99C3B499, 0x975BF197, 0x8347E183, 0x6B18E66B, 0xC822BDC8, 0x0E98450E,
0x6E1FE26E, 0xC9B3F4C9, 0x2F74B62F, 0xCBF866CB, 0xFF99CCFF, 0xEA1495EA,
0xED5803ED, 0xF7DC56F7, 0xE18BD4E1, 0x1B151C1B, 0xADA21EAD, 0x0CD3D70C,
0x2BE2FB2B, 0x1DC8C31D, 0x195E8E19, 0xC22CB5C2, 0x8949E989, 0x12C1CF12,
0x7E95BF7E, 0x207DBA20, 0x6411EA64, 0x840B7784, 0x6DC5396D, 0x6A89AF6A,
0xD17C33D1, 0xA171C9A1, 0xCEFF62CE, 0x37BB7137, 0xFB0F81FB, 0x3DB5793D,
0x51E10951, 0xDC3EADDC, 0x2D3F242D, 0xA476CDA4, 0x9D55F99D, 0xEE82D8EE,
0x8640E586, 0xAE78C5AE, 0xCD25B9CD, 0x04964D04, 0x55774455, 0x0A0E080A,
0x13508613, 0x30F7E730, 0xD337A1D3, 0x40FA1D40, 0x3461AA34, 0x8C4EED8C,
0xB3B006B3, 0x6C54706C, 0x2A73B22A, 0x523BD252, 0x0B9F410B, 0x8B027B8B,
0x88D8A088, 0x4FF3114F, 0x67CB3167, 0x4627C246, 0xC06727C0, 0xB4FC90B4,
0x28382028, 0x7F04F67F, 0x78486078, 0x2EE5FF2E, 0x074C9607, 0x4B655C4B,
0xC72BB1C7, 0x6F8EAB6F, 0x0D429E0D, 0xBBF59CBB, 0xF2DB52F2, 0xF34A1BF3,
0xA63D5FA6, 0x59A49359, 0xBCB90ABC, 0x3AF9EF3A, 0xEF1391EF, 0xFE0885FE,
0x01914901, 0x6116EE61, 0x7CDE2D7C, 0xB2214FB2, 0x42B18F42, 0xDB723BDB,
0xB82F47B8, 0x48BF8748, 0x2CAE6D2C, 0xE3C046E3, 0x573CD657, 0x859A3E85,
0x29A96929, 0x7D4F647D, 0x94812A94, 0x492ECE49, 0x17C6CB17, 0xCA692FCA,
0xC3BDFCC3, 0x5CA3975C, 0x5EE8055E, 0xD0ED7AD0, 0x87D1AC87, 0x8E057F8E,
0xBA64D5BA, 0xA8A51AA8, 0xB7264BB7, 0xB9BE0EB9, 0x6087A760, 0xF8D55AF8,
0x22362822, 0x111B1411, 0xDE753FDE, 0x79D92979, 0xAAEE88AA, 0x332D3C33,
0x5F794C5F, 0xB6B702B6, 0x96CAB896, 0x5835DA58, 0x9CC4B09C, 0xFC4317FC,
0x1A84551A, 0xF64D1FF6, 0x1C598A1C, 0x38B27D38, 0xAC3357AC, 0x18CFC718,
0xF4068DF4, 0x69537469, 0x749BB774, 0xF597C4F5, 0x56AD9F56, 0xDAE372DA,
0xD5EA7ED5, 0x4AF4154A, 0x9E8F229E, 0xA2AB12A2, 0x4E62584E, 0xE85F07E8,
0xE51D99E5, 0x39233439, 0xC1F66EC1, 0x446C5044, 0x5D32DE5D, 0x72466872,
0x26A06526, 0x93CDBC93, 0x03DADB03, 0xC6BAF8C6, 0xFA9EC8FA, 0x82D6A882,
0xCF6E2BCF, 0x50704050, 0xEB85DCEB, 0x750AFE75, 0x8A93328A, 0x8DDFA48D,
0x4C29CA4C, 0x141C1014, 0x73D72173, 0xCCB4F0CC, 0x09D4D309, 0x108A5D10,
0xE2510FE2, 0x00000000, 0x9A196F9A, 0xE01A9DE0, 0x8F94368F, 0xE6C742E6,
0xECC94AEC, 0xFDD25EFD, 0xAB7FC1AB, 0xD8A8E0D8}
};
/* The exp_to_poly and poly_to_exp tables are used to perform efficient
* operations in GF(2^8) represented as GF(2)[x]/w(x) where
* w(x)=x^8+x^6+x^3+x^2+1. We care about doing that because it's part of the
* definition of the RS matrix in the key schedule. Elements of that field
* are polynomials of degree not greater than 7 and all coefficients 0 or 1,
* which can be represented naturally by bytes (just substitute x=2). In that
* form, GF(2^8) addition is the same as bitwise XOR, but GF(2^8)
* multiplication is inefficient without hardware support. To multiply
* faster, I make use of the fact x is a generator for the nonzero elements,
* so that every element p of GF(2)[x]/w(x) is either 0 or equal to (x)^n for
* some n in 0..254. Note that that caret is exponentiation in GF(2^8),
* *not* polynomial notation. So if I want to compute pq where p and q are
* in GF(2^8), I can just say:
* 1. if p=0 or q=0 then pq=0
* 2. otherwise, find m and n such that p=x^m and q=x^n
* 3. pq=(x^m)(x^n)=x^(m+n), so add m and n and find pq
* The translations in steps 2 and 3 are looked up in the tables
* poly_to_exp (for step 2) and exp_to_poly (for step 3). To see this
* in action, look at the CALC_S macro. As additional wrinkles, note that
* one of my operands is always a constant, so the poly_to_exp lookup on it
* is done in advance; I included the original values in the comments so
* readers can have some chance of recognizing that this *is* the RS matrix
* from the Twofish paper. I've only included the table entries I actually
* need; I never do a lookup on a variable input of zero and the biggest
* exponents I'll ever see are 254 (variable) and 237 (constant), so they'll
* never sum to more than 491. I'm repeating part of the exp_to_poly table
* so that I don't have to do mod-255 reduction in the exponent arithmetic.
* Since I know my constant operands are never zero, I only have to worry
* about zero values in the variable operand, and I do it with a simple
* conditional branch. I know conditionals are expensive, but I couldn't
* see a non-horrible way of avoiding them, and I did manage to group the
* statements so that each if covers four group multiplications. */
static const u8 poly_to_exp[255] = {
0x00, 0x01, 0x17, 0x02, 0x2E, 0x18, 0x53, 0x03, 0x6A, 0x2F, 0x93, 0x19,
0x34, 0x54, 0x45, 0x04, 0x5C, 0x6B, 0xB6, 0x30, 0xA6, 0x94, 0x4B, 0x1A,
0x8C, 0x35, 0x81, 0x55, 0xAA, 0x46, 0x0D, 0x05, 0x24, 0x5D, 0x87, 0x6C,
0x9B, 0xB7, 0xC1, 0x31, 0x2B, 0xA7, 0xA3, 0x95, 0x98, 0x4C, 0xCA, 0x1B,
0xE6, 0x8D, 0x73, 0x36, 0xCD, 0x82, 0x12, 0x56, 0x62, 0xAB, 0xF0, 0x47,
0x4F, 0x0E, 0xBD, 0x06, 0xD4, 0x25, 0xD2, 0x5E, 0x27, 0x88, 0x66, 0x6D,
0xD6, 0x9C, 0x79, 0xB8, 0x08, 0xC2, 0xDF, 0x32, 0x68, 0x2C, 0xFD, 0xA8,
0x8A, 0xA4, 0x5A, 0x96, 0x29, 0x99, 0x22, 0x4D, 0x60, 0xCB, 0xE4, 0x1C,
0x7B, 0xE7, 0x3B, 0x8E, 0x9E, 0x74, 0xF4, 0x37, 0xD8, 0xCE, 0xF9, 0x83,
0x6F, 0x13, 0xB2, 0x57, 0xE1, 0x63, 0xDC, 0xAC, 0xC4, 0xF1, 0xAF, 0x48,
0x0A, 0x50, 0x42, 0x0F, 0xBA, 0xBE, 0xC7, 0x07, 0xDE, 0xD5, 0x78, 0x26,
0x65, 0xD3, 0xD1, 0x5F, 0xE3, 0x28, 0x21, 0x89, 0x59, 0x67, 0xFC, 0x6E,
0xB1, 0xD7, 0xF8, 0x9D, 0xF3, 0x7A, 0x3A, 0xB9, 0xC6, 0x09, 0x41, 0xC3,
0xAE, 0xE0, 0xDB, 0x33, 0x44, 0x69, 0x92, 0x2D, 0x52, 0xFE, 0x16, 0xA9,
0x0C, 0x8B, 0x80, 0xA5, 0x4A, 0x5B, 0xB5, 0x97, 0xC9, 0x2A, 0xA2, 0x9A,
0xC0, 0x23, 0x86, 0x4E, 0xBC, 0x61, 0xEF, 0xCC, 0x11, 0xE5, 0x72, 0x1D,
0x3D, 0x7C, 0xEB, 0xE8, 0xE9, 0x3C, 0xEA, 0x8F, 0x7D, 0x9F, 0xEC, 0x75,
0x1E, 0xF5, 0x3E, 0x38, 0xF6, 0xD9, 0x3F, 0xCF, 0x76, 0xFA, 0x1F, 0x84,
0xA0, 0x70, 0xED, 0x14, 0x90, 0xB3, 0x7E, 0x58, 0xFB, 0xE2, 0x20, 0x64,
0xD0, 0xDD, 0x77, 0xAD, 0xDA, 0xC5, 0x40, 0xF2, 0x39, 0xB0, 0xF7, 0x49,
0xB4, 0x0B, 0x7F, 0x51, 0x15, 0x43, 0x91, 0x10, 0x71, 0xBB, 0xEE, 0xBF,
0x85, 0xC8, 0xA1
};
static const u8 exp_to_poly[492] = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x4D, 0x9A, 0x79, 0xF2,
0xA9, 0x1F, 0x3E, 0x7C, 0xF8, 0xBD, 0x37, 0x6E, 0xDC, 0xF5, 0xA7, 0x03,
0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xCD, 0xD7, 0xE3, 0x8B, 0x5B, 0xB6,
0x21, 0x42, 0x84, 0x45, 0x8A, 0x59, 0xB2, 0x29, 0x52, 0xA4, 0x05, 0x0A,
0x14, 0x28, 0x50, 0xA0, 0x0D, 0x1A, 0x34, 0x68, 0xD0, 0xED, 0x97, 0x63,
0xC6, 0xC1, 0xCF, 0xD3, 0xEB, 0x9B, 0x7B, 0xF6, 0xA1, 0x0F, 0x1E, 0x3C,
0x78, 0xF0, 0xAD, 0x17, 0x2E, 0x5C, 0xB8, 0x3D, 0x7A, 0xF4, 0xA5, 0x07,
0x0E, 0x1C, 0x38, 0x70, 0xE0, 0x8D, 0x57, 0xAE, 0x11, 0x22, 0x44, 0x88,
0x5D, 0xBA, 0x39, 0x72, 0xE4, 0x85, 0x47, 0x8E, 0x51, 0xA2, 0x09, 0x12,
0x24, 0x48, 0x90, 0x6D, 0xDA, 0xF9, 0xBF, 0x33, 0x66, 0xCC, 0xD5, 0xE7,
0x83, 0x4B, 0x96, 0x61, 0xC2, 0xC9, 0xDF, 0xF3, 0xAB, 0x1B, 0x36, 0x6C,
0xD8, 0xFD, 0xB7, 0x23, 0x46, 0x8C, 0x55, 0xAA, 0x19, 0x32, 0x64, 0xC8,
0xDD, 0xF7, 0xA3, 0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x2D, 0x5A, 0xB4, 0x25,
0x4A, 0x94, 0x65, 0xCA, 0xD9, 0xFF, 0xB3, 0x2B, 0x56, 0xAC, 0x15, 0x2A,
0x54, 0xA8, 0x1D, 0x3A, 0x74, 0xE8, 0x9D, 0x77, 0xEE, 0x91, 0x6F, 0xDE,
0xF1, 0xAF, 0x13, 0x26, 0x4C, 0x98, 0x7D, 0xFA, 0xB9, 0x3F, 0x7E, 0xFC,
0xB5, 0x27, 0x4E, 0x9C, 0x75, 0xEA, 0x99, 0x7F, 0xFE, 0xB1, 0x2F, 0x5E,
0xBC, 0x35, 0x6A, 0xD4, 0xE5, 0x87, 0x43, 0x86, 0x41, 0x82, 0x49, 0x92,
0x69, 0xD2, 0xE9, 0x9F, 0x73, 0xE6, 0x81, 0x4F, 0x9E, 0x71, 0xE2, 0x89,
0x5F, 0xBE, 0x31, 0x62, 0xC4, 0xC5, 0xC7, 0xC3, 0xCB, 0xDB, 0xFB, 0xBB,
0x3B, 0x76, 0xEC, 0x95, 0x67, 0xCE, 0xD1, 0xEF, 0x93, 0x6B, 0xD6, 0xE1,
0x8F, 0x53, 0xA6, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x4D,
0x9A, 0x79, 0xF2, 0xA9, 0x1F, 0x3E, 0x7C, 0xF8, 0xBD, 0x37, 0x6E, 0xDC,
0xF5, 0xA7, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xC0, 0xCD, 0xD7, 0xE3,
0x8B, 0x5B, 0xB6, 0x21, 0x42, 0x84, 0x45, 0x8A, 0x59, 0xB2, 0x29, 0x52,
0xA4, 0x05, 0x0A, 0x14, 0x28, 0x50, 0xA0, 0x0D, 0x1A, 0x34, 0x68, 0xD0,
0xED, 0x97, 0x63, 0xC6, 0xC1, 0xCF, 0xD3, 0xEB, 0x9B, 0x7B, 0xF6, 0xA1,
0x0F, 0x1E, 0x3C, 0x78, 0xF0, 0xAD, 0x17, 0x2E, 0x5C, 0xB8, 0x3D, 0x7A,
0xF4, 0xA5, 0x07, 0x0E, 0x1C, 0x38, 0x70, 0xE0, 0x8D, 0x57, 0xAE, 0x11,
0x22, 0x44, 0x88, 0x5D, 0xBA, 0x39, 0x72, 0xE4, 0x85, 0x47, 0x8E, 0x51,
0xA2, 0x09, 0x12, 0x24, 0x48, 0x90, 0x6D, 0xDA, 0xF9, 0xBF, 0x33, 0x66,
0xCC, 0xD5, 0xE7, 0x83, 0x4B, 0x96, 0x61, 0xC2, 0xC9, 0xDF, 0xF3, 0xAB,
0x1B, 0x36, 0x6C, 0xD8, 0xFD, 0xB7, 0x23, 0x46, 0x8C, 0x55, 0xAA, 0x19,
0x32, 0x64, 0xC8, 0xDD, 0xF7, 0xA3, 0x0B, 0x16, 0x2C, 0x58, 0xB0, 0x2D,
0x5A, 0xB4, 0x25, 0x4A, 0x94, 0x65, 0xCA, 0xD9, 0xFF, 0xB3, 0x2B, 0x56,
0xAC, 0x15, 0x2A, 0x54, 0xA8, 0x1D, 0x3A, 0x74, 0xE8, 0x9D, 0x77, 0xEE,
0x91, 0x6F, 0xDE, 0xF1, 0xAF, 0x13, 0x26, 0x4C, 0x98, 0x7D, 0xFA, 0xB9,
0x3F, 0x7E, 0xFC, 0xB5, 0x27, 0x4E, 0x9C, 0x75, 0xEA, 0x99, 0x7F, 0xFE,
0xB1, 0x2F, 0x5E, 0xBC, 0x35, 0x6A, 0xD4, 0xE5, 0x87, 0x43, 0x86, 0x41,
0x82, 0x49, 0x92, 0x69, 0xD2, 0xE9, 0x9F, 0x73, 0xE6, 0x81, 0x4F, 0x9E,
0x71, 0xE2, 0x89, 0x5F, 0xBE, 0x31, 0x62, 0xC4, 0xC5, 0xC7, 0xC3, 0xCB
};
/* The table constants are indices of
* S-box entries, preprocessed through q0 and q1. */
static const u8 calc_sb_tbl[512] = {
0xA9, 0x75, 0x67, 0xF3, 0xB3, 0xC6, 0xE8, 0xF4,
0x04, 0xDB, 0xFD, 0x7B, 0xA3, 0xFB, 0x76, 0xC8,
0x9A, 0x4A, 0x92, 0xD3, 0x80, 0xE6, 0x78, 0x6B,
0xE4, 0x45, 0xDD, 0x7D, 0xD1, 0xE8, 0x38, 0x4B,
0x0D, 0xD6, 0xC6, 0x32, 0x35, 0xD8, 0x98, 0xFD,
0x18, 0x37, 0xF7, 0x71, 0xEC, 0xF1, 0x6C, 0xE1,
0x43, 0x30, 0x75, 0x0F, 0x37, 0xF8, 0x26, 0x1B,
0xFA, 0x87, 0x13, 0xFA, 0x94, 0x06, 0x48, 0x3F,
0xF2, 0x5E, 0xD0, 0xBA, 0x8B, 0xAE, 0x30, 0x5B,
0x84, 0x8A, 0x54, 0x00, 0xDF, 0xBC, 0x23, 0x9D,
0x19, 0x6D, 0x5B, 0xC1, 0x3D, 0xB1, 0x59, 0x0E,
0xF3, 0x80, 0xAE, 0x5D, 0xA2, 0xD2, 0x82, 0xD5,
0x63, 0xA0, 0x01, 0x84, 0x83, 0x07, 0x2E, 0x14,
0xD9, 0xB5, 0x51, 0x90, 0x9B, 0x2C, 0x7C, 0xA3,
0xA6, 0xB2, 0xEB, 0x73, 0xA5, 0x4C, 0xBE, 0x54,
0x16, 0x92, 0x0C, 0x74, 0xE3, 0x36, 0x61, 0x51,
0xC0, 0x38, 0x8C, 0xB0, 0x3A, 0xBD, 0xF5, 0x5A,
0x73, 0xFC, 0x2C, 0x60, 0x25, 0x62, 0x0B, 0x96,
0xBB, 0x6C, 0x4E, 0x42, 0x89, 0xF7, 0x6B, 0x10,
0x53, 0x7C, 0x6A, 0x28, 0xB4, 0x27, 0xF1, 0x8C,
0xE1, 0x13, 0xE6, 0x95, 0xBD, 0x9C, 0x45, 0xC7,
0xE2, 0x24, 0xF4, 0x46, 0xB6, 0x3B, 0x66, 0x70,
0xCC, 0xCA, 0x95, 0xE3, 0x03, 0x85, 0x56, 0xCB,
0xD4, 0x11, 0x1C, 0xD0, 0x1E, 0x93, 0xD7, 0xB8,
0xFB, 0xA6, 0xC3, 0x83, 0x8E, 0x20, 0xB5, 0xFF,
0xE9, 0x9F, 0xCF, 0x77, 0xBF, 0xC3, 0xBA, 0xCC,
0xEA, 0x03, 0x77, 0x6F, 0x39, 0x08, 0xAF, 0xBF,
0x33, 0x40, 0xC9, 0xE7, 0x62, 0x2B, 0x71, 0xE2,
0x81, 0x79, 0x79, 0x0C, 0x09, 0xAA, 0xAD, 0x82,
0x24, 0x41, 0xCD, 0x3A, 0xF9, 0xEA, 0xD8, 0xB9,
0xE5, 0xE4, 0xC5, 0x9A, 0xB9, 0xA4, 0x4D, 0x97,
0x44, 0x7E, 0x08, 0xDA, 0x86, 0x7A, 0xE7, 0x17,
0xA1, 0x66, 0x1D, 0x94, 0xAA, 0xA1, 0xED, 0x1D,
0x06, 0x3D, 0x70, 0xF0, 0xB2, 0xDE, 0xD2, 0xB3,
0x41, 0x0B, 0x7B, 0x72, 0xA0, 0xA7, 0x11, 0x1C,
0x31, 0xEF, 0xC2, 0xD1, 0x27, 0x53, 0x90, 0x3E,
0x20, 0x8F, 0xF6, 0x33, 0x60, 0x26, 0xFF, 0x5F,
0x96, 0xEC, 0x5C, 0x76, 0xB1, 0x2A, 0xAB, 0x49,
0x9E, 0x81, 0x9C, 0x88, 0x52, 0xEE, 0x1B, 0x21,
0x5F, 0xC4, 0x93, 0x1A, 0x0A, 0xEB, 0xEF, 0xD9,
0x91, 0xC5, 0x85, 0x39, 0x49, 0x99, 0xEE, 0xCD,
0x2D, 0xAD, 0x4F, 0x31, 0x8F, 0x8B, 0x3B, 0x01,
0x47, 0x18, 0x87, 0x23, 0x6D, 0xDD, 0x46, 0x1F,
0xD6, 0x4E, 0x3E, 0x2D, 0x69, 0xF9, 0x64, 0x48,
0x2A, 0x4F, 0xCE, 0xF2, 0xCB, 0x65, 0x2F, 0x8E,
0xFC, 0x78, 0x97, 0x5C, 0x05, 0x58, 0x7A, 0x19,
0xAC, 0x8D, 0x7F, 0xE5, 0xD5, 0x98, 0x1A, 0x57,
0x4B, 0x67, 0x0E, 0x7F, 0xA7, 0x05, 0x5A, 0x64,
0x28, 0xAF, 0x14, 0x63, 0x3F, 0xB6, 0x29, 0xFE,
0x88, 0xF5, 0x3C, 0xB7, 0x4C, 0x3C, 0x02, 0xA5,
0xB8, 0xCE, 0xDA, 0xE9, 0xB0, 0x68, 0x17, 0x44,
0x55, 0xE0, 0x1F, 0x4D, 0x8A, 0x43, 0x7D, 0x69,
0x57, 0x29, 0xC7, 0x2E, 0x8D, 0xAC, 0x74, 0x15,
0xB7, 0x59, 0xC4, 0xA8, 0x9F, 0x0A, 0x72, 0x9E,
0x7E, 0x6E, 0x15, 0x47, 0x22, 0xDF, 0x12, 0x34,
0x58, 0x35, 0x07, 0x6A, 0x99, 0xCF, 0x34, 0xDC,
0x6E, 0x22, 0x50, 0xC9, 0xDE, 0xC0, 0x68, 0x9B,
0x65, 0x89, 0xBC, 0xD4, 0xDB, 0xED, 0xF8, 0xAB,
0xC8, 0x12, 0xA8, 0xA2, 0x2B, 0x0D, 0x40, 0x52,
0xDC, 0xBB, 0xFE, 0x02, 0x32, 0x2F, 0xA4, 0xA9,
0xCA, 0xD7, 0x10, 0x61, 0x21, 0x1E, 0xF0, 0xB4,
0xD3, 0x50, 0x5D, 0x04, 0x0F, 0xF6, 0x00, 0xC2,
0x6F, 0x16, 0x9D, 0x25, 0x36, 0x86, 0x42, 0x56,
0x4A, 0x55, 0x5E, 0x09, 0xC1, 0xBE, 0xE0, 0x91
};
/* Macro to perform one column of the RS matrix multiplication. The
* parameters a, b, c, and d are the four bytes of output; i is the index
* of the key bytes, and w, x, y, and z, are the column of constants from
* the RS matrix, preprocessed through the poly_to_exp table. */
#define CALC_S(a, b, c, d, i, w, x, y, z) \
if (key[i]) { \
tmp = poly_to_exp[key[i] - 1]; \
(a) ^= exp_to_poly[tmp + (w)]; \
(b) ^= exp_to_poly[tmp + (x)]; \
(c) ^= exp_to_poly[tmp + (y)]; \
(d) ^= exp_to_poly[tmp + (z)]; \
}
/* Macros to calculate the key-dependent S-boxes for a 128-bit key using
* the S vector from CALC_S. CALC_SB_2 computes a single entry in all
* four S-boxes, where i is the index of the entry to compute, and a and b
* are the index numbers preprocessed through the q0 and q1 tables
* respectively. */
#define CALC_SB_2(i, a, b) \
ctx->s[0][i] = mds[0][q0[(a) ^ sa] ^ se]; \
ctx->s[1][i] = mds[1][q0[(b) ^ sb] ^ sf]; \
ctx->s[2][i] = mds[2][q1[(a) ^ sc] ^ sg]; \
ctx->s[3][i] = mds[3][q1[(b) ^ sd] ^ sh]
/* Macro exactly like CALC_SB_2, but for 192-bit keys. */
#define CALC_SB192_2(i, a, b) \
ctx->s[0][i] = mds[0][q0[q0[(b) ^ sa] ^ se] ^ si]; \
ctx->s[1][i] = mds[1][q0[q1[(b) ^ sb] ^ sf] ^ sj]; \
ctx->s[2][i] = mds[2][q1[q0[(a) ^ sc] ^ sg] ^ sk]; \
ctx->s[3][i] = mds[3][q1[q1[(a) ^ sd] ^ sh] ^ sl];
/* Macro exactly like CALC_SB_2, but for 256-bit keys. */
#define CALC_SB256_2(i, a, b) \
ctx->s[0][i] = mds[0][q0[q0[q1[(b) ^ sa] ^ se] ^ si] ^ sm]; \
ctx->s[1][i] = mds[1][q0[q1[q1[(a) ^ sb] ^ sf] ^ sj] ^ sn]; \
ctx->s[2][i] = mds[2][q1[q0[q0[(a) ^ sc] ^ sg] ^ sk] ^ so]; \
ctx->s[3][i] = mds[3][q1[q1[q0[(b) ^ sd] ^ sh] ^ sl] ^ sp];
/* Macros to calculate the whitening and round subkeys. CALC_K_2 computes the
* last two stages of the h() function for a given index (either 2i or 2i+1).
* a, b, c, and d are the four bytes going into the last two stages. For
* 128-bit keys, this is the entire h() function and a and c are the index
* preprocessed through q0 and q1 respectively; for longer keys they are the
* output of previous stages. j is the index of the first key byte to use.
* CALC_K computes a pair of subkeys for 128-bit Twofish, by calling CALC_K_2
* twice, doing the Pseudo-Hadamard Transform, and doing the necessary
* rotations. Its parameters are: a, the array to write the results into,
* j, the index of the first output entry, k and l, the preprocessed indices
* for index 2i, and m and n, the preprocessed indices for index 2i+1.
* CALC_K192_2 expands CALC_K_2 to handle 192-bit keys, by doing an
* additional lookup-and-XOR stage. The parameters a, b, c and d are the
* four bytes going into the last three stages. For 192-bit keys, c = d
* are the index preprocessed through q0, and a = b are the index
* preprocessed through q1; j is the index of the first key byte to use.
* CALC_K192 is identical to CALC_K but for using the CALC_K192_2 macro
* instead of CALC_K_2.
* CALC_K256_2 expands CALC_K192_2 to handle 256-bit keys, by doing an
* additional lookup-and-XOR stage. The parameters a and b are the index
* preprocessed through q0 and q1 respectively; j is the index of the first
* key byte to use. CALC_K256 is identical to CALC_K but for using the
* CALC_K256_2 macro instead of CALC_K_2. */
#define CALC_K_2(a, b, c, d, j) \
mds[0][q0[a ^ key[(j) + 8]] ^ key[j]] \
^ mds[1][q0[b ^ key[(j) + 9]] ^ key[(j) + 1]] \
^ mds[2][q1[c ^ key[(j) + 10]] ^ key[(j) + 2]] \
^ mds[3][q1[d ^ key[(j) + 11]] ^ key[(j) + 3]]
#define CALC_K(a, j, k, l, m, n) \
x = CALC_K_2 (k, l, k, l, 0); \
y = CALC_K_2 (m, n, m, n, 4); \
y = (y << 8) + (y >> 24); \
x += y; y += x; ctx->a[j] = x; \
ctx->a[(j) + 1] = (y << 9) + (y >> 23)
#define CALC_K192_2(a, b, c, d, j) \
CALC_K_2 (q0[a ^ key[(j) + 16]], \
q1[b ^ key[(j) + 17]], \
q0[c ^ key[(j) + 18]], \
q1[d ^ key[(j) + 19]], j)
#define CALC_K192(a, j, k, l, m, n) \
x = CALC_K192_2 (l, l, k, k, 0); \
y = CALC_K192_2 (n, n, m, m, 4); \
y = (y << 8) + (y >> 24); \
x += y; y += x; ctx->a[j] = x; \
ctx->a[(j) + 1] = (y << 9) + (y >> 23)
#define CALC_K256_2(a, b, j) \
CALC_K192_2 (q1[b ^ key[(j) + 24]], \
q1[a ^ key[(j) + 25]], \
q0[a ^ key[(j) + 26]], \
q0[b ^ key[(j) + 27]], j)
#define CALC_K256(a, j, k, l, m, n) \
x = CALC_K256_2 (k, l, 0); \
y = CALC_K256_2 (m, n, 4); \
y = (y << 8) + (y >> 24); \
x += y; y += x; ctx->a[j] = x; \
ctx->a[(j) + 1] = (y << 9) + (y >> 23)
/* Macros to compute the g() function in the encryption and decryption
* rounds. G1 is the straight g() function; G2 includes the 8-bit
* rotation for the high 32-bit word. */
#define G1(a) \
(ctx->s[0][(a) & 0xFF]) ^ (ctx->s[1][((a) >> 8) & 0xFF]) \
^ (ctx->s[2][((a) >> 16) & 0xFF]) ^ (ctx->s[3][(a) >> 24])
#define G2(b) \
(ctx->s[1][(b) & 0xFF]) ^ (ctx->s[2][((b) >> 8) & 0xFF]) \
^ (ctx->s[3][((b) >> 16) & 0xFF]) ^ (ctx->s[0][(b) >> 24])
/* Encryption and decryption Feistel rounds. Each one calls the two g()
* macros, does the PHT, and performs the XOR and the appropriate bit
* rotations. The parameters are the round number (used to select subkeys),
* and the four 32-bit chunks of the text. */
#define ENCROUND(n, a, b, c, d) \
x = G1 (a); y = G2 (b); \
x += y; y += x + ctx->k[2 * (n) + 1]; \
(c) ^= x + ctx->k[2 * (n)]; \
(c) = ((c) >> 1) + ((c) << 31); \
(d) = (((d) << 1)+((d) >> 31)) ^ y
#define DECROUND(n, a, b, c, d) \
x = G1 (a); y = G2 (b); \
x += y; y += x; \
(d) ^= y + ctx->k[2 * (n) + 1]; \
(d) = ((d) >> 1) + ((d) << 31); \
(c) = (((c) << 1)+((c) >> 31)); \
(c) ^= (x + ctx->k[2 * (n)])
/* Encryption and decryption cycles; each one is simply two Feistel rounds
* with the 32-bit chunks re-ordered to simulate the "swap" */
#define ENCCYCLE(n) \
ENCROUND (2 * (n), a, b, c, d); \
ENCROUND (2 * (n) + 1, c, d, a, b)
#define DECCYCLE(n) \
DECROUND (2 * (n) + 1, c, d, a, b); \
DECROUND (2 * (n), a, b, c, d)
/* Macros to convert the input and output bytes into 32-bit words,
* and simultaneously perform the whitening step. INPACK packs word
* number n into the variable named by x, using whitening subkey number m.
* OUTUNPACK unpacks word number n from the variable named by x, using
* whitening subkey number m. */
#define INPACK(n, x, m) \
x = le32_to_cpu(src[n]) ^ ctx->w[m]
#define OUTUNPACK(n, x, m) \
x ^= ctx->w[m]; \
dst[n] = cpu_to_le32(x)
#define TF_MIN_KEY_SIZE 16
#define TF_MAX_KEY_SIZE 32
#define TF_BLOCK_SIZE 16
/* Structure for an expanded Twofish key. s contains the key-dependent
* S-boxes composed with the MDS matrix; w contains the eight "whitening"
* subkeys, K[0] through K[7]. k holds the remaining, "round" subkeys. Note
* that k[i] corresponds to what the Twofish paper calls K[i+8]. */
struct twofish_ctx {
u32 s[4][256], w[8], k[32];
};
/* Perform the key setup. */
static int twofish_setkey(void *cx, const u8 *key,
unsigned int key_len, u32 *flags)
{
struct twofish_ctx *ctx = cx;
int i, j, k;
/* Temporaries for CALC_K. */
u32 x, y;
/* The S vector used to key the S-boxes, split up into individual bytes.
* 128-bit keys use only sa through sh; 256-bit use all of them. */
u8 sa = 0, sb = 0, sc = 0, sd = 0, se = 0, sf = 0, sg = 0, sh = 0;
u8 si = 0, sj = 0, sk = 0, sl = 0, sm = 0, sn = 0, so = 0, sp = 0;
/* Temporary for CALC_S. */
u8 tmp;
/* Check key length. */
if (key_len != 16 && key_len != 24 && key_len != 32)
{
*flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
return -EINVAL; /* unsupported key length */
}
/* Compute the first two words of the S vector. The magic numbers are
* the entries of the RS matrix, preprocessed through poly_to_exp. The
* numbers in the comments are the original (polynomial form) matrix
* entries. */
CALC_S (sa, sb, sc, sd, 0, 0x00, 0x2D, 0x01, 0x2D); /* 01 A4 02 A4 */
CALC_S (sa, sb, sc, sd, 1, 0x2D, 0xA4, 0x44, 0x8A); /* A4 56 A1 55 */
CALC_S (sa, sb, sc, sd, 2, 0x8A, 0xD5, 0xBF, 0xD1); /* 55 82 FC 87 */
CALC_S (sa, sb, sc, sd, 3, 0xD1, 0x7F, 0x3D, 0x99); /* 87 F3 C1 5A */
CALC_S (sa, sb, sc, sd, 4, 0x99, 0x46, 0x66, 0x96); /* 5A 1E 47 58 */
CALC_S (sa, sb, sc, sd, 5, 0x96, 0x3C, 0x5B, 0xED); /* 58 C6 AE DB */
CALC_S (sa, sb, sc, sd, 6, 0xED, 0x37, 0x4F, 0xE0); /* DB 68 3D 9E */
CALC_S (sa, sb, sc, sd, 7, 0xE0, 0xD0, 0x8C, 0x17); /* 9E E5 19 03 */
CALC_S (se, sf, sg, sh, 8, 0x00, 0x2D, 0x01, 0x2D); /* 01 A4 02 A4 */
CALC_S (se, sf, sg, sh, 9, 0x2D, 0xA4, 0x44, 0x8A); /* A4 56 A1 55 */
CALC_S (se, sf, sg, sh, 10, 0x8A, 0xD5, 0xBF, 0xD1); /* 55 82 FC 87 */
CALC_S (se, sf, sg, sh, 11, 0xD1, 0x7F, 0x3D, 0x99); /* 87 F3 C1 5A */
CALC_S (se, sf, sg, sh, 12, 0x99, 0x46, 0x66, 0x96); /* 5A 1E 47 58 */
CALC_S (se, sf, sg, sh, 13, 0x96, 0x3C, 0x5B, 0xED); /* 58 C6 AE DB */
CALC_S (se, sf, sg, sh, 14, 0xED, 0x37, 0x4F, 0xE0); /* DB 68 3D 9E */
CALC_S (se, sf, sg, sh, 15, 0xE0, 0xD0, 0x8C, 0x17); /* 9E E5 19 03 */
if (key_len == 24 || key_len == 32) { /* 192- or 256-bit key */
/* Calculate the third word of the S vector */
CALC_S (si, sj, sk, sl, 16, 0x00, 0x2D, 0x01, 0x2D); /* 01 A4 02 A4 */
CALC_S (si, sj, sk, sl, 17, 0x2D, 0xA4, 0x44, 0x8A); /* A4 56 A1 55 */
CALC_S (si, sj, sk, sl, 18, 0x8A, 0xD5, 0xBF, 0xD1); /* 55 82 FC 87 */
CALC_S (si, sj, sk, sl, 19, 0xD1, 0x7F, 0x3D, 0x99); /* 87 F3 C1 5A */
CALC_S (si, sj, sk, sl, 20, 0x99, 0x46, 0x66, 0x96); /* 5A 1E 47 58 */
CALC_S (si, sj, sk, sl, 21, 0x96, 0x3C, 0x5B, 0xED); /* 58 C6 AE DB */
CALC_S (si, sj, sk, sl, 22, 0xED, 0x37, 0x4F, 0xE0); /* DB 68 3D 9E */
CALC_S (si, sj, sk, sl, 23, 0xE0, 0xD0, 0x8C, 0x17); /* 9E E5 19 03 */
}
if (key_len == 32) { /* 256-bit key */
/* Calculate the fourth word of the S vector */
CALC_S (sm, sn, so, sp, 24, 0x00, 0x2D, 0x01, 0x2D); /* 01 A4 02 A4 */
CALC_S (sm, sn, so, sp, 25, 0x2D, 0xA4, 0x44, 0x8A); /* A4 56 A1 55 */
CALC_S (sm, sn, so, sp, 26, 0x8A, 0xD5, 0xBF, 0xD1); /* 55 82 FC 87 */
CALC_S (sm, sn, so, sp, 27, 0xD1, 0x7F, 0x3D, 0x99); /* 87 F3 C1 5A */
CALC_S (sm, sn, so, sp, 28, 0x99, 0x46, 0x66, 0x96); /* 5A 1E 47 58 */
CALC_S (sm, sn, so, sp, 29, 0x96, 0x3C, 0x5B, 0xED); /* 58 C6 AE DB */
CALC_S (sm, sn, so, sp, 30, 0xED, 0x37, 0x4F, 0xE0); /* DB 68 3D 9E */
CALC_S (sm, sn, so, sp, 31, 0xE0, 0xD0, 0x8C, 0x17); /* 9E E5 19 03 */
/* Compute the S-boxes. */
for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) {
CALC_SB256_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
}
/* Calculate whitening and round subkeys. The constants are
* indices of subkeys, preprocessed through q0 and q1. */
CALC_K256 (w, 0, 0xA9, 0x75, 0x67, 0xF3);
CALC_K256 (w, 2, 0xB3, 0xC6, 0xE8, 0xF4);
CALC_K256 (w, 4, 0x04, 0xDB, 0xFD, 0x7B);
CALC_K256 (w, 6, 0xA3, 0xFB, 0x76, 0xC8);
CALC_K256 (k, 0, 0x9A, 0x4A, 0x92, 0xD3);
CALC_K256 (k, 2, 0x80, 0xE6, 0x78, 0x6B);
CALC_K256 (k, 4, 0xE4, 0x45, 0xDD, 0x7D);
CALC_K256 (k, 6, 0xD1, 0xE8, 0x38, 0x4B);
CALC_K256 (k, 8, 0x0D, 0xD6, 0xC6, 0x32);
CALC_K256 (k, 10, 0x35, 0xD8, 0x98, 0xFD);
CALC_K256 (k, 12, 0x18, 0x37, 0xF7, 0x71);
CALC_K256 (k, 14, 0xEC, 0xF1, 0x6C, 0xE1);
CALC_K256 (k, 16, 0x43, 0x30, 0x75, 0x0F);
CALC_K256 (k, 18, 0x37, 0xF8, 0x26, 0x1B);
CALC_K256 (k, 20, 0xFA, 0x87, 0x13, 0xFA);
CALC_K256 (k, 22, 0x94, 0x06, 0x48, 0x3F);
CALC_K256 (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
CALC_K256 (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
CALC_K256 (k, 28, 0x84, 0x8A, 0x54, 0x00);
CALC_K256 (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
} else if (key_len == 24) { /* 192-bit key */
/* Compute the S-boxes. */
for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) {
CALC_SB192_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
}
/* Calculate whitening and round subkeys. The constants are
* indices of subkeys, preprocessed through q0 and q1. */
CALC_K192 (w, 0, 0xA9, 0x75, 0x67, 0xF3);
CALC_K192 (w, 2, 0xB3, 0xC6, 0xE8, 0xF4);
CALC_K192 (w, 4, 0x04, 0xDB, 0xFD, 0x7B);
CALC_K192 (w, 6, 0xA3, 0xFB, 0x76, 0xC8);
CALC_K192 (k, 0, 0x9A, 0x4A, 0x92, 0xD3);
CALC_K192 (k, 2, 0x80, 0xE6, 0x78, 0x6B);
CALC_K192 (k, 4, 0xE4, 0x45, 0xDD, 0x7D);
CALC_K192 (k, 6, 0xD1, 0xE8, 0x38, 0x4B);
CALC_K192 (k, 8, 0x0D, 0xD6, 0xC6, 0x32);
CALC_K192 (k, 10, 0x35, 0xD8, 0x98, 0xFD);
CALC_K192 (k, 12, 0x18, 0x37, 0xF7, 0x71);
CALC_K192 (k, 14, 0xEC, 0xF1, 0x6C, 0xE1);
CALC_K192 (k, 16, 0x43, 0x30, 0x75, 0x0F);
CALC_K192 (k, 18, 0x37, 0xF8, 0x26, 0x1B);
CALC_K192 (k, 20, 0xFA, 0x87, 0x13, 0xFA);
CALC_K192 (k, 22, 0x94, 0x06, 0x48, 0x3F);
CALC_K192 (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
CALC_K192 (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
CALC_K192 (k, 28, 0x84, 0x8A, 0x54, 0x00);
CALC_K192 (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
} else { /* 128-bit key */
/* Compute the S-boxes. */
for ( i = j = 0, k = 1; i < 256; i++, j += 2, k += 2 ) {
CALC_SB_2( i, calc_sb_tbl[j], calc_sb_tbl[k] );
}
/* Calculate whitening and round subkeys. The constants are
* indices of subkeys, preprocessed through q0 and q1. */
CALC_K (w, 0, 0xA9, 0x75, 0x67, 0xF3);
CALC_K (w, 2, 0xB3, 0xC6, 0xE8, 0xF4);
CALC_K (w, 4, 0x04, 0xDB, 0xFD, 0x7B);
CALC_K (w, 6, 0xA3, 0xFB, 0x76, 0xC8);
CALC_K (k, 0, 0x9A, 0x4A, 0x92, 0xD3);
CALC_K (k, 2, 0x80, 0xE6, 0x78, 0x6B);
CALC_K (k, 4, 0xE4, 0x45, 0xDD, 0x7D);
CALC_K (k, 6, 0xD1, 0xE8, 0x38, 0x4B);
CALC_K (k, 8, 0x0D, 0xD6, 0xC6, 0x32);
CALC_K (k, 10, 0x35, 0xD8, 0x98, 0xFD);
CALC_K (k, 12, 0x18, 0x37, 0xF7, 0x71);
CALC_K (k, 14, 0xEC, 0xF1, 0x6C, 0xE1);
CALC_K (k, 16, 0x43, 0x30, 0x75, 0x0F);
CALC_K (k, 18, 0x37, 0xF8, 0x26, 0x1B);
CALC_K (k, 20, 0xFA, 0x87, 0x13, 0xFA);
CALC_K (k, 22, 0x94, 0x06, 0x48, 0x3F);
CALC_K (k, 24, 0xF2, 0x5E, 0xD0, 0xBA);
CALC_K (k, 26, 0x8B, 0xAE, 0x30, 0x5B);
CALC_K (k, 28, 0x84, 0x8A, 0x54, 0x00);
CALC_K (k, 30, 0xDF, 0xBC, 0x23, 0x9D);
}
return 0;
}
/* Encrypt one block. in and out may be the same. */
static void twofish_encrypt(void *cx, u8 *out, const u8 *in)
{
struct twofish_ctx *ctx = cx;
const __le32 *src = (const __le32 *)in;
__le32 *dst = (__le32 *)out;
/* The four 32-bit chunks of the text. */
u32 a, b, c, d;
/* Temporaries used by the round function. */
u32 x, y;
/* Input whitening and packing. */
INPACK (0, a, 0);
INPACK (1, b, 1);
INPACK (2, c, 2);
INPACK (3, d, 3);
/* Encryption Feistel cycles. */
ENCCYCLE (0);
ENCCYCLE (1);
ENCCYCLE (2);
ENCCYCLE (3);
ENCCYCLE (4);
ENCCYCLE (5);
ENCCYCLE (6);
ENCCYCLE (7);
/* Output whitening and unpacking. */
OUTUNPACK (0, c, 4);
OUTUNPACK (1, d, 5);
OUTUNPACK (2, a, 6);
OUTUNPACK (3, b, 7);
}
/* Decrypt one block. in and out may be the same. */
static void twofish_decrypt(void *cx, u8 *out, const u8 *in)
{
struct twofish_ctx *ctx = cx;
const __le32 *src = (const __le32 *)in;
__le32 *dst = (__le32 *)out;
/* The four 32-bit chunks of the text. */
u32 a, b, c, d;
/* Temporaries used by the round function. */
u32 x, y;
/* Input whitening and packing. */
INPACK (0, c, 4);
INPACK (1, d, 5);
INPACK (2, a, 6);
INPACK (3, b, 7);
/* Encryption Feistel cycles. */
DECCYCLE (7);
DECCYCLE (6);
DECCYCLE (5);
DECCYCLE (4);
DECCYCLE (3);
DECCYCLE (2);
DECCYCLE (1);
DECCYCLE (0);
/* Output whitening and unpacking. */
OUTUNPACK (0, a, 0);
OUTUNPACK (1, b, 1);
OUTUNPACK (2, c, 2);
OUTUNPACK (3, d, 3);
}
static struct crypto_alg alg = {
.cra_name = "twofish",
.cra_flags = CRYPTO_ALG_TYPE_CIPHER,
.cra_blocksize = TF_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct twofish_ctx),
.cra_alignmask = 3,
.cra_module = THIS_MODULE,
.cra_list = LIST_HEAD_INIT(alg.cra_list),
.cra_u = { .cipher = {
.cia_min_keysize = TF_MIN_KEY_SIZE,
.cia_max_keysize = TF_MAX_KEY_SIZE,
.cia_setkey = twofish_setkey,
.cia_encrypt = twofish_encrypt,
.cia_decrypt = twofish_decrypt } }
};
static int __init init(void)
{
return crypto_register_alg(&alg);
}
static void __exit fini(void)
{
crypto_unregister_alg(&alg);
}
module_init(init);
module_exit(fini);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION ("Twofish Cipher Algorithm");
| 50.694934 | 78 | 0.669375 |
31876fff2c7c1c0990bdf391add22b7117355341 | 397 | c | C | C/easy/e271.c | tlgs/dailyprogrammer | 6e7d3352616fa54a8e9caf8564a9cfb951eb0af9 | [
"Unlicense"
] | 4 | 2017-10-18T02:17:02.000Z | 2022-02-02T01:19:02.000Z | C/easy/e271.c | tlseabra/dailyprogrammer | 6e7d3352616fa54a8e9caf8564a9cfb951eb0af9 | [
"Unlicense"
] | 4 | 2016-01-24T20:30:02.000Z | 2017-01-18T16:01:23.000Z | C/easy/e271.c | tlgs/dailyprogrammer | 6e7d3352616fa54a8e9caf8564a9cfb951eb0af9 | [
"Unlicense"
] | null | null | null | /* 20/01/2017 */
#include <stdio.h>
float p(int d, int h){
if(h > d)
return (1 / (float) d) * p(d, h-d);
else
return (1 / (float) d * (d-h+1));
}
int main(void){
int input[][2] = {{4,1}, {4,4}, {4,5}, {4,6}, {1,10}, {100, 200}, {8,20}};
for(int i=0; i < 7; i++)
printf("%3d : %3d --> %0.5f\n", input[i][0], input[i][1], p(input[i][0], input[i][1]));
}
| 24.8125 | 98 | 0.428212 |
bd15a1c294be25d978a91ef9592d8e185e68e97f | 19,510 | c | C | qemu/tests/qtest/npcm7xx_pwm-test.c | hyunjoy/scripts | 01114d3627730d695b5ebe61093c719744432ffa | [
"Apache-2.0"
] | null | null | null | qemu/tests/qtest/npcm7xx_pwm-test.c | hyunjoy/scripts | 01114d3627730d695b5ebe61093c719744432ffa | [
"Apache-2.0"
] | null | null | null | qemu/tests/qtest/npcm7xx_pwm-test.c | hyunjoy/scripts | 01114d3627730d695b5ebe61093c719744432ffa | [
"Apache-2.0"
] | null | null | null | /*
* QTests for Nuvoton NPCM7xx PWM Modules.
*
* Copyright 2020 Google LLC
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 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 General Public License
* for more details.
*/
#include "qemu/osdep.h"
#include "qemu/bitops.h"
#include "libqos/libqtest.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qnum.h"
#define REF_HZ 25000000
/* Register field definitions. */
#define CH_EN BIT(0)
#define CH_INV BIT(2)
#define CH_MOD BIT(3)
/* Registers shared between all PWMs in a module */
#define PPR 0x00
#define CSR 0x04
#define PCR 0x08
#define PIER 0x3c
#define PIIR 0x40
/* CLK module related */
#define CLK_BA 0xf0801000
#define CLKSEL 0x04
#define CLKDIV1 0x08
#define CLKDIV2 0x2c
#define PLLCON0 0x0c
#define PLLCON1 0x10
#define PLL_INDV(rv) extract32((rv), 0, 6)
#define PLL_FBDV(rv) extract32((rv), 16, 12)
#define PLL_OTDV1(rv) extract32((rv), 8, 3)
#define PLL_OTDV2(rv) extract32((rv), 13, 3)
#define APB4CKDIV(rv) extract32((rv), 30, 2)
#define APB3CKDIV(rv) extract32((rv), 28, 2)
#define CLK2CKDIV(rv) extract32((rv), 0, 1)
#define CLK4CKDIV(rv) extract32((rv), 26, 2)
#define CPUCKSEL(rv) extract32((rv), 0, 2)
#define MAX_DUTY 1000000
/* MFT (PWM fan) related */
#define MFT_BA(n) (0xf0180000 + ((n) * 0x1000))
#define MFT_IRQ(n) (96 + (n))
#define MFT_CNT1 0x00
#define MFT_CRA 0x02
#define MFT_CRB 0x04
#define MFT_CNT2 0x06
#define MFT_PRSC 0x08
#define MFT_CKC 0x0a
#define MFT_MCTRL 0x0c
#define MFT_ICTRL 0x0e
#define MFT_ICLR 0x10
#define MFT_IEN 0x12
#define MFT_CPA 0x14
#define MFT_CPB 0x16
#define MFT_CPCFG 0x18
#define MFT_INASEL 0x1a
#define MFT_INBSEL 0x1c
#define MFT_MCTRL_ALL 0x64
#define MFT_ICLR_ALL 0x3f
#define MFT_IEN_ALL 0x3f
#define MFT_CPCFG_EQ_MODE 0x44
#define MFT_CKC_C2CSEL BIT(3)
#define MFT_CKC_C1CSEL BIT(0)
#define MFT_ICTRL_TFPND BIT(5)
#define MFT_ICTRL_TEPND BIT(4)
#define MFT_ICTRL_TDPND BIT(3)
#define MFT_ICTRL_TCPND BIT(2)
#define MFT_ICTRL_TBPND BIT(1)
#define MFT_ICTRL_TAPND BIT(0)
#define MFT_MAX_CNT 0xffff
#define MFT_TIMEOUT 0x5000
#define DEFAULT_RPM 19800
#define DEFAULT_PRSC 255
#define MFT_PULSE_PER_REVOLUTION 2
#define MAX_ERROR 1
typedef struct PWMModule {
int irq;
uint64_t base_addr;
} PWMModule;
typedef struct PWM {
uint32_t cnr_offset;
uint32_t cmr_offset;
uint32_t pdr_offset;
uint32_t pwdr_offset;
} PWM;
typedef struct TestData {
const PWMModule *module;
const PWM *pwm;
} TestData;
static const PWMModule pwm_module_list[] = {
{
.irq = 93,
.base_addr = 0xf0103000
},
{
.irq = 94,
.base_addr = 0xf0104000
}
};
static const PWM pwm_list[] = {
{
.cnr_offset = 0x0c,
.cmr_offset = 0x10,
.pdr_offset = 0x14,
.pwdr_offset = 0x44,
},
{
.cnr_offset = 0x18,
.cmr_offset = 0x1c,
.pdr_offset = 0x20,
.pwdr_offset = 0x48,
},
{
.cnr_offset = 0x24,
.cmr_offset = 0x28,
.pdr_offset = 0x2c,
.pwdr_offset = 0x4c,
},
{
.cnr_offset = 0x30,
.cmr_offset = 0x34,
.pdr_offset = 0x38,
.pwdr_offset = 0x50,
},
};
static const int ppr_base[] = { 0, 0, 8, 8 };
static const int csr_base[] = { 0, 4, 8, 12 };
static const int pcr_base[] = { 0, 8, 12, 16 };
static const uint32_t ppr_list[] = {
0,
1,
10,
100,
255, /* Max possible value. */
};
static const uint32_t csr_list[] = {
0,
1,
2,
3,
4, /* Max possible value. */
};
static const uint32_t cnr_list[] = {
0,
1,
50,
100,
150,
200,
1000,
10000,
65535, /* Max possible value. */
};
static const uint32_t cmr_list[] = {
0,
1,
10,
50,
100,
150,
200,
1000,
10000,
65535, /* Max possible value. */
};
/* Returns the index of the PWM module. */
static int pwm_module_index(const PWMModule *module)
{
ptrdiff_t diff = module - pwm_module_list;
g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list));
return diff;
}
/* Returns the index of the PWM entry. */
static int pwm_index(const PWM *pwm)
{
ptrdiff_t diff = pwm - pwm_list;
g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_list));
return diff;
}
static uint64_t pwm_qom_get(QTestState *qts, const char *path, const char *name)
{
QDict *response;
uint64_t val;
g_test_message("Getting properties %s from %s", name, path);
response = qtest_qmp(qts, "{ 'execute': 'qom-get',"
" 'arguments': { 'path': %s, 'property': %s}}",
path, name);
/* The qom set message returns successfully. */
g_assert_true(qdict_haskey(response, "return"));
val = qnum_get_uint(qobject_to(QNum, qdict_get(response, "return")));
qobject_unref(response);
return val;
}
static uint64_t pwm_get_freq(QTestState *qts, int module_index, int pwm_index)
{
char path[100];
char name[100];
sprintf(path, "/machine/soc/pwm[%d]", module_index);
sprintf(name, "freq[%d]", pwm_index);
return pwm_qom_get(qts, path, name);
}
static uint64_t pwm_get_duty(QTestState *qts, int module_index, int pwm_index)
{
char path[100];
char name[100];
sprintf(path, "/machine/soc/pwm[%d]", module_index);
sprintf(name, "duty[%d]", pwm_index);
return pwm_qom_get(qts, path, name);
}
static void mft_qom_set(QTestState *qts, int index, const char *name,
uint32_t value)
{
QDict *response;
char *path = g_strdup_printf("/machine/soc/mft[%d]", index);
g_test_message("Setting properties %s of mft[%d] with value %u",
name, index, value);
response = qtest_qmp(qts, "{ 'execute': 'qom-set',"
" 'arguments': { 'path': %s, "
" 'property': %s, 'value': %u}}",
path, name, value);
/* The qom set message returns successfully. */
g_assert_true(qdict_haskey(response, "return"));
}
static uint32_t get_pll(uint32_t con)
{
return REF_HZ * PLL_FBDV(con) / (PLL_INDV(con) * PLL_OTDV1(con)
* PLL_OTDV2(con));
}
static uint64_t read_pclk(QTestState *qts, bool mft)
{
uint64_t freq = REF_HZ;
uint32_t clksel = qtest_readl(qts, CLK_BA + CLKSEL);
uint32_t pllcon;
uint32_t clkdiv1 = qtest_readl(qts, CLK_BA + CLKDIV1);
uint32_t clkdiv2 = qtest_readl(qts, CLK_BA + CLKDIV2);
uint32_t apbdiv = mft ? APB4CKDIV(clkdiv2) : APB3CKDIV(clkdiv2);
switch (CPUCKSEL(clksel)) {
case 0:
pllcon = qtest_readl(qts, CLK_BA + PLLCON0);
freq = get_pll(pllcon);
break;
case 1:
pllcon = qtest_readl(qts, CLK_BA + PLLCON1);
freq = get_pll(pllcon);
break;
case 2:
break;
case 3:
break;
default:
g_assert_not_reached();
}
freq >>= (CLK2CKDIV(clkdiv1) + CLK4CKDIV(clkdiv1) + apbdiv);
return freq;
}
static uint32_t pwm_selector(uint32_t csr)
{
switch (csr) {
case 0:
return 2;
case 1:
return 4;
case 2:
return 8;
case 3:
return 16;
case 4:
return 1;
default:
g_assert_not_reached();
}
}
static uint64_t pwm_compute_freq(QTestState *qts, uint32_t ppr, uint32_t csr,
uint32_t cnr)
{
return read_pclk(qts, false) / ((ppr + 1) * pwm_selector(csr) * (cnr + 1));
}
static uint64_t pwm_compute_duty(uint32_t cnr, uint32_t cmr, bool inverted)
{
uint32_t duty;
if (cnr == 0) {
/* PWM is stopped. */
duty = 0;
} else if (cmr >= cnr) {
duty = MAX_DUTY;
} else {
duty = (uint64_t)MAX_DUTY * (cmr + 1) / (cnr + 1);
}
if (inverted) {
duty = MAX_DUTY - duty;
}
return duty;
}
static uint32_t pwm_read(QTestState *qts, const TestData *td, unsigned offset)
{
return qtest_readl(qts, td->module->base_addr + offset);
}
static void pwm_write(QTestState *qts, const TestData *td, unsigned offset,
uint32_t value)
{
qtest_writel(qts, td->module->base_addr + offset, value);
}
static uint8_t mft_readb(QTestState *qts, int index, unsigned offset)
{
return qtest_readb(qts, MFT_BA(index) + offset);
}
static uint16_t mft_readw(QTestState *qts, int index, unsigned offset)
{
return qtest_readw(qts, MFT_BA(index) + offset);
}
static void mft_writeb(QTestState *qts, int index, unsigned offset,
uint8_t value)
{
qtest_writeb(qts, MFT_BA(index) + offset, value);
}
static void mft_writew(QTestState *qts, int index, unsigned offset,
uint16_t value)
{
return qtest_writew(qts, MFT_BA(index) + offset, value);
}
static uint32_t pwm_read_ppr(QTestState *qts, const TestData *td)
{
return extract32(pwm_read(qts, td, PPR), ppr_base[pwm_index(td->pwm)], 8);
}
static void pwm_write_ppr(QTestState *qts, const TestData *td, uint32_t value)
{
pwm_write(qts, td, PPR, value << ppr_base[pwm_index(td->pwm)]);
}
static uint32_t pwm_read_csr(QTestState *qts, const TestData *td)
{
return extract32(pwm_read(qts, td, CSR), csr_base[pwm_index(td->pwm)], 3);
}
static void pwm_write_csr(QTestState *qts, const TestData *td, uint32_t value)
{
pwm_write(qts, td, CSR, value << csr_base[pwm_index(td->pwm)]);
}
static uint32_t pwm_read_pcr(QTestState *qts, const TestData *td)
{
return extract32(pwm_read(qts, td, PCR), pcr_base[pwm_index(td->pwm)], 4);
}
static void pwm_write_pcr(QTestState *qts, const TestData *td, uint32_t value)
{
pwm_write(qts, td, PCR, value << pcr_base[pwm_index(td->pwm)]);
}
static uint32_t pwm_read_cnr(QTestState *qts, const TestData *td)
{
return pwm_read(qts, td, td->pwm->cnr_offset);
}
static void pwm_write_cnr(QTestState *qts, const TestData *td, uint32_t value)
{
pwm_write(qts, td, td->pwm->cnr_offset, value);
}
static uint32_t pwm_read_cmr(QTestState *qts, const TestData *td)
{
return pwm_read(qts, td, td->pwm->cmr_offset);
}
static void pwm_write_cmr(QTestState *qts, const TestData *td, uint32_t value)
{
pwm_write(qts, td, td->pwm->cmr_offset, value);
}
static int mft_compute_index(const TestData *td)
{
int index = pwm_module_index(td->module) * ARRAY_SIZE(pwm_list) +
pwm_index(td->pwm);
g_assert_cmpint(index, <,
ARRAY_SIZE(pwm_module_list) * ARRAY_SIZE(pwm_list));
return index;
}
static void mft_reset_counters(QTestState *qts, int index)
{
mft_writew(qts, index, MFT_CNT1, MFT_MAX_CNT);
mft_writew(qts, index, MFT_CNT2, MFT_MAX_CNT);
mft_writew(qts, index, MFT_CRA, MFT_MAX_CNT);
mft_writew(qts, index, MFT_CRB, MFT_MAX_CNT);
mft_writew(qts, index, MFT_CPA, MFT_MAX_CNT - MFT_TIMEOUT);
mft_writew(qts, index, MFT_CPB, MFT_MAX_CNT - MFT_TIMEOUT);
}
static void mft_init(QTestState *qts, const TestData *td)
{
int index = mft_compute_index(td);
/* Enable everything */
mft_writeb(qts, index, MFT_CKC, 0);
mft_writeb(qts, index, MFT_ICLR, MFT_ICLR_ALL);
mft_writeb(qts, index, MFT_MCTRL, MFT_MCTRL_ALL);
mft_writeb(qts, index, MFT_IEN, MFT_IEN_ALL);
mft_writeb(qts, index, MFT_INASEL, 0);
mft_writeb(qts, index, MFT_INBSEL, 0);
/* Set cpcfg to use EQ mode, same as kernel driver */
mft_writeb(qts, index, MFT_CPCFG, MFT_CPCFG_EQ_MODE);
/* Write default counters, timeout and prescaler */
mft_reset_counters(qts, index);
mft_writeb(qts, index, MFT_PRSC, DEFAULT_PRSC);
/* Write default max rpm via QMP */
mft_qom_set(qts, index, "max_rpm[0]", DEFAULT_RPM);
mft_qom_set(qts, index, "max_rpm[1]", DEFAULT_RPM);
}
static int32_t mft_compute_cnt(uint32_t rpm, uint64_t clk)
{
uint64_t cnt;
if (rpm == 0) {
return -1;
}
cnt = clk * 60 / ((DEFAULT_PRSC + 1) * rpm * MFT_PULSE_PER_REVOLUTION);
if (cnt >= MFT_TIMEOUT) {
return -1;
}
return MFT_MAX_CNT - cnt;
}
static void mft_verify_rpm(QTestState *qts, const TestData *td, uint64_t duty)
{
int index = mft_compute_index(td);
uint16_t cnt, cr;
uint32_t rpm = DEFAULT_RPM * duty / MAX_DUTY;
uint64_t clk = read_pclk(qts, true);
int32_t expected_cnt = mft_compute_cnt(rpm, clk);
qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic");
g_test_message(
"verifying rpm for mft[%d]: clk: %" PRIu64 ", duty: %" PRIu64 ", rpm: %u, cnt: %d",
index, clk, duty, rpm, expected_cnt);
/* Verify rpm for fan A */
/* Stop capture */
mft_writeb(qts, index, MFT_CKC, 0);
mft_writeb(qts, index, MFT_ICLR, MFT_ICLR_ALL);
mft_reset_counters(qts, index);
g_assert_cmphex(mft_readw(qts, index, MFT_CNT1), ==, MFT_MAX_CNT);
g_assert_cmphex(mft_readw(qts, index, MFT_CRA), ==, MFT_MAX_CNT);
g_assert_cmphex(mft_readw(qts, index, MFT_CPA), ==,
MFT_MAX_CNT - MFT_TIMEOUT);
/* Start capture */
mft_writeb(qts, index, MFT_CKC, MFT_CKC_C1CSEL);
g_assert_true(qtest_get_irq(qts, MFT_IRQ(index)));
if (expected_cnt == -1) {
g_assert_cmphex(mft_readb(qts, index, MFT_ICTRL), ==, MFT_ICTRL_TEPND);
} else {
g_assert_cmphex(mft_readb(qts, index, MFT_ICTRL), ==, MFT_ICTRL_TAPND);
cnt = mft_readw(qts, index, MFT_CNT1);
/*
* Due to error in clock measurement and rounding, we might have a small
* error in measuring RPM.
*/
g_assert_cmphex(cnt + MAX_ERROR, >=, expected_cnt);
g_assert_cmphex(cnt, <=, expected_cnt + MAX_ERROR);
cr = mft_readw(qts, index, MFT_CRA);
g_assert_cmphex(cnt, ==, cr);
}
/* Verify rpm for fan B */
qtest_irq_intercept_out(qts, "/machine/soc/a9mpcore/gic");
}
/* Check pwm registers can be reset to default value */
static void test_init(gconstpointer test_data)
{
const TestData *td = test_data;
QTestState *qts = qtest_init("-machine npcm750-evb");
int module = pwm_module_index(td->module);
int pwm = pwm_index(td->pwm);
g_assert_cmpuint(pwm_get_freq(qts, module, pwm), ==, 0);
g_assert_cmpuint(pwm_get_duty(qts, module, pwm), ==, 0);
qtest_quit(qts);
}
/* One-shot mode should not change frequency and duty cycle. */
static void test_oneshot(gconstpointer test_data)
{
const TestData *td = test_data;
QTestState *qts = qtest_init("-machine npcm750-evb");
int module = pwm_module_index(td->module);
int pwm = pwm_index(td->pwm);
uint32_t ppr, csr, pcr;
int i, j;
pcr = CH_EN;
for (i = 0; i < ARRAY_SIZE(ppr_list); ++i) {
ppr = ppr_list[i];
pwm_write_ppr(qts, td, ppr);
for (j = 0; j < ARRAY_SIZE(csr_list); ++j) {
csr = csr_list[j];
pwm_write_csr(qts, td, csr);
pwm_write_pcr(qts, td, pcr);
g_assert_cmpuint(pwm_read_ppr(qts, td), ==, ppr);
g_assert_cmpuint(pwm_read_csr(qts, td), ==, csr);
g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr);
g_assert_cmpuint(pwm_get_freq(qts, module, pwm), ==, 0);
g_assert_cmpuint(pwm_get_duty(qts, module, pwm), ==, 0);
}
}
qtest_quit(qts);
}
/* In toggle mode, the PWM generates correct outputs. */
static void test_toggle(gconstpointer test_data)
{
const TestData *td = test_data;
QTestState *qts = qtest_init("-machine npcm750-evb");
int module = pwm_module_index(td->module);
int pwm = pwm_index(td->pwm);
uint32_t ppr, csr, pcr, cnr, cmr;
int i, j, k, l;
uint64_t expected_freq, expected_duty;
mft_init(qts, td);
pcr = CH_EN | CH_MOD;
for (i = 0; i < ARRAY_SIZE(ppr_list); ++i) {
ppr = ppr_list[i];
pwm_write_ppr(qts, td, ppr);
for (j = 0; j < ARRAY_SIZE(csr_list); ++j) {
csr = csr_list[j];
pwm_write_csr(qts, td, csr);
for (k = 0; k < ARRAY_SIZE(cnr_list); ++k) {
cnr = cnr_list[k];
pwm_write_cnr(qts, td, cnr);
for (l = 0; l < ARRAY_SIZE(cmr_list); ++l) {
cmr = cmr_list[l];
pwm_write_cmr(qts, td, cmr);
expected_freq = pwm_compute_freq(qts, ppr, csr, cnr);
expected_duty = pwm_compute_duty(cnr, cmr, false);
pwm_write_pcr(qts, td, pcr);
g_assert_cmpuint(pwm_read_ppr(qts, td), ==, ppr);
g_assert_cmpuint(pwm_read_csr(qts, td), ==, csr);
g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr);
g_assert_cmpuint(pwm_read_cnr(qts, td), ==, cnr);
g_assert_cmpuint(pwm_read_cmr(qts, td), ==, cmr);
g_assert_cmpuint(pwm_get_duty(qts, module, pwm),
==, expected_duty);
if (expected_duty != 0 && expected_duty != 100) {
/* Duty cycle with 0 or 100 doesn't need frequency. */
g_assert_cmpuint(pwm_get_freq(qts, module, pwm),
==, expected_freq);
}
/* Test MFT's RPM is correct. */
mft_verify_rpm(qts, td, expected_duty);
/* Test inverted mode */
expected_duty = pwm_compute_duty(cnr, cmr, true);
pwm_write_pcr(qts, td, pcr | CH_INV);
g_assert_cmpuint(pwm_read_pcr(qts, td), ==, pcr | CH_INV);
g_assert_cmpuint(pwm_get_duty(qts, module, pwm),
==, expected_duty);
if (expected_duty != 0 && expected_duty != 100) {
/* Duty cycle with 0 or 100 doesn't need frequency. */
g_assert_cmpuint(pwm_get_freq(qts, module, pwm),
==, expected_freq);
}
}
}
}
}
qtest_quit(qts);
}
static void pwm_add_test(const char *name, const TestData* td,
GTestDataFunc fn)
{
g_autofree char *full_name = g_strdup_printf(
"npcm7xx_pwm/module[%d]/pwm[%d]/%s", pwm_module_index(td->module),
pwm_index(td->pwm), name);
qtest_add_data_func(full_name, td, fn);
}
#define add_test(name, td) pwm_add_test(#name, td, test_##name)
int main(int argc, char **argv)
{
TestData test_data_list[ARRAY_SIZE(pwm_module_list) * ARRAY_SIZE(pwm_list)];
g_test_init(&argc, &argv, NULL);
for (int i = 0; i < ARRAY_SIZE(pwm_module_list); ++i) {
for (int j = 0; j < ARRAY_SIZE(pwm_list); ++j) {
TestData *td = &test_data_list[i * ARRAY_SIZE(pwm_list) + j];
td->module = &pwm_module_list[i];
td->pwm = &pwm_list[j];
add_test(init, td);
add_test(oneshot, td);
add_test(toggle, td);
}
}
return g_test_run();
}
| 28.398836 | 91 | 0.609944 |
fcd59d39afd54d10c657e70ba137ead5a7249119 | 18,779 | c | C | verification/cbmc/sources/make_common_data_structures.c | robin-aws/aws-encryption-sdk-c | ed3980886e8ca5ac24ee454624ebc96568501462 | [
"Apache-2.0"
] | 40 | 2019-05-23T01:45:26.000Z | 2022-02-27T13:57:06.000Z | verification/cbmc/sources/make_common_data_structures.c | robin-aws/aws-encryption-sdk-c | ed3980886e8ca5ac24ee454624ebc96568501462 | [
"Apache-2.0"
] | 240 | 2019-05-20T22:34:12.000Z | 2022-02-22T18:08:02.000Z | verification/cbmc/sources/make_common_data_structures.c | robin-aws/aws-encryption-sdk-c | ed3980886e8ca5ac24ee454624ebc96568501462 | [
"Apache-2.0"
] | 53 | 2019-05-23T01:45:10.000Z | 2022-03-17T20:20:01.000Z | /*
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file 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 <aws/cryptosdk/cipher.h>
#include <aws/cryptosdk/default_cmm.h>
#include <aws/cryptosdk/keyring_trace.h>
#include <aws/cryptosdk/materials.h>
#include <aws/cryptosdk/private/header.h>
#include <aws/cryptosdk/private/hkdf.h>
#include <aws/cryptosdk/private/keyring_trace.h>
#include <aws/cryptosdk/private/multi_keyring.h>
#include <aws/cryptosdk/private/session.h>
#include <cipher_openssl.h>
#include <ec_utils.h>
#include <evp_utils.h>
#include <openssl/ec.h>
#include <openssl/evp.h>
#include <proof_helpers/make_common_data_structures.h>
#include <proof_helpers/proof_allocators.h>
struct default_cmm {
struct aws_cryptosdk_cmm base;
struct aws_allocator *alloc;
struct aws_cryptosdk_keyring *kr;
/* Invariant: this is either DEFAULT_ALG_UNSET or is a valid algorithm ID */
enum aws_cryptosdk_alg_id default_alg;
};
const EVP_MD *nondet_EVP_MD_ptr(void);
const EVP_CIPHER *nondet_EVP_CIPHER_ptr(void);
struct aws_cryptosdk_alg_impl *ensure_impl_attempt_allocation(const size_t max_len) {
struct aws_cryptosdk_alg_impl *impl = malloc(sizeof(struct aws_cryptosdk_alg_impl));
if (impl) {
*(const EVP_MD **)(&impl->md_ctor) = (nondet_bool()) ? NULL : &nondet_EVP_MD_ptr;
*(const EVP_MD **)(&impl->sig_md_ctor) = (nondet_bool()) ? NULL : &nondet_EVP_MD_ptr;
*(const EVP_CIPHER **)(&impl->cipher_ctor) = (nondet_bool()) ? NULL : &nondet_EVP_CIPHER_ptr;
*(const char **)(&impl->curve_name) = ensure_c_str_is_allocated(max_len);
}
return impl;
}
struct aws_cryptosdk_alg_properties *ensure_alg_properties_attempt_allocation(const size_t max_len) {
struct aws_cryptosdk_alg_properties *alg_props = malloc(sizeof(struct aws_cryptosdk_alg_properties));
if (alg_props) {
alg_props->md_name = ensure_c_str_is_allocated(max_len);
alg_props->cipher_name = ensure_c_str_is_allocated(max_len);
alg_props->alg_name = ensure_c_str_is_allocated(max_len);
alg_props->sig_md_name = ensure_c_str_is_allocated(max_len);
alg_props->impl = ensure_impl_attempt_allocation(max_len);
}
return alg_props;
}
struct content_key *ensure_content_key_attempt_allocation() {
struct content_key *key = malloc(sizeof(uint8_t) * MAX_DATA_KEY_SIZE);
return key;
}
struct data_key *ensure_data_key_attempt_allocation() {
struct data_key *key = malloc(sizeof(uint8_t) * MAX_DATA_KEY_SIZE);
return key;
}
void ensure_record_has_allocated_members(struct aws_cryptosdk_keyring_trace_record *record, size_t max_len) {
record->wrapping_key_namespace = ensure_string_is_allocated_nondet_length();
if (record->wrapping_key_namespace) {
__CPROVER_assume(record->wrapping_key_namespace->len <= max_len);
}
record->wrapping_key_name = ensure_string_is_allocated_nondet_length();
if (record->wrapping_key_name) {
__CPROVER_assume(record->wrapping_key_name->len <= max_len);
}
record->flags = malloc(sizeof(uint32_t));
}
void ensure_trace_has_allocated_records(struct aws_array_list *trace, size_t max_len) {
struct aws_cryptosdk_keyring_trace_record *data;
/* iterate over each record in the keyring trace */
for (size_t i = 0; i < trace->length; ++i) {
data = (struct aws_cryptosdk_keyring_trace_record *)trace->data;
ensure_record_has_allocated_members(&(data[i]), max_len);
}
}
void ensure_md_context_has_allocated_members(struct aws_cryptosdk_md_context *ctx) {
ctx->alloc = nondet_bool() ? NULL : can_fail_allocator();
ctx->evp_md_ctx = evp_md_ctx_nondet_alloc();
}
struct aws_cryptosdk_sig_ctx *ensure_nondet_sig_ctx_has_allocated_members() {
struct aws_cryptosdk_sig_ctx *ctx = malloc(sizeof(*ctx));
if (ctx == NULL) {
return NULL;
}
ctx->alloc = nondet_bool() ? NULL : can_fail_allocator();
enum aws_cryptosdk_alg_id alg_id;
ctx->props = aws_cryptosdk_alg_props(alg_id);
ctx->keypair = ec_key_nondet_alloc();
ctx->pkey = evp_pkey_nondet_alloc();
ctx->ctx = evp_md_ctx_nondet_alloc();
// Need to ensure consistency of reference count later by assuming ctx is valid
evp_pkey_set0_ec_key(ctx->pkey, ctx->keypair);
if (ctx->is_sign) {
evp_md_ctx_set0_evp_pkey(ctx->ctx, NULL);
} else {
// Need to ensure consistency of reference count later by assuming ctx is valid
evp_md_ctx_set0_evp_pkey(ctx->ctx, ctx->pkey);
}
return ctx;
}
bool aws_cryptosdk_edk_is_bounded(const struct aws_cryptosdk_edk *edk, const size_t max_size) {
return aws_byte_buf_is_bounded(&edk->provider_id, max_size) &&
aws_byte_buf_is_bounded(&edk->provider_info, max_size) &&
aws_byte_buf_is_bounded(&edk->ciphertext, max_size);
}
void ensure_cryptosdk_edk_has_allocated_members(struct aws_cryptosdk_edk *edk) {
ensure_byte_buf_has_allocated_buffer_member(&edk->provider_id);
ensure_byte_buf_has_allocated_buffer_member(&edk->provider_info);
ensure_byte_buf_has_allocated_buffer_member(&edk->ciphertext);
}
bool aws_cryptosdk_edk_list_is_bounded(
const struct aws_array_list *const list, const size_t max_initial_item_allocation) {
if (list->item_size != sizeof(struct aws_cryptosdk_edk)) {
return false;
}
if (list->length > max_initial_item_allocation) {
return false;
}
return true;
}
bool aws_cryptosdk_edk_list_elements_are_bounded(const struct aws_array_list *const list, const size_t max_item_size) {
for (size_t i = 0; i < list->length; ++i) {
struct aws_cryptosdk_edk *data = (struct aws_cryptosdk_edk *)list->data;
if (!aws_cryptosdk_edk_is_bounded(&(data[i]), max_item_size)) {
return false;
}
}
return true;
}
void ensure_cryptosdk_edk_list_has_allocated_list(struct aws_array_list *list) {
if (list != NULL) {
if (list->current_size == 0) {
__CPROVER_assume(list->data == NULL);
list->alloc = can_fail_allocator();
} else {
size_t max_length = list->current_size / sizeof(struct aws_cryptosdk_edk);
list->data = bounded_malloc(sizeof(struct aws_cryptosdk_edk) * max_length);
list->alloc = nondet_bool() ? NULL : can_fail_allocator();
}
}
}
void ensure_cryptosdk_edk_list_has_allocated_list_elements(struct aws_array_list *list) {
if (aws_cryptosdk_edk_list_is_valid(list)) {
for (size_t i = 0; i < list->length; ++i) {
struct aws_cryptosdk_edk *data = (struct aws_cryptosdk_edk *)list->data;
ensure_cryptosdk_edk_has_allocated_members(&(data[i]));
}
}
}
void ensure_nondet_hdr_has_allocated_members_ref(struct aws_cryptosdk_hdr *hdr, const size_t max_table_size) {
if (hdr) {
hdr->alloc = nondet_bool() ? NULL : can_fail_allocator();
ensure_byte_buf_has_allocated_buffer_member(&hdr->iv);
ensure_byte_buf_has_allocated_buffer_member(&hdr->auth_tag);
ensure_byte_buf_has_allocated_buffer_member(&hdr->message_id);
ensure_byte_buf_has_allocated_buffer_member(&hdr->alg_suite_data);
ensure_allocated_hash_table(&hdr->enc_ctx, max_table_size);
ensure_cryptosdk_edk_list_has_allocated_list(&hdr->edk_list);
}
}
struct aws_cryptosdk_hdr *ensure_nondet_hdr_has_allocated_members(const size_t max_table_size) {
struct aws_cryptosdk_hdr *hdr = malloc(sizeof(*hdr));
if (hdr != NULL) {
hdr->alloc = nondet_bool() ? NULL : can_fail_allocator();
ensure_byte_buf_has_allocated_buffer_member(&hdr->iv);
ensure_byte_buf_has_allocated_buffer_member(&hdr->auth_tag);
ensure_byte_buf_has_allocated_buffer_member(&hdr->message_id);
ensure_byte_buf_has_allocated_buffer_member(&hdr->alg_suite_data);
ensure_allocated_hash_table(&hdr->enc_ctx, max_table_size);
ensure_cryptosdk_edk_list_has_allocated_list(&hdr->edk_list);
}
return hdr;
}
bool aws_cryptosdk_hdr_members_are_bounded(
const struct aws_cryptosdk_hdr *hdr, const size_t max_edk_item_size, const size_t max_item_size) {
if (hdr != NULL) {
/*IV buffer length might need further constraints, this is done in the harness when necessary */
return aws_cryptosdk_edk_list_is_bounded(&hdr->edk_list, max_edk_item_size) &&
(!aws_cryptosdk_edk_list_is_valid(&hdr->edk_list) ||
aws_cryptosdk_edk_list_elements_are_bounded(&hdr->edk_list, max_item_size)) &&
aws_byte_buf_is_bounded(&hdr->iv, max_item_size) &&
aws_byte_buf_is_bounded(&hdr->auth_tag, max_item_size) &&
aws_byte_buf_is_bounded(&hdr->message_id, max_item_size) &&
aws_byte_buf_is_bounded(&hdr->alg_suite_data, max_item_size);
}
return true; /* If hdr is NULL, true by default */
}
struct aws_cryptosdk_hdr *hdr_setup(
const size_t max_table_size, const size_t max_edk_item_size, const size_t max_item_size) {
struct aws_cryptosdk_hdr *hdr = ensure_nondet_hdr_has_allocated_members(max_table_size);
__CPROVER_assume(aws_cryptosdk_hdr_members_are_bounded(hdr, max_edk_item_size, max_item_size));
/* Precondition: The edk list has allocated list elements */
ensure_cryptosdk_edk_list_has_allocated_list_elements(&hdr->edk_list);
__CPROVER_assume(aws_cryptosdk_hdr_is_valid(hdr));
__CPROVER_assume(hdr->enc_ctx.p_impl != NULL);
ensure_hash_table_has_valid_destroy_functions(&hdr->enc_ctx);
return hdr;
}
enum aws_cryptosdk_sha_version aws_cryptosdk_which_sha(enum aws_cryptosdk_alg_id alg_id) {
switch (alg_id) {
case ALG_AES256_GCM_HKDF_SHA512_COMMIT_KEY_ECDSA_P384:
case ALG_AES256_GCM_HKDF_SHA512_COMMIT_KEY: return AWS_CRYPTOSDK_SHA512;
case ALG_AES256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384:
case ALG_AES192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: return AWS_CRYPTOSDK_SHA384;
case ALG_AES128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256:
case ALG_AES256_GCM_IV12_TAG16_HKDF_SHA256:
case ALG_AES192_GCM_IV12_TAG16_HKDF_SHA256:
case ALG_AES128_GCM_IV12_TAG16_HKDF_SHA256: return AWS_CRYPTOSDK_SHA256;
case ALG_AES256_GCM_IV12_TAG16_NO_KDF:
case ALG_AES192_GCM_IV12_TAG16_NO_KDF:
case ALG_AES128_GCM_IV12_TAG16_NO_KDF:
default: return AWS_CRYPTOSDK_NOSHA;
}
}
void ensure_cryptosdk_keyring_has_allocated_members(
struct aws_cryptosdk_keyring *keyring, const struct aws_cryptosdk_keyring_vt *vtable) {
if (keyring) {
keyring->refcount.value = malloc(sizeof(size_t));
keyring->vtable = nondet_bool() ? NULL : vtable;
}
}
void ensure_nondet_allocate_keyring_vtable_members(struct aws_cryptosdk_keyring_vt *vtable, size_t max_len) {
if (vtable) {
vtable->name = ensure_c_str_is_allocated(max_len);
}
}
void ensure_nondet_allocate_cmm_vtable_members(struct aws_cryptosdk_cmm_vt *vtable, size_t max_len) {
if (vtable) {
vtable->name = ensure_c_str_is_allocated(max_len);
}
}
struct aws_cryptosdk_cmm_vt *ensure_cmm_vt_attempt_allocation(const size_t max_len) {
struct aws_cryptosdk_cmm_vt *vtable = malloc(sizeof(struct aws_cryptosdk_cmm_vt));
if (vtable) {
vtable->name = ensure_c_str_is_allocated(max_len);
vtable->destroy = nondet_voidp();
vtable->generate_enc_materials = nondet_voidp();
vtable->decrypt_materials = nondet_voidp();
}
return vtable;
}
struct aws_cryptosdk_cmm *ensure_cmm_attempt_allocation(const size_t max_len) {
struct aws_cryptosdk_cmm *cmm = malloc(sizeof(struct aws_cryptosdk_cmm));
if (cmm) {
cmm->vtable = ensure_cmm_vt_attempt_allocation(max_len);
cmm->refcount.value = malloc(sizeof(size_t));
}
return cmm;
}
struct aws_cryptosdk_session *ensure_nondet_session_has_allocated_members(const size_t max_table_size, size_t max_len) {
struct aws_cryptosdk_session *session = malloc(sizeof(struct aws_cryptosdk_session));
if (session) {
session->alloc = nondet_bool() ? NULL : can_fail_allocator();
session->cmm = ensure_cmm_attempt_allocation(max_len);
session->header_copy = malloc(sizeof(*(session->header_copy)));
session->alg_props = ensure_alg_properties_attempt_allocation(max_len);
session->signctx = ensure_nondet_sig_ctx_has_allocated_members();
ensure_byte_buf_has_allocated_buffer_member(&session->key_commitment);
ensure_array_list_has_allocated_data_member(&session->keyring_trace);
ensure_nondet_hdr_has_allocated_members_ref(&session->header, max_table_size);
}
return session;
}
bool aws_cryptosdk_session_members_are_bounded(
const struct aws_cryptosdk_session *session,
const size_t max_trace_items,
const size_t max_edk_item_size,
const size_t max_item_size) {
if (session != NULL) {
return aws_cryptosdk_hdr_members_are_bounded(&session->header, max_edk_item_size, max_item_size) &&
aws_byte_buf_is_bounded(&session->key_commitment, max_item_size) &&
aws_array_list_is_bounded(
&session->keyring_trace, max_trace_items, sizeof(struct aws_cryptosdk_keyring_trace_record)) &&
session->keyring_trace.item_size == sizeof(struct aws_cryptosdk_keyring_trace_record);
}
return true; /* If hdr is NULL, true by default */
}
struct aws_cryptosdk_session *session_setup(
const size_t max_table_size,
const size_t max_trace_items,
const size_t max_edk_item_size,
const size_t max_item_size,
const size_t max_len) {
struct aws_cryptosdk_session *session = ensure_nondet_session_has_allocated_members(max_table_size, max_len);
__CPROVER_assume(
aws_cryptosdk_session_members_are_bounded(session, max_trace_items, max_edk_item_size, max_item_size));
/* Precondition: The keyring trace has allocated records */
if (session) {
__CPROVER_assume(aws_array_list_is_valid(&session->keyring_trace));
ensure_trace_has_allocated_records(&session->keyring_trace, max_len);
}
/* Precondition: The edk list has allocated list elements */
ensure_cryptosdk_edk_list_has_allocated_list_elements(&session->header.edk_list);
__CPROVER_assume(aws_cryptosdk_session_is_valid(session));
return session;
}
bool aws_cryptosdk_dec_materials_members_are_bounded(
const struct aws_cryptosdk_dec_materials *materials, const size_t max_trace_items, const size_t max_item_size) {
if (materials != NULL) {
return aws_byte_buf_is_bounded(&materials->unencrypted_data_key, max_item_size) &&
aws_array_list_is_bounded(
&materials->keyring_trace, max_trace_items, sizeof(struct aws_cryptosdk_keyring_trace_record)) &&
materials->keyring_trace.item_size == sizeof(struct aws_cryptosdk_keyring_trace_record);
}
return true;
}
struct aws_cryptosdk_dec_materials *ensure_dec_materials_attempt_allocation() {
struct aws_cryptosdk_dec_materials *materials = malloc(sizeof(struct aws_cryptosdk_dec_materials));
if (materials) {
materials->alloc = nondet_bool() ? NULL : can_fail_allocator();
materials->signctx = ensure_nondet_sig_ctx_has_allocated_members();
ensure_byte_buf_has_allocated_buffer_member(&materials->unencrypted_data_key);
ensure_array_list_has_allocated_data_member(&materials->keyring_trace);
}
return materials;
}
struct aws_cryptosdk_dec_materials *dec_materials_setup(
const size_t max_trace_items, const size_t max_item_size, const size_t max_len) {
struct aws_cryptosdk_dec_materials *materials = ensure_dec_materials_attempt_allocation();
__CPROVER_assume(aws_cryptosdk_dec_materials_members_are_bounded(materials, max_trace_items, max_item_size));
/* Precondition: The keyring trace has allocated records */
if (materials) {
__CPROVER_assume(aws_array_list_is_valid(&materials->keyring_trace));
ensure_trace_has_allocated_records(&materials->keyring_trace, max_len);
}
__CPROVER_assume(aws_cryptosdk_dec_materials_is_valid(materials));
return materials;
}
struct aws_cryptosdk_enc_request *ensure_enc_request_attempt_allocation(const size_t max_table_size) {
struct aws_cryptosdk_enc_request *request = malloc(sizeof(struct aws_cryptosdk_enc_request));
if (request) {
request->alloc = nondet_bool() ? NULL : can_fail_allocator();
request->enc_ctx = malloc(sizeof(struct aws_hash_table));
if (request->enc_ctx) {
ensure_allocated_hash_table(request->enc_ctx, max_table_size);
}
}
return request;
}
struct aws_cryptosdk_enc_materials *ensure_enc_materials_attempt_allocation() {
struct aws_cryptosdk_enc_materials *materials = malloc(sizeof(struct aws_cryptosdk_enc_materials));
if (materials) {
materials->alloc = nondet_bool() ? NULL : can_fail_allocator();
materials->signctx = ensure_nondet_sig_ctx_has_allocated_members();
ensure_byte_buf_has_allocated_buffer_member(&materials->encrypted_data_keys);
ensure_array_list_has_allocated_data_member(&materials->keyring_trace);
ensure_array_list_has_allocated_data_member(&materials->encrypted_data_keys);
}
return materials;
}
struct aws_cryptosdk_cmm *ensure_default_cmm_attempt_allocation(const struct aws_cryptosdk_keyring_vt *vtable) {
/* Nondet input required to init cmm */
struct aws_cryptosdk_keyring *keyring = malloc(sizeof(*keyring));
/* Assumptions required to init cmm */
ensure_cryptosdk_keyring_has_allocated_members(keyring, vtable);
__CPROVER_assume(aws_cryptosdk_keyring_is_valid(keyring));
__CPROVER_assume(keyring->vtable != NULL);
struct aws_cryptosdk_cmm *cmm = malloc(sizeof(struct default_cmm));
if (cmm) {
cmm->vtable = vtable;
}
struct default_cmm *self = NULL;
if (cmm) {
self = (struct default_cmm *)cmm;
self->alloc = nondet_bool() ? NULL : can_fail_allocator();
self->kr = keyring;
}
return (struct aws_cryptosdk_cmm *)self;
}
| 43.672093 | 120 | 0.734704 |
6c383e0c3007232dc142c0a47655b99f89e6b2b9 | 16,932 | c | C | supporting_libs/scarab/Scarab-0.1.00d19/c/session.c | esayui/mworks | 0522e5afc1e30fdbf1e67cedd196ee50f7924499 | [
"MIT"
] | null | null | null | supporting_libs/scarab/Scarab-0.1.00d19/c/session.c | esayui/mworks | 0522e5afc1e30fdbf1e67cedd196ee50f7924499 | [
"MIT"
] | null | null | null | supporting_libs/scarab/Scarab-0.1.00d19/c/session.c | esayui/mworks | 0522e5afc1e30fdbf1e67cedd196ee50f7924499 | [
"MIT"
] | null | null | null | /**
* session.c
*
* Description: I believe this is some sort of adapter for a stream engine.
*
* History:
* ?? on ??/??/?? - Created by some bastards in Iowa who don't like comments
* Paul Jankunas on 8/10/05 - Added a non-blocking tcpip stream engine.(JK)
* Paul Jankunas on 08/10/05 - Added a strean that blocks in select not read.
*
* Copyright 2005 MIT. All rights reserved.
*/
#include "scarab.h"
#include <string.h>
#include <signal.h>
#include <stdio.h>
/*
* Import Encoders
*/
extern ScarabEncoderEngine scarab_ldo_encoder;
/*
* Import Streams
*/
//extern ScarabStreamEngine scarab_stream_tcpip;
extern ScarabStreamEngine scarab_stream_file;
extern ScarabStreamEngine scarab_stream_file_readonly;
//extern ScarabStreamEngine scarab_stream_tcpipnb; // non-blocking
//extern ScarabStreamEngine scarab_stream_tcpip_select;
//extern ScarabStreamEngine scarab_buffered_stream_tcpip;
/*
* Define Encoder and Stream list.
*/
static ScarabEncoderEngine *g_encoder_engines[64] = {
&scarab_ldo_encoder,
NULL,
};
static ScarabStreamEngine *g_stream_engines[64] = {
//&scarab_stream_tcpip,
&scarab_stream_file,
&scarab_stream_file_readonly,
//&scarab_stream_tcpip_select,
//&scarab_buffered_stream_tcpip,
NULL,
};
/*
* Only for isnan() and isinf()
*/
#include <math.h>
#include <float.h>
#ifdef _WIN32
#define isnan(x) ( _isnan(x) )
#define isinf(x) ( !(_finite(x)) )
#define strcasecmp(x,y) ( _stricmp((x),(y)) )
#endif
/*
* Error codes
*/
#define SCARAB_ERR_BAD_ENCODER_TYPE 1
#define SCARAB_ERR_BAD_STREAM_TYPE 2
#define SCARAB_ERR_API_VERSION 3
static int g_errcnt = 1000;
static int g_next_errcode = 1000;
static const char *g_error_strings[] = {
"No Error",
"Invalid Encoder Type",
"Invalid Stream Type",
"Driver Version Not Supported",
"Unknown Error",
"Unknown Error",
NULL,
};
static ScarabEncoderEngine *find_encoder(const char *uri);
static ScarabStreamEngine *find_stream(const char *uri);
static ScarabEncoderEngine *
find_encoder(const char *uri)
{
char scheme[64];
char *c;
int len;
ScarabEncoderEngine **engine;
/*
* Make a string to match against.
*/
c = (char *)uri;
len = 0;
while (*c != ':' && *c != 0 && len < sizeof(scheme))
{
c++;
len++;
}
if (*c != ':')
return NULL;
memcpy(scheme, uri, len);
scheme[len] = 0;
/*
* Look for it in the encoder list.
*/
for (engine = g_encoder_engines; *engine; engine++)
{
if (strcasecmp((*engine)->uri_scheme, scheme) == 0)
return *engine;
}
return NULL;
}
static ScarabStreamEngine *
find_stream(const char *uri)
{
char scheme[64];
char *c;
int len;
ScarabStreamEngine **engine;
/*
* Make a string to match against.
*/
c = (char *)uri;
len = 0;
while (*c != ':' && *c != 0 && len < sizeof(scheme))
{
c++;
len++;
}
if (*c != ':')
return NULL;
memcpy(scheme, uri, len);
scheme[len] = 0;
/*
* Look for it in the encoder list.
*/
for (engine = g_stream_engines; *engine; engine++)
{
if (strcasecmp((*engine)->uri_scheme, scheme) == 0)
return *engine;
}
return NULL;
}
int
scarab_init(int ignore_sigpipe)
{
int r;
ScarabEncoderEngine **encoder;
ScarabStreamEngine **stream;
scarab_os_init();
scarab_mem_init();
r = 0;
// <EDIT>
// DDC added PAJ moved
// SIGPIPE is sent when a host connection is terminated and
// data gets written to the socket. The SIGPIPE signal will be
// ignored and EPIPE will be generated. This was removed from
// inside the stream_write function to here because it is a process
// wide thing to ignore the SIGPIPE message
if(ignore_sigpipe && signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
//handle error
fprintf(stderr, "Failed to Ignore SIGPIPE signal in scarab_init()");
fflush(stderr);
}
// <END_EDIT>
for (encoder = g_encoder_engines; *encoder; encoder++)
{
if (SCARAB_ERR_API_VERSION == (*encoder)->api_version)
return SCARAB_ERR_API_VERSION;
(*encoder)->err_code_base = g_next_errcode;
g_next_errcode += (*encoder)->nerr_code;
r = (*encoder)->lib_init();
if (r)
return r;
}
for (stream = g_stream_engines; *stream; stream++)
{
if (SCARAB_ERR_API_VERSION == (*stream)->api_version)
return SCARAB_ERR_API_VERSION;
(*stream)->err_code_base = g_next_errcode;
g_next_errcode += (*stream)->nerr_code;
r = (*stream)->lib_init();
if (r)
return r;
}
return r;
}
ScarabSession *
scarab_session_connect(const char *url)
{
ScarabSession *session;
ScarabEncoderEngine *enc;
session = (ScarabSession*)scarab_mem_malloc(sizeof(ScarabSession));
if (!session)
return NULL;
session->encoder_engine = NULL;
session->encoder = NULL;
session->stream_head = NULL;
session->errcode = 0;
session->os_errno = 0;
session->force_buffering = FORCE_BUFFERING_OFF;
session->send_recursion_counter = 0;
session->send_buffer_position = 0;
session->read_buffer_fill_position = 0;
session->read_buffer_read_position = 0;
session->url = (char *)scarab_mem_malloc(strlen(url)+1); // DDC edit
strncpy(session->url, url, strlen(url)+1); // Whoever wrote this is a fucker
enc = find_encoder(url);
if (!enc)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_ENCODER_TYPE);
return session;
}
url += strlen(enc->uri_scheme) + 1;
if (scarab_session_push_connect(session, NULL, url) != 0)
{
return session;
}
session->encoder_engine = enc;
if (enc->session_connect(session) != 0)
{
scarab_stream_close(session->stream_head);
return session;
}
return session;
}
ScarabSession *
scarab_session_listen(const char *url)
{
ScarabSession *session;
ScarabEncoderEngine *enc;
session = (ScarabSession*)scarab_mem_malloc(sizeof(ScarabSession));
if (!session)
return NULL;
session->encoder_engine = NULL;
session->encoder = NULL;
session->stream_head = NULL;
session->errcode = 0;
session->os_errno = 0;
session->force_buffering = FORCE_BUFFERING_OFF;
session->send_recursion_counter = 0;
session->send_buffer_position = 0;
session->read_buffer_fill_position = 0;
session->read_buffer_read_position = 0;
session->url = (char *)scarab_mem_malloc(strlen(url)+1); // DDC edit
// (+1)
strncpy(session->url, url, strlen(url)+1);
enc = find_encoder(url);
if (!enc)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_ENCODER_TYPE);
return session;
}
url += strlen(enc->uri_scheme) + 1;
if (scarab_session_push_listen(session, NULL, url) != 0)
{
return session;
}
return session;
}
ScarabSession *
scarab_session_accept(ScarabSession * binding)
{
ScarabSession *session;
ScarabEncoderEngine *enc;
char *url;
session = (ScarabSession*)scarab_mem_malloc(sizeof(ScarabSession));
if (!session)
return NULL;
session->encoder_engine = NULL;
session->encoder = NULL;
session->stream_head = NULL;
session->errcode = 0;
session->os_errno = 0;
session->force_buffering = FORCE_BUFFERING_OFF;
session->send_recursion_counter = 0;
session->send_buffer_position = 0;
session->read_buffer_fill_position = 0;
session->read_buffer_read_position = 0;
url = binding->url;
session->url = (char *)scarab_mem_malloc(strlen(url)+1); // DDC edit
strncpy(session->url, url, strlen(url)+1); // FUCKERS!!!!
enc = find_encoder(url);
if (!enc)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_ENCODER_TYPE);
return session;
}
url += strlen(enc->uri_scheme) + 1;
if (scarab_session_push_accept(session, NULL, url,
binding->stream_head) != 0)
{
return session;
}
session->encoder_engine = enc;
if (enc->session_accept(session) != 0)
{
scarab_stream_close(session->stream_head);
return session;
}
return session;
}
void
scarab_session_set_encoder(ScarabSession * session,
ScarabEncoderEngine * engine, void *engine_data)
{
session->encoder_engine = engine;
session->encoder = engine_data;
}
int
scarab_session_push_listen(ScarabSession * session,
ScarabStream * stream,
const char *uri)
{
ScarabStreamEngine *e;
ScarabStream *s;
e = find_stream(uri);
if (!e)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_STREAM_TYPE);
return -SCARAB_ERR_BAD_STREAM_TYPE;
}
s = e->stream_listen(session, uri + strlen(e->uri_scheme) + 1);
if (!s)
{
return -session->errcode;
}
s->engine = e;
s->session = session;
if (stream)
{
while (stream->next)
{
stream = stream->next;
}
s->next = NULL;
stream->next = s;
} else
{
s->next = session->stream_head;
session->stream_head = s;
}
return 0;
}
int
scarab_session_push_accept(ScarabSession * session,
ScarabStream * stream,
char *uri, ScarabStream * binding)
{
ScarabStreamEngine *e;
ScarabStream *s;
e = find_stream(uri);
if (!e)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_STREAM_TYPE);
return -SCARAB_ERR_BAD_STREAM_TYPE;
}
s = e->stream_accept(session, uri + strlen(e->uri_scheme) + 1, binding);
if (!s)
{
return -session->errcode;
}
s->engine = e;
s->session = session;
if (stream)
{
while (stream->next)
{
stream = stream->next;
}
s->next = NULL;
stream->next = s;
} else
{
s->next = session->stream_head;
session->stream_head = s;
}
return 0;
}
int
scarab_session_push_connect(ScarabSession * session,
ScarabStream * stream,
const char *uri)
{
ScarabStreamEngine *e;
ScarabStream *s;
e = find_stream(uri);
if (!e)
{
scarab_session_seterr(session, SCARAB_ERR_BAD_STREAM_TYPE);
return -SCARAB_ERR_BAD_STREAM_TYPE;
}
s = e->stream_connect(session, uri + strlen(e->uri_scheme) + 1);
if (!s)
{
return -session->errcode;
}
s->engine = e;
s->session = session;
if (stream)
{
while (stream->next)
{
stream = stream->next;
}
s->next = NULL;
stream->next = s;
} else
{
s->next = session->stream_head;
session->stream_head = s;
}
return 0;
}
int
scarab_session_close(ScarabSession * session)
{
//<EDIT>
// Getting a bad access here when trying to close a listening socket.
// This function is only returning 0 so i am going to comment it out.
//session->encoder_engine->session_close(session);
/*
* Make sure we flush before we close it.
*/
// This function is also only returning 0 but I am going to keep it because
// it wont throw an error.
//scarab_session_flush(session);
// keeping this one because this one actually calls shutdown on the socket
scarab_stream_close(session->stream_head);
scarab_mem_free(session);
//<END_EDIT>
return 0;
}
int
scarab_session_seterr(ScarabSession * session, int code)
{
session->errcode = code;
session->os_errno = scarab_os_geterr();
return -code;
}
int
scarab_session_geterr(ScarabSession * session)
{
return session->errcode;
}
/*
int
scarab_did_select_timeout(int errorCode) {
return (errorCode == SCARAB_SELECT_TIMEDOUT);
}
*/
int
scarab_session_getoserr(ScarabSession * session)
{
return session->os_errno;
}
const char *
scarab_moderror(int errcode)
{
int base;
int cnt;
ScarabEncoderEngine **encoder;
ScarabStreamEngine **stream;
if (errcode >= 1 && errcode < g_errcnt)
return "SCARAB";
for (encoder = g_encoder_engines; *encoder; encoder++)
{
base = (*encoder)->err_code_base;
cnt = (*encoder)->nerr_code;
if (errcode >= base && errcode < base + cnt)
return (*encoder)->uri_scheme;
}
for (stream = g_stream_engines; *stream; stream++)
{
base = (*stream)->err_code_base;
cnt = (*stream)->nerr_code;
if (errcode >= base && errcode < base + cnt)
return (*stream)->uri_scheme;
}
return NULL;
}
const char *
scarab_strerror(int errcode)
{
int base;
int cnt;
ScarabEncoderEngine **encoder;
ScarabStreamEngine **stream;
if (errcode >= 1 && errcode < g_errcnt)
return g_error_strings[errcode];
for (encoder = g_encoder_engines; *encoder; encoder++)
{
base = (*encoder)->err_code_base;
cnt = (*encoder)->nerr_code;
if (errcode >= base && errcode < base + cnt)
return (*encoder)->strerr(errcode - base);
}
for (stream = g_stream_engines; *stream; stream++)
{
base = (*stream)->err_code_base;
cnt = (*stream)->nerr_code;
if (errcode >= base && errcode < base + cnt)
return (*stream)->strerr(errcode - base);
}
return NULL;
}
int
scarab_session_read(ScarabSession * session, void *data, int len)
{
return scarab_stream_read(session->stream_head, data, len);
}
int scarab_session_seek(ScarabSession *session, long int offset, int origin)
{
return scarab_stream_seek(session->stream_head, offset, origin);
}
long int scarab_session_tell(ScarabSession *session)
{
return scarab_stream_tell(session->stream_head);
}
int
scarab_session_write(ScarabSession * session, const void *data, int len)
{
return scarab_stream_write(session->stream_head, data, len);
}
int
scarab_session_send(ScarabSession * session)
{
return scarab_stream_send(session->stream_head);
}
int
scarab_session_flush(ScarabSession * session)
{
return scarab_stream_flush(session->stream_head);
}
/**
* More Mabbit Functions
*/
int scarab_session_local_port(ScarabSession * session) {
if(session == NULL) { return 0; }
return (session->stream_head)->engine->local_port(session->stream_head);
}
char * scarab_session_local_address(ScarabSession * session) {
if(session == NULL) { return ""; }
return (session->stream_head)->engine->local_address(session->stream_head);
}
int scarab_session_foreign_port(ScarabSession * session) {
if(session == NULL) { return 0; }
return (session->stream_head)->engine->foreign_port(session->stream_head);
}
char * scarab_session_foreign_address(ScarabSession * session) {
if(session == NULL) { return ""; }
return (session->stream_head)->engine->foreign_address(session->stream_head);
}
int scarab_session_read_should_die(ScarabSession * session) {
//if(READ_FUBAR_FLAG) {
// READ_FUBAR_FLAG = 0;
// return 1;
//} else {
return 0;
//}
}
int
scarab_write(ScarabSession * session, ScarabDatum * value)
{
ScarabEncoderEngine *enc;
enc = session->encoder_engine;
session->send_recursion_counter++;
int returnval;
if (!value)
{
session->send_recursion_counter--;
return enc->write_null(session);
}
switch (value->type)
{
case SCARAB_NULL:
returnval = enc->write_null(session);
break;
case SCARAB_INTEGER:
returnval = enc->write_integer(session, value->data.integer);
break;
case SCARAB_FLOAT:
returnval = enc->write_float(session, value->data.floatp);
break;
case SCARAB_DICT:
returnval = enc->write_dict(session, value->data.dict);
break;
case SCARAB_LIST:
returnval = enc->write_list(session, value->data.list);
break;
case SCARAB_OPAQUE:
returnval = enc->write_opaque(session, (const char *)value->data.opaque.data,
value->data.opaque.size);
break;
default:
returnval = -1;
break;
}
session->send_recursion_counter--;
if(session->send_recursion_counter <= 0){
scarab_session_send(session);
}
return returnval;
}
int
scarab_write_integer(ScarabSession * session, long long value)
{
//printf("Called scarab_write_integer");
return session->encoder_engine->write_integer(session, value);
}
int
scarab_write_float(ScarabSession * session, double value)
{
return session->encoder_engine->write_float(session, value);
}
int
scarab_write_string(ScarabSession * session, const char *value)
{
return session->encoder_engine->write_opaque(session, value, strlen(value) + 1);
}
int
scarab_write_opaque(ScarabSession * session, const char *value, int size)
{
return session->encoder_engine->write_opaque(session, value, size);
}
int
scarab_write_list(ScarabSession * session, ScarabList * list)
{
return session->encoder_engine->write_list(session, list);
}
int
scarab_write_dict(ScarabSession * session, ScarabDict * dict)
{
return session->encoder_engine->write_dict(session, dict);
}
ScarabDatum *
scarab_read(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
int
scarab_seek(ScarabSession *session, long int offset, int origin)
{
return session->encoder_engine->seek(session, offset, origin);
}
long int
scarab_tell(ScarabSession *session)
{
return session->encoder_engine->tell(session);
}
ScarabDatum *
scarab_read_integer(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
ScarabDatum *
scarab_read_float(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
ScarabDatum *
scarab_read_opaque(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
ScarabDatum *
scarab_read_list(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
ScarabDatum *
scarab_read_dict(ScarabSession * session)
{
return session->encoder_engine->read(session);
}
void scarab_force_buffering(ScarabSession *s, int value){
s->force_buffering = value;
}
| 21.059701 | 81 | 0.69596 |
6c58ea00bcf20968dd88c9dc9f446cfb105e3fed | 506 | h | C | src/klibc/include/assert.h | zhengruohuang/toddler | 0d7bde9aaf1fab8fed5f37973eeda9eaa100bd7a | [
"BSD-2-Clause"
] | 80 | 2016-03-27T04:26:57.000Z | 2021-12-24T08:27:55.000Z | src/klibc/include/assert.h | zhengruohuang/toddler | 0d7bde9aaf1fab8fed5f37973eeda9eaa100bd7a | [
"BSD-2-Clause"
] | 1 | 2016-12-08T18:08:20.000Z | 2018-02-23T02:51:35.000Z | src/klibc/include/assert.h | zhengruohuang/toddler | 0d7bde9aaf1fab8fed5f37973eeda9eaa100bd7a | [
"BSD-2-Clause"
] | 11 | 2017-05-09T01:42:07.000Z | 2020-02-13T13:56:36.000Z | #ifndef __KLIBC_INCLUDE_ASSERT__
#define __KLIBC_INCLUDE_ASSERT__
#include "klibc/include/stdio.h"
#ifdef assert
#undef assert
#endif
#define assert(exp) do { \
if (!(exp)) { \
kprintf("[ASSERT] Failed: "); \
kprintf(#exp); \
kprintf("\n"); \
kprintf("[SRC] File: %s, Base: %s, Line: %d\n", __FILE__, __BASE_FILE__, __LINE__); \
} \
} while (0)
#endif
| 22 | 93 | 0.468379 |
96abb0a5e97c49c2e5f9e3d56382544fd40ca181 | 544 | h | C | JuiceNote/Other/Category/UIImage+XJJImage.h | xxlololo/JuiceNote | 96ce7697b92e573feda1133d7f3875dfb3942457 | [
"MIT"
] | null | null | null | JuiceNote/Other/Category/UIImage+XJJImage.h | xxlololo/JuiceNote | 96ce7697b92e573feda1133d7f3875dfb3942457 | [
"MIT"
] | null | null | null | JuiceNote/Other/Category/UIImage+XJJImage.h | xxlololo/JuiceNote | 96ce7697b92e573feda1133d7f3875dfb3942457 | [
"MIT"
] | 1 | 2020-12-29T05:43:12.000Z | 2020-12-29T05:43:12.000Z |
#import <UIKit/UIKit.h>
@interface UIImage (XJJImage)
/**
* 通过 imageName 获得一个未渲染的图片
*/
+ (instancetype)imageWithOriginalName:(NSString *)imageName;
/**
* 通过 imageName 获得一个边角不拉伸的图片
*/
+ (instancetype)imageWithStretchableName:(NSString *)imageName;
/**
* 设置 image 的颜色
*/
+ (instancetype)imageWithName:(NSString *)imageName imageColor:(UIColor *)imageColor;
//获得一个圆角图片
+ (instancetype)createRoundedRectImage:(UIImage*)image size:(CGSize)size radius:(NSInteger)r;
//根据View获取一个Image
+ (UIImage *) imageWithView:(UIView *)view;
@end
| 19.428571 | 93 | 0.733456 |
e7ca7da42f4339d38ec46a26cf4e8be7e3a7e0b3 | 2,926 | h | C | proxy/Transform.h | allandproust/TrafficServer-1 | 7d517c7ab3f21b812bc0969244386480a94df467 | [
"Apache-2.0"
] | 83 | 2015-01-13T14:44:55.000Z | 2021-10-30T07:57:03.000Z | proxy/Transform.h | flashbuckets/trafficserver | 236fab894c0909913580f7a75a307ab393b3986c | [
"Apache-2.0"
] | 9 | 2015-03-13T15:17:28.000Z | 2017-04-19T08:53:24.000Z | proxy/Transform.h | flashbuckets/trafficserver | 236fab894c0909913580f7a75a307ab393b3986c | [
"Apache-2.0"
] | 50 | 2015-01-29T14:51:38.000Z | 2021-11-10T02:03:35.000Z | /** @file
A brief file description
@section license License
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
*/
#ifndef __TRANSFORM_H__
#define __TRANSFORM_H__
#include "P_EventSystem.h"
#include "HTTP.h"
#include "InkAPIInternal.h"
#define TRANSFORM_READ_READY (TRANSFORM_EVENTS_START + 0)
typedef struct _RangeRecord
{
_RangeRecord() :
_start(-1), _end(-1), _done_byte(-1)
{ }
int64_t _start;
int64_t _end;
int64_t _done_byte;
} RangeRecord;
class RangeTransform:public INKVConnInternal
{
public:
RangeTransform(ProxyMutex * mutex, MIMEField * range_field, HTTPHdr * resp, int64_t cl, HTTPHdr * transform_resp);
~RangeTransform();
void parse_range_and_compare();
int handle_event(int event, void *edata);
void transform_to_range();
void add_boundary(bool end);
void add_sub_header(int index);
void change_response_header();
void calculate_output_cl();
bool is_this_range_not_handled()
{
return m_not_handle_range;
}
bool is_range_unsatisfiable()
{
return m_unsatisfiable_range;
}
typedef struct _RangeRecord
{
_RangeRecord() :
_start(-1), _end(-1), _done_byte(-1)
{ }
int64_t _start;
int64_t _end;
int64_t _done_byte;
} RangeRecord;
public:
MIOBuffer * m_output_buf;
IOBufferReader *m_output_reader;
MIMEField *m_range_field;
HTTPHdr *m_transform_resp;
VIO *m_output_vio;
bool m_unsatisfiable_range;
bool m_not_handle_range;
int64_t m_content_length;
int m_num_chars_for_cl;
int m_num_range_fields;
int m_current_range;
const char *m_content_type;
int m_content_type_len;
RangeRecord *m_ranges;
int64_t m_output_cl;
int64_t m_done;
};
class TransformProcessor
{
public:
void start();
public:
VConnection * open(Continuation * cont, APIHook * hooks);
INKVConnInternal *null_transform(ProxyMutex * mutex);
RangeTransform *range_transform(ProxyMutex * mutex, MIMEField * range_field, HTTPHdr * resp, int64_t cl,
HTTPHdr * transform_resp, bool & b);
};
#ifdef TS_HAS_TESTS
class TransformTest
{
public:
static void run();
};
#endif
extern TransformProcessor transformProcessor;
#endif /* __TRANSFORM_H__ */
| 23.222222 | 116 | 0.738893 |
f022928b498643eea9bcafb6e97d266d0fb0ce08 | 21,844 | c | C | gearsBridge/procps-3.2.8/vmstat.c | SSEHUB/spassMeter | f5071105fec6f5afbbd7426b8149b7973c1a5e55 | [
"Apache-2.0"
] | 1 | 2015-08-06T08:48:12.000Z | 2015-08-06T08:48:12.000Z | gearsBridge/procps-3.2.8/vmstat.c | SSEHUB/spassMeter | f5071105fec6f5afbbd7426b8149b7973c1a5e55 | [
"Apache-2.0"
] | 1 | 2018-05-08T12:17:23.000Z | 2018-05-09T12:03:13.000Z | gearsBridge/procps-3.2.8/vmstat.c | SSEHUB/spassMeter | f5071105fec6f5afbbd7426b8149b7973c1a5e55 | [
"Apache-2.0"
] | 3 | 2015-09-26T22:19:40.000Z | 2018-08-27T05:36:34.000Z | // old: "Copyright 1994 by Henry Ware <al172@yfn.ysu.edu>. Copyleft same year."
// most code copyright 2002 Albert Cahalan
//
// 27/05/2003 (Fabian Frederick) : Add unit conversion + interface
// Export proc/stat access to libproc
// Adapt vmstat helpfile
// 31/05/2003 (Fabian) : Add diskstat support (/libproc)
// June 2003 (Fabian) : -S <x> -s & -s -S <x> patch
// June 2003 (Fabian) : -Adding diskstat against 3.1.9, slabinfo
// -patching 'header' in disk & slab
// July 2003 (Fabian) : -Adding disk partition output
// -Adding disk table
// -Syncing help / usage
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/dir.h>
#include <dirent.h>
#include "proc/sysinfo.h"
#include "proc/version.h"
static unsigned long dataUnit=1024;
static char szDataUnit [16];
#define UNIT_B 1
#define UNIT_k 1000
#define UNIT_K 1024
#define UNIT_m 1000000
#define UNIT_M 1048576
#define VMSTAT 0
#define DISKSTAT 0x00000001
#define VMSUMSTAT 0x00000002
#define SLABSTAT 0x00000004
#define PARTITIONSTAT 0x00000008
#define DISKSUMSTAT 0x00000010
static int statMode=VMSTAT;
#define FALSE 0
#define TRUE 1
static int a_option; /* "-a" means "show active/inactive" */
static unsigned sleep_time = 1;
static unsigned long num_updates;
static unsigned int height; // window height
static unsigned int moreheaders=TRUE;
/////////////////////////////////////////////////////////////////////////
static void usage(void) NORETURN;
static void usage(void) {
fprintf(stderr,"usage: vmstat [-V] [-n] [delay [count]]\n");
fprintf(stderr," -V prints version.\n");
fprintf(stderr," -n causes the headers not to be reprinted regularly.\n");
fprintf(stderr," -a print inactive/active page stats.\n");
fprintf(stderr," -d prints disk statistics\n");
fprintf(stderr," -D prints disk table\n");
fprintf(stderr," -p prints disk partition statistics\n");
fprintf(stderr," -s prints vm table\n");
fprintf(stderr," -m prints slabinfo\n");
fprintf(stderr," -S unit size\n");
fprintf(stderr," delay is the delay between updates in seconds. \n");
fprintf(stderr," unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)\n");
fprintf(stderr," count is the number of updates.\n");
exit(EXIT_FAILURE);
}
/////////////////////////////////////////////////////////////////////////////
#if 0
// produce: " 6 ", "123 ", "123k ", etc.
static int format_1024(unsigned long long val64, char *restrict dst){
unsigned oldval;
const char suffix[] = " kmgtpe";
unsigned level = 0;
unsigned val32;
if(val64 < 1000){ // special case to avoid "6.0 " when plain " 6 " would do
val32 = val64;
return sprintf(dst,"%3u ",val32);
}
while(val64 > 0xffffffffull){
level++;
val64 /= 1024;
}
val32 = val64;
while(val32 > 999){
level++;
oldval = val32;
val32 /= 1024;
}
if(val32 < 10){
unsigned fract = (oldval % 1024) * 10 / 1024;
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
}
return sprintf(dst, "%3u%c ", val32, suffix[level]);
}
// produce: " 6 ", "123 ", "123k ", etc.
static int format_1000(unsigned long long val64, char *restrict dst){
unsigned oldval;
const char suffix[] = " kmgtpe";
unsigned level = 0;
unsigned val32;
if(val64 < 1000){ // special case to avoid "6.0 " when plain " 6 " would do
val32 = val64;
return sprintf(dst,"%3u ",val32);
}
while(val64 > 0xffffffffull){
level++;
val64 /= 1000;
}
val32 = val64;
while(val32 > 999){
level++;
oldval = val32;
val32 /= 1000;
}
if(val32 < 10){
unsigned fract = (oldval % 1000) / 100;
return sprintf(dst, "%u.%u%c ", val32, fract, suffix[level]);
}
return sprintf(dst, "%3u%c ", val32, suffix[level]);
}
#endif
////////////////////////////////////////////////////////////////////////////
static void new_header(void){
printf("procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----\n");
printf(
"%2s %2s %6s %6s %6s %6s %4s %4s %5s %5s %4s %4s %2s %2s %2s %2s\n",
"r","b",
"swpd", "free", a_option?"inact":"buff", a_option?"active":"cache",
"si","so",
"bi","bo",
"in","cs",
"us","sy","id","wa"
);
}
////////////////////////////////////////////////////////////////////////////
static unsigned long unitConvert(unsigned int size){
float cvSize;
cvSize=(float)size/dataUnit*((statMode==SLABSTAT)?1:1024);
return ((unsigned long) cvSize);
}
////////////////////////////////////////////////////////////////////////////
static void new_format(void) {
const char format[]="%2u %2u %6lu %6lu %6lu %6lu %4u %4u %5u %5u %4u %4u %2u %2u %2u %2u\n";
unsigned int tog=0; /* toggle switch for cleaner code */
unsigned int i;
unsigned int hz = Hertz;
unsigned int running,blocked,dummy_1,dummy_2;
jiff cpu_use[2], cpu_nic[2], cpu_sys[2], cpu_idl[2], cpu_iow[2], cpu_xxx[2], cpu_yyy[2], cpu_zzz[2];
jiff duse, dsys, didl, diow, dstl, Div, divo2;
unsigned long pgpgin[2], pgpgout[2], pswpin[2], pswpout[2];
unsigned int intr[2], ctxt[2];
unsigned int sleep_half;
unsigned long kb_per_page = sysconf(_SC_PAGESIZE) / 1024ul;
int debt = 0; // handle idle ticks running backwards
sleep_half=(sleep_time/2);
new_header();
meminfo();
getstat(cpu_use,cpu_nic,cpu_sys,cpu_idl,cpu_iow,cpu_xxx,cpu_yyy,cpu_zzz,
pgpgin,pgpgout,pswpin,pswpout,
intr,ctxt,
&running,&blocked,
&dummy_1, &dummy_2);
duse= *cpu_use + *cpu_nic;
dsys= *cpu_sys + *cpu_xxx + *cpu_yyy;
didl= *cpu_idl;
diow= *cpu_iow;
dstl= *cpu_zzz;
Div= duse+dsys+didl+diow+dstl;
divo2= Div/2UL;
printf(format,
running, blocked,
unitConvert(kb_swap_used), unitConvert(kb_main_free),
unitConvert(a_option?kb_inactive:kb_main_buffers),
unitConvert(a_option?kb_active:kb_main_cached),
(unsigned)( (*pswpin * unitConvert(kb_per_page) * hz + divo2) / Div ),
(unsigned)( (*pswpout * unitConvert(kb_per_page) * hz + divo2) / Div ),
(unsigned)( (*pgpgin * hz + divo2) / Div ),
(unsigned)( (*pgpgout * hz + divo2) / Div ),
(unsigned)( (*intr * hz + divo2) / Div ),
(unsigned)( (*ctxt * hz + divo2) / Div ),
(unsigned)( (100*duse + divo2) / Div ),
(unsigned)( (100*dsys + divo2) / Div ),
(unsigned)( (100*didl + divo2) / Div ),
(unsigned)( (100*diow + divo2) / Div ) /* ,
(unsigned)( (100*dstl + divo2) / Div ) */
);
for(i=1;i<num_updates;i++) { /* \\\\\\\\\\\\\\\\\\\\ main loop ////////////////// */
sleep(sleep_time);
if (moreheaders && ((i%height)==0)) new_header();
tog= !tog;
meminfo();
getstat(cpu_use+tog,cpu_nic+tog,cpu_sys+tog,cpu_idl+tog,cpu_iow+tog,cpu_xxx+tog,cpu_yyy+tog,cpu_zzz+tog,
pgpgin+tog,pgpgout+tog,pswpin+tog,pswpout+tog,
intr+tog,ctxt+tog,
&running,&blocked,
&dummy_1,&dummy_2);
duse= cpu_use[tog]-cpu_use[!tog] + cpu_nic[tog]-cpu_nic[!tog];
dsys= cpu_sys[tog]-cpu_sys[!tog] + cpu_xxx[tog]-cpu_xxx[!tog] + cpu_yyy[tog]-cpu_yyy[!tog];
didl= cpu_idl[tog]-cpu_idl[!tog];
diow= cpu_iow[tog]-cpu_iow[!tog];
dstl= cpu_zzz[tog]-cpu_zzz[!tog];
/* idle can run backwards for a moment -- kernel "feature" */
if(debt){
didl = (int)didl + debt;
debt = 0;
}
if( (int)didl < 0 ){
debt = (int)didl;
didl = 0;
}
Div= duse+dsys+didl+diow+dstl;
divo2= Div/2UL;
printf(format,
running, blocked,
unitConvert(kb_swap_used),unitConvert(kb_main_free),
unitConvert(a_option?kb_inactive:kb_main_buffers),
unitConvert(a_option?kb_active:kb_main_cached),
(unsigned)( ( (pswpin [tog] - pswpin [!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*si*/
(unsigned)( ( (pswpout[tog] - pswpout[!tog])*unitConvert(kb_per_page)+sleep_half )/sleep_time ), /*so*/
(unsigned)( ( pgpgin [tog] - pgpgin [!tog] +sleep_half )/sleep_time ), /*bi*/
(unsigned)( ( pgpgout[tog] - pgpgout[!tog] +sleep_half )/sleep_time ), /*bo*/
(unsigned)( ( intr [tog] - intr [!tog] +sleep_half )/sleep_time ), /*in*/
(unsigned)( ( ctxt [tog] - ctxt [!tog] +sleep_half )/sleep_time ), /*cs*/
(unsigned)( (100*duse+divo2)/Div ), /*us*/
(unsigned)( (100*dsys+divo2)/Div ), /*sy*/
(unsigned)( (100*didl+divo2)/Div ), /*id*/
(unsigned)( (100*diow+divo2)/Div )/*, //wa
(unsigned)( (100*dstl+divo2)/Div ) //st */
);
}
}
////////////////////////////////////////////////////////////////////////////
static void diskpartition_header(const char *partition_name){
printf("%-10s %10s %10s %10s %10s\n",partition_name, "reads ", "read sectors", "writes ", "requested writes");
}
////////////////////////////////////////////////////////////////////////////
static int diskpartition_format(const char* partition_name){
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions, *current_partition=NULL;
unsigned long ndisks, j, k, npartitions;
const char format[] = "%20u %10llu %10u %10u\n";
fDiskstat=fopen("/proc/diskstats","rb");
if(!fDiskstat){
fprintf(stderr, "Your kernel doesn't support diskstat. (2.5.70 or above required)\n");
exit(EXIT_FAILURE);
}
fclose(fDiskstat);
ndisks=getdiskstat(&disks,&partitions);
npartitions=getpartitions_num(disks, ndisks);
for(k=0; k<npartitions; k++){
if(!strcmp(partition_name, partitions[k].partition_name)){
current_partition=&(partitions[k]);
}
}
if(!current_partition){
return -1;
}
diskpartition_header(partition_name);
printf (format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
for(j=1; j<num_updates; j++){
if (moreheaders && ((j%height)==0)) diskpartition_header(partition_name);
sleep(sleep_time);
ndisks=getdiskstat(&disks,&partitions);
npartitions=getpartitions_num(disks, ndisks);
current_partition=NULL;
for(k=0; k<npartitions; k++){
if(!strcmp(partition_name, partitions[k].partition_name)){
current_partition=&(partitions[k]);
}
}
if(!current_partition){
return -1;
}
printf (format,
current_partition->reads,current_partition->reads_sectors,current_partition->writes,current_partition->requested_writes);
fflush(stdout);
free(disks);
free(partitions);
}
return 0;
}
////////////////////////////////////////////////////////////////////////////
static void diskheader(void){
printf("disk- ------------reads------------ ------------writes----------- -----IO------\n");
printf("%5s %6s %6s %7s %7s %6s %6s %7s %7s %6s %6s\n",
" ", "total", "merged","sectors","ms","total","merged","sectors","ms","cur","sec");
}
////////////////////////////////////////////////////////////////////////////
static void diskformat(void){
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions;
unsigned long ndisks,i,j,k;
const char format[]="%-5s %6u %6u %7llu %7u %6u %6u %7llu %7u %6u %6u\n";
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
fclose(fDiskstat);
ndisks=getdiskstat(&disks,&partitions);
for(k=0; k<ndisks; k++){
if (moreheaders && ((k%height)==0)) diskheader();
printf(format,
disks[k].disk_name,
disks[k].reads,
disks[k].merged_reads,
disks[k].reads_sectors,
disks[k].milli_reading,
disks[k].writes,
disks[k].merged_writes,
disks[k].written_sectors,
disks[k].milli_writing,
disks[k].inprogress_IO?disks[k].inprogress_IO/1000:0,
disks[k].milli_spent_IO?disks[k].milli_spent_IO/1000:0/*,
disks[i].weighted_milli_spent_IO/1000*/
);
fflush(stdout);
}
free(disks);
free(partitions);
for(j=1; j<num_updates; j++){
sleep(sleep_time);
ndisks=getdiskstat(&disks,&partitions);
for(i=0; i<ndisks; i++,k++){
if (moreheaders && ((k%height)==0)) diskheader();
printf(format,
disks[i].disk_name,
disks[i].reads,
disks[i].merged_reads,
disks[i].reads_sectors,
disks[i].milli_reading,
disks[i].writes,
disks[i].merged_writes,
disks[i].written_sectors,
disks[i].milli_writing,
disks[i].inprogress_IO?disks[i].inprogress_IO/1000:0,
disks[i].milli_spent_IO?disks[i].milli_spent_IO/1000:0/*,
disks[i].weighted_milli_spent_IO/1000*/
);
fflush(stdout);
}
free(disks);
free(partitions);
}
}else{
fprintf(stderr, "Your kernel doesn't support diskstat (2.5.70 or above required)\n");
exit(EXIT_FAILURE);
}
}
////////////////////////////////////////////////////////////////////////////
static void slabheader(void){
printf("%-24s %6s %6s %6s %6s\n","Cache","Num", "Total", "Size", "Pages");
}
////////////////////////////////////////////////////////////////////////////
static void slabformat (void){
FILE *fSlab;
struct slab_cache *slabs;
unsigned long nSlab,i,j,k;
const char format[]="%-24s %6u %6u %6u %6u\n";
fSlab=fopen("/proc/slabinfo", "rb");
if(!fSlab){
fprintf(stderr, "Your kernel doesn't support slabinfo.\n");
return;
}
nSlab = getslabinfo(&slabs);
for(k=0; k<nSlab; k++){
if (moreheaders && ((k%height)==0)) slabheader();
printf(format,
slabs[k].name,
slabs[k].active_objs,
slabs[k].num_objs,
slabs[k].objsize,
slabs[k].objperslab
);
}
free(slabs);
for(j=1,k=1; j<num_updates; j++) {
sleep(sleep_time);
nSlab = getslabinfo(&slabs);
for(i=0; i<nSlab; i++,k++){
if (moreheaders && ((k%height)==0)) slabheader();
printf(format,
slabs[i].name,
slabs[i].active_objs,
slabs[i].num_objs,
slabs[i].objsize,
slabs[i].objperslab
);
}
free(slabs);
}
}
////////////////////////////////////////////////////////////////////////////
static void disksum_format(void) {
FILE *fDiskstat;
struct disk_stat *disks;
struct partition_stat *partitions;
int ndisks, i;
unsigned long reads, merged_reads, read_sectors, milli_reading, writes,
merged_writes, written_sectors, milli_writing, inprogress_IO,
milli_spent_IO, weighted_milli_spent_IO;
reads=merged_reads=read_sectors=milli_reading=writes=merged_writes= \
written_sectors=milli_writing=inprogress_IO=milli_spent_IO= \
weighted_milli_spent_IO=0;
if ((fDiskstat=fopen("/proc/diskstats", "rb"))){
fclose(fDiskstat);
ndisks=getdiskstat(&disks, &partitions);
printf("%13d disks \n", ndisks);
printf("%13d partitions \n", getpartitions_num(disks, ndisks));
for(i=0; i<ndisks; i++){
reads+=disks[i].reads;
merged_reads+=disks[i].merged_reads;
read_sectors+=disks[i].reads_sectors;
milli_reading+=disks[i].milli_reading;
writes+=disks[i].writes;
merged_writes+=disks[i].merged_writes;
written_sectors+=disks[i].written_sectors;
milli_writing+=disks[i].milli_writing;
inprogress_IO+=disks[i].inprogress_IO?disks[i].inprogress_IO/1000:0;
milli_spent_IO+=disks[i].milli_spent_IO?disks[i].milli_spent_IO/1000:0;
}
printf("%13lu total reads\n",reads);
printf("%13lu merged reads\n",merged_reads);
printf("%13lu read sectors\n",read_sectors);
printf("%13lu milli reading\n",milli_reading);
printf("%13lu writes\n",writes);
printf("%13lu merged writes\n",merged_writes);
printf("%13lu written sectors\n",written_sectors);
printf("%13lu milli writing\n",milli_writing);
printf("%13lu inprogress IO\n",inprogress_IO);
printf("%13lu milli spent IO\n",milli_spent_IO);
free(disks);
free(partitions);
}
}
////////////////////////////////////////////////////////////////////////////
static void sum_format(void) {
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
unsigned int intr, ctxt;
meminfo();
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
&pgpgin, &pgpgout, &pswpin, &pswpout,
&intr, &ctxt,
&running, &blocked,
&btime, &processes);
printf("%13lu %s total memory\n", unitConvert(kb_main_total),szDataUnit);
printf("%13lu %s used memory\n", unitConvert(kb_main_used),szDataUnit);
printf("%13lu %s active memory\n", unitConvert(kb_active),szDataUnit);
printf("%13lu %s inactive memory\n", unitConvert(kb_inactive),szDataUnit);
printf("%13lu %s free memory\n", unitConvert(kb_main_free),szDataUnit);
printf("%13lu %s buffer memory\n", unitConvert(kb_main_buffers),szDataUnit);
printf("%13lu %s swap cache\n", unitConvert(kb_main_cached),szDataUnit);
printf("%13lu %s total swap\n", unitConvert(kb_swap_total),szDataUnit);
printf("%13lu %s used swap\n", unitConvert(kb_swap_used),szDataUnit);
printf("%13lu %s free swap\n", unitConvert(kb_swap_free),szDataUnit);
printf("%13Lu non-nice user cpu ticks\n", cpu_use);
printf("%13Lu nice user cpu ticks\n", cpu_nic);
printf("%13Lu system cpu ticks\n", cpu_sys);
printf("%13Lu idle cpu ticks\n", cpu_idl);
printf("%13Lu IO-wait cpu ticks\n", cpu_iow);
printf("%13Lu IRQ cpu ticks\n", cpu_xxx);
printf("%13Lu softirq cpu ticks\n", cpu_yyy);
printf("%13Lu stolen cpu ticks\n", cpu_zzz);
printf("%13lu pages paged in\n", pgpgin);
printf("%13lu pages paged out\n", pgpgout);
printf("%13lu pages swapped in\n", pswpin);
printf("%13lu pages swapped out\n", pswpout);
printf("%13u interrupts\n", intr);
printf("%13u CPU context switches\n", ctxt);
printf("%13u boot time\n", btime);
printf("%13u forks\n", processes);
}
////////////////////////////////////////////////////////////////////////////
static void fork_format(void) {
unsigned int running, blocked, btime, processes;
jiff cpu_use, cpu_nic, cpu_sys, cpu_idl, cpu_iow, cpu_xxx, cpu_yyy, cpu_zzz;
unsigned long pgpgin, pgpgout, pswpin, pswpout;
unsigned int intr, ctxt;
getstat(&cpu_use, &cpu_nic, &cpu_sys, &cpu_idl,
&cpu_iow, &cpu_xxx, &cpu_yyy, &cpu_zzz,
&pgpgin, &pgpgout, &pswpin, &pswpout,
&intr, &ctxt,
&running, &blocked,
&btime, &processes);
printf("%13u forks\n", processes);
}
////////////////////////////////////////////////////////////////////////////
static int winhi(void) {
struct winsize win;
int rows = 24;
if (ioctl(1, TIOCGWINSZ, &win) != -1 && win.ws_row > 0)
rows = win.ws_row;
return rows;
}
////////////////////////////////////////////////////////////////////////////
int main(int argc, char *argv[]) {
char partition[16];
argc=0; /* redefined as number of integer arguments */
for (argv++;*argv;argv++) {
if ('-' ==(**argv)) {
switch (*(++(*argv))) {
case 'V':
display_version();
exit(0);
case 'd':
statMode |= DISKSTAT;
break;
case 'a':
/* active/inactive mode */
a_option=1;
break;
case 'f':
// FIXME: check for conflicting args
fork_format();
exit(0);
case 'm':
statMode |= SLABSTAT;
break;
case 'D':
statMode |= DISKSUMSTAT;
break;
case 'n':
/* print only one header */
moreheaders=FALSE;
break;
case 'p':
statMode |= PARTITIONSTAT;
if (argv[1]){
char *cp = *++argv;
if(!memcmp(cp,"/dev/",5)) cp += 5;
snprintf(partition, sizeof partition, "%s", cp);
}else{
fprintf(stderr, "-p requires an argument\n");
exit(EXIT_FAILURE);
}
break;
case 'S':
if (argv[1]){
++argv;
if (!strcmp(*argv, "k")) dataUnit=UNIT_k;
else if (!strcmp(*argv, "K")) dataUnit=UNIT_K;
else if (!strcmp(*argv, "m")) dataUnit=UNIT_m;
else if (!strcmp(*argv, "M")) dataUnit=UNIT_M;
else {fprintf(stderr, "-S requires k, K, m or M (default is kb)\n");
exit(EXIT_FAILURE);
}
strcpy(szDataUnit, *argv);
}else {fprintf(stderr, "-S requires an argument\n");
exit(EXIT_FAILURE);
}
break;
case 's':
statMode |= VMSUMSTAT;
break;
default:
/* no other aguments defined yet. */
usage();
}
}else{
argc++;
switch (argc) {
case 1:
if ((sleep_time = atoi(*argv)) == 0)
usage();
num_updates = ULONG_MAX;
break;
case 2:
num_updates = atol(*argv);
break;
default:
usage();
} /* switch */
}
}
if (moreheaders) {
int tmp=winhi()-3;
height=((tmp>0)?tmp:22);
}
setlinebuf(stdout);
switch(statMode){
case(VMSTAT): new_format();
break;
case(VMSUMSTAT): sum_format();
break;
case(DISKSTAT): diskformat();
break;
case(PARTITIONSTAT): if(diskpartition_format(partition)==-1)
printf("Partition was not found\n");
break;
case(SLABSTAT): slabformat();
break;
case(DISKSUMSTAT): disksum_format();
break;
default: usage();
break;
}
return 0;
}
| 31.657971 | 129 | 0.575719 |
f0754c82c7de82935c96f756fea5e160d20e9283 | 5,901 | h | C | include/onnxruntime/core/graph/schema_registry.h | KsenijaS/onnxruntime | 5086e55a35f83e3137bdb34b6d7210c97a512e6a | [
"MIT"
] | 4 | 2019-06-06T23:48:57.000Z | 2021-06-03T11:51:45.000Z | include/onnxruntime/core/graph/schema_registry.h | Montaer/onnxruntime | 6dc25a60f8b058a556964801d99d5508641dcf69 | [
"MIT"
] | 17 | 2020-07-21T11:13:27.000Z | 2022-03-27T02:37:05.000Z | include/onnxruntime/core/graph/schema_registry.h | Surfndez/onnxruntime | 9d748afff19e9604a00632d66b97159b917dabb2 | [
"MIT"
] | 3 | 2019-05-07T01:29:04.000Z | 2020-08-09T08:36:12.000Z | // Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#pragma once
#include "core/graph/constants.h"
#include "core/common/common.h"
#include "core/common/status.h"
#include "core/graph/onnx_protobuf.h"
#include "core/platform/ort_mutex.h"
#include <mutex>
#include <deque>
#include "sstream"
namespace onnxruntime {
using OpName_Domain_Version_Schema_Map = std::unordered_map<
std::string,
std::unordered_map<std::string, std::map<ONNX_NAMESPACE::OperatorSetVersion, ONNX_NAMESPACE::OpSchema>>>;
/**
@struct SchemaRegistryVersion
onnxruntime schema registry is a supplement to the built-in ONNX schema.
Every schema registry represent a collection of schema deltas from baseline_opset_version to opset_version
*/
struct SchemaRegistryVersion {
int baseline_opset_version;
int opset_version;
};
using DomainToVersionMap = std::unordered_map<std::string, int>;
using DomainToVersionRangeMap = std::unordered_map<std::string, SchemaRegistryVersion>;
class IOnnxRuntimeOpSchemaCollection : public ONNX_NAMESPACE::ISchemaRegistry {
public:
virtual DomainToVersionMap GetLatestOpsetVersions(bool is_onnx_only) const = 0;
using ISchemaRegistry::GetSchema;
const ONNX_NAMESPACE::OpSchema* GetSchema(const std::string& key, const int maxInclusiveVersion,
const std::string& domain) const final {
const ONNX_NAMESPACE::OpSchema* latest_schema = nullptr;
int earliest_opset_where_unchanged = std::numeric_limits<int>::max();
GetSchemaAndHistory(key, maxInclusiveVersion, domain, &latest_schema, &earliest_opset_where_unchanged);
assert(latest_schema == nullptr || (latest_schema->SinceVersion() <= maxInclusiveVersion &&
earliest_opset_where_unchanged == latest_schema->SinceVersion()));
return latest_schema;
}
virtual void GetSchemaAndHistory(
const std::string& key,
int maxInclusiveVersion,
const std::string& domain,
const ONNX_NAMESPACE::OpSchema** latest_schema,
int* earliest_opset_where_unchanged) const = 0;
};
/**
@class OnnxRuntimeOpSchemaRegistry
OnnxRuntimeOpSchemaRegistry is used to provide supplement for built-in ONNX schemas.
Each OnnxRuntimeOpSchemaRegistry must register complete opsets delta from a baseline version to max opset version.
(Please notice that baseline opsets are not include in the delta)
For example, ONNXRuntime is build with ONNX 1.2 which is at opset7, to use ONNX opset8 and opset9,
user could create a OnnxRuntimeOpSchemaRegistry and config it as {baseline_opset_version = 7, opset_version = 9}
it means this OnnxRuntimeOpSchemaRegistry contains the complete delta from opset7 to opset9.
*/
class OnnxRuntimeOpSchemaRegistry : public IOnnxRuntimeOpSchemaCollection {
public:
OnnxRuntimeOpSchemaRegistry() = default;
common::Status SetBaselineAndOpsetVersionForDomain(
const std::string& domain,
int baseline_opset_version,
int opset_version);
DomainToVersionMap GetLatestOpsetVersions(bool is_onnx_only) const override;
// OnnxRuntimeOpSchemaRegistry must register complete delta for a opset.
common::Status RegisterOpSet(
std::vector<ONNX_NAMESPACE::OpSchema>& schemas,
const std::string& domain,
int baseline_opset_version,
int opset_version);
using IOnnxRuntimeOpSchemaCollection::GetSchema;
void GetSchemaAndHistory(const std::string& key, int maxInclusiveVersion, const std::string& domain,
const ONNX_NAMESPACE::OpSchema** latest_schema,
int* earliest_opset_where_unchanged) const override;
bool empty() const {
return map_.empty();
}
private:
common::Status RegisterOpSchema(ONNX_NAMESPACE::OpSchema&& op_schema);
common::Status RegisterOpSchemaInternal(ONNX_NAMESPACE::OpSchema&& op_schema);
OrtMutex mutex_;
OpName_Domain_Version_Schema_Map map_;
DomainToVersionRangeMap domain_version_range_map_;
};
/**
@class SchemaRegistryManager
SchemaRegistryManager provides a view based on built-in ONNX schema and a list of
OnnxRuntimeOpSchemaRegistry as supplement.
The user needs to make sure the customized schema registry is valid, otherwise the behavior is undefined.
@todo We may add more consistency checks later.
*/
class SchemaRegistryManager : public onnxruntime::IOnnxRuntimeOpSchemaCollection {
public:
/**
Register a new schema registry instance.
@remarks The schema registry priority is the reverse of registration order. i.e. the last registry added will be
searched first for a matching OpSchema.
*/
void RegisterRegistry(std::shared_ptr<IOnnxRuntimeOpSchemaCollection> registry);
/** Gets the latest opset versions.
@param is_onnx_only If true, return the latest ONNX schemas. If false, return the latest schemas for all domains.
*/
DomainToVersionMap GetLatestOpsetVersions(bool is_onnx_only) const override;
/**
Gets the OpSchema and its history.
Searches custom schema registries starting with the last one added. \
If the OpSchema is not found the default ONNX schema registry is searched.
@param key Operator type.
@param max_inclusive_version Maximum opset version allowed, inclusive.
@param domain The domain of the operator.
@param[out] latest_schema Returns the latest OpSchema if found. nullptr otherwise.
@param[out] earliest_opset_where_unchanged The earliest opset version preceding max_inclusive_version where the
operator is known to be unchanged.
*/
void GetSchemaAndHistory(const std::string& key, int max_inclusive_version, const std::string& domain,
const ONNX_NAMESPACE::OpSchema** latest_schema,
int* earliest_opset_where_unchanged) const override;
private:
std::deque<std::shared_ptr<IOnnxRuntimeOpSchemaCollection>> registries;
};
} // namespace onnxruntime
| 38.568627 | 115 | 0.762244 |
5378f0f6901768663f4ddc44848c22dce61b5587 | 709 | h | C | server-client-sample/generic/Main.h | kaiostech/gonk-binder | 5ab61435a1939f992e4ace372b9c694a65023927 | [
"FSFAP"
] | null | null | null | server-client-sample/generic/Main.h | kaiostech/gonk-binder | 5ab61435a1939f992e4ace372b9c694a65023927 | [
"FSFAP"
] | null | null | null | server-client-sample/generic/Main.h | kaiostech/gonk-binder | 5ab61435a1939f992e4ace372b9c694a65023927 | [
"FSFAP"
] | 2 | 2020-07-17T01:55:32.000Z | 2021-08-12T06:12:29.000Z | /* (c) 2020 KAI OS TECHNOLOGIES (HONG KONG) LIMITED All rights reserved. This
* file or any portion thereof may not be reproduced or used in any manner
* whatsoever without the express written permission of KAI OS TECHNOLOGIES
* (HONG KONG) LIMITED. KaiOS is the trademark of KAI OS TECHNOLOGIES (HONG
* KONG) LIMITED or its affiliate company and may be registered in some
* jurisdictions. All other trademarks are the property of their respective
* owners.
*/
#ifndef _AIDL_TEST_H_
#define _AIDL_TEST_H_
#include <android/log.h>
#include <binder/Status.h>
#if defined(CLASSIC_TEST) || defined(INHERIT_TEST) || defined(REAL_SERVER_TEST)
volatile int serverStop = 0;
#endif
#endif // _AIDL_TEST_H_
| 33.761905 | 79 | 0.767278 |
bb20c1793c447e83090caf6876909f3df0a008e4 | 500 | h | C | src/images/font/Chars8bpp/Char_s.h | filmote/Karateka_Pokitto | 0448237eb5df93591955a1ca51ee066323cf90f3 | [
"BSD-3-Clause"
] | 1 | 2020-08-25T14:59:30.000Z | 2020-08-25T14:59:30.000Z | src/images/font/Chars8bpp/Char_s.h | filmote/Karateka_Pokitto | 0448237eb5df93591955a1ca51ee066323cf90f3 | [
"BSD-3-Clause"
] | null | null | null | src/images/font/Chars8bpp/Char_s.h | filmote/Karateka_Pokitto | 0448237eb5df93591955a1ca51ee066323cf90f3 | [
"BSD-3-Clause"
] | null | null | null | // Automatically generated file, do not edit.
#pragma once
const uint8_t Char_s[] = {
6, 13,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x07,0x07,0x07,0x07,0x00,
0x07,0x07,0x00,0x00,0x07,0x07,
0x07,0x07,0x00,0x00,0x00,0x00,
0x00,0x07,0x07,0x07,0x00,0x00,
0x00,0x00,0x07,0x07,0x07,0x00,
0x00,0x00,0x00,0x00,0x07,0x07,
0x07,0x07,0x00,0x00,0x07,0x07,
0x00,0x07,0x07,0x07,0x07,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00
};
| 23.809524 | 45 | 0.756 |
bb583995614c4ce8675e7e201cb534722028bc63 | 457 | c | C | nitan/d/baituo/obj/branch2.c | cantona/NT6 | 073f4d491b3cfe6bfbe02fbad12db8983c1b9201 | [
"MIT"
] | 1 | 2019-03-27T07:25:16.000Z | 2019-03-27T07:25:16.000Z | nitan/d/city/obj/branch2.c | cantona/NT6 | 073f4d491b3cfe6bfbe02fbad12db8983c1b9201 | [
"MIT"
] | null | null | null | nitan/d/city/obj/branch2.c | cantona/NT6 | 073f4d491b3cfe6bfbe02fbad12db8983c1b9201 | [
"MIT"
] | null | null | null | // Code of ShenZhou
// branch2.c
// Jay 7/4/96
#include <ansi.h>
#include <weapon.h>
inherit CLUB;
void create()
{
set_name(YEL"大樹枝"NOR, ({"shuzhi", "zhi", "branch"}));
set_weight(500+random(500));
if( clonep() )
set_default_object(__FILE__);
else {
set("long", "這是一根大樹枝。\n");
set("unit","根");
set("wield_msg","$N拔出一根大樹枝握在手中。\n");
set("material", "wood");
}
init_club(random(2));
setup();
} | 19.869565 | 57 | 0.551422 |
9bb656309c852989d33743c72c0d304b2f764c18 | 761 | h | C | include/FeOSMusic.h | fincs/FeOSMusic | c036d358facf9b469ac7bae1884f79a0e5a78462 | [
"BSD-2-Clause"
] | 2 | 2019-02-14T19:33:37.000Z | 2019-04-27T20:16:58.000Z | include/FeOSMusic.h | fincs/FeOSMusic | c036d358facf9b469ac7bae1884f79a0e5a78462 | [
"BSD-2-Clause"
] | null | null | null | include/FeOSMusic.h | fincs/FeOSMusic | c036d358facf9b469ac7bae1884f79a0e5a78462 | [
"BSD-2-Clause"
] | null | null | null | #ifndef FEOS_MUSIC_H
#define FEOS_MUSIC_H
#include <feos.h>
#include <feos3d.h>
#include <SndStream.h>
#include <far.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <stdarg.h>
#include "browser.h"
#include "codec.h"
#include "decoder.h"
#include "file.h"
#include "filter.h"
#include "gui.h"
#include "input.h"
#include "playlist.h"
#include "sprite.h"
#include "video.h"
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define CYCLE(n,l,u) ((n) = ((n)>(u) ? (l) : ((n)<(l) ? (u) : (n))))
#define CLAMP(n,l,u) ((n) = ((n) > (u) ? (u) : ((n)<(l) ? (l) : (n))))
void initFeOSMusic(const char* cmdLineArg);
void deinitFeOSMusic(void);
int binLog(int no);
#endif | 21.742857 | 70 | 0.605782 |
49b32d426c3c7a18de73b9fa5d150b72df459c79 | 1,541 | c | C | ciri/consensus/tip_selection/cw_rating_calculator/cw_rating_calculator.c | thibault-martinez/entangled | a166273fe518f001decf76e599c4ee615a9b4985 | [
"Apache-2.0"
] | 19 | 2019-09-17T18:14:36.000Z | 2021-12-06T07:29:27.000Z | ciri/consensus/tip_selection/cw_rating_calculator/cw_rating_calculator.c | thibault-martinez/entangled | a166273fe518f001decf76e599c4ee615a9b4985 | [
"Apache-2.0"
] | 5 | 2019-09-30T04:57:14.000Z | 2020-11-10T15:41:03.000Z | ciri/consensus/tip_selection/cw_rating_calculator/cw_rating_calculator.c | thibault-martinez/entangled | a166273fe518f001decf76e599c4ee615a9b4985 | [
"Apache-2.0"
] | 2 | 2019-09-17T19:03:16.000Z | 2021-03-01T01:04:31.000Z | /*
* Copyright (c) 2018 IOTA Stiftung
* https://github.com/iotaledger/entangled
*
* Refer to the LICENSE file for licensing information
*/
#include "ciri/consensus/tip_selection/cw_rating_calculator/cw_rating_dfs_impl.h"
#include "common/errors.h"
#include "utils/logger_helper.h"
#include "utils/macros.h"
#define CW_RATING_CALCULATOR_LOGGER_ID "cw_rating_calculator"
static logger_id_t logger_id;
retcode_t iota_consensus_cw_rating_init(cw_rating_calculator_t *const cw_calc, cw_calculation_implementation_t impl) {
logger_id = logger_helper_enable(CW_RATING_CALCULATOR_LOGGER_ID, LOGGER_DEBUG, true);
if (impl == DFS_FROM_ENTRY_POINT) {
init_cw_calculator_dfs(&cw_calc->base);
return RC_OK;
}
return RC_OK;
}
retcode_t iota_consensus_cw_rating_destroy(cw_rating_calculator_t *cw_calc) {
UNUSED(cw_calc);
logger_helper_release(logger_id);
return RC_OK;
}
retcode_t iota_consensus_cw_rating_calculate(cw_rating_calculator_t const *const cw_calc, tangle_t *const tangle,
flex_trit_t const *const entry_point, cw_calc_result *const out) {
if (cw_calc->base.vtable.cw_rating_calculate == NULL) {
log_error(logger_id, "Vtable is not initialized\n");
return RC_NULL_PARAM;
}
return cw_calc->base.vtable.cw_rating_calculate(cw_calc, tangle, entry_point, out);
}
void cw_calc_result_destroy(cw_calc_result *const calc_result) {
hash_to_indexed_hash_set_map_free(&calc_result->tx_to_approvers);
hash_to_int64_t_map_free(&calc_result->cw_ratings);
}
| 32.787234 | 118 | 0.77547 |
4f96268f7f37069903c0bc7e9e0b9f329c5db1e3 | 6,505 | h | C | tcb/include/tencentcloud/tcb/v20180608/model/CreateWxCloudBaseRunEnvRequest.h | suluner/tencentcloud-sdk-cpp | a56c73cc3f488c4d1e10755704107bb15c5e000d | [
"Apache-2.0"
] | 43 | 2019-08-14T08:14:12.000Z | 2022-03-30T12:35:09.000Z | tcb/include/tencentcloud/tcb/v20180608/model/CreateWxCloudBaseRunEnvRequest.h | suluner/tencentcloud-sdk-cpp | a56c73cc3f488c4d1e10755704107bb15c5e000d | [
"Apache-2.0"
] | 12 | 2019-07-15T10:44:59.000Z | 2021-11-02T12:35:00.000Z | tcb/include/tencentcloud/tcb/v20180608/model/CreateWxCloudBaseRunEnvRequest.h | suluner/tencentcloud-sdk-cpp | a56c73cc3f488c4d1e10755704107bb15c5e000d | [
"Apache-2.0"
] | 28 | 2019-07-12T09:06:22.000Z | 2022-03-30T08:04:18.000Z | /*
* Copyright (c) 2017-2019 THL A29 Limited, a Tencent company. All Rights Reserved.
*
* 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.
*/
#ifndef TENCENTCLOUD_TCB_V20180608_MODEL_CREATEWXCLOUDBASERUNENVREQUEST_H_
#define TENCENTCLOUD_TCB_V20180608_MODEL_CREATEWXCLOUDBASERUNENVREQUEST_H_
#include <string>
#include <vector>
#include <map>
#include <tencentcloud/core/AbstractModel.h>
namespace TencentCloud
{
namespace Tcb
{
namespace V20180608
{
namespace Model
{
/**
* CreateWxCloudBaseRunEnv请求参数结构体
*/
class CreateWxCloudBaseRunEnvRequest : public AbstractModel
{
public:
CreateWxCloudBaseRunEnvRequest();
~CreateWxCloudBaseRunEnvRequest() = default;
std::string ToJsonString() const;
/**
* 获取wx应用Id
* @return WxAppId wx应用Id
*/
std::string GetWxAppId() const;
/**
* 设置wx应用Id
* @param WxAppId wx应用Id
*/
void SetWxAppId(const std::string& _wxAppId);
/**
* 判断参数 WxAppId 是否已赋值
* @return WxAppId 是否已赋值
*/
bool WxAppIdHasBeenSet() const;
/**
* 获取环境别名,要以a-z开头,不能包含 a-z,0-9,- 以外的字符
* @return Alias 环境别名,要以a-z开头,不能包含 a-z,0-9,- 以外的字符
*/
std::string GetAlias() const;
/**
* 设置环境别名,要以a-z开头,不能包含 a-z,0-9,- 以外的字符
* @param Alias 环境别名,要以a-z开头,不能包含 a-z,0-9,- 以外的字符
*/
void SetAlias(const std::string& _alias);
/**
* 判断参数 Alias 是否已赋值
* @return Alias 是否已赋值
*/
bool AliasHasBeenSet() const;
/**
* 获取用户享有的免费额度级别,目前只能为“basic”,不传该字段或该字段为空,标识不享受免费额度。
* @return FreeQuota 用户享有的免费额度级别,目前只能为“basic”,不传该字段或该字段为空,标识不享受免费额度。
*/
std::string GetFreeQuota() const;
/**
* 设置用户享有的免费额度级别,目前只能为“basic”,不传该字段或该字段为空,标识不享受免费额度。
* @param FreeQuota 用户享有的免费额度级别,目前只能为“basic”,不传该字段或该字段为空,标识不享受免费额度。
*/
void SetFreeQuota(const std::string& _freeQuota);
/**
* 判断参数 FreeQuota 是否已赋值
* @return FreeQuota 是否已赋值
*/
bool FreeQuotaHasBeenSet() const;
/**
* 获取订单标记。建议使用方统一转大小写之后再判断。
QuickStart:快速启动来源
Activity:活动来源
* @return Flag 订单标记。建议使用方统一转大小写之后再判断。
QuickStart:快速启动来源
Activity:活动来源
*/
std::string GetFlag() const;
/**
* 设置订单标记。建议使用方统一转大小写之后再判断。
QuickStart:快速启动来源
Activity:活动来源
* @param Flag 订单标记。建议使用方统一转大小写之后再判断。
QuickStart:快速启动来源
Activity:活动来源
*/
void SetFlag(const std::string& _flag);
/**
* 判断参数 Flag 是否已赋值
* @return Flag 是否已赋值
*/
bool FlagHasBeenSet() const;
/**
* 获取私有网络Id
* @return VpcId 私有网络Id
*/
std::string GetVpcId() const;
/**
* 设置私有网络Id
* @param VpcId 私有网络Id
*/
void SetVpcId(const std::string& _vpcId);
/**
* 判断参数 VpcId 是否已赋值
* @return VpcId 是否已赋值
*/
bool VpcIdHasBeenSet() const;
/**
* 获取子网列表
* @return SubNetIds 子网列表
*/
std::vector<std::string> GetSubNetIds() const;
/**
* 设置子网列表
* @param SubNetIds 子网列表
*/
void SetSubNetIds(const std::vector<std::string>& _subNetIds);
/**
* 判断参数 SubNetIds 是否已赋值
* @return SubNetIds 是否已赋值
*/
bool SubNetIdsHasBeenSet() const;
private:
/**
* wx应用Id
*/
std::string m_wxAppId;
bool m_wxAppIdHasBeenSet;
/**
* 环境别名,要以a-z开头,不能包含 a-z,0-9,- 以外的字符
*/
std::string m_alias;
bool m_aliasHasBeenSet;
/**
* 用户享有的免费额度级别,目前只能为“basic”,不传该字段或该字段为空,标识不享受免费额度。
*/
std::string m_freeQuota;
bool m_freeQuotaHasBeenSet;
/**
* 订单标记。建议使用方统一转大小写之后再判断。
QuickStart:快速启动来源
Activity:活动来源
*/
std::string m_flag;
bool m_flagHasBeenSet;
/**
* 私有网络Id
*/
std::string m_vpcId;
bool m_vpcIdHasBeenSet;
/**
* 子网列表
*/
std::vector<std::string> m_subNetIds;
bool m_subNetIdsHasBeenSet;
};
}
}
}
}
#endif // !TENCENTCLOUD_TCB_V20180608_MODEL_CREATEWXCLOUDBASERUNENVREQUEST_H_
| 31.274038 | 88 | 0.430284 |
99333feac89983004071d63e6a091f8ae5cdc83d | 28,842 | h | C | gameboy.h | sysprog21/gameboy-emulator | 49b3befa0853578cee06d6b837e48f424bafc9e9 | [
"MIT"
] | 35 | 2020-11-23T08:06:16.000Z | 2022-01-18T18:31:24.000Z | gameboy.h | sysprog21/gameboy-emulator | 49b3befa0853578cee06d6b837e48f424bafc9e9 | [
"MIT"
] | 9 | 2020-11-23T14:15:30.000Z | 2021-01-14T11:42:02.000Z | gameboy.h | sysprog21/gameboy-emulator | 49b3befa0853578cee06d6b837e48f424bafc9e9 | [
"MIT"
] | 10 | 2020-11-23T09:01:55.000Z | 2022-02-07T12:54:20.000Z | /**
* MIT License
*
* Copyright (c) 2020 National Cheng Kung University, Taiwan.
* Copyright (c) 2018 Mahyar Koshkouei
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#pragma once
#include <time.h>
#include "core.h"
#include "cpu.h"
/* Tick the internal RTC by one second */
void gb_tick_rtc(struct gb_s *gb)
{
/* is timer running? */
if ((gb->cart_rtc[4] & 0x40) == 0) {
if (++gb->rtc_bits.sec == 60) {
gb->rtc_bits.sec = 0;
if (++gb->rtc_bits.min == 60) {
gb->rtc_bits.min = 0;
if (++gb->rtc_bits.hour == 24) {
gb->rtc_bits.hour = 0;
if (++gb->rtc_bits.yday == 0) {
if (gb->rtc_bits.high & 1) /* Bit 8 of days */
gb->rtc_bits.high |= 0x80; /* Overflow bit */
gb->rtc_bits.high ^= 1;
}
}
}
}
}
}
/* Set initial values in RTC.
* Should be called after gb_init().
*/
void gb_set_rtc(struct gb_s *gb, const struct tm *const time)
{
gb->cart_rtc[0] = time->tm_sec;
gb->cart_rtc[1] = time->tm_min;
gb->cart_rtc[2] = time->tm_hour;
gb->cart_rtc[3] = time->tm_yday & 0xFF; /* Low 8 bits of day counter */
gb->cart_rtc[4] = time->tm_yday >> 8; /* High 1 bit of day counter */
}
/* Internal function used to read bytes. */
uint8_t __gb_read(struct gb_s *gb, const uint_fast16_t addr)
{
switch (addr >> 12) {
case 0x0:
/* TODO: BIOS support */
case 0x1:
case 0x2:
case 0x3:
return gb->gb_rom_read(gb, addr);
case 0x4:
case 0x5:
case 0x6:
case 0x7:
if (gb->mbc == 1 && gb->cart_mode_select)
return gb->gb_rom_read(
gb,
addr + ((gb->selected_rom_bank & 0x1F) - 1) * ROM_BANK_SIZE);
return gb->gb_rom_read(
gb, addr + (gb->selected_rom_bank - 1) * ROM_BANK_SIZE);
case 0x8:
case 0x9:
return gb->vram[addr - VRAM_ADDR];
case 0xA:
case 0xB:
if (gb->cart_ram && gb->enable_cart_ram) {
if (gb->mbc == 3 && gb->cart_ram_bank >= 0x08)
return gb->cart_rtc[gb->cart_ram_bank - 0x08];
if ((gb->cart_mode_select || gb->mbc != 1) &&
gb->cart_ram_bank < gb->num_ram_banks)
return gb->gb_cart_ram_read(
gb, addr - CART_RAM_ADDR +
(gb->cart_ram_bank * CRAM_BANK_SIZE));
return gb->gb_cart_ram_read(gb, addr - CART_RAM_ADDR);
}
return 0;
case 0xC:
return gb->wram[addr - WRAM_0_ADDR];
case 0xD:
return gb->wram[addr - WRAM_1_ADDR + WRAM_BANK_SIZE];
case 0xE:
return gb->wram[addr - ECHO_ADDR];
case 0xF:
if (addr < OAM_ADDR)
return gb->wram[addr - ECHO_ADDR];
if (addr < UNUSED_ADDR)
return gb->oam[addr - OAM_ADDR];
/* Unusable memory area. Reading from this area returns 0. */
if (addr < IO_ADDR)
return 0xFF;
/* HRAM */
if (HRAM_ADDR <= addr && addr < INTR_EN_ADDR)
return gb->hram[addr - HRAM_ADDR];
if ((addr >= 0xFF10) && (addr <= 0xFF3F)) {
#if ENABLE_SOUND
return audio_read(addr);
#else
return 1;
#endif
}
/* IO and Interrupts */
switch (addr & 0xFF) {
/* IO Registers */
case 0x00:
return 0xC0 | gb->gb_reg.P1;
case 0x01:
return gb->gb_reg.SB;
case 0x02:
return gb->gb_reg.SC;
/* Timer Registers */
case 0x04:
return gb->gb_reg.DIV;
case 0x05:
return gb->gb_reg.TIMA;
case 0x06:
return gb->gb_reg.TMA;
case 0x07:
return gb->gb_reg.TAC;
/* Interrupt Flag Register */
case 0x0F:
return gb->gb_reg.IF;
/* LCD Registers */
case 0x40:
return gb->gb_reg.LCDC;
case 0x41:
return (gb->gb_reg.STAT & STAT_USER_BITS) |
(gb->gb_reg.LCDC & LCDC_ENABLE ? gb->lcd_mode : LCD_VBLANK);
case 0x42:
return gb->gb_reg.SCY;
case 0x43:
return gb->gb_reg.SCX;
case 0x44:
return gb->gb_reg.LY;
case 0x45:
return gb->gb_reg.LYC;
/* DMA Register */
case 0x46:
return gb->gb_reg.DMA;
/* DMG Palette Registers */
case 0x47:
return gb->gb_reg.BGP;
case 0x48:
return gb->gb_reg.OBP0;
case 0x49:
return gb->gb_reg.OBP1;
/* Window Position Registers */
case 0x4A:
return gb->gb_reg.WY;
case 0x4B:
return gb->gb_reg.WX;
/* Interrupt Enable Register */
case 0xFF:
return gb->gb_reg.IE;
/* Unused registers return 1 */
default:
return 0xFF;
}
}
(gb->gb_error)(gb, GB_INVALID_READ, addr);
return 0xFF;
}
/* Internal function used to write bytes */
void __gb_write(struct gb_s *gb,
const uint_fast16_t addr,
const uint8_t val)
{
switch (addr >> 12) {
case 0x0:
case 0x1:
if (gb->mbc == 2 && addr & 0x10)
return;
else if (gb->mbc > 0 && gb->cart_ram)
gb->enable_cart_ram = ((val & 0x0F) == 0x0A);
return;
case 0x2:
if (gb->mbc == 5) {
gb->selected_rom_bank = (gb->selected_rom_bank & 0x100) | val;
gb->selected_rom_bank = gb->selected_rom_bank % gb->num_rom_banks;
return;
}
/* Intentional fall through */
case 0x3:
if (gb->mbc == 1) {
// selected_rom_bank = val & 0x7;
gb->selected_rom_bank =
(val & 0x1F) | (gb->selected_rom_bank & 0x60);
if ((gb->selected_rom_bank & 0x1F) == 0x00)
gb->selected_rom_bank++;
} else if (gb->mbc == 2 && addr & 0x10) {
gb->selected_rom_bank = val & 0x0F;
if (!gb->selected_rom_bank)
gb->selected_rom_bank++;
} else if (gb->mbc == 3) {
gb->selected_rom_bank = val & 0x7F;
if (!gb->selected_rom_bank)
gb->selected_rom_bank++;
} else if (gb->mbc == 5)
gb->selected_rom_bank =
(val & 0x01) << 8 | (gb->selected_rom_bank & 0xFF);
gb->selected_rom_bank = gb->selected_rom_bank % gb->num_rom_banks;
return;
case 0x4:
case 0x5:
if (gb->mbc == 1) {
gb->cart_ram_bank = (val & 3);
gb->selected_rom_bank =
((val & 3) << 5) | (gb->selected_rom_bank & 0x1F);
gb->selected_rom_bank = gb->selected_rom_bank % gb->num_rom_banks;
} else if (gb->mbc == 3)
gb->cart_ram_bank = val;
else if (gb->mbc == 5)
gb->cart_ram_bank = (val & 0x0F);
return;
case 0x6:
case 0x7:
gb->cart_mode_select = (val & 1);
return;
case 0x8:
case 0x9:
gb->vram[addr - VRAM_ADDR] = val;
return;
case 0xA:
case 0xB:
if (gb->cart_ram && gb->enable_cart_ram) {
if (gb->mbc == 3 && gb->cart_ram_bank >= 0x08)
gb->cart_rtc[gb->cart_ram_bank - 0x08] = val;
else if (gb->cart_mode_select &&
gb->cart_ram_bank < gb->num_ram_banks) {
gb->gb_cart_ram_write(
gb,
addr - CART_RAM_ADDR + (gb->cart_ram_bank * CRAM_BANK_SIZE),
val);
} else if (gb->num_ram_banks)
gb->gb_cart_ram_write(gb, addr - CART_RAM_ADDR, val);
}
return;
case 0xC:
gb->wram[addr - WRAM_0_ADDR] = val;
return;
case 0xD:
gb->wram[addr - WRAM_1_ADDR + WRAM_BANK_SIZE] = val;
return;
case 0xE:
gb->wram[addr - ECHO_ADDR] = val;
return;
case 0xF:
if (addr < OAM_ADDR) {
gb->wram[addr - ECHO_ADDR] = val;
return;
}
if (addr < UNUSED_ADDR) {
gb->oam[addr - OAM_ADDR] = val;
return;
}
/* Unusable memory area. */
if (addr < IO_ADDR)
return;
if (HRAM_ADDR <= addr && addr < INTR_EN_ADDR) {
gb->hram[addr - HRAM_ADDR] = val;
return;
}
if ((addr >= 0xFF10) && (addr <= 0xFF3F)) {
#if ENABLE_SOUND
audio_write(addr, val);
#endif
return;
}
/* IO and Interrupts. */
switch (addr & 0xFF) {
/* Joypad */
case 0x00:
/* Only bits 5 and 4 are R/W.
* The lower bits are overwritten later, and the two most
* significant bits are unused. */
gb->gb_reg.P1 = val;
/* Direction keys selected */
if ((gb->gb_reg.P1 & 0b010000) == 0)
gb->gb_reg.P1 |= (gb->direct.joypad >> 4);
/* Button keys selected */
else
gb->gb_reg.P1 |= (gb->direct.joypad & 0x0F);
return;
/* Serial */
case 0x01:
gb->gb_reg.SB = val;
return;
case 0x02:
gb->gb_reg.SC = val;
return;
/* Timer Registers */
case 0x04:
gb->gb_reg.DIV = 0x00;
return;
case 0x05:
gb->gb_reg.TIMA = val;
return;
case 0x06:
gb->gb_reg.TMA = val;
return;
case 0x07:
gb->gb_reg.TAC = val;
return;
/* Interrupt Flag Register */
case 0x0F:
gb->gb_reg.IF = (val | 0b11100000);
return;
/* LCD Registers */
case 0x40:
gb->gb_reg.LCDC = val;
/* LY fixed to 0 when LCD turned off. */
if ((gb->gb_reg.LCDC & LCDC_ENABLE) == 0) {
/* Do not turn off LCD outside of VBLANK. This may happen due
* to poor timing in this emulator.
*/
if (gb->lcd_mode != LCD_VBLANK) {
gb->gb_reg.LCDC |= LCDC_ENABLE;
return;
}
gb->gb_reg.STAT = (gb->gb_reg.STAT & ~0x03) | LCD_VBLANK;
gb->gb_reg.LY = 0;
gb->counter.lcd_count = 0;
}
return;
case 0x41:
gb->gb_reg.STAT = (val & 0b01111000);
return;
case 0x42:
gb->gb_reg.SCY = val;
return;
case 0x43:
gb->gb_reg.SCX = val;
return;
/* LY (0xFF44) is read only */
case 0x45:
gb->gb_reg.LYC = val;
return;
/* DMA Register */
case 0x46:
gb->gb_reg.DMA = (val % 0xF1);
for (uint8_t i = 0; i < OAM_SIZE; i++)
gb->oam[i] = __gb_read(gb, (gb->gb_reg.DMA << 8) + i);
return;
/* DMG Palette Registers */
case 0x47:
gb->gb_reg.BGP = val;
gb->display.bg_palette[0] = (gb->gb_reg.BGP & 0x03);
gb->display.bg_palette[1] = (gb->gb_reg.BGP >> 2) & 0x03;
gb->display.bg_palette[2] = (gb->gb_reg.BGP >> 4) & 0x03;
gb->display.bg_palette[3] = (gb->gb_reg.BGP >> 6) & 0x03;
return;
case 0x48:
gb->gb_reg.OBP0 = val;
gb->display.sp_palette[0] = (gb->gb_reg.OBP0 & 0x03);
gb->display.sp_palette[1] = (gb->gb_reg.OBP0 >> 2) & 0x03;
gb->display.sp_palette[2] = (gb->gb_reg.OBP0 >> 4) & 0x03;
gb->display.sp_palette[3] = (gb->gb_reg.OBP0 >> 6) & 0x03;
return;
case 0x49:
gb->gb_reg.OBP1 = val;
gb->display.sp_palette[4] = (gb->gb_reg.OBP1 & 0x03);
gb->display.sp_palette[5] = (gb->gb_reg.OBP1 >> 2) & 0x03;
gb->display.sp_palette[6] = (gb->gb_reg.OBP1 >> 4) & 0x03;
gb->display.sp_palette[7] = (gb->gb_reg.OBP1 >> 6) & 0x03;
return;
/* Window Position Registers */
case 0x4A:
gb->gb_reg.WY = val;
return;
case 0x4B:
gb->gb_reg.WX = val;
return;
/* Turn off boot ROM */
case 0x50:
gb->gb_bios_enable = 0;
return;
/* Interrupt Enable Register */
case 0xFF:
gb->gb_reg.IE = val;
return;
}
}
(gb->gb_error)(gb, GB_INVALID_WRITE, addr);
}
#if ENABLE_LCD
void __gb_draw_line(struct gb_s *gb)
{
uint8_t pixels[160] = {0};
/* If LCD not initialized by front-end, don't render anything. */
if (gb->display.lcd_draw_line == NULL)
return;
if (gb->direct.frame_skip && !gb->display.frame_skip_count)
return;
/* If interlaced mode is activated, check if we need to draw the current
* line.
*/
if (gb->direct.interlace) {
if ((gb->display.interlace_count == 0 && (gb->gb_reg.LY & 1) == 0) ||
(gb->display.interlace_count == 1 && (gb->gb_reg.LY & 1) == 1)) {
/* Compensate for missing window draw if required. */
if (gb->gb_reg.LCDC & LCDC_WINDOW_ENABLE &&
gb->gb_reg.LY >= gb->display.WY && gb->gb_reg.WX <= 166)
gb->display.window_clear++;
return;
}
}
/* If background is enabled, draw it. */
if (gb->gb_reg.LCDC & LCDC_BG_ENABLE) {
/* Calculate current background line to draw. Constant because
* this function draws only this one line each time it is
* called. */
const uint8_t bg_y = gb->gb_reg.LY + gb->gb_reg.SCY;
/* Get selected background map address for first tile
* corresponding to current line.
* 0x20 (32) is the width of a background tile, and the bit
* shift is to calculate the address. */
const uint16_t bg_map =
((gb->gb_reg.LCDC & LCDC_BG_MAP) ? VRAM_BMAP_2 : VRAM_BMAP_1) +
(bg_y >> 3) * 0x20;
/* The displays (what the player sees) X coordinate, drawn right
* to left. */
uint8_t disp_x = LCD_WIDTH - 1;
/* The X coordinate to begin drawing the background at. */
uint8_t bg_x = disp_x + gb->gb_reg.SCX;
/* Get tile index for current background tile. */
uint8_t idx = gb->vram[bg_map + (bg_x >> 3)];
/* Y coordinate of tile pixel to draw. */
const uint8_t py = (bg_y & 0x07);
/* X coordinate of tile pixel to draw. */
uint8_t px = 7 - (bg_x & 0x07);
uint16_t tile;
/* Select addressing mode. */
if (gb->gb_reg.LCDC & LCDC_TILE_SELECT)
tile = VRAM_TILES_1 + idx * 0x10;
else
tile = VRAM_TILES_2 + ((idx + 0x80) % 0x100) * 0x10;
tile += 2 * py;
/* fetch first tile */
uint8_t t1 = gb->vram[tile] >> px;
uint8_t t2 = gb->vram[tile + 1] >> px;
for (; disp_x != 0xFF; disp_x--) {
if (px == 8) {
/* fetch next tile */
px = 0;
bg_x = disp_x + gb->gb_reg.SCX;
idx = gb->vram[bg_map + (bg_x >> 3)];
if (gb->gb_reg.LCDC & LCDC_TILE_SELECT)
tile = VRAM_TILES_1 + idx * 0x10;
else
tile = VRAM_TILES_2 + ((idx + 0x80) % 0x100) * 0x10;
tile += 2 * py;
t1 = gb->vram[tile];
t2 = gb->vram[tile + 1];
}
/* copy background */
uint8_t c = (t1 & 0x1) | ((t2 & 0x1) << 1);
pixels[disp_x] = gb->display.bg_palette[c];
pixels[disp_x] |= LCD_PALETTE_BG;
t1 = t1 >> 1;
t2 = t2 >> 1;
px++;
}
}
/* draw window */
if (gb->gb_reg.LCDC & LCDC_WINDOW_ENABLE &&
gb->gb_reg.LY >= gb->display.WY && gb->gb_reg.WX <= 166) {
/* calculate window map address */
uint16_t win_line =
(gb->gb_reg.LCDC & LCDC_WINDOW_MAP) ? VRAM_BMAP_2 : VRAM_BMAP_1;
win_line += (gb->display.window_clear >> 3) * 0x20;
uint8_t disp_x = LCD_WIDTH - 1;
uint8_t win_x = disp_x - gb->gb_reg.WX + 7;
/* look up tile */
uint8_t py = gb->display.window_clear & 0x07;
uint8_t px = 7 - (win_x & 0x07);
uint8_t idx = gb->vram[win_line + (win_x >> 3)];
uint16_t tile;
if (gb->gb_reg.LCDC & LCDC_TILE_SELECT)
tile = VRAM_TILES_1 + idx * 0x10;
else
tile = VRAM_TILES_2 + ((idx + 0x80) % 0x100) * 0x10;
tile += 2 * py;
/* fetch first tile */
uint8_t t1 = gb->vram[tile] >> px;
uint8_t t2 = gb->vram[tile + 1] >> px;
/* loop & copy window */
uint8_t end = (gb->gb_reg.WX < 7 ? 0 : gb->gb_reg.WX - 7) - 1;
for (; disp_x != end; disp_x--) {
if (px == 8) {
/* fetch next tile */
px = 0;
win_x = disp_x - gb->gb_reg.WX + 7;
idx = gb->vram[win_line + (win_x >> 3)];
if (gb->gb_reg.LCDC & LCDC_TILE_SELECT)
tile = VRAM_TILES_1 + idx * 0x10;
else
tile = VRAM_TILES_2 + ((idx + 0x80) % 0x100) * 0x10;
tile += 2 * py;
t1 = gb->vram[tile];
t2 = gb->vram[tile + 1];
}
/* copy window */
uint8_t c = (t1 & 0x1) | ((t2 & 0x1) << 1);
pixels[disp_x] = gb->display.bg_palette[c];
pixels[disp_x] |= LCD_PALETTE_BG;
t1 = t1 >> 1;
t2 = t2 >> 1;
px++;
}
gb->display.window_clear++; /* advance window line */
}
/* draw sprites */
if (gb->gb_reg.LCDC & LCDC_OBJ_ENABLE) {
uint8_t count = 0;
for (uint8_t s = NUM_SPRITES - 1;
s != 0xFF /* && count < MAX_SPRITES_LINE */; s--) {
/* Sprite Y position */
uint8_t OY = gb->oam[4 * s + 0];
/* Sprite X position */
uint8_t OX = gb->oam[4 * s + 1];
/* Sprite Tile/Pattern Number */
uint8_t OT = gb->oam[4 * s + 2] &
(gb->gb_reg.LCDC & LCDC_OBJ_SIZE ? 0xFE : 0xFF);
/* Additional attributes */
uint8_t OF = gb->oam[4 * s + 3];
/* If sprite isn't on this line, continue. */
if (gb->gb_reg.LY + (gb->gb_reg.LCDC & LCDC_OBJ_SIZE ? 0 : 8) >=
OY ||
gb->gb_reg.LY + 16 < OY)
continue;
count++;
/* Continue if sprite not visible. */
if (OX == 0 || OX >= 168)
continue;
/* y flip */
uint8_t py = gb->gb_reg.LY - OY + 16;
if (OF & OBJ_FLIP_Y)
py = (gb->gb_reg.LCDC & LCDC_OBJ_SIZE ? 15 : 7) - py;
/* fetch the tile */
uint8_t t1 = gb->vram[VRAM_TILES_1 + OT * 0x10 + 2 * py];
uint8_t t2 = gb->vram[VRAM_TILES_1 + OT * 0x10 + 2 * py + 1];
/* handle x flip */
uint8_t dir, start, end, shift;
if (OF & OBJ_FLIP_X) {
dir = 1;
start = (OX < 8 ? 0 : OX - 8);
end = MIN(OX, LCD_WIDTH);
shift = 8 - OX + start;
} else {
dir = -1;
start = MIN(OX, LCD_WIDTH) - 1;
end = (OX < 8 ? 0 : OX - 8) - 1;
shift = OX - (start + 1);
}
/* copy tile */
t1 >>= shift, t2 >>= shift;
for (uint8_t disp_x = start; disp_x != end; disp_x += dir) {
uint8_t c = (t1 & 0x1) | ((t2 & 0x1) << 1);
/* TODO: check transparency / sprite overlap / background
* overlap.
*/
if (c && !(OF & OBJ_PRIORITY && pixels[disp_x] & 0x3)) {
/* Set pixel color. */
pixels[disp_x] = (OF & OBJ_PALETTE)
? gb->display.sp_palette[c + 4]
: gb->display.sp_palette[c];
/* Set pixel palette (OBJ0 or OBJ1) */
pixels[disp_x] |= (OF & OBJ_PALETTE);
/* Deselect BG palette */
pixels[disp_x] &= ~LCD_PALETTE_BG;
}
t1 = t1 >> 1, t2 = t2 >> 1;
}
}
}
gb->display.lcd_draw_line(gb, pixels, gb->gb_reg.LY);
}
#endif
/* Gets the size of the save file required for the ROM. */
uint_fast32_t gb_get_save_size(struct gb_s *gb)
{
const uint_fast16_t ram_size_location = 0x0149;
const uint_fast32_t ram_sizes[] = {0x00, 0x800, 0x2000, 0x8000, 0x20000};
uint8_t ram_size = gb->gb_rom_read(gb, ram_size_location);
return ram_sizes[ram_size];
}
/* Set the function used to handle serial transfer in the front-end. This is
* optional.
* gb_serial_transfer takes a byte to transmit and returns the received byte. If
* no cable is connected to the console, return 0xFF.
*/
void gb_init_serial(struct gb_s *gb,
void (*gb_serial_tx)(struct gb_s *, const uint8_t),
gb_serial_rx_ret_t (*gb_serial_rx)(struct gb_s *,
uint8_t *))
{
gb->gb_serial_tx = gb_serial_tx;
gb->gb_serial_rx = gb_serial_rx;
}
uint8_t gb_color_hash(struct gb_s *gb)
{
#define ROM_TITLE_START_ADDR 0x0134
#define ROM_TITLE_END_ADDR 0x0143
uint8_t x = 0;
for (uint16_t i = ROM_TITLE_START_ADDR; i <= ROM_TITLE_END_ADDR; i++)
x += gb->gb_rom_read(gb, i);
return x;
}
/* Resets the context, and initializes startup values. */
void gb_reset(struct gb_s *gb)
{
gb->gb_halt = 0;
gb->gb_ime = 1;
gb->gb_bios_enable = 0;
gb->lcd_mode = LCD_HBLANK;
/* Initialize MBC values. */
gb->selected_rom_bank = 1;
gb->cart_ram_bank = 0;
gb->enable_cart_ram = 0;
gb->cart_mode_select = 0;
/* Initialize CPU registers as though a DMG. */
gb->cpu_reg.af = 0x01B0;
gb->cpu_reg.bc = 0x0013;
gb->cpu_reg.de = 0x00D8;
gb->cpu_reg.hl = 0x014D;
gb->cpu_reg.sp = 0xFFFE;
/* TODO: Add BIOS support. */
gb->cpu_reg.pc = 0x0100;
gb->counter.lcd_count = 0;
gb->counter.div_count = 0;
gb->counter.tima_count = 0;
gb->counter.serial_count = 0;
gb->gb_reg.TIMA = 0x00;
gb->gb_reg.TMA = 0x00;
gb->gb_reg.TAC = 0xF8;
gb->gb_reg.DIV = 0xAC;
gb->gb_reg.IF = 0xE1;
gb->gb_reg.LCDC = 0x91;
gb->gb_reg.SCY = 0x00;
gb->gb_reg.SCX = 0x00;
gb->gb_reg.LYC = 0x00;
/* Appease valgrind for invalid reads and unconditional jumps. */
gb->gb_reg.SC = 0x7E;
gb->gb_reg.STAT = 0;
gb->gb_reg.LY = 0;
__gb_write(gb, 0xFF47, 0xFC); /* BGP */
__gb_write(gb, 0xFF48, 0xFF); /* OBJP0 */
__gb_write(gb, 0xFF49, 0x0F); /* OBJP1 */
gb->gb_reg.WY = 0x00;
gb->gb_reg.WX = 0x00;
gb->gb_reg.IE = 0x00;
gb->direct.joypad = 0xFF;
gb->gb_reg.P1 = 0xCF;
}
/* Initialize the emulator context. gb_reset() is also called to initialize
* the CPU.
*/
gb_init_error_t gb_init(
struct gb_s *gb,
uint8_t (*gb_rom_read)(struct gb_s *, const uint_fast32_t),
uint8_t (*gb_cart_ram_read)(struct gb_s *, const uint_fast32_t),
void (*gb_cart_ram_write)(struct gb_s *,
const uint_fast32_t,
const uint8_t),
void (*gb_error)(struct gb_s *, const gb_error_t, const uint16_t),
void *priv)
{
const uint16_t mbc_location = 0x0147;
const uint16_t bank_count_location = 0x0148;
const uint16_t ram_size_location = 0x0149;
/* Table for cartridge type (MBC). -1 if invalid.
* TODO: MMM01 is untested.
* TODO: MBC6 is untested.
* TODO: MBC7 is unsupported.
* TODO: POCKET CAMERA is unsupported.
* TODO: BANDAI TAMA5 is unsupported.
* TODO: HuC3 is unsupported.
* TODO: HuC1 is unsupported.
**/
const uint8_t cart_mbc[] = {0, 1, 1, 1, -1, 2, 2, -1, 0, 0, -1,
0, 0, 0, -1, 3, 3, 3, 3, 3, -1, -1,
-1, -1, -1, 5, 5, 5, 5, 5, 5, -1};
const uint8_t cart_ram[] = {0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0};
const uint16_t num_rom_banks[] = {
2, 4, 8, 16, 32, 64, 128, 256, 512, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 72, 80, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
const uint8_t num_ram_banks[] = {0, 1, 1, 4, 16, 8};
gb->gb_rom_read = gb_rom_read;
gb->gb_cart_ram_read = gb_cart_ram_read;
gb->gb_cart_ram_write = gb_cart_ram_write;
gb->gb_error = gb_error;
gb->direct.priv = priv;
/* Initialize serial transfer function to NULL. If the front-end does
* not provide serial support, it will emulate no cable connected
* automatically.
*/
gb->gb_serial_tx = NULL;
gb->gb_serial_rx = NULL;
/* Check valid ROM using checksum value. */
{
uint8_t x = 0;
for (uint16_t i = 0x0134; i <= 0x014C; i++)
x = x - gb->gb_rom_read(gb, i) - 1;
if (x != gb->gb_rom_read(gb, ROM_HEADER_CHECKSUM_LOC))
return GB_INIT_INVALID_CHECKSUM;
}
/* Check if cartridge type is supported, and set MBC type. */
{
const uint8_t mbc_value = gb->gb_rom_read(gb, mbc_location);
if (mbc_value > sizeof(cart_mbc) - 1 ||
(gb->mbc = cart_mbc[gb->gb_rom_read(gb, mbc_location)]) == 255u)
return GB_INIT_CARTRIDGE_UNSUPPORTED;
}
gb->cart_ram = cart_ram[gb->gb_rom_read(gb, mbc_location)];
gb->num_rom_banks = num_rom_banks[gb->gb_rom_read(gb, bank_count_location)];
gb->num_ram_banks = num_ram_banks[gb->gb_rom_read(gb, ram_size_location)];
gb->display.lcd_draw_line = NULL;
gb_reset(gb);
return GB_INIT_NO_ERROR;
}
/* Return the title of ROM.
*
* \param gb Initialized context.
* \param title_str Allocated string at least 16 characters.
* \returns Pointer to start of string, null terminated.
*/
const char *gb_get_rom_name(struct gb_s *gb, char *title_str)
{
uint_fast16_t title_loc = 0x134;
/* End of title may be 0x13E for newer games. */
const uint_fast16_t title_end = 0x143;
const char *title_start = title_str;
for (; title_loc <= title_end; title_loc++) {
const char title_char = gb->gb_rom_read(gb, title_loc);
if (title_char >= ' ' && title_char <= '_') {
*title_str = title_char;
title_str++;
} else
break;
}
*title_str = '\0';
return title_start;
}
#if ENABLE_LCD
void gb_init_lcd(struct gb_s *gb,
void (*lcd_draw_line)(struct gb_s *gb,
const uint8_t *pixels,
const uint_fast8_t line))
{
gb->display.lcd_draw_line = lcd_draw_line;
gb->direct.interlace = 0;
gb->display.interlace_count = 0;
gb->direct.frame_skip = 0;
gb->display.frame_skip_count = 0;
gb->display.window_clear = 0;
gb->display.WY = 0;
}
#endif
| 30.075078 | 80 | 0.507212 |
3e45002662c40931d63872ddfa3f74b61d5a3c80 | 466 | h | C | CollinsJustin_MidtermProject/CollinsJustin_MidtermProject/Planets.h | justcollins/SolarSystem | 66ebb11961afe4723ac7431b268a8ecad1ec4d0d | [
"MIT"
] | null | null | null | CollinsJustin_MidtermProject/CollinsJustin_MidtermProject/Planets.h | justcollins/SolarSystem | 66ebb11961afe4723ac7431b268a8ecad1ec4d0d | [
"MIT"
] | null | null | null | CollinsJustin_MidtermProject/CollinsJustin_MidtermProject/Planets.h | justcollins/SolarSystem | 66ebb11961afe4723ac7431b268a8ecad1ec4d0d | [
"MIT"
] | null | null | null | #ifndef PLANETS_H_
#define PLANETS_H_
//#include <GL/glut.h>
//#include "SOIL.h"
void makeSun(float day);
void makeMercury(float year, float day);
void makeVenus(float year, float day);
void makeEarth(float year, float day);
void makeMars(float year, float day);
void makeJupiter(float year, float day);
void makeSaturn(float year, float day);
void makeUranus(float year, float day);
void makeNeptune(float year, float day);
void makeBackground(float day);
#endif | 25.888889 | 40 | 0.761803 |
6bfcb7ab3e3e317e52d7be547b0903688663fa93 | 2,675 | c | C | d/attaya/tunnels/obj/gem.c | Dbevan/SunderingShadows | 6c15ec56cef43c36361899bae6dc08d0ee907304 | [
"MIT"
] | 13 | 2019-07-19T05:24:44.000Z | 2021-11-18T04:08:19.000Z | d/attaya/tunnels/obj/gem.c | Dbevan/SunderingShadows | 6c15ec56cef43c36361899bae6dc08d0ee907304 | [
"MIT"
] | 4 | 2021-03-15T18:56:39.000Z | 2021-08-17T17:08:22.000Z | d/attaya/tunnels/obj/gem.c | Dbevan/SunderingShadows | 6c15ec56cef43c36361899bae6dc08d0ee907304 | [
"MIT"
] | 13 | 2019-09-12T06:22:38.000Z | 2022-01-31T01:15:12.000Z | #include <std.h>
#include "../tunnel.h"
#define GEMS ({"%^BOLD%^%^WHITE%^diamond%^RESET%^",\
"%^BOLD%^%^GREEN%^emerald%^RESET%^",\
"%^BOLD%^%^RED%^ruby%^RESET%^",\
"%^BOLD%^%^BLUE%^sapphire%^RESET%^",\
"%^RED%^garnet%^RESET%^",\
"%^MAGENTA%^amethyst%^RESET%^",\
"%^ORANGE%^topaz%^RESET%^",\
"%^BOLD%^%^RED%^fire opal%^RESET%^",\
"%^BOLD%^%^WHITE%^moonstone%^RESET%^",\
"%^BOLD%^%^BLACK%^black opal%^RESET%^",\
"%^BOLD%^%^WHITE%^o%^CYAN%^p%^WHITE%^a%^MAGENTA%^l%^RESET%^",\
"%^ORANGE%^piece of amber%^RESET%^",\
"%^BOLD%^%^GREEN%^piece of jade%^RESET%^",\
"%^BOLD%^%^CYAN%^water opal%^RESET%^"})
inherit OBJECT;
void create()
{
int i,j, val;
string str;
::create();
j=random(9);
str= GEMS[j];
val = random(4000);
if (val>3000){val += random(4000);}
switch(val) {
case 0..200:
set_long("This is a small "+str+". The light catches"
+" in the gem and it looks like it would sell for a"
+" nice price.");
set_short("Small "+str+"");
break;
case 201..400:
set_long("This is a "+str+" of a nice size. From the"
+" way the light catches within the gem, it could"
+" probably be sold for a fair sum.");
set_short("Medium "+str+"");
break;
case 401..600:
set_long("This is a fairly nice sized "+str+". The"
+" light twinkles within the gem very prettily and"
+" it is obviously worth a fair bit of gold.");
set_short("Large "+str+"");
break;
case 601..2500:
set_long("This is a fine "+str+". It is a very nice size and"
+" the facets are bright and finely cut. The"
+" light twinkles within the gem very prettily"
+" and it is obviously worth a good bit of"
+" gold.");
set_short("Fine "+str+"");
break;
case 2501..5000:
set_long("This is an exquisite "+str+". It is large and fine."
+" The cut and shape of the gem are beautiful. The"
+" light twinkles within it very attractively"
+" and it is obviously worth a lot of"
+" gold.");
set_short("Exquisite "+str+"");
break;
default:
set_long("This is a fabulous "+str+". It is not huge in size, but"
+" the clarity and perfection of form is simply breathtaking"
+". The light shines so brightly within the gem you could"
+" almost imagine it was lit from within. This gem must be"
+" worth a fortune!");
set_short("Fabulous "+str+"");
}
if(val < 50) {
set_value(50);
}
else {
set_value(val);
}
set_id(({"gem",str}));
set_name("gem");
set_weight(5);
}
int is_gem(){return 1;} | 31.845238 | 74 | 0.56 |
d4071fb9cda3ab7b80633d5cdc9803691b451450 | 944 | h | C | log.h | avalluri/connman-uci | c351f91ec608d614877041bb55fc39a258b06268 | [
"Apache-2.0"
] | 2 | 2017-09-02T14:55:34.000Z | 2020-07-27T17:59:52.000Z | log.h | avalluri/connman-uci | c351f91ec608d614877041bb55fc39a258b06268 | [
"Apache-2.0"
] | null | null | null | log.h | avalluri/connman-uci | c351f91ec608d614877041bb55fc39a258b06268 | [
"Apache-2.0"
] | null | null | null | #ifndef __CONNMAN_UCI_LOG_H_
#define __CONNMAN_UCI_LOG_H_
#include <stdio.h>
enum LogLevel {
LOG_ERR,
LOG_WARN,
LOG_INFO,
LOG_DEBUG,
};
extern enum LogLevel verbose;
extern const char *prefix;
static inline const char *s_loglevel(enum LogLevel level) {
switch(level) {
case LOG_ERR: return "ERROR";
case LOG_WARN: return "WARN";
case LOG_INFO: return "INFO";
case LOG_DEBUG: return "DEBUG";
}
return "";
}
#define LOG(level, fmt, ...) \
if (verbose >= level) { \
fprintf(stderr, "%s: %s:"fmt"\n", prefix, s_loglevel(level), ##__VA_ARGS__); \
}
#define ERR(fmt, ...) LOG(LOG_ERR, fmt, ##__VA_ARGS__)
#define WARN(fmt, ...) LOG(LOG_WARN, fmt, ##__VA_ARGS__)
#define INFO(fmt, ...) LOG(LOG_INFO, fmt, ##__VA_ARGS__)
#define DBG(fmt, ...) LOG(LOG_DEBUG, fmt, ##__VA_ARGS__)
void log_init(const char *prefix, enum LogLevel level);
#endif // __CONNMAN_UCI_LOG_H_
| 24.205128 | 86 | 0.647246 |
38f1905a608a3a42f9cb5b26862c1d41282faba1 | 478 | h | C | jni/libutils/utils.h | hhool/ffplayer | 8016a4afbaf7da6875ec5e2dc22dcb5f35157bd0 | [
"Apache-2.0"
] | 23 | 2015-11-13T08:30:55.000Z | 2022-02-24T05:45:43.000Z | jni/libutils/utils.h | hhool/ffplayer | 8016a4afbaf7da6875ec5e2dc22dcb5f35157bd0 | [
"Apache-2.0"
] | 2 | 2016-09-12T03:17:46.000Z | 2017-03-20T06:33:36.000Z | jni/libutils/utils.h | hhool/ffplayer | 8016a4afbaf7da6875ec5e2dc22dcb5f35157bd0 | [
"Apache-2.0"
] | 18 | 2015-11-14T00:54:38.000Z | 2021-08-23T11:44:52.000Z | /**
* @file utils.h"
* @author windsome <windsome@windsome-desktop>
* @date Tue Jan 5 19:19:06 2010
*
* @brief
*
*
*/
#ifndef __UTILS_H
#define __UTILS_H
#include "util_types.h"
#include "util_crc32.h"
#include "util_eventloop.h"
#include "util_file.h"
#include "util_lock.h"
#include "util_log.h"
#include "util_md5sum.h"
#include "util_network.h"
#include "util_thread.h"
#include "util_time.h"
#include "util_uri.h"
#endif /// __UTILS_H
| 17.703704 | 47 | 0.661088 |
5c3e0e5419ca019fcd90411b7bb80e0ff1278266 | 1,347 | h | C | src/hash_helper.h | totalgames/playchain-client | 7821a3470fca6ae368a68bef2ba424006bc81989 | [
"MIT"
] | 1 | 2019-07-05T14:37:17.000Z | 2019-07-05T14:37:17.000Z | src/hash_helper.h | totalgames/playchain-client | 7821a3470fca6ae368a68bef2ba424006bc81989 | [
"MIT"
] | null | null | null | src/hash_helper.h | totalgames/playchain-client | 7821a3470fca6ae368a68bef2ba424006bc81989 | [
"MIT"
] | null | null | null | #pragma once
#include <cstdint>
#include <cstring>
namespace playchain {
inline void shift_l(const uint8_t* in, uint8_t* out, std::size_t n, unsigned int i)
{
if (i < n)
{
std::memcpy(out, in + i, n - i);
}
else
{
i = n;
}
std::memset(out + (n - i), 0, i);
}
inline void shift_l(const char* in, char* out, std::size_t n, unsigned int i)
{
const uint8_t* in8 = (uint8_t*)in;
uint8_t* out8 = (uint8_t*)out;
if (i >= 8)
{
shift_l(in8, out8, n, i / 8);
i &= 7;
in8 = out8;
}
std::size_t p;
for (p = 0; p < n - 1; ++p)
out8[p] = (in8[p] << i) | (in8[p + 1] >> (8 - i));
out8[p] = in8[p] << i;
}
inline void shift_r(const uint8_t* in, uint8_t* out, std::size_t n, unsigned int i)
{
if (i < n)
{
std::memcpy(out + i, in, n - i);
}
else
{
i = n;
}
std::memset(out, 0, i);
}
inline void shift_r(const char* in, char* out, std::size_t n, unsigned int i)
{
const uint8_t* in8 = (uint8_t*)in;
uint8_t* out8 = (uint8_t*)out;
if (i >= 8)
{
shift_r(in8, out8, n, i / 8);
i &= 7;
in8 = out8;
}
std::size_t p;
for (p = n - 1; p > 0; --p)
out8[p] = (in8[p] >> i) | (in8[p - 1] << (8 - i));
out8[p] = in8[p] >> i;
}
} // namespace playchain
| 19.521739 | 83 | 0.47513 |
8da774569ed2292fdd8d3c6fc2afe370b00f28fe | 1,010 | h | C | Fader.h | jaekar99/wemosTesterWS2812 | 39c07547519c2f26a804b6da1df9979c0700d3c1 | [
"Apache-2.0"
] | null | null | null | Fader.h | jaekar99/wemosTesterWS2812 | 39c07547519c2f26a804b6da1df9979c0700d3c1 | [
"Apache-2.0"
] | null | null | null | Fader.h | jaekar99/wemosTesterWS2812 | 39c07547519c2f26a804b6da1df9979c0700d3c1 | [
"Apache-2.0"
] | null | null | null | /*
Released under Creative Commons Attribution 4.0
by bitluni 2016
https://creativecommons.org/licenses/by/4.0/
Attribution means you can use it however you like as long you
mention that it's base on my stuff.
I'll be pleased if you'd do it by sharing http://youtube.com/bitlunislab
*/
template<class T>
class Fader
{
public:
bool active = false;
long startTime = 0;
long duration = 0;
T &from;
T &to;
Fader(T &fromState, T &toState)
:from(fromState)
,to(toState)
{
}
bool start(int duration)
{
if(active)
return false;
active = true;
startTime = millis();
this->duration = duration;
}
bool fade()
{
if(!active)
return false;
long t = millis() - startTime;
if(t >= duration || t < 0 || duration == 0)
{
from.setValues(to);
active = false;
return false;
}
float f1 = (float)t / duration;
float f0 = 1 - f1;
from.fade(to, long(f0 * 0x10000), long(f1 * 0x10000));
return true;
}
};
| 19.056604 | 72 | 0.607921 |
ed0746955eb5c3c3e0a44205303d1b7e0fb51917 | 78,628 | c | C | dlls/user/message.c | roytam1/wine-win31look | 2c8284c53a46c1309fbf62a3998538c44fcbf207 | [
"MIT"
] | 1 | 2019-10-23T04:07:16.000Z | 2019-10-23T04:07:16.000Z | dlls/user/message.c | roytam1/wine-win31look | 2c8284c53a46c1309fbf62a3998538c44fcbf207 | [
"MIT"
] | null | null | null | dlls/user/message.c | roytam1/wine-win31look | 2c8284c53a46c1309fbf62a3998538c44fcbf207 | [
"MIT"
] | null | null | null | /*
* Window messaging support
*
* Copyright 2001 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include "wine/port.h"
#include <assert.h>
#include <stdarg.h>
#include "ntstatus.h"
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "winerror.h"
#include "winnls.h"
#include "dde.h"
#include "wine/unicode.h"
#include "wine/server.h"
#include "message.h"
#include "user.h"
#include "win.h"
#include "winproc.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(msg);
WINE_DECLARE_DEBUG_CHANNEL(relay);
#define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
#define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
#define MAX_PACK_COUNT 4
/* description of the data fields that need to be packed along with a sent message */
struct packed_message
{
int count;
const void *data[MAX_PACK_COUNT];
size_t size[MAX_PACK_COUNT];
};
/* info about the message currently being received by the current thread */
struct received_message_info
{
enum message_type type;
MSG msg;
UINT flags; /* InSendMessageEx return flags */
};
/* structure to group all parameters for sent messages of the various kinds */
struct send_message_info
{
enum message_type type;
HWND hwnd;
UINT msg;
WPARAM wparam;
LPARAM lparam;
UINT flags; /* flags for SendMessageTimeout */
UINT timeout; /* timeout for SendMessageTimeout */
SENDASYNCPROC callback; /* callback function for SendMessageCallback */
ULONG_PTR data; /* callback data */
};
/* flag for messages that contain pointers */
/* 32 messages per entry, messages 0..31 map to bits 0..31 */
#define SET(msg) (1 << ((msg) & 31))
static const unsigned int message_pointer_flags[] =
{
/* 0x00 - 0x1f */
SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
/* 0x20 - 0x3f */
SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
SET(WM_COMPAREITEM),
/* 0x40 - 0x5f */
SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
SET(WM_NOTIFY) | SET(WM_HELP),
/* 0x60 - 0x7f */
SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
/* 0x80 - 0x9f */
SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
/* 0xa0 - 0xbf */
SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
/* 0xc0 - 0xdf */
SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
/* 0xe0 - 0xff */
SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO),
/* 0x100 - 0x11f */
0,
/* 0x120 - 0x13f */
0,
/* 0x140 - 0x15f */
SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
/* 0x160 - 0x17f */
0,
/* 0x180 - 0x19f */
SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
SET(LB_DIR) | SET(LB_FINDSTRING) |
SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
/* 0x1a0 - 0x1bf */
SET(LB_FINDSTRINGEXACT),
/* 0x1c0 - 0x1df */
0,
/* 0x1e0 - 0x1ff */
0,
/* 0x200 - 0x21f */
SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
/* 0x220 - 0x23f */
SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
/* 0x240 - 0x25f */
0,
/* 0x260 - 0x27f */
0,
/* 0x280 - 0x29f */
0,
/* 0x2a0 - 0x2bf */
0,
/* 0x2c0 - 0x2df */
0,
/* 0x2e0 - 0x2ff */
0,
/* 0x300 - 0x31f */
SET(WM_ASKCBFORMATNAME)
};
/* flags for messages that contain Unicode strings */
static const unsigned int message_unicode_flags[] =
{
/* 0x00 - 0x1f */
SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
/* 0x20 - 0x3f */
SET(WM_CHARTOITEM),
/* 0x40 - 0x5f */
0,
/* 0x60 - 0x7f */
0,
/* 0x80 - 0x9f */
SET(WM_NCCREATE),
/* 0xa0 - 0xbf */
0,
/* 0xc0 - 0xdf */
SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
/* 0xe0 - 0xff */
0,
/* 0x100 - 0x11f */
SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
/* 0x120 - 0x13f */
SET(WM_MENUCHAR),
/* 0x140 - 0x15f */
SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
/* 0x160 - 0x17f */
0,
/* 0x180 - 0x19f */
SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
/* 0x1a0 - 0x1bf */
SET(LB_FINDSTRINGEXACT),
/* 0x1c0 - 0x1df */
0,
/* 0x1e0 - 0x1ff */
0,
/* 0x200 - 0x21f */
0,
/* 0x220 - 0x23f */
SET(WM_MDICREATE),
/* 0x240 - 0x25f */
0,
/* 0x260 - 0x27f */
0,
/* 0x280 - 0x29f */
SET(WM_IME_CHAR),
/* 0x2a0 - 0x2bf */
0,
/* 0x2c0 - 0x2df */
0,
/* 0x2e0 - 0x2ff */
0,
/* 0x300 - 0x31f */
SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
};
/* check whether a given message type includes pointers */
inline static int is_pointer_message( UINT message )
{
if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
return (message_pointer_flags[message / 32] & SET(message)) != 0;
}
/* check whether a given message type contains Unicode (or ASCII) chars */
inline static int is_unicode_message( UINT message )
{
if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
return (message_unicode_flags[message / 32] & SET(message)) != 0;
}
#undef SET
/* add a data field to a packed message */
inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
{
data->data[data->count] = ptr;
data->size[data->count] = size;
data->count++;
}
/* add a string to a packed message */
inline static void push_string( struct packed_message *data, LPCWSTR str )
{
push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
}
/* retrieve a pointer to data from a packed message and increment the buffer pointer */
inline static void *get_data( void **buffer, size_t size )
{
void *ret = *buffer;
*buffer = (char *)*buffer + size;
return ret;
}
/* make sure that the buffer contains a valid null-terminated Unicode string */
inline static BOOL check_string( LPCWSTR str, size_t size )
{
for (size /= sizeof(WCHAR); size; size--, str++)
if (!*str) return TRUE;
return FALSE;
}
/* make sure that there is space for 'size' bytes in buffer, growing it if needed */
inline static void *get_buffer_space( void **buffer, size_t size )
{
void *ret;
if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
HeapFree( GetProcessHeap(), 0, *buffer );
*buffer = ret;
return ret;
}
/* retrieve a string pointer from packed data */
inline static LPWSTR get_string( void **buffer )
{
return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
}
/* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
inline static BOOL combobox_has_strings( HWND hwnd )
{
DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
}
/* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
inline static BOOL listbox_has_strings( HWND hwnd )
{
DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
}
/***********************************************************************
* broadcast_message_callback
*
* Helper callback for broadcasting messages.
*/
static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
{
struct send_message_info *info = (struct send_message_info *)lparam;
if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
switch(info->type)
{
case MSG_UNICODE:
SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
info->flags, info->timeout, NULL );
break;
case MSG_ASCII:
SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
info->flags, info->timeout, NULL );
break;
case MSG_NOTIFY:
SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
break;
case MSG_CALLBACK:
SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
info->callback, info->data );
break;
case MSG_POSTED:
PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
break;
default:
ERR( "bad type %d\n", info->type );
break;
}
return TRUE;
}
/***********************************************************************
* map_wparam_AtoW
*
* Convert the wparam of an ASCII message to Unicode.
*/
static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
{
switch(message)
{
case WM_CHARTOITEM:
case EM_SETPASSWORDCHAR:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
case WM_MENUCHAR:
{
char ch = LOWORD(wparam);
WCHAR wch;
MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
wparam = MAKEWPARAM( wch, HIWORD(wparam) );
}
break;
case WM_IME_CHAR:
{
char ch[2];
WCHAR wch;
ch[0] = (wparam >> 8);
ch[1] = (wparam & 0xff);
if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
wparam = MAKEWPARAM( wch, HIWORD(wparam) );
}
break;
}
return wparam;
}
/***********************************************************************
* map_wparam_WtoA
*
* Convert the wparam of a Unicode message to ASCII.
*/
static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
{
switch(message)
{
case WM_CHARTOITEM:
case EM_SETPASSWORDCHAR:
case WM_CHAR:
case WM_DEADCHAR:
case WM_SYSCHAR:
case WM_SYSDEADCHAR:
case WM_MENUCHAR:
{
WCHAR wch = LOWORD(wparam);
BYTE ch;
WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
wparam = MAKEWPARAM( ch, HIWORD(wparam) );
}
break;
case WM_IME_CHAR:
{
WCHAR wch = LOWORD(wparam);
BYTE ch[2];
if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
else
wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
}
break;
}
return wparam;
}
/***********************************************************************
* pack_message
*
* Pack a message for sending to another process.
* Return the size of the data we expect in the message reply.
* Set data->count to -1 if there is an error.
*/
static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
struct packed_message *data )
{
data->count = 0;
switch(message)
{
case WM_NCCREATE:
case WM_CREATE:
{
CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
push_data( data, cs, sizeof(*cs) );
if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
return sizeof(*cs);
}
case WM_GETTEXT:
case WM_ASKCBFORMATNAME:
return wparam * sizeof(WCHAR);
case WM_WININICHANGE:
if (lparam) push_string(data, (LPWSTR)lparam );
return 0;
case WM_SETTEXT:
case WM_DEVMODECHANGE:
case CB_DIR:
case LB_DIR:
case LB_ADDFILE:
case EM_REPLACESEL:
push_string( data, (LPWSTR)lparam );
return 0;
case WM_GETMINMAXINFO:
push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
return sizeof(MINMAXINFO);
case WM_DRAWITEM:
push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
return 0;
case WM_MEASUREITEM:
push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
return sizeof(MEASUREITEMSTRUCT);
case WM_DELETEITEM:
push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
return 0;
case WM_COMPAREITEM:
push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
return 0;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
return sizeof(WINDOWPOS);
case WM_COPYDATA:
{
COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
push_data( data, cp, sizeof(*cp) );
if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
return 0;
}
case WM_NOTIFY:
/* WM_NOTIFY cannot be sent across processes (MSDN) */
data->count = -1;
return 0;
case WM_HELP:
push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
return 0;
case WM_STYLECHANGING:
case WM_STYLECHANGED:
push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
return 0;
case WM_NCCALCSIZE:
if (!wparam)
{
push_data( data, (RECT *)lparam, sizeof(RECT) );
return sizeof(RECT);
}
else
{
NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
push_data( data, nc, sizeof(*nc) );
push_data( data, nc->lppos, sizeof(*nc->lppos) );
return sizeof(*nc) + sizeof(*nc->lppos);
}
case WM_GETDLGCODE:
if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
return sizeof(MSG);
case SBM_SETSCROLLINFO:
push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
return 0;
case SBM_GETSCROLLINFO:
push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
return sizeof(SCROLLINFO);
case EM_GETSEL:
case SBM_GETRANGE:
case CB_GETEDITSEL:
{
size_t size = 0;
if (wparam) size += sizeof(DWORD);
if (lparam) size += sizeof(DWORD);
return size;
}
case EM_GETRECT:
case LB_GETITEMRECT:
case CB_GETDROPPEDCONTROLRECT:
return sizeof(RECT);
case EM_SETRECT:
case EM_SETRECTNP:
push_data( data, (RECT *)lparam, sizeof(RECT) );
return 0;
case EM_GETLINE:
{
WORD *pw = (WORD *)lparam;
push_data( data, pw, sizeof(*pw) );
return *pw * sizeof(WCHAR);
}
case EM_SETTABSTOPS:
case LB_SETTABSTOPS:
if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
return 0;
case CB_ADDSTRING:
case CB_INSERTSTRING:
case CB_FINDSTRING:
case CB_FINDSTRINGEXACT:
case CB_SELECTSTRING:
if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
return 0;
case CB_GETLBTEXT:
if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
case LB_ADDSTRING:
case LB_INSERTSTRING:
case LB_FINDSTRING:
case LB_FINDSTRINGEXACT:
case LB_SELECTSTRING:
if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
return 0;
case LB_GETTEXT:
if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
case LB_GETSELITEMS:
return wparam * sizeof(UINT);
case WM_NEXTMENU:
push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
return sizeof(MDINEXTMENU);
case WM_SIZING:
case WM_MOVING:
push_data( data, (RECT *)lparam, sizeof(RECT) );
return sizeof(RECT);
case WM_MDICREATE:
{
MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
push_data( data, cs, sizeof(*cs) );
if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
return sizeof(*cs);
}
case WM_MDIGETACTIVE:
if (lparam) return sizeof(BOOL);
return 0;
case WM_WINE_SETWINDOWPOS:
push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
return 0;
case WM_WINE_KEYBOARD_LL_HOOK:
push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
return 0;
case WM_WINE_MOUSE_LL_HOOK:
push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
return 0;
/* these contain an HFONT */
case WM_SETFONT:
case WM_GETFONT:
/* these contain an HDC */
case WM_PAINT:
case WM_ERASEBKGND:
case WM_ICONERASEBKGND:
case WM_NCPAINT:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
case WM_PRINT:
case WM_PRINTCLIENT:
/* these contain an HGLOBAL */
case WM_PAINTCLIPBOARD:
case WM_SIZECLIPBOARD:
/* these contain HICON */
case WM_GETICON:
case WM_SETICON:
case WM_QUERYDRAGICON:
case WM_QUERYPARKICON:
/* these contain pointers */
case WM_DROPOBJECT:
case WM_QUERYDROPOBJECT:
case WM_DRAGLOOP:
case WM_DRAGSELECT:
case WM_DRAGMOVE:
case WM_DEVICECHANGE:
FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
data->count = -1;
return 0;
}
return 0;
}
/***********************************************************************
* unpack_message
*
* Unpack a message received from another process.
*/
static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
void **buffer, size_t size )
{
size_t minsize = 0;
switch(message)
{
case WM_NCCREATE:
case WM_CREATE:
{
CREATESTRUCTW *cs = *buffer;
WCHAR *str = (WCHAR *)(cs + 1);
if (size < sizeof(*cs)) return FALSE;
size -= sizeof(*cs);
if (HIWORD(cs->lpszName))
{
if (!check_string( str, size )) return FALSE;
cs->lpszName = str;
size -= (strlenW(str) + 1) * sizeof(WCHAR);
str += strlenW(str) + 1;
}
if (HIWORD(cs->lpszClass))
{
if (!check_string( str, size )) return FALSE;
cs->lpszClass = str;
}
break;
}
case WM_GETTEXT:
case WM_ASKCBFORMATNAME:
if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
break;
case WM_WININICHANGE:
if (!*lparam) return TRUE;
/* fall through */
case WM_SETTEXT:
case WM_DEVMODECHANGE:
case CB_DIR:
case LB_DIR:
case LB_ADDFILE:
case EM_REPLACESEL:
if (!check_string( *buffer, size )) return FALSE;
break;
case WM_GETMINMAXINFO:
minsize = sizeof(MINMAXINFO);
break;
case WM_DRAWITEM:
minsize = sizeof(DRAWITEMSTRUCT);
break;
case WM_MEASUREITEM:
minsize = sizeof(MEASUREITEMSTRUCT);
break;
case WM_DELETEITEM:
minsize = sizeof(DELETEITEMSTRUCT);
break;
case WM_COMPAREITEM:
minsize = sizeof(COMPAREITEMSTRUCT);
break;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
case WM_WINE_SETWINDOWPOS:
minsize = sizeof(WINDOWPOS);
break;
case WM_COPYDATA:
{
COPYDATASTRUCT *cp = *buffer;
if (size < sizeof(*cp)) return FALSE;
if (cp->lpData)
{
minsize = sizeof(*cp) + cp->cbData;
cp->lpData = cp + 1;
}
break;
}
case WM_NOTIFY:
/* WM_NOTIFY cannot be sent across processes (MSDN) */
return FALSE;
case WM_HELP:
minsize = sizeof(HELPINFO);
break;
case WM_STYLECHANGING:
case WM_STYLECHANGED:
minsize = sizeof(STYLESTRUCT);
break;
case WM_NCCALCSIZE:
if (!*wparam) minsize = sizeof(RECT);
else
{
NCCALCSIZE_PARAMS *nc = *buffer;
if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
nc->lppos = (WINDOWPOS *)(nc + 1);
}
break;
case WM_GETDLGCODE:
if (!*lparam) return TRUE;
minsize = sizeof(MSG);
break;
case SBM_SETSCROLLINFO:
minsize = sizeof(SCROLLINFO);
break;
case SBM_GETSCROLLINFO:
if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
break;
case EM_GETSEL:
case SBM_GETRANGE:
case CB_GETEDITSEL:
if (*wparam || *lparam)
{
if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
if (*wparam) *wparam = (WPARAM)*buffer;
if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
}
return TRUE;
case EM_GETRECT:
case LB_GETITEMRECT:
case CB_GETDROPPEDCONTROLRECT:
if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
break;
case EM_SETRECT:
case EM_SETRECTNP:
minsize = sizeof(RECT);
break;
case EM_GETLINE:
{
WORD len;
if (size < sizeof(WORD)) return FALSE;
len = *(WORD *)*buffer;
if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
*lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
return TRUE;
}
case EM_SETTABSTOPS:
case LB_SETTABSTOPS:
if (!*wparam) return TRUE;
minsize = *wparam * sizeof(UINT);
break;
case CB_ADDSTRING:
case CB_INSERTSTRING:
case CB_FINDSTRING:
case CB_FINDSTRINGEXACT:
case CB_SELECTSTRING:
case LB_ADDSTRING:
case LB_INSERTSTRING:
case LB_FINDSTRING:
case LB_FINDSTRINGEXACT:
case LB_SELECTSTRING:
if (!*buffer) return TRUE;
if (!check_string( *buffer, size )) return FALSE;
break;
case CB_GETLBTEXT:
{
size = sizeof(ULONG_PTR);
if (combobox_has_strings( hwnd ))
size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
if (!get_buffer_space( buffer, size )) return FALSE;
break;
}
case LB_GETTEXT:
{
size = sizeof(ULONG_PTR);
if (listbox_has_strings( hwnd ))
size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
if (!get_buffer_space( buffer, size )) return FALSE;
break;
}
case LB_GETSELITEMS:
if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
break;
case WM_NEXTMENU:
minsize = sizeof(MDINEXTMENU);
if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
break;
case WM_SIZING:
case WM_MOVING:
minsize = sizeof(RECT);
if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
break;
case WM_MDICREATE:
{
MDICREATESTRUCTW *cs = *buffer;
WCHAR *str = (WCHAR *)(cs + 1);
if (size < sizeof(*cs)) return FALSE;
size -= sizeof(*cs);
if (HIWORD(cs->szTitle))
{
if (!check_string( str, size )) return FALSE;
cs->szTitle = str;
size -= (strlenW(str) + 1) * sizeof(WCHAR);
str += strlenW(str) + 1;
}
if (HIWORD(cs->szClass))
{
if (!check_string( str, size )) return FALSE;
cs->szClass = str;
}
break;
}
case WM_MDIGETACTIVE:
if (!*lparam) return TRUE;
if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
break;
case WM_WINE_KEYBOARD_LL_HOOK:
minsize = sizeof(KBDLLHOOKSTRUCT);
break;
case WM_WINE_MOUSE_LL_HOOK:
minsize = sizeof(MSLLHOOKSTRUCT);
break;
/* these contain an HFONT */
case WM_SETFONT:
case WM_GETFONT:
/* these contain an HDC */
case WM_PAINT:
case WM_ERASEBKGND:
case WM_ICONERASEBKGND:
case WM_NCPAINT:
case WM_CTLCOLORMSGBOX:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORDLG:
case WM_CTLCOLORSCROLLBAR:
case WM_CTLCOLORSTATIC:
case WM_PRINT:
case WM_PRINTCLIENT:
/* these contain an HGLOBAL */
case WM_PAINTCLIPBOARD:
case WM_SIZECLIPBOARD:
/* these contain HICON */
case WM_GETICON:
case WM_SETICON:
case WM_QUERYDRAGICON:
case WM_QUERYPARKICON:
/* these contain pointers */
case WM_DROPOBJECT:
case WM_QUERYDROPOBJECT:
case WM_DRAGLOOP:
case WM_DRAGSELECT:
case WM_DRAGMOVE:
case WM_DEVICECHANGE:
FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
return FALSE;
default:
return TRUE; /* message doesn't need any unpacking */
}
/* default exit for most messages: check minsize and store buffer in lparam */
if (size < minsize) return FALSE;
*lparam = (LPARAM)*buffer;
return TRUE;
}
/***********************************************************************
* pack_reply
*
* Pack a reply to a message for sending to another process.
*/
static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
LRESULT res, struct packed_message *data )
{
data->count = 0;
switch(message)
{
case WM_NCCREATE:
case WM_CREATE:
push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
break;
case WM_GETTEXT:
case CB_GETLBTEXT:
case LB_GETTEXT:
push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
break;
case WM_GETMINMAXINFO:
push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
break;
case WM_MEASUREITEM:
push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
break;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
break;
case WM_GETDLGCODE:
if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
break;
case SBM_GETSCROLLINFO:
push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
break;
case EM_GETRECT:
case LB_GETITEMRECT:
case CB_GETDROPPEDCONTROLRECT:
case WM_SIZING:
case WM_MOVING:
push_data( data, (RECT *)lparam, sizeof(RECT) );
break;
case EM_GETLINE:
{
WORD *ptr = (WORD *)lparam;
push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
break;
}
case LB_GETSELITEMS:
push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
break;
case WM_MDIGETACTIVE:
if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
break;
case WM_NCCALCSIZE:
if (!wparam)
push_data( data, (RECT *)lparam, sizeof(RECT) );
else
{
NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
push_data( data, nc, sizeof(*nc) );
push_data( data, nc->lppos, sizeof(*nc->lppos) );
}
break;
case EM_GETSEL:
case SBM_GETRANGE:
case CB_GETEDITSEL:
if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
break;
case WM_NEXTMENU:
push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
break;
case WM_MDICREATE:
push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
break;
case WM_ASKCBFORMATNAME:
push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
break;
}
}
/***********************************************************************
* unpack_reply
*
* Unpack a message reply received from another process.
*/
static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
void *buffer, size_t size )
{
switch(message)
{
case WM_NCCREATE:
case WM_CREATE:
{
CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
LPCWSTR name = cs->lpszName, class = cs->lpszClass;
memcpy( cs, buffer, min( sizeof(*cs), size ));
cs->lpszName = name; /* restore the original pointers */
cs->lpszClass = class;
break;
}
case WM_GETTEXT:
case WM_ASKCBFORMATNAME:
memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
break;
case WM_GETMINMAXINFO:
memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
break;
case WM_MEASUREITEM:
memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
break;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
break;
case WM_GETDLGCODE:
if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
break;
case SBM_GETSCROLLINFO:
memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
break;
case EM_GETRECT:
case CB_GETDROPPEDCONTROLRECT:
case LB_GETITEMRECT:
case WM_SIZING:
case WM_MOVING:
memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
break;
case EM_GETLINE:
size = min( size, (size_t)*(WORD *)lparam );
memcpy( (WCHAR *)lparam, buffer, size );
break;
case LB_GETSELITEMS:
memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
break;
case LB_GETTEXT:
case CB_GETLBTEXT:
memcpy( (WCHAR *)lparam, buffer, size );
break;
case WM_NEXTMENU:
memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
break;
case WM_MDIGETACTIVE:
if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
break;
case WM_NCCALCSIZE:
if (!wparam)
memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
else
{
NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
WINDOWPOS *wp = nc->lppos;
memcpy( nc, buffer, min( sizeof(*nc), size ));
if (size > sizeof(*nc))
{
size -= sizeof(*nc);
memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
}
nc->lppos = wp; /* restore the original pointer */
}
break;
case EM_GETSEL:
case SBM_GETRANGE:
case CB_GETEDITSEL:
if (wparam)
{
memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
if (size <= sizeof(DWORD)) break;
size -= sizeof(DWORD);
buffer = (DWORD *)buffer + 1;
}
if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
break;
case WM_MDICREATE:
{
MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
LPCWSTR title = cs->szTitle, class = cs->szClass;
memcpy( cs, buffer, min( sizeof(*cs), size ));
cs->szTitle = title; /* restore the original pointers */
cs->szClass = class;
break;
}
default:
ERR( "should not happen: unexpected message %x\n", message );
break;
}
}
/***********************************************************************
* reply_message
*
* Send a reply to a sent message.
*/
static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
{
struct packed_message data;
int i, replied = info->flags & ISMEX_REPLIED;
if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
if (!remove && replied) return; /* replied already */
data.count = 0;
info->flags |= ISMEX_REPLIED;
if (info->type == MSG_OTHER_PROCESS && !replied)
{
pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
info->msg.lParam, result, &data );
}
SERVER_START_REQ( reply_message )
{
req->type = info->type;
req->result = result;
req->remove = remove;
for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
wine_server_call( req );
}
SERVER_END_REQ;
}
/***********************************************************************
* handle_internal_message
*
* Handle an internal Wine message instead of calling the window proc.
*/
static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
if (hwnd == GetDesktopWindow()) return 0;
switch(msg)
{
case WM_WINE_DESTROYWINDOW:
return WIN_DestroyWindow( hwnd );
case WM_WINE_SETWINDOWPOS:
return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
case WM_WINE_SHOWWINDOW:
return ShowWindow( hwnd, wparam );
case WM_WINE_SETPARENT:
return (LRESULT)SetParent( hwnd, (HWND)wparam );
case WM_WINE_SETWINDOWLONG:
return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
case WM_WINE_ENABLEWINDOW:
return EnableWindow( hwnd, wparam );
case WM_WINE_SETACTIVEWINDOW:
return (LRESULT)SetActiveWindow( (HWND)wparam );
case WM_WINE_KEYBOARD_LL_HOOK:
return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
case WM_WINE_MOUSE_LL_HOOK:
return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
default:
FIXME( "unknown internal message %x\n", msg );
return 0;
}
}
/* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
* to the memory handle, we keep track (in the server side) of all pairs of handle
* used (the client passes its value and the content of the memory handle), and
* the server stored both values (the client, and the local one, created after the
* content). When a ACK message is generated, the list of pair is searched for a
* matching pair, so that the client memory handle can be returned.
*/
struct DDE_pair {
HGLOBAL client_hMem;
HGLOBAL server_hMem;
};
static struct DDE_pair* dde_pairs;
static int dde_num_alloc;
static int dde_num_used;
static CRITICAL_SECTION dde_crst;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &dde_crst,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
};
static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
{
int i;
#define GROWBY 4
EnterCriticalSection(&dde_crst);
/* now remember the pair of hMem on both sides */
if (dde_num_used == dde_num_alloc)
{
struct DDE_pair* tmp;
if (dde_pairs)
tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
(dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
else
tmp = HeapAlloc( GetProcessHeap(), 0,
(dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
if (!tmp)
{
LeaveCriticalSection(&dde_crst);
return FALSE;
}
dde_pairs = tmp;
/* zero out newly allocated part */
memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
dde_num_alloc += GROWBY;
}
#undef GROWBY
for (i = 0; i < dde_num_alloc; i++)
{
if (dde_pairs[i].server_hMem == 0)
{
dde_pairs[i].client_hMem = chm;
dde_pairs[i].server_hMem = shm;
dde_num_used++;
break;
}
}
LeaveCriticalSection(&dde_crst);
return TRUE;
}
static HGLOBAL dde_get_pair(HGLOBAL shm)
{
int i;
HGLOBAL ret = 0;
EnterCriticalSection(&dde_crst);
for (i = 0; i < dde_num_alloc; i++)
{
if (dde_pairs[i].server_hMem == shm)
{
/* free this pair */
dde_pairs[i].server_hMem = 0;
dde_num_used--;
ret = dde_pairs[i].client_hMem;
break;
}
}
LeaveCriticalSection(&dde_crst);
return ret;
}
/***********************************************************************
* post_dde_message
*
* Post a DDE message
*/
static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
{
void* ptr = NULL;
int size = 0;
UINT uiLo, uiHi;
LPARAM lp = 0;
HGLOBAL hunlock = 0;
int i;
DWORD res;
if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
return FALSE;
lp = info->lparam;
switch (info->msg)
{
/* DDE messages which don't require packing are:
* WM_DDE_INITIATE
* WM_DDE_TERMINATE
* WM_DDE_REQUEST
* WM_DDE_UNADVISE
*/
case WM_DDE_ACK:
if (HIWORD(uiHi))
{
/* uiHi should contain a hMem from WM_DDE_EXECUTE */
HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
if (h)
{
/* send back the value of h on the other side */
push_data( data, &h, sizeof(HGLOBAL) );
lp = uiLo;
TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
}
}
else
{
/* uiHi should contain either an atom or 0 */
TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
lp = MAKELONG( uiLo, uiHi );
}
break;
case WM_DDE_ADVISE:
case WM_DDE_DATA:
case WM_DDE_POKE:
size = 0;
if (uiLo)
{
size = GlobalSize( (HGLOBAL)uiLo ) ;
if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
(info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
(info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
)
return FALSE;
}
else if (info->msg != WM_DDE_DATA) return FALSE;
lp = uiHi;
if (uiLo)
{
if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
{
DDEDATA *dde_data = (DDEDATA *)ptr;
TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
dde_data->unused, dde_data->fResponse, dde_data->fRelease,
dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
push_data( data, ptr, size );
hunlock = (HGLOBAL)uiLo;
}
}
TRACE( "send ddepack %u %x\n", size, uiHi );
break;
case WM_DDE_EXECUTE:
if (info->lparam)
{
if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
{
push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
/* so that the other side can send it back on ACK */
lp = info->lparam;
hunlock = (HGLOBAL)info->lparam;
}
}
break;
}
SERVER_START_REQ( send_message )
{
req->id = dest_tid;
req->type = info->type;
req->flags = 0;
req->win = info->hwnd;
req->msg = info->msg;
req->wparam = info->wparam;
req->lparam = lp;
req->time = GetCurrentTime();
req->timeout = -1;
for (i = 0; i < data->count; i++)
wine_server_add_data( req, data->data[i], data->size[i] );
if ((res = wine_server_call( req )))
{
if (res == STATUS_INVALID_PARAMETER)
/* FIXME: find a STATUS_ value for this one */
SetLastError( ERROR_INVALID_THREAD_ID );
else
SetLastError( RtlNtStatusToDosError(res) );
}
else
FreeDDElParam(info->msg, info->lparam);
}
SERVER_END_REQ;
if (hunlock) GlobalUnlock(hunlock);
return !res;
}
/***********************************************************************
* unpack_dde_message
*
* Unpack a posted DDE message received from another process.
*/
static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
void **buffer, size_t size )
{
UINT uiLo, uiHi;
HGLOBAL hMem = 0;
void* ptr;
switch (message)
{
case WM_DDE_ACK:
if (size)
{
/* hMem is being passed */
if (size != sizeof(HGLOBAL)) return FALSE;
if (!buffer || !*buffer) return FALSE;
uiLo = *lparam;
memcpy( &hMem, *buffer, size );
uiHi = (UINT)hMem;
TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
}
else
{
uiLo = LOWORD( *lparam );
uiHi = HIWORD( *lparam );
TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
}
*lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
break;
case WM_DDE_ADVISE:
case WM_DDE_DATA:
case WM_DDE_POKE:
if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
uiHi = *lparam;
TRACE( "recv ddepack %u %x\n", size, uiHi );
if (size)
{
hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
if (hMem && (ptr = GlobalLock( hMem )))
{
memcpy( ptr, *buffer, size );
GlobalUnlock( hMem );
}
else return FALSE;
}
uiLo = (UINT)hMem;
*lparam = PackDDElParam( message, uiLo, uiHi );
break;
case WM_DDE_EXECUTE:
if (size)
{
if (!buffer || !*buffer) return FALSE;
hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
if (hMem && (ptr = GlobalLock( hMem )))
{
memcpy( ptr, *buffer, size );
GlobalUnlock( hMem );
TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
{
GlobalFree( hMem );
return FALSE;
}
}
} else return FALSE;
*lparam = (LPARAM)hMem;
break;
}
return TRUE;
}
/***********************************************************************
* call_window_proc
*
* Call a window procedure and the corresponding hooks.
*/
static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
BOOL unicode, BOOL same_thread )
{
LRESULT result = 0;
WNDPROC winproc;
CWPSTRUCT cwp;
CWPRETSTRUCT cwpret;
MESSAGEQUEUE *queue = QUEUE_Current();
if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
queue->recursion_count++;
if (msg & 0x80000000)
{
result = handle_internal_message( hwnd, msg, wparam, lparam );
goto done;
}
/* first the WH_CALLWNDPROC hook */
hwnd = WIN_GetFullHandle( hwnd );
cwp.lParam = lparam;
cwp.wParam = wparam;
cwp.message = msg;
cwp.hwnd = hwnd;
HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
/* now call the window procedure */
if (unicode)
{
if (!(winproc = (WNDPROC)GetWindowLongW( hwnd, GWL_WNDPROC ))) goto done;
result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
}
else
{
if (!(winproc = (WNDPROC)GetWindowLongA( hwnd, GWL_WNDPROC ))) goto done;
result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
}
/* and finally the WH_CALLWNDPROCRET hook */
cwpret.lResult = result;
cwpret.lParam = lparam;
cwpret.wParam = wparam;
cwpret.message = msg;
cwpret.hwnd = hwnd;
HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
done:
queue->recursion_count--;
return result;
}
/***********************************************************************
* process_hardware_message
*
* Process a hardware message; return TRUE if message should be passed on to the app
*/
static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
UINT first, UINT last, BOOL remove )
{
BOOL ret;
if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
return FALSE;
ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
/* tell the server we have passed it to the app
* (even though we may end up dropping it later on)
*/
SERVER_START_REQ( reply_message )
{
req->type = MSG_HARDWARE;
req->result = 0;
req->remove = remove || !ret;
wine_server_call( req );
}
SERVER_END_REQ;
return ret;
}
/***********************************************************************
* call_sendmsg_callback
*
* Call the callback function of SendMessageCallback.
*/
static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
ULONG_PTR data, LRESULT result )
{
if (TRACE_ON(relay))
DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
data, result );
callback( hwnd, msg, data, result );
if (TRACE_ON(relay))
DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
data, result );
}
/***********************************************************************
* MSG_peek_message
*
* Peek for a message matching the given parameters. Return FALSE if none available.
* All pending sent messages are processed before returning.
*/
BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
{
LRESULT result;
ULONG_PTR extra_info = 0;
MESSAGEQUEUE *queue = QUEUE_Current();
struct received_message_info info, *old_info;
if (!first && !last) last = ~0;
for (;;)
{
NTSTATUS res;
void *buffer = NULL;
size_t size = 0, buffer_size = 0;
do /* loop while buffer is too small */
{
if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
return FALSE;
SERVER_START_REQ( get_message )
{
req->flags = flags;
req->get_win = hwnd;
req->get_first = first;
req->get_last = last;
if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
if (!(res = wine_server_call( req )))
{
size = wine_server_reply_size( reply );
info.type = reply->type;
info.msg.hwnd = reply->win;
info.msg.message = reply->msg;
info.msg.wParam = reply->wparam;
info.msg.lParam = reply->lparam;
info.msg.time = reply->time;
info.msg.pt.x = reply->x;
info.msg.pt.y = reply->y;
extra_info = reply->info;
}
else
{
if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
buffer_size = reply->total;
}
}
SERVER_END_REQ;
} while (res == STATUS_BUFFER_OVERFLOW);
if (res) return FALSE;
TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
info.msg.hwnd, info.msg.wParam, info.msg.lParam );
switch(info.type)
{
case MSG_ASCII:
case MSG_UNICODE:
info.flags = ISMEX_SEND;
break;
case MSG_NOTIFY:
info.flags = ISMEX_NOTIFY;
break;
case MSG_CALLBACK:
info.flags = ISMEX_CALLBACK;
break;
case MSG_CALLBACK_RESULT:
call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
info.msg.message, extra_info, info.msg.lParam );
goto next;
case MSG_OTHER_PROCESS:
info.flags = ISMEX_SEND;
if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
&info.msg.lParam, &buffer, size ))
{
ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
info.msg.wParam, info.msg.lParam, size );
/* ignore it */
reply_message( &info, 0, TRUE );
goto next;
}
break;
case MSG_HARDWARE:
if (!process_hardware_message( &info.msg, extra_info,
hwnd, first, last, flags & GET_MSG_REMOVE ))
{
TRACE("dropping msg %x\n", info.msg.message );
goto next; /* ignore it */
}
queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
/* fall through */
case MSG_POSTED:
queue->GetMessageExtraInfoVal = extra_info;
if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
{
if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
&info.msg.lParam, &buffer, size ))
{
ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
goto next; /* ignore it */
}
}
*msg = info.msg;
if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
return TRUE;
}
/* if we get here, we have a sent message; call the window procedure */
old_info = queue->receive_info;
queue->receive_info = &info;
result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
info.msg.lParam, (info.type != MSG_ASCII), FALSE );
reply_message( &info, result, TRUE );
queue->receive_info = old_info;
next:
if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
}
}
/***********************************************************************
* wait_message_reply
*
* Wait until a sent message gets replied to.
*/
static void wait_message_reply( UINT flags )
{
MESSAGEQUEUE *queue;
if (!(queue = QUEUE_Current())) return;
for (;;)
{
unsigned int wake_bits = 0, changed_bits = 0;
DWORD dwlc, res;
SERVER_START_REQ( set_queue_mask )
{
req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
req->changed_mask = req->wake_mask;
req->skip_wait = 1;
if (!wine_server_call( req ))
{
wake_bits = reply->wake_bits;
changed_bits = reply->changed_bits;
}
}
SERVER_END_REQ;
if (wake_bits & QS_SMRESULT) return; /* got a result */
if (wake_bits & QS_SENDMESSAGE)
{
/* Process the sent message immediately */
MSG msg;
MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
continue;
}
/* now wait for it */
ReleaseThunkLock( &dwlc );
if (USER_Driver.pMsgWaitForMultipleObjectsEx)
res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
INFINITE, 0, 0 );
else
res = WaitForSingleObject( queue->server_queue, INFINITE );
if (dwlc) RestoreThunkLock( dwlc );
}
}
/***********************************************************************
* put_message_in_queue
*
* Put a sent message into the destination queue.
* For inter-process message, reply_size is set to expected size of reply data.
*/
static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
size_t *reply_size )
{
struct packed_message data;
unsigned int res;
int i, timeout = -1;
if (info->type != MSG_NOTIFY &&
info->type != MSG_CALLBACK &&
info->type != MSG_POSTED &&
info->timeout != INFINITE)
timeout = info->timeout;
data.count = 0;
if (info->type == MSG_OTHER_PROCESS)
{
*reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
if (data.count == -1)
{
WARN( "cannot pack message %x\n", info->msg );
return FALSE;
}
}
else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
{
return post_dde_message( dest_tid, &data, info );
}
SERVER_START_REQ( send_message )
{
req->id = dest_tid;
req->type = info->type;
req->flags = 0;
req->win = info->hwnd;
req->msg = info->msg;
req->wparam = info->wparam;
req->lparam = info->lparam;
req->time = GetCurrentTime();
req->timeout = timeout;
if (info->type == MSG_CALLBACK)
{
req->callback = info->callback;
req->info = info->data;
}
if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
if ((res = wine_server_call( req )))
{
if (res == STATUS_INVALID_PARAMETER)
/* FIXME: find a STATUS_ value for this one */
SetLastError( ERROR_INVALID_THREAD_ID );
else
SetLastError( RtlNtStatusToDosError(res) );
}
}
SERVER_END_REQ;
return !res;
}
/***********************************************************************
* retrieve_reply
*
* Retrieve a message reply from the server.
*/
static LRESULT retrieve_reply( const struct send_message_info *info,
size_t reply_size, LRESULT *result )
{
NTSTATUS status;
void *reply_data = NULL;
if (reply_size)
{
if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
{
WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
reply_size = 0;
}
}
SERVER_START_REQ( get_message_reply )
{
req->cancel = 1;
if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
if (!(status = wine_server_call( req ))) *result = reply->result;
reply_size = wine_server_reply_size( reply );
}
SERVER_END_REQ;
if (!status && reply_size)
unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
if (reply_data) HeapFree( GetProcessHeap(), 0, reply_data );
TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
info->lparam, *result, status );
/* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
if (status) SetLastError( RtlNtStatusToDosError(status) );
return !status;
}
/***********************************************************************
* send_inter_thread_message
*/
static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
LRESULT *res_ptr )
{
LRESULT ret;
int locks;
size_t reply_size = 0;
TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
/* there's no reply to wait for on notify/callback messages */
if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
locks = WIN_SuspendWndsLock();
wait_message_reply( info->flags );
ret = retrieve_reply( info, reply_size, res_ptr );
WIN_RestoreWndsLock( locks );
return ret;
}
/***********************************************************************
* MSG_SendInternalMessageTimeout
*
* Same as SendMessageTimeoutW but sends the message to a specific thread
* without requiring a window handle. Only works for internal Wine messages.
*/
LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr )
{
struct send_message_info info;
LRESULT ret, result;
assert( msg & 0x80000000 ); /* must be an internal Wine message */
info.type = MSG_UNICODE;
info.hwnd = 0;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = flags;
info.timeout = timeout;
if (USER_IsExitingThread( dest_tid )) return 0;
if (dest_tid == GetCurrentThreadId())
{
result = handle_internal_message( 0, msg, wparam, lparam );
ret = 1;
}
else
{
if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
ret = send_inter_thread_message( dest_tid, &info, &result );
}
if (ret && res_ptr) *res_ptr = result;
return ret;
}
/***********************************************************************
* SendMessageTimeoutW (USER32.@)
*/
LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr )
{
struct send_message_info info;
DWORD dest_tid, dest_pid;
LRESULT ret, result;
info.type = MSG_UNICODE;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = flags;
info.timeout = timeout;
if (is_broadcast(hwnd))
{
EnumWindows( broadcast_message_callback, (LPARAM)&info );
if (res_ptr) *res_ptr = 1;
return 1;
}
if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
if (USER_IsExitingThread( dest_tid )) return 0;
SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
if (dest_tid == GetCurrentThreadId())
{
result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
ret = 1;
}
else
{
if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
ret = send_inter_thread_message( dest_tid, &info, &result );
}
SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
if (ret && res_ptr) *res_ptr = result;
return ret;
}
/***********************************************************************
* SendMessageTimeoutA (USER32.@)
*/
LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
UINT flags, UINT timeout, PDWORD_PTR res_ptr )
{
struct send_message_info info;
DWORD dest_tid, dest_pid;
LRESULT ret, result;
info.type = MSG_ASCII;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = flags;
info.timeout = timeout;
if (is_broadcast(hwnd))
{
EnumWindows( broadcast_message_callback, (LPARAM)&info );
if (res_ptr) *res_ptr = 1;
return 1;
}
if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
if (USER_IsExitingThread( dest_tid )) return 0;
SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
if (dest_tid == GetCurrentThreadId())
{
result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
ret = 1;
}
else if (dest_pid == GetCurrentProcessId())
{
ret = send_inter_thread_message( dest_tid, &info, &result );
}
else
{
/* inter-process message: need to map to Unicode */
info.type = MSG_OTHER_PROCESS;
if (is_unicode_message( info.msg ))
{
if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
return 0;
ret = send_inter_thread_message( dest_tid, &info, &result );
result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
info.lparam, result );
}
else ret = send_inter_thread_message( dest_tid, &info, &result );
}
SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
if (ret && res_ptr) *res_ptr = result;
return ret;
}
/***********************************************************************
* SendMessageW (USER32.@)
*/
LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
LRESULT res = 0;
SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
return res;
}
/***********************************************************************
* SendMessageA (USER32.@)
*/
LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
LRESULT res = 0;
SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
return res;
}
/***********************************************************************
* SendNotifyMessageA (USER32.@)
*/
BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
}
/***********************************************************************
* SendNotifyMessageW (USER32.@)
*/
BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
struct send_message_info info;
DWORD dest_tid;
LRESULT result;
if (is_pointer_message(msg))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
info.type = MSG_NOTIFY;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = 0;
if (is_broadcast(hwnd))
{
EnumWindows( broadcast_message_callback, (LPARAM)&info );
return TRUE;
}
if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
if (USER_IsExitingThread( dest_tid )) return TRUE;
if (dest_tid == GetCurrentThreadId())
{
call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
return TRUE;
}
return send_inter_thread_message( dest_tid, &info, &result );
}
/***********************************************************************
* SendMessageCallbackA (USER32.@)
*/
BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
SENDASYNCPROC callback, ULONG_PTR data )
{
return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
lparam, callback, data );
}
/***********************************************************************
* SendMessageCallbackW (USER32.@)
*/
BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
SENDASYNCPROC callback, ULONG_PTR data )
{
struct send_message_info info;
LRESULT result;
DWORD dest_tid;
if (is_pointer_message(msg))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
info.type = MSG_CALLBACK;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.callback = callback;
info.data = data;
info.flags = 0;
if (is_broadcast(hwnd))
{
EnumWindows( broadcast_message_callback, (LPARAM)&info );
return TRUE;
}
if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
if (USER_IsExitingThread( dest_tid )) return TRUE;
if (dest_tid == GetCurrentThreadId())
{
result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
call_sendmsg_callback( callback, hwnd, msg, data, result );
return TRUE;
}
FIXME( "callback will not be called\n" );
return send_inter_thread_message( dest_tid, &info, &result );
}
/***********************************************************************
* ReplyMessage (USER32.@)
*/
BOOL WINAPI ReplyMessage( LRESULT result )
{
MESSAGEQUEUE *queue = QUEUE_Current();
struct received_message_info *info = queue->receive_info;
if (!info) return FALSE;
reply_message( info, result, FALSE );
return TRUE;
}
/***********************************************************************
* InSendMessage (USER32.@)
*/
BOOL WINAPI InSendMessage(void)
{
return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
}
/***********************************************************************
* InSendMessageEx (USER32.@)
*/
DWORD WINAPI InSendMessageEx( LPVOID reserved )
{
MESSAGEQUEUE *queue = QUEUE_Current();
struct received_message_info *info = queue->receive_info;
if (info) return info->flags;
return ISMEX_NOSEND;
}
/***********************************************************************
* PostMessageA (USER32.@)
*/
BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
}
/***********************************************************************
* PostMessageW (USER32.@)
*/
BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
struct send_message_info info;
DWORD dest_tid;
if (is_pointer_message( msg ))
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
info.type = MSG_POSTED;
info.hwnd = hwnd;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = 0;
if (is_broadcast(hwnd))
{
EnumWindows( broadcast_message_callback, (LPARAM)&info );
return TRUE;
}
if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
if (USER_IsExitingThread( dest_tid )) return TRUE;
return put_message_in_queue( dest_tid, &info, NULL );
}
/**********************************************************************
* PostThreadMessageA (USER32.@)
*/
BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
{
return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
}
/**********************************************************************
* PostThreadMessageW (USER32.@)
*/
BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
{
struct send_message_info info;
if (is_pointer_message( msg ))
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
if (USER_IsExitingThread( thread )) return TRUE;
info.type = MSG_POSTED;
info.hwnd = 0;
info.msg = msg;
info.wparam = wparam;
info.lparam = lparam;
info.flags = 0;
return put_message_in_queue( thread, &info, NULL );
}
/***********************************************************************
* PostQuitMessage (USER32.@)
*/
void WINAPI PostQuitMessage( INT exitCode )
{
PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
}
/***********************************************************************
* PeekMessageW (USER32.@)
*/
BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
{
MESSAGEQUEUE *queue;
MSG msg;
int locks;
/* check for graphics events */
if (USER_Driver.pMsgWaitForMultipleObjectsEx)
USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
hwnd = WIN_GetFullHandle( hwnd );
locks = WIN_SuspendWndsLock();
if (!MSG_peek_message( &msg, hwnd, first, last,
(flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
{
if (!(flags & PM_NOYIELD))
{
DWORD count;
ReleaseThunkLock(&count);
if (count) RestoreThunkLock(count);
}
WIN_RestoreWndsLock( locks );
return FALSE;
}
WIN_RestoreWndsLock( locks );
/* need to fill the window handle for WM_PAINT message */
if (msg.message == WM_PAINT)
{
if (IsIconic( msg.hwnd ) && GetClassLongA( msg.hwnd, GCL_HICON ))
{
msg.message = WM_PAINTICON;
msg.wParam = 1;
}
/* clear internal paint flag */
RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
}
if ((queue = QUEUE_Current()))
{
queue->GetMessageTimeVal = msg.time;
msg.pt.x = LOWORD( queue->GetMessagePosVal );
msg.pt.y = HIWORD( queue->GetMessagePosVal );
}
HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
/* copy back our internal safe copy of message data to msg_out.
* msg_out is a variable from the *program*, so it can't be used
* internally as it can get "corrupted" by our use of SendMessage()
* (back to the program) inside the message handling itself. */
*msg_out = msg;
return TRUE;
}
/***********************************************************************
* PeekMessageA (USER32.@)
*/
BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
{
BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
return ret;
}
/***********************************************************************
* GetMessageW (USER32.@)
*/
BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
{
MESSAGEQUEUE *queue = QUEUE_Current();
int mask, locks;
mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
if (first || last)
{
if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
}
else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
locks = WIN_SuspendWndsLock();
while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
{
/* wait until one of the bits is set */
unsigned int wake_bits = 0, changed_bits = 0;
DWORD dwlc;
SERVER_START_REQ( set_queue_mask )
{
req->wake_mask = QS_SENDMESSAGE;
req->changed_mask = mask;
req->skip_wait = 1;
if (!wine_server_call( req ))
{
wake_bits = reply->wake_bits;
changed_bits = reply->changed_bits;
}
}
SERVER_END_REQ;
if (changed_bits & mask) continue;
if (wake_bits & QS_SENDMESSAGE) continue;
TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
queue->self, mask, wake_bits, changed_bits );
ReleaseThunkLock( &dwlc );
if (USER_Driver.pMsgWaitForMultipleObjectsEx)
USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
else
WaitForSingleObject( queue->server_queue, INFINITE );
if (dwlc) RestoreThunkLock( dwlc );
}
WIN_RestoreWndsLock( locks );
return (msg->message != WM_QUIT);
}
/***********************************************************************
* GetMessageA (USER32.@)
*/
BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
{
GetMessageW( msg, hwnd, first, last );
msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
return (msg->message != WM_QUIT);
}
/***********************************************************************
* IsDialogMessage (USER32.@)
* IsDialogMessageA (USER32.@)
*/
BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
{
MSG msg = *pmsg;
msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
return IsDialogMessageW( hwndDlg, &msg );
}
/***********************************************************************
* SetMessageQueue (USER32.@)
*/
BOOL WINAPI SetMessageQueue( INT size )
{
/* now obsolete the message queue will be expanded dynamically as necessary */
return TRUE;
}
/**********************************************************************
* AttachThreadInput (USER32.@)
*
* Attaches the input processing mechanism of one thread to that of
* another thread.
*/
BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
{
BOOL ret;
SERVER_START_REQ( attach_thread_input )
{
req->tid_from = from;
req->tid_to = to;
req->attach = attach;
ret = !wine_server_call_err( req );
}
SERVER_END_REQ;
return ret;
}
/**********************************************************************
* GetGUIThreadInfo (USER32.@)
*/
BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
{
BOOL ret;
SERVER_START_REQ( get_thread_input )
{
req->tid = id;
if ((ret = !wine_server_call_err( req )))
{
info->flags = 0;
info->hwndActive = reply->active;
info->hwndFocus = reply->focus;
info->hwndCapture = reply->capture;
info->hwndMenuOwner = reply->menu_owner;
info->hwndMoveSize = reply->move_size;
info->hwndCaret = reply->caret;
info->rcCaret.left = reply->rect.left;
info->rcCaret.top = reply->rect.top;
info->rcCaret.right = reply->rect.right;
info->rcCaret.bottom = reply->rect.bottom;
if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
if (reply->move_size) info->flags |= GUI_INMOVESIZE;
if (reply->caret) info->flags |= GUI_CARETBLINKING;
}
}
SERVER_END_REQ;
return ret;
}
/**********************************************************************
* GetKeyState (USER32.@)
*
* An application calls the GetKeyState function in response to a
* keyboard-input message. This function retrieves the state of the key
* at the time the input message was generated.
*/
SHORT WINAPI GetKeyState(INT vkey)
{
SHORT retval = 0;
SERVER_START_REQ( get_key_state )
{
req->tid = GetCurrentThreadId();
req->key = vkey;
if (!wine_server_call( req )) retval = (signed char)reply->state;
}
SERVER_END_REQ;
TRACE("key (0x%x) -> %x\n", vkey, retval);
return retval;
}
/**********************************************************************
* GetKeyboardState (USER32.@)
*/
BOOL WINAPI GetKeyboardState( LPBYTE state )
{
BOOL ret;
TRACE("(%p)\n", state);
memset( state, 0, 256 );
SERVER_START_REQ( get_key_state )
{
req->tid = GetCurrentThreadId();
req->key = -1;
wine_server_set_reply( req, state, 256 );
ret = !wine_server_call_err( req );
}
SERVER_END_REQ;
return ret;
}
/**********************************************************************
* SetKeyboardState (USER32.@)
*/
BOOL WINAPI SetKeyboardState( LPBYTE state )
{
BOOL ret;
TRACE("(%p)\n", state);
SERVER_START_REQ( set_key_state )
{
req->tid = GetCurrentThreadId();
wine_server_add_data( req, state, 256 );
ret = !wine_server_call_err( req );
}
SERVER_END_REQ;
return ret;
}
/******************************************************************
* IsHungAppWindow (USER32.@)
*
*/
BOOL WINAPI IsHungAppWindow( HWND hWnd )
{
DWORD dwResult;
return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
}
| 30.980299 | 113 | 0.564697 |
ed60e8bc76b0476882ad8e815f20daf612c25612 | 1,549 | c | C | test/thread.c | YingshuLu/libcask | b2d7c070d566c1ca603a6a672aaec747669a1614 | [
"MIT"
] | 13 | 2018-05-29T02:02:24.000Z | 2020-12-29T06:14:21.000Z | nattan/src/deps/libcask/test/thread.c | YingshuLu/nattan | aedc6bf2735fca700edf8679c334b35d783080ab | [
"MIT"
] | 1 | 2020-04-14T08:14:32.000Z | 2021-11-30T10:16:34.000Z | nattan/src/deps/libcask/test/thread.c | YingshuLu/nattan | aedc6bf2735fca700edf8679c334b35d783080ab | [
"MIT"
] | 2 | 2020-04-05T08:35:03.000Z | 2020-04-07T19:15:29.000Z | #include <pthread.h>
#include "co_define.h"
#include "co_mutex.h"
#include "atomic.h"
#include "co_cond.h"
#include "co_bar.h"
#include "co_await.h"
#define THREAD_MAX 6
#define CO_MAX 10000
co_mutex_t g_mutex;
co_bar_t g_bar;
atomic_t am;
int g_count = 0;
int add(void *ip) {
int i;
for(i = 0; i < 1000000; i++) {}
return i;
}
void task(void *ip, void *op) {
sleep(10000);
INF_LOG("task cond wait");
co_bar_wait(&g_bar);
INF_LOG("task cond start");
while(1) {
atomic_inc(&am);
INF_LOG("thread task: %d, atomic: %d", getcid(), atomic_get(&am));
co_mutex_lock(&g_mutex);
if(g_count >= 10) goto end;
g_count++;
INF_LOG("[count] g_count : %d", g_count);
co_mutex_unlock(&g_mutex);
co_yield();
}
end:
co_mutex_unlock(&g_mutex);
}
void wait_task(void *ip, void *op) {
int ret = co_await(add, NULL);
INF_LOG("co wait return: %d", ret);
}
void *routine(void *param) {
INF_LOG("pthread %d start", tid());
int i = 0;
for(; i<CO_MAX; i++) {
co_create(task, NULL, NULL);
}
co_create(wait_task, NULL, NULL);
schedule();
}
int main() {
co_mutex_init(&g_mutex);
co_bar_init(&g_bar, 6);
pthread_t pid[THREAD_MAX];
int i = 0;
for(; i < THREAD_MAX; i++) {
pthread_create(&(pid[i]), NULL, routine, NULL);
}
for(i = 0; i < THREAD_MAX; i++) {
pthread_join(pid[i], NULL);
INF_LOG("main thread waited thread %d", pid[i]);
}
return 0;
}
| 19.607595 | 74 | 0.5694 |
370bf9e37ce5295e810d9fab264171797accad8e | 719 | h | C | src/rom.h | Lieutenant-Debaser/rom-checksum | 45104adc2280dac448b9f37e7b637909e69f760c | [
"MIT"
] | null | null | null | src/rom.h | Lieutenant-Debaser/rom-checksum | 45104adc2280dac448b9f37e7b637909e69f760c | [
"MIT"
] | null | null | null | src/rom.h | Lieutenant-Debaser/rom-checksum | 45104adc2280dac448b9f37e7b637909e69f760c | [
"MIT"
] | null | null | null | /* File: rom.h
* Author: Lieutenant Debaser
* Last Update (yyyy-mm-dd_hhMM): 2022-01-27_1428
*
* File contains definition for the Rom_File class.
*
* See rom.cpp for function definitions.
*/
#ifndef ROM_H
#define ROM_H
#include <string>
class Rom_File {
public:
// Class constructors
Rom_File();
// Accessors
std::string get_name();
std::string get_md5();
std::string get_sha1();
unsigned long long get_size();
// Mutators
void set_name (std::string s);
void set_md5 (std::string s);
void set_sha1 (std::string s);
void set_size (unsigned long long i);
private:
std::string name;
std::string md5, sha1;
unsigned long long size;
};
#endif | 17.536585 | 51 | 0.645341 |
a68269acd85820347f72f9048c83cd591cf7d292 | 5,564 | h | C | Engine/Source/Runtime/Math/YumeVector2.h | rodrigobmg/YumeEngine | 67c525c84616a5167b5bae45f36641e90227c281 | [
"MIT"
] | 129 | 2016-05-05T23:34:44.000Z | 2022-03-07T20:17:18.000Z | Engine/Source/Runtime/Math/YumeVector2.h | rodrigobmg/YumeEngine | 67c525c84616a5167b5bae45f36641e90227c281 | [
"MIT"
] | 1 | 2017-05-07T16:09:41.000Z | 2017-05-08T15:35:50.000Z | Engine/Source/Runtime/Math/YumeVector2.h | rodrigobmg/YumeEngine | 67c525c84616a5167b5bae45f36641e90227c281 | [
"MIT"
] | 20 | 2016-02-24T20:40:08.000Z | 2022-02-04T23:48:18.000Z |
#ifndef __YumeVector2_h__
#define __YumeVector2_h__
//--------------------------------------------------------------------------------
#include "YumeRequired.h"
#include "YumeMath.h"
//--------------------------------------------------------------------------------
namespace YumeEngine
{
class YumeAPIExport Vector2
{
public:
Vector2():
x_(0.0f),
y_(0.0f)
{
}
Vector2(const Vector2& vector):
x_(vector.x_),
y_(vector.y_)
{
}
Vector2(float x,float y):
x_(x),
y_(y)
{
}
explicit Vector2(const float* data):
x_(data[0]),
y_(data[1])
{
}
Vector2& operator =(const Vector2& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
return *this;
}
bool operator ==(const Vector2& rhs) const { return x_ == rhs.x_ && y_ == rhs.y_; }
bool operator !=(const Vector2& rhs) const { return x_ != rhs.x_ || y_ != rhs.y_; }
Vector2 operator +(const Vector2& rhs) const { return Vector2(x_ + rhs.x_,y_ + rhs.y_); }
Vector2 operator -() const { return Vector2(-x_,-y_); }
Vector2 operator -(const Vector2& rhs) const { return Vector2(x_ - rhs.x_,y_ - rhs.y_); }
Vector2 operator *(float rhs) const { return Vector2(x_ * rhs,y_ * rhs); }
Vector2 operator *(const Vector2& rhs) const { return Vector2(x_ * rhs.x_,y_ * rhs.y_); }
Vector2 operator /(float rhs) const { return Vector2(x_ / rhs,y_ / rhs); }
Vector2 operator /(const Vector2& rhs) const { return Vector2(x_ / rhs.x_,y_ / rhs.y_); }
Vector2& operator +=(const Vector2& rhs)
{
x_ += rhs.x_;
y_ += rhs.y_;
return *this;
}
Vector2& operator -=(const Vector2& rhs)
{
x_ -= rhs.x_;
y_ -= rhs.y_;
return *this;
}
Vector2& operator *=(float rhs)
{
x_ *= rhs;
y_ *= rhs;
return *this;
}
Vector2& operator *=(const Vector2& rhs)
{
x_ *= rhs.x_;
y_ *= rhs.y_;
return *this;
}
Vector2& operator /=(float rhs)
{
float invRhs = 1.0f / rhs;
x_ *= invRhs;
y_ *= invRhs;
return *this;
}
Vector2& operator /=(const Vector2& rhs)
{
x_ /= rhs.x_;
y_ /= rhs.y_;
return *this;
}
void Normalize()
{
float lenSquared = LengthSquared();
if(!YumeEngine::Equals(lenSquared,1.0f) && lenSquared > 0.0f)
{
float invLen = 1.0f / sqrtf(lenSquared);
x_ *= invLen;
y_ *= invLen;
}
}
float Length() const { return sqrtf(x_ * x_ + y_ * y_); }
float LengthSquared() const { return x_ * x_ + y_ * y_; }
float DotProduct(const Vector2& rhs) const { return x_ * rhs.x_ + y_ * rhs.y_; }
float AbsDotProduct(const Vector2& rhs) const { return YumeEngine::Abs(x_ * rhs.x_) + YumeEngine::Abs(y_ * rhs.y_); }
float Angle(const Vector2& rhs) const { return Acos(DotProduct(rhs) / (Length() * rhs.Length())); }
Vector2 Abs() const { return Vector2(YumeEngine::Abs(x_),YumeEngine::Abs(y_)); }
Vector2 Lerp(const Vector2& rhs,float t) const { return *this * (1.0f - t) + rhs * t; }
bool Equals(const Vector2& rhs) const { return YumeEngine::Equals(x_,rhs.x_) && YumeEngine::Equals(y_,rhs.y_); }
bool IsNaN() const { return YumeEngine::IsNaN(x_) || YumeEngine::IsNaN(y_); }
Vector2 Normalized() const
{
float lenSquared = LengthSquared();
if(!YumeEngine::Equals(lenSquared,1.0f) && lenSquared > 0.0f)
{
float invLen = 1.0f / sqrtf(lenSquared);
return *this * invLen;
}
else
return *this;
}
const float* Data() const { return &x_; }
YumeString ToString() const;
float x_;
float y_;
static const Vector2 ZERO;
static const Vector2 LEFT;
static const Vector2 RIGHT;
static const Vector2 UP;
static const Vector2 DOWN;
static const Vector2 ONE;
};
inline Vector2 operator *(float lhs,const Vector2& rhs) { return rhs * lhs; }
class YumeAPIExport IntVector2
{
public:
IntVector2():
x_(0),
y_(0)
{
}
IntVector2(int x,int y):
x_(x),
y_(y)
{
}
IntVector2(const int* data):
x_(data[0]),
y_(data[1])
{
}
IntVector2(const IntVector2& rhs):
x_(rhs.x_),
y_(rhs.y_)
{
}
IntVector2& operator =(const IntVector2& rhs)
{
x_ = rhs.x_;
y_ = rhs.y_;
return *this;
}
bool operator ==(const IntVector2& rhs) const { return x_ == rhs.x_ && y_ == rhs.y_; }
bool operator !=(const IntVector2& rhs) const { return x_ != rhs.x_ || y_ != rhs.y_; }
IntVector2 operator +(const IntVector2& rhs) const { return IntVector2(x_ + rhs.x_,y_ + rhs.y_); }
IntVector2 operator -() const { return IntVector2(-x_,-y_); }
IntVector2 operator -(const IntVector2& rhs) const { return IntVector2(x_ - rhs.x_,y_ - rhs.y_); }
IntVector2 operator *(int rhs) const { return IntVector2(x_ * rhs,y_ * rhs); }
IntVector2 operator /(int rhs) const { return IntVector2(x_ / rhs,y_ / rhs); }
IntVector2& operator +=(const IntVector2& rhs)
{
x_ += rhs.x_;
y_ += rhs.y_;
return *this;
}
IntVector2& operator -=(const IntVector2& rhs)
{
x_ -= rhs.x_;
y_ -= rhs.y_;
return *this;
}
IntVector2& operator *=(int rhs)
{
x_ *= rhs;
y_ *= rhs;
return *this;
}
IntVector2& operator /=(int rhs)
{
x_ /= rhs;
y_ /= rhs;
return *this;
}
const int* Data() const { return &x_; }
YumeString ToString() const;
int x_;
int y_;
static const IntVector2 ZERO;
};
inline IntVector2 operator *(int lhs,const IntVector2& rhs) { return rhs * lhs; }
}
#endif
| 15.942693 | 119 | 0.569015 |
a6ba467431a28c525e11a77c1be638906bfff0da | 174 | h | C | include/sys/io.h | rofl0r/musl-ppc | 1e717ea3d2a864e00e507f1a70a892c551955f1b | [
"MIT"
] | 1 | 2021-03-10T12:38:09.000Z | 2021-03-10T12:38:09.000Z | include/sys/io.h | rofl0r/musl-ppc | 1e717ea3d2a864e00e507f1a70a892c551955f1b | [
"MIT"
] | null | null | null | include/sys/io.h | rofl0r/musl-ppc | 1e717ea3d2a864e00e507f1a70a892c551955f1b | [
"MIT"
] | null | null | null | #ifndef _SYS_IO_H
#define _SYS_IO_H
#ifdef __cplusplus
extern "C" {
#endif
int ioperm(unsigned long, unsigned long, int);
int iopl(int);
#ifdef __cplusplus
}
#endif
#endif
| 12.428571 | 46 | 0.747126 |
b0c76fff6b8f9c5c03c75a01c4dcf515399d1359 | 3,870 | h | C | src/platforms/ios/Pods/SciChart/SciChart.framework/Headers/SCIRange.h | ABTSoftware/SciChart.NativeScript.Examples | e090333b7564bf870a94f1763c4735707e039147 | [
"Apache-2.0"
] | null | null | null | src/platforms/ios/Pods/SciChart/SciChart.framework/Headers/SCIRange.h | ABTSoftware/SciChart.NativeScript.Examples | e090333b7564bf870a94f1763c4735707e039147 | [
"Apache-2.0"
] | null | null | null | src/platforms/ios/Pods/SciChart/SciChart.framework/Headers/SCIRange.h | ABTSoftware/SciChart.NativeScript.Examples | e090333b7564bf870a94f1763c4735707e039147 | [
"Apache-2.0"
] | 1 | 2020-06-03T03:14:33.000Z | 2020-06-03T03:14:33.000Z | //
// Range.h
// SciChart
//
// Created by Admin on 08.07.15.
// Copyright (c) 2015 SciChart Ltd. All rights reserved.
//
/** \addtogroup Ranges
* @{
*/
#import <Foundation/Foundation.h>
#import "SCIGenericType.h"
/**
@typedef SCIRangeClipMode
@brief Enum defines range clipping modes
@see SCIRange
@field SCIRangeClipMode_MinMax range is clipped at min and max values
@field SCIRangeClipMode_Max range is clipped only at max value
@field SCIRangeClipMode_Min range is clipped only at min value
*/
typedef NS_ENUM(int, SCIRangeClipMode) {
/** range is clipped at min and max values */
SCIRangeClipMode_MinMax,
/** range is clipped only at max value */
SCIRangeClipMode_Max,
/** range is clipped only at min value */
SCIRangeClipMode_Min
};
/**
@typedef SCIRangeType
@brief Defines range types
@field SCIRangeType_Numeric numeric range
@field SCIRangeType_Date date time range
@field SCIRangeType_Index index range
@see SCIRange
*/
typedef NS_ENUM(int, SCIRangeType) {
/** numeric range */
SCIRangeType_Numeric,
/** date time range */
SCIRangeType_Date,
/** index range */
SCIRangeType_Index
};
/**
@brief Defines protcol for ranges. Range is defined by min, max values and type
*/
@protocol SCIRangeProtocol ///
<NSObject>
/** @{ @} */
@required
/**
@brief Returns range type (numeric, date time or index)
@see SCIRangeType
*/
-(SCIRangeType) rangeType;
/**
@brief Gets or sets min value for range
@see SCIGenericType
*/
@property (nonatomic) SCIGenericType min;
/**
@brief Gets or sets max value for range
@see SCIGenericType
*/
@property (nonatomic) SCIGenericType max;
/**
@brief Returns difference between max and min values
@see SCIGenericType
*/
-(SCIGenericType) diff;
/**
@brief Return true if difference between max and min is zero
*/
-(BOOL) isZero;
/**
@brief Converts range to SCIDoubleRange
@see SCIDoubleRange
*/
-(id<SCIRangeProtocol>) asDoubleRange;
/**
@brief Method sets min and max values for range
@see SCIGenericType
*/
-(void) setMinTo:(SCIGenericType)min MaxTo:(SCIGenericType)max;
/**
@brief Method sets min and max values for range and clips values to limits
@param min SCIGenericType min value
@param max SCIGenericType max value
@limits SCIRange resulting min and max can not be out of this range
@see SCIGenericType
*/
-(void) setMinTo:(SCIGenericType)min MaxTo:(SCIGenericType)max WithLimits:(id<SCIRangeProtocol>)limits;
/**
@brief Multiplies min and max values of current range. Returns self
@param min min multiplier
@param max max multiplier
*/
-(id<SCIRangeProtocol>) growMinBy:(SCIGenericType)min MaxBy:(SCIGenericType)max;
/**
@brief Clips range to maximum range. Return self
*/
-(id<SCIRangeProtocol>) clipTo:(id<SCIRangeProtocol>)maximumRange;
/**
@brief Returns true if value is greater than min and lesser than max of range
*/
-(BOOL) isValueWithinTheRange:(SCIGenericType)value;
/**
@brief Returns true if range is defines. Usually it means that max greater than min and min and max is not NaN
*/
-(BOOL) isDefined;
/**
@brief Compares range instance to another range and returhns true if they are equal
*/
-(BOOL) equals:(__unsafe_unretained id<SCIRangeProtocol>)otherRange;
/**
@brief Returns new range as union of two ranges. Min is minimal from two ranges and max is maximal from two ranges
*/
-(id<SCIRangeProtocol>) unionWith:(__unsafe_unretained id<SCIRangeProtocol>)range;
/**
@brief Creates copy of range
*/
-(id<SCIRangeProtocol>) clone;
/**
@brief Check if min lesser than max and throw exception if not
*/
-(void) assertMinLessOrEqualToThanMax;
/**
@brief Enlarges current range with logarithmic scaling
*/
-(id<SCIRangeProtocol>) growMinBy:(SCIGenericType)minFraction MaxBy:(SCIGenericType)maxFraction isLogarithmic:(BOOL)isLogarithmic LogBase:(double)logBase;
@end
/** @}*/
| 25.294118 | 154 | 0.734109 |
b0d0c301500cb7585d0f853532267378c7355928 | 707 | h | C | src/debug.h | thomas-sterrenburg/fingerprinting-poc | 58cdac4b687d3769462f8cd9ede6201a093c4b84 | [
"MIT"
] | null | null | null | src/debug.h | thomas-sterrenburg/fingerprinting-poc | 58cdac4b687d3769462f8cd9ede6201a093c4b84 | [
"MIT"
] | null | null | null | src/debug.h | thomas-sterrenburg/fingerprinting-poc | 58cdac4b687d3769462f8cd9ede6201a093c4b84 | [
"MIT"
] | null | null | null | /*
* Copyright 2017 Thomas Sterrenburg
*
* Licensed under the MIT License (the License); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at https://opensource.org/licenses/MIT
*/
#ifndef FINGERPRINTING_POC_DEBUG_H
#define FINGERPRINTING_POC_DEBUG_H
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
#define YELLOW "\x1b[33m"
#define BLUE "\x1b[34m"
#define MAGENTA "\x1b[35m"
#define CYAN "\x1b[36m"
#define RESET "\x1b[0m"
#define SUCCESS GREEN
#define WARNING MAGENTA
#define ERROR RED
#define INFO CYAN
#define DEBUG
#ifdef DEBUG
#define D
#else
#define D for(;0;)
#endif
#endif //FINGERPRINTING_POC_DEBUG_H
| 20.794118 | 77 | 0.712871 |
b0d2c56b662f1552d742726169c9f34da7511ace | 668 | h | C | days/Day4--Giant_Squid/program/Board.h | wojtkolos/AdventOfCode2021 | 4ea33fee9c076cd208b097278168f7d397c1da6a | [
"Apache-2.0"
] | null | null | null | days/Day4--Giant_Squid/program/Board.h | wojtkolos/AdventOfCode2021 | 4ea33fee9c076cd208b097278168f7d397c1da6a | [
"Apache-2.0"
] | null | null | null | days/Day4--Giant_Squid/program/Board.h | wojtkolos/AdventOfCode2021 | 4ea33fee9c076cd208b097278168f7d397c1da6a | [
"Apache-2.0"
] | null | null | null | #include <iostream>
#include <vector>
#include <string>
//
// Board
//
class Board {
private:
std::vector<std::vector<bool>> checked;
std::vector<std::vector<int>> board;
std::vector<std::vector<int>> counter;
bool isBingo;
int lastNumber;
int sumOfNotHited();
bool added;
friend std::istream& operator>>(std::istream&, Board&);
friend std::ostream& operator<<(std::ostream&, Board&);
friend bool operator== (std::vector<Board>&, Board&);
public:
Board();
bool bingo(int toCheck);
unsigned int getScore();
void setAdded(bool a);
bool getAdded() { return added; }
}; | 20.875 | 60 | 0.597305 |
90a641257f908a90860a400fae36a01e9893e32d | 189 | h | C | WDYBaseProject/Classes/Category/UIApplication/UIApplication+KeyboardFrame.h | wangdongyang/WDYBaseProject | 863982cc88d4ca9a999f4653b89d1ce8a0a16687 | [
"MIT"
] | null | null | null | WDYBaseProject/Classes/Category/UIApplication/UIApplication+KeyboardFrame.h | wangdongyang/WDYBaseProject | 863982cc88d4ca9a999f4653b89d1ce8a0a16687 | [
"MIT"
] | null | null | null | WDYBaseProject/Classes/Category/UIApplication/UIApplication+KeyboardFrame.h | wangdongyang/WDYBaseProject | 863982cc88d4ca9a999f4653b89d1ce8a0a16687 | [
"MIT"
] | null | null | null | //
// UIApplication+KeyboardFrame.h
// Pods
//
// Created by fang wang on 17/1/10.
//
//
#import <UIKit/UIKit.h>
@interface UIApplication (KeyboardFrame)
- (CGRect)keyboardFrame;
@end
| 13.5 | 40 | 0.68254 |
884853c3774d98ba8509a36e6e5ce9151704c065 | 2,741 | h | C | data/train/cpp/884853c3774d98ba8509a36e6e5ce9151704c065SampleUser.h | harshp8l/deep-learning-lang-detection | 2a54293181c1c2b1a2b840ddee4d4d80177efb33 | [
"MIT"
] | 84 | 2017-10-25T15:49:21.000Z | 2021-11-28T21:25:54.000Z | data/train/cpp/884853c3774d98ba8509a36e6e5ce9151704c065SampleUser.h | vassalos/deep-learning-lang-detection | cbb00b3e81bed3a64553f9c6aa6138b2511e544e | [
"MIT"
] | 5 | 2018-03-29T11:50:46.000Z | 2021-04-26T13:33:18.000Z | data/train/cpp/884853c3774d98ba8509a36e6e5ce9151704c065SampleUser.h | vassalos/deep-learning-lang-detection | cbb00b3e81bed3a64553f9c6aa6138b2511e544e | [
"MIT"
] | 24 | 2017-11-22T08:31:00.000Z | 2022-03-27T01:22:31.000Z | /* YTP King - Easy to use sentence mixer
* Copyright (C) 2013 Alex "rainChu" Haddad et al.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __YTPKING_SMP_SampleUser_h
#define __YTPKING_SMP_SampleUser_h
namespace ytpking
{
namespace smp
{
class Sample;
class SampleManager;
/** Base class for classes which are affected when a Sample is added or removed. */
class SampleUser
{
friend class SampleManager;
public:
explicit SampleUser( SampleManager &manager );
virtual ~SampleUser( void );
private:
explicit SampleUser( SampleUser &);
void operator=( const SampleUser & );
protected:
/** A new Sample has been added to SampleManager object.
\param sampleName The name of the added Sample.
\param speakerName The name of the speaker
\param addedSample The newly added Sample. */
virtual void
onAddSample( char const *sampleName, char const *speakerName, Sample *addedSample );
/** Called when a Sample is selected.
\param selectedSample The newly selected Sample */
virtual void
onSelectSample( Sample *selectedSample );
/** Called when a Sample is about to be deleted.
If a pointer matching deletedSample is held, it should be set to NULL or otherwise
set to no longer match the sample, as that data is soon to be destroyed.
\param deletedSample The sample which will soon be destroyed by SampleManager */
virtual void
onDeleteSample( Sample *deletedSample );
/** Called when a Sample has been renamed.
\param newSampleName The new name of the sample
\param sample A pointer to the sample being renamed. */
virtual void
onRenameSample( char const *newSampleName, Sample *sample );
/** Called when a Sample's speaker has been changed.
\param newSampleName The new name of the sample
\param sample A pointer to the sample being renamed. */
virtual void
onChangeSampleSpeaker( char const *speakerName, Sample *sample );
/** Called when all the samples should be (re)loaded from the beginning. */
virtual void
onLoadAllSamples( void );
virtual void
onChangeSampleRange( Sample *sample );
private:
SampleManager *m_manager;
};
} }
#endif | 29.793478 | 86 | 0.74243 |
b0b3e144a2a1be4156bd49a3de7fe826b16282cd | 1,483 | c | C | data/ddi/Gods98/Gods98/src/Materials.c | trigger-segfault/legorockraiders-analysis | 38a3dd5dd35c141f1acbdbe320e11adc1f3e9660 | [
"MIT"
] | 9 | 2021-09-03T23:52:55.000Z | 2022-03-19T01:05:40.000Z | data/ddi/Gods98/Gods98/src/Materials.c | trigger-segfault/legorockraiders-analysis | 38a3dd5dd35c141f1acbdbe320e11adc1f3e9660 | [
"MIT"
] | null | null | null | data/ddi/Gods98/Gods98/src/Materials.c | trigger-segfault/legorockraiders-analysis | 38a3dd5dd35c141f1acbdbe320e11adc1f3e9660 | [
"MIT"
] | null | null | null |
#include <d3drm.h>
#include "..\Inc\Standard.h"
#include "..\Inc\Errors.h"
#include "..\Inc\Main.h"
#include "..\Inc\Materials.h"
lpMaterial Material_Create(REAL emissiveRed, REAL emissiveGreen, REAL emissiveBlue, REAL specularRed, REAL specularGreen, REAL specularBlue, REAL power){
LPDIRECT3DRMMATERIAL2 mat;
if (D3DRM_OK == lpD3DRM()->lpVtbl->CreateMaterial(lpD3DRM(), power, &mat)){
mat->lpVtbl->SetEmissive(mat, emissiveRed, emissiveGreen, emissiveBlue);
mat->lpVtbl->SetSpecular(mat, specularRed, specularGreen, specularBlue);
return (lpMaterial) mat;
}
return NULL;
}
VOID Material_Remove(lpMaterial material){
LPDIRECT3DRMMATERIAL mat = (LPDIRECT3DRMMATERIAL) material;
Error_Fatal(!mat, "Null passed as material to Material_Remove()");
mat->lpVtbl->Release(mat);
}
VOID Material_SetEmissive(lpMaterial material, REAL emissiveRed, REAL emissiveGreen, REAL emissiveBlue){
LPDIRECT3DRMMATERIAL mat = (LPDIRECT3DRMMATERIAL) material;
Error_Fatal(!mat, "Null passed as material to Material_SetEmissive()");
mat->lpVtbl->SetEmissive(mat, emissiveRed, emissiveGreen, emissiveBlue);
}
VOID Material_SetSpecular(lpMaterial material, REAL specularRed, REAL specularGreen, REAL specularBlue, REAL power){
LPDIRECT3DRMMATERIAL mat = (LPDIRECT3DRMMATERIAL) material;
Error_Fatal(!mat, "Null passed as material to Material_SetSpecular()");
mat->lpVtbl->SetPower(mat, power);
mat->lpVtbl->SetSpecular(mat, specularRed, specularGreen, specularBlue);
}
| 30.265306 | 153 | 0.769386 |
50152a0d22bdee758e9d95b5c5551ad8060d2427 | 2,081 | h | C | src/ScoreBuffer.h | monsanto-pinheiro/ngmlr | 8d7677929001d1d13c6b4593c409a52044180dca | [
"MIT"
] | 239 | 2017-01-18T15:14:34.000Z | 2022-03-09T10:44:08.000Z | src/ScoreBuffer.h | monsanto-pinheiro/ngmlr | 8d7677929001d1d13c6b4593c409a52044180dca | [
"MIT"
] | 96 | 2017-01-13T15:03:29.000Z | 2022-02-07T14:27:18.000Z | src/ScoreBuffer.h | monsanto-pinheiro/ngmlr | 8d7677929001d1d13c6b4593c409a52044180dca | [
"MIT"
] | 44 | 2017-03-17T20:31:08.000Z | 2021-12-02T07:27:09.000Z | /**
* Contact: philipp.rescheneder@gmail.com
*/
#ifndef SWWOBUFFER_H_
#define SWWOBUFFER_H_
#include <list>
#include "IAlignment.h"
#include "NGM.h"
#include "AlignmentBuffer.h"
#undef module_name
#define module_name "FILTER"
class ScoreBuffer {
public:
private:
struct Score {
MappedRead * read;
int scoreId;
};
private:
void topNSE(MappedRead* read);
void DoRun();
void computeMQ(MappedRead* read);
int computeMQ(float bestScore, float secondBestScore);
void debugScoresFinished(MappedRead * read);
ReadGroup* updateGroupInfo(MappedRead* cur_read);
const char** m_QryBuffer;
const char** m_RefBuffer;
float* m_ScoreBuffer;
int qryMaxLen;
uloc refMaxLen;
int corridor;
Score * scores;
int iScores;
IAlignment * aligner;
AlignmentBuffer * out;
const int swBatchSize;
float scoreTime;
public:
ScoreBuffer(IAlignment * mAligner, AlignmentBuffer * mOut) :
aligner(mAligner), out(mOut), swBatchSize(aligner->GetScoreBatchSize()) {
m_QryBuffer = 0;
m_RefBuffer = 0;
m_ScoreBuffer = 0;
corridor = Config.getReadPartCorridor();
m_QryBuffer = new char const *[swBatchSize];
m_RefBuffer = new char const *[swBatchSize];
m_ScoreBuffer = new float[swBatchSize];
qryMaxLen = Config.getReadPartLength() + 10;
refMaxLen = ((qryMaxLen + corridor) | 1) + 1;
for (int i = 0; i < swBatchSize; ++i) {
m_RefBuffer[i] = new char[refMaxLen];
}
scores = new Score[swBatchSize];
iScores = 0;
scoreTime = 0.0f;
}
~ScoreBuffer() {
delete[] scores;
scores = 0;
delete[] m_ScoreBuffer;
m_ScoreBuffer = 0;
for (int i = 0; i < swBatchSize; ++i) {
delete[] m_RefBuffer[i];
m_RefBuffer[i] = 0;
}
delete[] m_RefBuffer;
m_RefBuffer = 0;
delete[] m_QryBuffer;
m_QryBuffer = 0;
}
void addRead(MappedRead * read, int count);
void scoreShortRead(MappedRead * read);
void flush();
float getTime() {
float tmp = scoreTime;
// scoreTime = 0.0f;
return tmp;
}
inline int GetStage() const {
return 2;
}
inline const char* GetName() const {return "SW";}
};
#endif /* SWWOBUFFER_H_ */
| 17.198347 | 76 | 0.686689 |
1c3084daaf127a34c4f8e5664fd417ccaa24e4d3 | 4,912 | h | C | xlat/adjtimex_status.h | android-rv/external_strace | 7720b932250bd7def49c439c235f4175c30b8e51 | [
"BSD-3-Clause"
] | 22 | 2018-10-05T07:19:06.000Z | 2022-02-24T07:12:55.000Z | xlat/adjtimex_status.h | android-rv/external_strace | 7720b932250bd7def49c439c235f4175c30b8e51 | [
"BSD-3-Clause"
] | 1 | 2020-11-10T11:06:08.000Z | 2020-11-10T11:06:08.000Z | xlat/adjtimex_status.h | android-rv/external_strace | 7720b932250bd7def49c439c235f4175c30b8e51 | [
"BSD-3-Clause"
] | 10 | 2018-10-05T07:19:06.000Z | 2022-03-23T14:24:53.000Z | /* Generated by ./xlat/gen.sh from ./xlat/adjtimex_status.in; do not edit. */
#include "gcc_compat.h"
#include "static_assert.h"
#if defined(STA_PLL) || (defined(HAVE_DECL_STA_PLL) && HAVE_DECL_STA_PLL)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PLL) == (0x0001), "STA_PLL != 0x0001");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PLL 0x0001
#endif
#if defined(STA_PPSFREQ) || (defined(HAVE_DECL_STA_PPSFREQ) && HAVE_DECL_STA_PPSFREQ)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSFREQ) == (0x0002), "STA_PPSFREQ != 0x0002");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSFREQ 0x0002
#endif
#if defined(STA_PPSTIME) || (defined(HAVE_DECL_STA_PPSTIME) && HAVE_DECL_STA_PPSTIME)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSTIME) == (0x0004), "STA_PPSTIME != 0x0004");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSTIME 0x0004
#endif
#if defined(STA_FLL) || (defined(HAVE_DECL_STA_FLL) && HAVE_DECL_STA_FLL)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_FLL) == (0x0008), "STA_FLL != 0x0008");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_FLL 0x0008
#endif
#if defined(STA_INS) || (defined(HAVE_DECL_STA_INS) && HAVE_DECL_STA_INS)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_INS) == (0x0010), "STA_INS != 0x0010");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_INS 0x0010
#endif
#if defined(STA_DEL) || (defined(HAVE_DECL_STA_DEL) && HAVE_DECL_STA_DEL)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_DEL) == (0x0020), "STA_DEL != 0x0020");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_DEL 0x0020
#endif
#if defined(STA_UNSYNC) || (defined(HAVE_DECL_STA_UNSYNC) && HAVE_DECL_STA_UNSYNC)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_UNSYNC) == (0x0040), "STA_UNSYNC != 0x0040");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_UNSYNC 0x0040
#endif
#if defined(STA_FREQHOLD) || (defined(HAVE_DECL_STA_FREQHOLD) && HAVE_DECL_STA_FREQHOLD)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_FREQHOLD) == (0x0080), "STA_FREQHOLD != 0x0080");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_FREQHOLD 0x0080
#endif
#if defined(STA_PPSSIGNAL) || (defined(HAVE_DECL_STA_PPSSIGNAL) && HAVE_DECL_STA_PPSSIGNAL)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSSIGNAL) == (0x0100), "STA_PPSSIGNAL != 0x0100");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSSIGNAL 0x0100
#endif
#if defined(STA_PPSJITTER) || (defined(HAVE_DECL_STA_PPSJITTER) && HAVE_DECL_STA_PPSJITTER)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSJITTER) == (0x0200), "STA_PPSJITTER != 0x0200");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSJITTER 0x0200
#endif
#if defined(STA_PPSWANDER) || (defined(HAVE_DECL_STA_PPSWANDER) && HAVE_DECL_STA_PPSWANDER)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSWANDER) == (0x0400), "STA_PPSWANDER != 0x0400");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSWANDER 0x0400
#endif
#if defined(STA_PPSERROR) || (defined(HAVE_DECL_STA_PPSERROR) && HAVE_DECL_STA_PPSERROR)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_PPSERROR) == (0x0800), "STA_PPSERROR != 0x0800");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_PPSERROR 0x0800
#endif
#if defined(STA_CLOCKERR) || (defined(HAVE_DECL_STA_CLOCKERR) && HAVE_DECL_STA_CLOCKERR)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_CLOCKERR) == (0x1000), "STA_CLOCKERR != 0x1000");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_CLOCKERR 0x1000
#endif
#if defined(STA_NANO) || (defined(HAVE_DECL_STA_NANO) && HAVE_DECL_STA_NANO)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_NANO) == (0x2000), "STA_NANO != 0x2000");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_NANO 0x2000
#endif
#if defined(STA_MODE) || (defined(HAVE_DECL_STA_MODE) && HAVE_DECL_STA_MODE)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_MODE) == (0x4000), "STA_MODE != 0x4000");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_MODE 0x4000
#endif
#if defined(STA_CLK) || (defined(HAVE_DECL_STA_CLK) && HAVE_DECL_STA_CLK)
DIAG_PUSH_IGNORE_TAUTOLOGICAL_COMPARE
static_assert((STA_CLK) == (0x8000), "STA_CLK != 0x8000");
DIAG_POP_IGNORE_TAUTOLOGICAL_COMPARE
#else
# define STA_CLK 0x8000
#endif
#ifndef XLAT_MACROS_ONLY
# ifdef IN_MPERS
extern const struct xlat adjtimex_status[];
# else
# if !(defined HAVE_M32_MPERS || defined HAVE_MX32_MPERS)
static
# endif
const struct xlat adjtimex_status[] = {
XLAT(STA_PLL),
XLAT(STA_PPSFREQ),
XLAT(STA_PPSTIME),
XLAT(STA_FLL),
XLAT(STA_INS),
XLAT(STA_DEL),
XLAT(STA_UNSYNC),
XLAT(STA_FREQHOLD),
XLAT(STA_PPSSIGNAL),
XLAT(STA_PPSJITTER),
XLAT(STA_PPSWANDER),
XLAT(STA_PPSERROR),
XLAT(STA_CLOCKERR),
XLAT(STA_NANO),
XLAT(STA_MODE),
XLAT(STA_CLK),
XLAT_END
};
# endif /* !IN_MPERS */
#endif /* !XLAT_MACROS_ONLY */
| 32.104575 | 91 | 0.803339 |
1c5eaa54aaba34bf691f07d8c869b8fa4ccfdd19 | 884 | h | C | src/PriceChildren.h | genlab03pog2/GEN_Labo05_Catel_Mirko_Muller | 53d72ace027d9fa420482e2694894b07989d27c2 | [
"MIT"
] | null | null | null | src/PriceChildren.h | genlab03pog2/GEN_Labo05_Catel_Mirko_Muller | 53d72ace027d9fa420482e2694894b07989d27c2 | [
"MIT"
] | null | null | null | src/PriceChildren.h | genlab03pog2/GEN_Labo05_Catel_Mirko_Muller | 53d72ace027d9fa420482e2694894b07989d27c2 | [
"MIT"
] | null | null | null | #ifndef GEN_LABO05_CATEL_MIRKO_MULLER_PRICECHILDREN_H
#define GEN_LABO05_CATEL_MIRKO_MULLER_PRICECHILDREN_H
#include "Price.h"
class PriceChildren : public Price {
private:
const double PRICE_PER_DAY = 1.5;
const double DAYS_STEP = 3;
const double MIN_AMOUNT = 1.5;
public:
double getAmount(int _daysRented) const;
std::string getPriceType() const;
int getFrequentRenterPoints(int _daysRented) const;
};
inline double PriceChildren::getAmount(int _daysRented) const {
double thisAmount = MIN_AMOUNT;
if (_daysRented > DAYS_STEP )
thisAmount += (_daysRented - DAYS_STEP ) * PRICE_PER_DAY;
return thisAmount;
}
inline std::string PriceChildren::getPriceType() const {
return "children";
}
inline int PriceChildren::getFrequentRenterPoints(int _daysRented) const {
return MIN_RENTER_POINT;
}
#endif //GEN_LABO05_CATEL_MIRKO_MULLER_PRICECHILDREN_H
| 25.257143 | 74 | 0.777149 |
7cb3afdb179bd9b89c4140733dba761277ee8783 | 954 | h | C | det/det.h | intdxdt/clibs | dfa43e038924db26abd1d4dfa617f68d5fa179c8 | [
"MIT"
] | null | null | null | det/det.h | intdxdt/clibs | dfa43e038924db26abd1d4dfa617f68d5fa179c8 | [
"MIT"
] | null | null | null | det/det.h | intdxdt/clibs | dfa43e038924db26abd1d4dfa617f68d5fa179c8 | [
"MIT"
] | null | null | null | //
//05/06/18.
//
#include <vector>
#include "../compress/compress.h"
#include "../twoproduct/two_product.h"
#include "../scale/scale.h"
#include "../sum/sum.h"
#ifndef DET_DET_H
#define DET_DET_H
namespace robust {
std::vector<double> det2(const std::vector<std::vector<double>>& m) {
return compress(sum(two_product(m[0][0], m[1][1]), two_product(-m[0][1], m[1][0])));
}
std::vector<double> det3(const std::vector<std::vector<double>>& m) {
return compress(
sum(
scale(sum(two_product(m[1][1], m[2][2]), two_product(-m[1][2], m[2][1])), m[0][0]),
sum(
scale(sum(two_product(m[1][0], m[2][2]), two_product(-m[1][2], m[2][0])), -m[0][1]),
scale(sum(two_product(m[1][0], m[2][1]), two_product(-m[1][1], m[2][0])), m[0][2])
)
));
}
}
#endif //DET_DET_H
| 31.8 | 116 | 0.489518 |
0c52f45b0d7cd54b116454d15336ea12a3b591d7 | 530 | h | C | Source/RemoteControlLibrary/Classes/RemoteControlLibrary.h | sovietspaceship/UE4RemoteControlLibrary | 2f440f1cedb1ce8e0aa104499edf270f2dd791be | [
"MIT"
] | 6 | 2020-06-25T16:51:27.000Z | 2021-12-11T12:18:22.000Z | Source/RemoteControlLibrary/Classes/RemoteControlLibrary.h | sovietspaceship/UE4RemoteControlLibrary | 2f440f1cedb1ce8e0aa104499edf270f2dd791be | [
"MIT"
] | 1 | 2021-02-23T16:30:53.000Z | 2021-02-26T17:39:36.000Z | Source/RemoteControlLibrary/Classes/RemoteControlLibrary.h | sovietspaceship/UE4RemoteControlLibrary | 2f440f1cedb1ce8e0aa104499edf270f2dd791be | [
"MIT"
] | null | null | null | #pragma once
#include <Kismet/BlueprintFunctionLibrary.h>
#include "RemoteControlLibrary.generated.h"
UCLASS(BlueprintType)
class URemoteControlLibrary : public UBlueprintFunctionLibrary {
GENERATED_BODY()
public:
// IMPORTANT NOTE: All methods must be BlueprintCallable and public to be callabie via remote control
UFUNCTION(BlueprintCallable)
static bool IsRunning();
UFUNCTION(BlueprintCallable)
static bool StartPIE();
UFUNCTION(BlueprintCallable)
static FString GetCurrentLevel();
};
| 21.2 | 105 | 0.767925 |
0cb521a976de7abd90553f9a4fa153242f8ec88d | 15,348 | c | C | src/fonts/tools/convfnt.c | symfund/microwindows | f267e5c368c5e5a49ac6b3907af9527b06a1c67f | [
"X11"
] | 1 | 2020-12-19T13:47:11.000Z | 2020-12-19T13:47:11.000Z | src/fonts/tools/convfnt.c | symfund/microwindows | f267e5c368c5e5a49ac6b3907af9527b06a1c67f | [
"X11"
] | null | null | null | src/fonts/tools/convfnt.c | symfund/microwindows | f267e5c368c5e5a49ac6b3907af9527b06a1c67f | [
"X11"
] | null | null | null | /*
* Copyright (c) 1999 Greg Haerr <greg@censoft.com>
*
* Modified by Tom Walton at Altia, Jan. 2002. to:
* 1. Handle fonts with widths up to 80 pixels.
* 2. Support passing command line arguments for the
* font name, pixel height, average pixel width (optional),
* bold (optional), and italic (optional). If the font
* name has spaces, enclose it in double-quotes ("myfont").
* 3. Use the average width in the output file name
* instead of the maximum width. And, the max width is
* computed dynamically as characters are converted. This
* max width is the value assigned to the data structure's
* maxwidth element.
* 4. The window created for converting fonts remains open and
* displays information about what is being converted,
* what the output file name is, and when the conversion
* is done. The window is closed like any regular Windows
* application after it reports that the conversion is done.
*
* MS Windows Font Grabber for Micro-Windows
*
* Usage: convfnt32 [1|2|3|4]
* convfnt32 "fontname" [pixel_height [pixel_width] [bold] [italic]]
* Example: convfnt32 "my font" 25 12
*
* Note: a Microsoft License is required to use MS Fonts
*/
#define FONT_NORMAL 0
#define FONT_BOLD 1
#define FONT_ITALIC 2
#define FONT_BOLDITALIC (FONT_BOLD | FONT_ITALIC)
static char *Font_Name = "MS Sans Serif";
static int Font_Height = 20;
static int Font_Width = 0;
static int Font_Style = FONT_NORMAL;
static char *Font_Style_String = "normal";
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_BITS_HEIGHT 48 /* max character height*/
#define MAX_BITS_WIDTH 80 /* max character width*/
typedef unsigned short IMAGEBITS; /* bitmap image unit size*/
/* IMAGEBITS macros*/
#define IMAGE_SIZE(width, height) ((height) * (((width) + sizeof(IMAGEBITS) * 8 - 1) / (sizeof(IMAGEBITS) * 8)))
#define IMAGE_WORDS(x) (((x)+15)/16)
#define IMAGE_BITSPERIMAGE (sizeof(IMAGEBITS) * 8)
#define IMAGE_FIRSTBIT ((IMAGEBITS) 0x8000)
#define IMAGE_NEXTBIT(m) ((IMAGEBITS) ((m) >> 1))
#define IMAGE_TESTBIT(m) ((m) & IMAGE_FIRSTBIT) /* use with shiftbit*/
#define IMAGE_SHIFTBIT(m) ((IMAGEBITS) ((m) << 1)) /* for testbit*/
/* global data*/
HINSTANCE ghInstance;
char APPWINCLASS[] = "convfnt";
int MAX_WIDTH = 0;
int AVE_WIDTH;
int CHAR_HEIGHT;
int CHAR_ASCENT;
char fontname[64];
FILE * fp;
HFONT hfont;
int FIRST_CHAR = ' ';
int LAST_CHAR = 256;
long curoff = 0;
long offsets[256];
int widths[256];
int haveArgs = 0;
/* forward decls*/
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wp,LPARAM lp);
HWND InitApp(void);
int InitClasses(void);
void doit(HDC hdc);
void convfnt(HDC hdc);
void print_char(int ch,IMAGEBITS *b, int w, int h);
void print_bits(IMAGEBITS *bits, int width, int height);
HFONT WINAPI GetFont(HDC hDC, LPSTR name, int height, int width, int style);
HFONT WINAPI GetFontEx(HDC hDC, LPSTR name, int height, int width, int style,
int charset);
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nShowCmd)
{
MSG msg;
HDC hdc;
int i;
char *argv[10];
int argc;
char cmdLine[1024];
char *cmdLinePtr;
ghInstance = hInstance;
InitClasses();
InitApp();
strncpy(cmdLine, lpCmdLine, 1024);
cmdLine[1023] = '\0';
i = atoi(cmdLine);
hdc = GetDC(NULL);
switch(i) {
case 0:
if(*cmdLine == 0)
{
haveArgs = 0;
strcpy(cmdLine, "\"MS Sans Serif\"");
}
else
haveArgs = 1;
argc = 0;
cmdLinePtr = cmdLine;
do
{
while (*cmdLinePtr != '\0'
&& (*cmdLinePtr == ' ' || *cmdLinePtr == '\t'))
cmdLinePtr++;
if (*cmdLinePtr != '\0')
{
if(*cmdLinePtr == '"' || *cmdLinePtr == '\'')
{
cmdLinePtr++;
argv[argc] = cmdLinePtr;
argc++;
while (*cmdLinePtr != '\0' && *cmdLinePtr != '"'
&& *cmdLinePtr != '\t')
cmdLinePtr++;
if (*cmdLinePtr == '\0')
break;
else
*cmdLinePtr++ = '\0';
}
else
{
argv[argc] = cmdLinePtr;
argc++;
while (*cmdLinePtr != '\0' && *cmdLinePtr != ' '
&& *cmdLinePtr != '\t')
cmdLinePtr++;
if (*cmdLinePtr == '\0')
break;
else
*cmdLinePtr++ = '\0';
}
}
} while (argc < 10 && *cmdLinePtr != '\0');
if (argc == 0)
haveArgs = 0;
if (argc >= 1)
Font_Name = argv[0];
if (argc >= 2)
Font_Height = atoi(argv[1]);
if (argc >= 3 && *(argv[2]) >= '0' && *(argv[2]) <= '9')
Font_Width = atoi(argv[2]);
if (Font_Width < 0)
Font_Width = 0;
for (i = 2; i < argc; i++)
{
if (stricmp(argv[i], "italic") == 0)
Font_Style |= FONT_ITALIC;
else if (stricmp(argv[i], "bold") == 0)
Font_Style |= FONT_BOLD;
}
switch(Font_Style)
{
case FONT_BOLD:
Font_Style_String = "bold";
break;
case FONT_ITALIC:
Font_Style_String = "italic";
break;
case FONT_BOLD | FONT_ITALIC:
Font_Style_String = "bold italic";
break;
}
hfont = GetFont(hdc, Font_Name, -Font_Height,
Font_Width, Font_Style);
break;
case 1:
hfont = GetStockObject(DEFAULT_GUI_FONT); /* winMSSansSerif11x13 */
break;
case 2:
hfont = GetStockObject(SYSTEM_FONT); /* winSystem14x16 */
break;
case 3:
hfont = GetStockObject(OEM_FIXED_FONT); /* winTerminal8x12 */
break;
case 4:
hfont = GetStockObject(ANSI_VAR_FONT); /* winMSSansSerif11x13 */
break;
}
ReleaseDC(NULL, hdc);
while(GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
int
InitClasses(void)
{
WNDCLASS wc;
wc.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = ghInstance;
wc.hIcon = LoadIcon(ghInstance, MAKEINTRESOURCE( 1));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPWINCLASS;
return RegisterClass( &wc);
}
HWND
InitApp(void)
{
HWND hwnd;
hwnd = CreateWindowEx( 0L, APPWINCLASS,
"Font Grabber",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL,
NULL,
ghInstance,
NULL);
if( hwnd == NULL)
return( 0);
ShowWindow( hwnd, SW_SHOW);
return hwnd;
}
LRESULT CALLBACK
WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
PAINTSTRUCT ps;
HDC hdc;
LOGFONT lf;
TEXTMETRIC tm;
char outfile[64];
char *p, *q;
switch( msg) {
case WM_CREATE:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SelectObject(hdc, hfont);
GetObject(hfont, sizeof(lf), &lf);
GetTextMetrics(hdc, &tm);
MAX_WIDTH = 0; /* was tm.tmMaxCharWidth, now we compute it */
AVE_WIDTH = tm.tmAveCharWidth;
CHAR_HEIGHT = tm.tmHeight;
CHAR_ASCENT = tm.tmAscent;
FIRST_CHAR = tm.tmFirstChar;
LAST_CHAR = tm.tmLastChar + 1;
strcpy(fontname, lf.lfFaceName);
q = p = fontname;
while(*p) {
if(*p != ' ')
*q++ = *p;
++p;
}
*q = 0;
if (haveArgs)
{
char sample[1024];
sprintf(sample, "Converting font \"%s\", Height %d, Width %d, Style \"%s\" ", Font_Name, Font_Height, Font_Width, Font_Style_String);
TextOut(hdc, 0, 150, sample, strlen(sample));
wsprintf(outfile, "win%s%dx%d.c", fontname,
AVE_WIDTH, CHAR_HEIGHT);
sprintf(sample,
"To file \"%s\" (%dx%d is Width x Height)",
outfile, AVE_WIDTH, CHAR_HEIGHT);
TextOut(hdc, 0, 200, sample, strlen(sample));
fp = fopen(outfile, "wt");
doit(hdc);
fclose(fp);
TextOut(hdc, 0, 250, " DONE! ", 7);
}
else
{
char *usage = "Usage: convfnt.exe \"fontname\" [ pixel_height [pixel_width] [bold] [italic] ] ";
TextOut(hdc, 0, 0, usage, strlen(usage));
usage = "Example: convfnt.exe \"my font\" 25 12 bold italic ";
TextOut(hdc, 0, 30, usage, strlen(usage));
}
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONDOWN:
break;
default:
return DefWindowProc( hwnd, msg, wp, lp);
}
return( 0);
}
void
convfnt(HDC hdc)
{
SIZE size;
unsigned char ch;
int i;
int x, y, w;
int word_width;
IMAGEBITS mask_value;
IMAGEBITS *image_ptr;
IMAGEBITS c;
IMAGEBITS image[MAX_BITS_HEIGHT * IMAGE_WORDS(MAX_BITS_WIDTH)];
static IMAGEBITS mask[IMAGE_BITSPERIMAGE * IMAGE_WORDS(MAX_BITS_WIDTH)] = {
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001,
0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100,
0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001
};
for(i = FIRST_CHAR; i < LAST_CHAR; ++i)
{
ch = i;
TextOut(hdc, 0, 0, &ch, 1);
GetTextExtentPoint32(hdc, &ch, 1, &size);
if (size.cx > MAX_BITS_WIDTH)
{
offsets[ch] = curoff;
widths[ch] = 0;
}
else if (size.cx > MAX_WIDTH)
MAX_WIDTH = size.cx;
word_width = IMAGE_WORDS(size.cx);
for(y = 0; y < size.cy; ++y)
{
for (w = 0; w < word_width; w++)
{
image_ptr = &(image[(y * word_width) + w]);
*image_ptr = 0;
for(x=IMAGE_BITSPERIMAGE * w;
x < (int)((IMAGE_BITSPERIMAGE * w) + 16) && x < size.cx;
++x)
{
c = GetPixel(hdc, x, y)? 0: 1;
mask_value = mask[x];
*image_ptr = (*image_ptr & ~mask_value)
| (c << (15 - (x % 16)));
}
}
}
offsets[ch] = curoff;
widths[ch] = size.cx;
print_char(ch, image, size.cx, size.cy);
print_bits(image, size.cx, size.cy);
curoff += (size.cy * word_width);
fprintf(fp, "\n");
}
}
void
doit(HDC hdc)
{
int i;
fprintf(fp, "/* Generated by convfnt.exe*/\n");
fprintf(fp, "#include \"device.h\"\n\n");
fprintf(fp, "/* Windows %s %dx%d Font */\n",
fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "/* Originated from: \"%s\", Height %d, Width %d, Style \"%s\" */\n\n",
Font_Name, Font_Height, Font_Width, Font_Style_String);
fprintf(fp, "static MWIMAGEBITS win%s%dx%d_bits[] = {\n\n",
fontname, AVE_WIDTH, CHAR_HEIGHT);
convfnt(hdc);
fprintf(fp, "};\n\n");
fprintf(fp, "/* Character->glyph data. */\n");
fprintf(fp, "static uint32_t win%s%dx%d_offset[] = {\n",
fontname, AVE_WIDTH, CHAR_HEIGHT);
for(i=FIRST_CHAR; i<LAST_CHAR; ++i)
fprintf(fp, " %d,\t /* %c (0x%02x) */\n", offsets[i], i<' '? ' ':i , i);
fprintf(fp, "};\n\n");
fprintf(fp, "/* Character width data. */\n");
fprintf(fp, "static unsigned char win%s%dx%d_width[] = {\n",
fontname, AVE_WIDTH, CHAR_HEIGHT);
for(i=FIRST_CHAR; i<LAST_CHAR; ++i)
fprintf(fp, " %d,\t /* %c (0x%02x) */\n", widths[i], i<' '? ' ':i , i);
fprintf(fp, "};\n\n");
fprintf(fp, "/* Exported structure definition. */\n"
"MWCFONT font_win%s%dx%d = {\n",
fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "\t\"win%s%dx%d\",\n", fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "\t%d,\n", MAX_WIDTH);
fprintf(fp, "\t%d,\n", CHAR_HEIGHT);
fprintf(fp, "\t%d,\n", CHAR_ASCENT);
fprintf(fp, "\t%d,\n\t%d,\n", FIRST_CHAR, LAST_CHAR-FIRST_CHAR);
fprintf(fp, "\twin%s%dx%d_bits,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "\twin%s%dx%d_offset,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "\twin%s%dx%d_width,\n", fontname, AVE_WIDTH, CHAR_HEIGHT);
fprintf(fp, "};\n");
}
/* Character ! (0x21):
ht=16, width=8
+----------------+
| |
| |
| * |
| * |
| * |
| * |
| * |
| * |
| |
| * |
| |
| |
+----------------+ */
void
print_char(int ch,IMAGEBITS *bits, int width, int height)
{
int x, word_width;
int bitcount; /* number of bits left in bitmap word */
IMAGEBITS bitvalue; /* bitmap word value */
fprintf(fp, "/* Character %c (0x%02x):\n", (ch < ' '? ' ': ch), ch);
fprintf(fp, " ht=%d, width=%d\n", height, width);
fprintf(fp, " +");
for(x = 0; x < width; ++x)
fprintf(fp, "-");
fprintf(fp, "+\n");
x = 0;
bitcount = 0;
word_width = IMAGE_WORDS(width);
while (height > 0)
{
if (bitcount <= 0)
{
fprintf(fp, " |");
bitcount = IMAGE_BITSPERIMAGE * word_width;
bitvalue = *bits++;
}
if (IMAGE_TESTBIT(bitvalue))
fprintf(fp, "*");
else
fprintf(fp, " ");
bitvalue = IMAGE_SHIFTBIT(bitvalue);
--bitcount;
if (bitcount > 0 && (bitcount % IMAGE_BITSPERIMAGE) == 0)
bitvalue = *bits++;
if (x++ == width-1)
{
x = 0;
--height;
bitcount = 0;
fprintf(fp, "|\n");
}
}
fprintf(fp, " +");
for(x=0; x<width; ++x)
fprintf(fp, "-");
fprintf(fp, "+ */\n");
}
#define IMAGE_GETBIT4(m) (((m) & 0xf000) >> 12)
#define IMAGE_SHIFTBIT4(m) ((IMAGEBITS) ((m) << 4))
void
print_bits(IMAGEBITS *bits, int width, int height)
{
int x, word_width;
int bitcount; /* number of bits left in bitmap word */
IMAGEBITS bitvalue; /* bitmap word value */
x = 0;
bitcount = 0;
word_width = IMAGE_WORDS(width);
while (height > 0)
{
if (bitcount <= 0)
{
fprintf(fp, "0x");
bitcount = IMAGE_BITSPERIMAGE * word_width;
bitvalue = *bits++;
}
fprintf(fp, "%x", IMAGE_GETBIT4(bitvalue));
bitvalue = IMAGE_SHIFTBIT4(bitvalue);
bitcount -= 4;
if (bitcount > 0 && (bitcount % IMAGE_BITSPERIMAGE) == 0)
{
fprintf(fp, ",0x");
bitvalue = *bits++;
}
x += 4;
if (x >= width)
{
if(IMAGE_BITSPERIMAGE > (width % IMAGE_BITSPERIMAGE)
&& (width % IMAGE_BITSPERIMAGE) != 0)
for(x = IMAGE_BITSPERIMAGE - (width % IMAGE_BITSPERIMAGE);
x > 3; x -= 4)
{
fprintf(fp, "0");
}
x = 0;
--height;
bitcount = 0;
fprintf(fp, ",\n");
}
}
}
/*
* WIN Draw Library
*
* GetFont style bits:
* 01 bold
* 02 italic
* fontSize > 0 points (must pass hDC for non-screen font)
* fontSize < 0 pixels (no HDC needed)
*/
HFONT WINAPI
GetFont(HDC hDC, LPSTR fontName,int fontSize,int fontWidth,int fontStyle)
{
return GetFontEx(hDC, fontName, fontSize, fontWidth,
fontStyle, ANSI_CHARSET);
}
HFONT WINAPI
GetFontEx(HDC hDC, LPSTR fontName,int fontSize,int fontWidth,
int fontStyle,int charset)
{
LOGFONT lf;
HDC hdc;
memset( &lf, 0, sizeof(LOGFONT));
if( fontSize < 0 || hDC)
hdc = hDC;
else hdc = GetDC( GetDesktopWindow());
/* calculate font size from passed point size*/
if( fontSize < 0)
lf.lfHeight = -fontSize;
else lf.lfHeight = -MulDiv( fontSize,
GetDeviceCaps( hdc, LOGPIXELSY), 72);
if( fontName)
strncpy( lf.lfFaceName, fontName, LF_FACESIZE);
else lf.lfFaceName[ 0] = '\0';
lf.lfWeight = (fontStyle & 01)? FW_BOLD: FW_NORMAL;
if( fontStyle & 02)
lf.lfItalic = 1;
lf.lfCharSet = charset;
lf.lfWidth = fontWidth;
if( fontSize > 0 && !hDC)
ReleaseDC( GetDesktopWindow(), hdc);
return CreateFontIndirect( &lf);
}
| 25.537438 | 136 | 0.608939 |
40e9d50fb2d5f6bff2ea05f354bc0542cdc22a94 | 5,193 | c | C | middleware/linkkit/sdk-c/src/sdk-impl/sdk-impl.c | jinlongliu/AliOS-Things | ce051172a775f987183e7aca88bb6f3b809ea7b0 | [
"Apache-2.0"
] | 4 | 2019-03-12T11:04:48.000Z | 2019-10-22T06:06:53.000Z | middleware/linkkit/sdk-c/src/sdk-impl/sdk-impl.c | IamBaoMouMou/AliOS-Things | 195a9160b871b3d78de6f8cf6c2ab09a71977527 | [
"Apache-2.0"
] | 3 | 2018-12-17T13:06:46.000Z | 2018-12-28T01:40:59.000Z | middleware/linkkit/sdk-c/src/sdk-impl/sdk-impl.c | IamBaoMouMou/AliOS-Things | 195a9160b871b3d78de6f8cf6c2ab09a71977527 | [
"Apache-2.0"
] | 2 | 2018-01-23T07:54:08.000Z | 2018-01-23T11:38:59.000Z | /*
* Copyright (C) 2015-2018 Alibaba Group Holding Limited
*/
#include "sdk-impl_internal.h"
#define KV_KEY_DEVICE_SECRET "DyncRegDeviceSecret"
static sdk_impl_ctx_t g_sdk_impl_ctx = {0};
sdk_impl_ctx_t *sdk_impl_get_ctx(void)
{
return &g_sdk_impl_ctx;
}
void IOT_OpenLog(const char *ident)
{
const char *mod = ident;
if (NULL == mod) {
mod = "---";
}
LITE_openlog(mod);
}
void IOT_CloseLog(void)
{
LITE_closelog();
}
void IOT_SetLogLevel(IOT_LogLevel level)
{
int lvl = (int)level;
if (lvl > LOG_DEBUG_LEVEL) {
sdk_err("Invalid input level: %d out of [%d, %d]", level,
LOG_EMERG_LEVEL,
LOG_DEBUG_LEVEL);
return;
}
LITE_set_loglevel(lvl);
}
void IOT_DumpMemoryStats(IOT_LogLevel level)
{
int lvl = (int)level;
if (lvl > LOG_DEBUG_LEVEL) {
lvl = LOG_DEBUG_LEVEL;
sdk_warning("Invalid input level, using default: %d => %d", level, lvl);
}
LITE_dump_malloc_free_stats(lvl);
}
#if defined(MQTT_COMM_ENABLED)
int IOT_SetupConnInfo(const char *product_key,
const char *device_name,
const char *device_secret,
void **info_ptr)
{
int rc = 0;
char device_secret_actual[DEVICE_SECRET_MAXLEN] = {0};
char product_secret[PRODUCT_SECRET_MAXLEN] = {0};
int device_secret_len = DEVICE_SECRET_MAXLEN;
sdk_impl_ctx_t *ctx = sdk_impl_get_ctx();
if (!info_ptr) {
sdk_err("Invalid argument, info_ptr = %p", info_ptr);
return -1;
}
STRING_PTR_SANITY_CHECK(product_key, -1);
STRING_PTR_SANITY_CHECK(device_name, -1);
/* Dynamic Register Device If Need */
if (ctx->dynamic_register == 0) {
#if !defined(SUPPORT_ITLS)
STRING_PTR_SANITY_CHECK(device_secret, -1);
memcpy(device_secret_actual, device_secret, strlen(device_secret));
#else
if (device_secret == NULL || strlen(device_secret) == 0) {
LITE_get_randstr(device_secret_actual, DEVICE_SECRET_MAXLEN - 1);
} else {
memcpy(device_secret_actual, device_secret, strlen(device_secret));
}
#endif
} else {
/* Check if Device Secret exit in KV */
if (HAL_Kv_Get(KV_KEY_DEVICE_SECRET, device_secret_actual, &device_secret_len) == 0) {
sdk_info("Get DeviceSecret from KV succeed");
*(device_secret_actual + device_secret_len) = 0;
HAL_SetDeviceSecret(device_secret_actual);
} else {
/* KV not exit, goto dynamic register */
sdk_info("DeviceSecret KV not exist, Now We Need Dynamic Register...");
/* Check If Product Secret Exist */
HAL_GetProductSecret(product_secret);
if (strlen(product_secret) == 0) {
sdk_err("Product Secret Is Not Exist");
return FAIL_RETURN;
}
STRING_PTR_SANITY_CHECK(product_secret, -1);
rc = perform_dynamic_register((char *)product_key, (char *)product_secret, (char *)device_name, device_secret_actual);
if (rc != SUCCESS_RETURN) {
sdk_err("Dynamic Register Failed");
return FAIL_RETURN;
}
device_secret_len = strlen(device_secret_actual);
if (HAL_Kv_Set(KV_KEY_DEVICE_SECRET, device_secret_actual, device_secret_len, 1) != 0) {
sdk_err("Save Device Secret to KV Failed");
return FAIL_RETURN;
}
HAL_SetDeviceSecret(device_secret_actual);
}
}
iotx_device_info_init();
iotx_device_info_set(product_key, device_name, device_secret_actual);
if (0 == iotx_guider_auth_get()) {
rc = iotx_guider_authenticate();
}
if (rc == 0) {
iotx_guider_auth_set(1);
*info_ptr = (void *)iotx_conn_info_get();
} else {
iotx_guider_auth_set(0);
*info_ptr = NULL;
}
return rc;
}
#endif /* #if defined(MQTT_COMM_ENABLED) */
int IOT_Ioctl(int option, void *data)
{
int res = SUCCESS_RETURN;
sdk_impl_ctx_t *ctx = sdk_impl_get_ctx();
if (option < 0 || data == NULL) {
sdk_err("Invalid Parameter");
return FAIL_RETURN;
}
switch (option) {
case IOTX_IOCTL_SET_DOMAIN: {
ctx->domain_type = *(int *)data;
iotx_guider_set_domain_type(*(int *)data);
res = SUCCESS_RETURN;
}
break;
case IOTX_IOCTL_GET_DOMAIN: {
*(int *)data = ctx->domain_type;
res = SUCCESS_RETURN;
}
break;
case IOTX_IOCTL_SET_DYNAMIC_REGISTER: {
ctx->dynamic_register = *(int *)data;
res = SUCCESS_RETURN;
}
break;
case IOTX_IOCTL_GET_DYNAMIC_REGISTER: {
*(int *)data = ctx->dynamic_register;
res = SUCCESS_RETURN;
}
break;
default: {
sdk_err("Unknown Ioctl Option");
res = FAIL_RETURN;
}
break;
}
return res;
}
| 27.046875 | 130 | 0.58213 |
efcd08c26486c50f17e96e7133d941aed9960e61 | 3,820 | c | C | src/timeutils.c | IRATI/tgen | 83d85a6a94c5853b8a2d01bb553d904501545437 | [
"MIT"
] | 3 | 2015-11-06T10:48:09.000Z | 2021-02-17T23:21:00.000Z | src/timeutils.c | IRATI/tgen | 83d85a6a94c5853b8a2d01bb553d904501545437 | [
"MIT"
] | 15 | 2015-02-19T12:09:21.000Z | 2017-01-13T13:06:54.000Z | src/timeutils.c | IRATI/tgen | 83d85a6a94c5853b8a2d01bb553d904501545437 | [
"MIT"
] | 11 | 2015-02-04T08:19:14.000Z | 2021-02-17T23:21:02.000Z | /*
* Utilities for math with timespecs and timevals
*
* Addy Bombeke <addy.bombeke@ugent.be>
* Dimitri Staessens <dimitri.staessens@intec.ugent.be>
* Douwe De Bock <douwe.debock@ugent.be>
* Francesco Salvestrini <f.salvestrini@nextworks.it>
*
* This source code has been released under the GEANT outward license.
* Refer to the accompanying LICENSE file for further information
*/
#include "timeutils.h"
/* functions for timespecs */
/* add intv to t and store it in res*/
void ts_add(const struct timespec *t,
const struct timespec *intv,
struct timespec *res)
{
long nanos = 0;
if (!(t && intv && res))
return;
nanos = t->tv_nsec + intv->tv_nsec;
res->tv_sec = t->tv_sec + intv->tv_sec;
while (nanos > BILLION) {
nanos -= BILLION;
++(res->tv_sec);
}
res->tv_nsec = nanos;
}
/* subtract intv from t and stores it in res */
void ts_diff(const struct timespec *t,
const struct timespec *intv,
struct timespec *res)
{
long nanos = 0;
if (!(t && intv && res))
return;
nanos = t->tv_nsec - intv->tv_nsec;
res->tv_sec = t->tv_sec - intv->tv_sec;
while (nanos < 0) {
nanos += BILLION;
--(res->tv_sec);
}
res->tv_nsec = nanos;
}
/* subtracting fields is faster than using ts_diff */
/* returns LONG_MAX on null_ptr input */
long ts_diff_ns(const struct timespec *start,
const struct timespec *end)
{
if (!(start && end))
return LONG_MAX;
return (end->tv_sec-start->tv_sec)*BILLION
+ (end->tv_nsec-start->tv_nsec);
}
/* subtracting fields is faster than using ts_diff */
long ts_diff_us(const struct timespec *start,
const struct timespec *end)
{
if (!(start && end))
return LONG_MAX;
return (end->tv_sec-start->tv_sec)*MILLION
+ (end->tv_nsec - start->tv_nsec)/1000L;
}
/* subtracting fields is faster than using ts_diff */
long ts_diff_ms(const struct timespec *start,
const struct timespec *end)
{
if (!(start && end))
return LONG_MAX;
return (end->tv_sec-start->tv_sec)*1000L
+ (end->tv_nsec-start->tv_nsec)/MILLION;
}
/* functions for timevals */
/* add intv to t and store it in res*/
void tv_add(const struct timeval *t,
const struct timeval *intv,
struct timeval *res)
{
long micros = 0;
if (!(t && intv && res))
return;
micros = t->tv_usec + intv->tv_usec;
res->tv_sec = t->tv_sec + intv->tv_sec;
while (micros > MILLION) {
micros -= MILLION;
--(res->tv_sec);
}
res->tv_usec = micros;
}
/* subtract intv from t and stores it in res */
void tv_diff(const struct timeval *t,
const struct timeval *intv,
struct timeval *res)
{
long micros = 0;
if (!(t && intv && res))
return;
micros = t->tv_usec - intv->tv_usec;
res->tv_sec = t->tv_sec - intv->tv_sec;
while (micros < 0) {
micros += MILLION;
--(res->tv_sec);
}
res->tv_usec = micros;
}
/* subtracting fields is faster than using tv_diff */
long tv_diff_us(const struct timeval *start,
const struct timeval *end)
{
if (!(start && end))
return LONG_MAX;
return (end->tv_sec-start->tv_sec)*MILLION
+ (end->tv_usec-start->tv_usec);
}
/* subtracting fields is faster than using tv_diff */
long tv_diff_ms(const struct timeval *start,
const struct timeval *end)
{
if (!(start && end))
return LONG_MAX;
return (end->tv_sec-start->tv_sec)*1000L
+ (end->tv_usec-start->tv_usec)/1000L;
}
/* FIXME: not sure about the next two functions */
/* copying a timeval into a timespec */
void tv_to_ts(const struct timeval *src,
struct timespec *dst)
{
if (!(src && dst))
return;
dst->tv_sec = src->tv_sec;
dst->tv_nsec = src->tv_usec*1000L;
}
/* copying a timespec into a timeval (loss of resolution) */
void ts_to_tv(const struct timespec *src,
struct timeval *dst)
{
if (!(src && dst))
return;
dst->tv_sec = src->tv_sec;
dst->tv_usec = src->tv_nsec/1000L;
}
| 21.581921 | 70 | 0.659686 |
d003fc68fdda416dcce429b7c4e49276d1f1cdb5 | 464 | h | C | include/ozo/ext/boost/shared_ptr.h | IlyaSidorov/ozo | cdc667b700c7ae6dcf723ef6f939a8495f40fb7e | [
"PostgreSQL"
] | null | null | null | include/ozo/ext/boost/shared_ptr.h | IlyaSidorov/ozo | cdc667b700c7ae6dcf723ef6f939a8495f40fb7e | [
"PostgreSQL"
] | null | null | null | include/ozo/ext/boost/shared_ptr.h | IlyaSidorov/ozo | cdc667b700c7ae6dcf723ef6f939a8495f40fb7e | [
"PostgreSQL"
] | null | null | null | #pragma once
#include <ozo/type_traits.h>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
namespace ozo {
template <typename T>
struct is_nullable<boost::shared_ptr<T>> : std::true_type {};
template <typename T>
struct allocate_nullable_impl<boost::shared_ptr<T>> {
template <typename Alloc>
static void apply(boost::shared_ptr<T>& out, const Alloc& a) {
out = boost::allocate_shared<T, Alloc>(a);
}
};
} // namespace ozo
| 22.095238 | 66 | 0.702586 |
f48f352d201fc38bdfeb7d943957ad692254b2e3 | 263 | h | C | 003_GuiLauncher/radio_button.h | hongwenjun/cbstudy | e87b18e3643bf932fbcc1d909bf5026e22630266 | [
"MIT"
] | 1 | 2021-04-05T07:17:51.000Z | 2021-04-05T07:17:51.000Z | 003_GuiLauncher/radio_button.h | hongwenjun/cbstudy | e87b18e3643bf932fbcc1d909bf5026e22630266 | [
"MIT"
] | null | null | null | 003_GuiLauncher/radio_button.h | hongwenjun/cbstudy | e87b18e3643bf932fbcc1d909bf5026e22630266 | [
"MIT"
] | null | null | null | #ifndef RADIO_BUTTON_H_INCLUDED
#define RADIO_BUTTON_H_INCLUDED
#include <stdio.h>
#include <windows.h>
#include "resource.h"
// 用户收音机按钮 函数 process_button
int process_button(HWND hwndDlg, WPARAM wParam);
static int rx = -1;
#endif // RADIO_BUTTON_H_INCLUDED
| 18.785714 | 48 | 0.779468 |
ad831d65b8f2f858e6f8cd030029806809e7412e | 2,281 | h | C | include/openXpsAging.h | XPliant/OpenXPS | d4e8e80da546a6e53490a71dc73e26216bb40125 | [
"Apache-2.0"
] | 11 | 2016-03-12T07:59:24.000Z | 2021-06-16T02:07:50.000Z | include/openXpsAging.h | XPliant/OpenXPS | d4e8e80da546a6e53490a71dc73e26216bb40125 | [
"Apache-2.0"
] | 2 | 2016-10-31T16:19:48.000Z | 2017-01-23T14:07:42.000Z | include/openXpsAging.h | XPliant/OpenXPS | d4e8e80da546a6e53490a71dc73e26216bb40125 | [
"Apache-2.0"
] | 12 | 2016-03-09T04:07:35.000Z | 2020-08-29T08:13:38.000Z | /************************************************************************
* Copyright (C) 2016, Cavium, Inc.
* All Rights Reserved.
*
* 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.
*
* THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
* LIMITATIONS ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS
* FOR PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
*
* See the Apache Version 2.0 License for specific language governing
* permissions and limitations under the License.
*
* FILE : openXpsAging.h
*
* Abstract: This file defines the apis for Aging Management in OpenXPS.
************************************************************************/
/**
* \file openXpsAging.h
* \brief This file contains API prototypes and type definitions
* for the openXps Aging Management
* \copyright (c) 2016 Cavium Inc
*/
#ifndef _openXpsAging_h_
#define _openXpsAging_h_
#include "openXpsTypes.h"
#include "openXpsEnums.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief This API calls the read FIFO message API to identify aged
* out entry. If it will find such entry then API will call
* process FIFO message API to call the registered handler
* and perform necessary steps on that entry
*
* \param [in] devId Device Id of device.
*
* \return XP_STATUS
*
*/
XP_STATUS xpsAgeFifoHandler(xpDevice_t devId);
/**
* \brief This API sets the Aging Mode to the global age Configuration.
*
* \param [in] devId Device Id of device.
* \param [in] ageMode Global table aging mode
*
* \return XP_STATUS
*
*/
XP_STATUS xpsSetAgingMode(xpDevice_t devId, XP_AGE_MODE_T ageMode);
/**
* \brief This API sets the Aging Cycle Unit Time into the
* global age Configuration.
*
* \param [in] devId Device Id of device.
* \param [in] unitTime Number of clock cycles
*
* \return XP_STATUS
*
*/
XP_STATUS xpsSetAgingCycleUnitTime(xpDevice_t devId, uint32_t unitTime);
#ifdef __cplusplus
}
#endif
#endif //_openXpsAging_h_
| 28.873418 | 76 | 0.668128 |
216e4ca5710a7107327bee2bb17cc89a8e753da4 | 816 | h | C | packaging/common/UtilGUILog.h | Dixiashui/TestWork | 8316f1ca65edf089edd326bbd4097e3106ac8ae0 | [
"Apache-2.0"
] | null | null | null | packaging/common/UtilGUILog.h | Dixiashui/TestWork | 8316f1ca65edf089edd326bbd4097e3106ac8ae0 | [
"Apache-2.0"
] | null | null | null | packaging/common/UtilGUILog.h | Dixiashui/TestWork | 8316f1ca65edf089edd326bbd4097e3106ac8ae0 | [
"Apache-2.0"
] | null | null | null | #ifndef _UTILGUILOG_H
#define _UTILGUILOG_H
/**
* @file UtilGUILog.h
* @brief Defines the UtilGUILog class.
*/
#include "common/Util.h"
#include "common/TwLog.h"
#include <time.h>
#include <string>
/**
* @brief UtilGUILog class.
*
*/
class UtilGUILog
{
private:
/**
* @brief UtilGUILog contructor. UtilGUILog cannot be instanced.
*/
UtilGUILog();
/**
* @brief UtilGUILog destructor. UtilGUILog cannot be deleted.
*/
~UtilGUILog();
public:
static void logDbug(const std::string &s);
static void logTrac(const std::string &s);
static void logInfo(const std::string &s);
static void logWarn(const std::string &s);
static void logErro(const std::string &s);
private:
static TwLog mTwLog; ///< Testwork LOG.
};
#endif // ifndef _UTILGUILOG_H
| 17.73913 | 68 | 0.654412 |
6e0171357cc2609d120628dc238f5f8acce171e5 | 320 | h | C | Core/ObjectiveREST/Client/ORNoCacheIncrementalStore.h | ygini/ObjectiveREST | 81c11cc3d9af96b859534531ab47aacb4f4ca2d3 | [
"Apache-2.0"
] | 3 | 2015-01-17T02:59:32.000Z | 2016-01-12T18:21:49.000Z | Core/ObjectiveREST/Client/ORNoCacheIncrementalStore.h | ygini/ObjectiveREST | 81c11cc3d9af96b859534531ab47aacb4f4ca2d3 | [
"Apache-2.0"
] | null | null | null | Core/ObjectiveREST/Client/ORNoCacheIncrementalStore.h | ygini/ObjectiveREST | 81c11cc3d9af96b859534531ab47aacb4f4ca2d3 | [
"Apache-2.0"
] | null | null | null | //
// ORNoCacheIncrementalStore.h
// OSX-ObjectiveREST
//
// Created by Yoann Gini on 07/11/12.
// Copyright (c) 2012 iNig-Services. All rights reserved.
//
#import <CoreData/CoreData.h>
#import <SocketRocketOSX/SRWebSocket.h>
@interface ORNoCacheIncrementalStore : NSIncrementalStore <SRWebSocketDelegate>
@end
| 20 | 79 | 0.753125 |
5518fdc765ea09abd89e0186dc893624159b7f5b | 14,068 | c | C | src/isc/dat2isc.c | avillasenorh/OCR-bulletins | 77cc20e80827d50707217381d9aad6ca0f16c3c3 | [
"MIT"
] | null | null | null | src/isc/dat2isc.c | avillasenorh/OCR-bulletins | 77cc20e80827d50707217381d9aad6ca0f16c3c3 | [
"MIT"
] | null | null | null | src/isc/dat2isc.c | avillasenorh/OCR-bulletins | 77cc20e80827d50707217381d9aad6ca0f16c3c3 | [
"MIT"
] | null | null | null | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*******************************************************************************
Program: dat2isc.c
Purpose: Reads text files
convert to ISC 96-byte format
Author: Antonio Villasenor, USGS, Golden
Date: 14-MAR-1999
*******************************************************************************/
/* maximum filename length */
#ifndef FILENAME_MAX
#define FILENAME_MAX 1024
#endif
#define NINT(x) (int)floor((x)+0.5)
#define INT_UNDEF -12345
#define FLT_UNDEF -12345.0
#define MAXLINE 97
#define MAXPHASES 5
#define MAXCARDS 2000
#define MAXSTA 1000
#define TRUE 1
#define FALSE 0
struct itm {
int year;
int month;
int day;
int hour;
int minute;
int second;
int millisecond;
};
struct itm iaddsec1(struct itm RefTime, int dt);
int get_hypo(char *line, int *month, int *day, int *hour, int *minute,
int *second, float *lat, float *lon, float *depth);
int get_phases(char *line, char *stnm, float *delta, float *azim,
int *Pmin, int *Psec, int *Pres, int *Ppol,
int *Smin, int *Ssec, int *Sres,
int *pPmin, int *pPsec,
int *Suppmin, int *Suppsec, char *Supp);
void asterisk(char *phase);
int trim(char s[]);
int phase_code2(char *phase);
void lookup_(float *ALAT, char *DRCLAT, float *ALNG, char *DRCLNG, int *IGREG, int *ISREG);
int main(int argc, char *argv[])
{
struct itm OriginTime, PTime, STime, pPTime, SuppTime;
struct itm PhaseTime[MAXPHASES];
FILE *fpdat, *fpisc, *fpheq, *fpsta;
char datfile[FILENAME_MAX];
char iscfile[FILENAME_MAX];
char line[MAXLINE+1];
char *card[MAXCARDS];
int icard = 0;
char *sta_name[MAXSTA];
char *sta_code[MAXSTA];
int nsta = 0;
int ist;
int yr, mo, dy;
int year, month, day, hour, minute, second;
float lat, lon, depth;
float rdepth; /* depth of focus (fraction of Earth radius) */
float a, b, c, d, e;
float g, h, k, ht;
float se; /* standard error (seconds) (RMS?) */
float mag = 0.0;
int imag = 0;
int ntel = 0;
float iscdepth;
int ndep;
int igreg, isreg;
char stnm[32];
float delta, azim;
int Pmin, Psec, Pres, Ppol;
int Smin, Ssec, Sres;
int pPmin, pPsec;
int Suppmin, Suppsec;
char Supp[16];
int dt;
/*
int rday[MAXPHASE], rhour[MAXPHASE];
int rmin[MAXPHASE], rsec[MAXPHASE];
*/
int res[MAXPHASES];
int op_id[MAXPHASES];
char phase[MAXPHASES][9];
char pol[MAXPHASES];
char ord;
int lineno, evno;
char evname[8];
char csta[5];
int irf, inrf;
int ips = 0;
int icode;
int header = FALSE; /* true while reading hypocenter header. False otherwise */
int neq = 0; /* number of events in data file */
int nobs = 0; /* number of observations (stations) in current event */
int lcomments = FALSE;
int verbose = FALSE;
int infile = FALSE;
int i;
/* Decode flag options */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
switch (argv[i][1]) {
case 'C':
lcomments = TRUE;
break;
case 'V':
verbose = TRUE;
break;
default:
break;
}
} else {
if ((fpdat = fopen(argv[i], "r")) == NULL) {
fprintf(stderr, "Error in dat2isc: ");
fprintf(stderr, "cannot open %s \n", argv[i]);
return 1;
} else {
strcpy(datfile,argv[i]);
infile = TRUE;
}
}
}
if (! infile) {
/* read from standard input */
fpdat = stdin;
} else {
if (verbose) {
fprintf(stderr, "dat2isc: ");
fprintf(stderr, "processing file %s\n", datfile);
}
}
/* initialize arrays */
for (i = 0; i < MAXCARDS; i++) {
card[i] = (char *)malloc(MAXLINE);
if (card[i] != NULL) {
card[i][0] = '\0';
} else {
fprintf(stderr, "Cannot allocate memory for card[]\n");
return 1;
}
}
for (i = 0; i < MAXSTA; i++) {
sta_name[i] = (char *)malloc(14);
sta_code[i] = (char *)malloc(5);
sta_name[i][0] = '\0';
sta_code[i][0] = '\0';
}
/* Open and read station file */
if ((fpsta = fopen("/Users/antonio/Projects/ISS/stations/1960.stn", "r")) == NULL) {
fprintf(stderr, "Error in dat2isc: ");
fprintf(stderr, "cannot open output station file: %s\n",
"/Users/antonio/Projects/ISS/stations/1960.stn");
return 1;
}
i = 0;
while (fgets(line, MAXLINE, fpsta) != NULL) {
if (line[0] != '!') {
strncpy(sta_name[i], &line[16], 12);
sta_name[i][12] = '\0';
strncpy(sta_code[i], &line[59], 4);
sta_code[i][4] = '\0';
trim(sta_name[i]);
trim(sta_code[i]);
i++;
}
}
nsta = i;
/*
fprintf(stderr, "Number of station names in 1960.stn: %d\n", nsta);
*/
fclose(fpsta);
/* Open HEQ file */
if ((fpheq = fopen("HEQ", "w")) == NULL) {
fprintf(stderr, "Error in dat2isc: ");
fprintf(stderr, "cannot open output HEQ file\n");
return 1;
}
/* Open DAT file */
if ((fpisc = fopen("DAT", "w")) == NULL) {
fprintf(stderr, "Error in dat2isc: ");
fprintf(stderr, "cannot open output DAT file in ISC format\n");
return 1;
}
/* Allocate 96-byte cards */
for (i = 0; i < MAXCARDS; i++) {
;
}
neq = 0;
while (fgets(line, MAXLINE, fpdat) != NULL) {
/* read year from line header */
sscanf(line, "%2d%2d%2d%c%3d",
&yr, &mo, &dy, &ord, &lineno);
year = yr + 1900;
evno = ord - 'A' + 1;
/*
fprintf(stderr, "%4d/%02d/%02d %2d %3d\n",
year, mo, dy, evno, lineno);
*/
/* call to function to determine type of line:
* Possible code values:
0 or negative = error
1 = Origin, epicentre and depth
2 = First constant line (A=, B=, C=, ...)
3 = Second constant line (G=, H=, K=, HT=)
4 = Depth of focus or standard error line
5 = Standard error line or first station
> 5 = Phase card
*/
if (lineno == 1) {
/* write previous event (if any) */
if (icard > 0) {
/* write hypocenter card */
fprintf(fpisc,
"%2d%2d%4d%2d%2d%2d%2d%4d%2d%3d%c%7d%2d%8d%2d%4d%2d",
1, 5, year, month, day, hour, minute, second*100, 0, 0, 'A',
NINT(lat*10000), -2, NINT(lon*10000), -2, NINT(depth*10), 0);
fprintf(fpisc, " 99 99");
fprintf(fpisc, "%4d%3d%4d%4d%2d \n",
igreg, isreg, nobs, NINT(se*100), -2);
/* write phase cards */
for (i = 1; i < icard; i++) {
fprintf(fpisc, "%s", card[i]);
}
/* inpr has to be changed to 1 for last phase card */
card[icard][2] = ' ';
card[icard][3] = '1';
fprintf(fpisc, "%s", card[icard]);
/* write to HEQ file */
iscdepth = depth;
if (depth == 0.0) depth = 35.0;
ndep = 0;
fprintf(fpheq,
" HEQ %2d %2d %2d %2d %2d %5.2f %7.3f%8.3f %5.1f %3.1f%2d%3d%5.1f%3d%3d\n",
year-1900, month, day, hour, minute, (float)second,
lat, lon, depth, mag, imag,
ntel,iscdepth,igreg,ndep);
}
if (neq) {
;
}
/* start processing this event */
if (strstr(line, "EPICENTRE") == (char *)NULL) {
fprintf(stderr, "Error processing hypocenter line:\n");
fprintf(stderr, "%s", line);
return 1;
}
get_hypo(&line[11], &month, &day, &hour,
&minute, &second, &lat, &lon, &depth);
if (month != mo || day != dy) {
fprintf(stderr, "Error in hypocenter date:\n");
fprintf(stderr, "%s", line);
return 1;
}
OriginTime.year = year;
OriginTime.month = month;
OriginTime.day = day;
OriginTime.hour = hour;
OriginTime.minute = minute;
OriginTime.second = second;
OriginTime.millisecond = 0;
igreg = isreg = 0;
/*
lookup_(&lat, " ", &lon, " ", &igreg, &isreg);
fprintf(stderr, "IGREG = %3d, ISREG = %3d\n", igreg, isreg);
*/
/* initialize variables and arrays for this event */
neq++;
nobs = 0;
icard = 0;
strncpy(evname, line, 7);
evname[7] = '\0';
header = TRUE;
rdepth = FLT_UNDEF;
se = FLT_UNDEF;
/*
fprintf(stderr, "%4d/%02d/%02d %02d:%02d:%02d %6.2f %7.2f %3.0f\n",
year, month, day, hour, minute, second, lat, lon, depth);
*/
}
/* Ignore lineno = 2 and lineno = 3 */
if (header) { /* read standard error from line 4 or 5 */
if (lineno <= 5) {
if (strstr(line, "SE=") != (char *)NULL) {
sscanf(line, "%*s%*s%f", &se);
/*fprintf(stderr, "%s SE=%6.2f\n", line, se);*/
header = FALSE;
}
} else {
fprintf(stderr, "dat2isc: ");
fprintf(stderr, "standard error not found for event %s\n", evname);
return 1;
}
} else { /* read phase card */
get_phases(&line[11], stnm, &delta, &azim, &Pmin, &Psec, &Pres, &Ppol,
&Smin, &Ssec, &Sres, &pPmin, &pPsec, &Suppmin, &Suppsec, Supp);
ips = 0;
if (Pmin != INT_UNDEF) {
ips++;
dt = Pmin*60 + Psec;
PhaseTime[ips]=iaddsec1(OriginTime, dt);
if (delta <= 105.0) {
op_id[ips] = 0;
strcpy(phase[ips], "P");
} else if (delta > 105.0 && delta < 110.0) {
if (Pres == 777) {
op_id[ips] = 85;
strcpy(phase[ips], "Pdiff");
} else {
op_id[ips] = 4;
strcpy(phase[ips], "PKP");
}
} else {
op_id[ips] = 4;
strcpy(phase[ips], "PKP");
}
res[ips] = 10 * Pres;
if (Pres == 777) res[ips] = 9999;
if (res[ips] > 9999) res[ips] = 9999;
if (res[ips] < -999) res[ips] = -999;
if (Ppol == 'K') {
pol[ips] = 'D';
} else if (Ppol == 'A') {
pol[ips] = 'C';
} else if (Ppol == ' ') {
pol[ips] = Ppol;
} else {
fprintf(stderr, "Error: invalid polarity code: %c\n%s\n",
Ppol, line);
pol[ips] = ' ';
return 1;
}
}
if (Smin != INT_UNDEF) {
ips++;
dt = Smin*60 + Ssec;
PhaseTime[ips] = iaddsec1(OriginTime, dt);
if (delta <= 95.0) {
op_id[ips] = 35;
strcpy(phase[ips], "S");
} else {
op_id[ips] = 39;
strcpy(phase[ips], "SKS");
}
res[ips] = 10 * Sres;
if (res[ips] > 9999) res[ips] = 9999;
if (res[ips] < -999) res[ips] = -999;
pol[ips] = ' ';
}
if (pPmin != INT_UNDEF) {
ips++;
dt = pPmin*60 + pPsec;
PhaseTime[ips] = iaddsec1(OriginTime, dt);
if (delta <= 105.0) {
op_id[ips] = 60;
strcpy(phase[ips], "pP");
} else if (delta > 105.0 && delta < 110.0) {
if (Pres == 777) {
/*
fprintf(stderr, "Possible pPdiff: %s\n", line);
op_id[ips] = ??;
strcpy(phase[ips], "pPdiff");
*/
}
op_id[ips] = 59;
strcpy(phase[ips], "pPKP");
} else {
op_id[ips] = 59;
strcpy(phase[ips], "pPKP");
}
res[ips] = 9999;
pol[ips] = ' ';
}
if (Suppmin != INT_UNDEF) {
ips++;
dt = Suppmin*60 + Suppsec;
PhaseTime[ips] = iaddsec1(OriginTime, dt);
asterisk(Supp);
op_id[ips] = phase_code2(Supp);
/*
if (op_id[ips] != 999)
fprintf(stderr, "%s %d\n", Supp, op_id[ips]);
*/
strcpy(phase[ips], Supp);
res[ips] = 9999;
pol[ips] = ' ';
}
if (ips) {
/* find station code for stnm */
/* function: pass a name and date -> returns a 4 character code (csta) */
csta[0] = '\0';
trim(stnm);
for (ist = 0; ist < nsta; ist++) {
if (strcmp(stnm, sta_name[ist]) == 0) {
strcpy(csta, sta_code[ist]);
break;
}
}
if (strlen(csta) < 3) {
fprintf(stderr, "Error finding station code for: %s\n", stnm);
strcpy(csta, "????");
}
/* write phase cards (record formats 5 or 6) */
inrf = 5;
i = 1;
do {
if (strlen(csta) < 3) break;
icard++; /* increment card number for this event */
irf = inrf;
if (i < ips)
inrf = 6;
else {
if (lcomments) inrf = 7;
else inrf = 5;
}
/*
fprintf(stderr, "%2d%2d%4d%2d", irf, inrf, year, month);
if (irf == 5) {
fprintf(stderr,
"%-4s %3d%5d%3d%2d%2d%2d%4d%2d%3d%-8s%4d%3d%4d%c",
csta, NINT(azim), NINT(delta*100.0),ips,
PhaseTime[i].day,PhaseTime[i].hour,
PhaseTime[i].minute, NINT(PhaseTime[i].second*100.0), 0,
op_id[i], phase[i], 9999, op_id[i], res[i], pol[i]);
} else if (irf == 6) {
fprintf(stderr, "%2d%2d%2d%2d%4d%2d%3d%-8s%4d%3d%4d%c", i,
PhaseTime[i].day,PhaseTime[i].hour,
PhaseTime[i].minute, NINT(PhaseTime[i].second*100.0), 0,
op_id[i], phase[i], 9999, op_id[i], res[i], pol[i]);
}
fprintf(stderr, " 99 99 99 \n");
*/
sprintf(card[icard], "%2d%2d%4d%2d", irf, inrf, year, month);
if (irf == 5) {
sprintf(&card[icard][10],
"%-4s %3d%5d%3d%2d%2d%2d%4d%2d%3d%-8s%4d%3d%4d%c",
csta, NINT(azim), NINT(delta*100.0),ips,
PhaseTime[i].day,PhaseTime[i].hour,
PhaseTime[i].minute, NINT(PhaseTime[i].second*100.0), 0,
op_id[i], phase[i], 9999, op_id[i], res[i], pol[i]);
sprintf(&card[icard][68], " 99 99 99 \n");
} else if (irf == 6) {
sprintf(&card[icard][10], "%2d%2d%2d%2d%4d%2d%3d%-8s%4d%3d%4d%c", i,
PhaseTime[i].day,PhaseTime[i].hour,
PhaseTime[i].minute, NINT(PhaseTime[i].second*100.0), 0,
op_id[i], phase[i], 9999, op_id[i], res[i], pol[i]);
sprintf(&card[icard][47],
" 99 99 99 \n");
}
i++;
} while (i <= ips);
if (lcomments) {
sprintf(card[++icard], "%2d%2d%4d%2d%2d%-84s\n",7, 5, year, month, 1, stnm);
}
nobs++;
} else {
fprintf(stderr, "WARNING: no phases for this card:\n%s\n", line);
}
}
}
/* write last event */
if (icard > 0) {
/* write hypocenter card */
fprintf(fpisc,
"%2d%2d%4d%2d%2d%2d%2d%4d%2d%3d%c%7d%2d%8d%2d%4d%2d",
1, 5, year, month, day, hour, minute, second*100, 0, 0, 'A',
NINT(lat*10000), -2, NINT(lon*10000), -2, NINT(depth*10), 0);
fprintf(fpisc, " 99 99");
fprintf(fpisc, "%4d%3d%4d%4d%2d \n",
igreg, isreg, nobs, NINT(se*100), -2);
/* write phase cards */
for (i = 1; i < icard; i++) {
fprintf(fpisc, "%s", card[i]);
}
/* inpr has to be changed to -1 for last phase card in file */
card[icard][2] = '-';
card[icard][3] = '1';
fprintf(fpisc, "%s", card[icard]);
/* write to HEQ file */
iscdepth = depth;
if (depth == 0.0) depth = 35.0;
ndep = 0;
fprintf(fpheq,
" HEQ %2d %2d %2d %2d %2d %5.2f %7.3f%8.3f %5.1f %3.1f%2d%3d%5.1f%3d%3d\n",
year-1900, month, day, hour, minute, (float)second,
lat, lon, depth, mag, imag,
ntel,iscdepth,igreg,ndep);
}
fclose(fpdat);
fclose(fpheq);
fclose(fpisc);
return 0;
}
| 23.72344 | 91 | 0.550398 |
50bf074497469dfaaa983e4f52a031cdf0f4bd35 | 477 | h | C | mojo/tools/embed/data.h | smklein/motown | eb4cd4f30c134eb411f6e6390ebe1b396769e2d5 | [
"BSD-3-Clause"
] | 1 | 2020-04-28T14:35:10.000Z | 2020-04-28T14:35:10.000Z | mojo/tools/embed/data.h | smklein/motown | eb4cd4f30c134eb411f6e6390ebe1b396769e2d5 | [
"BSD-3-Clause"
] | null | null | null | mojo/tools/embed/data.h | smklein/motown | eb4cd4f30c134eb411f6e6390ebe1b396769e2d5 | [
"BSD-3-Clause"
] | 1 | 2020-04-28T14:35:11.000Z | 2020-04-28T14:35:11.000Z | // Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_TOOLS_EMBED_DATA_H_
#define MOJO_TOOLS_EMBED_DATA_H_
#include <stddef.h> // For size_t.
namespace mojo {
namespace embed {
struct Data {
const char* const hash;
const char* const data;
const size_t size;
};
} // namespace embed
} // namespace mojo
#endif // MOJO_TOOLS_EMBED_DATA_H_
| 20.73913 | 73 | 0.737945 |
fb5cf369c550dd104117373824c144aaa026bdab | 4,584 | h | C | musicplayer/plugins/openmptplugin/openmpt/common/mptBufferIO.h | Osmose/moseamp | 8357daf2c93bc903c8041cc82bf3567e8d085a60 | [
"MIT"
] | 6 | 2017-04-19T19:06:03.000Z | 2022-01-11T14:44:14.000Z | plugins/openmptplugin/openmpt/common/mptBufferIO.h | sasq64/musicplayer | 372852c2f4e3231a09db2628fc4b7e7c2bfeec67 | [
"MIT"
] | 4 | 2018-04-04T20:27:32.000Z | 2020-04-25T10:46:21.000Z | musicplayer/plugins/openmptplugin/openmpt/common/mptBufferIO.h | Osmose/moseamp | 8357daf2c93bc903c8041cc82bf3567e8d085a60 | [
"MIT"
] | 2 | 2018-06-08T15:20:48.000Z | 2020-08-19T14:24:21.000Z | /*
* mptBufferIO.h
* -------------
* Purpose: A wrapper around std::stringstream, fixing MSVC tell/seek problems with empty streams.
* Notes : You should only ever use these wrappers instead of plain std::stringstream classes.
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "BuildSettings.h"
#include <ios>
#include <istream>
#include <ostream>
#include <sstream>
#include <streambuf>
OPENMPT_NAMESPACE_BEGIN
// MSVC std::stringbuf (and thereby std::ostringstream, std::istringstream and
// std::stringstream) fail seekpos() and seekoff() when the stringbuf is
// currently empty.
// seekpos() and seekoff() can get called via tell*() or seek*() iostream
// members. seekoff() (and thereby tell*()), but not seekpos(), has been fixed
// from VS2010 onwards to handle this specific case and changed to not fail
// when the stringbuf is empty.
// Work-around strategy:
// As re-implementing or duplicating the whole std::stringbuf semantics would be
// rather convoluted, we make use of the knowledge of specific inner workings of
// the MSVC implementation here and just fix-up where it causes problems. This
// keeps the additional code at a minimum size.
namespace mpt
{
#ifdef MPT_COMPILER_QUIRK_MSVC_STRINGSTREAM
class stringbuf
: public std::stringbuf
{
public:
stringbuf(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: std::stringbuf(mode)
{
return;
}
stringbuf(const std::string &str, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: std::stringbuf(str, mode)
{
return;
}
public:
virtual pos_type seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out)
{
pos_type result = std::stringbuf::seekoff(off, way, which);
if(result == pos_type(-1))
{
if((which & std::ios_base::in) || (which & std::ios_base::out))
{
if(off == 0)
{
result = 0;
}
}
}
return result;
}
virtual pos_type seekpos(pos_type ptr, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
{
pos_type result = std::stringbuf::seekpos(ptr, mode);
if(result == pos_type(-1))
{
if((mode & std::ios_base::in) || (mode & std::ios_base::out))
{
if(static_cast<std::streamoff>(ptr) == 0)
{
result = 0;
}
}
}
return result;
}
};
class istringstream
: public std::basic_istream<char>
{
private:
mpt::stringbuf buf;
public:
istringstream(std::ios_base::openmode mode = std::ios_base::in)
: std::basic_istream<char>(&buf)
, buf(mode | std::ios_base::in)
{
}
istringstream(const std::string &str, std::ios_base::openmode mode = std::ios_base::in)
: std::basic_istream<char>(&buf)
, buf(str, mode | std::ios_base::in)
{
}
~istringstream()
{
}
public:
mpt::stringbuf *rdbuf() const { return const_cast<mpt::stringbuf*>(&buf); }
std::string str() const { return buf.str(); }
void str(const std::string &str) { buf.str(str); }
};
class ostringstream
: public std::basic_ostream<char>
{
private:
mpt::stringbuf buf;
public:
ostringstream(std::ios_base::openmode mode = std::ios_base::out)
: std::basic_ostream<char>(&buf)
, buf(mode | std::ios_base::out)
{
}
ostringstream(const std::string &str, std::ios_base::openmode mode = std::ios_base::out)
: std::basic_ostream<char>(&buf)
, buf(str, mode | std::ios_base::out)
{
}
~ostringstream()
{
}
public:
mpt::stringbuf *rdbuf() const { return const_cast<mpt::stringbuf*>(&buf); }
std::string str() const { return buf.str(); }
void str(const std::string &str) { buf.str(str); }
};
class stringstream
: public std::basic_iostream<char>
{
private:
mpt::stringbuf buf;
public:
stringstream(std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: std::basic_iostream<char>(&buf)
, buf(mode | std::ios_base::in | std::ios_base::out)
{
}
stringstream(const std::string &str, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out)
: std::basic_iostream<char>(&buf)
, buf(str, mode | std::ios_base::in | std::ios_base::out)
{
}
~stringstream()
{
}
public:
mpt::stringbuf *rdbuf() const { return const_cast<mpt::stringbuf*>(&buf); }
std::string str() const { return buf.str(); }
void str(const std::string &str) { buf.str(str); }
};
#else
typedef std::stringbuf stringbuf;
typedef std::istringstream istringstream;
typedef std::ostringstream ostringstream;
typedef std::stringstream stringstream;
#endif
} // namespace mpt
OPENMPT_NAMESPACE_END
| 25.752809 | 139 | 0.684119 |
74a2b853d233f1b7d6c1fa9ad32034bf6c0732dd | 7,235 | h | C | src/avt/VisWindow/Colleagues/VisWinAxes3D.h | visit-dav/vis | c08bc6e538ecd7d30ddc6399ec3022b9e062127e | [
"BSD-3-Clause"
] | 226 | 2018-12-29T01:13:49.000Z | 2022-03-30T19:16:31.000Z | src/avt/VisWindow/Colleagues/VisWinAxes3D.h | visit-dav/vis | c08bc6e538ecd7d30ddc6399ec3022b9e062127e | [
"BSD-3-Clause"
] | 5,100 | 2019-01-14T18:19:25.000Z | 2022-03-31T23:08:36.000Z | src/avt/VisWindow/Colleagues/VisWinAxes3D.h | visit-dav/vis | c08bc6e538ecd7d30ddc6399ec3022b9e062127e | [
"BSD-3-Clause"
] | 84 | 2019-01-24T17:41:50.000Z | 2022-03-10T10:01:46.000Z | // Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers. See the top-level LICENSE file for dates and other
// details. No copyright assignment is required to contribute to VisIt.
// ************************************************************************* //
// VisWinAxes3D.h //
// ************************************************************************* //
#ifndef VIS_WIN_AXES3D_H
#define VIS_WIN_AXES3D_H
#include <viswindow_exports.h>
#include <VisWinColleague.h>
class vtkVisItCubeAxesActor;
class vtkPolyDataMapper;
class vtkOutlineSource;
// ****************************************************************************
// Class: VisWinAxes3D
//
// Purpose:
// This is a concrete colleague for the mediator VisWindow. It places
// a 3D axes around the bounding box for the plots.
//
// Programmer: Kathleen Bonnell
// Creation: June 28, 2001
//
// Modifications:
//
// Kathleen Bonnell, Fri Aug 3 14:55:59 PDT 2001
// Changed from using a 2d cube axes actor to using a 3d version.
//
// Kathleen Bonnell, Tue Oct 30 10:30:10 PST 2001
// Moved AdjustValues, AdjustRange and related members to the
// more appropriate location of vtkVisItCubeAxesActor
//
// Kathleen Bonnell, Wed May 28 15:52:32 PDT 2003
// Added method 'ReAddToWindow'.
//
// Kathleen Bonnell, Tue Dec 16 11:34:33 PST 2003
// Added method 'SetLabelScaling'.
//
// Brad Whitlock, Thu Jul 28 10:10:40 PDT 2005
// Added methods to set the units and title.
//
// Brad Whitlock, Tue Mar 25 16:27:40 PDT 2008
// Added methods for line width, font, font size.
//
// Eric Brugger, Wed Oct 15 13:05:33 PDT 2008
// Added SetAutoSetTicks, SetMajorTickMinimum, SetMajorTickMaximum,
// SetMajorTickSpacing and SetMinorTickSpacing.
//
// Jeremy Meredith, Wed May 5 14:32:23 EDT 2010
// Added support for title visibility separate from label visibility.
//
// Jeremy Meredith, Wed May 19 14:15:58 EDT 2010
// Account for 3D axis scaling (3D equivalent of full-frame mode).
//
// Hank Childs, Mon May 23 13:26:09 PDT 2011
// Add method for overriding bounding box location.
//
// Burlen Loring, Wed Oct 21 15:23:16 PDT 2015
// I added a get method to query actor visibility.
//
// ****************************************************************************
class VISWINDOW_API VisWinAxes3D : public VisWinColleague
{
public:
VisWinAxes3D(VisWindowColleagueProxy &);
virtual ~VisWinAxes3D();
virtual void SetForegroundColor(double, double, double);
virtual void UpdateView(void);
virtual void UpdatePlotList(std::vector<avtActor_p> &);
virtual void Start3DMode(void);
virtual void Stop3DMode(void);
virtual void HasPlots(void);
virtual void NoPlots(void);
virtual void ReAddToWindow(void);
void SetBBoxLocation(bool, const double *);
void SetBounds(double [6], double scales[3]);
void SetXTickVisibility(int, int);
void SetYTickVisibility(int, int);
void SetZTickVisibility(int, int);
void SetXLabelVisibility(int);
void SetYLabelVisibility(int);
void SetZLabelVisibility(int);
void SetXTitleVisibility(int);
void SetYTitleVisibility(int);
void SetZTitleVisibility(int);
void SetXGridVisibility(int);
void SetYGridVisibility(int);
void SetZGridVisibility(int);
void SetVisibility(int);
int GetVisibility(){ return visibility; }
void SetAutoSetTicks(int);
void SetMajorTickMinimum(double, double, double);
void SetMajorTickMaximum(double, double, double);
void SetMajorTickSpacing(double, double, double);
void SetMinorTickSpacing(double, double, double);
void SetBBoxVisibility(int);
void SetFlyMode(int);
void SetTickLocation(int);
void SetLabelScaling(bool, int, int, int);
void SetXTitle(const std::string &, bool);
void SetXUnits(const std::string &, bool);
void SetYTitle(const std::string &, bool);
void SetYUnits(const std::string &, bool);
void SetZTitle(const std::string &, bool);
void SetZUnits(const std::string &, bool);
void SetLineWidth(int);
void SetTitleTextAttributes(
const VisWinTextAttributes &xAxis,
const VisWinTextAttributes &yAxis,
const VisWinTextAttributes &zAxis);
void SetLabelTextAttributes(
const VisWinTextAttributes &xAxis,
const VisWinTextAttributes &yAxis,
const VisWinTextAttributes &zAxis);
void Set3DAxisScalingFactors(bool scale,
const double s[3]);
bool GetBoundsOverridden() const;
void GetOverrideBounds( double *bounds ) const;
protected:
void UpdateTitleTextAttributes(double fr, double fg, double fb);
void UpdateLabelTextAttributes(double fr, double fg, double fb);
vtkVisItCubeAxesActor *axes;
vtkOutlineSource *axesBoxSource;
vtkPolyDataMapper *axesBoxMapper;
vtkActor *axesBox;
bool addedAxes3D;
double currentBounds[6];
double currentScaleFactors[3];
bool visibility;
bool boundsOverridden;
double overrideBounds[6];
std::string userXTitle;
std::string userYTitle;
std::string userZTitle;
std::string userXUnits;
std::string userYUnits;
std::string userZUnits;
bool userXTitleFlag;
bool userYTitleFlag;
bool userZTitleFlag;
bool userXUnitsFlag;
bool userYUnitsFlag;
bool userZUnitsFlag;
VisWinTextAttributes titleTextAttributes[3];
VisWinTextAttributes labelTextAttributes[3];
void AddAxes3DToWindow(void);
void RemoveAxes3DFromWindow(void);
bool ShouldAddAxes3D(void);
};
#endif
| 41.58046 | 79 | 0.522046 |
74fa8d316aba0d589277a37a8897731f99c475ad | 3,078 | h | C | Matrix.h | cerati/mkFit | ba37025247ff72c8edd2baea02b5b4ac335bdede | [
"Apache-2.0"
] | 10 | 2019-07-25T21:15:50.000Z | 2022-02-01T11:16:00.000Z | Matrix.h | osschar/mkFit | e08198918b0baa986501f315519080e97b854816 | [
"Intel"
] | 120 | 2019-08-02T16:14:35.000Z | 2022-01-24T22:15:24.000Z | Matrix.h | osschar/mkFit | e08198918b0baa986501f315519080e97b854816 | [
"Intel"
] | 11 | 2019-07-22T12:48:48.000Z | 2021-09-12T15:44:23.000Z | #ifndef _matrix_
#define _matrix_
#include "Config.h"
#include "MatrixSTypes.h"
// This should go elsewhere, eventually.
#ifdef __cpp_lib_clamp
using std::clamp;
#else
template<class T, class Compare> inline
constexpr const T clamp( const T v, const T lo, const T hi, Compare comp )
{
return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}
template<class T> inline
constexpr const T clamp( const T v, const T lo, const T hi )
{
return clamp( v, lo, hi, std::less<T>() );
}
#endif
#include <sys/time.h>
namespace mkfit {
inline double dtime()
{
double tseconds = 0.0;
struct timeval mytime;
gettimeofday(&mytime,(struct timezone*)0);
tseconds = (double)(mytime.tv_sec + mytime.tv_usec*1.0e-6);
return( tseconds );
}
inline float hipo(float x, float y)
{
return std::sqrt(x*x + y*y);
}
inline float hipo_sqr(float x, float y)
{
return x*x + y*y;
}
inline void sincos4(const float x, float& sin, float& cos)
{
// Had this writen with explicit division by factorial.
// The *whole* fitting test ran like 2.5% slower on MIC, sigh.
const float x2 = x*x;
cos = 1.f - 0.5f*x2 + 0.04166667f*x2*x2;
sin = x - 0.16666667f*x*x2;
}
} // end namespace mkfit
//==============================================================================
// Matriplex dimensions and typedefs
#ifdef __INTEL_COMPILER
#define ASSUME_ALIGNED(a, b) __assume_aligned(a, b)
#else
#define ASSUME_ALIGNED(a, b) a = static_cast<decltype(a)>(__builtin_assume_aligned(a, b))
#endif
#include "Matriplex/MatriplexSym.h"
namespace mkfit {
constexpr Matriplex::idx_t NN = MPT_SIZE; // "Length" of MPlex.
constexpr Matriplex::idx_t LL = 6; // Dimension of large/long MPlex entities
constexpr Matriplex::idx_t HH = 3; // Dimension of small/short MPlex entities
typedef Matriplex::Matriplex<float, LL, LL, NN> MPlexLL;
typedef Matriplex::Matriplex<float, LL, 1, NN> MPlexLV;
typedef Matriplex::MatriplexSym<float, LL, NN> MPlexLS;
typedef Matriplex::Matriplex<float, HH, HH, NN> MPlexHH;
typedef Matriplex::Matriplex<float, HH, 1, NN> MPlexHV;
typedef Matriplex::MatriplexSym<float, HH, NN> MPlexHS;
typedef Matriplex::Matriplex<float, 2, 2, NN> MPlex22;
typedef Matriplex::Matriplex<float, 2, 1, NN> MPlex2V;
typedef Matriplex::MatriplexSym<float, 2, NN> MPlex2S;
typedef Matriplex::Matriplex<float, LL, HH, NN> MPlexLH;
typedef Matriplex::Matriplex<float, HH, LL, NN> MPlexHL;
typedef Matriplex::Matriplex<float, LL, 2, NN> MPlexL2;
typedef Matriplex::Matriplex<float, 1, 1, NN> MPlexQF;
typedef Matriplex::Matriplex<int, 1, 1, NN> MPlexQI;
typedef Matriplex::Matriplex<unsigned int, 1, 1, NN> MPlexQUI;
typedef Matriplex::Matriplex<bool, 1, 1, NN> MPlexQB;
} // end namespace mkfit
//==============================================================================
#include <random>
namespace mkfit {
extern std::default_random_engine g_gen;
extern std::normal_distribution<float> g_gaus;
extern std::uniform_real_distribution<float> g_unif;
} // end namespace mkfit
#endif
| 27 | 91 | 0.660494 |
97a71b51908ab4ac5c45559835936ed2df25b0d1 | 1,915 | h | C | Upper_1/Classes/View/ZKSegment.h | AmazingFM/UpperPS | 7d3f40c7f1bb8b4d0fd1092ccf9d3a2bde83db86 | [
"Apache-2.0"
] | null | null | null | Upper_1/Classes/View/ZKSegment.h | AmazingFM/UpperPS | 7d3f40c7f1bb8b4d0fd1092ccf9d3a2bde83db86 | [
"Apache-2.0"
] | null | null | null | Upper_1/Classes/View/ZKSegment.h | AmazingFM/UpperPS | 7d3f40c7f1bb8b4d0fd1092ccf9d3a2bde83db86 | [
"Apache-2.0"
] | null | null | null | //
// ZKSegment.h
// ZKSegment
//
// Created by WangWenzhuang on 15/10/20.
// Copyright © 2015年 WangWenzhuang. All rights reserved.
//
#import <UIKit/UIKit.h>
/**
* 样式
*/
typedef enum {
/**
* 线条样式
*/
ZKSegmentLineStyle = 0,
/**
* 矩形样式
*/
ZKSegmentRectangleStyle = 1,
/**
* 文字样式
*/
ZKSegmentTextStyle = 2
} ZKSegmentStyle;
@interface ZKSegment : UIScrollView
/**
* 每一项默认颜色
* 默认 [r:102.0f,g:102.0f,b:102.0f]
*/
@property(nonatomic, strong) UIColor *zk_itemDefaultColor;
/**
* 选中项颜色
*
* ZKSegmentLineStyle 默认[r:202.0, g:51.0, b:54.0]
* ZKSegmentRectangleStyle 默认[r:250.0, g:250.0, b:250.0]
*/
@property(nonatomic, strong) UIColor *zk_itemSelectedColor;
/**
* 选中项样式颜色
*
* 默认[r:202.0, g:51.0, b:54.0]
*/
@property(nonatomic, strong) UIColor *zk_itemStyleSelectedColor;
/**
* 背景色
*
* 默认[r:238.0, g:238.0, b:238.0]
*/
@property(nonatomic, strong) UIColor *zk_backgroundColor;
/**
* 项切换 Block
*/
@property(nonatomic, copy) void (^zk_itemClickBlock) (NSString *itemName, NSInteger itemIndex);
/**
* 获取当前选中项索引
*/
@property(nonatomic, readonly, getter=zk_selectedItemIndex) int zk_selectedItemIndex;
/**
* 获取当前选中项
*/
@property(nonatomic, strong, readonly, getter=zk_selectedItem) NSString *zk_selectedItem;
/**
* 版本号
*/
@property(nonatomic, strong, readonly) NSString *zk_version;
/**
* 工厂方法,创建不同样式的选择器
*/
+ (ZKSegment *)zk_segmentWithFrame:(CGRect)frame style:(ZKSegmentStyle)style;
/**
* 初始化
*/
- (id)zk_initWithFrame:(CGRect)frame style:(ZKSegmentStyle)style;
/**
* 设置项目集合
*/
- (void)zk_setItems:(NSArray *)items;
/**
* 获取项目集合
*/
- (NSArray *)zk_items;
/**
* 根据索引触发单击事件
*/
- (void)zk_itemClickByIndex:(NSInteger)index;
/**
* 添加一项
*/
- (void)zk_addItem:(NSString *)item;
/**
* 根据索引移除一项
*/
- (void)zk_removeItemAtIndex:(NSInteger)index;
/**
* 移除指定项
*/
- (void)zk_removeItem:(NSString *)item;
@end
| 18.592233 | 95 | 0.646475 |
08fce4779c7ceef316d69d89dc7279b3ea103277 | 940 | h | C | reblur_package/reblur_package_lib/cuda_geometry.h | adityakrishnavamsy/SelfDeblur | 29d02605d64faf8428f4c862d8e004a85c2cd719 | [
"MIT"
] | 104 | 2020-02-09T00:58:00.000Z | 2022-03-23T07:59:56.000Z | reblur_package/reblur_package_lib/cuda_geometry.h | adityakrishnavamsy/SelfDeblur | 29d02605d64faf8428f4c862d8e004a85c2cd719 | [
"MIT"
] | 5 | 2020-03-06T04:21:41.000Z | 2022-03-21T01:04:05.000Z | reblur_package/reblur_package_lib/cuda_geometry.h | adityakrishnavamsy/SelfDeblur | 29d02605d64faf8428f4c862d8e004a85c2cd719 | [
"MIT"
] | 18 | 2020-02-10T13:02:46.000Z | 2021-09-05T14:45:54.000Z | #ifndef CUDA_GEOMETRY_H
#define CUDA_GEOMETRY_H
void rearrange_vertices(const float* vertex_array,
const int* faces,
const int nVertexPerBatch,
const int nFacesPerBatch,
const int batch_size,
const int vertexDim,
float* rearranged_vertex_array);
void backward_rearrange_vertices(const float* grad_rearranged_vertices,
const int* faces,
const int nVertexPerBatch,
const int nFacesPerBatch,
const int batch_size,
const int vertexDim,
const float fraction,
float* grad_vertices);
void mask_via_flow_forward_warp(const float* flow_forward_warped_xy, int B, int H, int W, float* mask);
#endif | 40.869565 | 103 | 0.520213 |
40e5cd945466efa56783961600b5d9007cc1d169 | 744 | h | C | libraries/ms-drivers/inc/bts7xxx_common_impl.h | Citrusboa/firmware_xiv | 4379cefae900fd67bd14d930da6b8acfce625176 | [
"MIT"
] | 14 | 2019-11-12T00:11:29.000Z | 2021-12-13T05:32:41.000Z | libraries/ms-drivers/inc/bts7xxx_common_impl.h | 123Logan321/firmware_xiv | 14468d55753ad62f8a63a9289511e72131443042 | [
"MIT"
] | 191 | 2019-11-12T05:36:58.000Z | 2022-03-21T19:54:46.000Z | libraries/ms-drivers/inc/bts7xxx_common_impl.h | 123Logan321/firmware_xiv | 14468d55753ad62f8a63a9289511e72131443042 | [
"MIT"
] | 14 | 2020-06-06T14:43:14.000Z | 2022-03-08T00:48:11.000Z | #pragma once
// Common private functions for BTS7XXX-series load switches.
// These functions should not be called outside of the BTS7200/7040 drivers.
#include "bts7xxx_common.h"
// Fault restart delay is the same across both the BTS7040 and the BTS7200
#define BTS7XXX_FAULT_RESTART_DELAY_MS 110
#define BTS7XXX_FAULT_RESTART_DELAY_US (BTS7XXX_FAULT_RESTART_DELAY_MS * 1000)
// Broad pin soft timer cb without re-enabling the pin
void bts7xxx_fault_handler_cb(SoftTimerId timer_id, void *context);
// Broad pin re-enable soft timer cb
void bts7xxx_fault_handler_enable_cb(SoftTimerId timer_id, void *context);
// Helper function to clear fault on a given pin
StatusCode bts7xxx_handle_fault_pin(Bts7xxxEnablePin *pin);
| 39.157895 | 79 | 0.797043 |
671a8378380aafb107aff3d28ff092742925c406 | 1,030 | c | C | 05_Cub3D/lib/libft/src/linked_list/ft_lstdelone.c | tderwedu/42cursus | 2f56b87ce87227175e7a297d850aa16031acb0a8 | [
"Unlicense"
] | null | null | null | 05_Cub3D/lib/libft/src/linked_list/ft_lstdelone.c | tderwedu/42cursus | 2f56b87ce87227175e7a297d850aa16031acb0a8 | [
"Unlicense"
] | null | null | null | 05_Cub3D/lib/libft/src/linked_list/ft_lstdelone.c | tderwedu/42cursus | 2f56b87ce87227175e7a297d850aa16031acb0a8 | [
"Unlicense"
] | null | null | null | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tderwedu <tderwedu@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/01/18 15:38:39 by tderwedu #+# #+# */
/* Updated: 2021/01/29 21:59:27 by tderwedu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst)
{
if (del)
del(lst->content);
free(lst);
}
}
| 42.916667 | 80 | 0.180583 |
8cb34d7aac35c312484d3fc045084af9b3b8d83e | 226 | h | C | Library/heft/Shared/Crc.h | handpoint/Handpoint-iOS-SDK | 44ab69a878c4e1ea7e216cd7fb66521125542b67 | [
"BSD-3-Clause"
] | 1 | 2018-12-26T22:35:12.000Z | 2018-12-26T22:35:12.000Z | Library/heft/Shared/Crc.h | handpoint/Handpoint-iOS-SDK | 44ab69a878c4e1ea7e216cd7fb66521125542b67 | [
"BSD-3-Clause"
] | 1 | 2021-02-26T09:46:26.000Z | 2021-02-26T09:46:26.000Z | Library/heft/Shared/Crc.h | handpoint/Handpoint-iOS-SDK | 44ab69a878c4e1ea7e216cd7fb66521125542b67 | [
"BSD-3-Clause"
] | 3 | 2018-09-18T10:07:08.000Z | 2021-02-03T14:31:46.000Z | #pragma once
#ifndef _CRC_INCLUDE_DEFINED_
#define _CRC_INCLUDE_DEFINED_
#include <cstdint>
namespace CRC {
std::uint16_t CalcCRC(const std::uint8_t *paucData, std::int16_t shLength, std::uint16_t usSeed = 0);
}
#endif | 18.833333 | 105 | 0.761062 |
8cfebf2dc3ac44f4f0edf54771f5448ebcacc1f7 | 315 | h | C | MathStats/sample_builder.h | goldim/unistats | e8dd54e46f84422d868c942367f0103949791ede | [
"MIT"
] | null | null | null | MathStats/sample_builder.h | goldim/unistats | e8dd54e46f84422d868c942367f0103949791ede | [
"MIT"
] | null | null | null | MathStats/sample_builder.h | goldim/unistats | e8dd54e46f84422d868c942367f0103949791ede | [
"MIT"
] | null | null | null | #pragma once
#include <map>
#include "sample.h"
namespace stats
{
class PerfomanceSampleBuilder
{
public:
PerfomanceSampleBuilder() = default;
void add(int name, unsigned m, unsigned n);
std::map<int, PerfomanceSample> build();
private:
std::map<int, PerfomanceSample> _samples;
};
}// stats
| 13.695652 | 47 | 0.695238 |
48ae1e56920177897ac107ca2117565ae091ae51 | 3,329 | h | C | graphics/sphere.h | Tibonium/genecis | 4de1d987f5a7928b1fc3e31d2820f5d2452eb5fc | [
"BSD-2-Clause"
] | null | null | null | graphics/sphere.h | Tibonium/genecis | 4de1d987f5a7928b1fc3e31d2820f5d2452eb5fc | [
"BSD-2-Clause"
] | null | null | null | graphics/sphere.h | Tibonium/genecis | 4de1d987f5a7928b1fc3e31d2820f5d2452eb5fc | [
"BSD-2-Clause"
] | null | null | null | /**
* @file sphere.h
*/
#pragma once
#define _USE_MATH_DEFINES
#include <cmath>
#define GL_GLEXT_PROTOTYPES
#include <genecis/container/array.h>
#include <GL/glx.h>
#include <GL/glext.h>
#include <GL/glu.h>
namespace genecis {
namespace graphics {
class Sphere {
public:
typedef std::size_t size_type ;
typedef double integral_type ;
typedef container::array<GLfloat> container_type ;
/**
* Constructor
*
* @param radius
* @param rings
* @param sectors
*/
Sphere(integral_type radius, size_type rings, size_type sectors) ;
/**
* Empty Destructor
*/
virtual ~Sphere() ;
void draw( container::array<double> center, double dt ) ;
/**
* Draws the sphere on the display at the coordinates (x,y,z)
*
* @param x x-coordinate value for the center of the sphere
* @param y y-coordinate value for the center of the sphere
* @param z z-coordinate value for the center of the sphere
*/
void draw(GLfloat x, GLfloat y, GLfloat z, double dt ) ;
/**
* Sets the color of each sector/ring for the sphere
*/
void color(GLfloat r, GLfloat g, GLfloat b) ;
/**
* Returns a reference to the sphere's current rotation matrix
*/
GLfloat* rotation_matrix() {
return _rotation ;
}
/**
* Accesors for the position
*/
GLfloat position( const size_type i ) {
return _position[i] ;
}
void position( const size_type i, GLfloat p ) {
_position[i] = p ;
}
container_type* position() {
return &_position ;
}
/**
* Accesors for the velocity
*/
GLfloat velocity( const size_type i ) {
return _velocity[i] ;
}
void velocity( const size_type i, GLfloat v ) {
_velocity[i] = v ;
}
container_type* velocity() {
return &_velocity ;
}
/**
* Accesors for the acceleration
*/
GLfloat acceleration( const size_type i ) {
return _acceleration[i] ;
}
void acceleration( const size_type i, GLfloat a ) {
_acceleration[i] = a ;
}
container_type* acceleration() {
return &_acceleration ;
}
void id( GLuint i ) {
_id = i ;
}
GLuint id() {
return _id ;
}
private:
/**
* Vertices of the surfaces that make up the sphere
*/
container_type _vertices ;
/**
* Normals to the surfaces of the sphere
*/
container_type _normals ;
/**
* Texture coordinates
*/
container_type _texcoords ;
/**
* Color of each surface that makes up the sphere
*/
container_type _colors ;
/**
* Position vector
*/
container_type _position ;
/**
* Velocity vector
*/
container_type _velocity ;
/**
* Acceleration vector
*/
container_type _acceleration ;
/**
* Indices of the vertices
*/
container::array<GLushort> _indices ;
/**
* Color values
*/
GLfloat _red ;
GLfloat _green ;
GLfloat _blue ;
/**
* Rotation matrix for this object
*/
GLfloat* _rotation ;
/**
* Sphere's ID
*/
GLuint _id ;
};
} // end namespace graphics
} // end namespace genecis
| 18.80791 | 70 | 0.570141 |
71716b2f9e469a6e6d0503e3b400be9caf6e6749 | 9,570 | c | C | trunk/aes/Rijndael/rijndael-api-fst.c | flomar/CrypTool-VS2015 | 6468257af2e1002418882f22a9ed9fabddde096d | [
"Apache-2.0"
] | null | null | null | trunk/aes/Rijndael/rijndael-api-fst.c | flomar/CrypTool-VS2015 | 6468257af2e1002418882f22a9ed9fabddde096d | [
"Apache-2.0"
] | null | null | null | trunk/aes/Rijndael/rijndael-api-fst.c | flomar/CrypTool-VS2015 | 6468257af2e1002418882f22a9ed9fabddde096d | [
"Apache-2.0"
] | 5 | 2016-07-02T12:59:28.000Z | 2021-10-02T14:58:30.000Z | /* rijndael-api-fst.c v2.0 August '99
* Optimised ANSI C code
* authors: v1.0: Antoon Bosselaers
* v2.0: Vincent Rijmen
*/
#include <stdlib.h>
#include <string.h>
#include "rijndael-alg-fst.h"
#include "rijndael-api-fst.h"
#pragma warning(disable : 4996)
int makeKeyRijndael(keyInstanceRijndael *key, BYTE direction, int keyLen, char *keyMaterial)
{
word8 k[MAXKC][4];
int i, j, t;
if (key == NULL) {
return BAD_KEY_INSTANCE;
}
if ((direction == DIR_ENCRYPT) || (direction == DIR_DECRYPT)) {
key->direction = direction;
} else {
return BAD_KEY_DIR;
}
if ((keyLen == 128) || (keyLen == 192) || (keyLen == 256)) {
key->keyLen = keyLen;
} else {
return BAD_KEY_MAT;
}
if ( keyMaterial ) {
strncpy(key->keyMaterial, keyMaterial, keyLen/4);
}
ROUNDS = keyLen/32 + 6;
/* initialize key schedule: */
for(i = 0; i < key->keyLen/8; i++) {
t = key->keyMaterial[2*i];
if ((t >= '0') && (t <= '9')) j = (t - '0') << 4;
else if ((t >= 'a') && (t <= 'f')) j = (t - 'a' + 10) << 4;
else if ((t >= 'A') && (t <= 'F')) j = (t - 'A' + 10) << 4;
else return BAD_KEY_MAT;
t = key->keyMaterial[2*i+1];
if ((t >= '0') && (t <= '9')) j ^= (t - '0');
else if ((t >= 'a') && (t <= 'f')) j ^= (t - 'a' + 10);
else if ((t >= 'A') && (t <= 'F')) j ^= (t - 'A' + 10);
else return BAD_KEY_MAT;
k[i / 4][i % 4] = (word8) j;
}
rijndaelKeySched (k, key->keyLen, key->keySched);
if (direction == DIR_DECRYPT)
rijndaelKeyEnctoDec (key->keyLen, key->keySched);
return TRUE;
}
int cipherInitRijndael(cipherInstanceRijndael *cipher, BYTE mode, char *IV)
{
int i, j, t;
if ((mode == MODE_ECB) || (mode == MODE_CBC) || (mode == MODE_CFB1)) {
cipher->mode = mode;
} else {
return BAD_CIPHER_MODE;
}
if (IV != NULL) {
for(i = 0; i < 16; i++) {
t = IV[2*i];
if ((t >= '0') && (t <= '9')) j = (t - '0') << 4;
else if ((t >= 'a') && (t <= 'f')) j = (t - 'a' + 10) << 4;
else if ((t >= 'A') && (t <= 'F')) j = (t - 'A' + 10) << 4;
else return BAD_CIPHER_INSTANCE;
t = IV[2*i+1];
if ((t >= '0') && (t <= '9')) j ^= (t - '0');
else if ((t >= 'a') && (t <= 'f')) j ^= (t - 'a' + 10);
else if ((t >= 'A') && (t <= 'F')) j ^= (t - 'A' + 10);
else return BAD_CIPHER_INSTANCE;
cipher->IV[i] = (word8) j;
}
}
return TRUE;
}
int blockEncryptRijndael(cipherInstanceRijndael *cipher,
keyInstanceRijndael *key, BYTE *input, int inputLen, BYTE *outBuffer)
{
int i, k, numBlocks;
word8 block[16], iv[4][4];
if (cipher == NULL ||
key == NULL ||
key->direction == DIR_DECRYPT) {
return BAD_CIPHER_STATE;
}
numBlocks = inputLen/128;
switch (cipher->mode) {
case MODE_ECB:
for (i = numBlocks; i > 0; i--) {
rijndaelEncrypt (input, outBuffer, key->keySched);
input += 16;
outBuffer += 16;
}
break;
case MODE_CBC:
#if STRICT_ALIGN
memcpy(block,cipher->IV,16);
#else
*((word32*)block) = *((word32*)(cipher->IV));
*((word32*)(block+4)) = *((word32*)(cipher->IV+4));
*((word32*)(block+8)) = *((word32*)(cipher->IV+8));
*((word32*)(block+12)) = *((word32*)(cipher->IV+12));
#endif
for (i = numBlocks; i > 0; i--) {
*((word32*)block) ^= *((word32*)(input));
*((word32*)(block+4)) ^= *((word32*)(input+4));
*((word32*)(block+8)) ^= *((word32*)(input+8));
*((word32*)(block+12)) ^= *((word32*)(input+12));
rijndaelEncrypt (block, outBuffer, key->keySched);
*((word32*)block) = *((word32*)(outBuffer));
*((word32*)(block+4)) = *((word32*)(outBuffer+4));
*((word32*)(block+8)) = *((word32*)(outBuffer+8));
*((word32*)(block+12)) = *((word32*)(outBuffer+12));
input += 16;
outBuffer += 16;
}
break;
case MODE_CFB1:
#if STRICT_ALIGN
memcpy(iv,cipher->IV,16);
#else
*((word32*)iv[0]) = *((word32*)(cipher->IV));
*((word32*)iv[1]) = *((word32*)(cipher->IV+4));
*((word32*)iv[2]) = *((word32*)(cipher->IV+8));
*((word32*)iv[3]) = *((word32*)(cipher->IV+12));
#endif
for (i = numBlocks; i > 0; i--) {
for (k = 0; k < 128; k++) {
*((word32*)block) = *((word32*)iv[0]);
*((word32*)(block+4)) = *((word32*)iv[1]);
*((word32*)(block+8)) = *((word32*)iv[2]);
*((word32*)(block+12)) = *((word32*)iv[3]);
rijndaelEncrypt (block, block, key->keySched);
outBuffer[k/8] ^= (block[0] & 0x80) >> (k & 7);
iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7);
iv[0][1] = (iv[0][1] << 1) | (iv[0][2] >> 7);
iv[0][2] = (iv[0][2] << 1) | (iv[0][3] >> 7);
iv[0][3] = (iv[0][3] << 1) | (iv[1][0] >> 7);
iv[1][0] = (iv[1][0] << 1) | (iv[1][1] >> 7);
iv[1][1] = (iv[1][1] << 1) | (iv[1][2] >> 7);
iv[1][2] = (iv[1][2] << 1) | (iv[1][3] >> 7);
iv[1][3] = (iv[1][3] << 1) | (iv[2][0] >> 7);
iv[2][0] = (iv[2][0] << 1) | (iv[2][1] >> 7);
iv[2][1] = (iv[2][1] << 1) | (iv[2][2] >> 7);
iv[2][2] = (iv[2][2] << 1) | (iv[2][3] >> 7);
iv[2][3] = (iv[2][3] << 1) | (iv[3][0] >> 7);
iv[3][0] = (iv[3][0] << 1) | (iv[3][1] >> 7);
iv[3][1] = (iv[3][1] << 1) | (iv[3][2] >> 7);
iv[3][2] = (iv[3][2] << 1) | (iv[3][3] >> 7);
iv[3][3] = (iv[3][3] << 1) | (outBuffer[k/8] >> (7-(k&7))) & 1;
}
}
break;
default:
return BAD_CIPHER_STATE;
}
return numBlocks*128;
}
int blockDecryptRijndael(cipherInstanceRijndael *cipher,
keyInstanceRijndael *key, BYTE *input, int inputLen, BYTE *outBuffer)
{
int i, k, numBlocks;
word8 block[16], iv[4][4];
if (cipher == NULL ||
key == NULL ||
cipher->mode != MODE_CFB1 && key->direction == DIR_ENCRYPT) {
return BAD_CIPHER_STATE;
}
numBlocks = inputLen/128;
switch (cipher->mode) {
case MODE_ECB:
for (i = numBlocks; i > 0; i--) {
rijndaelDecrypt (input, outBuffer, key->keySched);
input += 16;
outBuffer += 16;
}
break;
case MODE_CBC:
/* first block */
rijndaelDecrypt (input, block, key->keySched);
#if STRICT_ALIGN
memcpy(outBuffer,cipher->IV,16);
*((word32*)(outBuffer)) ^= *((word32*)block);
*((word32*)(outBuffer+4)) ^= *((word32*)(block+4));
*((word32*)(outBuffer+8)) ^= *((word32*)(block+8));
*((word32*)(outBuffer+12)) ^= *((word32*)(block+12));
#else
*((word32*)(outBuffer)) = *((word32*)block) ^ *((word32*)(cipher->IV));
*((word32*)(outBuffer+4)) = *((word32*)(block+4)) ^ *((word32*)(cipher->IV+4));
*((word32*)(outBuffer+8)) = *((word32*)(block+8)) ^ *((word32*)(cipher->IV+8));
*((word32*)(outBuffer+12)) = *((word32*)(block+12)) ^ *((word32*)(cipher->IV+12));
#endif
/* next blocks */
for (i = numBlocks-1; i > 0; i--) {
input += 16;
rijndaelDecrypt (input, block, key->keySched);
*((word32*)(outBuffer+16)) = *((word32*)block) ^
*((word32*)(input-16));
*((word32*)(outBuffer+20)) = *((word32*)(block+4)) ^
*((word32*)(input-12));
*((word32*)(outBuffer+24)) = *((word32*)(block+8)) ^
*((word32*)(input-8));
*((word32*)(outBuffer+28)) = *((word32*)(block+12)) ^
*((word32*)(input-4));
outBuffer += 16;
}
break;
case MODE_CFB1:
#if STRICT_ALIGN
memcpy(iv,cipher->IV,16);
#else
*((word32*)iv[0]) = *((word32*)(cipher->IV));
*((word32*)iv[1]) = *((word32*)(cipher->IV+4));
*((word32*)iv[2]) = *((word32*)(cipher->IV+8));
*((word32*)iv[3]) = *((word32*)(cipher->IV+12));
#endif
for (i = numBlocks; i > 0; i--) {
for (k = 0; k < 128; k++) {
*((word32*)block) = *((word32*)iv[0]);
*((word32*)(block+4)) = *((word32*)iv[1]);
*((word32*)(block+8)) = *((word32*)iv[2]);
*((word32*)(block+12)) = *((word32*)iv[3]);
rijndaelEncrypt (block, block, key->keySched);
iv[0][0] = (iv[0][0] << 1) | (iv[0][1] >> 7);
iv[0][1] = (iv[0][1] << 1) | (iv[0][2] >> 7);
iv[0][2] = (iv[0][2] << 1) | (iv[0][3] >> 7);
iv[0][3] = (iv[0][3] << 1) | (iv[1][0] >> 7);
iv[1][0] = (iv[1][0] << 1) | (iv[1][1] >> 7);
iv[1][1] = (iv[1][1] << 1) | (iv[1][2] >> 7);
iv[1][2] = (iv[1][2] << 1) | (iv[1][3] >> 7);
iv[1][3] = (iv[1][3] << 1) | (iv[2][0] >> 7);
iv[2][0] = (iv[2][0] << 1) | (iv[2][1] >> 7);
iv[2][1] = (iv[2][1] << 1) | (iv[2][2] >> 7);
iv[2][2] = (iv[2][2] << 1) | (iv[2][3] >> 7);
iv[2][3] = (iv[2][3] << 1) | (iv[3][0] >> 7);
iv[3][0] = (iv[3][0] << 1) | (iv[3][1] >> 7);
iv[3][1] = (iv[3][1] << 1) | (iv[3][2] >> 7);
iv[3][2] = (iv[3][2] << 1) | (iv[3][3] >> 7);
iv[3][3] = (iv[3][3] << 1) | (input[k/8] >> (7-(k&7))) & 1;
outBuffer[k/8] ^= (block[0] & 0x80) >> (k & 7);
}
}
break;
default:
return BAD_CIPHER_STATE;
}
return numBlocks*128;
}
/**
* cipherUpdateRounds:
*
* Encrypts/Decrypts exactly one full block a specified number of rounds.
* Only used in the Intermediate Value Known Answer Test.
*
* Returns:
* TRUE - on success
* BAD_CIPHER_STATE - cipher in bad state (e.g., not initialized)
*/
int cipherUpdateRounds(cipherInstanceRijndael *cipher,
keyInstanceRijndael *key, BYTE *input, int inputLen, BYTE *outBuffer, int rounds)
{
int j;
word8 block[4][4];
if (cipher == NULL ||
key == NULL) {
return BAD_CIPHER_STATE;
}
for (j = 3; j >= 0; j--) {
/* parse input stream into rectangular array */
*((word32*)block[j]) = *((word32*)(input+4*j));
}
switch (key->direction) {
case DIR_ENCRYPT:
rijndaelEncryptRound (block, key->keySched, rounds);
break;
case DIR_DECRYPT:
rijndaelDecryptRound (block, key->keySched, rounds);
break;
default: return BAD_KEY_DIR;
}
for (j = 3; j >= 0; j--) {
/* parse rectangular array into output ciphertext bytes */
*((word32*)(outBuffer+4*j)) = *((word32*)block[j]);
}
return TRUE;
}
| 27.1875 | 92 | 0.505538 |
73d91b0d93c3fcd8316cb8e37fb3947122d6bea8 | 2,213 | h | C | Impl/Session.h | TollisK/Browser-Simulator-Data-Structures | 2fd8a08ad946451e0f18a416a5a268dd2f7f28bf | [
"MIT"
] | 1 | 2022-01-09T17:33:18.000Z | 2022-01-09T17:33:18.000Z | Impl/Session.h | TollisK/Browser-Simulator-Data-Structures | 2fd8a08ad946451e0f18a416a5a268dd2f7f28bf | [
"MIT"
] | null | null | null | Impl/Session.h | TollisK/Browser-Simulator-Data-Structures | 2fd8a08ad946451e0f18a416a5a268dd2f7f28bf | [
"MIT"
] | null | null | null | /*************************************************************************
Implementation File : Session.h
Author Date : Apostolos Karvelas 1115201800312 4/5/2019
Purpose : Header file for Session.c
**************************************************************************/
#ifndef __SESSION__
#define __SESSION__
typedef struct InfoSession *InfoSessionPtr;
typedef struct SiteNode *SiteNodePtr;
typedef struct TabNode *TabNodePtr;
InfoSessionPtr SessionNew(char *);/*Dhmiourgei neo Session*/
void SessionNewTab(InfoSessionPtr,int *);/*Dhmiourgei neo tab sto session*/
/* The rest of the interface functions follow */
char * SessionTabShow(InfoSessionPtr Session);/*return to OpeningAddress tou CurrSite toy CurrTab*/
void SessionTabNext(InfoSessionPtr Session,int *);/*Phgainei ston epomeno tab kyklika*/
void SessionTabPrev(InfoSessionPtr Session,int *);/*Phgainei ston proigoymeno tab kyklika*/
void SessionTabMoveLeft(InfoSessionPtr Session,int *);/*Antimetathesh me ton proigoumeno Tab tou CurrTab*/
void SessionTabMoveRight(InfoSessionPtr Session,int *error);/*Antimetathesh me ton epomeno Tab tou CurrTab*/
void SessionNewOpeningAddress(InfoSessionPtr Session,char *Open,int *);/*Bazei diaforetikh timh sto OpeningAddress*/
char * SessionShowOpeningAddress(InfoSessionPtr Session);/*return to OpeningAddress*/
void SessionSiteNext(InfoSessionPtr Session,int *);/*Phgainei sto epomeno site*/
void SessionSitePrev(InfoSessionPtr Session,int *);/*Phgainei sto proigoymeno site*/
char *SessionSiteShow(InfoSessionPtr Session);/*return to OpeningAddress toy CurrSite toy CurrTab*/
void SessionTabClose(InfoSessionPtr *Session,TabNodePtr flag);/*Diagrafei to CurrTab kai o deikths paei ston epomeno kyklika*/
void SessionClose(InfoSessionPtr *Session);/*Diagrafei to session*/
void SessionNewAddress(InfoSessionPtr Session,char *,int *);/*Dhmioyrgei neo site ston CurrTab me neo OpeningAddress*/
void SessionOpenNewTab(InfoSessionPtr Session,TabNodePtr *,int *);/*Dhmiourgei neo tab to opoio an diagrafei paei sto site sto opoio dhmioyrghthhke*/
char *Value();/*Return mia timh poy eisagoume*/
void print_options(int);/*Deixnei tis epiloges toy switch case*/
#endif
| 61.472222 | 150 | 0.740172 |
2148b0ef56827ecf97458245c72ff13809573272 | 3,304 | h | C | Source/GameObject.h | Project2CITM/Proyecto2 | a10c78fded2b226629a817c4e9cd46ed9e8b5bc8 | [
"MIT"
] | 2 | 2022-03-13T20:31:50.000Z | 2022-03-28T06:43:45.000Z | Source/GameObject.h | Project2CITM/The-last-purifier | e082e8ce6d6aa90b1d232cd9e15f4bec994556ed | [
"MIT"
] | null | null | null | Source/GameObject.h | Project2CITM/The-last-purifier | e082e8ce6d6aa90b1d232cd9e15f4bec994556ed | [
"MIT"
] | null | null | null | #ifndef __GAMEOBJECT_H__
#define __GAMEOBJECT_H__
#include "Application.h"
#include "External/Box2D/Box2D/Box2D.h"
#include "RenderObject.hpp"
struct SDL_Texture;
class PhysBody;
#define MAX_GAMEOBJECT_TEXTURES 5
class GameObject
{
public:
GameObject();
GameObject(std::string name = "Default", std::string tag = "None");
GameObject(GameObject& obj);
virtual ~GameObject();
/// <summary>
/// IMPORTANT: Do not destroy or disable anythink related to body in Trigger or Collision
/// </summary>
/// <param name="col"></param>
virtual void OnCollisionEnter(PhysBody* col);
/// <summary>
/// IMPORTANT: Do not destroy or disable anythink related to body in Trigger or Collision
/// </summary>
/// <param name="col"></param>
virtual void OnCollisionExit(PhysBody* col);
/// <summary>
/// IMPORTANT: Do not destroy or disable anythink related to body in Trigger or Collision
/// </summary>
/// <param name="col"></param>
virtual void OnTriggerEnter(std::string trigger, PhysBody* col);
/// <summary>
/// IMPORTANT: Do not destroy or disable anythink related to body in Trigger or Collision
/// </summary>
/// <param name="col"></param>
virtual void OnTriggerStay(std::string trigger, PhysBody* col);
/// <summary>
/// IMPORTANT: Do not destroy or disable anythink related to body in Trigger or Collision
/// </summary>
/// <param name="col"></param>
virtual void OnTriggerExit(std::string trigger, PhysBody* col);
virtual void Start();
virtual void PreUpdate();
virtual void Update();
virtual void PostUpdate();
virtual void CleanUp();
bool CompareTag(std::string tag);
iPoint GetDrawPosition(int index = 0);
void UpdateOrderInLayer(int index = 0);
/// <summary>
/// Si exixte pBody devuelve angluo de pBody, si no el de GameObject
/// </summary>
/// <returns>angulo en degradado</returns>
float GetDegreeAngle();
/// <summary>
/// Si exixte pBody devuelve position de pBody, si no el de GameObject (px)
/// </summary>
/// <returns>position en pixel</returns>
iPoint GetPosition();
iPoint GetScreenPosition();
/// <summary>
/// Si exixte pBody devuelve position de pBody, si no {0,0}
/// </summary>
b2Vec2 GetLinearVelocity();
/// <summary>
/// Si exixte pBody, cambia la position de pBody, si no la de GameObject
/// </summary>
/// <param name="pos">= position in pixel</param>
void SetPosition(iPoint pos);
/// <summary>
/// Si exixte pBody, cambia el amgulo de pBody, si no el de GameObject
/// </summary>
/// <param name="angle">= angle in deg</param>
void SetRotation(float angle, bool externPivot = false, b2Vec2 pivot = { 0,0 });
/// <summary>
/// Si exixte pBody, cambia la velocidad de pBody, si no saldra un aviso en Console
/// </summary>
/// <param name="vel"></param>
void SetLinearVelocity(b2Vec2 vel);
void SetLinearVelocity(fPoint vel);
protected:
void InitRenderObjectWithXml(std::string texName = "null", int index = 0);
protected:
Application* app = nullptr;
iPoint position = { 0,0 };
float rotation = 0;
public:
std::string name = "";
std::string tag = "";
PhysBody* pBody = nullptr;
RenderObject renderObjects[MAX_GAMEOBJECT_TEXTURES];
bool pendingToDelete = false;
bool adjustToGrid = false;
bool isDie = false;
bool enable = true;
};
#endif // !__GAMEOBJECT_H__ | 23.942029 | 90 | 0.69431 |
42d9b14b27c2a6c673f2cf367032a24897089b1e | 1,039 | h | C | dali/execution/beam_search.h | bzcheeseman/Dali | a77c7ce60b20ce150a5927747e128688657907eb | [
"MIT"
] | null | null | null | dali/execution/beam_search.h | bzcheeseman/Dali | a77c7ce60b20ce150a5927747e128688657907eb | [
"MIT"
] | null | null | null | dali/execution/beam_search.h | bzcheeseman/Dali | a77c7ce60b20ce150a5927747e128688657907eb | [
"MIT"
] | null | null | null | #ifndef DALI_ARRAY_EXECUTION_BEAM_SEARCH_H
#define DALI_ARRAY_EXECUTION_BEAM_SEARCH_H
#include <vector>
namespace beam_search_helper {
template<typename state_t>
struct BeamSearchResult {
state_t state;
std::vector<uint> solution;
double score;
BeamSearchResult();
BeamSearchResult(const state_t& state_,
const std::vector<uint>& solution_,
const double& score_);
};
}
// breadth-first search that keeps k best solutions at every step of search.
template<typename state_t, typename Container>
std::vector<beam_search_helper::BeamSearchResult<state_t>>
beam_search(state_t initial_state,
uint beam_width,
std::function<Container(state_t)> candidate_scores,
std::function<state_t(state_t, uint)> make_choice,
uint end_symbol,
int max_solution_length,
std::vector<uint> forbidden_symbols=std::vector<uint>());
#include "dali/execution/beam_search-impl.h"
#endif
| 30.558824 | 76 | 0.674687 |
4286dc725897934aeb9bf1aa4dd9772ebbe6f30a | 2,071 | h | C | src/bytes.h | close2/alibvr | 2e191be70d5b90b8d576ff4c33b3d4474a4bcb7e | [
"MIT"
] | 1 | 2021-09-21T06:07:44.000Z | 2021-09-21T06:07:44.000Z | src/bytes.h | close2/alibvr | 2e191be70d5b90b8d576ff4c33b3d4474a4bcb7e | [
"MIT"
] | null | null | null | src/bytes.h | close2/alibvr | 2e191be70d5b90b8d576ff4c33b3d4474a4bcb7e | [
"MIT"
] | null | null | null | #pragma once
/**
* @file
*
* @brief This file contains `typedef`s which make it easier to access
* specific bytes of multi-byte values.
*
* An `uint16_t` for instance may be cast to `union bits16_s` which
* makes it possible to access to less significant byte with:
* `v.avr.lo`.
*
* All `union` `typedef`s provide an `avr` member, with `lo` and `hi`
* members. `avr` / gcc is little-endian!
**/
// -----------------------------------------------------------------------
// Types for easier byte-word-dword conversions
// -----------------------------------------------------------------------
// avr / gcc is little-endian
typedef struct bits16_hilo_s {
uint8_t hi;
uint8_t lo;
} bits16_hilo_t;
typedef struct bits16_lohi_s {
uint8_t lo;
uint8_t hi;
} bits16_lohi_t;
typedef union bits16_s {
uint8_t byte[2];
uint8_t uint8[2];
int8_t int8[2];
bits16_lohi_t avr;
bits16_hilo_t hilo;
bits16_lohi_t lohi;
uint16_t word;
uint16_t uint16;
int16_t int16;
} bits16_t;
typedef struct bits32_hilo_s {
bits16_t hi;
bits16_t lo;
} bits32_hilo_t;
typedef struct bits32_lohi_s {
bits16_t lo;
bits16_t hi;
} bits32_lohi_t;
typedef union bits32_t {
uint8_t byte[4];
uint8_t uint8[4];
int8_t int8[4];
uint16_t word[2];
uint16_t uint16[2];
int16_t int16[2];
bits32_lohi_t avr;
bits32_hilo_t hilo;
bits32_lohi_t lohi;
uint32_t dword;
uint32_t uint32;
int32_t int32;
} bits32_t;
typedef struct bits64_hilo_s {
bits32_t hi;
bits32_t lo;
} bits64_hilo_t;
typedef struct bits64_lohi_s {
bits32_t lo;
bits32_t hi;
} bits64_lohi_t;
typedef union bits64_s {
uint8_t byte[8];
uint8_t uint8[8];
int8_t int8[8];
uint16_t word[4];
uint16_t uint16[4];
int16_t int16[4];
uint32_t dword[2];
uint32_t uint32[2];
int32_t int32[2];
bits64_lohi_t avr;
bits64_hilo_t hilo;
bits64_lohi_t lohi;
uint64_t uint64;
int64_t int64;
} bits64_t;
| 21.572917 | 74 | 0.604056 |
550c9f3786c57d00e97277b1eabe57e827686ec1 | 830 | h | C | src/ExtraSoundFormats.h | haya3218/cse2-tweaks | 48bccbd58240942ed5f5b288a90ef092820698c0 | [
"MIT"
] | 12 | 2020-12-14T19:10:55.000Z | 2022-03-16T12:45:56.000Z | src/ExtraSoundFormats.h | haya3218/cse2-tweaks | 48bccbd58240942ed5f5b288a90ef092820698c0 | [
"MIT"
] | null | null | null | src/ExtraSoundFormats.h | haya3218/cse2-tweaks | 48bccbd58240942ed5f5b288a90ef092820698c0 | [
"MIT"
] | 6 | 2020-12-13T03:05:24.000Z | 2021-11-23T14:16:49.000Z | #pragma once
void ExtraSound_Init(unsigned int sample_rate);
void ExtraSound_Deinit(void);
void ExtraSound_Play(void);
void ExtraSound_Stop(void);
void ExtraSound_LoadMusic(const char *intro_file_path, const char *loop_file_path, bool loop);
void ExtraSound_LoadPreviousMusic(void);
void ExtraSound_PauseMusic(void);
void ExtraSound_UnpauseMusic(void);
void ExtraSound_FadeOutMusic(void);
void ExtraSound_SetMusicVolume(unsigned short volume); // Logarithmic - 0 is silent, 0x80 is half-volume, 0x100 is full-volume
void ExtraSound_LoadSFX(const char *path, int id);
void ExtraSound_PlaySFX(int id, int mode);
void ExtraSound_SetSFXFrequency(int id, unsigned long frequency);
void ExtraSound_SetSFXVolume(int id, long volume);
void ExtraSound_SetSFXPan(int id, long pan);
void ExtraSound_Mix(long *buffer, unsigned long frames);
| 43.684211 | 126 | 0.822892 |
4e64dd02a83061b9dc312eb11a8456474cdf1d4d | 479 | h | C | chrome/browser/ssl/captive_portal_helper.h | zipated/src | 2b8388091c71e442910a21ada3d97ae8bc1845d3 | [
"BSD-3-Clause"
] | 2,151 | 2020-04-18T07:31:17.000Z | 2022-03-31T08:39:18.000Z | chrome/browser/ssl/captive_portal_helper.h | cangulcan/src | 2b8388091c71e442910a21ada3d97ae8bc1845d3 | [
"BSD-3-Clause"
] | 395 | 2020-04-18T08:22:18.000Z | 2021-12-08T13:04:49.000Z | chrome/browser/ssl/captive_portal_helper.h | cangulcan/src | 2b8388091c71e442910a21ada3d97ae8bc1845d3 | [
"BSD-3-Clause"
] | 338 | 2020-04-18T08:03:10.000Z | 2022-03-29T12:33:22.000Z | // Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SSL_CAPTIVE_PORTAL_HELPER_H_
#define CHROME_BROWSER_SSL_CAPTIVE_PORTAL_HELPER_H_
namespace chrome {
// Returns true if the OS reports that the device is behind a captive portal.
bool IsBehindCaptivePortal();
} // namespace chrome
#endif // CHROME_BROWSER_SSL_CAPTIVE_PORTAL_HELPER_H_
| 29.9375 | 77 | 0.805846 |
b69c3421f5c2d9af3b306edcb12e10fb785875eb | 6,674 | h | C | lib/ros_lib/jsk_recognition_msgs/PolygonArray.h | hrjp/teensy_ros_ethernet | 9ee2afa4edfc5a15175182dc17d4b9e874622be9 | [
"Apache-2.0"
] | null | null | null | lib/ros_lib/jsk_recognition_msgs/PolygonArray.h | hrjp/teensy_ros_ethernet | 9ee2afa4edfc5a15175182dc17d4b9e874622be9 | [
"Apache-2.0"
] | null | null | null | lib/ros_lib/jsk_recognition_msgs/PolygonArray.h | hrjp/teensy_ros_ethernet | 9ee2afa4edfc5a15175182dc17d4b9e874622be9 | [
"Apache-2.0"
] | null | null | null | #ifndef _ROS_jsk_recognition_msgs_PolygonArray_h
#define _ROS_jsk_recognition_msgs_PolygonArray_h
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "ros/msg.h"
#include "std_msgs/Header.h"
#include "geometry_msgs/PolygonStamped.h"
namespace jsk_recognition_msgs
{
class PolygonArray : public ros::Msg
{
public:
typedef std_msgs::Header _header_type;
_header_type header;
uint32_t polygons_length;
typedef geometry_msgs::PolygonStamped _polygons_type;
_polygons_type st_polygons;
_polygons_type * polygons;
uint32_t labels_length;
typedef uint32_t _labels_type;
_labels_type st_labels;
_labels_type * labels;
uint32_t likelihood_length;
typedef float _likelihood_type;
_likelihood_type st_likelihood;
_likelihood_type * likelihood;
PolygonArray():
header(),
polygons_length(0), polygons(NULL),
labels_length(0), labels(NULL),
likelihood_length(0), likelihood(NULL)
{
}
virtual int serialize(unsigned char *outbuffer) const
{
int offset = 0;
offset += this->header.serialize(outbuffer + offset);
*(outbuffer + offset + 0) = (this->polygons_length >> (8 * 0)) & 0xFF;
*(outbuffer + offset + 1) = (this->polygons_length >> (8 * 1)) & 0xFF;
*(outbuffer + offset + 2) = (this->polygons_length >> (8 * 2)) & 0xFF;
*(outbuffer + offset + 3) = (this->polygons_length >> (8 * 3)) & 0xFF;
offset += sizeof(this->polygons_length);
for( uint32_t i = 0; i < polygons_length; i++){
offset += this->polygons[i].serialize(outbuffer + offset);
}
*(outbuffer + offset + 0) = (this->labels_length >> (8 * 0)) & 0xFF;
*(outbuffer + offset + 1) = (this->labels_length >> (8 * 1)) & 0xFF;
*(outbuffer + offset + 2) = (this->labels_length >> (8 * 2)) & 0xFF;
*(outbuffer + offset + 3) = (this->labels_length >> (8 * 3)) & 0xFF;
offset += sizeof(this->labels_length);
for( uint32_t i = 0; i < labels_length; i++){
*(outbuffer + offset + 0) = (this->labels[i] >> (8 * 0)) & 0xFF;
*(outbuffer + offset + 1) = (this->labels[i] >> (8 * 1)) & 0xFF;
*(outbuffer + offset + 2) = (this->labels[i] >> (8 * 2)) & 0xFF;
*(outbuffer + offset + 3) = (this->labels[i] >> (8 * 3)) & 0xFF;
offset += sizeof(this->labels[i]);
}
*(outbuffer + offset + 0) = (this->likelihood_length >> (8 * 0)) & 0xFF;
*(outbuffer + offset + 1) = (this->likelihood_length >> (8 * 1)) & 0xFF;
*(outbuffer + offset + 2) = (this->likelihood_length >> (8 * 2)) & 0xFF;
*(outbuffer + offset + 3) = (this->likelihood_length >> (8 * 3)) & 0xFF;
offset += sizeof(this->likelihood_length);
for( uint32_t i = 0; i < likelihood_length; i++){
union {
float real;
uint32_t base;
} u_likelihoodi;
u_likelihoodi.real = this->likelihood[i];
*(outbuffer + offset + 0) = (u_likelihoodi.base >> (8 * 0)) & 0xFF;
*(outbuffer + offset + 1) = (u_likelihoodi.base >> (8 * 1)) & 0xFF;
*(outbuffer + offset + 2) = (u_likelihoodi.base >> (8 * 2)) & 0xFF;
*(outbuffer + offset + 3) = (u_likelihoodi.base >> (8 * 3)) & 0xFF;
offset += sizeof(this->likelihood[i]);
}
return offset;
}
virtual int deserialize(unsigned char *inbuffer)
{
int offset = 0;
offset += this->header.deserialize(inbuffer + offset);
uint32_t polygons_lengthT = ((uint32_t) (*(inbuffer + offset)));
polygons_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
polygons_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
polygons_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
offset += sizeof(this->polygons_length);
if(polygons_lengthT > polygons_length)
this->polygons = (geometry_msgs::PolygonStamped*)realloc(this->polygons, polygons_lengthT * sizeof(geometry_msgs::PolygonStamped));
polygons_length = polygons_lengthT;
for( uint32_t i = 0; i < polygons_length; i++){
offset += this->st_polygons.deserialize(inbuffer + offset);
memcpy( &(this->polygons[i]), &(this->st_polygons), sizeof(geometry_msgs::PolygonStamped));
}
uint32_t labels_lengthT = ((uint32_t) (*(inbuffer + offset)));
labels_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
labels_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
labels_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
offset += sizeof(this->labels_length);
if(labels_lengthT > labels_length)
this->labels = (uint32_t*)realloc(this->labels, labels_lengthT * sizeof(uint32_t));
labels_length = labels_lengthT;
for( uint32_t i = 0; i < labels_length; i++){
this->st_labels = ((uint32_t) (*(inbuffer + offset)));
this->st_labels |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
this->st_labels |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
this->st_labels |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
offset += sizeof(this->st_labels);
memcpy( &(this->labels[i]), &(this->st_labels), sizeof(uint32_t));
}
uint32_t likelihood_lengthT = ((uint32_t) (*(inbuffer + offset)));
likelihood_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
likelihood_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
likelihood_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
offset += sizeof(this->likelihood_length);
if(likelihood_lengthT > likelihood_length)
this->likelihood = (float*)realloc(this->likelihood, likelihood_lengthT * sizeof(float));
likelihood_length = likelihood_lengthT;
for( uint32_t i = 0; i < likelihood_length; i++){
union {
float real;
uint32_t base;
} u_st_likelihood;
u_st_likelihood.base = 0;
u_st_likelihood.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
u_st_likelihood.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
u_st_likelihood.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
u_st_likelihood.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
this->st_likelihood = u_st_likelihood.real;
offset += sizeof(this->st_likelihood);
memcpy( &(this->likelihood[i]), &(this->st_likelihood), sizeof(float));
}
return offset;
}
const char * getType(){ return "jsk_recognition_msgs/PolygonArray"; };
const char * getMD5(){ return "709b37d39871cfdbbfbd5c41cf9bc2be"; };
};
}
#endif
| 45.094595 | 139 | 0.597543 |
b6e5c07f4450c3ac610223709e9edcc8b4b041b4 | 1,149 | h | C | include/il2cpp/ColiseumRoomManager/__LeaveUnion_g__Leave|62_0_d.h | martmists-gh/BDSP | d6326c5d3ad9697ea65269ed47aa0b63abac2a0a | [
"MIT"
] | 1 | 2022-01-15T20:20:27.000Z | 2022-01-15T20:20:27.000Z | include/il2cpp/ColiseumRoomManager/__LeaveUnion_g__Leave|62_0_d.h | martmists-gh/BDSP | d6326c5d3ad9697ea65269ed47aa0b63abac2a0a | [
"MIT"
] | null | null | null | include/il2cpp/ColiseumRoomManager/__LeaveUnion_g__Leave|62_0_d.h | martmists-gh/BDSP | d6326c5d3ad9697ea65269ed47aa0b63abac2a0a | [
"MIT"
] | null | null | null | #pragma once
#include "il2cpp.h"
void ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d___ctor (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, int32_t __1__state, const MethodInfo* method_info);
void ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d__System_IDisposable_Dispose (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, const MethodInfo* method_info);
bool ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d__MoveNext (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, const MethodInfo* method_info);
Il2CppObject* ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d__System_Collections_Generic_IEnumerator_System_Object__get_Current (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, const MethodInfo* method_info);
void ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d__System_Collections_IEnumerator_Reset (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, const MethodInfo* method_info);
Il2CppObject* ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d__System_Collections_IEnumerator_get_Current (ColiseumRoomManager___LeaveUnion_g__Leave_62_0_d_o* __this, const MethodInfo* method_info);
| 104.454545 | 222 | 0.91819 |
228a49780eb91a6e596c93612baa8fe2fd2df205 | 6,422 | h | C | MXSAppKit/Lib/MXSKit.framework/Headers/NSDate+RHDate.h | Anonymous-Monk/MXSAppKit | 0f5d6b994b2843a536e4b2f8e4417546249b0617 | [
"MIT"
] | null | null | null | MXSAppKit/Lib/MXSKit.framework/Headers/NSDate+RHDate.h | Anonymous-Monk/MXSAppKit | 0f5d6b994b2843a536e4b2f8e4417546249b0617 | [
"MIT"
] | null | null | null | MXSAppKit/Lib/MXSKit.framework/Headers/NSDate+RHDate.h | Anonymous-Monk/MXSAppKit | 0f5d6b994b2843a536e4b2f8e4417546249b0617 | [
"MIT"
] | null | null | null | //
// NSDate+RHDate.h
// RHBaseModule
//
// Created by aicai on 2018/7/9.
// Copyright © 2018年 aicai. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSDate (RHDate)
+ (NSCalendar *)currentCalendar;
#pragma mark - 时间戳处理/计算日期
/**
通过时间戳计算出与当前时间差
@param timeStamp 时间戳
@return 与当前时间的差距, 比如一天前
*/
+ (NSString *)rh_compareCureentTimeWithDate:(NSTimeInterval)timeStamp;
/**
把当前时间转换成时间戳
@return 时间戳
*/
+ (NSString *)rh_getCurrentTimeStamp;
/**
通过传入的时间戳算出年月日
@param timeStamp 时间戳
@return 年月日, 默认格式xxxx年xx月xx日
*/
+ (NSString *)rh_displayTimeWithTimeStamp:(NSTimeInterval)timeStamp;
/**
通过传入的时间戳和日期格式算出年月日
@param timeStamp 时间戳
@param formatter 时间显示格式
@return 年月日
*/
+ (NSString *)rh_displayTimeWithTimeStamp:(NSTimeInterval)timeStamp
formatter:(NSString *)formatter;
/**
获取指定NSDate的字符串日期
@param date NSDate
@param formatter NSString
@return NSString
*/
+ (NSString *)rh_getDateStringWithDate:(NSDate *)date
formatter:(NSString *)formatter;
/** 获取指定NSDate的字符串日期
*/
+ (NSString *)rh_getDateStringWithDate:(NSDate *)date
dateFormat:(NSString *)dateFormat
timeZone:(NSTimeZone *)timeZone
language:(NSString *)language;
/** NSString 转 NSDate */
+ (NSDate *)rh_getDateFromString:(NSString *)dateString dateFormat:(NSString *)dateFormat;
/** NSString 转 NSDate */
+ (NSDate *)rh_getDateFromString:(NSString *)dateString
dateFormat:(NSString *)dateFormat
timeZone:(NSTimeZone *)timeZone
language:(NSString *)language;
#pragma mark - 日期处理
/** 获取某个月的天数(通过年月求每月天数)*/
+ (NSUInteger)rh_getDaysInYear:(NSInteger)year month:(NSInteger)month;
/**
获取指定NSDate的纪元
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getEraWithDate:(NSDate *)date;
/**
获取指定NSDate的年
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getYearWithDate:(NSDate *)date;
/**
获取指定NSDate的月
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getMonthWithDate:(NSDate *)date;
/**
获取指定NSDate的天
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getDayWithDate:(NSDate *)date;
/**
获取指定NSDate的时
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getHourWithDate:(NSDate *)date;
/**
获取指定NSDate的分
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getMinuteWithDate:(NSDate *)date;
/**
获取指定NSDate的秒
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getSecondWithDate:(NSDate *)date;
/**
获取指定NSDate的星期几, PS: 1代表的是周日, 2代表的是周一, 以此类推
@param date NSDate
@return NSInteger
*/
+ (NSInteger)rh_getWeekdayStringFromDate:(NSDate *)date;
/**
通过传入两组时间, 计算出相差的天数
@param beginDate 开始的时间
@param endDate 结束的时间
@return return NSInteger
*/
+ (NSInteger)rh_getDateTimeDifferenceWithBeginDate:(NSDate *)beginDate
endDate:(NSDate *)endDate;
//计算时间间隔秒数
+ (NSInteger)rh_calculateSecondsWithStartDate:(NSDate *)startDate endDate:(NSDate *)endDate;
/**
获取指定NSDate的每月第一天的日期
@param date NSDate
@return NSDate
*/
+ (NSDate *)rh_getMonthFirstDeteWithDate:(NSDate *)date;
/**
获取指定NSDate的每月最后一天的日期
@param date NSDate
@return NSDate
*/
+ (NSDate *)rh_getMonthLastDayWithDate:(NSDate *)date;
/**
获取指定日期在一年中是第几周
@param date NSDate
@return NSUInteger
*/
+ (NSUInteger)rh_getWeekOfYearWithDate:(NSDate *)date;
/**
通过传入指定的时间获取第二天的日期
@param date NSDate
@return NSDate
*/
+ (NSDate *)rh_getTomorrowDay:(NSDate *)date;
/**
获取指定NSDate第years年后的日期
@param date NSDate
@param years NSInteger, 多少年
@return NSDate
*/
+ (NSDate *)rh_getYearDateWithDate:(NSDate *)date
years:(NSInteger)years;
/**
获取指定NSDate第months月后的日期
@param date NSDate
@param months NSInteger, 多少月
@return NSDate
*/
+ (NSDate *)rh_getMonthDateWithDate:(NSDate *)date
months:(NSInteger)months;
/**
获取指定NSDate第days天后的日期
@param date NSDate
@param days NSInteger, 多少天
@return NSDate
*/
+ (NSDate *)rh_getDaysDateWithDate:(NSDate *)date
days:(NSInteger)days;
/**
获取指定NSDate第hours时后的日期
@param date NSDate
@param hours NSInteger, 多少小时
@return NSDate
*/
+ (NSDate *)rh_getHoursDateWithDate:(NSDate *)date
hours:(NSInteger)hours;
#pragma mark - 日期判断
/**
判断传入的NSDate是否是闰年
@param date NSDate
@return BOOL
*/
+ (BOOL)rh_isLeapYear:(NSDate *)date;
/**
传入指定的时间判断是否为今天
@param date 指定时间
@return BOOL
*/
+ (BOOL)rh_checkTodayWithDate:(NSDate *)date;
#pragma mark - 获取NSDateComponents
/**
获取指定NSCalendarUnit和指定NSDate的NSDateComponents
@param unitFlags NSCalendarUnit
@param date NSDate
@return NSDateComponents
*/
+ (NSDateComponents *)rh_getCalendarWithUnitFlags:(NSCalendarUnit)unitFlags
date:(NSDate *)date;
#pragma mark - 获取工作日
- (BOOL)isWorkday;
- (BOOL)isWeekend;
+ (BOOL)isWorkdayOfDate:(NSDate *)date;
+ (BOOL)isWeekendOfDate:(NSDate *)date;
#pragma mark - 获取日期零点和结束
- (NSDate *)zeroDate;
- (NSDate *)endDate;
+ (NSDate *)zeroDateOfDate:(NSDate *)date;
+ (NSDate *)endDateOfDate:(NSDate *)date;
#pragma mark - 创建日期
/** yyyy */
+ (NSDate *)rh_setYear:(NSInteger)year;
/** yyyy-MM */
+ (NSDate *)rh_setYear:(NSInteger)year month:(NSInteger)month;
/** yyyy-MM-dd */
+ (NSDate *)rh_setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day;
/** yyyy-MM-dd HH */
+ (NSDate *)rh_setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour;
/** yyyy-MM-dd HH:mm */
+ (NSDate *)rh_setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute;
/** yyyy-MM-dd HH:mm:ss */
+ (NSDate *)rh_setYear:(NSInteger)year month:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
/** MM-dd HH:mm */
+ (NSDate *)rh_setMonth:(NSInteger)month day:(NSInteger)day hour:(NSInteger)hour minute:(NSInteger)minute;
/** MM-dd */
+ (NSDate *)rh_setMonth:(NSInteger)month day:(NSInteger)day;
/** HH:mm:ss */
+ (NSDate *)rh_setHour:(NSInteger)hour minute:(NSInteger)minute second:(NSInteger)second;
/** HH:mm */
+ (NSDate *)rh_setHour:(NSInteger)hour minute:(NSInteger)minute;
/** mm:ss */
+ (NSDate *)rh_setMinute:(NSInteger)minute second:(NSInteger)second;
@end
| 21.194719 | 152 | 0.681096 |
e2f940b94e0169578837adee65c09b95d797761e | 2,450 | h | C | examples/sdl2/blargg_apu/Gb_Apu.h | Ryzee119/Peanut-GBX | b10a5b2ee4d6da3ec30dd7c0d869b3834e302a4c | [
"MIT"
] | 6 | 2015-10-05T21:28:16.000Z | 2018-11-11T13:51:31.000Z | examples/sdl2/blargg_apu/Gb_Apu.h | Ryzee119/Peanut-GB | b10a5b2ee4d6da3ec30dd7c0d869b3834e302a4c | [
"MIT"
] | 9 | 2015-10-04T23:18:32.000Z | 2017-03-17T11:06:02.000Z | examples/sdl2/blargg_apu/Gb_Apu.h | Ryzee119/Peanut-GB | b10a5b2ee4d6da3ec30dd7c0d869b3834e302a4c | [
"MIT"
] | 1 | 2020-07-14T04:24:30.000Z | 2020-07-14T04:24:30.000Z |
// Nintendo Game Boy PAPU sound chip emulator
// Gb_Snd_Emu 0.1.4. Copyright (C) 2003-2005 Shay Green. GNU LGPL license.
#ifndef GB_APU_H
#define GB_APU_H
typedef long gb_time_t; // clock cycle count
typedef unsigned gb_addr_t; // 16-bit address
#include "Gb_Oscs.h"
class Gb_Apu {
public:
Gb_Apu();
~Gb_Apu();
// Set overall volume of all oscillators, where 1.0 is full volume
void volume( double );
// Set treble equalization
void treble_eq( const blip_eq_t& );
// Reset oscillators and internal state
void reset();
// Assign all oscillator outputs to specified buffer(s). If buffer
// is NULL, silence all oscillators.
void output( Blip_Buffer* mono );
void output( Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
// Assign single oscillator output to buffer(s). Valid indicies are 0 to 3,
// which refer to Square 1, Square 2, Wave, and Noise.
// If buffer is NULL, silence oscillator.
enum { osc_count = 4 };
void osc_output( int index, Blip_Buffer* mono );
void osc_output( int index, Blip_Buffer* center, Blip_Buffer* left, Blip_Buffer* right );
// Reads and writes at addr must satisfy start_addr <= addr <= end_addr
enum { start_addr = 0xff10 };
enum { end_addr = 0xff3f };
enum { register_count = end_addr - start_addr + 1 };
// Write 'data' to address at specified time
void write_register( gb_time_t, gb_addr_t, int data );
// Read from address at specified time
int read_register( gb_time_t, gb_addr_t );
// Run all oscillators up to specified time, end current time frame, then
// start a new frame at time 0. Return true if any oscillators added
// sound to one of the left/right buffers, false if they only added
// to the center buffer.
bool end_frame( gb_time_t );
private:
// noncopyable
Gb_Apu( const Gb_Apu& );
Gb_Apu& operator = ( const Gb_Apu& );
Gb_Osc* oscs [osc_count];
gb_time_t next_frame_time;
gb_time_t last_time;
int frame_count;
bool stereo_found;
Gb_Square square1;
Gb_Square square2;
Gb_Wave wave;
Gb_Noise noise;
BOOST::uint8_t regs [register_count];
Gb_Square::Synth square_synth; // shared between squares
Gb_Wave::Synth other_synth; // shared between wave and noise
void run_until( gb_time_t );
};
inline void Gb_Apu::output( Blip_Buffer* b ) { output( b, NULL, NULL ); }
inline void Gb_Apu::osc_output( int i, Blip_Buffer* b ) { osc_output( i, b, NULL, NULL ); }
#endif
| 28.823529 | 91 | 0.707755 |
c20c8a80990aee807653f95a7b77f2398dd0bb9b | 10,813 | c | C | src/libs/jabberwerx/test/tracker_test.c | cisco/JabberWerxC | 5a69904922a534e140ef7edb26190e38885aac90 | [
"BSD-2-Clause"
] | 19 | 2015-07-08T17:33:27.000Z | 2021-02-24T03:05:49.000Z | src/libs/jabberwerx/test/tracker_test.c | cisco/JabberWerxC | 5a69904922a534e140ef7edb26190e38885aac90 | [
"BSD-2-Clause"
] | 9 | 2015-07-08T19:11:15.000Z | 2015-07-10T18:54:54.000Z | src/libs/jabberwerx/test/tracker_test.c | cisco/JabberWerxC | 5a69904922a534e140ef7edb26190e38885aac90 | [
"BSD-2-Clause"
] | 9 | 2015-07-08T17:34:05.000Z | 2021-03-16T12:03:40.000Z | /**
* Copyrights
*
* Portions created or assigned to Cisco Systems, Inc. are
* Copyright (c) 2010-2015 Cisco Systems, Inc. All Rights Reserved.
* See LICENSE for details.
*/
#include <assert.h>
#include <string.h>
#include "stanza_defines.h"
#include "fct.h"
#include "test_utils.h"
#include <jabberwerx/tracker.h>
#include <jabberwerx/dom.h>
#include <jabberwerx/util/str.h>
#include <event2/event.h>
struct _tracker_cb_data
{
jw_dom_node *result;
size_t call_count;
};
static void _tracker_cb(jw_dom_node *result, void *user_data)
{
struct _tracker_cb_data *data = (struct _tracker_cb_data*)user_data;
data->result = result;
++data->call_count;
}
//create a simple iq/query
static jw_dom_node *_new_request(jw_dom_node *ctx_node)
{
jw_dom_ctx *ctx;
jw_dom_node *query;
jw_dom_node *request;
if (ctx_node)
{
ctx = jw_dom_get_context(ctx_node);
}
else if (!jw_dom_context_create(&ctx, NULL))
{
return NULL;
}
if (!jw_dom_element_create(ctx, "{}iq", &request, NULL) ||
!jw_dom_set_attribute(request, "{}to", "foo@example.com", NULL) ||
!jw_dom_set_attribute(request, "{}from", "bar@example.com", NULL) ||
!jw_dom_set_attribute(request, "{}type", "get", NULL) ||
!jw_dom_element_create(ctx,
"{http://jabber.org/protocol/disco#info}query",
&query,
NULL) ||
!jw_dom_add_child(request, query, NULL))
{
return NULL;
}
return request;
}
//clone request, switch to/from and set type==result
static jw_dom_node *_new_result(jw_dom_node *request)
{
//not checking dom function results as this is not testing DOM
jw_dom_node *result;
const char *to, *from;
if (jw_dom_clone(request, true, &result, NULL))
{
to = jw_dom_get_attribute(request, "{}to");
from = jw_dom_get_attribute(request, "{}from");
if (to && from &&
jw_dom_set_attribute(result, "{}to", from, NULL) &&
jw_dom_set_attribute(result, "{}from", to, NULL) &&
jw_dom_set_attribute(result, "{}type", "result", NULL))
{
return result;
}
}
return NULL;
}
FCTMF_SUITE_BGN(tracker_test)
{
FCT_TEST_BGN(jw_tracker_create)
{
jw_err err;
jw_tracker *tracker;
jw_dom_node *request;
jw_dom_node *result;
jw_event_dispatcher *dispatch;
jw_event *event;
struct _tracker_cb_data cb_data;
struct event_base *evbase = event_base_new();
fct_req(jw_event_dispatcher_create(
"tracker_test", NULL, &dispatch, NULL));
fct_req(jw_event_dispatcher_create_event(dispatch,
"beforeIQreceived",
&event,
NULL));
fct_req(jw_tracker_create(evbase, &tracker, &err));
fct_req(jw_event_bind(event,
jw_tracker_get_callback(),
tracker,
NULL));
request = _new_request(NULL);
fct_req(request);
fct_req(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
30,
&err));
const char *id = jw_dom_get_attribute(request, "{}id");
fct_chk(id != NULL);
result = _new_result(request);
fct_req(result);
memset(&cb_data, 0, sizeof(struct _tracker_cb_data));
//trigger fires beforeIQreceived synchronously
fct_req(jw_event_trigger(event, result, NULL, NULL, NULL));
fct_chk_eq_int(cb_data.call_count, 1);
fct_chk(cb_data.result == result);
cb_data.call_count = 0; // don't reset result, on purpose
fct_req(jw_dom_set_attribute(result, "{}id", NULL, NULL));
fct_req(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
1,
&err));
// there should only be the timeout event.
//once that fires, and is removed dispatch should return.
(void)event_base_dispatch(evbase);
fct_chk_eq_int(cb_data.call_count, 1);
fct_chk(cb_data.result == NULL);
// check for timeout when stream is closed
cb_data.call_count = 0;
fct_req(jw_dom_set_attribute(result, "{}id", NULL, NULL));
fct_req(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
1,
&err));
jw_tracker_clear(tracker);
(void)event_base_dispatch(evbase);
fct_chk_eq_int(cb_data.call_count, 1);
fct_chk(cb_data.result == NULL);
jw_event_dispatcher_destroy(dispatch);
jw_dom_context_destroy(jw_dom_get_context(request));
jw_tracker_destroy(tracker);
//OOM creation
OOM_SIMPLE_TEST(jw_tracker_create(evbase, &tracker, &err));
jw_tracker_destroy(tracker);
//repeat OOM test with NULL error for coverage, no need to destroy
//tracker, using alloc count from OOM_SIMPLE_TEST
OOM_TEST_INIT();
OOM_TEST(NULL, jw_tracker_create(evbase, &tracker, NULL));
event_base_free(evbase);
} FCT_TEST_END()
FCT_TEST_BGN(jw_tracker_track)
{
jw_err err;
jw_tracker *tracker;
jw_dom_node *request;
jw_dom_node *result;
jw_event_dispatcher *dispatch;
jw_event *event;
struct _tracker_cb_data cb_data;
struct event_base *evbase = event_base_new();
fct_req(jw_event_dispatcher_create(
"tracker_test", NULL, &dispatch, NULL));
fct_req(jw_event_dispatcher_create_event(dispatch,
"beforeIQreceived",
&event,
NULL));
fct_req(jw_tracker_create(evbase, &tracker, NULL));
fct_req(jw_event_bind(event,
jw_tracker_get_callback(),
tracker,
NULL));
//track with defined id
request = _new_request(NULL);
fct_req(request);
fct_req(jw_dom_set_attribute(request, "{}id", "my-id", NULL));
fct_req(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
30,
NULL));
fct_chk(0 == jw_strcmp("my-id", jw_dom_get_attribute(request, "{}id")));
jw_tracker_clear(tracker);
jw_dom_context_destroy(jw_dom_get_context(request));
request = _new_request(NULL);
fct_req(request);
//track with 0 timeout
fct_req(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
0,
NULL));
memset(&cb_data, 0, sizeof(struct _tracker_cb_data));
result = _new_result(request);
fct_req(result);
//trigger with various results to walk packet matching code
fct_req(jw_dom_set_attribute(result, "{}from", NULL, NULL));
fct_req(jw_event_trigger(event, result, NULL, NULL, NULL));
fct_chk_eq_int(cb_data.call_count, 0);
fct_chk(NULL == cb_data.result);
result = _new_result(request);
fct_req(result);
fct_req(jw_dom_set_attribute(result, "{}id", NULL, NULL));
fct_req(jw_event_trigger(event, result, NULL, NULL, NULL));
fct_chk_eq_int(cb_data.call_count, 0);
fct_chk(NULL == cb_data.result);
result = _new_result(request);
fct_req(result);
fct_req(jw_dom_set_attribute(result, "{}type", NULL, NULL));
fct_req(jw_event_trigger(event, result, NULL, NULL, NULL));
fct_chk_eq_int(cb_data.call_count, 0);
fct_chk(NULL == cb_data.result);
result = _new_result(request);
fct_req(result);
fct_req(jw_dom_set_attribute(result, "{}type", "set", NULL));
fct_req(jw_event_trigger(event, result, NULL, NULL, NULL));
fct_chk_eq_int(cb_data.call_count, 0);
fct_chk(NULL == cb_data.result);
jw_tracker_clear(tracker);
fct_chk_eq_int(cb_data.call_count, 1);
fct_chk(NULL == cb_data.result);
jw_dom_context_destroy(jw_dom_get_context(request));
// to do OOM from within beforeIQReceived event handler, OOM macros
// don't currently allow testing of event handlers.
//OOM from within track
request = _new_request(NULL);
fct_req(request);
OOM_RECORD_ALLOCS(jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
30,
NULL));
OOM_TEST_INIT();
jw_tracker_clear(tracker);
jw_dom_context_destroy(jw_dom_get_context(request));
request = _new_request(NULL);
fct_req(request);
OOM_TEST(&err, jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
30,
&err));
//repeat with NULL error for coverage
OOM_TEST_INIT();
jw_tracker_clear(tracker);
jw_dom_context_destroy(jw_dom_get_context(request));
request = _new_request(NULL);
fct_req(request);
OOM_TEST(NULL, jw_tracker_track(tracker,
request,
_tracker_cb,
&cb_data,
30,
NULL));
jw_event_dispatcher_destroy(dispatch);
jw_tracker_destroy(tracker);
event_base_free(evbase);
jw_dom_context_destroy(jw_dom_get_context(request));
} FCT_TEST_END()
} FCTMF_SUITE_END()
| 35.336601 | 80 | 0.527791 |
796f4642d882a397a97aec594006123af84b5c91 | 2,048 | h | C | xdl/xdl/core/ops/unique_op.h | hitflame/x-deeplearning | c8029396c6ae6dbf397a34a1801ceadc824e4f8d | [
"Apache-2.0"
] | 2 | 2019-11-11T09:51:56.000Z | 2021-08-04T04:02:29.000Z | xdl/xdl/core/ops/unique_op.h | hitflame/x-deeplearning | c8029396c6ae6dbf397a34a1801ceadc824e4f8d | [
"Apache-2.0"
] | 1 | 2019-11-29T14:52:53.000Z | 2019-11-29T14:52:53.000Z | xdl/xdl/core/ops/unique_op.h | hitflame/x-deeplearning | c8029396c6ae6dbf397a34a1801ceadc824e4f8d | [
"Apache-2.0"
] | 1 | 2019-08-03T05:22:19.000Z | 2019-08-03T05:22:19.000Z | /* Copyright (C) 2016-2018 Alibaba Group Holding Limited
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.
==============================================================================*/
/*
* Copyright 1999-2017 Alibaba Group.
*
* 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.
*/
#ifndef XDL_CORE_OPS_UNIQUE_OP_H_
#define XDL_CORE_OPS_UNIQUE_OP_H_
#include "xdl/core/framework/cpu_device.h"
namespace xdl {
class GpuDevice;
namespace functor {
template <typename Device, typename T, typename I>
struct UniqueFunctor;
template <typename T, typename I>
struct UniqueFunctor<CpuDevice, T, I> {
void operator()(CpuDevice* d, const Tensor& in, Tensor* out, Tensor& out_index);
};
template <typename T, typename I>
struct UniqueFunctor<GpuDevice, T, I> {
void operator()(GpuDevice* d, const Tensor& in, Tensor* out, Tensor& out_index);
};
} // namespace functor
template <typename T, typename I>
class UniqueCpuOp : public OpKernel {
public:
Status Compute(OpKernelContext* ctx) override;
};
} // namespace xdl
#endif // XDL_CORE_OPS_UNIQUE_OP_H_
| 31.507692 | 82 | 0.728027 |
9f5e70b7187768f89d52f129a08f29870d8f5a6e | 691 | h | C | include/DataStructures/Stack.h | ToppDev/brotcrunsher-game-engine | 0f6a40277adb52c3c8a2d7c5638dfbbb89141bfb | [
"Unlicense"
] | null | null | null | include/DataStructures/Stack.h | ToppDev/brotcrunsher-game-engine | 0f6a40277adb52c3c8a2d7c5638dfbbb89141bfb | [
"Unlicense"
] | null | null | null | include/DataStructures/Stack.h | ToppDev/brotcrunsher-game-engine | 0f6a40277adb52c3c8a2d7c5638dfbbb89141bfb | [
"Unlicense"
] | null | null | null | #pragma once
#pragma once
#include "List.h"
namespace bbe
{
template <typename T>
class Stack
{
private:
List<T> m_data;
public:
void push(const T &object)
{
m_data.pushBack(object);
}
T pop()
{
if (m_data.getLength() <= 0)
{
//TODO add further error handling
__debugbreak();
}
T data = std::move(m_data.last());
m_data.removeIndex(m_data.getLength() - 1);
return data;
}
T peek()
{
if (m_data.getLength() <= 0)
{
//TODO add further error handling
__debugbreak();
}
return m_data.last();
}
size_t dataLeft()
{
return m_data.getLength();
}
bool hasDataLeft()
{
return dataLeft() > 0;
}
};
} | 12.796296 | 46 | 0.58466 |
b00ddbe3e220472128c7037c3f7d90e580120072 | 6,720 | c | C | sdk/core/core/src/az_http_policy_logging.c | amih90/azure-sdk-for-c | b33ca37648e75c14a02e94257d85af7371249f26 | [
"MIT"
] | null | null | null | sdk/core/core/src/az_http_policy_logging.c | amih90/azure-sdk-for-c | b33ca37648e75c14a02e94257d85af7371249f26 | [
"MIT"
] | null | null | null | sdk/core/core/src/az_http_policy_logging.c | amih90/azure-sdk-for-c | b33ca37648e75c14a02e94257d85af7371249f26 | [
"MIT"
] | null | null | null | // Copyright (c) Microsoft Corporation. All rights reserved.
// SPDX-License-Identifier: MIT
#include "az_http_policy_logging_private.h"
#include "az_http_policy_private.h"
#include "az_span_private.h"
#include <az_http_internal.h>
#include <az_http_transport.h>
#include <az_log_internal.h>
#include <az_platform_internal.h>
#include <_az_cfg.h>
enum
{
_az_LOG_LENGTHY_VALUE_MAX_LENGTH
= 50, // When we print values, such as header values, if they are longer than
// _az_LOG_VALUE_MAX_LENGTH, we trim their contents (decorate with ellipsis in the middle)
// to make sure each individual header value does not exceed _az_LOG_VALUE_MAX_LENGTH so
// that they don't blow up the logs.
};
static az_result _az_http_policy_logging_append_lengthy_value(az_span value, az_span* ref_log_msg)
{
int32_t value_size = az_span_length(value);
if (value_size <= _az_LOG_LENGTHY_VALUE_MAX_LENGTH)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, value, ref_log_msg));
return AZ_OK;
}
az_span const ellipsis = AZ_SPAN_FROM_STR(" ... ");
int32_t const ellipsis_len = az_span_length(ellipsis);
int32_t const first
= (_az_LOG_LENGTHY_VALUE_MAX_LENGTH / 2) - ((ellipsis_len / 2) + (ellipsis_len % 2));
int32_t const last
= ((_az_LOG_LENGTHY_VALUE_MAX_LENGTH / 2) + (_az_LOG_LENGTHY_VALUE_MAX_LENGTH % 2))
- (ellipsis_len / 2);
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, az_span_slice(value, 0, first), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, ellipsis, ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(
*ref_log_msg, az_span_slice(value, value_size - last, value_size), ref_log_msg));
return AZ_OK;
}
static az_result _az_http_policy_logging_append_http_request_msg(
_az_http_request const* request,
az_span* ref_log_msg)
{
AZ_RETURN_IF_FAILED(
az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("HTTP Request : "), ref_log_msg));
if (request == NULL)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("NULL"), ref_log_msg));
return AZ_OK;
}
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, request->_internal.method, ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(" "), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, request->_internal.url, ref_log_msg));
int32_t const headers_count = _az_http_request_headers_count(request);
for (int32_t index = 0; index < headers_count; ++index)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("\n\t"), ref_log_msg));
az_pair header = { 0 };
AZ_RETURN_IF_FAILED(az_http_request_get_header(request, index, &header));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, header.key, ref_log_msg));
if (az_span_length(header.value) > 0)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(" : "), ref_log_msg));
AZ_RETURN_IF_FAILED(_az_http_policy_logging_append_lengthy_value(header.value, ref_log_msg));
}
}
return AZ_OK;
}
static az_result _az_http_policy_logging_append_http_response_msg(
az_http_response* ref_response,
int64_t duration_msec,
_az_http_request const* request,
az_span* ref_log_msg)
{
AZ_RETURN_IF_FAILED(
az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("HTTP Response ("), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append_i64toa(*ref_log_msg, duration_msec, ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("ms) "), ref_log_msg));
if (ref_response == NULL || az_span_length(ref_response->_internal.http_response) == 0)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("is empty"), ref_log_msg));
return AZ_OK;
}
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(": "), ref_log_msg));
az_http_response_status_line status_line = { 0 };
AZ_RETURN_IF_FAILED(az_http_response_get_status_line(ref_response, &status_line));
AZ_RETURN_IF_FAILED(
az_span_append_u64toa(*ref_log_msg, (uint64_t)status_line.status_code, ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(" "), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, status_line.reason_phrase, ref_log_msg));
for (az_pair header;
az_http_response_get_next_header(ref_response, &header) != AZ_ERROR_ITEM_NOT_FOUND;)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("\n\t"), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, header.key, ref_log_msg));
if (az_span_length(header.value) > 0)
{
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(" : "), ref_log_msg));
AZ_RETURN_IF_FAILED(_az_http_policy_logging_append_lengthy_value(header.value, ref_log_msg));
}
}
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR("\n\n"), ref_log_msg));
AZ_RETURN_IF_FAILED(az_span_append(*ref_log_msg, AZ_SPAN_FROM_STR(" -> "), ref_log_msg));
AZ_RETURN_IF_FAILED(_az_http_policy_logging_append_http_request_msg(request, ref_log_msg));
return AZ_OK;
}
void _az_http_policy_logging_log_http_request(_az_http_request const* request)
{
uint8_t log_msg_buf[AZ_LOG_MSG_BUF_SIZE] = { 0 };
az_span log_msg = AZ_SPAN_FROM_BUFFER(log_msg_buf);
(void)_az_http_policy_logging_append_http_request_msg(request, &log_msg);
az_log_write(AZ_LOG_HTTP_REQUEST, log_msg);
}
void _az_http_policy_logging_log_http_response(
az_http_response const* response,
int64_t duration_msec,
_az_http_request const* request)
{
uint8_t log_msg_buf[AZ_LOG_MSG_BUF_SIZE] = { 0 };
az_span log_msg = AZ_SPAN_FROM_BUFFER(log_msg_buf);
az_http_response response_copy = *response;
(void)_az_http_policy_logging_append_http_response_msg(
&response_copy, duration_msec, request, &log_msg);
az_log_write(AZ_LOG_HTTP_RESPONSE, log_msg);
}
AZ_NODISCARD az_result az_http_pipeline_policy_logging(
_az_http_policy* p_policies,
void* p_data,
_az_http_request* p_request,
az_http_response* p_response)
{
(void)p_data;
if (az_log_should_write(AZ_LOG_HTTP_REQUEST))
{
_az_http_policy_logging_log_http_request(p_request);
}
if (!az_log_should_write(AZ_LOG_HTTP_RESPONSE))
{
// If no logging is needed, do not even measure the response time.
return az_http_pipeline_nextpolicy(p_policies, p_request, p_response);
}
int64_t const start = az_platform_clock_msec();
az_result const result = az_http_pipeline_nextpolicy(p_policies, p_request, p_response);
int64_t const end = az_platform_clock_msec();
_az_http_policy_logging_log_http_response(p_response, end - start, p_request);
return result;
}
| 35.935829 | 99 | 0.770387 |
bfaa08de1147a425d0eaac900f0c80bf0472bf61 | 2,928 | h | C | Family/Family/LIB/CPKenburnsView.h | VomPom/IOS_Family | ea9a25f7ea897b35619d50a51be7036ae273aacf | [
"Apache-2.0"
] | null | null | null | Family/Family/LIB/CPKenburnsView.h | VomPom/IOS_Family | ea9a25f7ea897b35619d50a51be7036ae273aacf | [
"Apache-2.0"
] | null | null | null | Family/Family/LIB/CPKenburnsView.h | VomPom/IOS_Family | ea9a25f7ea897b35619d50a51be7036ae273aacf | [
"Apache-2.0"
] | null | null | null | //
// CPKenburnsImageView.h
//
//The MIT License (MIT)
//Copyright © 2014 Muukii (www.muukii.me)
//
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the “Software”), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in
//all copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//THE SOFTWARE.
#import <UIKit/UIKit.h>
typedef NS_ENUM(NSInteger, CPKenburnsImageViewState) {
CPKenburnsImageViewStateAnimating,
CPKenburnsImageViewStatePausing
};
typedef NS_ENUM(NSInteger, CPKenburnsImageViewZoomCourse) {
CPKenburnsImageViewZoomCourseRandom = 0,
CPKenburnsImageViewZoomCourseUpperLeftToLowerRight = 1,
CPKenburnsImageViewZoomCourseUpperRightToLowerLeft = 2,
CPKenburnsImageViewZoomCourseLowerLeftToUpperRight = 3,
CPKenburnsImageViewZoomCourseLowerRightToUpperLeft = 4
};
typedef NS_ENUM(NSInteger, CPKenburnsImageViewZoomPoint) {
CPKenburnsImageViewZoomPointLowerLeft = 0,
CPKenburnsImageViewZoomPointLowerRight = 1,
CPKenburnsImageViewZoomPointUpperLeft = 2,
CPKenburnsImageViewZoomPointUpperRight = 3
};
@interface CPKenburnsImageView : UIImageView
@end
@interface CPKenburnsView : UIView
@property (nonatomic, strong) CPKenburnsImageView * imageView;
@property (nonatomic, strong) UIImage * image;
@property (nonatomic, assign) CGFloat animationDuration; //default is 13.f
@property (nonatomic, assign) CGFloat zoomRatio; // default 0.1 0 ~ 1 not working
@property (nonatomic, assign) CGFloat endZoomRate; // default 1.2
@property (nonatomic, assign) CGFloat startZoomRate; // default 1.3
@property (nonatomic, assign) UIEdgeInsets padding; // default UIEdgeInsetsMake(10, 10, 10, 10);
@property (nonatomic, assign) CPKenburnsImageViewZoomCourse course; // default is 0
@property (nonatomic, assign) CPKenburnsImageViewState state;
- (void)restartMotion;
- (void)showWholeImage;
- (void)zoomAndRestartAnimation;
- (void)zoomAndRestartAnimationWithCompletion:(void(^)(BOOL finished))completion;
@end
| 43.701493 | 96 | 0.758197 |
bfb86aee152b23530ec0f601f371f3c1eef15667 | 651 | h | C | System/Library/PrivateFrameworks/HomeKitDaemon.framework/__HMDBundleApplicationInfo.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | 1 | 2020-11-04T15:43:01.000Z | 2020-11-04T15:43:01.000Z | System/Library/PrivateFrameworks/HomeKitDaemon.framework/__HMDBundleApplicationInfo.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | System/Library/PrivateFrameworks/HomeKitDaemon.framework/__HMDBundleApplicationInfo.h | zhangkn/iOS14Header | 4323e9459ed6f6f5504ecbea2710bfd6c3d7c946 | [
"MIT"
] | null | null | null | /*
* This header is generated by classdump-dyld 1.0
* on Sunday, September 27, 2020 at 11:51:55 AM Mountain Standard Time
* Operating System: Version 14.0 (Build 18A373)
* Image Source: /System/Library/PrivateFrameworks/HomeKitDaemon.framework/HomeKitDaemon
* classdump-dyld is licensed under GPLv3, Copyright © 2013-2016 by Elias Limneos.
*/
#import <HomeKitDaemon/HMDApplicationInfo.h>
@class LSPropertyList;
@interface __HMDBundleApplicationInfo : HMDApplicationInfo {
LSPropertyList* _entitlements;
}
-(id)initWithRecord:(id)arg1 ;
-(id)initWithBundleIdentifier:(id)arg1 ;
-(BOOL)isEntitledForSPIAccess;
-(BOOL)isEntitledForAPIAccess;
@end
| 27.125 | 87 | 0.788018 |
ba4870a299a5d670584384a876629c100dc7b367 | 1,866 | h | C | webrtc/include/third_party/blink/renderer/modules/buckets/bucket_manager.h | yxlao/webrtc-cpp-sample | 60bb1948f714693e7c8ade2fc6ffba218ea13859 | [
"MIT"
] | null | null | null | webrtc/include/third_party/blink/renderer/modules/buckets/bucket_manager.h | yxlao/webrtc-cpp-sample | 60bb1948f714693e7c8ade2fc6ffba218ea13859 | [
"MIT"
] | null | null | null | webrtc/include/third_party/blink/renderer/modules/buckets/bucket_manager.h | yxlao/webrtc-cpp-sample | 60bb1948f714693e7c8ade2fc6ffba218ea13859 | [
"MIT"
] | null | null | null | // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_BUCKETS_BUCKET_MANAGER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_BUCKETS_BUCKET_MANAGER_H_
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
#include "third_party/blink/renderer/platform/supplementable.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink {
class ExceptionState;
class NavigatorBase;
class MODULES_EXPORT BucketManager final : public ScriptWrappable,
public Supplement<NavigatorBase> {
DEFINE_WRAPPERTYPEINFO();
public:
static const char kSupplementName[];
// Web-exposed as navigator.storageBuckets
static BucketManager* storageBuckets(NavigatorBase&, ExceptionState&);
explicit BucketManager(NavigatorBase&);
~BucketManager() override = default;
ScriptPromise openOrCreate(ScriptState* script_state,
const String& name,
ExceptionState& exception_state);
ScriptPromise keys(ScriptState* script_state,
ExceptionState& exception_state);
ScriptPromise Delete(ScriptState* script_state,
const String& name,
ExceptionState& exception_state);
void Trace(Visitor*) const override;
private:
// TODO(ayui): Temporary list of bucket names. This information will be
// obtained from the browser process in the future.
Vector<String> bucket_list_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_BUCKETS_BUCKET_MANAGER_H_
| 35.884615 | 80 | 0.73955 |
a772cbb22933d9afd420ec78ddd1faaf78ab16be | 102 | h | C | include/linalg.h | PavlenkoDR/linalg | 5756ab5b74ca9569307dae6d428dd7c72c10c46f | [
"MIT"
] | null | null | null | include/linalg.h | PavlenkoDR/linalg | 5756ab5b74ca9569307dae6d428dd7c72c10c46f | [
"MIT"
] | null | null | null | include/linalg.h | PavlenkoDR/linalg | 5756ab5b74ca9569307dae6d428dd7c72c10c46f | [
"MIT"
] | null | null | null | #ifndef LINALG_H
#define LINALG_H
#include "matrix.h"
#include "vector.h"
#endif // LINALG_H
| 12.75 | 20 | 0.676471 |
68514e3fb63a7254305c3b397fd1d899b0f50ae0 | 413 | h | C | SmartRationSmartAdjustHeuristicPerson.h | wbhoenig/MicroWorld | 89c91b3f66645904cbb2570aceea0ac7f19a960c | [
"MIT"
] | null | null | null | SmartRationSmartAdjustHeuristicPerson.h | wbhoenig/MicroWorld | 89c91b3f66645904cbb2570aceea0ac7f19a960c | [
"MIT"
] | null | null | null | SmartRationSmartAdjustHeuristicPerson.h | wbhoenig/MicroWorld | 89c91b3f66645904cbb2570aceea0ac7f19a960c | [
"MIT"
] | null | null | null | #ifndef SMART_RATION_SMART_ADJUST_HEURISTIC_PERSON_H
#define SMART_RATION_SMART_ADJUST_HEURISTIC_PERSON_H
#include "SmartAdjust.h"
#include "SmartRation.h"
#include "SmartWTP.h"
class SmartRationSmartAdjustHeuristicPerson :
public SmartRation, public SmartAdjust, public SmartWTP {
public:
SmartRationSmartAdjustHeuristicPerson();
SmartRationSmartAdjustHeuristicPerson(const PersonBase& other);
};
#endif
| 22.944444 | 64 | 0.845036 |
be2afacd38024f406d02981da8fd20205fa8bf27 | 2,166 | h | C | src/OpcUaStackCore/SecureChannel/MessageHeader.h | gianricardo/OpcUaStack | ccdef574175ffe8b7e82b886abc5e5403968b280 | [
"Apache-2.0"
] | 108 | 2018-10-08T17:03:32.000Z | 2022-03-21T00:52:26.000Z | src/OpcUaStackCore/SecureChannel/MessageHeader.h | gianricardo/OpcUaStack | ccdef574175ffe8b7e82b886abc5e5403968b280 | [
"Apache-2.0"
] | 287 | 2018-09-18T14:59:12.000Z | 2022-01-13T12:28:23.000Z | src/OpcUaStackCore/SecureChannel/MessageHeader.h | gianricardo/OpcUaStack | ccdef574175ffe8b7e82b886abc5e5403968b280 | [
"Apache-2.0"
] | 32 | 2018-10-19T14:35:03.000Z | 2021-11-12T09:36:46.000Z | /*
Copyright 2015-2018 Kai Huebl (kai@huebl-sgh.de)
Lizenziert gemäß Apache Licence Version 2.0 (die „Lizenz“); Nutzung dieser
Datei nur in Übereinstimmung mit der Lizenz erlaubt.
Eine Kopie der Lizenz erhalten Sie auf http://www.apache.org/licenses/LICENSE-2.0.
Sofern nicht gemäß geltendem Recht vorgeschrieben oder schriftlich vereinbart,
erfolgt die Bereitstellung der im Rahmen der Lizenz verbreiteten Software OHNE
GEWÄHR ODER VORBEHALTE – ganz gleich, ob ausdrücklich oder stillschweigend.
Informationen über die jeweiligen Bedingungen für Genehmigungen und Einschränkungen
im Rahmen der Lizenz finden Sie in der Lizenz.
Autor: Kai Huebl (kai@huebl-sgh.de)
*/
#ifndef __OpcUaStackCore_MessageHeader_h__
#define __OpcUaStackCore_MessageHeader_h__
#include "OpcUaStackCore/Base/ObjectPool.h"
#include "OpcUaStackCore/Base/os.h"
#include "OpcUaStackCore/BuildInTypes/OpcUaNumber.h"
namespace OpcUaStackCore
{
typedef enum {
MessageType_Unknown,
MessageType_Hello,
MessageType_Acknowledge,
MessageType_OpenSecureChannel,
MessageType_CloseSecureChannel,
MessageType_Error,
MessageType_Message
} MessageType;
class DLLEXPORT MessageHeader
: public Object
{
public:
typedef boost::shared_ptr<MessageHeader> SPtr;
MessageHeader(void);
virtual ~MessageHeader(void);
const char* messageTypeString(void);
void messageType(const MessageType& messageType);
MessageType messageType(void) const;
void messageSize(const OpcUaUInt32& messageSize);
OpcUaInt32 messageSize(void) const;
void segmentFlag(char segmentFlag);
char segmentFlag(void);
void channelId(uint32_t channelId);
uint32_t channelId(void);
void opcUaBinaryEncode(std::ostream& os, bool full = false) const;
void opcUaBinaryEncodeChannelId(std::ostream& os) const;
void opcUaBinaryDecode(std::istream& is, bool full = false);
void opcUaBinaryDecodeChannelId(std::istream& is);
private:
char messageTypeString_[3];
char segmentFlag_;
MessageType messageType_;
OpcUaUInt32 messageSize_;
OpcUaUInt32 channelId_;
};
}
#endif
| 29.27027 | 87 | 0.755309 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.