added
stringdate 2024-11-18 17:54:19
2024-11-19 03:39:31
| created
timestamp[s]date 1970-01-01 00:04:39
2023-09-06 04:41:57
| id
stringlengths 40
40
| metadata
dict | source
stringclasses 1
value | text
stringlengths 13
8.04M
| score
float64 2
4.78
| int_score
int64 2
5
|
---|---|---|---|---|---|---|---|
2024-11-18T21:06:08.930181+00:00 | 2021-08-29T08:52:35 | 39cd01416c46fb798ae4937017bc9ac919988a3e | {
"blob_id": "39cd01416c46fb798ae4937017bc9ac919988a3e",
"branch_name": "refs/heads/main",
"committer_date": "2021-08-29T08:52:35",
"content_id": "e591adbd4aced9f405e255f4cc54c176a6d12702",
"detected_licenses": [
"MIT"
],
"directory_id": "8af1e3937a84eb62875c44f2bbf230c27b51c4b2",
"extension": "c",
"filename": "ABitReader.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 4391,
"license": "MIT",
"license_type": "permissive",
"path": "/AVTools/Tools/ABitReader/ABitReader.c",
"provenance": "stackv2-0083.json.gz:15689",
"repo_name": "piaoxue85/AVTools",
"revision_date": "2021-08-29T08:52:35",
"revision_id": "cd04e54036576c479debbb1f8cbefeceb0c16db9",
"snapshot_id": "cbcfc5f50b5e98040fa66153cd3df55b891ee49e",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/piaoxue85/AVTools/cd04e54036576c479debbb1f8cbefeceb0c16db9/AVTools/Tools/ABitReader/ABitReader.c",
"visit_date": "2023-07-15T21:27:15.149575"
} | stackv2 | /*
* MpegtTS Basic Parser
* Copyright (c) jeoliva, All rights reserved.
* 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 3.0 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.
*/
#include "ABitReader.h"
/**
* 初始化 ABitReader
* @param bitReader ABitReader Instance
* @param data 待读取数据指针
* @param size 待读取数据大小
*/
void initABitReader(ABitReader *bitReader, uint8_t *data, size_t size) {
bitReader->mData = data;
bitReader->mSize = size;
bitReader->mReservoir = 0;
bitReader->mNumBitsLeft = 0;
}
/**
* 填充已读缓冲区
* @param bitReader ABitReader Instance
*/
void fillReservoir(ABitReader *bitReader) {
// 已读缓冲区置0
bitReader->mReservoir = 0;
size_t i = 0;
// 向已读缓冲区读入数据 尝试读取4字节
for (i = 0; bitReader->mSize > 0 && i < 4; ++i) {
// 每次读取前 先将mReservoir左移8位 将待读数据在内存低位的字节读到 mReservoir 的高位
bitReader->mReservoir = (bitReader->mReservoir << 8) | *(bitReader->mData);
// 待读取指针前移一字节
++bitReader->mData;
// 待读取数据大小减一
--bitReader->mSize;
}
// 记录已读缓冲区有效位数
bitReader->mNumBitsLeft = 8 * i;
// 如果4字节没读满 将剩余位数左移
bitReader->mReservoir <<= 32 - bitReader->mNumBitsLeft;
}
/**
* 已读缓冲区高位插入数据
* @param bitReader ABitReader Instance
* @param x data
* @param n bit count
*/
void putBits(ABitReader *bitReader, uint32_t x, size_t n) {
bitReader->mReservoir = (bitReader->mReservoir >> n) | (x << (32 - n));
bitReader->mNumBitsLeft += n;
}
/**
* 从已读缓冲区读取n位
* @param bitReader ABitReader Instance
* @param n bit count
*/
uint32_t getBits(ABitReader *bitReader, size_t n) {
uint32_t result = 0;
// 开始循环读取 直到n为0
while (n > 0) {
// 如果已读缓冲区没有数据 重新读取
if (bitReader->mNumBitsLeft == 0) {
fillReservoir(bitReader);
}
size_t m = n;
// 如果已读缓冲区剩余位数小于需要的位数 则本次只读取已读缓冲区剩余大小 下次进入循环重新填充已读缓冲区
if (m > bitReader->mNumBitsLeft) {
m = bitReader->mNumBitsLeft;
}
// result先左移m位给本次读取留位置 mReservoir 右移将高位的m位对齐result的低位m位
result = (result << m) | (bitReader->mReservoir >> (32 - m));
// m位读取完成 将 mReservoir 左移m位 有效位数mNumBitsLeft减去m位
bitReader->mReservoir <<= m;
bitReader->mNumBitsLeft -= m;
// n减去已读m位 如果还有剩余 进入下个循环
n -= m;
}
return result;
}
/**
* 从已读缓冲区跳过n位
* @param bitReader ABitReader Instance
* @param n bit count
*/
void skipBits(ABitReader *bitReader, size_t n) {
// bitReader->mReservoir 容量只有32位
while (n > 32) {
getBits(bitReader, 32);
n -= 32;
}
if (n > 0) {
getBits(bitReader, n);
}
}
/**
* 获取剩余数据大小
* @param bitReader ABitReader Instance
* @return 待读取数据和已读缓冲区数据大小总和
*/
size_t numBitsLeft(ABitReader *bitReader) {
return bitReader->mSize * 8 + bitReader->mNumBitsLeft;
}
/**
* 获取当前数据在待读取数据中的指针位置
* @param bitReader ABitReader Instance
* @return 返回已读缓冲区当前数据在待读取数据中的位置指针
*/
uint8_t *getBitReaderData(ABitReader *bitReader) {
return bitReader->mData - bitReader->mNumBitsLeft / 8;
}
| 2.859375 | 3 |
2024-11-18T21:06:09.186288+00:00 | 2017-05-10T09:50:21 | 2066e0e9743ff6283152ebe98eb944a11ba6659c | {
"blob_id": "2066e0e9743ff6283152ebe98eb944a11ba6659c",
"branch_name": "refs/heads/arm",
"committer_date": "2017-05-10T14:22:48",
"content_id": "222f24491dc464eb03d60c7114799ba74b25cfa9",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "6af50a4b5b928211880dd9f1c6ce92c2afea828b",
"extension": "c",
"filename": "ieee802154_shell.c",
"fork_events_count": 0,
"gha_created_at": "2016-12-16T09:52:08",
"gha_event_created_at": "2020-02-04T19:16:46",
"gha_language": "C",
"gha_license_id": "Apache-2.0",
"github_id": 76642373,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 9403,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/subsys/net/ip/l2/ieee802154/ieee802154_shell.c",
"provenance": "stackv2-0083.json.gz:15945",
"repo_name": "erwango/zephyr",
"revision_date": "2017-05-10T09:50:21",
"revision_id": "162f4574c781ae17d3fecfd4ac10df111e90ae3c",
"snapshot_id": "1c7aa447f613de76439291ba9dde1e4dc7c5786e",
"src_encoding": "UTF-8",
"star_events_count": 6,
"url": "https://raw.githubusercontent.com/erwango/zephyr/162f4574c781ae17d3fecfd4ac10df111e90ae3c/subsys/net/ip/l2/ieee802154/ieee802154_shell.c",
"visit_date": "2023-08-11T10:29:20.031948"
} | stackv2 | /*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief IEEE 802.15.4 shell module
*/
#include <zephyr.h>
#include <stdio.h>
#include <stdlib.h>
#include <shell/shell.h>
#include <misc/printk.h>
#include <net/net_if.h>
#include <net/ieee802154.h>
#include "ieee802154_mgmt.h"
#include "ieee802154_frame.h"
#define IEEE802154_SHELL_MODULE "ieee15_4"
struct ieee802154_req_params params;
static struct net_mgmt_event_callback scan_cb;
static int shell_cmd_ack(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
if (!strcmp(argv[1], "set") || !strcmp(argv[1], "1")) {
net_mgmt(NET_REQUEST_IEEE802154_SET_ACK, iface, NULL, 0);
printk("ACK flag set on outgoing packets\n");
return 0;
}
if (!strcmp(argv[1], "unset") || !strcmp(argv[1], "0")) {
net_mgmt(NET_REQUEST_IEEE802154_SET_ACK, iface, NULL, 0);
printk("ACK flag unset on outgoing packets\n");
return 0;
}
return -EINVAL;
}
static inline void parse_extended_address(char *addr, u8_t *ext_addr)
{
char *p, *n;
int i = 0;
p = addr;
do {
n = strchr(p, ':');
if (n) {
*n = '\0';
}
ext_addr[i] = strtol(p, NULL, 16);
p = n ? n + 1 : n;
} while (n);
}
static int shell_cmd_associate(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
params.pan_id = atoi(argv[1]);
if (strlen(argv[2]) == 23) {
parse_extended_address(argv[2], params.addr);
params.len = IEEE802154_EXT_ADDR_LENGTH;
} else {
params.short_addr = (u16_t) atoi(argv[2]);
params.len = IEEE802154_SHORT_ADDR_LENGTH;
}
if (net_mgmt(NET_REQUEST_IEEE802154_ASSOCIATE, iface,
¶ms, sizeof(struct ieee802154_req_params))) {
printk("Could not associate to %s on PAN ID %u\n",
argv[2], params.pan_id);
} else {
printk("Associated to PAN ID %u\n", params.pan_id);
}
return 0;
}
static int shell_cmd_disassociate(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
int ret;
ret = net_mgmt(NET_REQUEST_IEEE802154_DISASSOCIATE, iface, NULL, 0);
if (ret == -EALREADY) {
printk("Interface is not associated\n");
} else if (ret) {
printk("Could not disassociate? (status: %i)\n", ret);
} else {
printk("Interface is now disassociated\n");
}
return 0;
}
static inline u32_t parse_channel_set(char *str_set)
{
u32_t channel_set = 0;
char *p, *n;
p = str_set;
do {
u32_t chan;
n = strchr(p, ':');
if (n) {
*n = '\0';
}
chan = atoi(p);
channel_set |= BIT(chan - 1);
p = n ? n + 1 : n;
} while (n);
return channel_set;
}
static inline void print_coordinator_address(void)
{
if (params.len == IEEE802154_EXT_ADDR_LENGTH) {
int i;
printk("(extended) ");
for (i = 0; i < IEEE802154_EXT_ADDR_LENGTH; i++) {
printk("%02X", params.addr[i]);
if (i < (IEEE802154_EXT_ADDR_LENGTH - 1)) {
printk(":");
}
}
} else {
printk("(short) %u", params.short_addr);
}
}
static void scan_result_cb(struct net_mgmt_event_callback *cb,
u32_t mgmt_event, struct net_if *iface)
{
printk("\nChannel: %u\tPAN ID: %u\tCoordinator Address: ",
params.channel, params.pan_id);
print_coordinator_address();
printk("LQI: %u\n", params.lqi);
}
static int shell_cmd_scan(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u32_t scan_type;
int ret;
memset(¶ms, 0, sizeof(struct ieee802154_req_params));
net_mgmt_init_event_callback(&scan_cb, scan_result_cb,
NET_EVENT_IEEE802154_SCAN_RESULT);
if (!strcmp(argv[1], "active")) {
scan_type = NET_REQUEST_IEEE802154_ACTIVE_SCAN;
} else if (!strcmp(argv[1], "passive")) {
scan_type = NET_REQUEST_IEEE802154_PASSIVE_SCAN;
} else {
return -EINVAL;
}
if (!strcmp(argv[2], "all")) {
params.channel_set = IEEE802154_ALL_CHANNELS;
} else {
params.channel_set = parse_channel_set(argv[2]);
}
if (!params.channel_set) {
return -EINVAL;
}
params.duration = atoi(argv[3]);
printk("%s Scanning (channel set: 0x%08x, duration %u ms)...",
scan_type == NET_REQUEST_IEEE802154_ACTIVE_SCAN ?
"Active" : "Passive", params.channel_set, params.duration);
if (scan_type == NET_REQUEST_IEEE802154_ACTIVE_SCAN) {
ret = net_mgmt(NET_REQUEST_IEEE802154_ACTIVE_SCAN, iface,
¶ms, sizeof(struct ieee802154_req_params));
} else {
ret = net_mgmt(NET_REQUEST_IEEE802154_PASSIVE_SCAN, iface,
¶ms, sizeof(struct ieee802154_req_params));
}
if (ret) {
printk("Could not raise a scan (status: %i)\n", ret);
} else {
printk("Done\n");
}
return 0;
}
static int shell_cmd_set_chan(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t channel = (u16_t) atoi(argv[1]);
if (net_mgmt(NET_REQUEST_IEEE802154_SET_CHANNEL, iface,
&channel, sizeof(u16_t))) {
printk("Could not set channel %u\n", channel);
} else {
printk("Channel %u set\n", channel);
}
return 0;
}
static int shell_cmd_get_chan(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t channel;
if (net_mgmt(NET_REQUEST_IEEE802154_GET_CHANNEL, iface,
&channel, sizeof(u16_t))) {
printk("Could not get channel\n");
} else {
printk("Channel %u\n", channel);
}
return 0;
}
static int shell_cmd_set_pan_id(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t pan_id = (u16_t) atoi(argv[1]);
if (net_mgmt(NET_REQUEST_IEEE802154_SET_PAN_ID, iface,
&pan_id, sizeof(u16_t))) {
printk("Could not set PAN ID %u\n", pan_id);
} else {
printk("PAN ID %u set\n", pan_id);
}
return 0;
}
static int shell_cmd_get_pan_id(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t pan_id;
if (net_mgmt(NET_REQUEST_IEEE802154_GET_PAN_ID, iface,
&pan_id, sizeof(u16_t))) {
printk("Could not get PAN ID\n");
} else {
printk("PAN ID %u\n", pan_id);
}
return 0;
}
static int shell_cmd_set_ext_addr(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
if (strlen(argv[2]) != 23) {
printk("23 characters needed\n");
return 0;
}
parse_extended_address(argv[2], addr);
if (net_mgmt(NET_REQUEST_IEEE802154_SET_EXT_ADDR, iface,
addr, IEEE802154_EXT_ADDR_LENGTH)) {
printk("Could not set extended address\n");
} else {
printk("Extended address %s set\n", argv[2]);
}
return 0;
}
static int shell_cmd_get_ext_addr(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u8_t addr[IEEE802154_EXT_ADDR_LENGTH];
if (net_mgmt(NET_REQUEST_IEEE802154_GET_EXT_ADDR, iface,
addr, IEEE802154_EXT_ADDR_LENGTH)) {
printk("Could not get extended address\n");
} else {
int i;
printk("Extended address: ");
for (i = 0; i < IEEE802154_EXT_ADDR_LENGTH; i++) {
printk("%02X", addr[i]);
if (i < (IEEE802154_EXT_ADDR_LENGTH - 1)) {
printk(":");
}
}
printk("\n");
}
return 0;
}
static int shell_cmd_set_short_addr(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t short_addr = (u16_t) atoi(argv[1]);
if (net_mgmt(NET_REQUEST_IEEE802154_SET_SHORT_ADDR, iface,
&short_addr, sizeof(u16_t))) {
printk("Could not set short address %u\n", short_addr);
} else {
printk("Short address %u set\n", short_addr);
}
return 0;
}
static int shell_cmd_get_short_addr(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
u16_t short_addr;
if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface,
&short_addr, sizeof(u16_t))) {
printk("Could not get short address\n");
} else {
printk("Short address %u\n", short_addr);
}
return 0;
}
static int shell_cmd_set_tx_power(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
s16_t tx_power = (s16_t) atoi(argv[1]);
if (net_mgmt(NET_REQUEST_IEEE802154_SET_TX_POWER, iface,
&tx_power, sizeof(s16_t))) {
printk("Could not set TX power %d\n", tx_power);
} else {
printk("TX power %d set\n", tx_power);
}
return 0;
}
static int shell_cmd_get_tx_power(int argc, char *argv[])
{
struct net_if *iface = net_if_get_default();
s16_t tx_power;
if (net_mgmt(NET_REQUEST_IEEE802154_GET_SHORT_ADDR, iface,
&tx_power, sizeof(s16_t))) {
printk("Could not get TX power\n");
} else {
printk("TX power (in dbm) %d\n", tx_power);
}
return 0;
}
static struct shell_cmd ieee802154_commands[] = {
{ "ack", shell_cmd_ack,
"<set/1 | unset/0>" },
{ "associate", shell_cmd_associate,
"<pan_id> <PAN coordinator short or long address>" },
{ "disassociate", shell_cmd_disassociate,
NULL },
{ "scan", shell_cmd_scan,
"<passive|active> <channels set n[:m:...]:x|all>"
" <per-channel duration in ms>" },
{ "set_chan", shell_cmd_set_chan,
"<channel>" },
{ "get_chan", shell_cmd_get_chan,
NULL },
{ "set_pan_id", shell_cmd_set_pan_id,
"<pan_id>" },
{ "get_pan_id", shell_cmd_get_pan_id,
NULL },
{ "set_ext_addr", shell_cmd_set_ext_addr,
"<long/extended address>" },
{ "get_ext_addr", shell_cmd_get_ext_addr,
NULL },
{ "set_short_addr", shell_cmd_set_short_addr,
"<short address>" },
{ "get_short_addr", shell_cmd_get_short_addr,
NULL },
{ "set_tx_power", shell_cmd_set_tx_power,
"<-18/-7/-4/-2/0/1/2/3/5>" },
{ "get_tx_power", shell_cmd_get_tx_power,
NULL },
{ NULL, NULL, NULL },
};
void ieee802154_shell_init(void)
{
SHELL_REGISTER(IEEE802154_SHELL_MODULE, ieee802154_commands);
}
| 2.4375 | 2 |
2024-11-18T21:06:09.421843+00:00 | 2019-04-20T18:08:43 | 185ed9a9f4ae154da9099c23e03939e45d0e1182 | {
"blob_id": "185ed9a9f4ae154da9099c23e03939e45d0e1182",
"branch_name": "refs/heads/master",
"committer_date": "2019-04-20T18:08:43",
"content_id": "f40dc533f2ade72d361d56fd68dfca69ed02cc40",
"detected_licenses": [
"MIT"
],
"directory_id": "c5f67a63e73364fb7471bdbbd8feef1b5f7fb2b9",
"extension": "h",
"filename": "semanter.h",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 140074404,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1205,
"license": "MIT",
"license_type": "permissive",
"path": "/include/semanter.h",
"provenance": "stackv2-0083.json.gz:16204",
"repo_name": "loreloc/yog-lang",
"revision_date": "2019-04-20T18:08:43",
"revision_id": "1295a58daebca595408af146c52efa5349493e6c",
"snapshot_id": "3d80a1abe33187783b1424c360dded1bf2271c8d",
"src_encoding": "UTF-8",
"star_events_count": 5,
"url": "https://raw.githubusercontent.com/loreloc/yog-lang/1295a58daebca595408af146c52efa5349493e6c/include/semanter.h",
"visit_date": "2020-03-22T12:58:33.409309"
} | stackv2 |
/*! @file semanter.h */
#pragma once
#include "ast.h"
#include "error.h"
#include "instruction.h"
/*! @brief The semantic context data structure */
struct semantic_context
{
/*! @brief A pointer to the symbol table to modify */
struct symbol_table *st;
/*! @brief A pointer to an error list */
struct error_list *errs;
/*! @brief A pointer to the abstract syntax tree to analyse */
struct ast *tree;
/*! @brief The instruction list of the current statement */
struct instruction_list instrs;
/*! @brief The number of temporary variables */
size_t tmp_cnt;
};
/**
* @brief Initialize a semantic context
* @param ctx A pointer to the semantic context to initialize
* @param st A pointer to the symbol table to modify
* @param errs A pointer to the error list
* @param tree The abstract syntax tree to analyse
*/
void semantic_context_init(struct semantic_context *ctx, struct symbol_table *st, struct error_list *errs, struct ast *tree);
/**
* @brief Analyse the abstract syntax tree holded by the semantic context
* @param ctx A pointer to the semantic context
* @return The instruction list
*/
struct instruction_list semantic_context_analyse(struct semantic_context *ctx);
| 2.5 | 2 |
2024-11-18T21:06:10.190495+00:00 | 2015-07-21T23:24:45 | 35b46380fbf8ca552d1e5d97703aae1e4d23755a | {
"blob_id": "35b46380fbf8ca552d1e5d97703aae1e4d23755a",
"branch_name": "refs/heads/master",
"committer_date": "2015-07-21T23:24:45",
"content_id": "8d1af20121f3635a6a5a82078cfe8bf6e914d5df",
"detected_licenses": [
"CC0-1.0"
],
"directory_id": "93b791e656c439a65f5c6ae1a48315b7ab89886d",
"extension": "h",
"filename": "parallel_structures.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 34863729,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2080,
"license": "CC0-1.0",
"license_type": "permissive",
"path": "/HCA_Paralelo/parallel_structures.h",
"provenance": "stackv2-0083.json.gz:16589",
"repo_name": "svaigen/HCA_Paralelo",
"revision_date": "2015-07-21T23:24:45",
"revision_id": "24537f4e27f79d70eef4143c0ece49b93aa41af7",
"snapshot_id": "c60d25f9f922d044ad19d0a0289f5ec1ed921155",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/svaigen/HCA_Paralelo/24537f4e27f79d70eef4143c0ece49b93aa41af7/HCA_Paralelo/parallel_structures.h",
"visit_date": "2021-01-16T20:36:01.209002"
} | stackv2 | /*
* File: parallel_structures.h
* Author: svaigen
*
* Created on May 4, 2015, 3:38 PM
*/
#ifndef PARALLEL_STRUCTURES_H
#define PARALLEL_STRUCTURES_H
#include <semaphore.h>
#include <pthread.h>
#include "color.h"
#define MAX_TAM_BUFFER_TAREFAS 512
#define MAX_TAM_BUFFER_INDIVIDUOS 512
struct struct_buffer_tarefas {
gcp_solution_t* buffer[MAX_TAM_BUFFER_TAREFAS];
int buffer_parents[MAX_TAM_BUFFER_TAREFAS * 2];
int pos_remocao;
int pos_insercao;
int fim_fisico;
};
struct struct_buffer_individuos {
gcp_solution_t* buffer[MAX_TAM_BUFFER_INDIVIDUOS];
int buffer_parents[MAX_TAM_BUFFER_INDIVIDUOS * 2];
int fim_logico;
int pos_insercao;
};
struct struct_individuos_melhorados {
gcp_solution_t *individuo;
int parent1;
int parent2;
};
typedef struct struct_buffer_tarefas struct_buffer_tarefas;
typedef struct struct_buffer_individuos struct_buffer_individuos;
typedef struct struct_individuos_melhorados struct_individuos_melhorados;
sem_t sem_mutex_tarefas;
sem_t sem_is_cheio_tarefas;
sem_t sem_is_vazio_tarefas;
sem_t sem_mutex_individuos;
sem_t sem_preenche_individuos;
sem_t sem_atualiza_populacao;
sem_t sem_mutex_populacao;
void buffer_tarefas_inicializa(int tamanho, struct_buffer_tarefas* b);
void buffer_tarefas_add(struct_buffer_tarefas* b, gcp_solution_t *s, int parent1, int parent2);
void buffer_tarefas_remove(struct_buffer_tarefas* b, gcp_solution_t* dst);
void buffer_tarefas_get_parents(struct_buffer_tarefas *b, int pos, int *parent1, int *parent2);
void buffer_individuos_inicializa(int tamanho, struct_buffer_individuos* b);
void buffer_individuos_add(struct_buffer_individuos* b, gcp_solution_t *s, int parent1, int parent2);
void buffer_individuos_esvazia(struct_buffer_individuos* b);
void buffer_individuos_get_parents(struct_buffer_individuos *b, int pos, int *parent1, int *parent2);
int buffer_individuos_is_cheio(struct_buffer_individuos* b);
void buffer_individuos_seleciona_melhor(struct_buffer_individuos* b, struct_individuos_melhorados *best);
#endif /* PARALLEL_STRUCTURES_H */ | 2.171875 | 2 |
2024-11-18T21:06:10.290724+00:00 | 2012-10-29T19:20:39 | 230d4252e37652baf72853c59cf788014283ea92 | {
"blob_id": "230d4252e37652baf72853c59cf788014283ea92",
"branch_name": "refs/heads/master",
"committer_date": "2012-10-29T19:20:39",
"content_id": "200072b5fb8284a844d6adba738a4794c58dc6bb",
"detected_licenses": [
"BSD-2-Clause",
"BSD-3-Clause"
],
"directory_id": "edf2ae83355855968f058a3e1a4534fa6c112b9b",
"extension": "c",
"filename": "selftest.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 6446120,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 4720,
"license": "BSD-2-Clause,BSD-3-Clause",
"license_type": "permissive",
"path": "/tests/selftest.c",
"provenance": "stackv2-0083.json.gz:16717",
"repo_name": "developernotes/yubico-c",
"revision_date": "2012-10-29T19:20:39",
"revision_id": "246ac1dcf341a74e91642057dca9d16d3c777543",
"snapshot_id": "bbb8f20b537cce5de3701abebc1a13a9c2d434d1",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/developernotes/yubico-c/246ac1dcf341a74e91642057dca9d16d3c777543/tests/selftest.c",
"visit_date": "2021-01-17T17:15:35.085197"
} | stackv2 | /* yubikey-test.c --- Self-tests for authentication token functions.
*
* Written by Simon Josefsson <simon@josefsson.org>.
* Copyright (c) 2006-2012 Yubico AB
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <yubikey.h>
#include <stdio.h>
int
main (void)
{
char buf[1024];
size_t i;
int rc;
yubikey_token_st tok;
/* Test Modhex */
yubikey_modhex_encode (buf, "test", 4);
printf ("modhex-encode(\"test\") = %s\n", buf);
if (strcmp (buf, "ifhgieif") != 0)
{
printf ("ModHex failure\n");
return 1;
}
printf ("Modhex-1 success\n");
printf ("modhex-decode(\"%s\") = ", buf);
yubikey_modhex_decode (buf, buf, strlen ((char *) buf));
printf ("%.*s\n", 4, buf);
if (memcmp (buf, "test", 4) != 0)
{
printf ("ModHex failure\n");
return 1;
}
printf ("Modhex-2 success\n");
strcpy (buf, "cbdefghijklnrtuv");
rc = yubikey_modhex_p (buf);
printf ("hex-p(\"%s\") = %d\n", buf, rc);
if (!rc)
{
printf ("Hex_p failure\n");
return 1;
}
printf ("Hex-3 success\n");
strcpy (buf, "0123Xabc");
rc = yubikey_hex_p (buf);
printf ("hex-p(\"%s\") = %d\n", buf, rc);
if (rc)
{
printf ("Hex_p failure\n");
return 1;
}
printf ("Hex-3 success\n");
/* Test Hex */
yubikey_hex_encode (buf, "test", 4);
printf ("hex-encode(\"test\") = %s\n", buf);
if (strcmp (buf, "74657374") != 0)
{
printf ("Hex failure\n");
return 1;
}
printf ("Hex-1 success\n");
printf ("hex-decode(\"%s\") = ", buf);
yubikey_hex_decode (buf, buf, strlen ((char *) buf));
printf ("%.*s\n", 4, buf);
if (memcmp (buf, "test", 4) != 0)
{
printf ("Hex failure\n");
return 1;
}
printf ("Hex-2 success\n");
strcpy (buf, "0123456789abcdef");
rc = yubikey_hex_p (buf);
printf ("hex-p(\"%s\") = %d\n", buf, rc);
if (!rc)
{
printf ("Hex_p failure\n");
return 1;
}
printf ("Hex-3 success\n");
strcpy (buf, "0123Xabc");
rc = yubikey_hex_p (buf);
printf ("hex-p(\"%s\") = %d\n", buf, rc);
if (rc)
{
printf ("Hex_p failure\n");
return 1;
}
printf ("Hex-3 success\n");
/* Test AES */
{
uint8_t buf[1024];
char out[1024];
uint8_t key[16 + 1];
memcpy (buf, "0123456789abcdef\0", 17);
memcpy (key, "abcdef0123456789\0", 17);
printf ("aes-decrypt (data=%s, key=%s)\n => ", (char *) buf, (char *) key);
yubikey_aes_decrypt (buf, key);
for (i = 0; i < 16; i++)
printf ("%02x", buf[i] & 0xFF);
printf ("\n");
if (memcmp (buf,
"\x83\x8a\x46\x7f\x34\x63\x95\x51"
"\x75\x5b\xd3\x2a\x4a\x2f\x15\xe1", 16) != 0)
{
printf ("AES failure\n");
return 1;
}
printf ("AES-1 success\n");
yubikey_aes_encrypt (buf, key);
if (memcmp (buf, "0123456789abcdef", 16) != 0)
{
printf ("AES encryption failure\n");
return 1;
}
printf ("AES-2 success\n");
/* Test OTP */
memcpy ((void *) &tok,
"\x16\xe1\xe5\xd9\xd3\x99\x10\x04\x45\x20\x07\xe3\x02\x00\x00", 16);
memcpy (key, "abcdef0123456789", 16);
yubikey_generate ((void *) &tok, key, out);
yubikey_parse ((uint8_t *) out, key, &tok);
if (memcmp
(&tok, "\x16\xe1\xe5\xd9\xd3\x99\x10\x04\x45\x20\x07\xe3\x02\x00\x00",
16) != 0)
{
printf ("OTP generation - parse failure\n");
return 1;
}
printf ("OTP-1 success\n");
}
return 0;
}
| 2.03125 | 2 |
2024-11-18T21:06:10.389724+00:00 | 2021-09-17T00:57:55 | 81722f8db19cfcd5f4cb5724693874aea9308bd7 | {
"blob_id": "81722f8db19cfcd5f4cb5724693874aea9308bd7",
"branch_name": "refs/heads/main",
"committer_date": "2021-09-17T00:57:55",
"content_id": "d449a55cd6648cda9edc4e06b0b96578e26e4ca8",
"detected_licenses": [
"MIT"
],
"directory_id": "1a64ee0fb343890c455bff8d650932ab10d9dc88",
"extension": "c",
"filename": "vm.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 407360088,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 9047,
"license": "MIT",
"license_type": "permissive",
"path": "/assignment1-virtual-machine-net-pro/vm.c",
"provenance": "stackv2-0083.json.gz:16845",
"repo_name": "xNul/pl-0-compiler",
"revision_date": "2021-09-17T00:57:55",
"revision_id": "952e363961dfdef1b231b54d5ee2d6705042c1e5",
"snapshot_id": "8afc7956e030b85f6115161a41de1dc335cd923f",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/xNul/pl-0-compiler/952e363961dfdef1b231b54d5ee2d6705042c1e5/assignment1-virtual-machine-net-pro/vm.c",
"visit_date": "2023-08-16T22:55:45.669486"
} | stackv2 | #include <stdio.h>
#include "vm.h"
#include "data.h"
/* ************************************************************************************ */
/* Declarations */
/* ************************************************************************************ */
/**
* Recommended design includes the following functions implemented.
* However, you are free to change them as you wish inside the vm.c file.
* */
void initVM(VirtualMachine*);
int readInstructions(FILE*, Instruction*);
void dumpInstructions(FILE*, Instruction*, int numOfIns);
int getBasePointer(int *stack, int currentBP, int L);
void dumpStack(FILE*, int* stack, int sp, int bp);
int executeInstruction(VirtualMachine* vm, Instruction ins, FILE* vmIn, FILE* vmOut);
/* ************************************************************************************ */
/* Global Data and misc structs & enums */
/* ************************************************************************************ */
/**
* allows conversion from opcode to opcode string
* */
const char *opcodes[] =
{
"illegal", // opcode 0 is illegal
"lit", "rtn", "lod", "sto", "cal", // 1, 2, 3 ..
"inc", "jmp", "jpc", "sio", "sio",
"sio", "neg", "add", "sub", "mul",
"div", "odd", "mod", "eql", "neq",
"lss", "leq", "gtr", "geq"
};
enum { CONT, HALT };
/* ************************************************************************************ */
/* Definitions */
/* ************************************************************************************ */
/**
* Initialize Virtual Machine
* */
void initVM(VirtualMachine* vm)
{
if(vm)
{
vm->BP = 1;
// All other variables are automatically initialized to 0 in C
}
}
/**
* Fill the (ins)tructions array by reading instructions from (in)put file
* Return the number of instructions read
* */
int readInstructions(FILE* in, Instruction* ins)
{
// Instruction index
int i = 0;
while(fscanf(in, "%d %d %d %d", &ins[i].op, &ins[i].r, &ins[i].l, &ins[i].m) != EOF)
{
i++;
}
// Return the number of instructions read
return i;
}
/**
* Dump instructions to the output file
* */
void dumpInstructions(FILE* out, Instruction* ins, int numOfIns)
{
// Header
fprintf(out,
"***Code Memory***\n%3s %3s %3s %3s %3s \n",
"#", "OP", "R", "L", "M"
);
// Instructions
int i;
for(i = 0; i < numOfIns; i++)
{
fprintf(
out,
"%3d %3s %3d %3d %3d \n", // formatting
i, opcodes[ins[i].op], ins[i].r, ins[i].l, ins[i].m
);
}
}
/**
* Returns the base pointer for the lexiographic level L
* */
int getBasePointer(int *stack, int currentBP, int L)
{
// Based off of syllabus example. (Appendix D)
int b1 = currentBP;
// Iterate L levels down until we retrieve our desired b1 (base)
while (L > 0)
{
b1 = stack[b1 + 1];
L--;
}
return b1;
}
// Function that dumps the whole stack into output file
// Do not forget to use '|' character between stack frames
void dumpStack(FILE* out, int* stack, int sp, int bp)
{
if(bp == 0)
return;
// bottom-most level, where a single zero value lies
if(bp == 1)
{
fprintf(out, "%3d ", 0);
}
// former levels - if exists
if(bp != 1)
{
dumpStack(out, stack, bp - 1, stack[bp + 2]);
}
// top level: current activation record
if(bp <= sp)
{
// indicate a new activation record
fprintf(out, "| ");
// print the activation record
int i;
for(i = bp; i <= sp; i++)
{
fprintf(out, "%3d ", stack[i]);
}
}
}
/**
* Executes the (ins)truction on the (v)irtual (m)achine.
* This changes the state of the virtual machine.
* Returns HALT if the executed instruction was meant to halt the VM.
* .. Otherwise, returns CONT
* */
int executeInstruction(VirtualMachine* vm, Instruction ins, FILE* vmIn, FILE* vmOut)
{
switch(ins.op)
{
case 1:
vm->RF[ins.r] = ins.m;
break;
case 2:
vm->SP = vm->BP-1;
vm->BP = vm->stack[vm->SP+3];
vm->PC = vm->stack[vm->SP+4];
break;
case 3:
vm->RF[ins.r] = vm->stack[getBasePointer(vm->stack, vm->BP, ins.l)+ins.m];
break;
case 4:
vm->stack[getBasePointer(vm->stack, vm->BP, ins.l)+ins.m] = vm->RF[ins.r];
break;
case 5:
vm->stack[vm->SP+1] = 0;
vm->stack[vm->SP+2] = getBasePointer(vm->stack, vm->BP, ins.l);
vm->stack[vm->SP+3] = vm->BP;
vm->stack[vm->SP+4] = vm->PC;
vm->BP = vm->SP+1;
vm->PC = ins.m;
break;
case 6:
vm->SP = vm->SP+ins.m;
break;
case 7:
vm->PC = ins.m;
break;
case 8:
if (vm->RF[ins.r] == 0)
{
vm->PC = ins.m;
}
break;
case 9:
fprintf(vmOut, "%d ", vm->RF[ins.r]);
break;
case 10:
fscanf(vmIn, "%d", &(vm->RF[ins.r]));
break;
case 11:
return HALT;
case 12:
vm->RF[ins.r] = -vm->RF[ins.l];
break;
case 13:
vm->RF[ins.r] = (vm->RF[ins.l] + vm->RF[ins.m]);
break;
case 14:
vm->RF[ins.r] = (vm->RF[ins.l] - vm->RF[ins.m]);
break;
case 15:
vm->RF[ins.r] = (vm->RF[ins.l] * vm->RF[ins.m]);
break;
case 16:
vm->RF[ins.r] = (vm->RF[ins.l] / vm->RF[ins.m]);
break;
case 17:
vm->RF[ins.r] = vm->RF[ins.r] % 2; // 1 if Odd, 0 if even
break;
case 18:
vm->RF[ins.r] = (vm->RF[ins.l] % vm->RF[ins.m]);
break;
case 19:
vm->RF[ins.r] = (vm->RF[ins.l] == vm->RF[ins.m]);
break;
case 20:
vm->RF[ins.r] = (vm->RF[ins.l] != vm->RF[ins.m]);
break;
case 21:
vm->RF[ins.r] = (vm->RF[ins.l] < vm->RF[ins.m]);
break;
case 22:
vm->RF[ins.r] = (vm->RF[ins.l] <= vm->RF[ins.m]);
break;
case 23:
vm->RF[ins.r] = (vm->RF[ins.l] > vm->RF[ins.m]);
break;
case 24:
vm->RF[ins.r] = (vm->RF[ins.l] >= vm->RF[ins.m]);
break;
default:
fprintf(stderr, "Illegal instruction?");
return HALT;
}
return CONT;
}
/**
* inp: The FILE pointer containing the list of instructions to
* be loaded to code memory of the virtual machine.
*
* outp: The FILE pointer to write the simulation output, which
* contains both code memory and execution history.
*
* vm_inp: The FILE pointer that is going to be attached as the input
* stream to the virtual machine. Useful to feed input for SIO
* instructions.
*
* vm_outp: The FILE pointer that is going to be attached as the output
* stream to the virtual machine. Useful to save the output printed
* by SIO instructions.
* */
void simulateVM(
FILE* inp,
FILE* outp,
FILE* vm_inp,
FILE* vm_outp
)
{
// Read instructions from file
Instruction ins[MAX_CODE_LENGTH];
int insCount = readInstructions(inp, ins);
// Dump instructions to the output file
dumpInstructions(outp, ins, insCount);
// Before starting the code execution on the virtual machine,
// .. write the header for the simulation part (***Execution***)
fprintf(outp, "\n***Execution***\n");
fprintf(
outp,
"%3s %3s %3s %3s %3s %3s %3s %3s %3s \n", // formatting
"#", "OP", "R", "L", "M", "PC", "BP", "SP", "STK" // titles
);
// Create a virtual machine
VirtualMachine vm;
// Initialize the virtual machine
initVM(&vm);
// Fetch&Execute the instructions on the virtual machine until halting
int vmState = 0;
while(!vmState)
{
// Fetch
vm.IR = vm.PC;
// Advance PC - before execution!
vm.PC++;
// Execute the instruction
vmState = executeInstruction(&vm, ins[vm.IR], vm_inp, vm_outp);
// Print current state
fprintf(
outp,
"%3d %3s %3d %3d %3d %3d %3d %3d ",
vm.IR,
opcodes[ins[vm.IR].op], ins[vm.IR].r, ins[vm.IR].l, ins[vm.IR].m,
vm.PC, vm.BP, vm.SP
);
// Print stack info
dumpStack(outp, vm.stack, vm.SP, vm.BP);
fprintf(outp, "\n");
}
// Above loop ends when machine halts. Therefore, dump halt message.
fprintf(outp, "HLT\n");
return;
} | 2.96875 | 3 |
2024-11-18T21:06:10.476633+00:00 | 2023-08-09T18:19:32 | 1f7c27941f851e12a207914cf040174a84e844de | {
"blob_id": "1f7c27941f851e12a207914cf040174a84e844de",
"branch_name": "refs/heads/master",
"committer_date": "2023-08-09T18:19:32",
"content_id": "f8f368cd427936f29f5aa2396398be147adca276",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "a4a96286d9860e2661cd7c7f571d42bfa04c86cf",
"extension": "h",
"filename": "esp_spi_flash_counters.h",
"fork_events_count": 1,
"gha_created_at": "2020-01-23T18:05:37",
"gha_event_created_at": "2020-01-23T18:05:38",
"gha_language": null,
"gha_license_id": "Apache-2.0",
"github_id": 235855012,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1988,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/components/spi_flash/include/esp_spi_flash_counters.h",
"provenance": "stackv2-0083.json.gz:16973",
"repo_name": "KollarRichard/esp-idf",
"revision_date": "2023-08-09T18:19:32",
"revision_id": "3befd5fff72aa6980514454a50233037718b611f",
"snapshot_id": "1a3c314b37c763bdd231d974c9e16b9c7588e42c",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/KollarRichard/esp-idf/3befd5fff72aa6980514454a50233037718b611f/components/spi_flash/include/esp_spi_flash_counters.h",
"visit_date": "2023-08-16T20:32:50.823995"
} | stackv2 | /*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "sdkconfig.h"
#if CONFIG_SPI_FLASH_ENABLE_COUNTERS || defined __DOXYGEN__
#ifdef __cplusplus
extern "C" {
#endif
/**
* Structure holding statistics for one type of operation
*/
typedef struct {
uint32_t count; /*!< number of times operation was executed */
uint32_t time; /*!< total time taken, in microseconds */
uint32_t bytes; /*!< total number of bytes */
} esp_flash_counter_t;
/**
* Structure for counters of flash actions
*/
typedef struct {
esp_flash_counter_t read; /*!< counters for read action, like `esp_flash_read`*/
esp_flash_counter_t write; /*!< counters for write action, like `esp_flash_write`*/
esp_flash_counter_t erase; /*!< counters for erase action, like `esp_flash_erase`*/
} esp_flash_counters_t;
// for deprecate old api
typedef esp_flash_counter_t spi_flash_counter_t;
typedef esp_flash_counters_t spi_flash_counters_t;
/**
* @brief Reset SPI flash operation counters
*/
void esp_flash_reset_counters(void);
void spi_flash_reset_counters(void) __attribute__((deprecated("Please use 'esp_flash_reset_counters' instead")));
/**
* @brief Print SPI flash operation counters
*/
void esp_flash_dump_counters(FILE* stream);
void spi_flash_dump_counters(void) __attribute__((deprecated("Please use 'esp_flash_dump_counters' instead")));
/**
* @brief Return current SPI flash operation counters
*
* @return pointer to the esp_flash_counters_t structure holding values
* of the operation counters
*/
const esp_flash_counters_t* esp_flash_get_counters(void);
const spi_flash_counters_t* spi_flash_get_counters(void) __attribute__((deprecated("Please use 'esp_flash_get_counters' instead")));
#ifdef __cplusplus
}
#endif
#endif //CONFIG_SPI_FLASH_ENABLE_COUNTERS || defined __DOXYGEN__
| 2.140625 | 2 |
2024-11-18T21:06:11.177651+00:00 | 2016-03-24T19:58:32 | e16fdee23ff0f06db16fc6ba3cfd7770d5722869 | {
"blob_id": "e16fdee23ff0f06db16fc6ba3cfd7770d5722869",
"branch_name": "refs/heads/master",
"committer_date": "2016-03-24T19:58:32",
"content_id": "609cc902bd28ed9a25383c56a9d50275d29aa93d",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "fe397378a78ac7418091bc3ee606ff20ae8a66e3",
"extension": "c",
"filename": "hook.c",
"fork_events_count": 0,
"gha_created_at": "2015-09-18T16:11:09",
"gha_event_created_at": "2015-09-18T16:11:09",
"gha_language": null,
"gha_license_id": null,
"github_id": 42732829,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2209,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/loaders/hook/hook.c",
"provenance": "stackv2-0083.json.gz:17102",
"repo_name": "11111000000/lambdanative",
"revision_date": "2016-03-24T19:58:32",
"revision_id": "41dec16cb1cdcc57ccaa8993f797b8d8a9480706",
"snapshot_id": "840e0ba992e6e46ca2a39e1e8fa46234b393c77d",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/11111000000/lambdanative/41dec16cb1cdcc57ccaa8993f797b8d8a9480706/loaders/hook/hook.c",
"visit_date": "2020-12-24T12:00:36.127455"
} | stackv2 | // lambdanative hook
#include <stdio.h>
#include <stdlib.h>
#include <LNCONFIG.h>
//#define DEBUG_HOOK 1
#ifdef DEBUG_HOOK
#define DMSG(fmt...) (fprintf(stderr,"DEBUG_HOOK: " fmt),fprintf(stderr,"\n"))
#else
#define DMSG(fmt...)
#endif
// ---------------
// lambdanative payload bootstrap
#include <lambdanative.h>
void lambdanative_payload_setup(char *);
void lambdanative_payload_cleanup();
void lambdanative_payload_event(int,int,int);
void lambdanative_setup()
{
DMSG("lambdanative_setup");
system_init();
lambdanative_payload_setup(system_dir());
}
void lambdanative_cleanup()
{
DMSG("lambdanative_cleanup");
lambdanative_payload_cleanup();
}
// ---------------
#ifdef STANDALONE
// standalone setup
char **cmd_argv;
int cmd_argc=0;
int main(int argc, char *argv[])
{
cmd_argc=argc; cmd_argv=argv;
lambdanative_setup();
lambdanative_cleanup();
return 0;
}
#else
// event loop setup
#if defined(ANDROID) || defined(MACOSX) || defined(IOS) || defined(LINUX) || defined(OPENBSD) || defined(BB10) || defined(PLAYBOOK) || defined(NETBSD)
#include <pthread.h>
pthread_mutex_t ffi_event_lock;
#define FFI_EVENT_INIT pthread_mutex_init(&ffi_event_lock, 0);
#define FFI_EVENT_LOCK pthread_mutex_lock( &ffi_event_lock);
#define FFI_EVENT_UNLOCK pthread_mutex_unlock( &ffi_event_lock);
#else
#ifdef WIN32
#include <windows.h>
CRITICAL_SECTION ffi_event_cs;
#define FFI_EVENT_INIT InitializeCriticalSection(&ffi_event_cs);
#define FFI_EVENT_LOCK EnterCriticalSection(&ffi_event_cs);
#define FFI_EVENT_UNLOCK LeaveCriticalSection( &ffi_event_cs);
#else
static int ffi_event_lock;
#define FFI_EVENT_INIT ffi_event_lock=0;
#define FFI_EVENT_LOCK { while (ffi_event_lock) { }; ffi_event_lock=1; }
#define FFI_EVENT_UNLOCK ffi_event_lock=0;
#endif
#endif
void ffi_event(int t, int x, int y)
{
static int lambdanative_needsinit=1;
if (lambdanative_needsinit) {
lambdanative_setup();
FFI_EVENT_INIT
lambdanative_needsinit=0;
}
FFI_EVENT_LOCK
if (!lambdanative_needsinit&&t) lambdanative_payload_event(t,x,y);
if (t==EVENT_TERMINATE) { lambdanative_cleanup(); exit(0); }
FFI_EVENT_UNLOCK
}
#endif
// eof
| 2.359375 | 2 |
2024-11-18T21:06:11.955089+00:00 | 2020-01-22T00:11:27 | 59349ed817f1c2687f6d7a9b8e4b2105f7e0c39b | {
"blob_id": "59349ed817f1c2687f6d7a9b8e4b2105f7e0c39b",
"branch_name": "refs/heads/master",
"committer_date": "2020-01-22T00:11:27",
"content_id": "23a93ef8dc760ed8ecba34b98dd725883ec6d8f1",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "aa41bf52467aae0452a7783a0953341b793cce79",
"extension": "c",
"filename": "intersection.c",
"fork_events_count": 0,
"gha_created_at": "2020-03-14T17:12:17",
"gha_event_created_at": "2020-03-14T17:12:17",
"gha_language": null,
"gha_license_id": "Apache-2.0",
"github_id": 247319555,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 4429,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/eran/ELINA/partitions_api/intersection.c",
"provenance": "stackv2-0083.json.gz:17232",
"repo_name": "yqtianust/ReluDiff-ICSE2020-Artifact",
"revision_date": "2020-01-22T00:11:27",
"revision_id": "149f6efe4799602db749faa576980c36921a07c7",
"snapshot_id": "ecf106e90793395d8d296b38828d65dc3e443aab",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/yqtianust/ReluDiff-ICSE2020-Artifact/149f6efe4799602db749faa576980c36921a07c7/eran/ELINA/partitions_api/intersection.c",
"visit_date": "2021-03-21T18:19:19.172856"
} | stackv2 | /*
*
* This source file is part of ELINA (ETH LIbrary for Numerical Analysis).
* ELINA is Copyright © 2019 Department of Computer Science, ETH Zurich
* This software is distributed under GNU Lesser General Public License Version 3.0.
* For more information, see the ELINA project website at:
* http://elina.ethz.ch
*
* THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER
* EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS OR BE ERROR-FREE AND ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
* TITLE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY
* DAMAGES, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN
* ANY WAY CONNECTED WITH THIS SOFTWARE (WHETHER OR NOT BASED UPON WARRANTY,
* CONTRACT, TORT OR OTHERWISE).
*
*/
#include "comp_list.h"
comp_list_t * intersection_comp_list(comp_list_t *c1, comp_list_t *c2, unsigned short int n){
unsigned short int *map = (unsigned short int *)calloc(n,sizeof(unsigned short int));
comp_list_t *res = create_comp_list();
int l = 0;
comp_t *c = c1->head;
while(c!=NULL){
unsigned short int num = c->num;
map[num] = 1;
c = c->next;
}
c = c2->head;
while(c!=NULL){
unsigned short int num = c->num;
if(map[num]){
insert_comp(res,num);
}
c = c->next;
}
free(map);
return res;
}
comp_list_t * compute_diff(char *map, comp_list_t * cl, unsigned short int n){
comp_t * c = cl->head;
comp_list_t * res = create_comp_list();
int flag = 0;
while(c!=NULL){
unsigned short int num = c ->num;
if(!map[num]){
insert_comp(res,num);
}
else{
flag = 1;
}
c = c->next;
}
if(flag){
return res;
}
else{
free_comp_list(res);
return create_comp_list();
}
}
/***
c1 - c2 as well as c2 - c1
**/
array_comp_list_t * intersection_comp_list_compute_diff_both(comp_list_t *c1, comp_list_t *c2, unsigned short int n){
unsigned short int *map1 = (unsigned short int *)calloc(n,sizeof(unsigned short int));
unsigned short int *map2 = (unsigned short int *)calloc(n,sizeof(unsigned short int));
array_comp_list_t * res = create_array_comp_list();
comp_list_t *cl1 = create_comp_list();
comp_list_t *cl2 = create_comp_list();
comp_list_t *cl3 = create_comp_list();
int l = 0;
comp_t *c = c2->head;
while(c!=NULL){
unsigned short int num = c->num;
map2[num] = 1;
c = c->next;
}
c = c1->head;
while(c!=NULL){
unsigned short int num = c->num;
map1[num] = 1;
c = c->next;
}
c = c1->head;
while(c!=NULL){
unsigned short int num = c->num;
if(map2[num]){
insert_comp(cl1,num);
}
else{
insert_comp(cl2,num);
}
c = c->next;
}
c = c2->head;
while(c!=NULL){
unsigned short int num = c->num;
if(!map1[num]){
insert_comp(cl3,num);
}
c = c->next;
}
free(map1);
free(map2);
insert_comp_list(res,cl1);
insert_comp_list(res,cl2);
insert_comp_list(res,cl3);
return res;
}
/***
c1 - c2
**/
array_comp_list_t * intersection_comp_list_compute_diff(comp_list_t *c1, comp_list_t *c2, unsigned short int n){
unsigned short int *map = (unsigned short int *)calloc(n,sizeof(unsigned short int));
array_comp_list_t * res = create_array_comp_list();
comp_list_t *cl1 = create_comp_list();
comp_list_t *cl2 = create_comp_list();
int l = 0;
comp_t *c = c2->head;
while(c!=NULL){
unsigned short int num = c->num;
map[num] = 1;
c = c->next;
}
c = c1->head;
while(c!=NULL){
unsigned short int num = c->num;
if(map[num]){
insert_comp(cl1,num);
}
else{
insert_comp(cl2,num);
}
c = c->next;
}
free(map);
insert_comp_list(res,cl1);
insert_comp_list(res,cl2);
return res;
}
array_comp_list_t * intersection_array_comp_list(array_comp_list_t *acl1, array_comp_list_t *acl2, unsigned short int n){
int s1 = acl1->size;
int s2 = acl2->size;
array_comp_list_t * res = create_array_comp_list();
//int l = 0;
if(!s1 || !s2){
return res;
}
comp_list_t * cl1 = acl1->head;
while(cl1!=NULL){
comp_list_t * cl2 = acl2->head;
while(cl2!=NULL){
comp_list_t * src = intersection_comp_list(cl1,cl2,n);
if(src->size>0){
insert_comp_list(res,src);
}
else{
free_comp_list(src);
}
cl2 = cl2->next;
}
cl1 = cl1->next;
}
return res;
}
| 2.234375 | 2 |
2024-11-18T21:06:12.110339+00:00 | 2017-09-25T08:09:09 | 9c98ae20a1458f388c9d493e60dbe308b0d2fca9 | {
"blob_id": "9c98ae20a1458f388c9d493e60dbe308b0d2fca9",
"branch_name": "refs/heads/master",
"committer_date": "2017-09-25T08:09:09",
"content_id": "4cc54d36d616d86bef6bbf296bb40180238a5ad4",
"detected_licenses": [
"MIT"
],
"directory_id": "f5aec9f0f1991c07999268cb627c6bb82f0fe254",
"extension": "c",
"filename": "exp2.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 101335610,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2040,
"license": "MIT",
"license_type": "permissive",
"path": "/Experiment/exp2.c",
"provenance": "stackv2-0083.json.gz:17489",
"repo_name": "talsperre/Bash-Shell",
"revision_date": "2017-09-25T08:09:09",
"revision_id": "fa28cbb568ceef73fde2a6daf034d073e0571cc2",
"snapshot_id": "64a370c5c5c329a6b6e8353cb7cc58e6ed8bbdfd",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/talsperre/Bash-Shell/fa28cbb568ceef73fde2a6daf034d073e0571cc2/Experiment/exp2.c",
"visit_date": "2021-03-24T12:46:32.434707"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <termios.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <pwd.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <grp.h>
#include <time.h>
#include <locale.h>
#include <langinfo.h>
#include <stdint.h>
#include <sys/time.h> /* for setitimer */
#include <unistd.h> /* for pause */
#include <signal.h> /* for signal */
/*
* setitimer.c - simple use of the interval timer
*/
#include <sys/time.h> /* for setitimer */
#include <unistd.h> /* for pause */
#include <signal.h> /* for signal */
#define INTERVAL 10000 /* number of milliseconds to go off */
/* function prototype */
void DoStuff(void);
int getch(void)
{
struct termios oldattr, newattr;
int ch;
tcgetattr( STDIN_FILENO, &oldattr );
newattr = oldattr;
newattr.c_lflag &= ~( ICANON | ECHO );
tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
ch = getchar();
tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
return ch;
}
int main(int argc, char *argv[])
{
struct itimerval it_val; /* for setting itimer */
/* Upon SIGALRM, call DoStuff().
* Set interval timer. We want frequency in ms,
* but the setitimer call needs seconds and useconds. */
if (signal(SIGALRM, (void (*)(int)) DoStuff) == SIG_ERR) {
perror("Unable to catch SIGALRM");
exit(1);
}
it_val.it_value.tv_sec = INTERVAL/1000;
it_val.it_value.tv_usec = (INTERVAL*1000) % 1000000;
it_val.it_interval = it_val.it_value;
if (setitimer(ITIMER_REAL, &it_val, NULL) == -1) {
perror("error calling setitimer()");
exit(1);
}
while (getch()!='q')
{
pause();
}
}
/*
* DoStuff
*/
void DoStuff(void)
{
printf("Timer went off.\n");
}
| 2.546875 | 3 |
2024-11-18T21:06:12.153238+00:00 | 2019-01-14T10:06:57 | 9a9a8ad8b6894cfe380955e554abebf53b19e6bc | {
"blob_id": "9a9a8ad8b6894cfe380955e554abebf53b19e6bc",
"branch_name": "refs/heads/master",
"committer_date": "2019-01-14T10:06:57",
"content_id": "604a061517b8bc04b0685094d50d41348823adc9",
"detected_licenses": [
"MIT"
],
"directory_id": "dbe3388960b5af874297edc9c184a89485fdeb9d",
"extension": "c",
"filename": "kill_ccu.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 135004538,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1703,
"license": "MIT",
"license_type": "permissive",
"path": "/scripts/kill_ccu.c",
"provenance": "stackv2-0083.json.gz:17617",
"repo_name": "rogiro/HI",
"revision_date": "2019-01-14T10:06:57",
"revision_id": "e667da0fe74eda93e76a2cfb0c7b684e61a8e383",
"snapshot_id": "0a92a205e9821ba70968f4baa38269f7572bfa8d",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/rogiro/HI/e667da0fe74eda93e76a2cfb0c7b684e61a8e383/scripts/kill_ccu.c",
"visit_date": "2020-03-18T17:04:27.636290"
} | stackv2 | // -------------------------------------------------------------------------
// DCU_ref - Reference file for a DCU implementation
//
// Reference file for the DCU implementations for any device that needs
// to be integrated in the architecture.
// It handles basic registration with the CCU. How these commands are
// passed onto the specific device (or handled directly by the DCU_ref)
// is up to the developper extending the program for its specific purpose.
//
// -------------------------------------------------------------------------
// Version History
// 1.0 - RvR - 18.05.2018 - Initial version
//
// -------------------------------------------------------------------------
// Includes
#include <zmq.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include "../includes/ccu-memtypes.h"
#define ZMQ_CCU_RU_CONNECT "tcp://localhost:5550"
// Global variables
char buffer [MAX_MSGSIZE];
void *zmq_context;
void *zmq_requester;
// -------------------------------------------------------------------------
// Main
int main (void)
{
// Set up connection to CCU-RU
printf ("Connecting CCU Registration Unit\n");
zmq_context = zmq_ctx_new ();
zmq_requester = zmq_socket (zmq_context, ZMQ_REQ);
zmq_connect (zmq_requester, ZMQ_CCU_RU_CONNECT);
// Sending the DCU registration message
// to announce ourselves and set up the communication channels
printf ("Sending CCU shutdown message\n");
buffer[0] = MSG_RU_SHUTDOWN;
buffer[1] = 0;
zmq_send (zmq_requester, buffer, 2, 0);
zmq_recv (zmq_requester, buffer, MAX_MSGSIZE, 0);
printf( "shutdown processed\n" );
zmq_close (zmq_requester);
zmq_ctx_destroy (zmq_context);
}
| 2.234375 | 2 |
2024-11-18T21:06:12.709891+00:00 | 2016-10-02T16:54:28 | abdb857b78b894971c1e9e9c274a612a9fd13147 | {
"blob_id": "abdb857b78b894971c1e9e9c274a612a9fd13147",
"branch_name": "refs/heads/master",
"committer_date": "2016-10-02T16:54:28",
"content_id": "72fa595414b41c419ad5c19773f414b5119234da",
"detected_licenses": [
"MIT"
],
"directory_id": "50be93709c5656898dd3b2f7ab2874b74b416ce6",
"extension": "c",
"filename": "svg.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 68038812,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 857,
"license": "MIT",
"license_type": "permissive",
"path": "/src/svg.c",
"provenance": "stackv2-0083.json.gz:18133",
"repo_name": "firodj/ascigram",
"revision_date": "2016-10-02T16:54:28",
"revision_id": "83bf7cab0a3cd27f5e8d8843b3df62f857db437d",
"snapshot_id": "497d8340beccef1bf9892aece69c5d0d408bb84b",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/firodj/ascigram/83bf7cab0a3cd27f5e8d8843b3df62f857db437d/src/svg.c",
"visit_date": "2020-04-05T22:57:57.842835"
} | stackv2 | #include "svg.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
struct ascigram_svg_renderer_state {
void *opaque;
};
typedef struct ascigram_svg_renderer_state ascigram_svg_renderer_state;
ascigram_renderer *
ascigram_svg_renderer_new()
{
static const ascigram_renderer cb_default = {
NULL,
};
ascigram_svg_renderer_state *state;
ascigram_renderer *renderer;
/* Prepare the state pointer */
state = ascigram_malloc(sizeof(ascigram_svg_renderer_state));
memset(state, 0x0, sizeof(ascigram_svg_renderer_state));
/* Prepare the renderer */
renderer = ascigram_malloc(sizeof(ascigram_renderer));
memcpy(renderer, &cb_default, sizeof(ascigram_renderer));
renderer->opaque = state;
return renderer;
}
void
ascigram_svg_renderer_free(ascigram_renderer *renderer)
{
free(renderer->opaque);
free(renderer);
}
| 2.59375 | 3 |
2024-11-18T21:06:12.795972+00:00 | 2022-01-24T02:01:50 | 227a6dde165ffcd77832918926c7dbe40fc6d585 | {
"blob_id": "227a6dde165ffcd77832918926c7dbe40fc6d585",
"branch_name": "refs/heads/master",
"committer_date": "2022-01-24T02:01:50",
"content_id": "3d351fbaa40b57aac0d79e1b2cb4c33773e277f2",
"detected_licenses": [
"CC0-1.0"
],
"directory_id": "9aac1da1960d3f411bfcc647dcac03d29ade231c",
"extension": "c",
"filename": "wave_test.c",
"fork_events_count": 17,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 5088155,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2857,
"license": "CC0-1.0",
"license_type": "permissive",
"path": "/wave_test.c",
"provenance": "stackv2-0083.json.gz:18262",
"repo_name": "tai2/wave_reader_and_writer",
"revision_date": "2022-01-24T02:01:50",
"revision_id": "c79bc9921ddb9dc7625b5fc92aaeaf68420feb8f",
"snapshot_id": "e8fdb7180a0054e75542552ed3938dfca26c938b",
"src_encoding": "UTF-8",
"star_events_count": 14,
"url": "https://raw.githubusercontent.com/tai2/wave_reader_and_writer/c79bc9921ddb9dc7625b5fc92aaeaf68420feb8f/wave_test.c",
"visit_date": "2022-02-05T01:50:53.028835"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "wave_reader.h"
#include "wave_writer.h"
#define BUFFER_SIZE 4096
void test_read_write(const char *filename) {
wave_reader *wr;
wave_reader *wr2;
wave_reader_error rerror;
wave_writer *ww;
wave_writer_error werror;
wave_writer_format format;
char copied[256];
wr = wave_reader_open(filename, &rerror);
if (wr) {
snprintf(copied, sizeof(copied), "%s.copy", filename);
format.num_channels = wave_reader_get_num_channels(wr);
format.sample_rate = wave_reader_get_sample_rate(wr);
format.sample_bits = wave_reader_get_sample_bits(wr);
ww = wave_writer_open(copied, &format, &werror);
if (ww) {
unsigned char *buf;
int n;
printf("filename=%s format=%d num_channels=%d sample_rate=%d sample_bits=%d num_samples=%d\n",
filename,
wave_reader_get_format(wr),
wave_reader_get_num_channels(wr),
wave_reader_get_sample_rate(wr),
wave_reader_get_sample_bits(wr),
wave_reader_get_num_samples(wr));
buf = (unsigned char *)malloc(BUFFER_SIZE * format.num_channels * format.sample_bits / 8);
while (0 < (n = wave_reader_get_samples(wr, BUFFER_SIZE, buf))) {
wave_writer_put_samples(ww, n, buf);
}
assert(wave_reader_get_format(wr) == wave_writer_get_format(ww));
assert(wave_reader_get_num_channels(wr) == wave_writer_get_num_channels(ww));
assert(wave_reader_get_sample_rate(wr) == wave_writer_get_sample_rate(ww));
assert(wave_reader_get_sample_bits(wr) == wave_writer_get_sample_bits(ww));
assert(wave_reader_get_num_samples(wr) == wave_writer_get_num_samples(ww));
wave_writer_close(ww, &werror);
free(buf);
wr2 = wave_reader_open(copied, &rerror);
if (wr2) {
assert(wave_reader_get_format(wr) == wave_reader_get_format(wr2));
assert(wave_reader_get_num_channels(wr) == wave_reader_get_num_channels(wr2));
assert(wave_reader_get_sample_rate(wr) == wave_reader_get_sample_rate(wr2));
assert(wave_reader_get_sample_bits(wr) == wave_reader_get_sample_bits(wr2));
assert(wave_reader_get_num_samples(wr) == wave_reader_get_num_samples(wr2));
} else {
printf("rerror=%d\n", rerror);
}
wave_reader_close(wr2);
wave_reader_close(wr);
} else {
printf("werror=%d\n", werror);
}
} else {
printf("rerror=%d\n", rerror);
}
}
int main(void) {
test_read_write("11k16bitpcm.wav");
return 0;
}
| 2.46875 | 2 |
2024-11-18T21:06:12.954445+00:00 | 2021-03-24T10:52:19 | 0f74581238736a46db1eba97ea607c4403f57042 | {
"blob_id": "0f74581238736a46db1eba97ea607c4403f57042",
"branch_name": "refs/heads/main",
"committer_date": "2021-03-24T10:52:19",
"content_id": "7a8e11e81fda01958a29a3db7f7bfde44e88445d",
"detected_licenses": [
"MIT"
],
"directory_id": "a86071e9d92150f5a91d17dd4b65ece6d450825a",
"extension": "c",
"filename": "connection.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 351043833,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3403,
"license": "MIT",
"license_type": "permissive",
"path": "/src/connection.c",
"provenance": "stackv2-0083.json.gz:18520",
"repo_name": "hubenchang0515/X11Test",
"revision_date": "2021-03-24T10:52:19",
"revision_id": "51e4fdc8c3cca8dfe1b7ee486bbf56b9872ea4cf",
"snapshot_id": "f25090574eab8f3f68eab309d0101db7f2bb175c",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/hubenchang0515/X11Test/51e4fdc8c3cca8dfe1b7ee486bbf56b9872ea4cf/src/connection.c",
"visit_date": "2023-04-03T16:08:20.773633"
} | stackv2 | #include "log.h"
#include "connection.h"
#include "window.h"
// Lua
x11_test_connection_t* x11_test_lua_new_connection(lua_State* L, xcb_connection_t* c, xcb_window_t root)
{
static x11_test_bind_func_node_t methods[] =
{
{ "disconnect", x11_test_lua_disconnect },
{ "root", x11_test_lua_get_root_window },
{ NULL, NULL },
};
static x11_test_bind_func_node_t metamethods[] =
{
{ "__gc", x11_test_lua_disconnect },
{ "__tostring", x11_test_lua_connection_to_string },
{ NULL, NULL },
};
if(c == NULL)
{
X11_TEST_LOG_ERROR(MSG_ARG_NULL(c));
lua_pushnil(L);
return NULL;
}
x11_test_connection_t* conn = lua_newuserdata(L, sizeof(x11_test_connection_t));
if(conn == NULL)
{
X11_TEST_LOG_ERROR(MSG_INVOKE_FAILED(lua_newuserdata));
lua_pushnil(L);
return NULL;
}
conn->c = c;
conn->root = root;
x11_test_bind_methods(L, X11_TEST_CONNECTION_TYPE_NAME, methods);
x11_test_bind_metamethods(L, X11_TEST_CONNECTION_TYPE_NAME, metamethods);
return conn;
}
int x11_test_lua_connect(lua_State* L)
{
const char* display = NULL;
if(!lua_isnoneornil(L, 1))
{
display = luaL_checkstring(L, 1);
}
int* screenp = NULL;
int screen = 0;
if(!lua_isnoneornil(L, 2))
{
screen = luaL_checkinteger(L, 2);
screenp = &screen;
}
xcb_connection_t* c = x11_test_connect(display, screenp);
xcb_window_t root = x11_test_get_root_window(c);
x11_test_lua_new_connection(L, c, root);
return 1;
}
int x11_test_lua_connection_to_string(lua_State* L)
{
x11_test_connection_t* conn = luaL_checkudata(L, 1, X11_TEST_CONNECTION_TYPE_NAME);
char str[512];
if(conn != NULL)
sprintf(str, "%s <%p>", X11_TEST_CONNECTION_TYPE_NAME, conn->c);
else
sprintf(str, "%s <nil>", X11_TEST_CONNECTION_TYPE_NAME);
lua_pushstring(L, str);
return 1;
}
int x11_test_lua_disconnect(lua_State* L)
{
x11_test_connection_t* conn = luaL_checkudata(L, 1, X11_TEST_CONNECTION_TYPE_NAME);
if(conn == NULL || conn->c == NULL)
{
lua_pushboolean(L, false);
return 1;
}
X11_TEST_LOG_DEBUG("disconnect %p", conn->c);
x11_test_disconnect(conn->c);
conn->c = NULL;
lua_pushboolean(L, true);
return 1;
}
int x11_test_lua_get_root_window(lua_State* L)
{
x11_test_connection_t* conn = luaL_checkudata(L, 1, X11_TEST_CONNECTION_TYPE_NAME);
if(conn == NULL || conn->c == NULL)
{
lua_pushnil(L);
return 1;
}
xcb_window_t root = conn->root;
x11_test_lua_new_window(L, conn->c, root, root); // <conn> <window>
lua_pushnil(L); // <conn> <window> <nil>
lua_copy(L, 1, 3); // <conn> <window> <conn>
lua_setuservalue(L, -2); // <conn> <window>
return 1;
}
// C
xcb_connection_t* x11_test_connect(const char *displayname, int* screenp)
{
xcb_connection_t* c = xcb_connect(displayname, screenp);
return c;
}
void x11_test_disconnect(xcb_connection_t* c)
{
if(c == NULL)
return;
xcb_disconnect(c);
}
xcb_window_t x11_test_get_root_window(xcb_connection_t* c)
{
xcb_screen_iterator_t iterator = xcb_setup_roots_iterator(xcb_get_setup(c));
return iterator.data->root;
} | 2.453125 | 2 |
2024-11-18T21:06:13.362892+00:00 | 2022-03-07T18:25:42 | a1739d524a0529c8f75c48e1ca7c07b21758934a | {
"blob_id": "a1739d524a0529c8f75c48e1ca7c07b21758934a",
"branch_name": "refs/heads/master",
"committer_date": "2022-03-07T18:25:42",
"content_id": "59724543391bd4c50d2ca0db9e8afb106d75afd9",
"detected_licenses": [
"MIT"
],
"directory_id": "9959e8924f62a7e22da3b4da215f7ab5c4b76b08",
"extension": "h",
"filename": "TeensyMidi.h",
"fork_events_count": 49,
"gha_created_at": "2016-12-18T11:23:25",
"gha_event_created_at": "2022-03-07T18:25:43",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 76778684,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2199,
"license": "MIT",
"license_type": "permissive",
"path": "/examples/OPL3Duo/TeensyMidi/TeensyMidi.h",
"provenance": "stackv2-0083.json.gz:18905",
"repo_name": "DhrBaksteen/ArduinoOPL2",
"revision_date": "2022-03-07T18:25:42",
"revision_id": "2bf5702a744662d458ff3553f706a7354150e9df",
"snapshot_id": "0308dc7e56bd0a3d2cc39be28a489cc8bd55a515",
"src_encoding": "UTF-8",
"star_events_count": 180,
"url": "https://raw.githubusercontent.com/DhrBaksteen/ArduinoOPL2/2bf5702a744662d458ff3553f706a7354150e9df/examples/OPL3Duo/TeensyMidi/TeensyMidi.h",
"visit_date": "2022-03-25T23:56:34.820696"
} | stackv2 | #include <Arduino.h>
#define NUM_MIDI_CHANNELS 16
#define NUM_MELODIC_CHANNELS 12
#define NUM_DRUM_CHANNELS 12
#define MIDI_DRUM_CHANNEL 10
#define VALUE_UNDEFINED 255
// MIDI note number of the first drum sound.
#define DRUM_NOTE_BASE 27
#define NUM_MIDI_DRUMS 60
struct MidiChannel {
Instrument4OP instrument; // Current instrument.
byte program; // Program number currenly associated witht this MIDI channel.
float volume; // Channel volume.
float modulation; // Channel modulation.
float afterTouch; // Channel aftertouch.
unsigned long tAfterTouch; // Aftertouch start.
};
struct OPLChannel {
unsigned long eventIndex; // Midi event index to determine oldest channel to reuse.
byte midiChannel; // Midi channel associated with the event.
byte program; // Program number of the instrument loaded on the OPL channel.
byte note; // Note number playing on the channel (0xFF when channel is free).
byte transpose; // Transpose notes on this OPL channel for drums.
float noteVelocity; // Velocity of the note on event.
};
// Note FNumbers per octave +/- 2 semitones for pitch bend.
const unsigned int notePitches[16] = {
0x132, 0x144,
0x156, 0x16B, 0x181, 0x198, 0x1B0, 0x1CA,
0x1E5, 0x202, 0x220, 0x241, 0x263, 0x287,
0x2AC, 0x2D6
};
// OPL channels used for drums.
const byte drumChannelsOPL[12] = {
6, 7, 8, 15, 16, 17,
24, 25, 26, 33, 34, 35
};
void setup();
void loop();
byte getFreeMelodicChannel();
byte getFreeDrumChannel();
void playDrum(byte note, byte velocity);
void playMelodic(byte midiChannel, byte note, byte velocity);
void setOplChannelVolume(byte channel4OP, byte midiChannel);
void onNoteOff(byte midiChannel, byte note, byte velocity);
void onNoteOn(byte midiChannel, byte note, byte velocity);
void onProgramChange(byte midiChannel, byte program);
void onControlChange(byte midiChannel, byte control, byte value);
void onPitchChange(byte midiChannel, int pitch);
void onSystemReset();
| 2.3125 | 2 |
2024-11-18T21:06:14.054701+00:00 | 2019-11-25T04:23:25 | 77a4c05c20c2f0fe414ca67222e59c7c2d9c0a30 | {
"blob_id": "77a4c05c20c2f0fe414ca67222e59c7c2d9c0a30",
"branch_name": "refs/heads/master",
"committer_date": "2019-11-25T04:23:25",
"content_id": "1fe0ffe8f287f250a1e921dc41a32b521a372489",
"detected_licenses": [
"MIT"
],
"directory_id": "9888b161ced0b5a1d33502dc9d26a4d861cf7b16",
"extension": "c",
"filename": "singly_linked_list.c",
"fork_events_count": 2,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 146616729,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 252,
"license": "MIT",
"license_type": "permissive",
"path": "/Sem2/DSC/Internals 2/Linked List Two/singly_linked_list.c",
"provenance": "stackv2-0083.json.gz:19549",
"repo_name": "nsudhanva/mca-code",
"revision_date": "2019-11-25T04:23:25",
"revision_id": "812348ce53edbe0f42f85a9c362bfc8aad64e1e7",
"snapshot_id": "bef8c3b1b4804010b4bd282896e07e46f498b6f8",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/nsudhanva/mca-code/812348ce53edbe0f42f85a9c362bfc8aad64e1e7/Sem2/DSC/Internals 2/Linked List Two/singly_linked_list.c",
"visit_date": "2020-03-27T13:34:07.562016"
} | stackv2 | #include<stdio.h>
struct Node{
int info;
struct Node *next;
};
struct Node *is_empty(struct Node *list){
if(list == NULL){
return 1;
}
return 0;
}
struct Node *insert_at_beg(struct Node *list){
}
int main()
{
} | 2.46875 | 2 |
2024-11-18T21:06:14.293647+00:00 | 2021-09-02T01:01:57 | c375d02a71899d0c5ab7094943ea07cdd2998fe7 | {
"blob_id": "c375d02a71899d0c5ab7094943ea07cdd2998fe7",
"branch_name": "refs/heads/master",
"committer_date": "2021-09-02T01:01:57",
"content_id": "33eb0b42d9561d5cc58c8ef32c262d826306c4b7",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "979b595a2f8cb2df6846c1d9d666d2a93e6f0823",
"extension": "c",
"filename": "CVE_2013_1979_VULN_scm_set_cred.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 337,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/dataset/source/NVD/CVE_2013_1979_VULN_scm_set_cred.c",
"provenance": "stackv2-0083.json.gz:19805",
"repo_name": "ZouzhiqiangNxf/AutoVAS",
"revision_date": "2021-09-02T01:01:57",
"revision_id": "99a92411c21241f7030b3c3b697c4161aaaf852b",
"snapshot_id": "c4647ddedaf4b694b0c4f6772983d3e723b39183",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/ZouzhiqiangNxf/AutoVAS/99a92411c21241f7030b3c3b697c4161aaaf852b/dataset/source/NVD/CVE_2013_1979_VULN_scm_set_cred.c",
"visit_date": "2023-07-11T01:44:36.757798"
} | stackv2 | static __inline__ void CVE_2013_1979_VULN_scm_set_cred(struct scm_cookie *scm,
struct pid *pid, const struct cred *cred)
{
scm->pid = get_pid(pid);
scm->cred = cred ? get_cred(cred) : NULL;
scm->creds.pid = pid_vnr(pid);
scm->creds.uid = cred ? cred->euid : INVALID_UID;
scm->creds.gid = cred ? cred->egid : INVALID_GID;
}
| 2 | 2 |
2024-11-18T21:06:14.480014+00:00 | 2018-01-19T22:29:00 | 6e6c5d162f7241efd46decfbb9e1f9e461ec8087 | {
"blob_id": "6e6c5d162f7241efd46decfbb9e1f9e461ec8087",
"branch_name": "refs/heads/master",
"committer_date": "2018-01-19T22:29:00",
"content_id": "247a951e8c7369457e612301c3c435920177a39a",
"detected_licenses": [
"MIT"
],
"directory_id": "102a1417c6c0eff6a065f2fb745a83ef591748de",
"extension": "c",
"filename": "readline.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 118088503,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2287,
"license": "MIT",
"license_type": "permissive",
"path": "/c/readline.c",
"provenance": "stackv2-0083.json.gz:20192",
"repo_name": "BartMassey/randline",
"revision_date": "2018-01-19T22:29:00",
"revision_id": "1c47d4bab8201085448768cfaf6ac943c41f8bd0",
"snapshot_id": "db496c77b0f5887c1d02b9c9c7abbede469a7191",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/BartMassey/randline/1c47d4bab8201085448768cfaf6ac943c41f8bd0/c/readline.c",
"visit_date": "2021-09-04T15:31:02.359140"
} | stackv2 | /* Copyright © 2018 Bart Massey */
/* [This program is licensed under the "MIT License"]
Please see the file LICENSE in the source
distribution of this software for license terms. */
/* Read a line from stdin. */
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "readline.h"
/* Read a line of text from stdin and return a pointer to
malloced storage. Return 0 when file has ended and no
more lines are avilable. (The last line of the file is
read properly if it ends with EOF instead of newline.)
Exit with an error message on errors. */
char *
readline(void) {
/* Line buffer. */
char *line_buffer = 0;
size_t nread = 0;
while (1) {
/* Check for sufficient buffer space. */
if (nread >= __SIZE_MAX__ - 1) {
fprintf(stderr, "readline: line too long\n");
exit(1);
}
/* Get a valid character from stdin. */
errno = 0; /* Clear errno for later check. */
int ch = getchar();
/* EOF is returned on end-of-file or error. */
if (ch == EOF) {
if (errno != 0) {
/* Was not actually end-of-file. */
perror("readline: getchar");
exit(1);
}
/* End-of-file at beginning of line does not
create a line. */
if (nread == 0)
return 0;
/* End-of-file after beginning of line creates a
line. */
break;
}
/* C cannot reasonably handle NUL characters in
strings. */
if (ch == '\0') {
fprintf(stderr, "readline: null character in line\n");
exit(1);
}
/* Newline creates a line. */
if (ch == '\n')
break;
/* Make room for the character. */
line_buffer = realloc(line_buffer, nread + 1);
/* Make sure that worked. */
assert(line_buffer != 0);
/* Save the character. */
line_buffer[nread] = ch;
/* Increment the count. */
nread++;
}
/* Append the null character. */
line_buffer = realloc(line_buffer, nread + 1);
assert(line_buffer);
line_buffer[nread] = '\0';
return line_buffer;
}
| 3.234375 | 3 |
2024-11-18T21:06:14.561969+00:00 | 2021-10-25T17:06:06 | 8a1c6dc6c8a66d50117b18f4d1e818e20fcb9280 | {
"blob_id": "8a1c6dc6c8a66d50117b18f4d1e818e20fcb9280",
"branch_name": "refs/heads/master",
"committer_date": "2021-10-25T17:06:06",
"content_id": "6311bdd4b6c714800c8cfde10fb37eb36ae794ae",
"detected_licenses": [
"NCSA",
"BSD-3-Clause",
"BSD-2-Clause"
],
"directory_id": "6dd2d509d44ea035da9d2a9f6cc9797724c12484",
"extension": "c",
"filename": "CheckOverlap.C",
"fork_events_count": 1,
"gha_created_at": "2019-12-17T05:50:12",
"gha_event_created_at": "2019-12-17T05:50:13",
"gha_language": null,
"gha_license_id": "NOASSERTION",
"github_id": 228542764,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3015,
"license": "NCSA,BSD-3-Clause,BSD-2-Clause",
"license_type": "permissive",
"path": "/src/enzo/CheckOverlap.C",
"provenance": "stackv2-0083.json.gz:20321",
"repo_name": "appolloford/enzo-dev",
"revision_date": "2021-10-25T17:06:06",
"revision_id": "2b20d1c9ee5b9b4ee6706a73e32d2e4a8b7fc8f5",
"snapshot_id": "ea9ebc98036c6e5be0c98ebb903448a354cb4aaf",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/appolloford/enzo-dev/2b20d1c9ee5b9b4ee6706a73e32d2e4a8b7fc8f5/src/enzo/CheckOverlap.C",
"visit_date": "2023-08-06T01:18:34.631354"
} | stackv2 | /***********************************************************************
/
/ DETERMINE IF TWO BOXES OVERLAP
/
/ written by: Stephen Skory
/ date: September, 2012
/ modified1:
/
/ PURPOSE: Check for overlap in active zones of grids.
/
/ INPUTS:
/
************************************************************************/
#include "preincludes.h"
#include "ErrorExceptions.h"
#include "macros_and_parameters.h"
int one_overlap(FLOAT a[MAX_DIMENSION], FLOAT b[MAX_DIMENSION],
FLOAT s[MAX_DIMENSION], FLOAT t[MAX_DIMENSION],
int dims) {
int dim;
int overlap = SUCCESS;
for (dim = 0; dim < dims; dim++) {
if ((a[dim] >= t[dim]) || (b[dim] <= s[dim])) {
overlap = FAIL;
break;
}
}
if (overlap) {return SUCCESS;}
else {return FAIL;}
}
int check_overlap(FLOAT a[MAX_DIMENSION], FLOAT b[MAX_DIMENSION],
FLOAT s[MAX_DIMENSION], FLOAT t[MAX_DIMENSION],
int dims, FLOAT period[MAX_DIMENSION],
int *shift, int skipto) {
// a (left), b (right) - corners of box 1
// s, t - corners of box 2
// skipto - where to start the loops below.
FLOAT a_temp[MAX_DIMENSION], b_temp[MAX_DIMENSION];
int this_shift[MAX_DIMENSION];
int shift0, shift1, shift2, dim, overlap, max1, max2, i1, i2, count = -1;
// Test the simplest case, where they already overlap.
//overlap = one_overlap(a, b, s, t, dims);
//if (overlap) return SUCCESS;
// If we're here, we need to test all cases.
// Keep checking until we've exhausted all cases (as shift is handed back
// to here from above).
// This is to ensure that the box is shifted in all the dimensions it needs
// to for reproducibility, meaning if we shift box 1 by an amount, we would
// (swapping box 1 and box 2 in the algorithm) shift box 2 by the exact
// opposite amount.
// We shift box 1 around, keeping grid 2 static.
// Decide how many dimensions we move in.
max1 = (dims > 1) ? 2 : -1;
max2 = (dims > 2) ? 2 : -1;
i1 = (dims > 1) ? 1 : 0;
i2 = (dims > 2) ? 2 : 0;
// we start each loop at the *current* setting of shift.
for (shift0 = -1; shift0 < 2; shift0++) {
this_shift[0] = shift0;
for (shift1 = -1; shift1 < max1; shift1++) {
if (i2) this_shift[1] = shift1;
for (shift2 = -1; shift2 < max2; shift2++) {
if (i1) this_shift[2] = shift2;
count += 1;
if (count < skipto) continue;
// if we're here, this is a new inspection.
for (dim = 0; dim < dims; dim++) {
a_temp[dim] = a[dim] + this_shift[dim] * period[dim];
b_temp[dim] = b[dim] + this_shift[dim] * period[dim];
}
overlap = one_overlap(a_temp, b_temp, s, t, dims);
if (overlap) {
for (dim = 0; dim < dims; dim++) {
shift[dim] = this_shift[dim];
}
return (count + 1);
} // if overlap
} // shift2
} // shift1
} // shift0
// If we get here, they don't overlap.
return -1;
}
| 2.703125 | 3 |
2024-11-18T21:06:14.963963+00:00 | 2013-01-30T21:04:53 | 989ac29c3c90c0d1bb6fa2d9ca1d4ab8b089d149 | {
"blob_id": "989ac29c3c90c0d1bb6fa2d9ca1d4ab8b089d149",
"branch_name": "HEAD",
"committer_date": "2013-01-30T21:04:53",
"content_id": "3736117ab152b96861f67d634d5a13e5ff70fccd",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "f5e68ca0a23480185b4c17d69043a36c17ac1b0a",
"extension": "c",
"filename": "matrix_math.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3899,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/src/aerodroid/matrix_math.c",
"provenance": "stackv2-0083.json.gz:20836",
"repo_name": "dnnychan/aerodroid",
"revision_date": "2013-01-30T21:04:53",
"revision_id": "0c57ed9a8d843b3416d376e70beba811f30264e3",
"snapshot_id": "81ad08ebb4dcf41045c86f5533e98fe839ec1437",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/dnnychan/aerodroid/0c57ed9a8d843b3416d376e70beba811f30264e3/src/aerodroid/matrix_math.c",
"visit_date": "2016-09-05T20:01:03.663040"
} | stackv2 | /*******************************************************************************
* @file
* @purpose
* @version 0.1
*------------------------------------------------------------------------------
* Copyright (C) 2012 Gumstix Inc.
* All rights reserved.
*
* Contributer(s):
* Danny Chan <danny@gumstix.com>
*------------------------------------------------------------------------------
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <math.h>
#include "matrix_math.h"
void vectorCrossProduct(float* vectorC, float* vectorA, float* vectorB)
{
vectorC[0] = (vectorA[1] * vectorB[2]) - (vectorA[2] * vectorB[1]);
vectorC[1] = (vectorA[2] * vectorB[0]) - (vectorA[0] * vectorB[2]);
vectorC[2] = (vectorA[0] * vectorB[1]) - (vectorA[1] * vectorB[0]);
}
////////////////////////////////////////////////////////////////////////////////
// Matrix Multiply
// Multiply matrix A times matrix B, matrix A dimension m x n, matrix B dimension n x p
// Result placed in matrix C, dimension m x p
//
// Call as: matrixMultiply(m, n, p, C, A, B)
////////////////////////////////////////////////////////////////////////////////
void matrixMultiply(int aRows, int aCols_bRows, int bCols, float* matrixC, float* matrixA, float* matrixB)
{
int i, j, k;
for (i = 0; i < aRows * bCols; i++)
{
matrixC[i] = 0.0;
}
for (i = 0; i < aRows; i++)
{
for(j = 0; j < aCols_bRows; j++)
{
for(k = 0; k < bCols; k++)
{
matrixC[i * bCols + k] += matrixA[i * aCols_bRows + j] * matrixB[j * bCols + k];
}
}
}
}
void matrixAdd(int rows, int cols, float* matrixC, float* matrixA, float* matrixB)
{
int i;
for (i = 0; i < rows * cols; i++)
{
matrixC[i] = matrixA[i] + matrixB[i];
}
}
void matrixSubtract(int rows, int cols, float* matrixC, float* matrixA, float* matrixB)
{
int i;
for (i = 0; i < rows * cols; i++)
{
matrixC[i] = matrixA[i] - matrixB[i];
}
}
void matrixScale(int rows, int cols, float* matrixC, float* matrixA, float scaler)
{
int i;
for (i = 0; i < rows * cols; i++)
{
matrixC[i] = scaler * matrixA[i];
}
}
float vectorDotProduct(int length, float* vector1, float* vector2)
{
float dotProduct = 0;
int i;
for (i = 0; i < length; i++)
{
dotProduct += vector1[i] * vector2[i];
}
return dotProduct;
}
// NOT USED
//Converts floating point to Q16.16 format
int floatToQ (float num)
{
return (int) (num * pow(2,16));
}
//converts Q16.16 to floating point
float QToFloat(int num)
{
return pow(2,-16)*(float)num;
}
| 2.140625 | 2 |
2024-11-18T22:11:29.187465+00:00 | 2020-12-29T22:27:22 | 685e30cc1f1b1ff51840d4f265a789b007786ad1 | {
"blob_id": "685e30cc1f1b1ff51840d4f265a789b007786ad1",
"branch_name": "refs/heads/master",
"committer_date": "2020-12-29T22:27:22",
"content_id": "55e1d24fd15f937d9d5baf68c424c2b586f82da2",
"detected_licenses": [
"MIT"
],
"directory_id": "c5962fc4d2e2626d47ffc0a8ede77ddaeaad1f68",
"extension": "c",
"filename": "pthread_store.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 267451876,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1933,
"license": "MIT",
"license_type": "permissive",
"path": "/pthread_store.c",
"provenance": "stackv2-0087.json.gz:96",
"repo_name": "WillisAHershey/pthread_store",
"revision_date": "2020-12-29T22:27:22",
"revision_id": "b2b69117652911443e595f8fa03eaa4610f414b9",
"snapshot_id": "0af75d6e636464f9979a3ce5f84096c68fba0002",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/WillisAHershey/pthread_store/b2b69117652911443e595f8fa03eaa4610f414b9/pthread_store.c",
"visit_date": "2023-02-08T22:30:26.995394"
} | stackv2 | #include <stdlib.h>
#include <pthread.h>
#include "pthread_store.h"
#define PTHREAD_STORE_SUCCESS 0
#define PTHREAD_STORE_FAILURE -1
typedef struct storelistStruct{
struct storelistStruct *next;
void *store;
pthread_t tid;
}storelist;
static pthread_mutex_t mux=PTHREAD_MUTEX_INITIALIZER;
static storelist *head=NULL;
int pthread_store(void *store){
pthread_t self=pthread_self();
storelist *pt=malloc(sizeof(storelist));
if(!pt)
return PTHREAD_STORE_FAILURE;
pthread_mutex_lock(&mux);
*pt=(storelist){.next=head,.store=store,.tid=self};
head=pt;
pthread_mutex_unlock(&mux);
return PTHREAD_STORE_SUCCESS;
}
void* pthread_recall(){
pthread_t self=pthread_self();
pthread_mutex_lock(&mux);
void *out=NULL;
for(storelist *pt=head;pt;pt=pt->next)
if(pthread_equal(pt->tid,self)){
out=pt->store;
break;
}
pthread_mutex_unlock(&mux);
return out;
}
void* pthread_discard(){
pthread_t self=pthread_self();
void *out=NULL;
pthread_mutex_lock(&mux);
if(!head)
goto finished;
if(pthread_equal(head->tid,self)){
storelist *pt=head;
head=pt->next;
out=pt->store;
free(pt);
goto finished;
}
for(storelist *b=head,*r=head->next;r;b=r,r=r->next)
if(pthread_equal(r->tid,self)){
b->next=r->next;
out=r->store;
free(r);
break;
}
finished:
pthread_mutex_unlock(&mux);
return out;
}
int pthread_discard_all(){
pthread_t self=pthread_self();
int out=0;
pthread_mutex_lock(&mux);
while(head&&pthread_equal(head->tid,self)){
++out;
storelist *pt=head;
head=pt->next;
free(pt);
}
if(!head)
goto finished;
for(storelist *b=head,*r=head->next;r;)
if(pthread_equal(r->tid,self)){
++out;
b->next=r->next;
free(r);
r=b->next;
}
else{
b=r;
r=r->next;
}
finished:
pthread_mutex_unlock(&mux);
return out;
}
int pthread_store_close(){
while(head){
storelist *pt=head;
head=pt->next;
free(pt);
}
return pthread_mutex_destroy(&mux);
}
| 2.640625 | 3 |
2024-11-18T22:11:29.440554+00:00 | 2019-05-08T07:28:55 | 204e7d5bb27b40d95fcfa6dc766ea94347958583 | {
"blob_id": "204e7d5bb27b40d95fcfa6dc766ea94347958583",
"branch_name": "refs/heads/master",
"committer_date": "2019-05-08T07:28:55",
"content_id": "44eda7c84c226f843f9175fb49b4c0c72cc064cf",
"detected_licenses": [
"MIT"
],
"directory_id": "cf1da7241bf9fddbc26579074c6ee7c3adc7de8d",
"extension": "c",
"filename": "adder.c",
"fork_events_count": 0,
"gha_created_at": "2019-01-29T19:43:45",
"gha_event_created_at": "2019-01-29T19:43:45",
"gha_language": null,
"gha_license_id": "MIT",
"github_id": 168216966,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1800,
"license": "MIT",
"license_type": "permissive",
"path": "/exercises/ex02/adder.c",
"provenance": "stackv2-0087.json.gz:352",
"repo_name": "prava-d/ExercisesInC",
"revision_date": "2019-05-08T07:28:55",
"revision_id": "01286ea48e54d4b9b690386f9bff3fc0b22a0c36",
"snapshot_id": "2d8fd74dbf9a98de932f4a8141adaf0edd4eb928",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/prava-d/ExercisesInC/01286ea48e54d4b9b690386f9bff3fc0b22a0c36/exercises/ex02/adder.c",
"visit_date": "2020-04-19T13:24:38.274699"
} | stackv2 | /* Program that adds together integers passed in by a user.
Name: Prava Dhulipalla
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int size = 0;
/* Function that returns the size allocation of the array.
Returns user input (if between 1 or 100) or else, 10
*/
int get_size() {
char input[4];
printf("What is the max amount of integers you want to add together (1 to 100)?\nPress enter to keep default, 10.\n");
fgets(input, sizeof(input), stdin);
int val = atoi(input);
if (val > 0 && val <= 100) {
return val;
}
else {
return 10;
}
}
/* Gets input of integers seperated by an Enter and exitable by Ctrl+D
Errors if too many numbers are entered, the number is too large, or if the
entered character is 0 or a noninteger
nums: reference to array to store nums
*/
void get_input(int *nums) {
char input[5];
printf("Enter your numbers on seperate lines:\n");
int count = 0;
while (fgets(input, sizeof(input), stdin) != NULL) {
if (count == size) {
printf("Error: You entered too many numebrs.\n");
break;
}
if (input[strlen(input) - 1] != '\n') {
printf("Error: Your input length is too large.\n");
break;
}
if (atoi(input) == 0) {
printf("Error: You entered a 0 or a nonnumber.\n");
break;
}
nums[count] = atoi(input);
count++;
}
}
/* Adds together elements of an array and returns sum
nums: array with user input values
*/
int add_nums(int *nums) {
int sum = 0;
for (int i = 0; i < size; i++) {
sum += nums[i];
}
return sum;
}
/* Main function that gets user input to sum together nums
Prints out sum
*/
int main() {
size = get_size();
int nums[size];
memset(nums, 0, size * sizeof(int));
get_input(nums);
int sum = add_nums(nums);
printf("The sum is %i\n", sum);
return 0;
} | 4.28125 | 4 |
2024-11-18T22:11:31.521043+00:00 | 2018-11-22T13:33:24 | 770983fcd72858c1ba2e7cf0721b5c7e066d13fd | {
"blob_id": "770983fcd72858c1ba2e7cf0721b5c7e066d13fd",
"branch_name": "refs/heads/master",
"committer_date": "2018-11-22T13:33:24",
"content_id": "40afacbf227ce49518be1d0f3ae1802c3084276a",
"detected_licenses": [
"MIT"
],
"directory_id": "c50213a536c804578ae79d5e58d2bd96cea98a93",
"extension": "c",
"filename": "sender.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 157983025,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 861,
"license": "MIT",
"license_type": "permissive",
"path": "/sender.c",
"provenance": "stackv2-0087.json.gz:481",
"repo_name": "BlueMush/lab3",
"revision_date": "2018-11-22T13:33:24",
"revision_id": "cc3337a0c573bb285b726e8523de75d4ab677cce",
"snapshot_id": "798f6c8b663deec616a4ae86bec8e30e117342ed",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/BlueMush/lab3/cc3337a0c573bb285b726e8523de75d4ab677cce/sender.c",
"visit_date": "2020-04-07T02:37:19.623623"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define BUFF_SIZE 1024
typedef struct {
long data_type;
int data_num;
char data_buff[BUFF_SIZE];
} t_data;
int main( void)
{
int msqid;
int ndx = 0;
t_data data;
if ( -1 == ( msqid = msgget( (key_t)1234, IPC_CREAT ¦ 0666)))
{
perror( "msgget() 실패");
exit( 1);
}
while( 1 )
{
data.data_type = ( ndx++ % 3) +1; // data_type 는 1, 2, 3
data.data_num = ndx;
sprintf( data.data_buff, "type=%d, ndx=%d, http://forum.falinux.com", data.data_type, ndx);
if ( -1 == msgsnd( msqid, &data, sizeof( t_data) - sizeof( long), 0))
{
perror( "msgsnd() 실패");
exit( 1);
}
sleep( 1);
}
}
| 2.4375 | 2 |
2024-11-18T22:11:31.990731+00:00 | 2022-11-27T17:01:27 | b07b37f483c3307db4f2a86bf2feb3af9558c61e | {
"blob_id": "b07b37f483c3307db4f2a86bf2feb3af9558c61e",
"branch_name": "refs/heads/master",
"committer_date": "2022-11-27T17:01:27",
"content_id": "7970a2bf88587840f76be6b884fed86bf6da25d6",
"detected_licenses": [
"MIT"
],
"directory_id": "8a286ccdd8cdb348f82b7251fdf4b8a5619a0039",
"extension": "c",
"filename": "main.c",
"fork_events_count": 1,
"gha_created_at": "2017-12-24T17:00:15",
"gha_event_created_at": "2022-01-09T03:46:18",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 115276676,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 152,
"license": "MIT",
"license_type": "permissive",
"path": "/hashes/main.c",
"provenance": "stackv2-0087.json.gz:738",
"repo_name": "Hoshoyo/hutils",
"revision_date": "2022-11-27T17:01:27",
"revision_id": "ce4270442ac725580b2a263d9d679e488729618d",
"snapshot_id": "1331c0c1d043e6e8f224ee362a2e41c4cc9084fd",
"src_encoding": "UTF-8",
"star_events_count": 9,
"url": "https://raw.githubusercontent.com/Hoshoyo/hutils/ce4270442ac725580b2a263d9d679e488729618d/hashes/main.c",
"visit_date": "2022-12-13T03:44:38.373793"
} | stackv2 | #include <stdio.h>
#include "sha256.c"
int main() {
char result[32] = {0};
sha256("abc", 3, result);
sha256_print(result);
return 0;
} | 2.125 | 2 |
2024-11-18T22:11:32.754497+00:00 | 2023-08-16T12:50:05 | 53c46e8d36d2fa8e3d02e254dde10fbbc1c12371 | {
"blob_id": "53c46e8d36d2fa8e3d02e254dde10fbbc1c12371",
"branch_name": "refs/heads/master",
"committer_date": "2023-08-16T12:50:05",
"content_id": "7f64692d53d32eb365f99c1dc759ce17fecc46f7",
"detected_licenses": [
"MIT"
],
"directory_id": "984383140e7ad43ea42d6a79c3797438ebcfe71e",
"extension": "c",
"filename": "c_kbhit.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 167775750,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 582,
"license": "MIT",
"license_type": "permissive",
"path": "/lib/car/obj/src/c_kbhit.c",
"provenance": "stackv2-0087.json.gz:1253",
"repo_name": "chlds/util",
"revision_date": "2023-08-16T12:50:05",
"revision_id": "6c9fac1fbacad7657f3f93d59798e4774e681988",
"snapshot_id": "8bc5815e3babce87199e0f2669c4068bfd630fed",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/chlds/util/6c9fac1fbacad7657f3f93d59798e4774e681988/lib/car/obj/src/c_kbhit.c",
"visit_date": "2023-08-16T22:45:01.229839"
} | stackv2 | /*
Fn. kbhit for Linux
*/
// # include <termios.h>
// # include <fcntl.h>
# include <stdio.h>
// # include "./incl/car.h"
signed(__cdecl c_kbhit(void)) {
/*
auto signed flag;
auto signed fd;
auto signed r;
auto struct termios current,old;
fd = (0x00);
tcgetattr(fd,&old);
current = (old);
current.c_lflag &= (~(ICANON|(ECHO)));
tcsetattr(fd,TCSANOW,¤t);
flag = fcntl(fd,F_GETFL,0x00);
fcntl(fd,F_SETFL,flag|(O_NONBLOCK));
r = fgetc(stdin);
fcntl(fd,F_SETFL,flag);
tcsetattr(fd,TCSANOW,&old);
if(EQ(EOF,r)) return(0x00);
ungetc(r,stdin);
return(0x01);
//*/
return(0x01);
}
| 2.15625 | 2 |
2024-11-18T22:11:32.815189+00:00 | 2019-10-14T05:32:53 | 3d41a4f33b1bb9850bbafe32ecb92c1dee1ca592 | {
"blob_id": "3d41a4f33b1bb9850bbafe32ecb92c1dee1ca592",
"branch_name": "refs/heads/master",
"committer_date": "2019-10-14T05:32:53",
"content_id": "40723f555b04b151cc6bb760d50a8c2eb5926de4",
"detected_licenses": [
"MIT"
],
"directory_id": "0c4bd1b977cc714a8a6b2839f51c4247ecfd32b1",
"extension": "h",
"filename": "tools.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3921,
"license": "MIT",
"license_type": "permissive",
"path": "/Neural-Networks/AdaptativeNeuralNetwork/include/ANN/tools.h",
"provenance": "stackv2-0087.json.gz:1381",
"repo_name": "ishine/neuralLOGIC",
"revision_date": "2019-10-14T05:32:53",
"revision_id": "3eb3b9980e7f7a7d87a77ef40b1794fb5137c459",
"snapshot_id": "281d498b40159308815cee6327e6cf79c9426b16",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/ishine/neuralLOGIC/3eb3b9980e7f7a7d87a77ef40b1794fb5137c459/Neural-Networks/AdaptativeNeuralNetwork/include/ANN/tools.h",
"visit_date": "2020-08-14T14:11:54.487922"
} | stackv2 | /**
* \file ANN/tools.h
* \brief Some useful functions
* \author Cedric FARINAZZO
* \version 0.1
* \date 9 may 2019
*
* Some useful functions such as activation functions, cost functions or weight/bias initialization functions
*/
#ifndef _ANN_TOOLS_H_
#define _ANN_TOOLS_H_
#include "config.h"
#include <stdlib.h>
#include <math.h>
#include <time.h>
// Weight/bias initialization functions
/**
* \fn f_init_rand_norm()
* \brief Weight and bias initialization function for hidden and output layer
* \return a double between -1 and 1
*/
double f_init_rand_norm();
/**
* \fn f_init_input()
* \brief Weight and bias initialization function input layer
* \return 1
*/
double f_init_input();
// Activation functions
/**
* \fn f_act_sigmoid(double n)
* \brief Sigmoid activation function (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_sigmoid(double n);
/**
* \fn f_act_sigmoid_de(double n)
* \brief Derivative sigmoid activation function (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_sigmoid_de(double n);
/**
* \fn f_act_input(double n)
* \brief Activation function for input layer (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_input(double n);
/**
* \fn f_act_input_de(double n)
* \brief Derivative activation function for input layer (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_input_de(double n);
/**
* \fn f_act_relu(double n)
* \brief ReLu activation function (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_relu(double n);
/**
* \fn f_act_relu_de(double n)
* \brief Derivative ReLu activation function (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_relu_de(double n);
/**
* \fn f_act_softplus(double n)
* \brief SoftPlus activation function (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_softplus(double n);
/**
* \fn f_act_softplus_de(double n)
* \brief Derivative SoftPlus activation function (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_softplus_de(double n);
/**
\def F_ACT_ELU_ALPHA
Elu function constant: default 0.01
*/
#ifndef F_ACT_ELU_ALPHA
#define F_ACT_ELU_ALPHA 0.01
#endif /* F_ACT_ELU_ALPHA */
/**
* \fn f_act_elu(double n)
* \brief Elu activation function (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_elu(double n);
/**
* \fn f_act_elu_de(double n)
* \brief Derivative Elu activation function (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_elu_de(double n);
/**
* \fn f_act_swish(double n)
* \brief Swish activation function (for feedforward algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_swish(double n);
/**
* \fn f_act_swish_de(double n)
* \brief Derivative Swish activation function (for backpropagation algorithm)
* \param[in] n activation sum
* \return double
*/
double f_act_swish_de(double n);
// Cost functions
/**
\def F_COST_QUADRATIC_CONSTANT
Quadratic loss function constant: default 1/2
*/
#ifndef F_COST_QUADRATIC_CONSTANT
#define F_COST_QUADRATIC_CONSTANT 1/2
#endif /* F_COST_QUADRATIC_CONSTANT */
/**
* \fn f_cost_quadratic_loss(double o, double t)
* \brief Quadratic cost function
* \param[in] o output
* \param[in] t target
* \return double
*/
double f_cost_quadratic_loss(double o, double t);
/**
* \fn f_cost_quadratic_loss_de(double o, double t)
* \brief Derivative Quadratic cost function(for backpropagation algorithm)
* \param[in] o output
* \param[in] t target
* \return double
*/
double f_cost_quadratic_loss_de(double o, double t);
#endif /* _ANN_TOOLS_H_ */
| 2.65625 | 3 |
2024-11-18T22:11:33.009827+00:00 | 2019-05-11T11:25:02 | 714d68931865090fff0a35c21a49ba292ff458bc | {
"blob_id": "714d68931865090fff0a35c21a49ba292ff458bc",
"branch_name": "refs/heads/master",
"committer_date": "2019-05-11T11:25:02",
"content_id": "5a1245120dfe052f80ffa6233910b9cf7e3d47e5",
"detected_licenses": [
"MIT"
],
"directory_id": "dd4efed0be9a578f05b3b132f43adacd213674f5",
"extension": "c",
"filename": "cli.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 185970858,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 511,
"license": "MIT",
"license_type": "permissive",
"path": "/src/cli.c",
"provenance": "stackv2-0087.json.gz:1639",
"repo_name": "abzico/colorrectdump",
"revision_date": "2019-05-11T11:25:02",
"revision_id": "dbb9d54075d41d2f737add85c0d69cfeba1575e9",
"snapshot_id": "42de6fd3b23665aef3431beae0364b4d4db514a2",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/abzico/colorrectdump/dbb9d54075d41d2f737add85c0d69cfeba1575e9/src/cli.c",
"visit_date": "2020-05-21T08:02:01.764127"
} | stackv2 | #include "colorrectdump/cli.h"
#include <stdio.h>
void crd_print_help(int fd)
{
const char* help_text = "Usage: colorrectdump image-filepath|--help|--version";
if (fd == 1)
{
fprintf(stdout, "%s\n", help_text);
}
else
{
fprintf(stderr, "%s\n", help_text);
}
}
void crd_print_version(int fd)
{
const char* version_text = "colorrectdump v0.1 by Angry Baozi";
if (fd == 1)
{
fprintf(stdout, "%s\n", version_text);
}
else
{
fprintf(stderr, "%s\n", version_text);
}
}
| 2.21875 | 2 |
2024-11-18T22:11:33.497383+00:00 | 2023-04-18T07:47:33 | af0a25e45f374596b8a36af671b9717b27782774 | {
"blob_id": "af0a25e45f374596b8a36af671b9717b27782774",
"branch_name": "refs/heads/master",
"committer_date": "2023-04-18T07:47:33",
"content_id": "074029e07024fb216cefa3e06623ab9e56db2642",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "667518075af86c3e050277d5274be85762391403",
"extension": "h",
"filename": "sdp.h",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 103720631,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 5637,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/include/proto/sdp.h",
"provenance": "stackv2-0087.json.gz:1768",
"repo_name": "rozhuk-im/liblcb",
"revision_date": "2023-04-18T07:47:33",
"revision_id": "56e862e512171013aa9d916fe08d596bd3c5acdd",
"snapshot_id": "8711965bbdadbf1e66457f738e3fa364b7784816",
"src_encoding": "UTF-8",
"star_events_count": 3,
"url": "https://raw.githubusercontent.com/rozhuk-im/liblcb/56e862e512171013aa9d916fe08d596bd3c5acdd/include/proto/sdp.h",
"visit_date": "2023-05-01T17:06:30.636842"
} | stackv2 | /*-
* Copyright (c) 2012 - 2017 Rozhuk Ivan <rozhuk.im@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Author: Rozhuk Ivan <rozhuk.im@gmail.com>
*
*/
/*
* SDP: Session Description Protocol
* RFC 4566
*
*/
#ifndef __SDP_PROTO_H__
#define __SDP_PROTO_H__
#include <sys/types.h>
#include <inttypes.h>
#include "utils/mem_utils.h"
#ifndef CRLF
#define CRLF "\r\n"
#endif
/* Return value for specified type. */
static inline int
sdp_msg_type_get(uint8_t *sdp_msg, size_t sdp_msg_size, const uint8_t type,
size_t *line, uint8_t **val_ret, size_t *val_ret_size) {
uint8_t *val, *val_end;
size_t i, start_line;
if (NULL == sdp_msg || 0 == sdp_msg_size)
return (EINVAL);
/* Skeep first lines. */
val = (sdp_msg - 2);
start_line = (NULL != line) ? (*line) : 0;
for (i = 0; i < start_line && NULL != val; i ++) {
val = mem_find_ptr_cstr((val + 2), sdp_msg, sdp_msg_size, CRLF);
}
for (; NULL != val; i ++) {
val += 2;
if (type == (*val) && '=' == (*(val + 1))) {
/* Found! */
val += 2;
if (NULL != line) {
(*line) = i;
}
if (NULL != val_ret) {
(*val_ret) = val;
}
if (NULL != val_ret_size) {
val_end = mem_find_ptr_cstr(val, sdp_msg,
sdp_msg_size, CRLF);
if (NULL == val_end) {
val_end = (sdp_msg + sdp_msg_size);
}
(*val_ret_size) = (size_t)(val_end - val);
}
return (0);
}
/* Move to next value name. */
val = mem_find_ptr_cstr(val, sdp_msg, sdp_msg_size, CRLF);
}
return (EINVAL);
}
static inline size_t
sdp_msg_type_get_count(uint8_t *sdp_msg, size_t sdp_msg_size, const uint8_t type) {
size_t line = 0;
size_t ret = 0;
while (0 == sdp_msg_type_get(sdp_msg, sdp_msg_size, type, &line, NULL, NULL)) {
line ++;
ret ++;
}
return (ret);
}
/* Split buf to array of arguments, separated by SP return number of arguments. */
static inline size_t
sdp_msg_feilds_get(uint8_t *buf, size_t buf_size, size_t max_feilds,
uint8_t **feilds, size_t *feilds_sizes) {
uint8_t *cur_pos, *max_pos, *ptm;
size_t ret, data_size;
if (NULL == buf || 0 == buf_size || 0 == max_feilds || NULL == feilds)
return (0);
ret = 0;
cur_pos = buf;
max_pos = (buf + buf_size);
while (max_feilds > ret && max_pos > cur_pos) {
/* Calculate data size. */
ptm = mem_chr_ptr(cur_pos, buf, buf_size, ' ');
if (NULL != ptm) {
data_size = (size_t)(ptm - cur_pos);
} else {
data_size = (size_t)(max_pos - cur_pos);
}
feilds[ret] = cur_pos;
feilds_sizes[ret] = data_size;
ret ++;
/* Move to next arg. */
data_size ++;
cur_pos += data_size;
}
return (ret);
}
/* Check message format. */
static inline int
sdp_msg_sec_chk(uint8_t *sdp_msg, size_t sdp_msg_size) {
uint8_t *ptm, *msg_max;
/*
* Security checks:
* 1. Min size: 16
* 2. Start with: 'v=0'CRLF
* 3. Control codes: < 32, !=CRLF !=tab, > 126
* 4. Format: [CRLF]type=
* 5. "v=" count == 1 !
* 6. "o=" count == 1 !
* 7. "s=" count == 1 !
* 8. "t=" count > 0 !
* 9. "c=" count > 0 !
* 10. "m=" count > 0 !
* no order checks now.
*/
/* 1. */
if (16 > sdp_msg_size)
return (1);
/* 2. (4. - first line) */
if (0 != memcmp(sdp_msg, "v=0\r\n", 5))
return (2);
/* 3, 4. */
msg_max = (sdp_msg + sdp_msg_size);
for (ptm = sdp_msg; ptm < msg_max; ptm ++) {
if ((*ptm) > 31 || (*ptm) == '\t') /* XXX: tab? */
continue;
if ((*ptm) > 126)
return (3); /* Control codes. */
if ((*ptm) != '\r' || ((ptm + 1) < msg_max && (*(ptm + 1)) != '\n'))
return (3); /* Control codes. */
ptm ++; /* Skeep: CRLF. (point to LF) */
if ((ptm + 2) >= msg_max)
continue;
if ('a' > (*(ptm + 1)) || 'z' < (*(ptm + 1)))
return (3); /* Control codes / whitespace. */
if ('=' != (*(ptm + 2)))
return (4); /* Invalid format. */
ptm += 2; /* Skeep: '<type>='. (point to '=') */
}
/* 5. */
if (1 != sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 'v'))
return (5);
/* 6. */
if (1 != sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 'o'))
return (6);
/* 7. */
if (1 != sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 's'))
return (7);
/* 8. */
if (0 == sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 't'))
return (8);
/* 9. */
if (0 == sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 'c'))
return (9);
/* 10. */
if (0 == sdp_msg_type_get_count(sdp_msg, sdp_msg_size, 'm'))
return (9);
return (0);
}
#endif /* __SDP_PROTO_H__ */
| 2.03125 | 2 |
2024-11-18T22:11:34.006963+00:00 | 2021-06-24T14:31:25 | bfb191d51f8118c6706e22054888b92b130d2fe4 | {
"blob_id": "bfb191d51f8118c6706e22054888b92b130d2fe4",
"branch_name": "refs/heads/main",
"committer_date": "2021-06-24T14:31:25",
"content_id": "937d2e4fb2d6efb351c2161e9d9efd062203d166",
"detected_licenses": [
"MIT"
],
"directory_id": "8a9fc35be37178fe4063ac8d09d936353e622310",
"extension": "h",
"filename": "lexer.h",
"fork_events_count": 1,
"gha_created_at": "2021-05-04T17:23:58",
"gha_event_created_at": "2021-06-24T14:33:02",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 364333791,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1121,
"license": "MIT",
"license_type": "permissive",
"path": "/include/lexer.h",
"provenance": "stackv2-0087.json.gz:2284",
"repo_name": "bonlang/bonc",
"revision_date": "2021-06-24T14:31:25",
"revision_id": "d37691e0f05600be068911823dba270ce6f92074",
"snapshot_id": "261dd298a96af7f15666d101dde3718a961e118e",
"src_encoding": "UTF-8",
"star_events_count": 3,
"url": "https://raw.githubusercontent.com/bonlang/bonc/d37691e0f05600be068911823dba270ce6f92074/include/lexer.h",
"visit_date": "2023-06-14T02:16:01.025488"
} | stackv2 | #ifndef LEXER_H
#define LEXER_H
#include <stddef.h>
#include <stdint.h>
#include "helper.h"
typedef enum {
/* binary ops */
TOK_ADD,
TOK_SUB,
TOK_MUL,
TOK_DIV,
TOK_EQ,
TOK_DEQ, /* == */
TOK_NEQ,
TOK_GR, /* > */
TOK_LE, /* < */
TOK_GREQ, /* >= */
TOK_LEEQ, /* <= */
/* unary ops */
TOK_NOT,
/* open/closers */
TOK_LPAREN,
TOK_RPAREN,
TOK_LCURLY,
TOK_RCURLY,
TOK_LBRACK,
TOK_RBRACK,
/* punctuation */
TOK_COLON,
TOK_COMMA,
/* literals/symbols */
TOK_INT,
TOK_TRUE,
TOK_FALSE,
TOK_SYM,
/* type names */
TOK_I8,
TOK_I16,
TOK_I32,
TOK_I64,
TOK_U8,
TOK_U16,
TOK_U32,
TOK_U64,
TOK_BOOL,
/* keywords */
TOK_LET,
TOK_MUT,
TOK_RETURN,
/* misc. */
TOK_EOF,
TOK_NEWLINE,
} TokKind;
typedef enum {
INTLIT_I8,
INTLIT_U8,
INTLIT_I16,
INTLIT_U16,
INTLIT_I32,
INTLIT_U32,
INTLIT_I64,
INTLIT_U64,
INTLIT_I64_NONE,
} IntlitKind;
typedef struct {
TokKind t;
IntlitKind intlit_type;
SourcePosition pos;
} Token;
void lexer_init(const uint8_t *buf, size_t sz);
Token lexer_next();
Token lexer_peek();
#endif
| 2.296875 | 2 |
2024-11-18T22:11:34.641994+00:00 | 2019-08-06T14:24:54 | feb591d166e32f10080f4f74fafd29aa64d0aa59 | {
"blob_id": "feb591d166e32f10080f4f74fafd29aa64d0aa59",
"branch_name": "refs/heads/master",
"committer_date": "2019-08-06T14:24:54",
"content_id": "0daa665f963caa9669fe1154414d2fed43f515df",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "021a3ccdcb91d84629f1de7343981b572840b169",
"extension": "c",
"filename": "ex100.c",
"fork_events_count": 8,
"gha_created_at": "2016-02-22T11:40:41",
"gha_event_created_at": "2023-04-11T09:20:08",
"gha_language": "C",
"gha_license_id": "NOASSERTION",
"github_id": 52269402,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2943,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/src/ksp/ksp/examples/tutorials/ex100.c",
"provenance": "stackv2-0087.json.gz:2930",
"repo_name": "firedrakeproject/petsc",
"revision_date": "2019-08-06T14:24:54",
"revision_id": "7afe75c1a0a66862f32d7a0f5c0c5ae5079c4c77",
"snapshot_id": "dcf7b32e83bdc88d37099904960d7a4c3c4a89e4",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/firedrakeproject/petsc/7afe75c1a0a66862f32d7a0f5c0c5ae5079c4c77/src/ksp/ksp/examples/tutorials/ex100.c",
"visit_date": "2023-08-31T22:16:45.175956"
} | stackv2 | #include <petscksp.h>
/* ------------------------------------------------------- */
PetscErrorCode RunTest(void)
{
PetscInt N = 100, its = 0;
PetscBool draw = PETSC_FALSE, test = PETSC_FALSE;
PetscReal rnorm;
Mat A;
Vec b,x,r;
KSP ksp;
PC pc;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = PetscOptionsGetInt(NULL,NULL,"-N",&N,NULL);CHKERRQ(ierr);
ierr = PetscOptionsGetBool(NULL,NULL,"-test",&test,NULL);CHKERRQ(ierr);
ierr = PetscOptionsGetBool(NULL,NULL,"-draw",&draw,NULL);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,N,N);CHKERRQ(ierr);
ierr = MatSetType(A,MATPYTHON);CHKERRQ(ierr);
ierr = MatPythonSetType(A,"example100.py:Laplace1D");CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatCreateVecs(A,&x,&b);CHKERRQ(ierr);
ierr = VecSet(b,1);CHKERRQ(ierr);
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
ierr = KSPSetType(ksp,KSPPYTHON);CHKERRQ(ierr);
ierr = KSPPythonSetType(ksp,"example100.py:ConjGrad");CHKERRQ(ierr);
ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);
ierr = PCSetType(pc,PCPYTHON);CHKERRQ(ierr);
ierr = PCPythonSetType(pc,"example100.py:Jacobi");CHKERRQ(ierr);
ierr = KSPSetOperators(ksp,A,A);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
if (test) {
ierr = KSPGetTotalIterations(ksp,&its);CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD,"Number of KSP iterations = %D\n", its);CHKERRQ(ierr);
} else {
ierr = VecDuplicate(b,&r);CHKERRQ(ierr);
ierr = MatMult(A,x,r);CHKERRQ(ierr);
ierr = VecAYPX(r,-1,b);CHKERRQ(ierr);
ierr = VecNorm(r,NORM_2,&rnorm);CHKERRQ(ierr);
ierr = PetscPrintf(PETSC_COMM_WORLD,"error norm = %g\n",rnorm);CHKERRQ(ierr);
ierr = VecDestroy(&r);CHKERRQ(ierr);
}
if (draw) {
ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
ierr = PetscSleep(2);CHKERRQ(ierr);
}
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = VecDestroy(&b);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
/* ------------------------------------------------------- */
static char help[] = "Python-implemented Mat/KSP/PC.\n\n";
/*
#define PYTHON_EXE "python2.5"
#define PYTHON_LIB "/usr/lib/libpython2.5"
*/
#if !defined(PYTHON_EXE)
#define PYTHON_EXE 0
#endif
#if !defined(PYTHON_LIB)
#define PYTHON_LIB 0
#endif
int main(int argc, char *argv[])
{
PetscErrorCode ierr;
ierr = PetscInitialize(&argc,&argv,0,help);if (ierr) return ierr;
ierr = PetscPythonInitialize(PYTHON_EXE,PYTHON_LIB);CHKERRQ(ierr);
ierr = RunTest();PetscPythonPrintError();CHKERRQ(ierr);
ierr = PetscFinalize();
return ierr;
}
/*TEST
test:
args: -ksp_monitor_short
requires: petsc4py
localrunfiles: example100.py
TEST*/
| 2.03125 | 2 |
2024-11-18T22:11:34.821526+00:00 | 2023-08-17T13:00:20 | 654c4c3ccdff32bd8dc8ec7c660255fd09a0259d | {
"blob_id": "654c4c3ccdff32bd8dc8ec7c660255fd09a0259d",
"branch_name": "refs/heads/master",
"committer_date": "2023-08-31T07:43:37",
"content_id": "d5fcd0912d87858e227c853d7de8879565cfc5ee",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "c9bc99866cfab223c777cfb741083be3e9439d81",
"extension": "h",
"filename": "scmi.h",
"fork_events_count": 165,
"gha_created_at": "2018-05-22T10:35:56",
"gha_event_created_at": "2023-09-13T14:27:10",
"gha_language": "C",
"gha_license_id": "NOASSERTION",
"github_id": 134399880,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2542,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/module/scmi/include/internal/scmi.h",
"provenance": "stackv2-0087.json.gz:3186",
"repo_name": "ARM-software/SCP-firmware",
"revision_date": "2023-08-17T13:00:20",
"revision_id": "f6bcca436768359ffeadd84d65e8ea0c3efc7ef1",
"snapshot_id": "4738ca86ce42d82588ddafc2226a1f353ff2c797",
"src_encoding": "UTF-8",
"star_events_count": 211,
"url": "https://raw.githubusercontent.com/ARM-software/SCP-firmware/f6bcca436768359ffeadd84d65e8ea0c3efc7ef1/module/scmi/include/internal/scmi.h",
"visit_date": "2023-09-01T16:13:36.962036"
} | stackv2 | /*
* Arm SCP/MCP Software
* Copyright (c) 2015-2021, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* Description:
* System Control and Management Interface (SCMI) protocol independent
* definitions.
*/
#ifndef INTERNAL_SCMI_H
#define INTERNAL_SCMI_H
#include <stdint.h>
/*!
* \defgroup GroupSCMI System Control & Management Interface (SCMI)
* \{
*/
/*!
* \brief Entity role.
*/
enum scmi_role {
/*! Agent entity */
SCMI_ROLE_AGENT,
/*! Platform entity */
SCMI_ROLE_PLATFORM
};
/*!
* \brief Agent type
*
* \details The SCMI specification defines three specific agent types:
* - a PSCI implementation on AP processors.
* - a management agent.
* - an OSPM.
* The POWER_STATE_SET command targeting a power domain, including AP
* cores, is processed only if issued by a PSCI agent. The processing of
* the SYSTEM_POWER_STATE_SET command depends on the type of the agent that
* issued it. The OTHER type is added here to cover the other type of
* agents.
*/
enum scmi_agent_type {
/*! PSCI agent */
SCMI_AGENT_TYPE_PSCI,
/*! Management agent */
SCMI_AGENT_TYPE_MANAGEMENT,
/*! OSPM agent */
SCMI_AGENT_TYPE_OSPM,
/*! Other agent */
SCMI_AGENT_TYPE_OTHER,
/*! Number of agent types */
SCMI_AGENT_TYPE_COUNT,
};
/*!
* \brief Channel type.
*
* \details Defines the channel direction in terms of the requester to the
* completer.
*
* \note The integer values of this enumeration are based on the requester of
* communications in that configuration.
*/
enum scmi_channel_type {
/*!< Agent-to-platform */
SCMI_CHANNEL_TYPE_A2P = SCMI_ROLE_AGENT,
/*!< Platform-to-agent */
SCMI_CHANNEL_TYPE_P2A = SCMI_ROLE_PLATFORM
};
/*!
* \brief Generic platform-to-agent PROTOCOL_VERSION structure.
*/
struct scmi_protocol_version_p2a {
int32_t status;
uint32_t version;
};
/*!
* \brief Generic platform-to-agent PROTOCOL_ATTRIBUTES structure.
*/
struct scmi_protocol_attributes_p2a {
int32_t status;
uint32_t attributes;
};
/*!
* \brief Generic agent-to-platform PROTOCOL_MESSAGE_ATTRIBUTES structure.
*/
struct scmi_protocol_message_attributes_a2p {
uint32_t message_id;
};
/*!
* \brief Generic platform-to-agent PROTOCOL_MESSAGE_ATTRIBUTES structure.
*/
struct scmi_protocol_message_attributes_p2a {
int32_t status;
uint32_t attributes;
};
/*!
* \}
*/
#endif /* INTERNAL_SCMI_H */
| 2.15625 | 2 |
2024-11-18T22:11:35.304638+00:00 | 2015-08-12T20:20:37 | 2bfb9ec92ea3544bb321e3fa1e0dc9ef4de78cd9 | {
"blob_id": "2bfb9ec92ea3544bb321e3fa1e0dc9ef4de78cd9",
"branch_name": "refs/heads/master",
"committer_date": "2015-08-12T20:20:37",
"content_id": "fa6067e065a2663c21bfca860c3dfc1305245126",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "86f026381e488b879214d22f28b68fb6eb23cd6d",
"extension": "c",
"filename": "blang-doc.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 33747410,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 8910,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/psh/blang-doc.c",
"provenance": "stackv2-0087.json.gz:3443",
"repo_name": "sabrown256/pactnew",
"revision_date": "2015-08-12T20:20:37",
"revision_id": "c5952f6edb5e41fbd91ed91cc3f0038cc59505a0",
"snapshot_id": "1490a4a46fe71d3bf3ad15fb449b8f7f3869135b",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/sabrown256/pactnew/c5952f6edb5e41fbd91ed91cc3f0038cc59505a0/psh/blang-doc.c",
"visit_date": "2016-09-06T13:37:35.294245"
} | stackv2 | /*
* BLANG-DOC.C - generate documentation
*
* #include "cpyright.h"
*
*/
static int
MODE_DOC = -1;
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* INIT_DOC - initialize Doc file */
static void init_doc(statedes *st, bindes *bd)
{char fn[BFLRG];
const char *pck;
FILE *fp;
pck = st->pck;
if ((st->path == NULL) || (strcmp(st->path, ".") == 0))
snprintf(fn, BFLRG, "gh-%s.html", pck);
else
snprintf(fn, BFLRG, "%s/gh-%s.html", st->path, pck);
fp = open_file("w", fn);
fprintf(fp, "\n");
hsep(fp);
bd->fp[0] = fp;
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* DOC_PROTO_NAME_ONLY - render the arg list of DCL into A using
* - variable names only
*/
void doc_proto_name_only(char *a, int nc, fdecl *dcl, const char *dlm)
{int i, na;
farg *al;
na = dcl->na;
al = dcl->al;
a[0] = '\0';
if (na != 0)
{if (dlm == NULL)
{for (i = 0; i < na; i++)
vstrcat(a, BFLRG, " %s", al[i].name);}
else
{for (i = 0; i < na; i++)
vstrcat(a, BFLRG, " %s%s", al[i].name, dlm);
a[strlen(a)-strlen(dlm)] = '\0';};};
memmove(a, trim(a, BOTH, " "), nc);
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* FIND_COMMENT - return a pointer to the part of CDC which
* - documents CFN
*/
static char **find_comment(const char *cfn, int ndc, char **cdc)
{int i;
char *s, **com;
com = NULL;
for (i = 0; (i < ndc) && (com == NULL); i++)
{s = cdc[i];
if ((strstr(s, "#bind") != NULL) &&
(strstr(s, cfn) != NULL))
{for ( ; i >= 0; i--)
{s = cdc[i];
if (strncmp(s, "/*", 2) == 0)
{com = cdc + i;
break;};};};};
return(com);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* PROCESS_DOC - process the comments into a string */
static void process_doc(char *t, int nc, char **com)
{int i;
char *s, *p;
t[0] = '\0';
if (com != NULL)
{for (i = 0; IS_NULL(com[i]) == FALSE; i++)
{s = com[i] + 3;
if (strstr(s, "#bind ") == NULL)
{p = strchr(s, '-');
if (p != NULL)
vstrcat(t, nc, "%s\n", p+2);
else
nstrcat(t, nc, "\n");};};};
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* HTML_WRAP - wrap C function DCL in HTML form */
static void html_wrap(FILE *fp, fdecl *dcl, const char *sb, int ndc,
char **cdc)
{int ib;
char upn[BFLRG], lfn[BFLRG];
char fty[BFLRG], t[BFLRG];
char *cfn, **com;
bindes *pb;
cfn = dcl->proto.name;
com = find_comment(cfn, ndc, cdc);
nstrncpy(upn, BFLRG, cfn, -1);
upcase(upn);
nstrncpy(lfn, BFLRG, cfn, -1);
downcase(lfn);
cf_type(fty, BFLRG, dcl->proto.type);
hsep(fp);
fprintf(fp, "\n");
fprintf(fp, "<a name=\"%s\"><h2>%s</h2></a>\n", lfn, upn);
fprintf(fp, "\n");
fprintf(fp, "<p>\n");
fprintf(fp, "<pre>\n");
/* emit the contributions from the various languages */
for (pb = gbd, ib = 0; ib < nbd; ib++, pb++)
{if (pb->doc != NULL)
pb->doc(fp, dcl, DK_HTML);};
fprintf(fp, "</pre>\n");
fprintf(fp, "<p>\n");
process_doc(t, BFLRG, com);
if (IS_NULL(t) == FALSE)
{fprintf(fp, "<pre>\n");
fputs(t, fp);
fprintf(fp, "</pre>\n");};
fprintf(fp, "<p>\n");
fprintf(fp, "\n");
hsep(fp);
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* MAN_WRAP - wrap C function DCL in MAN form */
static void man_wrap(statedes *st, fdecl *dcl,
const char *sb, const char *pck, int ndc, char **cdc)
{int ib, voidf;
int tm[6];
char fname[BFLRG], upk[BFLRG];
char upn[BFLRG], lfn[BFLRG];
char fty[BFLRG], t[BFLRG];
char *cfn, **com;
FILE *fp;
bindes *pb;
cfn = dcl->proto.name;
voidf = dcl->voidf;
com = find_comment(cfn, ndc, cdc);
nstrncpy(upk, BFLRG, pck, -1);
upcase(upk);
nstrncpy(upn, BFLRG, cfn, -1);
upcase(upn);
nstrncpy(lfn, BFLRG, cfn, -1);
downcase(lfn);
cf_type(fty, BFLRG, dcl->proto.type);
if ((st->path == NULL) || (strcmp(st->path, ".") == 0))
snprintf(fname, BFLRG, "%s.3", cfn);
else
snprintf(fname, BFLRG, "%s/%s.3", st->path, cfn);
fp = fopen_safe(fname, "w");
if (fp == NULL)
return;
get_date_p(tm, 6);
fprintf(fp, ".\\\"\n");
fprintf(fp, ".\\\" See the terms of include/cpyright.h\n");
fprintf(fp, ".\\\"\n");
fprintf(fp, ".TH %s 3 %4d-%02d-%02d \"%s\" \"%s Documentation\"\n",
upn, tm[5], tm[4], tm[3], upk, upk);
fprintf(fp, ".SH NAME\n");
fprintf(fp, "%s \\- \n", cfn);
fprintf(fp, ".SH SYNOPSIS\n");
fprintf(fp, ".nf\n");
fprintf(fp, ".B #include <%s.h>\n", pck);
fprintf(fp, ".sp\n");
/* emit the contributions from the various languages */
for (pb = gbd, ib = 0; ib < nbd; ib++, pb++)
{if (pb->doc != NULL)
pb->doc(fp, dcl, DK_MAN);};
process_doc(t, BFLRG, com);
if (IS_NULL(t) == FALSE)
{fprintf(fp, ".fi\n");
fprintf(fp, ".SH DESCRIPTION\n");
fprintf(fp, "%s\n", t);};
if (voidf == TRUE)
{fprintf(fp, ".SH RETURN VALUE\n");
fprintf(fp, "none\n");
fprintf(fp, ".sp\n");};
fprintf(fp, ".SH COPYRIGHT\n");
fprintf(fp, "include/cpyright.h\n");
fprintf(fp, ".sp\n");
fprintf(fp, "\n");
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* BIND_DOC - generate Doc bindings from CPR and SBI
* - return TRUE iff successful
*/
static int bind_doc(bindes *bd)
{int ib, ndc, ndcl, rv;
char **cdc;
const char *pck;
fdecl *dcl, *dcls;
statedes *st;
FILE *fp;
fp = bd->fp[0];
st = bd->st;
ndc = bd->iparam[0];
cdc = st->cdc;
pck = st->pck;
dcls = st->dcl;
ndcl = st->ndcl;
rv = TRUE;
for (ib = 0; ib < ndcl; ib++)
{dcl = dcls + ib;
if (dcl->error == FALSE)
{html_wrap(fp, dcl, NULL, ndc, cdc);
man_wrap(st, dcl, NULL, pck, ndc, cdc);};};
return(rv);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* FIN_DOC - finalize Doc file */
static void fin_doc(bindes *bd)
{int i;
FILE *fp;
fp = bd->fp[0];
hsep(fp);
for (i = 0; i < NF; i++)
{fp = bd->fp[i];
if (fp != NULL)
{fclose_safe(fp);
bd->fp[i] = NULL;};};
return;}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* CL_DOC - process command line arguments for doc binding */
static int cl_doc(statedes *st, bindes *bd, int c, char **v)
{int i;
char *cdc, **sdc;
bd->iparam = MAKE_N(int, 1);
cdc = "";
for (i = 1; i < c; i++)
{if (strcmp(v[i], "-d") == 0)
cdc = v[++i];
else if (strcmp(v[i], "-h") == 0)
{printf(" Documentation options: [-d <doc>] [-nod]\n");
printf(" d file containing documentation comments\n");
printf(" nod do not generate documentation\n");
printf("\n");
return(1);}
else if (strcmp(v[i], "-nod") == 0)
st->no[MODE_DOC] = FALSE;};
sdc = file_text(FALSE, cdc);
st->cdc = sdc;
bd->iparam[0] = lst_length(sdc);
return(0);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/* REGISTER_DOC - register documentation methods */
static int register_doc(int fl, statedes *st)
{int i;
bindes *pb;
MODE_DOC = nbd;
if (fl == TRUE)
{pb = gbd + nbd++;
for (i = 0; i < NF; i++)
pb->fp[i] = NULL;
pb->lang = "doc";
pb->st = st;
pb->data = NULL;
pb->cl = cl_doc;
pb->init = init_doc;
pb->bind = bind_doc;
pb->doc = NULL;
pb->fin = fin_doc;};
return(MODE_DOC);}
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
| 2.15625 | 2 |
2024-11-18T22:11:36.218065+00:00 | 2022-08-21T20:43:20 | 44c81012a0155b19bba84d889275c8bae62210f0 | {
"blob_id": "44c81012a0155b19bba84d889275c8bae62210f0",
"branch_name": "refs/heads/master",
"committer_date": "2022-08-21T20:43:20",
"content_id": "0bc5043f0cbc1ca0ad3498baa7e756008f96c5b4",
"detected_licenses": [
"MIT"
],
"directory_id": "5ed309213e89fcec826eceaa2f1cd68d8c548aa4",
"extension": "c",
"filename": "Arrays and Merging.c",
"fork_events_count": 8,
"gha_created_at": "2019-12-02T18:55:54",
"gha_event_created_at": "2022-04-30T19:18:00",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 225446827,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 796,
"license": "MIT",
"license_type": "permissive",
"path": "/Hard/C/Arrays and Merging.c",
"provenance": "stackv2-0087.json.gz:3700",
"repo_name": "Aimnos/Dcoder-Challenges",
"revision_date": "2022-08-21T20:43:20",
"revision_id": "8f738ab230597b1a016e57460fff273c9e7fecfb",
"snapshot_id": "79f4d6583ae7179d7446c71cac9f00a779f06a82",
"src_encoding": "UTF-8",
"star_events_count": 31,
"url": "https://raw.githubusercontent.com/Aimnos/Dcoder-Challenges/8f738ab230597b1a016e57460fff273c9e7fecfb/Hard/C/Arrays and Merging.c",
"visit_date": "2022-08-24T20:14:04.441194"
} | stackv2 | #include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
uint8_t m;
scanf("%" SCNu8, &m);
uint32_t* array = malloc(m * sizeof(uint32_t));
for (uint8_t i = 0; i < m; ++i)
scanf("%" SCNu32, &array[i]);
uint8_t n;
scanf("%" SCNu8, &n);
array = realloc(array, (m + n) * sizeof(uint32_t));
for (uint8_t i = m; i < m + n; ++i)
scanf("%" SCNu32, &array[i]);
uint8_t k;
scanf("%" SCNu8, &k);
for (uint8_t i = 0; i < k; ++i) {
uint8_t smallest_pos = i;
for (uint8_t j = i + 1; j < m + n; ++j)
if (array[j] < array[smallest_pos])
smallest_pos = j;
array[smallest_pos] = array[i];
}
printf("%" PRIu32, array[k - 1]);
free(array);
}
| 2.890625 | 3 |
2024-11-18T22:11:36.313548+00:00 | 2021-02-17T14:25:33 | 3152e7db012384058b25d10571d48216bc570f8c | {
"blob_id": "3152e7db012384058b25d10571d48216bc570f8c",
"branch_name": "refs/heads/master",
"committer_date": "2021-02-17T14:25:33",
"content_id": "c5ec9191ad5c60ad56d2c6c95dacf3a956346cb9",
"detected_licenses": [
"MIT"
],
"directory_id": "7c95ce7736d2beffef02260e414a5c01930bf0e8",
"extension": "h",
"filename": "token.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 292926255,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 389,
"license": "MIT",
"license_type": "permissive",
"path": "/include/token.h",
"provenance": "stackv2-0087.json.gz:3829",
"repo_name": "jhosoume/porygon_lang",
"revision_date": "2021-02-17T14:25:33",
"revision_id": "5fd1cc00f66d08f2301c978c9af716d83db1e3b9",
"snapshot_id": "27e6570e03481f4fe5c990a583a29812b5b67955",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/jhosoume/porygon_lang/5fd1cc00f66d08f2301c978c9af716d83db1e3b9/include/token.h",
"visit_date": "2023-03-02T18:20:32.461494"
} | stackv2 | #ifndef TOKEN_H
#define TOKEN_H
#include "token_type.h"
/* Defines a token that will be returned by the scanner */
struct token {
enum yytokentype tok_type;
const char * att_value;
};
/* Returns a token from the information provided. */
struct token create_token(enum yytokentype tok_type, const char * value);
/* Prints a token. */
void print_token(struct token tok);
#endif
| 2.046875 | 2 |
2024-11-18T22:11:36.594521+00:00 | 2018-06-09T10:58:38 | f7234c1cf1de127500bc1def7b109736aea358d7 | {
"blob_id": "f7234c1cf1de127500bc1def7b109736aea358d7",
"branch_name": "refs/heads/master",
"committer_date": "2018-06-09T10:58:38",
"content_id": "eb073a73c7f7b4ef97ac5c857e43ef7500375261",
"detected_licenses": [
"MIT"
],
"directory_id": "03b39c11d9e73bf4aee483dcd05af3865ebd9998",
"extension": "c",
"filename": "vmm.c",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 127878014,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 4668,
"license": "MIT",
"license_type": "permissive",
"path": "/ucore/src/kern-ucore/arch/um/mm/vmm.c",
"provenance": "stackv2-0087.json.gz:4088",
"repo_name": "oscourse-tsinghua/OS2018spring-projects-g14",
"revision_date": "2018-06-09T10:58:38",
"revision_id": "94155cc7e560c740bf6d2938c1f08a2f3ac0ffb8",
"snapshot_id": "b51b8120b7dffc3923bb4de311dcf8f9d60fcea6",
"src_encoding": "UTF-8",
"star_events_count": 5,
"url": "https://raw.githubusercontent.com/oscourse-tsinghua/OS2018spring-projects-g14/94155cc7e560c740bf6d2938c1f08a2f3ac0ffb8/ucore/src/kern-ucore/arch/um/mm/vmm.c",
"visit_date": "2020-03-08T03:00:33.365276"
} | stackv2 | #include <vmm.h>
#include <types.h>
#include <host_syscall.h>
#include <proc.h>
#include <memlayout.h>
#include <pmm.h>
#include <mmu.h>
#include <string.h>
/**
* Copy data from user space.
* @param mm where the user data belongs to
* @param dst destination where data should be copied to (kernel space)
* @param src source address of the user data (user space)
* @param len the length of data
* @param writable whether the area should be writable
* @return 1 if the operation succeeds, and 0 if not
*/
bool
copy_from_user(struct mm_struct *mm, void *dst, const void *src, size_t len,
bool writable)
{
/* Make sure that the address is valid */
if (!user_mem_check(mm, (uintptr_t) src, len, writable)) {
return 0;
}
/* If no mm is specified, dst should be available in main process. */
if (mm == NULL) {
memcpy(dst, src, len);
return 1;
}
/* Copy data page by page. */
while (len > 0) {
/* Touch the page so that its status will be right after copying. */
if (host_getvalue(pls_read(current), (uintptr_t) src, NULL) < 0) {
return 0;
}
/* Determine the size to copy */
size_t avail = ROUNDUP(src, PGSIZE) - src;
if (PGOFF(src) == 0)
avail += PGSIZE;
if (avail > len)
avail = len;
/* Calculate the offset in the tmp file where the data can be found. */
pte_t *ptep = get_pte(mm->pgdir, (uintptr_t) src, 0);
assert(ptep != NULL && (*ptep & PTE_P));
uintptr_t addr = KERNBASE + PTE_ADDR(*ptep) + PGOFF(src);
/* Now copy the data. */
memcpy(dst, (void *)addr, avail);
len -= avail;
dst += avail;
src += avail;
}
return 1;
}
/**
* Write to user space.
* @param mm the user memory space where we need to write to
* @param dst the address where the data is copied to (user space)
* @param src the address of the data to be written (kernel space)
* @param len the length of the data
* @return 1 if the operation succeeds, and 0 if not
*/
bool copy_to_user(struct mm_struct * mm, void *dst, const void *src, size_t len)
{
/* Check whether the address specified is writable. */
if (!user_mem_check(mm, (uintptr_t) dst, len, 1)) {
return 0;
}
/* If no mm is specified, dst should be accessible in main process. */
if (mm == NULL) {
memcpy(dst, src, len);
return 1;
}
/* Write data page by page. */
while (len > 0) {
/* Touch the page so that the status of the entry is right. */
if (host_assign(pls_read(current), (uintptr_t) dst, 0) < 0)
return 0;
/* Determine the length which should be copied in the current page. */
size_t avail = ROUNDUP(dst, PGSIZE) - dst;
if (PGOFF(dst) == 0)
avail += PGSIZE;
if (avail > len)
avail = len;
/* Calculate the offset in the tmp file of the page. */
pte_t *ptep = get_pte(mm->pgdir, (uintptr_t) dst, 0);
assert(ptep != NULL && (*ptep & PTE_P));
uintptr_t addr = KERNBASE + PTE_ADDR(*ptep) + PGOFF(dst);
/* Carry out... */
memcpy((void *)addr, src, avail);
len -= avail;
dst += avail;
src += avail;
}
return 1;
}
/**
* Copy a string ended with '\0' from user space.
* @param mm the user space of the original string
* @param dst destination of the string (in kernel space)
* @param src pointer to the string (in user space)
* @param maxn the max length of the string
* @return 1 if succeeds and 0 otherwise
*/
bool copy_string(struct mm_struct * mm, char *dst, const char *src, size_t maxn)
{
/* If no use space is specified, dst should be accessible in the main process. */
if (mm == NULL) {
int alen = strnlen((const char *)src, maxn);
memcpy(dst, (void *)src, alen);
*(dst + alen) = 0;
return 1;
}
/* Copy the string page by page. */
while (maxn > 0) {
/* Determine the max length which can be copied in the current page. */
size_t avail = ROUNDUP(src, PGSIZE) - src;
if (PGOFF(src) == 0)
avail += PGSIZE;
if (avail > maxn)
avail = maxn;
/* Check whether the area is readable. */
if (!user_mem_check(mm, (uintptr_t) src, avail, 0))
goto fail;
/* Touch the page to make the page entry right. */
if (host_getvalue(pls_read(current), (uintptr_t) src, NULL) < 0)
goto fail;
/* Get the offset in the tmp file of the page where the string is */
pte_t *ptep = get_pte(mm->pgdir, (uintptr_t) src, 0);
assert(ptep != NULL && (*ptep & PTE_P));
uintptr_t addr = KERNBASE + PTE_ADDR(*ptep) + PGOFF(src);
/* Calculate the actual length to be copied and carry it out. */
size_t alen = strnlen((const char *)addr, avail);
memcpy(dst, (void *)addr, alen);
maxn -= alen;
dst += alen;
src += alen;
if (alen < avail)
break;
}
/* the copied string should be ended with '\0'. */
*dst = 0;
return 1;
fail:
*dst = 0;
return 0;
}
| 2.984375 | 3 |
2024-11-18T22:11:36.719638+00:00 | 2017-06-03T12:26:04 | 576cf6016776bb61affe6ce9f89ee6f0c60898b5 | {
"blob_id": "576cf6016776bb61affe6ce9f89ee6f0c60898b5",
"branch_name": "refs/heads/master",
"committer_date": "2017-06-03T12:26:04",
"content_id": "7402eaa8b8bc63d8edc7973a5d9af660d01a47fb",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "3839a59d66f65daaaf9f8f12ed1952223ecc116c",
"extension": "c",
"filename": "ieee802154_qemu_test.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 80175240,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1493,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/samples/net/ieee802154/qemu/src/ieee802154_qemu_test.c",
"provenance": "stackv2-0087.json.gz:4218",
"repo_name": "Jason0204/jasontek_f103rb-zephyrOS-project",
"revision_date": "2017-06-03T12:26:04",
"revision_id": "21f354f9f0f13ff5f9fe0ed4236fa79635068591",
"snapshot_id": "74e7863222c05e10f30a1c8951c43af60bc57baf",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/Jason0204/jasontek_f103rb-zephyrOS-project/21f354f9f0f13ff5f9fe0ed4236fa79635068591/samples/net/ieee802154/qemu/src/ieee802154_qemu_test.c",
"visit_date": "2021-01-11T14:37:16.982857"
} | stackv2 | /*
* Copyright (c) 2016 Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <zephyr.h>
#include <errno.h>
#include <net/net_if.h>
#include <net/net_core.h>
#if defined(CONFIG_STDOUT_CONSOLE)
#include <stdio.h>
#define PRINT printf
#else
#include <misc/printk.h>
#define PRINT printk
#endif
struct in6_addr addr6 = { { { 0x20, 0x01, 0x0d, 0xb8, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0x1 } } };
static struct net_if *init_device(void)
{
struct net_if *iface;
struct device *dev;
dev = device_get_binding(CONFIG_UPIPE_15_4_DRV_NAME);
if (!dev) {
PRINT("Cannot get UPIPE device\n");
return NULL;
}
iface = net_if_lookup_by_dev(dev);
if (!iface) {
PRINT("Cannot get UPIPE network interface\n");
return NULL;
}
net_if_ipv6_addr_add(iface, &addr6, NET_ADDR_MANUAL, 0);
PRINT("802.15.4 device up and running\n");
return iface;
}
void main(void)
{
struct net_if *iface;
iface = init_device();
return;
}
| 2.28125 | 2 |
2024-11-18T22:11:36.787165+00:00 | 2022-10-03T19:40:05 | 242da9a5fadab8c39e6843c7375a32cdb19f7365 | {
"blob_id": "242da9a5fadab8c39e6843c7375a32cdb19f7365",
"branch_name": "refs/heads/master",
"committer_date": "2022-10-03T19:40:05",
"content_id": "6c3403e733c56d4703f9d2b6082e05ee8d253bc1",
"detected_licenses": [
"MIT"
],
"directory_id": "1885ce333f6980ab6aad764b3f8caf42094d9f7d",
"extension": "h",
"filename": "SkPolyUtils.h",
"fork_events_count": 26,
"gha_created_at": "2014-02-08T12:20:01",
"gha_event_created_at": "2023-06-26T13:44:32",
"gha_language": "C++",
"gha_license_id": "MIT",
"github_id": 16642636,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 5003,
"license": "MIT",
"license_type": "permissive",
"path": "/test/e2e/test_input/skia/src/utils/SkPolyUtils.h",
"provenance": "stackv2-0087.json.gz:4348",
"repo_name": "satya-das/cppparser",
"revision_date": "2022-10-03T19:40:05",
"revision_id": "f9a4cfac1a3af7286332056d7c661d86b6c35eb3",
"snapshot_id": "1dbccdeed4287c36c61edc30190c82de447e415b",
"src_encoding": "UTF-8",
"star_events_count": 194,
"url": "https://raw.githubusercontent.com/satya-das/cppparser/f9a4cfac1a3af7286332056d7c661d86b6c35eb3/test/e2e/test_input/skia/src/utils/SkPolyUtils.h",
"visit_date": "2023-07-06T00:55:23.382303"
} | stackv2 | /*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkOffsetPolygon_DEFINED
#define SkOffsetPolygon_DEFINED
#include <functional>
#include "include/core/SkPoint.h"
#include "include/private/SkTDArray.h"
struct SkRect;
/**
* Generates a polygon that is inset a constant from the boundary of a given convex polygon.
*
* @param inputPolygonVerts Array of points representing the vertices of the original polygon.
* It should be convex and have no coincident points.
* @param inputPolygonSize Number of vertices in the original polygon.
* @param inset How far we wish to inset the polygon. This should be a positive value.
* @param insetPolygon The resulting inset polygon, if any.
* @return true if an inset polygon exists, false otherwise.
*/
bool SkInsetConvexPolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
SkScalar inset, SkTDArray<SkPoint>* insetPolygon);
/**
* Generates a simple polygon (if possible) that is offset a constant distance from the boundary
* of a given simple polygon.
* The input polygon must be simple and have no coincident vertices or collinear edges.
*
* @param inputPolygonVerts Array of points representing the vertices of the original polygon.
* @param inputPolygonSize Number of vertices in the original polygon.
* @param bounds Bounding rectangle for the original polygon.
* @param offset How far we wish to offset the polygon.
* Positive values indicate insetting, negative values outsetting.
* @param offsetPolgon The resulting offset polygon, if any.
* @param polygonIndices The indices of the original polygon that map to the new one.
* @return true if an offset simple polygon exists, false otherwise.
*/
bool SkOffsetSimplePolygon(const SkPoint* inputPolygonVerts, int inputPolygonSize,
const SkRect& bounds, SkScalar offset, SkTDArray<SkPoint>* offsetPolygon,
SkTDArray<int>* polygonIndices = nullptr);
/**
* Compute the number of points needed for a circular join when offsetting a vertex.
* The lengths of offset0 and offset1 don't have to equal |offset| -- only the direction matters.
* The segment lengths will be approximately four pixels.
*
* @param offset0 Starting offset vector direction.
* @param offset1 Ending offset vector direction.
* @param offset Offset value (can be negative).
* @param rotSin Sine of rotation delta per step.
* @param rotCos Cosine of rotation delta per step.
* @param n Number of steps to fill out the arc.
* @return true for success, false otherwise
*/
bool SkComputeRadialSteps(const SkVector& offset0, const SkVector& offset1, SkScalar offset,
SkScalar* rotSin, SkScalar* rotCos, int* n);
/**
* Determine winding direction for a polygon.
* The input polygon must be simple or the result will be meaningless.
*
* @param polygonVerts Array of points representing the vertices of the polygon.
* @param polygonSize Number of vertices in the polygon.
* @return 1 for cw, -1 for ccw, and 0 if zero signed area (either degenerate or self-intersecting).
* The y-axis is assumed to be pointing down.
*/
int SkGetPolygonWinding(const SkPoint* polygonVerts, int polygonSize);
/**
* Determine whether a polygon is convex or not.
*
* @param polygonVerts Array of points representing the vertices of the polygon.
* @param polygonSize Number of vertices in the polygon.
* @return true if the polygon is convex, false otherwise.
*/
bool SkIsConvexPolygon(const SkPoint* polygonVerts, int polygonSize);
/**
* Determine whether a polygon is simple (i.e., not self-intersecting) or not.
* The input polygon must have no coincident vertices or the test will fail.
*
* @param polygonVerts Array of points representing the vertices of the polygon.
* @param polygonSize Number of vertices in the polygon.
* @return true if the polygon is simple, false otherwise.
*/
bool SkIsSimplePolygon(const SkPoint* polygonVerts, int polygonSize);
/**
* Compute indices to triangulate the given polygon.
* The input polygon must be simple (i.e. it is not self-intersecting)
* and have no coincident vertices or collinear edges.
*
* @param polygonVerts Array of points representing the vertices of the polygon.
* @param indexMap Mapping from index in the given array to the final index in the triangulation.
* @param polygonSize Number of vertices in the polygon.
* @param triangleIndices Indices of the resulting triangulation.
* @return true if successful, false otherwise.
*/
bool SkTriangulateSimplePolygon(const SkPoint* polygonVerts, uint16_t* indexMap, int polygonSize,
SkTDArray<uint16_t>* triangleIndices);
// Experiment: doesn't handle really big floats (returns false), always returns true for count <= 3
bool SkIsPolyConvex_experimental(const SkPoint[], int count);
#endif
| 2.421875 | 2 |
2024-11-18T22:11:37.547870+00:00 | 2021-07-25T05:26:06 | c4886dbd0e13edd655345057f2eb9f26fdccb229 | {
"blob_id": "c4886dbd0e13edd655345057f2eb9f26fdccb229",
"branch_name": "refs/heads/main",
"committer_date": "2021-07-25T05:26:06",
"content_id": "61bafb5b605b1a93589bf38712cd1b5a5f674085",
"detected_licenses": [
"MIT"
],
"directory_id": "05168ccf77b76515830a2bf2c4574fe072f2a231",
"extension": "c",
"filename": "Check whether triangle is equilateral, isoceles or scalene.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 394,
"license": "MIT",
"license_type": "permissive",
"path": "/Miscellaneous/Check whether triangle is equilateral, isoceles or scalene.c",
"provenance": "stackv2-0087.json.gz:4479",
"repo_name": "Yasser-M-Abdalkader/C",
"revision_date": "2021-07-25T05:26:06",
"revision_id": "f603eef11ea14a730a5fb41e36b3dba5f852fe01",
"snapshot_id": "d2a81e942f2de450073970a8372ca208a246bb99",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/Yasser-M-Abdalkader/C/f603eef11ea14a730a5fb41e36b3dba5f852fe01/Miscellaneous/Check whether triangle is equilateral, isoceles or scalene.c",
"visit_date": "2023-06-25T10:37:00.888509"
} | stackv2 | #include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c;
printf("Enter the sides of a triangle: ");
scanf("%d%d%d",&a,&b,&c);
if(a==b && b==c && a==c)
{
printf("Triangle is equilateral.");
}
else if(a==b || b==c || a==c)
{
printf("Triangle is isoceles.");
}
else
{
printf("Triangle is scalene.");
}
_getch();
}
| 2.890625 | 3 |
2024-11-18T22:11:38.381935+00:00 | 2018-09-04T06:35:16 | 3c4281e8f31a7146d71caadca31c76c2c7941ee3 | {
"blob_id": "3c4281e8f31a7146d71caadca31c76c2c7941ee3",
"branch_name": "refs/heads/master",
"committer_date": "2018-09-04T06:35:16",
"content_id": "d767518a4a4a32ec658085e6fd15a04f07fc8933",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "a148c0d16e1cc6d0088dcd9d58716abb308bb94e",
"extension": "c",
"filename": "roots.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 15109,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/ics-4.x/bootable/recovery/roots.c",
"provenance": "stackv2-0087.json.gz:4994",
"repo_name": "BAT6188/mt36k_android_4.0.4",
"revision_date": "2018-09-04T06:35:16",
"revision_id": "3240564345913f02813e497672c9594af6563608",
"snapshot_id": "5f457b2c76c4d28d72b1002ba542371365d2b8b6",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/BAT6188/mt36k_android_4.0.4/3240564345913f02813e497672c9594af6563608/ics-4.x/bootable/recovery/roots.c",
"visit_date": "2023-05-24T04:13:23.011226"
} | stackv2 | /*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include "mtdutils/mtdutils.h"
#include "mtdutils/mounts.h"
#include "roots.h"
#include "common.h"
//#include "make_ext4fs.h"
#include "wipeubifs.h"
static int num_volumes = 0;
static Volume* device_volumes = NULL;
static int parse_options(char* options, Volume* volume) {
char* option;
while (option = strtok(options, ",")) {
options = NULL;
if (strncmp(option, "length=", 7) == 0) {
volume->length = strtoll(option+7, NULL, 10);
} else {
LOGE("bad option \"%s\"\n", option);
return -1;
}
}
return 0;
}
void load_volume_table() {
int alloc = 8;
device_volumes = malloc(alloc * sizeof(Volume));
// Insert an entry for /tmp, which is the ramdisk and is always mounted.
device_volumes[0].mount_point = "/tmp";
device_volumes[0].fs_type = "ramdisk";
device_volumes[0].device = NULL;
device_volumes[0].device2 = NULL;
device_volumes[0].length = 0;
num_volumes = 1;
FILE* fstab = fopen("/etc/recovery.fstab", "r");
if (fstab == NULL) {
LOGE("failed to open /etc/recovery.fstab (%s)\n", strerror(errno));
return;
}
char buffer[1024];
int i;
while (fgets(buffer, sizeof(buffer)-1, fstab)) {
for (i = 0; buffer[i] && isspace(buffer[i]); ++i);
if (buffer[i] == '\0' || buffer[i] == '#') continue;
char* original = strdup(buffer);
char* mount_point = strtok(buffer+i, " \t\n");
char* fs_type = strtok(NULL, " \t\n");
char* device = strtok(NULL, " \t\n");
// lines may optionally have a second device, to use if
// mounting the first one fails.
char* options = NULL;
char* device2 = strtok(NULL, " \t\n");
if (device2) {
if (device2[0] == '/') {
options = strtok(NULL, " \t\n");
} else {
options = device2;
device2 = NULL;
}
}
if (mount_point && fs_type && device) {
while (num_volumes >= alloc) {
alloc *= 2;
device_volumes = realloc(device_volumes, alloc*sizeof(Volume));
}
device_volumes[num_volumes].mount_point = strdup(mount_point);
device_volumes[num_volumes].fs_type = strdup(fs_type);
device_volumes[num_volumes].device = strdup(device);
device_volumes[num_volumes].device2 =
device2 ? strdup(device2) : NULL;
device_volumes[num_volumes].length = 0;
if (parse_options(options, device_volumes + num_volumes) != 0) {
LOGE("skipping malformed recovery.fstab line: %s\n", original);
} else {
++num_volumes;
}
} else {
LOGE("skipping malformed recovery.fstab line: %s\n", original);
}
free(original);
}
fclose(fstab);
printf("recovery filesystem table\n");
printf("=========================\n");
for (i = 0; i < num_volumes; ++i) {
Volume* v = &device_volumes[i];
printf(" %d %s %s %s %s %lld\n", i, v->mount_point, v->fs_type,
v->device, v->device2, v->length);
}
printf("\n");
}
Volume* volume_for_path(const char* path) {
int i;
for (i = 0; i < num_volumes; ++i) {
Volume* v = device_volumes+i;
int len = strlen(v->mount_point);
if (strncmp(path, v->mount_point, len) == 0 &&
(path[len] == '\0' || path[len] == '/')) {
return v;
}
}
return NULL;
}
int ensure_path_mounted(const char* path) {
Volume* v = volume_for_path(path);
if (v == NULL) {
LOGE("unknown volume for path [%s]\n", path);
return -1;
}
if (strcmp(v->fs_type, "ramdisk") == 0) {
// the ramdisk is always mounted.
return 0;
}
int result;
result = scan_mounted_volumes();
if (result < 0) {
LOGE("failed to scan mounted volumes\n");
return -1;
}
const MountedVolume* mv =
find_mounted_volume_by_mount_point(v->mount_point);
if (mv) {
// volume is already mounted
return 0;
}
mkdir(v->mount_point, 0755); // in case it doesn't already exist
#if 1
if ((strcmp(v->mount_point, "/mnt/sdcard") == 0)||(strcmp(v->mount_point, "/mnt/usb") == 0))
{
int wait_count = 0;
FILE * fp;
char read_buf[1024];
char s_dev_name[128];
char s_dev_fullpath[128];
int mount_ok = -1;
int hasmounted = 0;
while (wait_count < 30)
{
memset(s_dev_name, 0, 128);
memset(s_dev_fullpath, 0, 128);
fp = fopen("/proc/diskstats", "r");
if (fp == NULL)
{
return -1;
}
while(!feof(fp))
{
if(!fgets(read_buf, 1023 , fp))
{
break;
}
sscanf(read_buf, "%*d %*d %32s %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*u", s_dev_name);
hasmounted = 0; //mount_ok = -1;
printf("[Root] From /proc/diskstats %s %s\n", s_dev_name, v->mount_point);
/*Just look for sdX*/
if(strncmp("sd", s_dev_name, 2) == 0 && strcmp(v->mount_point, "/mnt/usb") == 0)
{
sprintf(s_dev_fullpath, "/dev/block/%s", s_dev_name);
mount_ok = mount(s_dev_fullpath, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
if (mount_ok == 0)
{
//break;
printf("mount ok\n");
hasmounted = 1;
}
else
{
mount_ok = mount(s_dev_fullpath, v->mount_point, "ntfs", MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
printf("mount ok: %d\n", mount_ok);
if (mount_ok == 0)
{
// break;
hasmounted = 1;
}
}
}
else if (strncmp("mmcblk", s_dev_name, 6) == 0 && strcmp(v->mount_point, "/mnt/sdcard") == 0)
{
sprintf(s_dev_fullpath, "/dev/block/%s", s_dev_name);
mount_ok = mount(s_dev_fullpath, v->mount_point, v->fs_type, MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
if (mount_ok == 0)
{
//break;
hasmounted = 1;
}
else
{
mount_ok = mount(s_dev_fullpath, v->mount_point, "ntfs", MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
if (mount_ok == 0)
{
// break;
hasmounted = 1;
}
}
}
if (hasmounted == 1) {
if (access(path, R_OK) == 0)
{
printf("access error\n");
break;
}else{
umount2(v->mount_point, MNT_FORCE);
printf("umount2 here\n");
}
}
}
fclose(fp);
if (mount_ok == 0)
{
return 0;
}
usleep(800000);
wait_count ++;
}
return -1;
}
#endif
else if ( (strcmp(v->fs_type, "yaffs2") == 0) || (strcmp(v->fs_type, "ubifs") == 0)) {
// mount an MTD partition as a YAFFS2 filesystem.
mtd_scan_partitions();
const MtdPartition* partition;
partition = mtd_find_partition_by_name(&v->mount_point[1]);
if (partition == NULL) {
LOGE("failed to find \"%s\" partition to mount at \"%s\"\n",
v->device, v->mount_point);
return -1;
}
return mtd_mount_partition(partition, v->mount_point, v->fs_type, 0);
} else if (strcmp(v->fs_type, "ext4") == 0 ||
strcmp(v->fs_type, "vfat") == 0) {
result = mount(v->device, v->mount_point, v->fs_type,
MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
if (result == 0) return 0;
if (v->device2) {
LOGW("failed to mount %s (%s); trying %s\n",
v->device, strerror(errno), v->device2);
result = mount(v->device2, v->mount_point, v->fs_type,
MS_NOATIME | MS_NODEV | MS_NODIRATIME, "");
if (result == 0) return 0;
}
LOGE("failed to mount %s (%s)\n", v->mount_point, strerror(errno));
return -1;
}
LOGE("unknown fs_type \"%s\" for %s\n", v->fs_type, v->mount_point);
return -1;
}
int ensure_path_unmounted(const char* path) {
Volume* v = volume_for_path(path);
if (v == NULL) {
LOGE("unknown volume for path [%s]\n", path);
return -1;
}
if (strcmp(v->fs_type, "ramdisk") == 0) {
// the ramdisk is always mounted; you can't unmount it.
LOGE("[%s] is always mounted; you can't unmount it.\n", path);
return -1;
}
int result;
result = scan_mounted_volumes();
if (result < 0) {
LOGE("failed to scan mounted volumes\n");
return -1;
}
const MountedVolume* mv =
find_mounted_volume_by_mount_point(v->mount_point);
if (mv == NULL) {
// volume is already unmounted
return 0;
}
return unmount_mounted_volume(mv);
}
int format_volume(const char* volume) {
Volume* v = volume_for_path(volume);
if (v == NULL) {
LOGE("unknown volume \"%s\"\n", volume);
return -1;
}
if (strcmp(v->fs_type, "ramdisk") == 0) {
// you can't format the ramdisk.
LOGE("can't format_volume \"%s\"", volume);
return -1;
}
if (strcmp(v->mount_point, volume) != 0) {
LOGE("can't give path \"%s\" to format_volume\n", volume);
return -1;
}
if (ensure_path_unmounted(volume) != 0) {
LOGE("format_volume failed to unmount \"%s\"\n", v->mount_point);
return -1;
}
if(!strcmp(v->fs_type, "ubifs"))
{
const MtdPartition *partition;
mtd_scan_partitions();
if(strcmp(v->mount_point, "/data"))
partition = mtd_find_partition_by_name(&v->mount_point[1]);
else
partition = mtd_find_partition_by_name("userdata");
if (partition == NULL) {
LOGE("format_volume: %s cat't find mtd partition\n", v->mount_point);
return -1;
}else{
if (strcmp(v->mount_point, "/system") == 0 ||
strcmp(v->mount_point, "/cache") == 0 ||
strcmp(v->mount_point, "/data") == 0 ){
char cmd_line[128];
int ubi_vol = 1;
// bool b_org_mounted = false;
int status;
ui_print("format partition: %s \n", v->mount_point);
#if 1
if (strcmp(v->mount_point, "/system") == 0){
ubi_vol = 1;
}else if (strcmp(v->mount_point, "/data") == 0){
ubi_vol = 2;
}else if(strcmp(v->mount_point, "/cache") == 0){
ubi_vol = 3;
}else{
ubi_vol = 4; //perm partition
}
#endif
//vapor : it is not properly, so we mask it.
//if (ensure_path_mounted(v->mount_point) == 0)
{
fprintf(stderr,"umount /%s\r\n", v->mount_point);
umount(v->mount_point);
}
memset(cmd_line, 0, 128);
sprintf(cmd_line, "/format.sh %d %d %s", partition->device_index, ubi_vol, partition->name);
format_ubifs(cmd_line);
ui_print("format partition: %s complete\n", v->device);
return 0;
}
}
}
else if (strcmp(v->fs_type, "yaffs2") == 0 || strcmp(v->fs_type, "mtd") == 0) {
mtd_scan_partitions();
const MtdPartition* partition = mtd_find_partition_by_name(v->device);
if (partition == NULL) {
LOGE("format_volume: no MTD partition \"%s\"\n", v->device);
return -1;
}
MtdWriteContext *write = mtd_write_partition(partition);
if (write == NULL) {
LOGW("format_volume: can't open MTD \"%s\"\n", v->device);
return -1;
} else if (mtd_erase_blocks(write, -1) == (off_t) -1) {
LOGW("format_volume: can't erase MTD \"%s\"\n", v->device);
mtd_write_close(write);
return -1;
} else if (mtd_write_close(write)) {
LOGW("format_volume: can't close MTD \"%s\"\n", v->device);
return -1;
}
return 0;
}
#if 0
else if (strcmp(v->fs_type, "ext4") == 0) {
int result = make_ext4fs(v->device, v->length);
if (result != 0) {
LOGE("format_volume: make_extf4fs failed on %s\n", v->device);
return -1;
}
return 0;
}
#endif
LOGE("format_volume: fs_type \"%s\" unsupported\n", v->fs_type);
return -1;
}
int
format_ubifs(const char *command)
{
pid_t pid;
sig_t intsave, quitsave;
sigset_t mask, omask;
int pstat;
char *argp[] = {"sh", "-c", NULL, NULL};
if (!command) /* just checking... */
return(1);
argp[2] = (char *)command;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &omask);
switch (pid = vfork()) {
case -1: /* error */
sigprocmask(SIG_SETMASK, &omask, NULL);
return(-1);
case 0: /* child */
sigprocmask(SIG_SETMASK, &omask, NULL);
execve("/sbin/sh", argp, environ);
_exit(127);
}
intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
pid = waitpid(pid, (int *)&pstat, 0);
sigprocmask(SIG_SETMASK, &omask, NULL);
(void)bsd_signal(SIGINT, intsave);
(void)bsd_signal(SIGQUIT, quitsave);
return ((pid == -1) ? -1 : pstat);
}
| 2.296875 | 2 |
2024-11-18T22:11:38.707999+00:00 | 2013-03-09T19:50:28 | 6b5da9f5919dc5dcc5075bdf2586645fadf082c3 | {
"blob_id": "6b5da9f5919dc5dcc5075bdf2586645fadf082c3",
"branch_name": "refs/heads/master",
"committer_date": "2013-03-09T19:50:28",
"content_id": "008bf8eda4bfdb7a3b1e9dbb1a45a81dc19d9026",
"detected_licenses": [
"ISC"
],
"directory_id": "6b4b223f16fd8a6d61746397f3ce664d410fff3c",
"extension": "c",
"filename": "cli.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2103,
"license": "ISC",
"license_type": "permissive",
"path": "/cli.c",
"provenance": "stackv2-0087.json.gz:5253",
"repo_name": "thodg/checkpassword-pg",
"revision_date": "2013-03-09T19:50:28",
"revision_id": "6bf74740a3958d0727e4be5bf802ba2d9bf770cd",
"snapshot_id": "b45879ae10abd091a9f16a47e1e8bc05a7b1365f",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/thodg/checkpassword-pg/6bf74740a3958d0727e4be5bf802ba2d9bf770cd/cli.c",
"visit_date": "2021-01-10T19:47:07.582002"
} | stackv2 | /*
checkpassword-pg - checkpassword with postgresql backend
Copyright 2008-2013 Thomas de Grivel
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
cli.c - command line interface
See http://cr.yp.to/checkpwd/ for interface description
*/
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include "checkpassword_pg.h"
#include "config.h"
/* returns new value of i, or call exit with code 2 on overflow */
static int find_zero (int i, const char *data)
{
while (i < 512 && data[i])
i++;
if (i == 512) {
syslog (LOG_ERR, "bad input at position %i", i);
exit (2);
}
return i;
}
static void read_data (char *data)
{
size_t size;
ssize_t r;
size = 512;
while ((r = read(3, data, size)) > 0) {
size -= r;
data += r;
}
close(3);
if (r == 0)
return;
if (r < 0) {
syslog (LOG_ERR, "read failed");
exit (2);
}
}
int main (int argc, char **argv)
{
char data[512];
const char *login;
const char *pass;
const char *time;
int i;
openlog ("checkpassword-pg", 0, LOG_AUTHPRIV);
setlogmask(LOG_UPTO(LOG_INFO));
read_data (data);
login = data;
i = find_zero (0, data) + 1;
pass = data + i;
i = find_zero (i, data) + 1;
time = data + i;
find_zero (i, data);
if (argc < 2) {
syslog (LOG_ERR, "no program to run");
return 2;
}
load_config();
argv[0] = argv[1];
return checkpassword_pg (login, pass, time, argv);
}
| 2.46875 | 2 |
2024-11-18T22:11:38.888646+00:00 | 2018-11-19T15:33:34 | b86792b0c08e7e80ae40d855c50397a711d8c1bb | {
"blob_id": "b86792b0c08e7e80ae40d855c50397a711d8c1bb",
"branch_name": "refs/heads/master",
"committer_date": "2018-11-19T15:33:34",
"content_id": "7c1c19e1eec860687bdc7f6f66d4fc1ceb226424",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "5968eac0120fb9d8c34b8779d7594a1185e32320",
"extension": "c",
"filename": "arch_int.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 5379,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/kernel/arch/ppc/arch_int.c",
"provenance": "stackv2-0087.json.gz:5638",
"repo_name": "marcellmarcell/newos",
"revision_date": "2018-11-19T15:33:34",
"revision_id": "12d4b0117f94ab02585bb4e20037464dbbbf4f4c",
"snapshot_id": "eacfca5dc934ea01be696c48eac901f4a52e8716",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/marcellmarcell/newos/12d4b0117f94ab02585bb4e20037464dbbbf4f4c/kernel/arch/ppc/arch_int.c",
"visit_date": "2020-04-07T09:18:04.888349"
} | stackv2 | /*
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License.
*/
#include <boot/stage2.h>
#include <kernel/int.h>
#include <kernel/vm.h>
#include <kernel/vm_priv.h>
#include <kernel/timer.h>
#include <kernel/thread.h>
#include <kernel/time.h>
#include <string.h>
// defined in arch_exceptions.S
extern int __irqvec_start;
extern int __irqvec_end;
void arch_int_enable_io_interrupt(int irq)
{
return;
}
void arch_int_disable_io_interrupt(int irq)
{
return;
}
static void print_iframe(struct iframe *frame)
{
dprintf("iframe at %p:\n", frame);
dprintf("r0-r3: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r0, frame->r1, frame->r2, frame->r3);
dprintf("r4-r7: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r4, frame->r5, frame->r6, frame->r7);
dprintf("r8-r11: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r8, frame->r9, frame->r10, frame->r11);
dprintf("r12-r15: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r12, frame->r13, frame->r14, frame->r15);
dprintf("r16-r19: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r16, frame->r17, frame->r18, frame->r19);
dprintf("r20-r23: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r20, frame->r21, frame->r22, frame->r23);
dprintf("r24-r27: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r24, frame->r25, frame->r26, frame->r27);
dprintf("r28-r31: 0x%08lx 0x%08lx 0x%08lx 0x%08lx\n", frame->r28, frame->r29, frame->r30, frame->r31);
dprintf(" ctr 0x%08lx xer 0x%08lx\n", frame->ctr, frame->xer);
dprintf(" cr 0x%08lx lr 0x%08lx\n", frame->cr, frame->lr);
dprintf(" dsisr 0x%08lx dar 0x%08lx\n", frame->dsisr, frame->dar);
dprintf(" srr1 0x%08lx srr0 0x%08lx\n", frame->srr1, frame->srr0);
}
void ppc_exception_entry(int vector, struct iframe *iframe);
void ppc_exception_entry(int vector, struct iframe *iframe)
{
int ret = INT_NO_RESCHEDULE;
if(vector != 0x900)
dprintf("ppc_exception_entry: time %Ld vector 0x%x, iframe %p\n", system_time(), vector, iframe);
switch(vector) {
case 0x100: // system reset
panic("system reset exception\n");
break;
case 0x200: // machine check
panic("machine check exception\n");
break;
case 0x300: // DSI
case 0x400: { // ISI
addr_t newip;
ret = vm_page_fault(iframe->dar, iframe->srr0,
iframe->dsisr & (1 << 25), // store or load
iframe->srr1 & (1 << 14), // was the system in user or supervisor
&newip);
if(newip != 0) {
// the page fault handler wants us to modify the iframe to set the
// IP the cpu will return to to be this ip
iframe->srr0 = newip;
}
break;
}
case 0x500: // external interrupt
panic("external interrrupt exception: unimplemented\n");
break;
case 0x600: // alignment exception
panic("alignment exception: unimplemented\n");
break;
case 0x700: // program exception
panic("program exception: unimplemented\n");
break;
case 0x800: // FP unavailable exception
panic("FP unavailable exception: unimplemented\n");
break;
case 0x900: // decrementer exception
ret = timer_interrupt();
break;
case 0xc00: // system call
panic("system call exception: unimplemented\n");
break;
case 0xd00: // trace exception
panic("trace exception: unimplemented\n");
break;
case 0xe00: // FP assist exception
panic("FP assist exception: unimplemented\n");
break;
case 0xf00: // performance monitor exception
panic("performance monitor exception: unimplemented\n");
break;
case 0xf20: // alitivec unavailable exception
panic("alitivec unavailable exception: unimplemented\n");
break;
case 0x1000:
case 0x1100:
case 0x1200:
panic("TLB miss exception: unimplemented\n");
break;
case 0x1300: // instruction address exception
panic("instruction address exception: unimplemented\n");
break;
case 0x1400: // system management exception
panic("system management exception: unimplemented\n");
break;
case 0x1600: // altivec assist exception
panic("altivec assist exception: unimplemented\n");
break;
case 0x1700: // thermal management exception
panic("thermal management exception: unimplemented\n");
break;
default:
dprintf("unhandled exception type 0x%x\n", vector);
print_iframe(iframe);
panic("unhandled exception type\n");
}
if(ret == INT_RESCHEDULE) {
int_disable_interrupts();
GRAB_THREAD_LOCK();
thread_resched();
RELEASE_THREAD_LOCK();
int_restore_interrupts();
}
}
int arch_int_init(kernel_args *ka)
{
return 0;
}
int arch_int_init2(kernel_args *ka)
{
region_id exception_region;
void *ex_handlers;
// create a region to map the irq vector code into (physical addres 0x0)
ex_handlers = (void *)ka->arch_args.exception_handlers.start;
exception_region = vm_create_anonymous_region(vm_get_kernel_aspace_id(), "exception_handlers",
&ex_handlers, REGION_ADDR_EXACT_ADDRESS,
ka->arch_args.exception_handlers.size, REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);
if(exception_region < 0)
panic("arch_int_init2: could not create exception handler region\n");
dprintf("exception handlers at %p\n", ex_handlers);
// copy the handlers into this area
memcpy(ex_handlers, &__irqvec_start, ka->arch_args.exception_handlers.size);
arch_cpu_sync_icache(0, 0x3000);
// make sure the IP bit isn't set (putting the exceptions at 0x0)
setmsr(getmsr() & ~MSR_IP);
return 0;
}
| 2.109375 | 2 |
2024-11-18T22:11:38.954184+00:00 | 2018-06-17T20:48:01 | 16cc9ca5b819559edd07fcc98d82d1916d79e827 | {
"blob_id": "16cc9ca5b819559edd07fcc98d82d1916d79e827",
"branch_name": "refs/heads/master",
"committer_date": "2018-06-17T20:48:01",
"content_id": "03b97cf30dd7c9ecc9bc49faee49b6e05afc8543",
"detected_licenses": [
"MIT"
],
"directory_id": "0ac0dd9ed607149496f604864600092eb29784c4",
"extension": "c",
"filename": "ctree.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 133144596,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2995,
"license": "MIT",
"license_type": "permissive",
"path": "/ctree.c",
"provenance": "stackv2-0087.json.gz:5770",
"repo_name": "LucaLumetti/Ctree",
"revision_date": "2018-06-17T20:48:01",
"revision_id": "4404848a0a502ccf113951afff1f832a3aac4d7c",
"snapshot_id": "6c17b735e75871e3a257edc0787ed197e69ace32",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/LucaLumetti/Ctree/4404848a0a502ccf113951afff1f832a3aac4d7c/ctree.c",
"visit_date": "2020-03-17T01:13:33.121214"
} | stackv2 | /*
* DO NOT COMPILE
* WATCH ctree.h
*/
#include "ctree.h"
tree emptytree(){
return NULL;
}
tree consTree(tree_type d, tree l, tree r){
tree t = malloc(sizeof(tree_node));
t->value = d;
t->left = l;
t->right = r;
return t;
}
tree left(tree t){
if(t == NULL)
return NULL;
return t->left;
}
tree right(tree t){
if(t == NULL)
return NULL;
return t->right;
}
tree_type root(tree t){
if(empty(t))
abort();
return t->value;
}
bool empty(tree t){
return t == NULL;
}
/* NON PRIMITIVE */
tree appendLeft(tree_type d, tree t){
if(t == NULL)
return consTree(d, NULL, NULL);
if(t->left != NULL)
free(t->left); //TODO: destroy(t->left)
t->left = consTree(d, NULL, NULL);
return t;
}
tree appendRight(tree_type d, tree t){
if(t == NULL)
return consTree(d, NULL, NULL);
if(t->right != NULL)
free(t->right); //TODO: destroy(t->right)
t->right = consTree(d, NULL, NULL);
return t;
}
unsigned getHeight(tree t){
if(empty(t))
return 0;
unsigned hl = getHeight(t->left);
unsigned hr = getHeight(t->right);
return 1+((hl>hr)?hl:hr);
}
void preOrder(tree t) {
if(empty(t))
return;
printf("%d\t", root(t));
preOrder(left(t));
preOrder(right(t));
}
void inOrder(tree t) {
if (empty(t))
return;
inOrder(left(t));
printf("%d\t", root(t));
inOrder(right(t));
}
void postOrder(tree t) {
if(empty(t))
return;
postOrder(left(t));
postOrder(right(t));
printf("%d\t", root(t));
}
int serie_a(int height){
return (height == -1) ? 0 : 3*(1<<height)-1;
}
int serie_b(int height){
if(height == -2)
return 0;
if(height == -1)
return 1;
return 3*(1<<height)-1;
}
tree getAbsPos(tree t, unsigned p){
if(empty(t))
return t;
int dir = 1;
while(p > 1){
dir = (dir<<1)+(p%2);
p = p>>1;
}
while(dir > 1){
if(dir%2)
t = right(t);
else
t = left(t);
dir = dir>>1;
}
return t;
}
void printTree(tree t){
printf("\n");
unsigned height = getHeight(t);
/* Blocchi (numero piu' /\) da stampare */
for(int h = 0; h < height; h++){
unsigned a = serie_a(height-h-1);
unsigned b = serie_a(height-h-2);
unsigned c = serie_b(height-h-3);
/* stampo spazi a sx */
for(int l = 0; l < b; l++)
printf(" ");
/* Stampo spazi tra i vari numeri */
for(int j = 0; j < (1<<h); j++){
tree k = getAbsPos(t, (1<<h)+j);
if(k == NULL)
printf("X");
else
printf("%d", root(k));
for(int r = 0; r < ((h==height-1)?(((j%2==0)?a:b)+1):a); r++)
printf(" ");
}
printf("\n");
/* Stampo \n e /\ */
for(int s = 0; s < c; s++){
for(int y = 0; y < (1<<h); y++){
for(int w = 0; w < b-s-1; w++)
printf(" ");
if(y != 0){
for(int d = 0; d < b-s; d++)
printf(" ");
}
printf("/");
for(int x = 0; x < a-2*(b-s); x++)
printf(" ");
printf("\\");
}
printf("\n");
}
}
}
| 3.328125 | 3 |
2024-11-18T22:11:39.025758+00:00 | 2020-03-30T21:41:55 | 335f67070898e606227b75b469d52bfd163d5588 | {
"blob_id": "335f67070898e606227b75b469d52bfd163d5588",
"branch_name": "refs/heads/master",
"committer_date": "2020-03-30T21:41:55",
"content_id": "1c70710a2d3366751abc4ac96e7e0174266cd774",
"detected_licenses": [
"MIT-Modern-Variant"
],
"directory_id": "19079f7944dc6f030aeae347a129f71f0ed596b4",
"extension": "c",
"filename": "except1.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 251434636,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 343,
"license": "MIT-Modern-Variant",
"license_type": "permissive",
"path": "/nachos/test/except1.c",
"provenance": "stackv2-0087.json.gz:5898",
"repo_name": "hanyax/NachosOS",
"revision_date": "2020-03-30T21:41:55",
"revision_id": "2897e11a6fc051be76a570eee5fa3785a89452df",
"snapshot_id": "1ae479b1101b5cfce02ebfbdfa2c8494a477574e",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/hanyax/NachosOS/2897e11a6fc051be76a570eee5fa3785a89452df/nachos/test/except1.c",
"visit_date": "2021-05-18T21:38:16.617188"
} | stackv2 | /*
* except1.c
*
* Simple program that causes a page fault exception outside of the
* boundaries of the virtual address space.
*
* Geoff Voelker
* 11/9/16
*/
#include "syscall.h"
int
main (int argc, char *argv[])
{
// initialize a bad pointer...
int *ptr = (int *) 0xBADFFFFF;
// ...and dereference it
return *ptr;
}
| 2.296875 | 2 |
2024-11-18T22:11:39.241284+00:00 | 2017-09-11T04:04:38 | 1e999432475efc3ea535ce5fef7295e0b3f07097 | {
"blob_id": "1e999432475efc3ea535ce5fef7295e0b3f07097",
"branch_name": "refs/heads/master",
"committer_date": "2017-09-11T04:04:38",
"content_id": "a1875a2022a4eb29ffb238555467d101e1cf826c",
"detected_licenses": [
"MIT"
],
"directory_id": "f364e8348bee46072434ee79fa6502169948277f",
"extension": "h",
"filename": "pool_alt.h",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 102831296,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 5671,
"license": "MIT",
"license_type": "permissive",
"path": "/Pods/PBPJSip/PBPJSip/Pod/Classes/includes/pjlib/pj/pool_alt.h",
"provenance": "stackv2-0087.json.gz:6154",
"repo_name": "iFindTA/PBVoipService",
"revision_date": "2017-09-11T04:04:38",
"revision_id": "7d2a117d97725fb7e80fe75a179a985f1ac1c9b9",
"snapshot_id": "ba34e4f9cdee2494f3e7ae00e83d39f0ff270d75",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/iFindTA/PBVoipService/7d2a117d97725fb7e80fe75a179a985f1ac1c9b9/Pods/PBPJSip/PBPJSip/Pod/Classes/includes/pjlib/pj/pool_alt.h",
"visit_date": "2021-01-23T19:35:06.539461"
} | stackv2 | /* $Id: pool_alt.h 5061 2015-04-10 13:19:47Z riza $ */
/*
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
*
* 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
*/
#ifndef __PJ_POOL_ALT_H__
#define __PJ_POOL_ALT_H__
#define __PJ_POOL_H__
PJ_BEGIN_DECL
/**
* The type for function to receive callback from the pool when it is unable
* to allocate memory. The elegant way to handle this condition is to throw
* exception, and this is what is expected by most of this library
* components.
*/
typedef void pj_pool_callback(pj_pool_t *pool, pj_size_t size);
struct pj_pool_mem
{
struct pj_pool_mem *next;
/* data follows immediately */
};
struct pj_pool_t
{
struct pj_pool_mem *first_mem;
pj_pool_factory *factory;
char obj_name[32];
pj_size_t used_size;
pj_pool_callback *cb;
};
#define PJ_POOL_SIZE (sizeof(struct pj_pool_t))
/**
* This constant denotes the exception number that will be thrown by default
* memory factory policy when memory allocation fails.
*/
extern int PJ_NO_MEMORY_EXCEPTION;
/*
* Declare all pool API as macro that calls the implementation
* function.
*/
#define pj_pool_create(fc,nm,init,inc,cb) \
pj_pool_create_imp(__FILE__, __LINE__, fc, nm, init, inc, cb)
#define pj_pool_release(pool) pj_pool_release_imp(pool)
#define pj_pool_getobjname(pool) pj_pool_getobjname_imp(pool)
#define pj_pool_reset(pool) pj_pool_reset_imp(pool)
#define pj_pool_get_capacity(pool) pj_pool_get_capacity_imp(pool)
#define pj_pool_get_used_size(pool) pj_pool_get_used_size_imp(pool)
#define pj_pool_alloc(pool,sz) \
pj_pool_alloc_imp(__FILE__, __LINE__, pool, sz)
#define pj_pool_calloc(pool,cnt,elem) \
pj_pool_calloc_imp(__FILE__, __LINE__, pool, cnt, elem)
#define pj_pool_zalloc(pool,sz) \
pj_pool_zalloc_imp(__FILE__, __LINE__, pool, sz)
/*
* Declare prototypes for pool implementation API.
*/
/* Create pool */
PJ_DECL(pj_pool_t*) pj_pool_create_imp(const char *file, int line,
void *factory,
const char *name,
pj_size_t initial_size,
pj_size_t increment_size,
pj_pool_callback *callback);
/* Release pool */
PJ_DECL(void) pj_pool_release_imp(pj_pool_t *pool);
/* Get pool name */
PJ_DECL(const char*) pj_pool_getobjname_imp(pj_pool_t *pool);
/* Reset pool */
PJ_DECL(void) pj_pool_reset_imp(pj_pool_t *pool);
/* Get capacity */
PJ_DECL(pj_size_t) pj_pool_get_capacity_imp(pj_pool_t *pool);
/* Get total used size */
PJ_DECL(pj_size_t) pj_pool_get_used_size_imp(pj_pool_t *pool);
/* Allocate memory from the pool */
PJ_DECL(void*) pj_pool_alloc_imp(const char *file, int line,
pj_pool_t *pool, pj_size_t sz);
/* Allocate memory from the pool and zero the memory */
PJ_DECL(void*) pj_pool_calloc_imp(const char *file, int line,
pj_pool_t *pool, unsigned cnt,
unsigned elemsz);
/* Allocate memory from the pool and zero the memory */
PJ_DECL(void*) pj_pool_zalloc_imp(const char *file, int line,
pj_pool_t *pool, pj_size_t sz);
#define PJ_POOL_ZALLOC_T(pool,type) \
((type*)pj_pool_zalloc(pool, sizeof(type)))
#define PJ_POOL_ALLOC_T(pool,type) \
((type*)pj_pool_alloc(pool, sizeof(type)))
#ifndef PJ_POOL_ALIGNMENT
# define PJ_POOL_ALIGNMENT 4
#endif
/**
* This structure declares pool factory interface.
*/
typedef struct pj_pool_factory_policy
{
/**
* Allocate memory block (for use by pool). This function is called
* by memory pool to allocate memory block.
*
* @param factory Pool factory.
* @param size The size of memory block to allocate.
*
* @return Memory block.
*/
void* (*block_alloc)(pj_pool_factory *factory, pj_size_t size);
/**
* Free memory block.
*
* @param factory Pool factory.
* @param mem Memory block previously allocated by block_alloc().
* @param size The size of memory block.
*/
void (*block_free)(pj_pool_factory *factory, void *mem, pj_size_t size);
/**
* Default callback to be called when memory allocation fails.
*/
pj_pool_callback *callback;
/**
* Option flags.
*/
unsigned flags;
} pj_pool_factory_policy;
struct pj_pool_factory
{
pj_pool_factory_policy policy;
int dummy;
};
struct pj_caching_pool
{
pj_pool_factory factory;
/* just to make it compilable */
unsigned used_count;
unsigned used_size;
unsigned peak_used_size;
};
/* just to make it compilable */
typedef struct pj_pool_block
{
int dummy;
} pj_pool_block;
#define pj_caching_pool_init( cp, pol, mac)
#define pj_caching_pool_destroy(cp)
#define pj_pool_factory_dump(pf, detail)
PJ_END_DECL
#endif /* __PJ_POOL_ALT_H__ */
| 2.046875 | 2 |
2024-11-18T22:11:39.314023+00:00 | 2019-11-06T14:59:31 | e9ea991a2a25bb65e0f03e9b4c72f1ab09963735 | {
"blob_id": "e9ea991a2a25bb65e0f03e9b4c72f1ab09963735",
"branch_name": "refs/heads/master",
"committer_date": "2019-11-06T14:59:31",
"content_id": "43b155b7af2592a68f154d68e187fd0afeadc34c",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "21069674d7e30b44f6c8bab46a3be7f15b85226a",
"extension": "h",
"filename": "strain_gauge_shield_and_lcd_support_functions.h",
"fork_events_count": 0,
"gha_created_at": "2019-11-05T18:44:07",
"gha_event_created_at": "2019-11-06T14:59:32",
"gha_language": null,
"gha_license_id": "BSD-3-Clause",
"github_id": 219826058,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 730,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/v1-0-2/BladderTracker_Pressure_Monitor_V2/BladderTracker_Pressure_Monitor/strain_gauge_shield_and_lcd_support_functions.h",
"provenance": "stackv2-0087.json.gz:6283",
"repo_name": "DrN8PhD/BladderTracker",
"revision_date": "2019-11-06T14:59:31",
"revision_id": "f67dd7c99ad1d9362a2555910ee86c03ac218fec",
"snapshot_id": "f2a5808ff5374dbaff95e7249519c78c32f61a18",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/DrN8PhD/BladderTracker/f67dd7c99ad1d9362a2555910ee86c03ac218fec/v1-0-2/BladderTracker_Pressure_Monitor_V2/BladderTracker_Pressure_Monitor/strain_gauge_shield_and_lcd_support_functions.h",
"visit_date": "2020-09-04T17:07:55.024551"
} | stackv2 | // Include the Wheatstone library
#include <WheatstoneBridge.h>
// Include the LCD library
#include <LiquidCrystal.h>
// Declare external global lcd
extern LiquidCrystal lcd;
// Button
#define btnRIGHT 1
#define btnUP 2
#define btnDOWN 4
#define btnLEFT 8
#define btnSELECT 16
#define btnNONE 32
// Return the first pressed button found
byte read_LCD_buttons();
// Return the number of digits in an integer
byte countDigits(int);
// Display full screen of text (2 rows x 16 characters)
void displayScreen(char[], char[]);
// Display to wait for select and then do so
void waitSelect(bool);
int getValueADC(char[], char[], byte, byte, byte);
int getValueInRange(char[], char[], byte, int, int, int, int, int);
| 2.171875 | 2 |
2024-11-18T22:11:39.573381+00:00 | 2011-08-22T04:29:19 | ad45d3997edbe07c477ffaa7c7feea55257f69f8 | {
"blob_id": "ad45d3997edbe07c477ffaa7c7feea55257f69f8",
"branch_name": "refs/heads/master",
"committer_date": "2011-08-22T04:29:19",
"content_id": "14b13cdc09b6af6f6249ab4f25c81d7b8eaf8524",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "4ba18dc75dd44ab5f7fcce1609d598b95061a520",
"extension": "h",
"filename": "config.def.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 31800873,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 5685,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/config.def.h",
"provenance": "stackv2-0087.json.gz:6542",
"repo_name": "lpezzaglia/pakledterm",
"revision_date": "2011-08-22T04:29:19",
"revision_id": "2acbd57196622c0146be9b2725f98f86ee3078d4",
"snapshot_id": "63e0d831da6b71f1b44e1c7850d3c1efb3bb56ab",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/lpezzaglia/pakledterm/2acbd57196622c0146be9b2725f98f86ee3078d4/config.def.h",
"visit_date": "2021-01-01T05:31:13.531245"
} | stackv2 | #define CONFIG_H_REVISION "config.h $Rev: 8$ $Date: 2011-08-21 21:29:19 -0700 (Sun, 21 Aug 2011) $"
#define PAKLEDFONTS_VERSION "0.0.1"
#define COLORS_VERSION "0.0.1"
#define TAB 4
//#define TNAME "st-256color"
#define TNAME "xterm"
#define BORDER 2
#define SHELL "/bin/sh"
/* Enable "bold-is-bright" */
/* See: http://lists.suckless.org/dev/1104/7414.html*/
#define BOLD_IS_BRIGHT
/* Begin pakledfonts */
static void makemyfontsgo(void);
typedef struct sfont {
char font[256];
char boldfont[256];
struct sfont *smaller;
struct sfont *bigger;
} Sfont;
Sfont *terminus12;
Sfont *terminus14;
Sfont *terminus16;
Sfont *terminus20;
Sfont *terminus22;
Sfont *terminus24;
Sfont *terminus28;
Sfont *terminus32;
Sfont *currentfont;
static void makemyfontsgo() {
terminus12 = (Sfont *)malloc(sizeof(Sfont));
terminus14 = (Sfont *)malloc(sizeof(Sfont));
terminus16 = (Sfont *)malloc(sizeof(Sfont));
terminus20 = (Sfont *)malloc(sizeof(Sfont));
terminus22 = (Sfont *)malloc(sizeof(Sfont));
terminus24 = (Sfont *)malloc(sizeof(Sfont));
terminus28 = (Sfont *)malloc(sizeof(Sfont));
terminus32 = (Sfont *)malloc(sizeof(Sfont));
strncpy(terminus12->font,"-*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*",255);
strncpy(terminus12->boldfont,"-*-terminus-medium-r-*-*-12-*-*-*-*-*-*-*",255);
terminus12->smaller=NULL;
terminus12->bigger=terminus14;
strncpy(terminus14->font,"-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*",255);
strncpy(terminus14->boldfont,"-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*",255);
terminus14->smaller=terminus12;
terminus14->bigger=terminus16;
strncpy(terminus16->font,"-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",255);
strncpy(terminus16->boldfont,"-*-terminus-medium-r-*-*-16-*-*-*-*-*-*-*",255);
terminus16->smaller=terminus14;
terminus16->bigger=terminus20;
strncpy(terminus20->font,"-*-terminus-medium-r-*-*-20-*-*-*-*-*-*-*",255);
strncpy(terminus20->boldfont,"-*-terminus-medium-r-*-*-20-*-*-*-*-*-*-*",255);
terminus20->smaller=terminus16;
terminus20->bigger=terminus24;
strncpy(terminus24->font,"-*-terminus-medium-r-*-*-24-*-*-*-*-*-*-*",255);
strncpy(terminus24->boldfont,"-*-terminus-medium-r-*-*-24-*-*-*-*-*-*-*",255);
terminus24->smaller=terminus20;
terminus24->bigger=terminus28;
strncpy(terminus28->font,"-*-terminus-medium-r-*-*-28-*-*-*-*-*-*-*",255);
strncpy(terminus28->boldfont,"-*-terminus-medium-r-*-*-28-*-*-*-*-*-*-*",255);
terminus28->smaller=terminus24;
terminus28->bigger=terminus32;
strncpy(terminus32->font,"-*-terminus-medium-r-*-*-32-*-*-*-*-*-*-*",255);
strncpy(terminus32->boldfont,"-*-terminus-medium-r-*-*-32-*-*-*-*-*-*-*",255);
terminus32->smaller=terminus28;
terminus32->bigger=NULL;
currentfont=terminus12;
}
/* End pakledfonts */
/* Terminal colors */
/*static const char *colorname[] = {
"black",
"red3",
"green3",
"yellow3",
"blue2",
"magenta3",
"cyan3",
"gray90",
"gray50",
"red",
"green",
"yellow",
"#5c5cff",
"magenta",
"cyan",
"white"
};*/
/*
urxvt*color10: #00ba00
urxvt*color12: #2F78A8
urxvt*color13: #A55B8C
urxvt*color14: #1db6dc
urxvt*color1: #A00000
urxvt*color2: #00a000
urxvt*color6: #0073B0
urxvt*color9: #EA3200
*/
//"#ea3200", // 1 red text
//"#2f78a8", // 4 cyan text ( ls directories) -- CORRECT
//"#1db6dc", // bright cyan -- symlinks
static const char *colorname[] = {
// color0 (black) = Black
"#000000", // 0
// color1 (red) = Red3
"#a00000", // 1 red text
// color2 (green) = Green3
"#00a000", // 2 green text
// color3 (yellow) = Yellow3
"#cdcd00", // 3 yellow text -- CORRECT
// color4 (blue) = Blue3
"#191970", // 4 blue text ( ls directories) -- CORRECT
// color5 (magenta) = Magenta3
"#A55B8C", // 5 magenta text
// color6 (cyan) = Cyan3
"#0073B0", // 6 cyan text ( in vim ) 2 ( also links in ls? )
// color7 (white) = AntiqueWhite
"#bebebe", // 7 normal grey text
/* "bright" colors (remember to set BOLD_IS_BRIGHT) */
// color8 (bright black) = Grey25
"#8b8f93",
// color9 (bright red) = Red
"#EA3200",
// color10 (bright green) = Green
"#00ba00",
// color11 (bright yellow) = Yellow
"#FFFF00",
// color12 (bright blue) = Blue
"#2F78A8",
// color13 (bright magenta) = Magenta
"#A55B8C",
// color14 (bright cyan) = Cyan
"#1db6dc",
// color15 (bright white) = White
"#FFFFFF",
//// "gray50",
//// "#EA3200",
//// "red",
//// "#2F78A8", // cyan ish
//// "#A55B8C",
//// "#1DB6DC",
//// "cyan",
//// "white"
};
/* Default colors (colorname index) */
/* foreground, background, cursor */
#define DefaultFG 7
#define DefaultBG 0
#define DefaultCS 7
/* Special keys */
static Key key[] = {
{ XK_BackSpace, "\177" },
{ XK_Insert, "\033[2~" },
{ XK_Delete, "\033[3~" },
{ XK_Home, "\033[1~" },
{ XK_End, "\033[4~" },
{ XK_Prior, "\033[5~" },
{ XK_Next, "\033[6~" },
{ XK_F1, "\033OP" },
{ XK_F2, "\033OQ" },
{ XK_F3, "\033OR" },
{ XK_F4, "\033OS" },
{ XK_F5, "\033[15~" },
{ XK_F6, "\033[17~" },
{ XK_F7, "\033[18~" },
{ XK_F8, "\033[19~" },
{ XK_F9, "\033[20~" },
{ XK_F10, "\033[21~" },
//{ XK_F11, "\033[23~" },
//{ XK_F12, "\033[24~" },
};
/* Line drawing characters (sometime specific to each font...) */
static char gfx[] = {
['f'] = 'o',
['g'] = '+',
['i'] = '#',
[255] = 0,
};
| 2.0625 | 2 |
2024-11-18T22:11:39.931969+00:00 | 2020-01-22T00:11:27 | 4aadc013ccb962a7a3c00ef412d1d9fd711648b0 | {
"blob_id": "4aadc013ccb962a7a3c00ef412d1d9fd711648b0",
"branch_name": "refs/heads/master",
"committer_date": "2020-01-22T00:11:27",
"content_id": "8c7e8848435b7dff4c7082371700b74b64b65b52",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "aa41bf52467aae0452a7783a0953341b793cce79",
"extension": "c",
"filename": "zonotope_resize.c",
"fork_events_count": 0,
"gha_created_at": "2020-03-14T17:12:17",
"gha_event_created_at": "2020-03-14T17:12:17",
"gha_language": null,
"gha_license_id": "Apache-2.0",
"github_id": 247319555,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 10291,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/eran/ELINA/elina_zonotope/zonotope_resize.c",
"provenance": "stackv2-0087.json.gz:7187",
"repo_name": "yqtianust/ReluDiff-ICSE2020-Artifact",
"revision_date": "2020-01-22T00:11:27",
"revision_id": "149f6efe4799602db749faa576980c36921a07c7",
"snapshot_id": "ecf106e90793395d8d296b38828d65dc3e443aab",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/yqtianust/ReluDiff-ICSE2020-Artifact/149f6efe4799602db749faa576980c36921a07c7/eran/ELINA/elina_zonotope/zonotope_resize.c",
"visit_date": "2021-03-21T18:19:19.172856"
} | stackv2 | /*
*
* This source file is part of ELINA (ETH LIbrary for Numerical Analysis).
* ELINA is Copyright © 2019 Department of Computer Science, ETH Zurich
* This software is distributed under GNU Lesser General Public License Version 3.0.
* For more information, see the ELINA project website at:
* http://elina.ethz.ch
*
* THE SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY WARRANTY OF ANY KIND, EITHER
* EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO ANY WARRANTY
* THAT THE SOFTWARE WILL CONFORM TO SPECIFICATIONS OR BE ERROR-FREE AND ANY
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
* TITLE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ETH ZURICH BE LIABLE FOR ANY
* DAMAGES, INCLUDING BUT NOT LIMITED TO DIRECT, INDIRECT,
* SPECIAL OR CONSEQUENTIAL DAMAGES, ARISING OUT OF, RESULTING FROM, OR IN
* ANY WAY CONNECTED WITH THIS SOFTWARE (WHETHER OR NOT BASED UPON WARRANTY,
* CONTRACT, TORT OR OTHERWISE).
*
*/
#include "zonotope_resize.h"
/*********************/
/* Add dimensions */
/*********************/
zonotope_t* zonotope_add_dimensions(elina_manager_t* man, bool destructive, zonotope_t* z, elina_dimchange_t* dimchange, bool project)
{
//printf("add input %d\n",destructive);
//zonotope_fprint(stdout,man,z,NULL);
//fflush(stdout);
start_timing();
zonotope_internal_t* pr = zonotope_init_from_manager(man, ELINA_FUNID_ADD_DIMENSIONS);
zonotope_t* res = destructive ? z : zonotope_copy(man, z);
size_t intdim = z->intdim + dimchange->intdim;
size_t dims = z->dims + (dimchange->intdim + dimchange->realdim);
res->box_inf = realloc(res->box_inf,dims*sizeof(double));
res->box_sup = realloc(res->box_sup,dims*sizeof(double));
res->paf = realloc(res->paf,dims*sizeof(zonotope_aff_t*));
size_t i = 0;
int j = 0;
for (i=0; i<dimchange->intdim + dimchange->realdim; i++) {
if (res->dims == dimchange->dim[i]) {
/* add in the last place */
res->box_inf[res->dims] = INFINITY;
res->box_sup[res->dims] = INFINITY;
} else {
/* increment */
for (j=(int)-1+res->dims;j>=(int)dimchange->dim[i];j--) {
res->paf[j+1] = res->paf[j];
res->box_inf[j+1] = res->box_inf[j];
res->box_sup[j+1] = res->box_sup[j];
}
}
res->paf[dimchange->dim[i]] = project ? zonotope_aff_alloc_init(pr) : pr->top;
res->paf[dimchange->dim[i]]->pby++;
if (project){
res->box_inf[dimchange->dim[i]]= 0.0;
res->box_sup[dimchange->dim[i]]= 0.0;
}
else {
res->box_inf[dimchange->dim[i]] = INFINITY;
res->box_sup[dimchange->dim[i]] = INFINITY;
}
res->dims++;
}
res->intdim = intdim;
//printf("add output\n");
//zonotope_fprint(stdout,man,res,NULL);
//fflush(stdout);
record_timing(zonotope_add_dimension_time);
return res;
}
/*********************/
/* Remove dimensions, Optimized for AI^2, Linear cost compared with quadratic with APRON */
/*********************/
zonotope_t* zonotope_remove_dimensions(elina_manager_t* man, bool destructive, zonotope_t* z, elina_dimchange_t* dimchange)
{
start_timing();
zonotope_internal_t* pr = zonotope_init_from_manager(man, ELINA_FUNID_REMOVE_DIMENSIONS);
//printf("remove input %d\n",destructive);
//zonotope_fprint(stdout,man,z,NULL);
//for(int i=0; i < dimchange->intdim+dimchange->realdim;i++){
//printf("%d ",dimchange->dim[i]);
//}
//printf("\n");
//fflush(stdout);
//zonotope_t* res = destructive ? z : zonotope_copy(man, z);
size_t i = 0;
size_t j = 0;
size_t num_remove = dimchange->intdim + dimchange->realdim;
size_t num_rem = z->dims - num_remove;
char * map = (char *)calloc(z->dims,sizeof(char));
elina_dim_t * var_rem = (elina_dim_t*)malloc(num_rem*sizeof(elina_dim_t));
size_t count = 0;
for(;i < num_remove; i++){
map[dimchange->dim[i]] = 1;
}
for(i=0; i < z->dims; i++){
if(!map[i]){
//printf("AI2 %d %d\n",i,count);
//fflush(stdout);
var_rem[count] = i;
count++;
}
}
zonotope_t* res = (zonotope_t *)malloc(sizeof(zonotope_t));
res->intdim = z->intdim -dimchange->intdim;
res->dims = num_rem;
res->size = z->size;
res->nsymcons = (elina_dim_t*)calloc(res->size, sizeof(elina_dim_t));
memcpy((void *)res->nsymcons, (void *)z->nsymcons, (res->size)*sizeof(elina_dim_t));
res->gamma = (elina_interval_t**)calloc(res->size, sizeof(elina_interval_t*));
res->abs = elina_abstract0_copy(pr->manNS, z->abs);
res->hypercube = z->hypercube;
res->box_inf = (double*)malloc(res->dims*sizeof(double));
res->box_sup = (double*)malloc(res->dims*sizeof(double));
res->gn = 0;
//res->g = NULL;
res->paf = (zonotope_aff_t**)malloc(res->dims*sizeof(zonotope_aff_t*));
for (i=0; i< num_rem; i++) {
j = var_rem[i];
res->paf[i] = zonotope_aff_alloc_init(pr);
//printf("coming here: %d %d %d %d %p %d\n",i,j,num_rem,num_remove,res->paf[i],res->dims);
//fflush(stdout);
//res->paf[i] = (zonotope_aff_t *)malloc(sizeof(zonotope_aff_t*));
res->paf[i] = z->paf[j];
//memcpy((void *)res->paf[i], (void *)z->paf[j], sizeof(zonotope_aff_t));
//zonotope_aff_check_free(pr,res->paf[dimchange->dim[i]]);
//res->paf[dimchange->dim[i]] = NULL;
//for (j=dimchange->dim[i];j<-1+res->dims;j++) {
// res->paf[j] = res->paf[j+1];
res->box_inf[i] = z->box_inf[j];
res->box_sup[i] = z->box_sup[j];
if(!destructive)
res->paf[i]->pby++;
//}
}
size_t nsymcons_size = zonotope_noise_symbol_cons_get_dimension(pr, z);
for (i=0; i<nsymcons_size; i++) {
if (z->gamma[i]) {
if (z->gamma[i] != pr->ap_muu) res->gamma[i] = elina_interval_alloc_set(z->gamma[i]);
else res->gamma[i] = pr->ap_muu;
} else {
fprintf(stderr,"zonotope_remove, unconsistent gamma for Zonotope abstract object\n");
}
}
//res->intdim = z->intdim - dimchange->intdim;
//res->dims = z->dims - (dimchange->intdim + dimchange->realdim);
//res->paf = realloc(res->paf,res->dims*sizeof(zonotope_aff_t*));
//printf("remove output %p\n",res);
//zonotope_fprint(stdout,man,res,NULL);
//fflush(stdout);
zonotope_t * tmp = z;
if(destructive){
//z = res;
//zonotope_free(man,tmp);
//return z;
//for(i=0; i < z->dims; z++){
// if(map[i]){
// zonotope_aff_check_free(pr,z->paf[i]);
//}
//}
//free(z->paf);
//z->paf=NULL;
//for (i=0; i<nsymcons_size; i++) {
// if (z->gamma[i]) {
// if (z->gamma[i] != pr->ap_muu) elina_interval_free(z->gamma[i]);
//}
//}
//free(z->gamma);
//z->gamma = NULL;
//free(z->nsymcons);
//z->nsymcons = NULL;
//elina_abstract0_free(pr->manNS, z->abs);
//free(z);
}
free(map);
free(var_rem);
record_timing(zonotope_remove_dimension_time);
return res;
}
zonotope_t* zonotope_permute_dimensions(elina_manager_t* man, bool destructive, zonotope_t* z, elina_dimperm_t* permutation)
{
zonotope_internal_t* pr = zonotope_init_from_manager(man, ELINA_FUNID_PERMUTE_DIMENSIONS);
//zonotope_aff_t* tmp = NULL;
// printf("permutation input %d\n",destructive);
//zonotope_fprint(stdout,man,z,NULL);
//for(int i=0; i < permutation->size;i++){
//printf("%d ",permutation->dim[i]);
//}
//printf("\n");
//fflush(stdout);
start_timing();
zonotope_t* res = (zonotope_t *)malloc(sizeof(zonotope_t));
res->intdim = z->intdim;
res->dims = z->dims;
res->size = z->size;
res->nsymcons = (elina_dim_t*)calloc(res->size, sizeof(elina_dim_t));
memcpy((void *)res->nsymcons, (void *)z->nsymcons, (res->size)*sizeof(elina_dim_t));
res->gamma = (elina_interval_t**)calloc(res->size, sizeof(elina_interval_t*));
res->abs = elina_abstract0_copy(pr->manNS, z->abs);
res->hypercube = z->hypercube;
res->box_inf = (double*)malloc(res->dims*sizeof(double));
res->box_sup = (double*)malloc(res->dims*sizeof(double));
res->gn = 0;
//res->g = NULL;
res->paf = (zonotope_aff_t**)malloc(res->dims*sizeof(zonotope_aff_t*));
size_t i = 0;
size_t j = 0;
for (i=0; i< permutation->size; i++) {
j = permutation->dim[i];
res->paf[j] = zonotope_aff_alloc_init(pr);
//printf("coming here: %d %d %d %d %p %d\n",i,j,num_rem,num_remove,res->paf[i],res->dims);
//fflush(stdout);
memcpy((void *)res->paf[j], (void *)z->paf[i], sizeof(zonotope_aff_t));
//zonotope_aff_check_free(pr,res->paf[dimchange->dim[i]]);
//res->paf[dimchange->dim[i]] = NULL;
//for (j=dimchange->dim[i];j<-1+res->dims;j++) {
// res->paf[j] = res->paf[j+1];
res->box_inf[j] = z->box_inf[i];
res->box_sup[j] = z->box_sup[i];
if(!destructive)
res->paf[i]->pby++;
//}
}
size_t nsymcons_size = zonotope_noise_symbol_cons_get_dimension(pr, z);
for (i=0; i<nsymcons_size; i++) {
if (z->gamma[i]) {
if (z->gamma[i] != pr->ap_muu) res->gamma[i] = elina_interval_alloc_set(z->gamma[i]);
else res->gamma[i] = pr->ap_muu;
} else {
fprintf(stderr,"zonotope_permute, unconsistent gamma for Zonotope abstract object\n");
}
}
//if(destructive){
// z = res;
//zonotope_free(man,tmp);
//return z;
//}
//char *map = (char *)calloc(permutation->size,sizeof(char));
//for (i=0; i<permutation->size; i++) {
//if(!map[i] && !map[permutation->dim[i]]){
// tmp = res->paf[i];
// res->paf[i] = res->paf[z->dim[i]];
//res->paf[permutation->dim[i]] = tmp;
//map[i] = 1;
//map[permutation->dim[i]] = 1;
//}
//}
//printf("permutation output %p\n",res);
//zonotope_fprint(stdout,man,res,NULL);
//fflush(stdout);
//free(map);
record_timing(zonotope_permute_dimension_time);
return res;
}
| 2.03125 | 2 |
2024-11-18T22:11:40.085562+00:00 | 2018-10-08T09:50:04 | 013bae03c47bcf287fd2a6e30270bfa781997105 | {
"blob_id": "013bae03c47bcf287fd2a6e30270bfa781997105",
"branch_name": "refs/heads/master",
"committer_date": "2018-10-08T09:50:04",
"content_id": "ff185e7cc5e33e440a8332b06ed4d4824caa2637",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "bd4d34f9aeca3fcb465abd5b5b277e5f739fad12",
"extension": "c",
"filename": "find_block.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 150408522,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1365,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/sources/intern/find_block.c",
"provenance": "stackv2-0087.json.gz:7443",
"repo_name": "Guiforge/ft_malloc2",
"revision_date": "2018-10-08T09:50:04",
"revision_id": "a1c3a18fa41fb528f9629f50f0a2cf6402f1087b",
"snapshot_id": "4e238a415d6b8783d1db8def6fa46459739b4e44",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/Guiforge/ft_malloc2/a1c3a18fa41fb528f9629f50f0a2cf6402f1087b/sources/intern/find_block.c",
"visit_date": "2020-03-29T22:12:22.197216"
} | stackv2 | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* find_block.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gpouyat <gpouyat@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/09/26 13:45:48 by gpouyat #+# #+# */
/* Updated: 2018/09/27 16:07:14 by gpouyat ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/intern_malloc.h"
#include "../../includes/malloc_error.h"
t_block *find_block_free(t_block *zone, size_t size)
{
t_block *b;
b = zone;
check_align(size);
while (b && !(b->free && b->size >= size))
{
b = b->next;
}
return (b);
}
t_block *find_block(t_block *zone, t_block *block, int free)
{
t_block *b;
b = zone;
while (b && b <= block)
{
if (b == block && b->free == free)
return (b);
b = b->next;
}
return (NULL);
}
| 2.59375 | 3 |
2024-11-18T22:11:40.299883+00:00 | 2021-03-31T21:37:03 | 65f6f88ad043bc20f314721d19364d57d81fb84b | {
"blob_id": "65f6f88ad043bc20f314721d19364d57d81fb84b",
"branch_name": "refs/heads/master",
"committer_date": "2021-04-02T14:49:07",
"content_id": "67bccf119191014a9ff9555ca2df3144854b6069",
"detected_licenses": [
"MIT"
],
"directory_id": "401d2ed96357366efc59a23be85ef3534eea0a98",
"extension": "h",
"filename": "kernel.h",
"fork_events_count": 0,
"gha_created_at": "2019-11-13T20:50:39",
"gha_event_created_at": "2023-07-05T20:45:11",
"gha_language": "Java",
"gha_license_id": "MIT",
"github_id": 221549226,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1938,
"license": "MIT",
"license_type": "permissive",
"path": "/yln/imaging/kernel.h",
"provenance": "stackv2-0087.json.gz:7572",
"repo_name": "smackem/ylangfx",
"revision_date": "2021-03-31T21:37:03",
"revision_id": "1cf583ad92b688df7bc2483a764f2f697a76211b",
"snapshot_id": "5b59c2a9cf25149e8c123d6a800540d44bd4e023",
"src_encoding": "UTF-8",
"star_events_count": 2,
"url": "https://raw.githubusercontent.com/smackem/ylangfx/1cf583ad92b688df7bc2483a764f2f697a76211b/yln/imaging/kernel.h",
"visit_date": "2023-07-23T02:38:44.973058"
} | stackv2 | //
// Created by Philip Boger on 29.11.20.
//
#ifndef YLN_KERNEL_H
#define YLN_KERNEL_H
/**
* Represents a two-dimensional matrix of float values, which can
* be used for image operations like convolution or to represent
* greyscale images.
*/
typedef struct kernel {
/**
* The width of the kernel.
*/
int width;
/**
* The height of the kernel.
*/
int height;
/**
* The kernel values. Length is equal to width * height.
*/
float *values;
} Kernel;
/**
* A type of function to compose float values.
*/
typedef float (*float_composition_t)(float left, float right);
/**
* Initializes the given kernel, allocating memory for the kernel values.
* Call `free_kernel` to dispose of the kernel memory.
*/
void init_kernel(Kernel *kernel, int width, int height, float value);
/**
* Wraps some preallocated memory with the given kernel structure.
* The size of the buffer at `values` must be equal to width * height.
*/
void wrap_kernel(Kernel *kernel, int width, int height, float *values);
/**
* Releases all resources allocated by the given kernel.
*/
void free_kernel(Kernel *kernel);
/**
* Sums up all values in the given kernel.
*/
float get_kernel_sum(const Kernel *kernel);
/**
* Applies the image operation convolution to `orig`, which in this case represents a greyscale image,
* using the given kernel and stores the result in `dest`.
* `dest` must be initialized to the same size as `orig`.
*/
void convolve_kernel(Kernel *dest, const Kernel *orig, const Kernel *kernel);
/**
* Composes two kernels `left` and `right`, using the given composition function (which is applied
* to all pixels in `left` and `right`) and stores the result in `dest`.
* `dest` must be initialized to the same size as `left` and `right`.
*/
void compose_kernel(Kernel *dest, const Kernel *left, const Kernel *right, float_composition_t compose);
#endif //YLN_KERNEL_H
| 3.140625 | 3 |
2024-11-18T22:11:40.932420+00:00 | 2022-07-07T07:48:59 | 4b3ddf5a24f2ed22c87e2b1068ef2ba46590871a | {
"blob_id": "4b3ddf5a24f2ed22c87e2b1068ef2ba46590871a",
"branch_name": "refs/heads/master",
"committer_date": "2022-07-07T07:48:59",
"content_id": "66cdf6874522309572a7ef8dc903ad73735e8517",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "ea8fc70c7dbf49059431fa45a940742736c68fb8",
"extension": "h",
"filename": "avltree.h",
"fork_events_count": 73,
"gha_created_at": "2015-12-02T07:44:43",
"gha_event_created_at": "2021-06-22T11:53:25",
"gha_language": "C",
"gha_license_id": null,
"github_id": 47245335,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 7132,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/ext/kernel/avltree.h",
"provenance": "stackv2-0087.json.gz:8346",
"repo_name": "dreamsxin/cphalcon7",
"revision_date": "2022-07-07T07:48:59",
"revision_id": "1b8c6b04b4ca237a5ead87d4752df0d2e85c7a9d",
"snapshot_id": "1bd2194a251657b48857326927db69fef617ab91",
"src_encoding": "UTF-8",
"star_events_count": 298,
"url": "https://raw.githubusercontent.com/dreamsxin/cphalcon7/1b8c6b04b4ca237a5ead87d4752df0d2e85c7a9d/ext/kernel/avltree.h",
"visit_date": "2023-03-08T04:53:08.829432"
} | stackv2 |
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2015 Phalcon Team (http://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file docs/LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <andres@phalconphp.com> |
| Eduar Carvajal <eduar@phalconphp.com> |
| ZhuZongXin <dreamsxin@qq.com> |
+------------------------------------------------------------------------+
*/
#ifndef PHALCON_KERNEL_AVLTREE_H
#define PHALCON_KERNEL_AVLTREE_H
#include "kernel/memory.h"
typedef struct {
phalcon_memory_void_value right;
phalcon_memory_void_value left;
phalcon_memory_void_value parent;
signed balance:3; /* balance factor [-2:+2] */
} phalcon_avltree_node;
typedef int (*phalcon_avltree_node_compare)(phalcon_avltree_node * , phalcon_avltree_node *);
typedef struct {
phalcon_memory_void_value root;
int height;
phalcon_memory_void_value first;
phalcon_memory_void_value last;
} phalcon_avltree;
static inline int phalcon_avltree_is_root_avl(phalcon_avltree_node *node)
{
return NULL == phalcon_memory_void_get(&node->parent);
}
static inline void phalcon_avltree_init_node(phalcon_avltree_node *node)
{
phalcon_memory_void_set(&node->left, NULL);
phalcon_memory_void_set(&node->right, NULL);
phalcon_memory_void_set(&node->parent, NULL);
node->balance = 0;;
}
static inline signed phalcon_avltree_get_balance(phalcon_avltree_node *node)
{
return node->balance;
}
static inline void phalcon_avltree_set_balance(int balance, phalcon_avltree_node *node)
{
node->balance = balance;
}
static inline int phalcon_avltree_inc_balance(phalcon_avltree_node *node)
{
return ++node->balance;
}
static inline int phalcon_avltree_dec_balance(phalcon_avltree_node *node)
{
return --node->balance;
}
static inline phalcon_avltree_node* phalcon_avltree_get_parent_avl(phalcon_avltree_node *node)
{
return phalcon_memory_void_get(&node->parent);
}
static inline void phalcon_avltree_set_parent_avl(phalcon_avltree_node *parent, phalcon_avltree_node *node)
{
phalcon_memory_void_set(&node->parent, parent);
}
/*
* Iterators
*/
static inline phalcon_avltree_node* phalcon_avltree_get_first_avl(phalcon_avltree_node *node)
{
while (phalcon_memory_void_get(&node->left))
node = phalcon_memory_void_get(&node->left);
return node;
}
static inline phalcon_avltree_node* phalcon_avltree_get_last_avl(phalcon_avltree_node *node)
{
while (phalcon_memory_void_get(&node->right))
node = phalcon_memory_void_get(&node->right);
return node;
}
/*
* The AVL tree is more rigidly balanced than Red-Black trees, leading
* to slower insertion and removal but faster retrieval.
*/
/* node->balance = height(node->right) - height(node->left); */
static inline void phalcon_avltree_rotate_left_avl(phalcon_avltree_node *node, phalcon_avltree *tree)
{
phalcon_avltree_node *p = node;
phalcon_avltree_node *q = phalcon_memory_void_get(&node->right); /* can't be NULL */
phalcon_avltree_node *parent = phalcon_avltree_get_parent_avl(p);
if (!phalcon_avltree_is_root_avl(p)) {
if (phalcon_memory_void_get(&parent->left) == p)
phalcon_memory_void_set(&parent->left, q);
else
phalcon_memory_void_set(&parent->right, q);
} else {
phalcon_memory_void_set(&tree->root, q);
}
phalcon_avltree_set_parent_avl(parent, q);
phalcon_avltree_set_parent_avl(q, p);
phalcon_memory_void_set(&p->right, phalcon_memory_void_get(&q->left));
if (phalcon_memory_void_get(&p->right))
phalcon_avltree_set_parent_avl(p, phalcon_memory_void_get(&p->right));
phalcon_memory_void_set(&q->left, p);
}
static inline void phalcon_avltree_rotate_right_avl(phalcon_avltree_node *node, phalcon_avltree *tree)
{
phalcon_avltree_node *p = node;
phalcon_avltree_node *q = phalcon_memory_void_get(&node->left) ; /* can't be NULL */
phalcon_avltree_node *parent = phalcon_avltree_get_parent_avl(p);
if (!phalcon_avltree_is_root_avl(p)) {
if (phalcon_memory_void_get(&parent->left) == p)
phalcon_memory_void_set(&parent->left, q);
else
phalcon_memory_void_set(&parent->right, q);
} else {
phalcon_memory_void_set(&tree->root, q);
}
phalcon_avltree_set_parent_avl(parent, q);
phalcon_avltree_set_parent_avl(q, p);
phalcon_memory_void_set(&p->left, phalcon_memory_void_get(&q->right));
if (phalcon_memory_void_get(&p->left))
phalcon_avltree_set_parent_avl(p, phalcon_memory_void_get(&p->left));
phalcon_memory_void_set(&q->right, p);
}
static inline void phalcon_avltree_set_child_avl(phalcon_avltree_node *child, phalcon_avltree_node *node, int left)
{
if (left) phalcon_memory_void_set(&node->left, child);
else phalcon_memory_void_set(&node->right, child);
}
/*
* 'pparent', 'unbalanced' and 'is_left' are only used for
* insertions. Normally GCC will notice this and get rid of them for
* lookups.
*/
static inline phalcon_avltree_node *phalcon_avltree_do_lookup_avl(phalcon_avltree_node *key, phalcon_avltree_node_compare cmp, phalcon_avltree *tree, phalcon_avltree_node **pparent, phalcon_avltree_node **unbalanced, int *is_left)
{
phalcon_avltree_node *node = phalcon_memory_void_get(&tree->root);
int res = 0;
*pparent = NULL;
*unbalanced = node;
*is_left = 0;
while (node) {
if (phalcon_avltree_get_balance(node) != 0)
*unbalanced = node;
res = cmp(node, key);
if (res == 0)
return node;
*pparent = node;
if ((*is_left = res > 0))
node = phalcon_memory_void_get(&node->left);
else
node = phalcon_memory_void_get(&node->right);
}
return NULL;
}
phalcon_avltree_node* phalcon_avltree_first(phalcon_avltree* tree);
phalcon_avltree_node* phalcon_avltree_last(phalcon_avltree* tree);
phalcon_avltree_node* phalcon_avltree_next(phalcon_avltree_node* node);
phalcon_avltree_node* phalcon_avltree_prev(phalcon_avltree_node* node);
phalcon_avltree_node* phalcon_avltree_lookup(phalcon_avltree_node* key, phalcon_avltree_node_compare cmp, phalcon_avltree* tree);
phalcon_avltree_node* phalcon_avltree_insert(phalcon_avltree_node* node, phalcon_avltree_node_compare cmp, phalcon_avltree* tree);
void phalcon_avltree_remove(phalcon_avltree_node* node, phalcon_avltree* tree);
void phalcon_avltree_replace(phalcon_avltree_node* old, phalcon_avltree_node* node, phalcon_avltree* tree);
void phalcon_avltree_init(phalcon_avltree* tree);
#endif /* PHALCON_KERNEL_AVLTREE_H */
| 2.453125 | 2 |
2024-11-18T22:11:40.995504+00:00 | 2020-08-06T09:35:43 | 0184f527ef6359d12936f057cbee7c6630db9215 | {
"blob_id": "0184f527ef6359d12936f057cbee7c6630db9215",
"branch_name": "refs/heads/master",
"committer_date": "2020-08-06T09:35:43",
"content_id": "62237350065c845302e9ad6ddf8508bc3eef3ffa",
"detected_licenses": [
"MIT"
],
"directory_id": "7e7912c22a7c834ba8d66cc86cfce717ec061b8b",
"extension": "c",
"filename": "Solver.c",
"fork_events_count": 0,
"gha_created_at": "2020-06-18T10:14:57",
"gha_event_created_at": "2020-07-31T07:39:03",
"gha_language": "C",
"gha_license_id": null,
"github_id": 273206280,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1872,
"license": "MIT",
"license_type": "permissive",
"path": "/exercise10/Aufgabe_3/Solver.c",
"provenance": "stackv2-0087.json.gz:8474",
"repo_name": "eppdo/PG1-S2020",
"revision_date": "2020-08-06T09:35:43",
"revision_id": "20fd57aec298d95bec2f06f82aba7a0bf180189f",
"snapshot_id": "1c468f1c43997562c37d984bcb02539a664337dd",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/eppdo/PG1-S2020/20fd57aec298d95bec2f06f82aba7a0bf180189f/exercise10/Aufgabe_3/Solver.c",
"visit_date": "2022-12-03T21:15:13.686146"
} | stackv2 | #include <stdio.h>
// function: Bewegungsrichtung finden
void Movement(_Bool Direction[], int* nextRow, int* nextCol);
// Benachbarte Elemente untersuchen
void Pathfinder(_Bool Direction[], char maze[][20], int row, int col, int* Crossing);
// Sackgasse
void DeadEnd(char maze[][20], int* row, int* col, int Way[][3], int* StaticIdx);
void Solver(char maze[][20], const int* StartRow, const int* StartCol, int row, int col, int Way[][3])
{
// Array zum speichern der freien Richtungen: _Bool 0 -> belegt | _Bool 1 -> frei
// Direction[0] -> Boolscher Wert: 1 = Freies Nachbarelement
// Direction[1] -> oben | Direction[2] -> unten
// Direction[3] -> links | Direction[4] -> rechts
_Bool Direction[5] = { 0 };
// Index fuer bereits begangenen Weg
static int idx = 0;
// Aktuelle Position speichern
Way[idx][0] = row;
Way[idx][1] = col;
idx++;
// Wieder an Start angekommen -> Kein Futter gefunden
if (row == StartRow && col == StartCol && maze[row][col] == '.')
{
// Wieder am Start angekommen -> Kein Futter gefunden
printf("\nEs wurde kein Futter gefunden und die Maus muss verhungern\n\n");
}
// Futter gefunden :)
else if (maze[row][col] == 'F')
{
// Ausgabe: "Futter gefunden" -> Ziel erreicht
printf("\n\tFutter gefunden!\n\n");
}
// Wegsuche
else
{
// Umgebung nach freien Feldern untersuchen: Ergebnis in Direction gespeichert
Pathfinder(Direction, maze, row, col, &Way[idx - 1][2]);
// Pruefung ob Sackgasse
if (Direction[0] == 0) // Direction[0] == 0 -> Sackgasse
{
DeadEnd(maze, &row, &col, Way, &idx);
}
else
{
// Weg markieren
maze[row][col] = '.';
}
// Bestimmung naechste Bewegunsrichtung
int nextRow = 0;
int nextCol = 0;
Movement(Direction, &nextRow, &nextCol);
// rek. Aufruf Funktion
Solver(maze, StartRow, StartCol, row + nextRow, col + nextCol, Way);
}
} | 2.84375 | 3 |
2024-11-18T22:11:41.120908+00:00 | 2023-06-11T13:15:15 | 99b38177c0c73c94d2233a4b2d9b2a111088e2a9 | {
"blob_id": "99b38177c0c73c94d2233a4b2d9b2a111088e2a9",
"branch_name": "refs/heads/master",
"committer_date": "2023-06-11T13:15:15",
"content_id": "87d1bf6938e9d53e32929d7fdf737a30f6853560",
"detected_licenses": [
"0BSD"
],
"directory_id": "9907672fcd81ab73ac63b2a83422a82bf31eadde",
"extension": "c",
"filename": "tyama_codeeval226.c",
"fork_events_count": 136,
"gha_created_at": "2013-01-11T09:40:26",
"gha_event_created_at": "2020-10-20T09:35:52",
"gha_language": "C++",
"gha_license_id": null,
"github_id": 7557464,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 213,
"license": "0BSD",
"license_type": "permissive",
"path": "/codeeval/tyama_codeeval226.c",
"provenance": "stackv2-0087.json.gz:8602",
"repo_name": "cielavenir/procon",
"revision_date": "2023-06-11T13:15:15",
"revision_id": "746e1a91f574f20647e8aaaac0d9e6173f741176",
"snapshot_id": "bbe1974b9bddb51b76d58722a0686a5b477c4456",
"src_encoding": "UTF-8",
"star_events_count": 137,
"url": "https://raw.githubusercontent.com/cielavenir/procon/746e1a91f574f20647e8aaaac0d9e6173f741176/codeeval/tyama_codeeval226.c",
"visit_date": "2023-06-21T23:11:24.562546"
} | stackv2 | #include <stdio.h>
char *T="abcdefghijklmuvwxyznopqrst";
int main(){
int c=0;
for(;~(c=getchar());){
if('a'<=c&&c<='z'){
int n=(strchr(T,c)-T+13)%26;
putchar(T[n]);
}
else putchar(c);
}
return 0;
} | 2.65625 | 3 |
2024-11-18T22:11:41.594810+00:00 | 2012-12-01T19:25:01 | 78c845b4afce379f4f48f05b356ad5d0bc182a89 | {
"blob_id": "78c845b4afce379f4f48f05b356ad5d0bc182a89",
"branch_name": "refs/heads/master",
"committer_date": "2012-12-01T19:25:01",
"content_id": "d731fe104101d4116b553f907414b99eb2ad5ea8",
"detected_licenses": [
"MIT"
],
"directory_id": "90e98a6701007eadf341b455e46b92a76a8ebac6",
"extension": "c",
"filename": "link.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 963,
"license": "MIT",
"license_type": "permissive",
"path": "/src/link/link.c",
"provenance": "stackv2-0087.json.gz:8989",
"repo_name": "whittacake/gentils",
"revision_date": "2012-12-01T19:25:01",
"revision_id": "f1166788d7e49bf6760813884bcfc0c29d15c227",
"snapshot_id": "05263477d545d41448fab53f85af36c59a1cc924",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/whittacake/gentils/f1166788d7e49bf6760813884bcfc0c29d15c227/src/link/link.c",
"visit_date": "2021-01-18T09:40:31.179602"
} | stackv2 | /*This program 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 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(int argc, char *argv[])
{
if (argc < 3) {
printf("usage: %s file1 file2\n", argv[0]);
return 1;
}
if (link(argv[1], argv[2])) {
printf("%s: could not create link: %s\n", argv[0], strerror(errno));
return 1;
}
return 0;
}
| 2.265625 | 2 |
2024-11-18T22:11:42.062907+00:00 | 2021-04-11T14:31:05 | 181bbc23497ae1d0194405e7c338959e8a3a862e | {
"blob_id": "181bbc23497ae1d0194405e7c338959e8a3a862e",
"branch_name": "refs/heads/master",
"committer_date": "2021-04-11T14:31:05",
"content_id": "5c21fae788a8f2ff5c4de50e501e49561c9c67a2",
"detected_licenses": [
"MIT"
],
"directory_id": "296278a0b87aecb72e20f0ffc8d4802c731b40ce",
"extension": "c",
"filename": "quick-sort.c",
"fork_events_count": 2,
"gha_created_at": "2019-07-03T10:22:13",
"gha_event_created_at": "2019-08-28T11:49:42",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 195031156,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2251,
"license": "MIT",
"license_type": "permissive",
"path": "/algorithm/CodingInterviews/sort/quick-sort.c",
"provenance": "stackv2-0087.json.gz:9376",
"repo_name": "kaynewbie/algorithm",
"revision_date": "2021-04-11T14:31:05",
"revision_id": "2b913ca583cce35757c6e33766e9226553f214fa",
"snapshot_id": "8b20afec27a5f19c25025eb7f51ffc17719f8cd1",
"src_encoding": "UTF-8",
"star_events_count": 8,
"url": "https://raw.githubusercontent.com/kaynewbie/algorithm/2b913ca583cce35757c6e33766e9226553f214fa/algorithm/CodingInterviews/sort/quick-sort.c",
"visit_date": "2021-06-17T11:11:34.796481"
} | stackv2 | //
// quick-sort.c
// algorithm
//
// Created by Kai on 2019/7/11.
// Copyright © 2019 kai. All rights reserved.
//
#include "quick-sort.h"
#include "stdlib.h"
#include <sys/time.h>
/**
交换两个变量的值。
@param p 一个待交换变量的地址
@param q 另一个待交换变量的地址
*/
void swap(int *p, int *q) {
if (p == NULL || q == NULL) {
return;
}
int temp = *p;
*p = *q;
*q = temp;
}
/**
获取一个参考值,遍历数组 start 和 end-1 索引区间内的元素,
小于等于参考值的放到索引左边,大于的放到右边,
过程中,记录小于等于参考值的元素数量,并返回该数。
@param p 数组指针
@param start 当前排序区间起始索引
@param end 当前排序区间终止索引
@return 当次排序的随机索引值
*/
int partition(int *p, int start, int end) {
int randomIdx;
int small;
//随机索引这里用中间索引
randomIdx = (start + end) >> 1;
small = start - 1;
swap(p + randomIdx, p + end);
for (int i = start; i < end; i++) {
if (*(p+i) <= *(p+end)) {
small++;
if (small != i) {
swap(p+i, p+small);
}
}
}
small++;
swap(p+small, p+end);
return small;
}
/**
快速排序驱动函数
*/
void quickSort(int *p, int start, int end) {
if (start == end) {
return;
}
int index = partition(p, start, end);
if (index > start) {
quickSort(p, start, index - 1);
}
if (index < end) {
quickSort(p, index + 1, end);
}
}
/**
元素大小为0~range内的随机数组
*/
int *randomArray(int length, int range) {
int *p = malloc(sizeof(int) * length);
srand((unsigned int)time(0));
int value;
for (int i = 0; i < length; i++) {
value = rand() % range;
*(p + i) = value;
}
return p;
}
void printArray(int p[], int length) {
printf("array: ");
for (int i = 0; i < length; i++) {
printf("%d ", p[i]);
}
printf("\n");
}
void testQuickSort(void) {
int length = 30;
int *p = randomArray(length, 1000);
quickSort(p, 0, length - 1);
printArray(p, length);
}
| 3.796875 | 4 |
2024-11-18T22:11:42.622123+00:00 | 2016-09-08T14:18:54 | 1761ff3ea91b2838dc4e5d2c47a934a7e6181d8c | {
"blob_id": "1761ff3ea91b2838dc4e5d2c47a934a7e6181d8c",
"branch_name": "refs/heads/master",
"committer_date": "2016-09-08T14:34:28",
"content_id": "7ebbb92985b8f926f14e039dd762dd0414b7f415",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "bb5371b9a1574654760dbc2627f7fe542d3be1bd",
"extension": "h",
"filename": "pmu.h",
"fork_events_count": 0,
"gha_created_at": "2016-09-08T14:31:33",
"gha_event_created_at": "2016-09-08T14:31:33",
"gha_language": null,
"gha_license_id": null,
"github_id": 67710707,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3177,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/instr/pmu.h",
"provenance": "stackv2-0087.json.gz:9765",
"repo_name": "roxell/odp-example-sisu",
"revision_date": "2016-09-08T14:18:54",
"revision_id": "a0896101fada5840aa49868c4aef0139ea9e3b5d",
"snapshot_id": "60bec41c27b118fe9988bcca7882af0f88e240d5",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/roxell/odp-example-sisu/a0896101fada5840aa49868c4aef0139ea9e3b5d/instr/pmu.h",
"visit_date": "2021-01-17T22:00:42.659199"
} | stackv2 | /* Copyright 2015, ARM Limited or its affiliates. All rights reserved. */
#define L1_CACHE_REFILL 0
#define L1_CACHE_ACCESS 1
#define L2_CACHE_REFILL 2
#define L2_CACHE_ACCESS 3
#define INSTR_RETIRED 4
#define L1_CACHE_REFILL_EVENT 0x03
#define L1_CACHE_ACCESS_EVENT 0x04
#define L2_CACHE_REFILL_EVENT 0x17
#define L2_CACHE_ACCESS_EVENT 0x16
#define INSTR_RETIRED_EVENT 0x08
#define USER_EVENTS (1 << 31)
#ifdef __x86_64__
static inline uint64_t __attribute__((always_inline))
rdtsc(void)
{
union {
uint64_t tsc_64;
struct {
uint32_t lo_32;
uint32_t hi_32;
};
} tsc;
asm volatile("rdtsc" :
"=a" (tsc.lo_32),
"=d" (tsc.hi_32));
return tsc.tsc_64;
}
#endif
static inline void __attribute__((always_inline))
pmu_set_pmselr(int r)
{
#ifdef __arm__
__asm__ __volatile__("MCR p15, 0, %0, c9, c12, 5" :: "r"(r));
#elif __aarch64__
__asm__ __volatile__("MSR PMSELR_EL0, %0" :: "r"(r));
#endif
}
static inline uint32_t __attribute__((always_inline))
pmu_get_pmselr()
{
uint32_t r;
#ifdef __arm__
__asm__ __volatile__("MRC p15, 0, %0, c9, c12, 5" : "=r"(r));
#elif __aarch64__
__asm__ __volatile__("MRS %0, PMSELR_EL0" : "=r"(r));
#endif
return r;
}
static inline uint64_t __attribute__((always_inline))
pmu_get_cycle_counter()
{
uint64_t c;
#ifdef __arm__
__asm__ __volatile__("MRC p15, 0, %0, c9, c13, 0" : "=r"(c));
#elif __aarch64__
__asm__ __volatile__("MRS %0, PMCCNTR_EL0" : "=r"(c));
#elif __x86_64__
c = rdtsc();
#endif
return c;
}
static inline void __attribute__((always_inline))
pmu_reset_event_counter(int type)
{
pmu_set_pmselr(type);
#ifdef __arm__
__asm__ __volatile__("MCR p15, 0, %0, c9, c13, 2" :: "r"(0));
#elif __aarch64__
__asm__ __volatile__("MSR PMXEVCNTR_EL0, %0" :: "r"(0));
#endif
}
static inline uint32_t __attribute__((always_inline))
pmu_get_event_counter(int type)
{
uint32_t c = 0;
pmu_set_pmselr(type);
#ifdef __arm__
__asm__ __volatile__("MRC p15, 0, %0, c9, c13, 2" : "=r"(c));
#elif __aarch64__
__asm__ __volatile__("MRS %0, PMXEVCNTR_EL0" : "=r"(c));
#endif
return c;
}
static inline uint32_t __attribute__((always_inline))
pmu_get_pmxevtyper()
{
uint32_t r;
#ifdef __arm__
__asm__ __volatile__("MRC p15, 0, %0, c9, c13, 1" : "=r"(r));
#elif __aarch64__
__asm__ __volatile__("MRS %0, PMXEVTYPER_EL0" : "=r"(r));
#endif
return r;
}
static inline void __attribute__((always_inline))
pmu_set_pmxevtyper(uint32_t r)
{
#ifdef __arm__
__asm__ __volatile__("MCR p15, 0, %0, c9, c13, 1" :: "r"(r));
#elif __aarch64__
__asm__ __volatile__("MSR PMXEVTYPER_EL0, %0" :: "r"(r));
#endif
}
static inline void __attribute__((always_inline))
pmu_init()
{
#if defined(__arm__) || defined(__aarch64__)
pmu_set_pmselr(L1_CACHE_REFILL);
pmu_set_pmxevtyper(L1_CACHE_REFILL_EVENT | USER_EVENTS);
pmu_set_pmselr(L1_CACHE_ACCESS);
pmu_set_pmxevtyper(L1_CACHE_ACCESS_EVENT | USER_EVENTS);
pmu_set_pmselr(L2_CACHE_REFILL);
pmu_set_pmxevtyper(L2_CACHE_REFILL_EVENT | USER_EVENTS);
pmu_set_pmselr(L2_CACHE_ACCESS);
pmu_set_pmxevtyper(L2_CACHE_ACCESS_EVENT | USER_EVENTS);
pmu_set_pmselr(INSTR_RETIRED);
pmu_set_pmxevtyper(INSTR_RETIRED_EVENT | USER_EVENTS);
#endif
}
| 2.125 | 2 |
2024-11-18T22:11:42.840706+00:00 | 2021-08-12T23:11:00 | e17c6b2bb966a9fdef5095626fd930a16a59b28c | {
"blob_id": "e17c6b2bb966a9fdef5095626fd930a16a59b28c",
"branch_name": "refs/heads/master",
"committer_date": "2021-08-12T23:11:00",
"content_id": "08610a653995a4518c8f3c304a929e22c89e90e7",
"detected_licenses": [
"MIT"
],
"directory_id": "2b451dd2397d056456354e8191cc27f55f7a54fe",
"extension": "h",
"filename": "stm32f446xx_gpio_driver.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 389768082,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 4601,
"license": "MIT",
"license_type": "permissive",
"path": "/FastBitMasteringMCU1/stm32f4xx_drivers/drivers/Inc/stm32f446xx_gpio_driver.h",
"provenance": "stackv2-0087.json.gz:9894",
"repo_name": "DiegoDN/FastBitMasteringMCU1",
"revision_date": "2021-08-12T23:11:00",
"revision_id": "a35a8f5288e89d8d1c55ff8274764427c2f9b964",
"snapshot_id": "e8eaa8d94496d8177b2ac494888b480f01f11218",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/DiegoDN/FastBitMasteringMCU1/a35a8f5288e89d8d1c55ff8274764427c2f9b964/FastBitMasteringMCU1/stm32f4xx_drivers/drivers/Inc/stm32f446xx_gpio_driver.h",
"visit_date": "2023-09-01T14:41:08.539957"
} | stackv2 | #ifndef STM32F446XX_GPIO_DRIVER_H_
#define STM32F446XX_GPIO_DRIVER_H_
#include <stdio.h>
#include <stdint.h>
#include "stm32f446xx.h"
/*
* DS = DATASHEET @ = PAGE NUMBER
* DATASHEET = dm00135183-stm32f446xx-advanced-arm-based-32-bit-mcus-stmicroelectronics.pdf
*/
/* ################################################################################################
* CONFIGURATION STRUCTURE FOR GPIO PINs
* ################################################################################################
*/
typedef struct
{
uint8_t GPIO_PinNumber; /* possible values from @GPIO_PIN_NUMBER - DS 187 - 192 */
uint8_t GPIO_PinMode; /* possible values from @GPIO_PIN_MODES - DS 187 - 192 */
uint8_t GPIO_PinSpeed; /* possible values from @GPIO_PIN_SPEED - DS 187 - 192 */
uint8_t GPIO_PinPuPdControl; /* possible values from @GPIO_PIN_PUPD - DS 187 - 192 */
uint8_t GPIO_PinOPType; /* possible values from @GPIO_PIN_OP_TYPE - DS 187 - 192 */
uint8_t GPIO_PinAltFuncMode; /* possible values from @GPIO_PIN_MODES - DS 187 - 192 */
} GPIO_PinConfig_t;
/* GPIO PIN Possible PINNUMBER macros */
/* @GPIO_PIN_NUMBER */
#define GPIO_PIN_00 0
#define GPIO_PIN_01 1
#define GPIO_PIN_02 2
#define GPIO_PIN_03 3
#define GPIO_PIN_04 4
#define GPIO_PIN_05 5
#define GPIO_PIN_06 6
#define GPIO_PIN_07 7
#define GPIO_PIN_08 8
#define GPIO_PIN_09 9
#define GPIO_PIN_10 10
#define GPIO_PIN_11 11
#define GPIO_PIN_12 12
#define GPIO_PIN_13 13
#define GPIO_PIN_14 14
#define GPIO_PIN_15 15
/* GPIO PIN Possible MODE macros */
/* @GPIO_PIN_MODES */
#define GPIO_MODE_IN 0
#define GPIO_MODE_OUT 1
#define GPIO_MODE_ALTFN 2
#define GPIO_MODE_ANALOG 3
#define GPIO_MODE_ITFT 4
#define GPIO_MODE_ITRT 5
#define GPIO_MODE_ITFRT 6
/* GPIO PIN Possible SPEEDS macros */
/* @GPIO_PIN_SPEED */
#define GPIO_SPEED_LOW 0
#define GPIO_SPEED_MEDIUM 1
#define GPIO_SPEED_FAST 2
#define GPIO_SPEED_HIGH 3
/* GPIO PIN Possible PULL-UP PULL-DOWN configuration macros */
/* @GPIO_PIN_PUPD */
#define GPIO_PIN_NO_PUPD 0
#define GPIO_PIN_PU 1
#define GPIO_PIN_PD 2
/* GPIO PIN Possible OUTPUT Types macros */
/* @GPIO_PIN_OP_TYPE */
#define GPIO_OP_TYPE_PP 0
#define GPIO_OP_TYPE_OD 1
/* ################################################################################################
* HANDLE STRUCTURE FOR GPIO PINs
* ################################################################################################
*/
typedef struct
{
GPIO_RegDef_t *pGPIOx; /* holds base addr of GPIO PORT to which this pin belongs */
GPIO_PinConfig_t GPIO_PinConfig; /* holds GPIO Pin configuration settings */
} GPIO_Handle_t;
/* ################################################################################################
* APIS SUPPORTED BY THIS DRIVER
* ################################################################################################
*/
/* Peripheral Clock Setup */
void GPIO_PeripheralClockControl(GPIO_RegDef_t *pGPIOx, uint8_t EnorDi);
/* Init / DeInit */
void GPIO_Init (GPIO_Handle_t *pGPIOHandle);
void GPIO_DeInit(GPIO_RegDef_t *pGPIOx);
/* Data Read and Write */
uint8_t GPIO_ReadFromInputPin (GPIO_RegDef_t *pGPIOx, uint8_t PinNumber);
uint16_t GPIO_ReadFromInputPort (GPIO_RegDef_t *pGPIOx);
void GPIO_WritetoOutputPin (GPIO_RegDef_t *pGPIOx, uint8_t PinNumber, uint8_t Value);
void GPIO_WritetoOutputPort (GPIO_RegDef_t *pGPIOx, uint16_t Value);
void GPIO_ToogleOutputPin (GPIO_RegDef_t *pGPIOx, uint8_t PinNumber);
/* IRQ Handling */
void GPIO_IRQInterruptConfig(uint8_t IRQNumber, uint8_t EnorDi);
void GPIO_IRQPriorityConfig(uint8_t IRQNumber, uint32_t IRQPriotity);
void GPIO_IRQHandling(uint8_t PinNumber);
#endif /* STM32F446XX_GPIO_DRIVER_H_ */
| 2.34375 | 2 |
2024-11-18T22:11:42.918712+00:00 | 2021-09-12T14:12:03 | 32419b418ae1fd68367eec1067ea6bd6c03a6fb8 | {
"blob_id": "32419b418ae1fd68367eec1067ea6bd6c03a6fb8",
"branch_name": "refs/heads/master",
"committer_date": "2021-09-12T14:12:03",
"content_id": "cd8b6cb598f723aa91f94d0e826c012074f603a1",
"detected_licenses": [
"MIT"
],
"directory_id": "8c702c2a93ae4266f50055204d640fa3cd251ed1",
"extension": "c",
"filename": "hoge.c",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 365509632,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 622,
"license": "MIT",
"license_type": "permissive",
"path": "/cp0/hoge.c",
"provenance": "stackv2-0087.json.gz:10024",
"repo_name": "jeansblog/ADXL355",
"revision_date": "2021-09-12T14:12:03",
"revision_id": "49c94067f9bcb562c131cde5d1248edf03f6898c",
"snapshot_id": "9374cf287f8af0a13bc72398f544568a96e40f82",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/jeansblog/ADXL355/49c94067f9bcb562c131cde5d1248edf03f6898c/cp0/hoge.c",
"visit_date": "2023-08-03T06:39:51.594061"
} | stackv2 | #include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *print_hello(void *dmy)
{
int i;
for(i = 0; i < 20; i++) {
printf("Hello\n");
usleep(10);
}
return NULL;
}
void *print_world(void *dmy)
{
int i;
for(i = 0; i < 20; i++) {
printf("World\n");
usleep(10);
}
return NULL;
}
int main()
{
pthread_t th;
pthread_create(&th, NULL, &print_hello, NULL);
print_world(NULL);
pthread_join(th, NULL);
return 0;
}
| 2.84375 | 3 |
2024-11-18T22:11:44.089478+00:00 | 2021-03-05T13:16:14 | 5a8f030c0b58866bd1a112b40cf0f244792a778e | {
"blob_id": "5a8f030c0b58866bd1a112b40cf0f244792a778e",
"branch_name": "refs/heads/master",
"committer_date": "2021-03-05T13:16:14",
"content_id": "3deeee957ab36ef74976fab9fea81bc1603d2fab",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "4a31cd19de126d7e057da5ac43fcc1a319164421",
"extension": "c",
"filename": "shield_checks.c",
"fork_events_count": 2,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 250032188,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1121,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/Linux_MacOS/src/fight/shield_checks.c",
"provenance": "stackv2-0087.json.gz:10282",
"repo_name": "Richard-DEPIERRE/MUL_my_rpg_2019",
"revision_date": "2021-03-05T13:16:14",
"revision_id": "a5cdabca710e4ba928a5c31ceedb78030e3e6ec7",
"snapshot_id": "c4bcc02f23b6a11ccb6ad0721054c4788de03344",
"src_encoding": "UTF-8",
"star_events_count": 6,
"url": "https://raw.githubusercontent.com/Richard-DEPIERRE/MUL_my_rpg_2019/a5cdabca710e4ba928a5c31ceedb78030e3e6ec7/Linux_MacOS/src/fight/shield_checks.c",
"visit_date": "2023-03-16T15:22:33.536717"
} | stackv2 | /*
** EPITECH PROJECT, 2020
** Visual Studio Live Share (Workspace)
** File description:
** shield_checks
*/
#include "rpg.h"
void check_touch_ennemie_shield_two(fight_t *fight, rpg_t *rpg, spell_t *spell,
int i)
{
if (fight->enns[i].in_live == 1)
if (spell->pos.x + 30 > fight->enns[i].pos.x - 25 &&
spell->pos.x - 30 < fight->enns[i].pos.x + 25 &&
spell->pos.y + 30 > fight->enns[i].pos.y - 35 &&
spell->pos.y - 30< fight->enns[i].pos.y + 35) {
fight->enns[i].life -= spell->damage;
(fight->enns[i].life <= 0) ? (rpg->quest.scd_quest.nb_kills
+= 1) : (rpg->quest.scd_quest.nb_kills =
rpg->quest.scd_quest.nb_kills);
}
fight->enns[i].buttons[1].rect.width = fight->enns[i].life + 2;
sfSprite_setTextureRect(fight->enns[i].buttons[1].sprite,
fight->enns[i].buttons[1].rect);
}
void check_touch_ennemie_shield(fight_t *fight, rpg_t *rpg, spell_t *spell)
{
for (int i = 0; i < fight->nb_enn; i++) {
check_touch_ennemie_shield_two(fight, rpg, spell, i);
}
shield_damage_enn(fight, rpg, spell);
}
| 2.28125 | 2 |
2024-11-18T22:11:44.226679+00:00 | 2013-12-11T11:02:35 | 526e882a415d6995fcd1340ebd27623099e3be06 | {
"blob_id": "526e882a415d6995fcd1340ebd27623099e3be06",
"branch_name": "refs/heads/master",
"committer_date": "2013-12-11T11:02:35",
"content_id": "843d751ddb3e85412d1ad7bd83b637960c129027",
"detected_licenses": [
"MIT"
],
"directory_id": "bd6f982c9a2cf0785a4f75c85cc1ad258d433795",
"extension": "c",
"filename": "server.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 10419,
"license": "MIT",
"license_type": "permissive",
"path": "/src/server.c",
"provenance": "stackv2-0087.json.gz:10410",
"repo_name": "ntpeters/remoteAdv",
"revision_date": "2013-12-11T11:02:35",
"revision_id": "2a7be2e4e59ae62bf28a4e2d658e0bdb5e51e940",
"snapshot_id": "3a741b255395c57645994b331b68143cf530508a",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/ntpeters/remoteAdv/2a7be2e4e59ae62bf28a4e2d658e0bdb5e51e940/src/server.c",
"visit_date": "2020-05-05T01:51:00.508709"
} | stackv2 | #include "opCodes.h"
#include "sockaddrAL.h"
#include "SimpleLogger/simplog.h"
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <strings.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdarg.h>
#include <getopt.h>
#include <stdbool.h>
/* 141.219.153.205 for wopr */
/* 141.219.153.206 for guardian */
/* 54.214.246.148 for my Amazon EC2 instance */
// Global Variables
int dbgLevel = dbg_verbose;
int server_portnumber = 51739; // Port must be constant due to the nature of this project
char* logFile = "server.log";
char* version = "Development Build";
int silentMode = 0;
// Function Prototypes
void printHelp();
void handleCommand( int command, int connectFD );
// Output is standard out
int main( int argc , char* argv[] ) {
// Handle command line arguments
char* short_options = "d:hl:v";
struct option long_options[] = {
{ "silent", no_argument, &silentMode, 1 },
{ "debug", required_argument, 0, 'd' },
{ "help", no_argument, 0, 'h' },
{ "logfile", required_argument, 0, 'l' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
int longIndex = 0;
// Get first option
char cmdOpt = getopt_long( argc, argv, short_options, long_options, &longIndex );
while( cmdOpt != -1 ) {
switch( cmdOpt ) {
case 'd':
dbgLevel = atoi( optarg );
break;
case 'l':
logFile = optarg;
break;
case 'v':
printf("remoteAdv Version: %s\n", version);
exit(0);
case 'h':
case '?': // Fall-through intentional
printHelp();
exit(0);
default:
break;
}
// Get next option
cmdOpt = getopt_long( argc, argv, short_options, long_options, &longIndex );
}
// Initilize settings based on argument input
setLogDebugLevel( dbgLevel );
setLogFile( logFile );
setLogSilentMode( silentMode );
// Begin setting up server
writeLog( 0, "Starting remoteAdv Server - Version: %s", version );
int listenFD;
int connectFD;
socklen_t length;
struct sockaddr_in s1;
struct sockaddr_in s2;
/* ---- Initialize port and print ---- */
listenFD = socket( AF_INET , SOCK_STREAM , 0 );
if( listenFD == -1 ) {
writeLog( -2, "Open socket failed" );
exit(1);
}
bzero( (char*) &s1 , sizeof( s1 ) ); /* Zero out struct */
s1.sin_family = AF_INET;
s1.sin_addr.s_addr = INADDR_ANY;
s1.sin_port = server_portnumber; /* Assign a port number */
int bindResult = bind( listenFD , (struct sockaddr*) &s1 , sizeof( s1 ) ); /* Bind an availible port to our fd */
if( bindResult == -1 ) {
writeLog( -2, "Bind failed" );
exit(1);
}
length = sizeof( s1 );
getsockname( listenFD , (struct sockaddr*) &s1 , &length );
writeLog( 0, "Listening on port: %d", s1.sin_port ); /* Print the port number */
signal( SIGCHLD , SIG_IGN ); /* So we don't wait on zombies */
int listenResult = listen( listenFD , max_connections ); /* I don't think we'll hit 512 clients.. */
if( listenResult == -1 ) {
writeLog( -2, "Unable to listen" );
exit(1);
}
/* ---- Keep listening for clients ---- */
while(1) {
length = sizeof( s2 );
connectFD = accept( listenFD , (struct sockaddr*) &s2 , &length ); /* Accept connection */
if( connectFD == -1 ) {
writeLog( -1, "Connection to client failed" );
} else {
int client_type = 0;
read( connectFD, &client_type, sizeof( client_type ) );
int response = type_server;
write( connectFD, &response, sizeof( response ) );
addInfo( s2, client_type, connectFD );
writeLog( 3, "Client added. Descriptor: %d", connectFD );
char* list = (char*)malloc(1000);
list = getClientListString( list, sizeof( list ) );
}
if( !fork() ){ /* Create child */
close( listenFD ); /* Close one end of the pipe */
writeLog( 2, "Client connection successful" );
struct client_info client = getClientInfo( getClientListSize() - 1 );
writeLog( 3, "Connected to '%s' client at '%s:%d'", client.type, client.ip, client.port );
int select = 0;
int dataRead = read( connectFD , &select, sizeof( int ) ); // Get the first opcode
OpHeader op;
int command;
while( dataRead ) {
switch( select ) {
case opcode_sent:
read( connectFD, &op, sizeof( op ) );
int connection = getConnection( 0 );
write( connection, &op, sizeof( op ) );
writeLog( 3, "Opcode '%d' sent to slave client", op.opcode );
break;
case command_sent:
read( connectFD, &command, sizeof( command ) );
writeLog( 3, "Recieved command '%d' from master client", command );
handleCommand( command, connectFD );
break;
default:
break;
}
// TODO: send response to client
// Get the next opcode
dataRead = read( connectFD , &select, sizeof( int ) );
} // End of while client actions loop
if( dataRead == -1 ) {
writeLog( 2, "Client connection has been lost");
}
close( connectFD );
deleteInfo( s2 );
writeLog( 3, "Child process is done. PID: %d", getpid() );
exit( 0 ); /* Child exits when done */
}
} // end of while
return 0;
}
/*
Handles printing out the help dialog
*/
void printHelp() {
printf( "remoteAdv Server - %s\n"
"\n"
"Usage:\tserver [arguments]\n"
"\n"
"Arguments:\n"
"\t-d [level]\t\tSets the debug level:\n"
"\t\t\t\t\t0 - No debug output\n"
"\t\t\t\t\t1 - Warnings only (default)\n"
"\t\t\t\t\t2 - Basic debug output\n"
"\t\t\t\t\t3 - Verbose debug output\n"
"\t--debug=[level]\t\tEquivalent to -d\n"
"\t-l [filename]\t\tSets the logfile\n"
"\t--logfile=[filename]\tEquivalent to -l\n"
"\t-h\t\t\tDisplays this dialog\n"
"\t--help\t\t\tEquivalent to -h\n"
"\t--silent\t\tRestricts all output to logs only\n"
"\t-v\t\t\tDisplays the version information of this program\n"
"\t--version\t\tEquivalent to -v\n"
, version );
}
/*
Handles commands sent to the server
Input:
int command - The command to execute
int connectFD - the connection file descriptorto the master client
*/
void handleCommand( int command, int connectFD ) {
char* list = (char*)malloc(1000);
memset( list, 0, 1000 );
switch( command ) {
case c_master_set_dbglvl:
writeLog( 3 , "Setting Debug Level" );
int newDbgValue;
read( connectFD , &newDbgValue , sizeof(newDbgValue) );
// TODO: Set global debug value on parent?
break;
case c_list_slaves:
writeLog( 3, "Sending slave list" );
list = getClientListString( list, sizeof( list ), type_client_slave );
write( connectFD, list, strlen( list ) );
free( list );
break;
case c_claim:
writeLog( 3, "Claiming client" );
int claim_index = -1;
read( connectFD, &claim_index, sizeof( claim_index ) );
int claim_result = claim( claim_index );
if( claim_result == -1 ) {
writeLog( 3, "Claim failed." );
} else {
writeLog( 3, "Claim succeeded." );
}
write( connectFD, &claim_result, sizeof( claim_result ) );
break;
case c_release:
writeLog( 3, "Releasing client" );
int release_index = -1;
read( connectFD, &release_index, sizeof( release_index ) );
int release_result = release( release_index );
if( release_result == -1 ) {
writeLog( 3, "Release failed!" );
} else {
writeLog( 3, "Release of client '%d' successful!", release_index );
}
break;
case c_master_kill_client:
writeLog( 3, "Killing slave" );
OpHeader op = {
.opcode = c_master_kill_client,
};
int kill_index = -1;
read( connectFD, &kill_index, sizeof( kill_index ) );
int kill_fd = getConnection( kill_index );
write( kill_fd , &op, sizeof( op ) );
close( kill_fd );
deleteInfoAtIndex( kill_index );
break;
}
}
| 2.296875 | 2 |
2024-11-18T22:11:44.668071+00:00 | 2017-12-29T07:22:27 | 51715a712517b38d6da364f2b4b0b751cc62e840 | {
"blob_id": "51715a712517b38d6da364f2b4b0b751cc62e840",
"branch_name": "refs/heads/master",
"committer_date": "2017-12-29T07:22:27",
"content_id": "658561cdc50ae4caf189002c3e6ecfa8930e54c9",
"detected_licenses": [
"MIT"
],
"directory_id": "1856e9949bce81cb3abb22716dc9759e72acad73",
"extension": "c",
"filename": "date.c",
"fork_events_count": 0,
"gha_created_at": "2017-12-29T04:15:59",
"gha_event_created_at": "2017-12-29T04:16:00",
"gha_language": null,
"gha_license_id": null,
"github_id": 115685732,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1404,
"license": "MIT",
"license_type": "permissive",
"path": "/date.c",
"provenance": "stackv2-0087.json.gz:10539",
"repo_name": "NePsUKi/xv6-public",
"revision_date": "2017-12-29T07:22:27",
"revision_id": "72ede696b5955759436b1aa5adb004c57676ff3f",
"snapshot_id": "31f5204430a75ae510305fad3cfe4e389bb65e2c",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/NePsUKi/xv6-public/72ede696b5955759436b1aa5adb004c57676ff3f/date.c",
"visit_date": "2021-09-01T23:42:55.550158"
} | stackv2 | #include "types.h"
#include "user.h"
#include "date.h"
#include "stat.h"
#include "fcntl.h"
int date();
int halt();
void periodic();
int
main(int argc, char *argv[])
{
uint temp_second=0, count=0, limit=0;
struct rtcdate r;
int i;
if(date(&r)){
printf(2, "date failed\n");
exit();
}
temp_second=r.second;
printf(1, "%d-%d-%d %d:%d:%d\n", r.year, r.month, r.day, r.hour, r.minute, r. second);
//halt();
if(argc>1)
{
printf(1, "argv: %d\n", atoi(argv[argc-1]));
limit=atoi(argv[1]);
for(i=0;r.second-temp_second<limit;i++)
{
if(date(&r)){
printf(2, "date failed\n");
exit();
}
if(count!=r.second-temp_second)
printf(1, "Count: %d\n", count=r.second-temp_second);
}
}
else
printf(1,"Wrong command: need enter [date number]\n");
printf(1, "%d-%d-%d %d:%d:%d\n", r.year, r.month, r.day, r.hour, r.minute, r. second);
temp_second=r.second;
/*printf(1, "alarmtear starting\n");
alarm(10, periodic);
for(i=0; i < 50*5000000;i++){
if((i++ %5000000)==0)
write(2, ".", 1);
}*/
chpr(atoi(argv[2]), atoi(argv[3]));
cps();
if(date(&r)){
printf(2, "date failed\n");
exit();
}
printf(1, "%d-%d-%d %d:%d:%d\n", r. year, r.month, r.day, r.hour, r.minute, r.second);
printf(1, "Total time: %d\n", r.second-temp_second);
exit();
}
void
periodic()
{
printf(1, "alarm!\n");
}
| 2.453125 | 2 |
2024-11-18T22:11:44.796398+00:00 | 2019-09-16T16:04:14 | 0e0ad5f6433e6848d20087d3bab40404e86c12fc | {
"blob_id": "0e0ad5f6433e6848d20087d3bab40404e86c12fc",
"branch_name": "refs/heads/master",
"committer_date": "2019-09-16T16:04:14",
"content_id": "2befa7640233f9168988d6487c57810887c89197",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "d292cf56667a6ef4027dacffff7a5c805a60a063",
"extension": "c",
"filename": "rlutils_memory.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 207782684,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2834,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/src/memory/rlutils_memory.c",
"provenance": "stackv2-0087.json.gz:10667",
"repo_name": "RedisLabsModules/RLUtils",
"revision_date": "2019-09-16T16:04:14",
"revision_id": "ca1ad7b6d58725e83fa199ea3180a14c78889564",
"snapshot_id": "e868fa51eb0fb3267e842e5a73fd0423056dd107",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/RedisLabsModules/RLUtils/ca1ad7b6d58725e83fa199ea3180a14c78889564/src/memory/rlutils_memory.c",
"visit_date": "2020-07-24T03:04:16.258175"
} | stackv2 | #include "../redismodule.h"
#include "../utils/arr_rm_alloc.h"
#include "rlutils_memory.h"
#include <string.h>
#include <stdarg.h>
#ifdef VALGRIND
#define ALLOC malloc
#define CALLOC calloc
#define REALLOC realloc
#define FREE free
#define STRDUP strdup
#else
#define ALLOC RedisModule_Alloc
#define CALLOC RedisModule_Calloc
#define REALLOC RedisModule_Realloc
#define FREE RedisModule_Free
#define STRDUP RedisModule_Strdup
#endif
void *RLUTILS_PRFX_malloc(size_t n){
return ALLOC(n);
}
void *RLUTILS_PRFX_calloc(size_t nelem, size_t elemsz){
return CALLOC(nelem, elemsz);
}
void *RLUTILS_PRFX_realloc(void *p, size_t n){
return REALLOC(p, n);
}
void RLUTILS_PRFX_free(void *p){
return FREE(p);
}
char *RLUTILS_PRFX_strdup(const char *s){
return STRDUP(s);
}
char *RLUTILS_PRFX_strndup(const char *s, size_t n){
char *ret = (char *)ALLOC(n + 1);
if (ret) {
ret[n] = '\0';
memcpy(ret, s, n);
}
return ret;
}
int RLUTILS_PRFX_vasprintf(char **__restrict __ptr, const char *__restrict __fmt, va_list __arg) {
va_list args_copy;
va_copy(args_copy, __arg);
size_t needed = vsnprintf(NULL, 0, __fmt, __arg) + 1;
*__ptr = (char *)ALLOC(needed);
int res = vsprintf(*__ptr, __fmt, args_copy);
va_end(args_copy);
return res;
}
int RLUTILS_PRFX_asprintf(char **__ptr, const char *__restrict __fmt, ...) {
va_list ap;
va_start(ap, __fmt);
int res = RLUTILS_PRFX_vasprintf(__ptr, __fmt, ap);
va_end(ap);
return res;
}
void RLUTILS_PRFX_MemoryGuardrInit(RLUTILS_PRFX_MemoryGuard* mg){
#define INITIAL_CAP 10
mg->units = array_new(RLUTILS_PRFX_GuardUnit, INITIAL_CAP);
}
void RLUTILS_PRFX_MemoryGuardFreeUnits(RLUTILS_PRFX_MemoryGuard* mg){
for(size_t i = 0 ; i < array_len(mg->units) ; ++i){
RLUTILS_PRFX_GuardUnit* unit = mg->units + i;
unit->freeFunc(unit->ptr);
}
}
void RLUTILS_PRFX_MemoryGuardFreeStructure(RLUTILS_PRFX_MemoryGuard* mg){
array_free(mg->units);
}
void RLUTILS_PRFX_MemoryGuardFree(RLUTILS_PRFX_MemoryGuard* mg){
RLUTILS_PRFX_MemoryGuardFreeUnits(mg);
RLUTILS_PRFX_MemoryGuardFreeStructure(mg);
}
void RLUTILS_PRFX_MemoryGuardAddUnit(RLUTILS_PRFX_MemoryGuard* mg, RLUTILS_PRFX_GuardUnit unit){
mg->units = array_append(mg->units, unit);
}
void RLUTILS_PRFX_MemoryGuardAddPtr(RLUTILS_PRFX_MemoryGuard* mg, void* ptr){
RLUTILS_PRFX_MemoryGuardAddUnit(mg, (RLUTILS_PRFX_GuardUnit){
.ptr = ptr,
.freeFunc = free,
});
}
static void FreeRedisModuleString(void* ptr){
RedisModule_FreeString(NULL, ptr);
}
void RLUTILS_PRFX_MemoryGuardAddRedisString(RLUTILS_PRFX_MemoryGuard* mg, RedisModuleString* ptr){
RLUTILS_PRFX_MemoryGuardAddUnit(mg, (RLUTILS_PRFX_GuardUnit){
.ptr = ptr,
.freeFunc = FreeRedisModuleString,
});
}
| 2.515625 | 3 |
2024-11-18T22:11:46.561058+00:00 | 2017-06-08T19:31:23 | b64610484be3ca1ccb063f056a4beeb928f505e7 | {
"blob_id": "b64610484be3ca1ccb063f056a4beeb928f505e7",
"branch_name": "refs/heads/master",
"committer_date": "2017-06-08T19:31:23",
"content_id": "a532cea2e3df1e27c0bc06a0aac37af51a7eded8",
"detected_licenses": [
"Unlicense"
],
"directory_id": "6eeb914e5b7d959d9bceb33d1271a2a70a2a5447",
"extension": "h",
"filename": "km_gg.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 76954844,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 8323,
"license": "Unlicense",
"license_type": "permissive",
"path": "/km_gg.h",
"provenance": "stackv2-0087.json.gz:10796",
"repo_name": "byllgrim/km",
"revision_date": "2017-06-08T19:31:23",
"revision_id": "a390387aaf3e8fe7c555c5a30450c77052d4ab39",
"snapshot_id": "aea93fd1fa5d91b5e392c50cce88e0b6fe243982",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/byllgrim/km/a390387aaf3e8fe7c555c5a30450c77052d4ab39/km_gg.h",
"visit_date": "2021-01-13T02:45:25.694024"
} | stackv2 | /***************************************************************************//**
* @file km_gg.h
* @brief Settings regarding pin numbering etc.
******************************************************************************/
#ifndef SRC_KM_GG_H_
#define SRC_KM_GG_H_
#include "em_gpio.h"
/* TODO Rename file? */
/**
* Refer to the schematics at github.com/byllgrim/km
*
* Upper row pins
* 5V PB10 PB9 GND PB11 PB12 PD15 GND PD0 PD1 PD2 ...
* R7 R5 R3 R1 R6 R4 R2 R0
*/
enum {
NUM_ROWS = 8,
NUM_COLS = 8,
}; /* TODO Use short enums. */
const GPIO_Port_TypeDef row_port[NUM_ROWS] =
{
gpioPortD, //R0 Reds are even
gpioPortB, //R1 Blues are odd
gpioPortD, //R2
gpioPortB, //R3
gpioPortD, //R4
gpioPortB, //R5
gpioPortD, //R6
gpioPortB, //R7
};
const unsigned int row_pin[NUM_ROWS] =
{
2, //R0
12, //R1
1, //R2
11, //R3
0, //R4
9, //R5
15, //R6
10, //R7
};
/**
* Bottom row pins
* 5V PA12 PA13 PA14 GND PE0 PE1 PE2 PE3 GND PC0 ...
* C0 C1 C2 C3 C4 C5 C6 C7
*/
const GPIO_Port_TypeDef col_port[NUM_COLS] =
{
gpioPortA, //C0
gpioPortA, //C1
gpioPortA, //C2
gpioPortE, //C3
gpioPortE, //C4
gpioPortE, //C5
gpioPortE, //C6
gpioPortC, //C7
};
const unsigned int col_pin[NUM_COLS] =
{
12, //C0
13, //C1
14, //C2
0, //C3
1, //C4
2, //C5
3, //C6
0, //C7
};
typedef enum {
/* TODO More descriptive naming. */
/* TODO Write in hex? */
MK_LC = 1 << 0 << 8, /* Left ctrl. */
MK_LS = 1 << 1 << 8, /* Left shift. */
MK_LA = 1 << 2 << 8, /* Left alt. */
MK_LG = 1 << 3 << 8, /* Left gui (e.g. win key og cmd). */
MK_RC = 1 << 4 << 8, /* Right ctrl. */
MK_RS = 1 << 5 << 8, /* Right shift. */
MK_RA = 1 << 6 << 8, /* Right alt. */
MK_RG = 1 << 7 << 8, /* Right gui. */
} ModifierKeys_TypeDef;
/* TODO KeyCode in the format uint16_t {modifier, keycode}? */
/* TODO typedef or struct the uint16_t format? */
typedef enum {
/* TODO
* TODO Better naming.
* TODO Correct order.
* TODO Correct all 0 values.
* TODO Align assignments?
*/
KC_OOB = 0, /* Out-Off-Bounds are non-existent keys. See schematics. */
KC_NIU = 0, /* Not-In-Use is non-qwerty extra buttons. */
KC_A = 0x04,
KC_B,
KC_C,
KC_D,
KC_E,
KC_F,
KC_G,
KC_H,
KC_I,
KC_J,
KC_K,
KC_L,
KC_M,
KC_N,
KC_O,
KC_P,
KC_Q,
KC_R,
KC_S,
KC_T,
KC_U,
KC_V,
KC_W,
KC_X,
KC_Y,
KC_Z,
//TODO missing pieces
KC_TAB = 0x2B,
KC_BACK = 0x2A, /* Backspace. TODO KC_BS? */
KC_ESC = 0x29,
KC_SEM = 0x33, /* Semicolon. */
KC_AP = 0x34, /* Apostrophe. */
KC_SH = 0 | MK_LS, /* Shift. */
KC_CM = 0x36, /* Comma. */
KC_PR = 0x37, /* Period. */
KC_FR = 0x38, /* Forward slash. */
KC_ENT = 0x28, /* Enter. */
KC_BL = 0, /* TODO BL is special to Planck. */
KC_CT = 0 | MK_LC, /* Ctrl. */
KC_AL = 0 | MK_LA, /* Alt. */
KC_OS = 0 | MK_LG, /* OS key (left gui) e.g. win key */
KC_LW = 0, /* TODO Lower is special. */
KC_SP = 0x2C, /* Space. */
KC_RS = 0, /* TODO Raise is special. */
KC_LE = 0x50, /* Left arrow key. */
KC_DO = 0x51, /* Down arrow key. */
KC_UP = 0x52, /* Up arrow key. */
KC_RI = 0x4F, /* Right arrow key */
KC_GA = 0x35,/* Grave accent. */
KC_DEL = 0x2A, /* Delete. */
KC_1 = 0x1E,
KC_2,
KC_3,
KC_4,
KC_5,
KC_6,
KC_7,
KC_8,
KC_9,
KC_0,
KC_F1 = 0x3A,
KC_F2,
KC_F3,
KC_F4,
KC_F5,
KC_F6,
KC_F7,
KC_F8,
KC_F9,
KC_F10,
KC_F11,
KC_F12,
KC_MIN = 0x2D, /* Minus '-'. */
KC_EQ = 0x2E, /* Equal '='. */
KC_SL = 0x2F, /* Square bracket Left. */
KC_SR = 0x30, /* Square bracket Right. */
KC_BS = 0x31, /* BackSlash. */
KC_NX = 0, /* TODO Music NeXt track! */
KC_VM = 0x81, /* Volume minus. TODO Rename Volume Down? */
KC_VP = 0x80, /* Volume plus. */
KC_PL = 0,/* TODO Music play. */
KC_TLD = KC_GA | MK_LS, /* Tilde. */
KC_XM = KC_1 | MK_LS, /* Exclamation mark. */
KC_AT, /* '@'. */
KC_HSH, /* Hash tag. */
KC_DL, /* Dollar sign. */
KC_PC, /* Percentage. */
KC_PW, /* Power '^'. */
KC_AM, /* Ampersand. */
KC_AS, /* Asterisk. */
KC_LP, /* Left parentheses. */
KC_RP, /* Right parentheses. */
KC_UN = KC_MIN | MK_LS, /* Underscore. */
KC_AD = KC_EQ | MK_LS, /* Addition '+'. */
KC_LB = KC_SL | MK_LS, /* Left braces '{' */
KC_RB = KC_SR | MK_LS, /* Right braces '}'. */
KC_PP = KC_BS | MK_LS, /* Pipe '|'. */
} KeyCode_TypeDef;
/* TODO Comment all keycodes with '/' ascii symbol. */
static const uint32_t TIMER_ID = 1; /* Timer used to scan keyboard. */
static const uint32_t TIMER_TIMEOUT = 50; /* Milliseconds to elapse. TODO 50? */
enum {ROLLOVER = 6}; /* Max simultaneous keypress. TODO rename NKEY_... */
enum {
NUM_LAYERS = 4, /* TODO Necessary? */
LAYER_NORMAL = 0, /* TODO LAYER_QWERTY? */
LAYER_LOWER = 1,
LAYER_RAISE = 2,
LAYER_ADJUST = LAYER_LOWER + LAYER_RAISE
/* Keymap index adds to 0, 1, 2, 3 for normal, lower, raise, adjust */
}; /* Planck lower/raise layers. */
/* TODO Move placement of these definitions. */
/* The keymap is based on Planck OLKB default keymap v4.0. */
const uint16_t keyMaps[NUM_LAYERS][NUM_ROWS][NUM_COLS] = {
[LAYER_NORMAL] =
{
/*C0 C0 C1 C1 C2 C2 C3 C3 C4 C4 C5 C5 C6 C6 C7 C7*/
{KC_OOB, KC_TAB, KC_W, KC_R, KC_Y, KC_I, KC_P, KC_NIU},
{KC_NIU, KC_Q, KC_E, KC_T, KC_U, KC_O, KC_BACK, KC_OOB},
{KC_OOB, KC_ESC, KC_S, KC_F, KC_H, KC_K, KC_SEM, KC_NIU},
{KC_NIU, KC_A, KC_D, KC_G, KC_J, KC_L, KC_AP, KC_OOB},
{KC_OOB, KC_SH, KC_X, KC_V, KC_N, KC_CM, KC_FR, KC_NIU},
{KC_NIU, KC_Z, KC_C, KC_B, KC_M, KC_PR, KC_ENT, KC_OOB},
{KC_OOB, KC_BL, KC_AL, KC_LW, KC_SP, KC_LE, KC_UP, KC_NIU},
{KC_NIU, KC_CT, KC_OS, KC_SP, KC_RS, KC_DO, KC_RI, KC_OOB},
},
/* Note that the row layout is weird. Consult the schematics. */
[LAYER_LOWER] =
{
/*C0 C0 C1 C1 C2 C2 C3 C3 C4 C4 C5 C5 C6 C6 C7 C7*/
{KC_OOB, KC_TLD, KC_AT, KC_DL, KC_PW, KC_AS, KC_RP, KC_NIU},
{KC_NIU, KC_XM, KC_HSH, KC_PC, KC_AM, KC_LP, 0, KC_OOB},
{KC_OOB, KC_DEL, KC_F2, KC_F4, KC_F6, KC_AD, KC_RB, KC_NIU},
{KC_NIU, KC_F1, KC_F3, KC_F5, KC_UN, KC_LB, KC_PP, KC_OOB},
{KC_OOB, 0, KC_F8, KC_F10, KC_F12, 0, 0, KC_NIU},
{KC_NIU, KC_F7, KC_F9, KC_F11, 0, 0, 0, KC_OOB},
{KC_OOB, 0, 0, 0, KC_SP, KC_NX, KC_VP, KC_NIU},
{KC_NIU, 0, 0, KC_SP, 0, KC_VM, KC_PL, KC_OOB},
},
[LAYER_RAISE] =
{
/*C0 C0 C1 C1 C2 C2 C3 C3 C4 C4 C5 C5 C6 C6 C7 C7*/
{KC_OOB, KC_GA, KC_2, KC_4, KC_6, KC_8, KC_0, KC_NIU},
{KC_NIU, KC_1, KC_3, KC_5, KC_7, KC_9, 0, KC_OOB},
{KC_OOB, KC_DEL, KC_F2, KC_F4, KC_F6, KC_EQ, KC_SR, KC_NIU},
{KC_NIU, KC_F1, KC_F3, KC_F5, KC_MIN, KC_SL, KC_BS, KC_OOB},
{KC_OOB, 0, KC_F8, KC_F10, KC_F12, 0, 0, KC_NIU},
{KC_NIU, KC_F7, KC_F9, KC_F11, 0, 0, 0, KC_OOB},
{KC_OOB, 0, 0, 0, KC_SP, KC_NX, KC_VP, KC_NIU},
{KC_NIU, 0, 0, KC_SP, 0, KC_VM, KC_PL, KC_OOB},
},
/* TODO KC_RA = 0 for raise, lower etc? */
[LAYER_ADJUST] = /* TODO Fill in the adjust layer? */
{
/*C0 C0 C1 C1 C2 C2 C3 C3 C4 C4 C5 C5 C6 C6 C7 C7*/
{KC_OOB, 0, 0, 0, 0, 0, 0, KC_NIU},
{KC_NIU, 0, 0, 0, 0, 0, 0, KC_OOB},
{KC_OOB, 0, 0, 0, 0, 0, 0, KC_NIU},
{KC_NIU, 0, 0, 0, 0, 0, 0, KC_OOB},
{KC_OOB, 0, 0, 0, 0, 0, 0, KC_NIU},
{KC_NIU, 0, 0, 0, 0, 0, 0, KC_OOB},
{KC_OOB, 0, 0, 0, 0, 0, 0, KC_NIU},
{KC_NIU, 0, 0, 0, 0, 0, 0, KC_OOB},
},
};
/* TODO Sort this file. */
#endif /* SRC_KM_GG_H_ */
| 2.21875 | 2 |
2024-11-18T22:11:51.693770+00:00 | 2019-01-09T21:54:35 | c673882b7d4ea35dba74c0e18fb9f11d72cffbb3 | {
"blob_id": "c673882b7d4ea35dba74c0e18fb9f11d72cffbb3",
"branch_name": "refs/heads/master",
"committer_date": "2019-01-09T21:54:35",
"content_id": "af3ff72faf9588126fb269b0e9080357c32b5fcb",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "b107d7f73326f8725e08023c5da3e5082535ca85",
"extension": "c",
"filename": "tst-strftime.c",
"fork_events_count": 0,
"gha_created_at": "2019-02-02T05:07:44",
"gha_event_created_at": "2019-02-02T05:07:45",
"gha_language": null,
"gha_license_id": "Apache-2.0",
"github_id": 168796582,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3240,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/include/glibc-time/tst-strftime.c",
"provenance": "stackv2-0087.json.gz:11442",
"repo_name": "DalavanCloud/libucresolv",
"revision_date": "2019-01-09T21:54:35",
"revision_id": "04a4827aa44c47556f425a4eed5e0ab4a5c0d25a",
"snapshot_id": "2073188dd95503447bcbea16fa43bd938112712b",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/DalavanCloud/libucresolv/04a4827aa44c47556f425a4eed5e0ab4a5c0d25a/include/glibc-time/tst-strftime.c",
"visit_date": "2020-04-20T10:42:52.062948"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
static int
do_bz18985 (void)
{
char buf[1000];
struct tm ttm;
int rc, ret = 0;
memset (&ttm, 1, sizeof (ttm));
ttm.tm_zone = NULL; /* Dereferenced directly if non-NULL. */
rc = strftime (buf, sizeof (buf), "%a %A %b %B %c %z %Z", &ttm);
if (rc == 66)
{
const char expected[]
= "? ? ? ? ? ? 16843009 16843009:16843009:16843009 16844909 +467836 ?";
if (0 != strcmp (buf, expected))
{
printf ("expected:\n %s\ngot:\n %s\n", expected, buf);
ret += 1;
}
}
else
{
printf ("expected 66, got %d\n", rc);
ret += 1;
}
/* Check negative values as well. */
memset (&ttm, 0xFF, sizeof (ttm));
ttm.tm_zone = NULL; /* Dereferenced directly if non-NULL. */
rc = strftime (buf, sizeof (buf), "%a %A %b %B %c %z %Z", &ttm);
if (rc == 30)
{
const char expected[] = "? ? ? ? ? ? -1 -1:-1:-1 1899 ";
if (0 != strcmp (buf, expected))
{
printf ("expected:\n %s\ngot:\n %s\n", expected, buf);
ret += 1;
}
}
else
{
printf ("expected 30, got %d\n", rc);
ret += 1;
}
return ret;
}
static struct
{
const char *fmt;
size_t min;
size_t max;
} tests[] =
{
{ "%2000Y", 2000, 4000 },
{ "%02000Y", 2000, 4000 },
{ "%_2000Y", 2000, 4000 },
{ "%-2000Y", 2000, 4000 },
};
#define ntests (sizeof (tests) / sizeof (tests[0]))
static int
do_test (void)
{
size_t cnt;
int result = 0;
time_t tnow = time (NULL);
struct tm *now = localtime (&tnow);
for (cnt = 0; cnt < ntests; ++cnt)
{
size_t size = 0;
int res;
char *buf = NULL;
do
{
size += 500;
buf = (char *) realloc (buf, size);
if (buf == NULL)
{
puts ("out of memory");
exit (1);
}
res = strftime (buf, size, tests[cnt].fmt, now);
if (res != 0)
break;
}
while (size < tests[cnt].max);
if (res == 0)
{
printf ("%Zu: %s: res == 0 despite size == %Zu\n",
cnt, tests[cnt].fmt, size);
result = 1;
}
else if (size < tests[cnt].min)
{
printf ("%Zu: %s: size == %Zu was enough\n",
cnt, tests[cnt].fmt, size);
result = 1;
}
else
printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size);
free (buf);
}
struct tm ttm =
{
/* Initialize the fields which are needed in the tests. */
.tm_mday = 1,
.tm_hour = 2
};
const struct
{
const char *fmt;
const char *exp;
size_t n;
} ftests[] =
{
{ "%-e", "1", 1 },
{ "%-k", "2", 1 },
{ "%-l", "2", 1 },
};
#define nftests (sizeof (ftests) / sizeof (ftests[0]))
for (cnt = 0; cnt < nftests; ++cnt)
{
char buf[100];
size_t r = strftime (buf, sizeof (buf), ftests[cnt].fmt, &ttm);
if (r != ftests[cnt].n)
{
printf ("strftime(\"%s\") returned %zu not %zu\n",
ftests[cnt].fmt, r, ftests[cnt].n);
result = 1;
}
if (strcmp (buf, ftests[cnt].exp) != 0)
{
printf ("strftime(\"%s\") produced \"%s\" not \"%s\"\n",
ftests[cnt].fmt, buf, ftests[cnt].exp);
result = 1;
}
}
return result + do_bz18985 ();
}
#define TEST_FUNCTION do_test ()
#include "../test-skeleton.c"
| 2.734375 | 3 |
2024-11-18T22:11:51.891347+00:00 | 2019-01-11T22:12:21 | e8c1bd3acb5408b9e91a05ccd364cd8c4b1b9062 | {
"blob_id": "e8c1bd3acb5408b9e91a05ccd364cd8c4b1b9062",
"branch_name": "refs/heads/master",
"committer_date": "2019-01-11T22:12:21",
"content_id": "629d45d61061b1739083af3fdf680466c867d786",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "af4ee28eb323e75c47c396e7efe9e982a4c6de68",
"extension": "c",
"filename": "streamFraming.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 162578663,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2760,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/streamFraming.c",
"provenance": "stackv2-0087.json.gz:11571",
"repo_name": "djtremolo/thermit",
"revision_date": "2019-01-11T22:12:21",
"revision_id": "98919986fb8d030c60df304b59c86ace72389296",
"snapshot_id": "e935c92ccccb6eef18866792787479499d4952e9",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/djtremolo/thermit/98919986fb8d030c60df304b59c86ace72389296/streamFraming.c",
"visit_date": "2020-04-12T16:46:01.995905"
} | stackv2 | #include <stdio.h>
#include <string.h>
#include "streamFraming.h"
#include "crc.h"
#define THERMIT_MAX_PAYLOAD_LENGTH 112
/*
Where packet-aware transfer mechanism is not used, the
start/stop bytes are used to recognize the frame:
[ A5 | A5 | thermit frame | 5A | 5A ]
thermit frame:
[ FCode | RecFileID | RecFeedback | SendFileID | SendChunkNo | PayloadLength | Payload | CRC (16bit) ]
The start/stop bytes are dropped and only the thermit
frame is given to the protocol.
*/
void streamFramingFollow(streamFraming_t *frame, uint8_t inByte)
{
bool error = true;
//printf("rec: %02X\r\n", inByte);
switch (frame->state)
{
case MSG_STATE_START:
if (inByte == START_CHAR)
{
if (--(frame->stateRoundsLeft) == 0)
{
/*last round -> advance to next state*/
frame->state = MSG_STATE_HEADER;
frame->stateRoundsLeft = 5;
}
error = false;
}
break;
case MSG_STATE_HEADER:
frame->buf[frame->len++] = inByte;
if (--(frame->stateRoundsLeft) == 0)
{
/*advance to next state*/
frame->state = MSG_STATE_LEN;
frame->stateRoundsLeft = 1;
}
error = false;
break;
case MSG_STATE_LEN:
frame->buf[frame->len++] = inByte;
if (--(frame->stateRoundsLeft) == 0)
{
if(inByte < THERMIT_MAX_PAYLOAD_LENGTH)
{
/*advance to next state*/
frame->state = MSG_STATE_PAYLOAD_AND_CRC;
frame->stateRoundsLeft = inByte + 2; /*payload+crc*/
}
}
error = false;
break;
case MSG_STATE_PAYLOAD_AND_CRC:
/*note: we don't check CRC here. The protocol handler will check it anyway.*/
frame->buf[frame->len++] = inByte;
if (--(frame->stateRoundsLeft) == 0)
{
/*advance to next state*/
frame->state = MSG_STATE_STOP;
frame->stateRoundsLeft = 2;
}
error = false;
break;
case MSG_STATE_STOP:
if (inByte == STOP_CHAR)
{
if (--(frame->stateRoundsLeft) == 0)
{
/*last round -> advance to next state*/
frame->state = MSG_STATE_FINISHED;
/*no stateRoundsLeft needed for this state*/
/*mark frame ready to be sent to ControlTask*/
frame->isReady = true;
}
error = false;
}
break;
case MSG_STATE_FINISHED:
/*idle... we shouldn't get here at anytime, but it wouldn't be an error.
We just drop all the bytes.*/
error = false;
break;
default:
/*out of sync*/
break;
}
if (error)
{
/*restart listening from start*/
streamFramingInitialize(frame);
}
}
void streamFramingInitialize(streamFraming_t *frame)
{
memset(frame, 0, sizeof(streamFraming_t));
frame->state = MSG_STATE_START;
frame->stateRoundsLeft = 2;
}
| 2.828125 | 3 |
2024-11-18T22:11:51.960970+00:00 | 2015-06-01T23:28:49 | 2d3b612aa7b654e7afb7e9fb3b15f20889bcec24 | {
"blob_id": "2d3b612aa7b654e7afb7e9fb3b15f20889bcec24",
"branch_name": "refs/heads/master",
"committer_date": "2015-06-01T23:28:49",
"content_id": "6829d6ef8e744e398f74008790e2635790896926",
"detected_licenses": [
"MIT"
],
"directory_id": "c95ebd5158dc9cdbb566faf8f91c4c8ae961bed3",
"extension": "h",
"filename": "pmm.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 29497217,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3222,
"license": "MIT",
"license_type": "permissive",
"path": "/src/include/sys/pmm.h",
"provenance": "stackv2-0087.json.gz:11699",
"repo_name": "rstenvi/frod",
"revision_date": "2015-06-01T23:28:49",
"revision_id": "c36eb56072b565ec4f4038f092cf2088cdc10d7e",
"snapshot_id": "6e8f9a69cb1884637241694d2cedcf31f48895a3",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/rstenvi/frod/c36eb56072b565ec4f4038f092cf2088cdc10d7e/src/include/sys/pmm.h",
"visit_date": "2016-09-05T17:55:41.079550"
} | stackv2 | /**
* \ingroup pmm
* \file pmm.h
* Header file for the physical memory manager.
* About the physical memory manager:
* - The implementation uses a bitmap to store free or taken blocks.
* - Each bit represents 4KB of memory, this is chosen to coincide with the size
* of pages in virtual memory, which is eventually used.
* - Initialize the system:
* - The system is first initialized with memory map from Grub, here the
* manager finds out how much space it need to store the bitmap.
* - The bitmap is stored on the first available space that is large enough.
* - Memory map does not say where our code is located, so this is marked
* seperately.
* - Virtual memory manager can allocate and free blocks as desired, both single
* and several consecutive blocks.
* \todo Store last block allocated / last freed block to make it faster to find
* available blocks.
* \remark There is no way to move physical memory around, so closing small holes
* to create larger gaps has not been implemented. Since paging is used, it
* should not be necessary, the kernel should instead pre-allocate some continous
* memory for when that is necessary (DMA).
*/
/**
* \addtogroup pmm
* @{
*/
#ifndef __PMM_H
#define __PMM_H
#include "kernel.h"
#include "multiboot1.h"
/**
* Initialize the physical memory manager. This should of course be called early
* in the process and prefereably before paging is enabled. It assumes it is
* working with physical memory and the bitmap can be placed anywhere, but is
* placed at the earliest place possible, i.e. where it will find enough
* consecutive blocks to store the bitmap.
* \param[in] mmap Mmap we get from Grub.
* \param[in] len Length of the mmap structure, also from Grub
* \returns Returns the highest available address / number of bytes we manage
* with our bitmap.
* \remark After this paging can be enabled, but the area containing the bitmap
* must be identity mapped.
* \todo
* - Clean up and divide into internal functions
*/
uint32_t init_pmm(multiboot_mmap* mmap, uint32_t len);
/**
* Find, allocate and return the first avaiable block of memory. This can be
* called whenever you need 1 block of memory.
* \remark Only the virtual memory manager should call this as this is physical
* memory.
* \return Returns the address to the block.
* \todo
* - Will have very low speed after a while, should at least check whole byte
* first
*/
void* pmm_alloc_first();
void* pmm_alloc_first_n_blocks(uint32_t n);
/**
* Mark region of memory as taken.
* \param[in] start Start address of memory region. Will be aligned downwards.
* \param[in] end End address of memory region. Will be aligned upwards.
*/
void pmm_mark_mem_taken(uint32_t start, uint32_t end);
/**
* Free a block of memory. Free a block that has been previously allocated with
* pmm_alloc_first.
* \param[in] block Address of the block, should be aligned on 4 KB boundary.
* \remark The address is aligned downwards and if the block is already free,
* nothing happens.
*/
void pmm_free(void* block);
/**
* Check if a block is taken.
* \param[in] block The block number.
* \return Returns true if it is taken, false if it is free.
*/
bool pmm_is_taken(uint32_t block);
#endif // File
/** @} */ // pmm
| 2.625 | 3 |
2024-11-18T22:11:54.472968+00:00 | 2021-06-19T16:08:11 | 21de3ac209284c26be13dee8575d0dfc340b6a81 | {
"blob_id": "21de3ac209284c26be13dee8575d0dfc340b6a81",
"branch_name": "refs/heads/master",
"committer_date": "2021-06-19T16:08:11",
"content_id": "75636cc775ba4cbf607249c7ce1433d7441b3edb",
"detected_licenses": [
"MIT"
],
"directory_id": "e9d311105459149570ce960ed900a6b2b26899e9",
"extension": "h",
"filename": "RH_color.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 359159943,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 13439,
"license": "MIT",
"license_type": "permissive",
"path": "/core/RH_color.h",
"provenance": "stackv2-0087.json.gz:11955",
"repo_name": "RandleH/SmartPi",
"revision_date": "2021-06-19T16:08:11",
"revision_id": "60bc8d55c7dbd13040acd074188f9a7cefae96ce",
"snapshot_id": "f0f7ca624d25f26277df436e0c5fff02db4512b5",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/RandleH/SmartPi/60bc8d55c7dbd13040acd074188f9a7cefae96ce/core/RH_color.h",
"visit_date": "2023-06-06T02:11:09.937468"
} | stackv2 | #ifndef _RH_COLOR_H
#define _RH_COLOR_H
#include "RH_common.h"
#include "RH_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#if ( RH_CFG_GRAPHIC_COLOR_TYPE == RH_CFG_GRAPHIC_COLOR_BIN )
#define REVERSE_COLOR( M_COLOR ) (((M_COLOR)==0)?(0xff):(0x00))
#define MAKE_COLOR(R_255,G_255,B_255) (uint8_t)(((R_255+G_255+B_255)/3 > 128)?0xff:0x00)
#define COLOR_MASK_RED 0x01
#define COLOR_MASK_GREEN 0x01
#define COLOR_MASK_BLUE 0x01
#define DARKEN_COLOR_1Bit(C) (uint8_t)((C)&0)
#define DARKEN_COLOR_2Bit(C) (uint8_t)((C)&0)
#elif ( RH_CFG_GRAPHIC_COLOR_TYPE == RH_CFG_GRAPHIC_COLOR_RGB565 )
#define MAKE_COLOR(R_255,G_255,B_255) (uint16_t)(((R_255>>3)<<11)|((G_255>>2)<<5)|(B_255>>3))
#define COLOR_MASK_RED 0xF800
#define COLOR_MASK_GREEN 0x7E00
#define COLOR_MASK_BLUE 0x001F
#define REVERSE_COLOR( M_COLOR ) (uint16_t)( (0xF800-(M_COLOR)&(0xF800)) | (0x7E00-(M_COLOR)&(0x7E00)) | (0x001F-(M_COLOR)&0x001F) )
#define DARKEN_COLOR_1Bit(C) (uint16_t)( ((((C)&COLOR_MASK_RED)>>1)&(COLOR_MASK_RED))|((((C)&COLOR_MASK_GREEN)>>1)&(COLOR_MASK_GREEN))|((((C)&COLOR_MASK_BLUE)>>1)&(COLOR_MASK_BLUE)) )
#define DARKEN_COLOR_2Bit(C) (uint16_t)( ((((C)&COLOR_MASK_RED)>>2)&(COLOR_MASK_RED))|((((C)&COLOR_MASK_GREEN)>>2)&(COLOR_MASK_GREEN))|((((C)&COLOR_MASK_BLUE)>>2)&(COLOR_MASK_BLUE)) )
#elif ( RH_CFG_GRAPHIC_COLOR_TYPE == RH_CFG_GRAPHIC_COLOR_RGB888 )
#define MAKE_COLOR(R_255,G_255,B_255) (uint32_t)((((R_255)&0xff)<<16)|(((G_255)&0xff)<<8)|((B_255)&0xff))
#define COLOR_MASK_RED 0x00FF0000
#define COLOR_MASK_GREEN 0x0000FF00
#define COLOR_MASK_BLUE 0x000000FF
#define REVERSE_COLOR( M_COLOR ) (uint32_t)( (0x00FF0000-(M_COLOR)&(0x00FF0000)) | (0x0000FF00-(M_COLOR)&(0x0000FF00)) | (0x000000FF-(M_COLOR)&0x000000FF) )
#define DARKEN_COLOR_1Bit(C) (uint32_t)( ((((C)&COLOR_MASK_RED)>>1)&(COLOR_MASK_RED))|((((C)&COLOR_MASK_GREEN)>>1)&(COLOR_MASK_GREEN))|((((C)&COLOR_MASK_BLUE)>>1)&(COLOR_MASK_BLUE)) )
#define DARKEN_COLOR_2Bit(C) (uint32_t)( ((((C)&COLOR_MASK_RED)>>2)&(COLOR_MASK_RED))|((((C)&COLOR_MASK_GREEN)>>2)&(COLOR_MASK_GREEN))|((((C)&COLOR_MASK_BLUE)>>2)&(COLOR_MASK_BLUE)) )
#else
#error "[RH_color]: Unknown color type."
#endif
// Standard
#define M_COLOR_WHITE (MAKE_COLOR(255,255,255)) // 白色
#define M_COLOR_BLACK (MAKE_COLOR( 0, 0, 0)) // 黑色
#define M_COLOR_BLUE (MAKE_COLOR( 0, 0,255)) // 蓝色
#define M_COLOR_RED (MAKE_COLOR(255, 0, 0)) // 红色
#define M_COLOR_GREEN (MAKE_COLOR( 0,255, 0)) // 绿色
#define M_COLOR_YELLOW (MAKE_COLOR(255,255, 0)) // 黄色
#define M_COLOR_CYAN (MAKE_COLOR( 0,255,255)) // 青色
#define M_COLOR_MAGENTA (MAKE_COLOR(255, 0,255)) // 洋紫
// Red-Blue Series
#define M_COLOR_PINK (MAKE_COLOR(255,192,203)) // 粉红
#define M_COLOR_CRIMSON (MAKE_COLOR(220, 20, 60)) // 猩红
#define M_COLOR_LAVENDERBLUSH (MAKE_COLOR(255,240,245)) // 苍白紫罗兰红
#define M_COLOR_PALEVIOLATRED (MAKE_COLOR(219,112,147)) // 羞涩淡紫红
#define M_COLOR_HOTPINK (MAKE_COLOR(255,105,180)) // 热情粉红
#define M_COLOR_MEDIUMVIOLATRED (MAKE_COLOR(199, 21,133)) // 适中紫罗兰
#define M_COLOR_ORCHID (MAKE_COLOR(218,112,214)) // 兰花紫
#define M_COLOR_THISTLE (MAKE_COLOR(216,191,216)) // 苍紫
#define M_COLOR_PLUM (MAKE_COLOR(221,160,221)) // 轻紫
#define M_COLOR_VOILET (MAKE_COLOR(218,112,214)) // 紫罗兰
#define M_COLOR_DARKVOILET (MAKE_COLOR(255, 0,255)) // 紫红
#define M_COLOR_PURPLE (MAKE_COLOR(128, 0,128)) // 紫
#define M_COLOR_MEDIUMORCHID (MAKE_COLOR(255, 0,255)) // 适中兰花紫
#define M_COLOR_DARKVIOLET (MAKE_COLOR(148, 0,211)) // 深紫罗兰
#define M_COLOR_INDIGO (MAKE_COLOR( 75, 0,130)) // 靓青
#define M_COLOR_BLUEVIOLET (MAKE_COLOR(138, 43,226)) // 蓝紫罗兰
#define M_COLOR_MEDIUMPURPLE (MAKE_COLOR(147,112,219)) // 适中紫
#define M_COLOR_MEDIUMSLATEBLUE (MAKE_COLOR(123,104,238)) // 适中板岩蓝
#define M_COLOR_SLATEBLUE (MAKE_COLOR(106, 90,205)) // 板岩蓝
#define M_COLOR_DARKSLATEBLUE (MAKE_COLOR( 72, 61,139)) // 深板岩蓝
#define M_COLOR_LAVENDER (MAKE_COLOR(230,230,250)) // 薰衣草淡
#define M_COLOR_GHOSTWHITE (MAKE_COLOR(248,248,255)) // 幽灵白
// Blue-Green Series
#define M_COLOR_MEDIUMBLUE (MAKE_COLOR( 0, 0,205)) // 适中蓝
#define M_COLOR_MIDNIGHTBLUE (MAKE_COLOR( 25, 25,112)) // 午夜蓝
#define M_COLOR_DARKBLUE (MAKE_COLOR( 0, 0,139)) // 深蓝
#define M_COLOR_NAVY (MAKE_COLOR( 0, 0,128)) // 海军蓝
#define M_COLOR_ROYALBLUE (MAKE_COLOR( 65,105,225)) // 皇家蓝
#define M_COLOR_CORNFLOWERBLUE (MAKE_COLOR(100,149,237)) // 矢车菊蓝
#define M_COLOR_LIGHTSTEELBLUE (MAKE_COLOR(176,196,222)) // 淡钢蓝
#define M_COLOR_LIGHTSLATEGRAY (MAKE_COLOR(119,136,153)) // 浅板岩灰
#define M_COLOR_SLATEGRAY (MAKE_COLOR(112,128,144)) // 石板灰
#define M_COLOR_DODGERBLUE (MAKE_COLOR( 30,114,255)) // 道奇蓝
#define M_COLOR_ALICEBLUE (MAKE_COLOR(240,248,255)) // 爱丽丝蓝
#define M_COLOR_STEELBLUE (MAKE_COLOR( 70,130,180)) // 钢蓝
#define M_COLOR_LIGHTSKYBLUE (MAKE_COLOR(135,206,250)) // 淡天蓝
#define M_COLOR_SKYBLUE (MAKE_COLOR(135,206,235)) // 天蓝
#define M_COLOR_DEEPSKYBLUE (MAKE_COLOR( 0,191,255)) // 深天蓝
#define M_COLOR_LIGHTBLUE (MAKE_COLOR(173,216,230)) // 淡蓝
#define M_COLOR_POWDERBLUE (MAKE_COLOR(176,224,230)) // 火药蓝
#define M_COLOR_CADETBLUE (MAKE_COLOR( 95,158,160)) // 军校蓝
#define M_COLOR_AZURE (MAKE_COLOR(245,255,255)) // 蔚蓝
#define M_COLOR_LIGHTCYAN (MAKE_COLOR(240,255,255)) // 淡青
#define M_COLOR_PALETURQUOISE (MAKE_COLOR(175,238,238)) // 苍白宝石绿
#define M_COLOR_AQUA (MAKE_COLOR( 0,255,255)) // 水绿
#define M_COLOR_DARKTURQUOISE (MAKE_COLOR( 0,206,209)) // 深宝石绿
#define M_COLOR_DARKSLATEGRAY (MAKE_COLOR( 47, 79, 79)) // 深石板灰
#define M_COLOR_DARKCYAN (MAKE_COLOR( 0,139,139)) // 深青色
#define M_COLOR_TEAL (MAKE_COLOR( 0,128,128)) // 水鸭色
#define M_COLOR_MEDIUMTURQUOISE (MAKE_COLOR( 72,209,204)) // 适中宝石绿
#define M_COLOR_LIGHTSEEGREEN (MAKE_COLOR( 32,178,170)) // 浅海样绿
#define M_COLOR_TURQUOISE (MAKE_COLOR( 64,224,208)) // 宝石绿
#define M_COLOR_AQUAMARINE (MAKE_COLOR(127,255,212)) // 碧绿
#define M_COLOR_MEDIUMAQUAMARINE (MAKE_COLOR(102,205,170)) // 适中碧绿
#define M_COLOR_MEDIUMSPRINGGREEN (MAKE_COLOR( 0,250,154)) // 适中春天绿
#define M_COLOR_SPRINGGREEN (MAKE_COLOR( 0,255,127)) // 春天绿
#define M_COLOR_MEDIUMSEEGREEN (MAKE_COLOR( 60,179,113)) // 适中海洋绿
#define M_COLOR_SEEGREEN (MAKE_COLOR( 46,139, 87)) // 海洋绿
#define M_COLOR_LIGHTGREEN (MAKE_COLOR(144,238,144)) // 浅绿
#define M_COLOR_PALEGREEN (MAKE_COLOR(152,251,152)) // 苍白绿
#define M_COLOR_DARKSEEGREEN (MAKE_COLOR(143,188,143)) // 深海洋绿
#define M_COLOR_LIME (MAKE_COLOR( 50,205, 50)) // 莱姆色
#define M_COLOR_CHARTREUSE (MAKE_COLOR(127,255, 0)) // 查特酒绿
// Green-RED Series
#define M_COLOR_FORESTGREEN (MAKE_COLOR( 34,139, 34)) // 森林绿
#define M_COLOR_LAWNGREEN (MAKE_COLOR(124,252, 0)) // 草坪绿
#define M_COLOR_GREENYELLOW (MAKE_COLOR(173,255, 47)) // 绿黄
#define M_COLOR_DARKOLIVEGREEN (MAKE_COLOR( 85,107, 47)) // 深橄榄绿
#define M_COLOR_YELLOWGREEN (MAKE_COLOR(154,205, 50)) // 黄绿
#define M_COLOR_OLIVEDRAB (MAKE_COLOR( 34,139, 34)) // 橄榄褐
#define M_COLOR_BEIGE (MAKE_COLOR(245,245,220)) // 米色
#define M_COLOR_LIGHTRODYELLOW (MAKE_COLOR( 34,139, 34)) // 浅秋黄
#define M_COLOR_IVORY (MAKE_COLOR(255,255,240)) // 象牙白
#define M_COLOR_OLIVE (MAKE_COLOR(128,128, 0)) // 橄榄
#define M_COLOR_DARKKHAKI (MAKE_COLOR(189,183,107)) // 深卡其布
#define M_COLOR_LEMONCHIFFON (MAKE_COLOR(255,250,205)) // 柠檬沙
#define M_COLOR_PALEGOLDROD (MAKE_COLOR(238,232,170)) // 灰秋
#define M_COLOR_KHAKI (MAKE_COLOR(240,230,140)) // 卡其布
#define M_COLOR_GOLDEN (MAKE_COLOR(255,215, 0)) // 金色
#define M_COLOR_CORNMILK (MAKE_COLOR(255,248,220)) // 玉米
#define M_COLOR_GOLDROD (MAKE_COLOR(218,165, 32)) // 秋天
#define M_COLOR_DARKGOLDROD (MAKE_COLOR(184,134, 11)) // 深秋
#define M_COLOR_FLORALWHITE (MAKE_COLOR(255,250,240)) // 白花
#define M_COLOR_OLDLACE (MAKE_COLOR(253,245,230)) // 浅米色
#define M_COLOR_WHEAT (MAKE_COLOR(245,222,179)) // 小麦
#define M_COLOR_MOCCASIN (MAKE_COLOR(255,228,181)) // 鹿皮
#define M_COLOR_ORANGE (MAKE_COLOR(255,165, 0)) // 橙色
#define M_COLOR_PAPAYAWHIP (MAKE_COLOR(255,239,213)) // 木瓜
#define M_COLOR_BLANCHEDALMOND (MAKE_COLOR(255,235,205)) // 漂白的杏仁
#define M_COLOR_NAVAJOWHITE (MAKE_COLOR(255,222,173)) // 耐而节白
#define M_COLOR_ANTIQUEWHITE (MAKE_COLOR(250,235,215)) // 古白
#define M_COLOR_TAN (MAKE_COLOR(210,180,140)) // 晒
#define M_COLOR_BURLYWOOD (MAKE_COLOR(222,184,135)) // 树干
#define M_COLOR_BISQUE (MAKE_COLOR(255,228,196)) // 乳脂
#define M_COLOR_DARKORANGE (MAKE_COLOR(255,140, 0)) // 深橙色
#define M_COLOR_LINEN (MAKE_COLOR(255,240,230)) // 亚麻
#define M_COLOR_PERU (MAKE_COLOR(205,133, 63)) // 秘鲁
#define M_COLOR_SANDYBROWN (MAKE_COLOR(244,164, 96)) // 沙棕
#define M_COLOR_CHOCOLATE (MAKE_COLOR(210,105, 30)) // 巧克力
#define M_COLOR_SEASHELL (MAKE_COLOR(255,245,238)) // 海贝
#define M_COLOR_SIENNA (MAKE_COLOR(160, 82, 45)) // 土黄赭
#define M_COLOR_SALMON (MAKE_COLOR(255,160,122)) // 三文鱼
#define M_COLOR_CORAL (MAKE_COLOR(255,127, 80)) // 珊瑚红
#define M_COLOR_ORANGERED (MAKE_COLOR(255, 69, 0)) // 橙红
#define M_COLOR_TOMATO (MAKE_COLOR(255, 99, 71)) // 番茄
#define M_COLOR_MISTYROSE (MAKE_COLOR(255,228,225)) // 迷雾玫瑰
#define M_COLOR_BLOODYMEAT (MAKE_COLOR(250,128,114)) // 鲜肉
#define M_COLOR_LIGHTCORAL (MAKE_COLOR(240,128,128)) // 浅珊瑚红
#define M_COLOR_ROSEBROWN (MAKE_COLOR(188,143,143)) // 玫瑰棕
#define M_COLOR_INDIANRED (MAKE_COLOR(205, 92, 92)) // 浅粉红
#define M_COLOR_BROWN (MAKE_COLOR(165, 42, 42)) // 棕色
#define M_COLOR_FIREBRICK (MAKE_COLOR(178, 34, 34)) // 火砖
#define M_COLOR_DARKRED (MAKE_COLOR(139, 0, 0)) // 深红
#define M_COLOR_MAROON (MAKE_COLOR(128, 0, 0)) // 栗色
// Neutral Series
#define M_COLOR_WHITESMOKE (MAKE_COLOR(245,245,245)) // 烟白
#define M_COLOR_GAINSBORO (MAKE_COLOR(220,220,220)) // 赶死部落
#define M_COLOR_LIGHTGRAY (MAKE_COLOR(211,211,211)) // 浅灰
#define M_COLOR_SILVER (MAKE_COLOR(192,192,192)) // 银色
#define M_COLOR_DARKGRAY (MAKE_COLOR( 73, 73, 73)) // 深灰
#define M_COLOR_DIMGRAY (MAKE_COLOR( 54, 54, 54)) // 暗灰
#define M_COLOR_COAL (MAKE_COLOR( 34, 35, 34)) // 煤炭黑
#ifdef __cplusplus
}
#endif
#endif
| 2.21875 | 2 |
2024-11-18T22:11:54.705857+00:00 | 2008-11-27T17:43:43 | 99bd673ddf272d455a91cb2aed90565303a184a2 | {
"blob_id": "99bd673ddf272d455a91cb2aed90565303a184a2",
"branch_name": "refs/heads/master",
"committer_date": "2008-11-27T17:43:43",
"content_id": "d09e773f23ec9f1c8ceea720058f57aea02741ea",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "92935169b99b2b9df9eb3151b6d4ddba170b7388",
"extension": "c",
"filename": "alias.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3919,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/src/int/alias.c",
"provenance": "stackv2-0087.json.gz:12214",
"repo_name": "philpep/philsh",
"revision_date": "2008-11-27T17:43:43",
"revision_id": "86fff8c760d219712649bc03829839044409a4f0",
"snapshot_id": "ee98309a72e41da8c9ecb056134245a4fd26a392",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/philpep/philsh/86fff8c760d219712649bc03829839044409a4f0/src/int/alias.c",
"visit_date": "2016-09-08T01:12:00.295879"
} | stackv2 | /*
* Copyright (C) 2008 Philippe Pepiot <philippe.pepiot@gmail.com>
* philsh is under BSD licence, see LICENCE file for more informations.
*
*/
#include <stdio.h> /* Pour printf, fprintf */
#include <string.h> /* Pour strlen, strchr, strcmp, strcpy */
#include <stdlib.h> /* Pour malloc, NULL, free */
#include "alias.h"
#include "../complete.h"
/* Fonction qui est appelée lors de la création d'un alias */
int alias(int argc, char **argv)
{
char *p;
alias_ll *tmp;
tmp = liste_alias;
/* Manque d'arguments */
if (argc != 2)
{
fprintf(stderr, "philsh : Usage : alias [-L|name=\"command\"\n");
return ERR_ARG;
}
/* L'option -p permet d'afficher les alias de la session en cours */
if (!strcmp(argv[1], "-L"))
{
while(tmp != NULL)
{
printf("%s aliased to '%s'\n", tmp->name, tmp->cmd);
tmp = tmp->next;
}
return 0;
}
/* Si la commande n'est pas de la forme alias machin=truc alors
* c'est qu'on cherche à afficher un alias */
if (NULL == (p = strchr(argv[1], '=')))
{
if(NULL == (p = search_alias(liste_alias, argv[1])))
{
fprintf(stderr,"philsh: %s is not a valid alias\n", argv[1]);
return 1;
}
return printf("%s aliased to '%s'\n", argv[1], p);
}
/* On coupe la chaine au =, ainsi argv[1] = machin et p+1 = truc */
*p = '\0';
/* On teste si l'alias n'existe pas déjà */
while(tmp != NULL)
{
if (!strcmp(tmp->name, argv[1]))
{
/* Si l'alias existe, on le modifie à sa nouvelle valeur */
free(tmp->cmd);
tmp->cmd = malloc(sizeof(char) * (1+strlen(p+1)));
strcpy(tmp->cmd, p+1);
return 0;
}
tmp = tmp->next;
}
/* L'alias n'existe pas ---> on le crée */
liste_alias = add_alias(liste_alias, argv[1], p+1);
/* On rajoute l'alias dans la completion */
command_completion = add_file_completion(argv[1], 0, command_completion);
return 0;
}
/* Cette fonction crée l'alias name=cmd, il le rajoute
* a la liste chainée des alias ... */
alias_ll *add_alias(alias_ll *liste, char *name, char *cmd)
{
/* TODO : est ce que cette fonction est sécurisée ? */
alias_ll *new = malloc(sizeof(alias_ll));
new->name = malloc(sizeof(char) * (1+strlen(name)));
new->cmd = malloc(sizeof(char) * (1+strlen(cmd)));
strcpy(new->name, name);
strcpy(new->cmd, cmd);
new->next = liste;
return new;
}
/* Cette fonction cherche un alias par son nom
* et renvoie la commande.
* f(machin) = truc */
char *search_alias(alias_ll *liste, char *name)
{
alias_ll *tmp;
tmp = liste;
/* On parcoure simplement la liste */
while(tmp != NULL)
{
if (!strcmp(tmp->name, name))
return tmp->cmd;
tmp = tmp->next;
}
/* On à rien trouvé... */
return NULL;
}
/* Cette fonction est appelée par la commande unalias */
int unalias(int argc, char **argv)
{
/* Manque d'arguments */
if (argc != 2)
{
fprintf(stderr, "philsh: Usage : Unalias <alias_name>\n");
return ERR_ARG;
}
/* Option -a, on supprime tous les alias */
if (!strcmp(argv[1], "-a"))
{
while(liste_alias != NULL)
del_alias(liste_alias->name);
return 0;
}
if(del_alias(argv[1]) != 0)
fprintf(stderr, "%s is not a valid alias\n", argv[1]);
return ERR_EXEC;
}
int del_alias(char *name)
{
alias_ll *current, *prev = NULL;
current = liste_alias;
/* On parcoure simplement la liste chainé
* jusqu'a trouver le bon alias */
while(current != NULL)
{
if(!strcmp(current->name, name))
{
/* Si l'alias est en tête de liste */
if(prev == NULL)
liste_alias = liste_alias->next;
else
prev->next = current->next;
/* On libère la memoire */
free(current->name);
free(current->cmd);
free(current);
return 0;
}
prev = current;
current = current->next;
}
/* Si on a pas trouvé l'alias */
return 1;
}
| 3.046875 | 3 |
2024-11-18T22:11:54.767233+00:00 | 2020-09-13T01:55:30 | 98901114f68d5fe155712af1b87c4dfd8e2c5c71 | {
"blob_id": "98901114f68d5fe155712af1b87c4dfd8e2c5c71",
"branch_name": "refs/heads/master",
"committer_date": "2020-09-13T01:55:30",
"content_id": "91f2c04c39c4af8293668d144c3c342cbd5c3133",
"detected_licenses": [
"MIT"
],
"directory_id": "cc373d7d00ebee4c07a2d9533beb6956d6a09e80",
"extension": "c",
"filename": "buthp.c",
"fork_events_count": 0,
"gha_created_at": "2019-03-24T04:00:33",
"gha_event_created_at": "2022-12-10T11:44:57",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 177368554,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1125,
"license": "MIT",
"license_type": "permissive",
"path": "/nodes/buthp.c",
"provenance": "stackv2-0087.json.gz:12343",
"repo_name": "brianfay/baliset",
"revision_date": "2020-09-13T01:55:30",
"revision_id": "06436b77f2cb0fe36195b284e4a80bbba33a7ed0",
"snapshot_id": "c3b282a5d0d9cf41fffed8d55db21c360f6ee707",
"src_encoding": "UTF-8",
"star_events_count": 5,
"url": "https://raw.githubusercontent.com/brianfay/baliset/06436b77f2cb0fe36195b284e4a80bbba33a7ed0/nodes/buthp.c",
"visit_date": "2022-12-23T13:26:07.384145"
} | stackv2 | #include "baliset_graph.h"
#include "soundpipe.h"
typedef struct {
sp_data *sp;
sp_buthp *buthp;
} buthp_data;
buthp_data *new_buthp_data(const blst_patch *p) {
buthp_data *data = malloc(sizeof(buthp_data));
sp_create(&data->sp);
sp_buthp_create(&data->buthp);
sp_buthp_init(data->sp, data->buthp);
return data;
}
void process_buthp(blst_node *self) {
blst_outlet o_out = self->outlets[0];
float *out_buf = self->outlets[0].buf;
float *in_buf = self->inlets[0].buf;
buthp_data *data = self->data;
sp_data *sp = data->sp;
sp_buthp *buthp = data->buthp;
buthp->freq = self->controls[0].val;
for(int i = 0; i < o_out.buf_size; i++) {
sp_buthp_compute(sp, buthp, &in_buf[i], &out_buf[i]);
}
}
void destroy_buthp(blst_node *self) {
buthp_data *data = self->data;
sp_buthp_destroy(&data->buthp);
sp_destroy(&data->sp);
}
blst_node *blst_new_buthp(const blst_patch *p) {
blst_node *n = blst_init_node(p, 1, 1, 1);
buthp_data *data = new_buthp_data(p);
n->data = data;
n->process = &process_buthp;
n->destroy = &destroy_buthp;
n->controls[0].val = 5.0;
return n;
}
| 2.171875 | 2 |
2024-11-18T22:11:54.908072+00:00 | 2021-09-22T18:11:24 | 126f6d1eba27ab598c66b4b22bbbcbfe24d79e26 | {
"blob_id": "126f6d1eba27ab598c66b4b22bbbcbfe24d79e26",
"branch_name": "refs/heads/main",
"committer_date": "2021-09-22T18:11:24",
"content_id": "f71fa067b36460cae7a49e56ee49bcbe7f520c89",
"detected_licenses": [
"MIT"
],
"directory_id": "0aaf408abce8bdcb4149ba43bac1762ab3d1e54a",
"extension": "c",
"filename": "Função lastCharPos.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 409304532,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 388,
"license": "MIT",
"license_type": "permissive",
"path": "/Code/Função lastCharPos.c",
"provenance": "stackv2-0087.json.gz:12471",
"repo_name": "lucascesar918/C-Programs",
"revision_date": "2021-09-22T18:11:24",
"revision_id": "564710656e219067770a33c0514c694f1e26033f",
"snapshot_id": "94d4ca7084d7b780cc811db07861492a24fda879",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/lucascesar918/C-Programs/564710656e219067770a33c0514c694f1e26033f/Code/Função lastCharPos.c",
"visit_date": "2023-08-20T19:26:16.610915"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int lastCharPos(char *s,char ch){
int i=0,pos=0;
while(s[i]!=0){
if (s[i]==ch)
pos=i;
i++;
}
if(pos==0)
return -1;
else
return pos;
}
void main(){
char str[]="acerto miseravi",ch = 'a';
printf("%s '%c' %d\n",str,ch,lastCharPos(str,ch));
} | 2.84375 | 3 |
2024-11-18T22:11:57.832380+00:00 | 2019-09-21T03:20:19 | e35bdf786b486491ed4ec742aee998b5ae07fa10 | {
"blob_id": "e35bdf786b486491ed4ec742aee998b5ae07fa10",
"branch_name": "refs/heads/master",
"committer_date": "2019-09-21T03:20:19",
"content_id": "6c2baca32edeacd17b9b6237737a674cfe45e091",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "fa4cf4236eac798c60c4e3195d78e603b846b37f",
"extension": "c",
"filename": "001-DecToHex.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1438,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/06-C语言程序开发范例宝典/C-Chapter01/001-DecToHex.c",
"provenance": "stackv2-0087.json.gz:12599",
"repo_name": "iloeng/ReadBooks",
"revision_date": "2019-09-21T03:20:19",
"revision_id": "e997b9c876cc692206a46f139a6b1fb0ba3787ab",
"snapshot_id": "d58131b9c216ef1f8948ee2a680314a7701b9526",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/iloeng/ReadBooks/e997b9c876cc692206a46f139a6b1fb0ba3787ab/06-C语言程序开发范例宝典/C-Chapter01/001-DecToHex.c",
"visit_date": "2022-11-22T13:33:09.074552"
} | stackv2 | /*
*实例 001 十进制转换为十六进制
*/
//void main()
//{
// int i;
// printf("Please Input decimalism number: ");
// scanf("%d", &i);
// /*
// * 直接使用控制字符串
// * %o 八进制
// * %x %X 十六进制
// */
// printf("the hex number is 0x%x\n", i);
// printf("the oct number is %o\n", i);
// printf("the bin number is %d\n", DecToBin(i));
// getchar();
// getchar();
//}
void DecToHex(int x)
{
printf("the hex number is 0x%x\n", x);
}
// 十进制转二进制
//long DecToBin(int x)
//{
// int remainder, temp; //remainder 是余数
// long result = 0, k = 1;
// temp = x;
// while (temp)
// {
// remainder = temp % 2;
// result = remainder * k + result;
// k = k * 10;
// temp = temp / 2;
// }
// return result;
//}
/*
函数 char *itoa(int value, char *string, int radix)
返回值类型char
参数value 待转换的数字
参数string 转换后存储到string中
参数radix 转换到几进制
定义在 stdlib.h
示例:
#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int main()
{
int userinput;
printf("Please enter a integer.\n");
scanf("%d",&userinput);
char octal[MAX],hex[MAX];
itoa(userinput,octal,8);
itoa(userinput,hex,16);
printf("Octal and Hex of the integer %d that you entered is %s and %s.\n",userinput,octal,hex);
return 0;
}
*/ | 3.484375 | 3 |
2024-11-18T22:11:58.839314+00:00 | 2022-02-27T22:41:37 | 3d594dde084957e23a0ca746ad97d3eb8cbbbbdf | {
"blob_id": "3d594dde084957e23a0ca746ad97d3eb8cbbbbdf",
"branch_name": "refs/heads/master",
"committer_date": "2022-02-27T22:41:37",
"content_id": "38cff043e1a1c7272367ebc68d438757572a4b90",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "903c0b770949e5de50351726333f9dfda5b12619",
"extension": "c",
"filename": "sec1.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 32406826,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 342,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/userland/tests/app/sec1/sec1.c",
"provenance": "stackv2-0087.json.gz:12728",
"repo_name": "hgeisse/eos32-on-eco32",
"revision_date": "2022-02-27T22:41:37",
"revision_id": "eac4d32b998fe21dbba402a3f7eb0230386e955d",
"snapshot_id": "494ccc6ad85e2d1056b0f6f51aa64f7f22dabe45",
"src_encoding": "UTF-8",
"star_events_count": 3,
"url": "https://raw.githubusercontent.com/hgeisse/eos32-on-eco32/eac4d32b998fe21dbba402a3f7eb0230386e955d/userland/tests/app/sec1/sec1.c",
"visit_date": "2023-03-09T17:03:04.213223"
} | stackv2 | /*
* sec1.c -- incremental display of the running seconds by busy waiting
*/
#include <stdio.h>
#include <time.h>
int main(void) {
int i;
long then, now;
then = time(NULL);
for (i = 1; i < 10; i++) {
do {
now = time(NULL);
} while (now == then);
then = now;
printf("seconds = %d\n", i);
}
return 0;
}
| 2.984375 | 3 |
2024-11-18T22:11:58.916795+00:00 | 2021-03-12T15:06:29 | 2faf667898f230fb1c8335e64506a7bd96b9e83f | {
"blob_id": "2faf667898f230fb1c8335e64506a7bd96b9e83f",
"branch_name": "refs/heads/master",
"committer_date": "2021-03-12T15:06:29",
"content_id": "898e348a80cc72b41f170cabe09b24cee025b52e",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "00a90405e5185b898ca8cb39082906a2cee5ccc3",
"extension": "h",
"filename": "emulator_if.h",
"fork_events_count": 0,
"gha_created_at": "2015-06-09T21:29:22",
"gha_event_created_at": "2021-03-12T15:06:29",
"gha_language": "C",
"gha_license_id": "Apache-2.0",
"github_id": 37159492,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3073,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/cpvmm/vmm/include/emulator_if.h",
"provenance": "stackv2-0087.json.gz:12858",
"repo_name": "jethrogb/cloudproxy",
"revision_date": "2021-03-12T15:06:29",
"revision_id": "fcf90a62bf09c4ecc9812117d065954be8a08da5",
"snapshot_id": "1c20a4670e8ed74c32f7d7ff0fca60f8e8ef181f",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/jethrogb/cloudproxy/fcf90a62bf09c4ecc9812117d065954be8a08da5/cpvmm/vmm/include/emulator_if.h",
"visit_date": "2021-07-14T12:54:54.105912"
} | stackv2 | /*
* Copyright (c) 2013 Intel Corporation
*
* 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 _EMULATOR_IF_H_
#define _EMULATOR_IF_H_
#include "vmm_defs.h"
#include "list.h"
#include "guest_cpu.h"
#include "gdt.h"
#include "hw_utils.h"
#include "vmm_globals.h"
typedef struct _EMULATOR_STATE * EMULATOR_HANDLE;
typedef struct _CPU_ARCH_STATE * CPU_ARCH_STATE;
typedef enum {
EMUL_MMIO_GPA_ACCESS = 1,
EMUL_MMIO_HVA_ACCESS = 2
} EMUL_MMIO_ACCESS_TYPE;
typedef VMM_STATUS (*EMUL_MMIO_HANDLER)(
ADDRESS addr, // virtual address to IO
void *p, // copy to/from
RW_ACCESS access, // read / write
INT32 num_bytes, // number bytes to transfer
INT32 *bytes_succeeded, // number bytes actually transferred
void *callee_context // pointer to callee defined state
);
// should not be used outside emulator. placed here for convenience :-(
typedef struct _EMU_MMIO_DESCRIPTOR {
LIST_ELEMENT list;
ADDRESS address;
INT32 region_size;
INT32 address_type; // 0 - GPA, 1 - HVA, others invalid
EMUL_MMIO_HANDLER mmio_handler;
EMUL_MMIO_HANDLER write;
void *callee_context;
} EMU_MMIO_DESCRIPTOR;
EMULATOR_HANDLE emul_create_handle(GUEST_CPU_HANDLE guest_cpu);
void emul_destroy_handle(EMULATOR_HANDLE handle);
void emul_intialize(EMULATOR_HANDLE handle);
void emul_start_guest_execution(EMULATOR_HANDLE handle);
void emul_stop_guest_execution(EMULATOR_HANDLE handle);
BOOLEAN emul_is_running(EMULATOR_HANDLE handle);
BOOLEAN emulator_interrupt_handler(EMULATOR_HANDLE handle, VECTOR_ID vector);
void emulator_register_handlers(EMULATOR_HANDLE handle);
BOOLEAN emul_run_single_instruction(EMULATOR_HANDLE handle);
BOOLEAN emul_state_show(EMULATOR_HANDLE p_emu);
void emul_register_mmio_handler(
EMULATOR_HANDLE p_emu,
ADDRESS region_address,
unsigned size_in_bytes,
EMUL_MMIO_ACCESS_TYPE addr_type,
EMUL_MMIO_HANDLER mmio_handler,
void *callee_context
);
// FUNCTION : emulator_is_running_as_guest()
// PURPOSE : Used in interrupt handler
// ARGUMENTS: void
// RETURNS : TRUE if guest runs emulator
INLINE BOOLEAN emulator_is_running_as_guest(void)
{
return ((vmm_get_state() == VMM_STATE_RUN) && (0 != hw_read_gs()));
}
#endif // _EMULATOR_IF_H_
| 2.0625 | 2 |
2024-11-18T22:11:59.159874+00:00 | 2017-11-04T07:54:04 | 4543af8bcb721ce46ddadccfb28352bb482e2ac5 | {
"blob_id": "4543af8bcb721ce46ddadccfb28352bb482e2ac5",
"branch_name": "refs/heads/master",
"committer_date": "2017-11-04T07:54:04",
"content_id": "d7938a9b14ee9ffc127ed86dca06675ab7d04658",
"detected_licenses": [
"MIT"
],
"directory_id": "2dddc5e6bedc07c2838b7ee4fb0931db62b72f1c",
"extension": "c",
"filename": "sprite.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 109477135,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 10302,
"license": "MIT",
"license_type": "permissive",
"path": "/src/sprite.c",
"provenance": "stackv2-0087.json.gz:13114",
"repo_name": "vdribeiro/arkanoid",
"revision_date": "2017-11-04T07:54:04",
"revision_id": "d1ed82cc0293cb416bf5e0e14a6efcf835ef7800",
"snapshot_id": "5f831658533089afbb889a7c708804d05d026f99",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/vdribeiro/arkanoid/d1ed82cc0293cb416bf5e0e14a6efcf835ef7800/src/sprite.c",
"visit_date": "2021-07-25T08:25:11.050366"
} | stackv2 | #include "sprite.h"
extern int HRES, VRES;
static char *video_buffer = NULL;
/** Reads a xpm-like sprite defined in "map" (look at pixmap.h for
* examples). Returns the address of the allocated memory where the
* sprite was read. Updates "width" and "heigh" with the sprite
* dimension. Return NULL on error.
* Assumes that VRES and HRES (the screen vertical and horizontal resolution)
* are externaly defined.
*
* Usage example, using the defined sprite in pixmap.h:
* <pre>
* #include "pixmap.h" // defines pic1, pic2, etc
* int wd, hg;
* char *sprite = read_xpm(pic1, &wd, &hg);
* </pre>
*/
char *read_xpm(char *map[], int *wd, int *ht)
{
__attribute__((unused)) static char read_xpm_jcard;
int width, height, colors;
char sym[256];
int col;
int i, j;
char *pix, *pixtmp, *tmp, *line;
char symbol;
// read width, height, colors
if (sscanf(map[0],"%d %d %d", &width, &height, &colors) != 3) {
printf("read_xpm: incorrect width, height, colors\n");
return NULL;
}
#ifdef DEBUG
printf("%d %d %d\n", width, height, colors);
#endif
if (width > HRES || height > VRES || colors > 256) {
printf("read_xpm: incorrect width, height, colors\n");
return NULL;
}
*wd = width;
*ht = height;
for (i=0; i<256; i++)
sym[i] = 0;
// read symbols <-> colors
for (i=0; i<colors; i++) {
if (sscanf(map[i+1], "%c %d", &symbol, &col) != 2) {
printf("read_xpm: incorrect symbol, color at line %d\n", i+1);
return NULL;
}
#ifdef DEBUG
printf("%c %d\n", symbol, col);
#endif
if (col > 256) {
printf("read_xpm: incorrect color at line %d\n", i+1);
return NULL;
}
sym[col] = symbol;
}
// allocate pixmap memory
pix = pixtmp = malloc(width*height);
// parse each pixmap symbol line
for (i=0; i<height; i++) {
line = map[colors+1+i];
#ifdef DEBUG
printf("\nparsing %s\n", line);
#endif
for (j=0; j<width; j++) {
tmp = memchr(sym, line[j], 256); // find color of each symbol
if (tmp == NULL) {
printf("read_xpm: incorrect symbol at line %d, col %d\n", colors+i+1, j);
return NULL;
}
*pixtmp++ = tmp - sym; // pointer arithmetic! back to books :-)
#ifdef DEBUG
printf("%c:%d ", line[j], tmp-sym);
#endif
}
}
return pix;
}
Sprite* create_sprite(char *pic[])
{
Sprite* sprt = create_unbuffered_sprite(pic);
if(!sprt) return NULL;
sprt->bgmap = malloc(sprt->width * sprt->height);
return sprt;
}
Sprite* create_unbuffered_sprite(char *pic[])
{
Sprite* sprt = malloc(sizeof(Sprite));
if(!sprt) return NULL;
int wd, ht;
sprt->map = read_xpm(pic, &wd, &ht);
if(!sprt->map) { free(sprt); return NULL; }
sprt->x = sprt->y = sprt->xspeed = sprt->yspeed = 0;
sprt->width = wd; sprt->height = ht;
sprt->bgmap = NULL;
return sprt;
}
Sprite* capture_screen(int x_ini, int y_ini, int width, int height, char* base)
{
Sprite* sprt = malloc(sizeof(Sprite));
if(!sprt) return NULL;
char* map = malloc(width * height);
if(!map) { free(sprt); return NULL; }
int i, k;
for(i = 0; i < height; i++)
for(k = 0; k < width; k++)
*(map + width*i + k) = get_pixel(x_ini + k, y_ini + i, base);
sprt->map = map;
sprt->x = x_ini;
sprt->y = y_ini;
sprt->xspeed = sprt->yspeed = 0;
sprt->width = width; sprt->height = height;
sprt->bgmap = NULL;
return sprt;
}
void draw_sprite(Sprite* sprt, char *base)
{
char* dSprt = sprt->map;
char* bgMap = sprt->bgmap;
int i,k;
for(i=0; i < sprt->height; i++)
for(k=0; k < sprt->width; k++)
{
if(bgMap) *(bgMap + sprt->width*i + k) = get_pixel(sprt->x+k, sprt->y+i, base); //guarda o valor antigo
if(*dSprt != 0) set_pixel(sprt->x+k,sprt->y+i, *dSprt, base); //actualiza com o valor actual
dSprt++;
}
}
void draw_sprite_rotated(Sprite *sprt, char *base, int angle)
{
char* dSprt = sprt->map;
char* bgMap = sprt->bgmap;
while(angle < 0) angle += 360;
while(angle >= 360) angle -= 360;
int i, k;
if(bgMap)
{
//guarda uma copia do background onde vai ser desenhada a sprite
for(i=0; i < sprt->height; i++)
for(k=0; k < sprt->width; k++)
if (angle==0 || angle==180 || angle==360) //caso as dimensoes vertical e horizontal da sprite se mantenham
*(bgMap + sprt->width*i + k) = get_pixel(sprt->x+k, sprt->y+i, base);
else
*(bgMap + sprt->width*k + i) = get_pixel(sprt->x+k, sprt->y+i, base);
}
//desenhar a sprite no sitio certo conforme o angulo
for(i=0; i < sprt->height; i++)
for(k=0; k < sprt->width; k++)
{
if(*dSprt != 0)
switch(angle)
{
case 90:
set_pixel(sprt->x+i,sprt->y+k, *dSprt, base);//actualiza com o valor actual
break;
case 180:
set_pixel(sprt->x+sprt->width-k,sprt->y+sprt->height-i, *dSprt, base); //actualiza com o valor actual
break;
case 270:
set_pixel(sprt->x+sprt->height-i,sprt->y+sprt->width-k, *dSprt, base); //actualiza com o valor actual
break;
default: //angulo 0 e 360
set_pixel(sprt->x+k,sprt->y+i, *dSprt, base); //actualiza com o valor actual
break;
}
dSprt++;
}
}
void draw_sprite_scaled(Sprite *sprt, char *base, int width, int height)
{
char *dSprt = sprt->map;
char* bgMap = sprt->bgmap;
if(bgMap)
{
bgMap = realloc(bgMap, width * height);
sprt->bgmap = bgMap;
}
double dx = (double)sprt->width / width;
double dy = (double)sprt->height / height;
int i,k;
for(i = 0; i < height; i++)
for(k = 0; k < width; k++)
{
if(bgMap) *(bgMap + width*i + k) = get_pixel(sprt->x+k, sprt->y+i, base); //guarda o valor antigo
int map_x = dx*k + 0.5;
int map_y = dy*i + 0.5;
int color = *(dSprt + sprt->width*map_y + map_x);
if(color != 0) set_pixel(sprt->x+k,sprt->y+i, color, base); //actualiza com o valor mapeado
}
}
void draw_sprite_rotated_scaled(Sprite *sprt, char *base, int angle, int width, int height)
{
char* dSprt = sprt->map;
char* bgMap = sprt->bgmap;
if(bgMap)
{
bgMap = realloc(bgMap, width * height);
sprt->bgmap = bgMap;
}
while(angle < 0) angle += 360;
while(angle >= 360) angle -= 360;
double dx = (double)sprt->width / width;
double dy = (double)sprt->height / height;
int i, k;
if(bgMap)
{
//guarda uma copia do background onde vai ser desenhada a sprite
for(i=0; i < height; i++)
for(k=0; k < width; k++)
if (angle==0 || angle==180) //caso as dimensoes vertical e horizontal da sprite se mantenham
*(bgMap + width*i + k) = get_pixel(sprt->x+k, sprt->y+i, base);
else
*(bgMap + width*i + k) = get_pixel(sprt->x+i, sprt->y+k, base);
}
//desenhar a sprite no sitio certo conforme o angulo
for(i=0; i < height; i++)
for(k = 0; k < width; k++)
{
int map_x = dx*k + 0.5;
int map_y = dy*i + 0.5;
int color = *(dSprt + sprt->width*map_y + map_x);
if(color != 0)
switch(angle)
{
case 90:
set_pixel(sprt->x+i,sprt->y+k, color, base);//actualiza com o valor actual
break;
case 180:
set_pixel(sprt->x+width-k,sprt->y+height-i, color, base); //actualiza com o valor actual
break;
case 270:
set_pixel(sprt->x+height-i,sprt->y+width-k, color, base); //actualiza com o valor actual
break;
default: //angulo 0 e 360
set_pixel(sprt->x+k,sprt->y+i, color, base); //actualiza com o valor actual
break;
}
}
}
void draw_mosaic(Sprite *sprt, char *base)
{
int x_original = sprt->x;
int y_original = sprt->y;
sprt->x = sprt->y = 0;
int n_sprites_x = HRES / sprt->width;
int n_sprites_y = VRES / sprt->height;
int i,k;
for(i = 0; i <= n_sprites_y; i++)
{
for(k = 0; k <= n_sprites_x; k++)
{
draw_sprite(sprt, base);
sprt->x += sprt->width;
}
sprt->x = 0;
sprt->y +=sprt->height;
}
sprt->x = x_original;
sprt->y = y_original;
}
void delete_sprite(Sprite *sprt, char *base)
{
char* bgMap = sprt->bgmap;
if(!bgMap) return;
int i, k;
for(i=0; i < sprt->height; i++)
for(k=0; k < sprt->width; k++)
set_pixel(sprt->x+k,sprt->y+i, *(bgMap + sprt->width*i + k), base);
}
void delete_sprite_rotated(Sprite *sprt, char *base, int angle)
{
char* bgMap = sprt->bgmap;
if(!bgMap) return;
while(angle < 0) angle += 360;
while(angle >= 360) angle -= 360;
int i, k;
for(i=0; i < sprt->height; i++)
for(k=0; k < sprt->width; k++)
if (angle==0 || angle==180) //caso as dimensoes vertical e horizontal da sprite se mantenham
set_pixel(sprt->x+k,sprt->y+i, *(bgMap + sprt->width*i + k), base);
else
set_pixel(sprt->x+i,sprt->y+k, *(bgMap + sprt->width*i + k), base);
}
void delete_sprite_scaled(Sprite *sprt, char *base, int width, int height)
{
char* bgMap = sprt->bgmap;
if(!bgMap) return;
int i, k;
for(i = 0; i < height; i++)
for(k = 0; k < width; k++)
set_pixel(sprt->x+k,sprt->y+i, *(bgMap + width*i + k), base);
bgMap = realloc(bgMap, sprt->width * sprt->height);
sprt->bgmap = bgMap;
}
void destroy_sprite(Sprite *sprt)
{
if (!sprt) return;
free(sprt->map);
free(sprt->bgmap);
free(sprt);
}
void animate_sprite(Sprite *sprt, char *base)
{
move_sprite(sprt, sprt->x + sprt->xspeed, sprt->y + sprt->yspeed, base);
}
void animate_sprite_rotated(Sprite *sprt, char *base, int angle)
{
if (sprt->bgmap != NULL)
delete_sprite_rotated(sprt, base, angle);
sprt->x += sprt->xspeed;
sprt->y += sprt->yspeed;
draw_sprite_rotated(sprt, base, angle);
//delay(20);
}
void move_sprite(Sprite *sprt, int x, int y, char *base)
{
int xi = (x > sprt->x) ? sprt->x : x;
int yi = (y > sprt->y) ? sprt->y : y;
int xf = (x > sprt->x) ? x + sprt->width : sprt->x + sprt->width;
int yf = (y > sprt->y) ? y + sprt->height : sprt->y + sprt->height;
video_buffer = realloc(video_buffer, HRES * VRES);
flip_buffer_partial(video_buffer, base, xi, yi, xf - xi, yf - yi);
delete_sprite(sprt, video_buffer);
sprt->x = x;
sprt->y = y;
draw_sprite(sprt, video_buffer);
flip_buffer_partial(base, video_buffer, xi, yi, xf - xi, yf - yi);
}
void flip_buffer(char* dest, char* src)
{
memcpy(dest, src, HRES*VRES);
}
void flip_buffer_partial(char* dest, char* src, int xi, int yi, int width, int height)
{
if(xi + width >= HRES)
width = HRES - xi;
if(xi < 0) {
width += xi;
xi = 0;
}
if(yi + height >= VRES)
height = VRES - yi;
if(yi < 0) {
height += yi;
yi = 0;
}
int i;
for (i = 0; i < height; i++)
memcpy(dest + (yi+i)*HRES + xi, src + (yi+i)*HRES + xi, width);
}
| 2.78125 | 3 |
2024-11-18T22:11:59.247569+00:00 | 2016-04-06T10:14:12 | eb1565c9936fdaf5f54b2d78732747e950639086 | {
"blob_id": "eb1565c9936fdaf5f54b2d78732747e950639086",
"branch_name": "refs/heads/master",
"committer_date": "2016-04-06T10:14:12",
"content_id": "4baa846aa966c67f6c57a7a67a1d1fc4ccd435ef",
"detected_licenses": [
"MIT"
],
"directory_id": "df9baf092803b7ad384089acfc01a7f0bbc42741",
"extension": "c",
"filename": "shmat_r.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 51303178,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 803,
"license": "MIT",
"license_type": "permissive",
"path": "/0127/shmat_r.c",
"provenance": "stackv2-0087.json.gz:13245",
"repo_name": "honeytavis/linux",
"revision_date": "2016-04-06T10:14:12",
"revision_id": "f5a148efb3fd3f5a06e846638c6a639909dcd1bc",
"snapshot_id": "b025f98eed70f13ad35bfeaad6584cf92639daa5",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/honeytavis/linux/f5a148efb3fd3f5a06e846638c6a639909dcd1bc/0127/shmat_r.c",
"visit_date": "2020-04-10T11:57:25.599640"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#define PROJ_ID 1
#define SHM_SIZE 4096
int main(int argc, char *argv[])
{
if (argc != 2) {
printf("error args!\n");
exit(0);
}
key_t skey = ftok(argv[1], PROJ_ID);
if (skey < 0) {
perror("ftok");
exit(-1);
}
printf("skey: %#x\n", skey);
//ipcs
//ipcrm -m shmid
int shmid = shmget(skey, SHM_SIZE, IPC_CREAT | 0600);
if (shmid < 0) {
perror("shmget");
exit(-1);
}
printf("shmid: %d\n", shmid);
char *shmptr = shmat(shmid, 0, 0);
if (shmptr == (void *)-1) {
perror("shmat") ;
exit(-1);
}
printf("share memory attach form %p to %p\n", (void *)shmptr, (void *)shmptr+SHM_SIZE);
//while(1);
printf("%c\n", *shmptr);
return 0;
}
| 2.34375 | 2 |
2024-11-18T22:12:00.084319+00:00 | 2021-08-09T22:00:32 | 644e3ff5c9e99a954a115a2f5baf92f074ed6075 | {
"blob_id": "644e3ff5c9e99a954a115a2f5baf92f074ed6075",
"branch_name": "refs/heads/master",
"committer_date": "2021-08-09T22:00:32",
"content_id": "601a09ac8a9859fb1e1429e10d97f33b94322643",
"detected_licenses": [
"MIT"
],
"directory_id": "b99728713825ff794dd889af09353aa477dca10e",
"extension": "c",
"filename": "csvprint.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3057,
"license": "MIT",
"license_type": "permissive",
"path": "/examples/csvprint.c",
"provenance": "stackv2-0087.json.gz:14021",
"repo_name": "vergaraed/libmba",
"revision_date": "2021-08-09T22:00:32",
"revision_id": "b082850ba9603c2f68c88cae32b9dccde26a6c4c",
"snapshot_id": "014e5db170416a4c56e1baf6cb65be74a5b1ec48",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/vergaraed/libmba/b082850ba9603c2f68c88cae32b9dccde26a6c4c/examples/csvprint.c",
"visit_date": "2023-07-31T13:18:23.013086"
} | stackv2 | #include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <errno.h>
#include <mba/msgno.h>
#include <mba/csv.h>
#define BUF_MAX 0x7FFF
#define ROW_MAX 0xFFF
int
run(const char *filename, const char *format, int filter, int count, int sep)
{
FILE *in;
unsigned char buf[BUF_MAX], *row[ROW_MAX];
int n, flags = CSV_TRIM | CSV_QUOTES;
if ((in = fopen(filename, "r")) == NULL) {
PMNF(errno, ": %s", filename);
return -1;
}
if (sep == '\t') {
flags &= ~CSV_QUOTES; /* do not interpret quotes with tab delimited files */
}
while ((n = csv_row_fread(in, buf, BUF_MAX, row, ROW_MAX, sep, flags)) > 0) {
const char *fmt = format;
char outbuf[BUF_MAX];
char *out = outbuf;
if (filter && strcmp(row[0], "0") == 0) {
continue;
}
while (*fmt) {
if (*fmt == '\\') {
fmt++;
switch (*fmt) {
case '\0':
return -1;
case 'n':
*out++ = '\n';
break;
case 't':
*out++ = '\t';
break;
case 'r':
*out++ = '\r';
break;
default:
*out++ = *fmt;
}
fmt++;
} else if (*fmt == '%') {
unsigned long i;
char *endptr;
fmt++;
if (*fmt == 'c') {
int n;
if ((n = sprintf(out, "%d", count)) == -1) {
PMNO(errno);
return -1;
}
out += n;
fmt++;
continue;
}
if ((i = strtoul(fmt, &endptr, 10)) == ULONG_MAX) {
PMNF(errno, ": %s", fmt);
return -1;
}
fmt = endptr;
if (i < ROW_MAX) {
const char *s = row[i];
if (s) {
while (*s) {
*out++ = *s++;
}
} else {
*out++ = '-';
}
}
} else {
*out++ = *fmt++;
}
}
*out = '\0';
count++;
fputs(outbuf, stdout);
}
if (n == -1) {
AMSG("");
return -1;
}
fclose(in);
return 0;
}
int
main(int argc, char *argv[])
{
char **args;
char *filename = NULL;
char *format = NULL;
int filter = 0;
unsigned long count = 1;
int sep = ',';
if (argc < 3) {
usage:
fprintf(stderr, "usage: %s [-f] [-s <sep>] <filename> <format>\n", argv[0]);
return EXIT_FAILURE;
}
errno = 0;
args = argv;
args++; argc--;
while (argc) {
if (strcmp(*args, "-f") == 0) {
filter = 1;
} else if (strcmp(*args, "-c") == 0) {
args++; argc--;
if ((count = strtoul(*args, NULL, 0)) == ULONG_MAX) {
fprintf(stderr, "invalid count value: %s", *args);
goto usage;
}
} else if (strcmp(*args, "-s") == 0) {
args++; argc--;
sep = **args;
if (sep == '\\') {
sep = *(*args + 1);
switch (sep) {
case 't':
sep = '\t';
break;
}
}
} else if (filename) {
if (format) {
fprintf(stderr, "invalid argument: %s\n", *args);
goto usage;
}
format = *args;
} else {
filename = *args;
}
args++; argc--;
}
if (run(filename, format, filter, count, sep) == -1) {
MMSG("Run failed.");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
| 2.6875 | 3 |
2024-11-18T22:12:01.468829+00:00 | 2016-07-12T01:29:35 | 2aba368d2756556526dbf41cf2062d8d4e164c1c | {
"blob_id": "2aba368d2756556526dbf41cf2062d8d4e164c1c",
"branch_name": "refs/heads/master",
"committer_date": "2016-07-12T01:29:35",
"content_id": "7c9abe7d7f0362b007fc5cec3b0527b10712f6fe",
"detected_licenses": [
"MIT"
],
"directory_id": "8947812c9c0be1f0bb6c30d1bb225d4d6aafb488",
"extension": "c",
"filename": "pngset.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 38571,
"license": "MIT",
"license_type": "permissive",
"path": "/01_Develop/libXMAtx/Source/PNG/pngset.c",
"provenance": "stackv2-0087.json.gz:14408",
"repo_name": "alissastanderwick/OpenKODE-Framework",
"revision_date": "2016-07-12T01:29:35",
"revision_id": "d4382d781da7f488a0e7667362a89e8e389468dd",
"snapshot_id": "cbb298974e7464d736a21b760c22721281b9c7ec",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/alissastanderwick/OpenKODE-Framework/d4382d781da7f488a0e7667362a89e8e389468dd/01_Develop/libXMAtx/Source/PNG/pngset.c",
"visit_date": "2021-10-25T01:33:37.821493"
} | stackv2 |
/* pngset.c - storage of image information into info struct
*
* Last changed in libpng 1.5.14 [January 24, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*
* The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data
* into the info struct for writing into the file. This abstracts the
* info struct and allows us to change the structure in the future.
*/
#include "pngpriv.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#ifdef PNG_bKGD_SUPPORTED
void PNGAPI
_png_set_bKGD(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_color_16p background)
{
_png_debug1(1, "in %s storage function", "bKGD");
if (_png_ptr == NULL || info_ptr == NULL)
return;
_png_memcpy(&(info_ptr->background), background, _png_sizeof(_png_color_16));
info_ptr->valid |= PNG_INFO_bKGD;
}
#endif
#ifdef PNG_cHRM_SUPPORTED
void PNGFAPI
_png_set_cHRM_fixed(_png_structp _png_ptr, _png_infop info_ptr,
_png_fixed_point white_x, _png_fixed_point white_y, _png_fixed_point red_x,
_png_fixed_point red_y, _png_fixed_point green_x, _png_fixed_point green_y,
_png_fixed_point blue_x, _png_fixed_point blue_y)
{
_png_debug1(1, "in %s storage function", "cHRM fixed");
if (_png_ptr == NULL || info_ptr == NULL)
return;
# ifdef PNG_CHECK_cHRM_SUPPORTED
if (_png_check_cHRM_fixed(_png_ptr,
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
# endif
{
info_ptr->x_white = white_x;
info_ptr->y_white = white_y;
info_ptr->x_red = red_x;
info_ptr->y_red = red_y;
info_ptr->x_green = green_x;
info_ptr->y_green = green_y;
info_ptr->x_blue = blue_x;
info_ptr->y_blue = blue_y;
info_ptr->valid |= PNG_INFO_cHRM;
}
}
void PNGFAPI
_png_set_cHRM_XYZ_fixed(_png_structp _png_ptr, _png_infop info_ptr,
_png_fixed_point int_red_X, _png_fixed_point int_red_Y,
_png_fixed_point int_red_Z, _png_fixed_point int_green_X,
_png_fixed_point int_green_Y, _png_fixed_point int_green_Z,
_png_fixed_point int_blue_X, _png_fixed_point int_blue_Y,
_png_fixed_point int_blue_Z)
{
_png_XYZ XYZ;
_png_xy xy;
_png_debug1(1, "in %s storage function", "cHRM XYZ fixed");
if (_png_ptr == NULL || info_ptr == NULL)
return;
XYZ.redX = int_red_X;
XYZ.redY = int_red_Y;
XYZ.redZ = int_red_Z;
XYZ.greenX = int_green_X;
XYZ.greenY = int_green_Y;
XYZ.greenZ = int_green_Z;
XYZ.blueX = int_blue_X;
XYZ.blueY = int_blue_Y;
XYZ.blueZ = int_blue_Z;
if (_png_xy_from_XYZ(&xy, XYZ))
_png_error(_png_ptr, "XYZ values out of representable range");
_png_set_cHRM_fixed(_png_ptr, info_ptr, xy.whitex, xy.whitey, xy.redx, xy.redy,
xy.greenx, xy.greeny, xy.bluex, xy.bluey);
}
# ifdef PNG_FLOATING_POINT_SUPPORTED
void PNGAPI
_png_set_cHRM(_png_structp _png_ptr, _png_infop info_ptr,
double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y)
{
_png_set_cHRM_fixed(_png_ptr, info_ptr,
_png_fixed(_png_ptr, white_x, "cHRM White X"),
_png_fixed(_png_ptr, white_y, "cHRM White Y"),
_png_fixed(_png_ptr, red_x, "cHRM Red X"),
_png_fixed(_png_ptr, red_y, "cHRM Red Y"),
_png_fixed(_png_ptr, green_x, "cHRM Green X"),
_png_fixed(_png_ptr, green_y, "cHRM Green Y"),
_png_fixed(_png_ptr, blue_x, "cHRM Blue X"),
_png_fixed(_png_ptr, blue_y, "cHRM Blue Y"));
}
void PNGAPI
_png_set_cHRM_XYZ(_png_structp _png_ptr, _png_infop info_ptr, double red_X,
double red_Y, double red_Z, double green_X, double green_Y, double green_Z,
double blue_X, double blue_Y, double blue_Z)
{
_png_set_cHRM_XYZ_fixed(_png_ptr, info_ptr,
_png_fixed(_png_ptr, red_X, "cHRM Red X"),
_png_fixed(_png_ptr, red_Y, "cHRM Red Y"),
_png_fixed(_png_ptr, red_Z, "cHRM Red Z"),
_png_fixed(_png_ptr, green_X, "cHRM Red X"),
_png_fixed(_png_ptr, green_Y, "cHRM Red Y"),
_png_fixed(_png_ptr, green_Z, "cHRM Red Z"),
_png_fixed(_png_ptr, blue_X, "cHRM Red X"),
_png_fixed(_png_ptr, blue_Y, "cHRM Red Y"),
_png_fixed(_png_ptr, blue_Z, "cHRM Red Z"));
}
# endif /* PNG_FLOATING_POINT_SUPPORTED */
#endif /* PNG_cHRM_SUPPORTED */
#ifdef PNG_gAMA_SUPPORTED
void PNGFAPI
_png_set_gAMA_fixed(_png_structp _png_ptr, _png_infop info_ptr, _png_fixed_point
file_gamma)
{
_png_debug1(1, "in %s storage function", "gAMA");
if (_png_ptr == NULL || info_ptr == NULL)
return;
/* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
* occur. Since the fixed point representation is assymetrical it is
* possible for 1/gamma to overflow the limit of 21474 and this means the
* gamma value must be at least 5/100000 and hence at most 20000.0. For
* safety the limits here are a little narrower. The values are 0.00016 to
* 6250.0, which are truly ridiculous gamma values (and will produce
* displays that are all black or all white.)
*/
if (file_gamma < 16 || file_gamma > 625000000)
_png_warning(_png_ptr, "Out of range gamma value ignored");
else
{
info_ptr->gamma = file_gamma;
info_ptr->valid |= PNG_INFO_gAMA;
}
}
# ifdef PNG_FLOATING_POINT_SUPPORTED
void PNGAPI
_png_set_gAMA(_png_structp _png_ptr, _png_infop info_ptr, double file_gamma)
{
_png_set_gAMA_fixed(_png_ptr, info_ptr, _png_fixed(_png_ptr, file_gamma,
"_png_set_gAMA"));
}
# endif
#endif
#ifdef PNG_hIST_SUPPORTED
void PNGAPI
_png_set_hIST(_png_structp _png_ptr, _png_infop info_ptr, _png_const_uint_16p hist)
{
int i;
_png_debug1(1, "in %s storage function", "hIST");
if (_png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->num_palette == 0 || info_ptr->num_palette
> PNG_MAX_PALETTE_LENGTH)
{
_png_warning(_png_ptr,
"Invalid palette size, hIST allocation skipped");
return;
}
_png_free_data(_png_ptr, info_ptr, PNG_FREE_HIST, 0);
/* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
* version 1.2.1
*/
_png_ptr->hist = (_png_uint_16p)_png_malloc_warn(_png_ptr,
PNG_MAX_PALETTE_LENGTH * _png_sizeof(_png_uint_16));
if (_png_ptr->hist == NULL)
{
_png_warning(_png_ptr, "Insufficient memory for hIST chunk data");
return;
}
for (i = 0; i < info_ptr->num_palette; i++)
_png_ptr->hist[i] = hist[i];
info_ptr->hist = _png_ptr->hist;
info_ptr->valid |= PNG_INFO_hIST;
info_ptr->free_me |= PNG_FREE_HIST;
}
#endif
void PNGAPI
_png_set_IHDR(_png_structp _png_ptr, _png_infop info_ptr,
_png_uint_32 width, _png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type,
int filter_type)
{
_png_debug1(1, "in %s storage function", "IHDR");
if (_png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->width = width;
info_ptr->height = height;
info_ptr->bit_depth = (_png_byte)bit_depth;
info_ptr->color_type = (_png_byte)color_type;
info_ptr->compression_type = (_png_byte)compression_type;
info_ptr->filter_type = (_png_byte)filter_type;
info_ptr->interlace_type = (_png_byte)interlace_type;
_png_check_IHDR (_png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
info_ptr->compression_type, info_ptr->filter_type);
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
info_ptr->channels = 1;
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
info_ptr->channels = 3;
else
info_ptr->channels = 1;
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
info_ptr->channels++;
info_ptr->pixel_depth = (_png_byte)(info_ptr->channels * info_ptr->bit_depth);
/* Check for potential overflow */
if (width >
(PNG_UINT_32_MAX >> 3) /* 8-byte RRGGBBAA pixels */
- 48 /* bigrowbuf hack */
- 1 /* filter byte */
- 7*8 /* rounding of width to multiple of 8 pixels */
- 8) /* extra max_pixel_depth pad */
info_ptr->rowbytes = 0;
else
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
}
#ifdef PNG_oFFs_SUPPORTED
void PNGAPI
_png_set_oFFs(_png_structp _png_ptr, _png_infop info_ptr,
_png_int_32 offset_x, _png_int_32 offset_y, int unit_type)
{
_png_debug1(1, "in %s storage function", "oFFs");
if (_png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_offset = offset_x;
info_ptr->y_offset = offset_y;
info_ptr->offset_unit_type = (_png_byte)unit_type;
info_ptr->valid |= PNG_INFO_oFFs;
}
#endif
#ifdef PNG_pCAL_SUPPORTED
void PNGAPI
_png_set_pCAL(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_charp purpose, _png_int_32 X0, _png_int_32 X1, int type,
int nparams, _png_const_charp units, _png_charpp params)
{
_png_size_t length;
int i;
_png_debug1(1, "in %s storage function", "pCAL");
if (_png_ptr == NULL || info_ptr == NULL)
return;
length = _png_strlen(purpose) + 1;
_png_debug1(3, "allocating purpose for info (%lu bytes)",
(unsigned long)length);
/* TODO: validate format of calibration name and unit name */
/* Check that the type matches the specification. */
if (type < 0 || type > 3)
_png_error(_png_ptr, "Invalid pCAL equation type");
/* Validate params[nparams] */
for (i=0; i<nparams; ++i)
if (!_png_check_fp_string(params[i], _png_strlen(params[i])))
_png_error(_png_ptr, "Invalid format for pCAL parameter");
info_ptr->pcal_purpose = (_png_charp)_png_malloc_warn(_png_ptr, length);
if (info_ptr->pcal_purpose == NULL)
{
_png_warning(_png_ptr, "Insufficient memory for pCAL purpose");
return;
}
_png_memcpy(info_ptr->pcal_purpose, purpose, length);
_png_debug(3, "storing X0, X1, type, and nparams in info");
info_ptr->pcal_X0 = X0;
info_ptr->pcal_X1 = X1;
info_ptr->pcal_type = (_png_byte)type;
info_ptr->pcal_nparams = (_png_byte)nparams;
length = _png_strlen(units) + 1;
_png_debug1(3, "allocating units for info (%lu bytes)",
(unsigned long)length);
info_ptr->pcal_units = (_png_charp)_png_malloc_warn(_png_ptr, length);
if (info_ptr->pcal_units == NULL)
{
_png_warning(_png_ptr, "Insufficient memory for pCAL units");
return;
}
_png_memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = (_png_charpp)_png_malloc_warn(_png_ptr,
(_png_size_t)((nparams + 1) * _png_sizeof(_png_charp)));
if (info_ptr->pcal_params == NULL)
{
_png_warning(_png_ptr, "Insufficient memory for pCAL params");
return;
}
_png_memset(info_ptr->pcal_params, 0, (nparams + 1) * _png_sizeof(_png_charp));
for (i = 0; i < nparams; i++)
{
length = _png_strlen(params[i]) + 1;
_png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
(unsigned long)length);
info_ptr->pcal_params[i] = (_png_charp)_png_malloc_warn(_png_ptr, length);
if (info_ptr->pcal_params[i] == NULL)
{
_png_warning(_png_ptr, "Insufficient memory for pCAL parameter");
return;
}
_png_memcpy(info_ptr->pcal_params[i], params[i], length);
}
info_ptr->valid |= PNG_INFO_pCAL;
info_ptr->free_me |= PNG_FREE_PCAL;
}
#endif
#ifdef PNG_sCAL_SUPPORTED
void PNGAPI
_png_set_sCAL_s(_png_structp _png_ptr, _png_infop info_ptr,
int unit, _png_const_charp swidth, _png_const_charp sheight)
{
_png_size_t lengthw = 0, lengthh = 0;
_png_debug1(1, "in %s storage function", "sCAL");
if (_png_ptr == NULL || info_ptr == NULL)
return;
/* Double check the unit (should never get here with an invalid
* unit unless this is an API call.)
*/
if (unit != 1 && unit != 2)
_png_error(_png_ptr, "Invalid sCAL unit");
if (swidth == NULL || (lengthw = _png_strlen(swidth)) == 0 ||
swidth[0] == 45 /* '-' */ || !_png_check_fp_string(swidth, lengthw))
_png_error(_png_ptr, "Invalid sCAL width");
if (sheight == NULL || (lengthh = _png_strlen(sheight)) == 0 ||
sheight[0] == 45 /* '-' */ || !_png_check_fp_string(sheight, lengthh))
_png_error(_png_ptr, "Invalid sCAL height");
info_ptr->scal_unit = (_png_byte)unit;
++lengthw;
_png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
info_ptr->scal_s_width = (_png_charp)_png_malloc_warn(_png_ptr, lengthw);
if (info_ptr->scal_s_width == NULL)
{
_png_warning(_png_ptr, "Memory allocation failed while processing sCAL");
return;
}
_png_memcpy(info_ptr->scal_s_width, swidth, lengthw);
++lengthh;
_png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
info_ptr->scal_s_height = (_png_charp)_png_malloc_warn(_png_ptr, lengthh);
if (info_ptr->scal_s_height == NULL)
{
_png_free (_png_ptr, info_ptr->scal_s_width);
info_ptr->scal_s_width = NULL;
_png_warning(_png_ptr, "Memory allocation failed while processing sCAL");
return;
}
_png_memcpy(info_ptr->scal_s_height, sheight, lengthh);
info_ptr->valid |= PNG_INFO_sCAL;
info_ptr->free_me |= PNG_FREE_SCAL;
}
# ifdef PNG_FLOATING_POINT_SUPPORTED
void PNGAPI
_png_set_sCAL(_png_structp _png_ptr, _png_infop info_ptr, int unit, double width,
double height)
{
_png_debug1(1, "in %s storage function", "sCAL");
/* Check the arguments. */
if (width <= 0)
_png_warning(_png_ptr, "Invalid sCAL width ignored");
else if (height <= 0)
_png_warning(_png_ptr, "Invalid sCAL height ignored");
else
{
/* Convert 'width' and 'height' to ASCII. */
char swidth[PNG_sCAL_MAX_DIGITS+1];
char sheight[PNG_sCAL_MAX_DIGITS+1];
_png_ascii_from_fp(_png_ptr, swidth, sizeof swidth, width,
PNG_sCAL_PRECISION);
_png_ascii_from_fp(_png_ptr, sheight, sizeof sheight, height,
PNG_sCAL_PRECISION);
_png_set_sCAL_s(_png_ptr, info_ptr, unit, swidth, sheight);
}
}
# endif
# ifdef PNG_FIXED_POINT_SUPPORTED
void PNGAPI
_png_set_sCAL_fixed(_png_structp _png_ptr, _png_infop info_ptr, int unit,
_png_fixed_point width, _png_fixed_point height)
{
_png_debug1(1, "in %s storage function", "sCAL");
/* Check the arguments. */
if (width <= 0)
_png_warning(_png_ptr, "Invalid sCAL width ignored");
else if (height <= 0)
_png_warning(_png_ptr, "Invalid sCAL height ignored");
else
{
/* Convert 'width' and 'height' to ASCII. */
char swidth[PNG_sCAL_MAX_DIGITS+1];
char sheight[PNG_sCAL_MAX_DIGITS+1];
_png_ascii_from_fixed(_png_ptr, swidth, sizeof swidth, width);
_png_ascii_from_fixed(_png_ptr, sheight, sizeof sheight, height);
_png_set_sCAL_s(_png_ptr, info_ptr, unit, swidth, sheight);
}
}
# endif
#endif
#ifdef PNG_pHYs_SUPPORTED
void PNGAPI
_png_set_pHYs(_png_structp _png_ptr, _png_infop info_ptr,
_png_uint_32 res_x, _png_uint_32 res_y, int unit_type)
{
_png_debug1(1, "in %s storage function", "pHYs");
if (_png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_pixels_per_unit = res_x;
info_ptr->y_pixels_per_unit = res_y;
info_ptr->phys_unit_type = (_png_byte)unit_type;
info_ptr->valid |= PNG_INFO_pHYs;
}
#endif
void PNGAPI
_png_set_PLTE(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_colorp palette, int num_palette)
{
_png_debug1(1, "in %s storage function", "PLTE");
if (_png_ptr == NULL || info_ptr == NULL)
return;
if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
{
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
_png_error(_png_ptr, "Invalid palette length");
else
{
_png_warning(_png_ptr, "Invalid palette length");
return;
}
}
/* It may not actually be necessary to set _png_ptr->palette here;
* we do it for backward compatibility with the way the _png_handle_tRNS
* function used to do the allocation.
*/
_png_free_data(_png_ptr, info_ptr, PNG_FREE_PLTE, 0);
/* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
* of num_palette entries, in case of an invalid PNG file that has
* too-large sample values.
*/
_png_ptr->palette = (_png_colorp)_png_calloc(_png_ptr,
PNG_MAX_PALETTE_LENGTH * _png_sizeof(_png_color));
_png_memcpy(_png_ptr->palette, palette, num_palette * _png_sizeof(_png_color));
info_ptr->palette = _png_ptr->palette;
info_ptr->num_palette = _png_ptr->num_palette = (_png_uint_16)num_palette;
info_ptr->free_me |= PNG_FREE_PLTE;
info_ptr->valid |= PNG_INFO_PLTE;
}
#ifdef PNG_sBIT_SUPPORTED
void PNGAPI
_png_set_sBIT(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_color_8p sig_bit)
{
_png_debug1(1, "in %s storage function", "sBIT");
if (_png_ptr == NULL || info_ptr == NULL)
return;
_png_memcpy(&(info_ptr->sig_bit), sig_bit, _png_sizeof(_png_color_8));
info_ptr->valid |= PNG_INFO_sBIT;
}
#endif
#ifdef PNG_sRGB_SUPPORTED
void PNGAPI
_png_set_sRGB(_png_structp _png_ptr, _png_infop info_ptr, int srgb_intent)
{
_png_debug1(1, "in %s storage function", "sRGB");
if (_png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->srgb_intent = (_png_byte)srgb_intent;
info_ptr->valid |= PNG_INFO_sRGB;
}
void PNGAPI
_png_set_sRGB_gAMA_and_cHRM(_png_structp _png_ptr, _png_infop info_ptr,
int srgb_intent)
{
_png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
if (_png_ptr == NULL || info_ptr == NULL)
return;
_png_set_sRGB(_png_ptr, info_ptr, srgb_intent);
# ifdef PNG_gAMA_SUPPORTED
_png_set_gAMA_fixed(_png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
# endif
# ifdef PNG_cHRM_SUPPORTED
_png_set_cHRM_fixed(_png_ptr, info_ptr,
/* color x y */
/* white */ 31270, 32900,
/* red */ 64000, 33000,
/* green */ 30000, 60000,
/* blue */ 15000, 6000
);
# endif /* cHRM */
}
#endif /* sRGB */
#ifdef PNG_iCCP_SUPPORTED
void PNGAPI
_png_set_iCCP(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_charp name, int compression_type,
_png_const_bytep profile, _png_uint_32 proflen)
{
_png_charp new_iccp_name;
_png_bytep new_iccp_profile;
_png_size_t length;
_png_debug1(1, "in %s storage function", "iCCP");
if (_png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
length = _png_strlen(name)+1;
new_iccp_name = (_png_charp)_png_malloc_warn(_png_ptr, length);
if (new_iccp_name == NULL)
{
_png_warning(_png_ptr, "Insufficient memory to process iCCP chunk");
return;
}
_png_memcpy(new_iccp_name, name, length);
new_iccp_profile = (_png_bytep)_png_malloc_warn(_png_ptr, proflen);
if (new_iccp_profile == NULL)
{
_png_free (_png_ptr, new_iccp_name);
_png_warning(_png_ptr,
"Insufficient memory to process iCCP profile");
return;
}
_png_memcpy(new_iccp_profile, profile, (_png_size_t)proflen);
_png_free_data(_png_ptr, info_ptr, PNG_FREE_ICCP, 0);
info_ptr->iccp_proflen = proflen;
info_ptr->iccp_name = new_iccp_name;
info_ptr->iccp_profile = new_iccp_profile;
/* Compression is always zero but is here so the API and info structure
* does not have to change if we introduce multiple compression types
*/
info_ptr->iccp_compression = (_png_byte)compression_type;
info_ptr->free_me |= PNG_FREE_ICCP;
info_ptr->valid |= PNG_INFO_iCCP;
}
#endif
#ifdef PNG_TEXT_SUPPORTED
void PNGAPI
_png_set_text(_png_structp _png_ptr, _png_infop info_ptr, _png_const_textp text_ptr,
int num_text)
{
int ret;
ret = _png_set_text_2(_png_ptr, info_ptr, text_ptr, num_text);
if (ret)
_png_error(_png_ptr, "Insufficient memory to store text");
}
int /* PRIVATE */
_png_set_text_2(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_textp text_ptr, int num_text)
{
int i;
_png_debug1(1, "in %lx storage function", _png_ptr == NULL ? "unexpected" :
(unsigned long)_png_ptr->chunk_name);
if (_png_ptr == NULL || info_ptr == NULL || num_text == 0)
return(0);
/* Make sure we have enough space in the "text" array in info_struct
* to hold all of the incoming text_ptr objects.
*/
if (num_text < 0 ||
num_text > INT_MAX - info_ptr->num_text - 8 ||
(unsigned int)/*SAFE*/(num_text +/*SAFE*/
info_ptr->num_text + 8) >=
PNG_SIZE_MAX/_png_sizeof(_png_text))
{
_png_warning(_png_ptr, "too many text chunks");
return(0);
}
if (info_ptr->num_text + num_text > info_ptr->max_text)
{
int old_max_text = info_ptr->max_text;
int old_num_text = info_ptr->num_text;
if (info_ptr->text != NULL)
{
_png_textp old_text;
info_ptr->max_text = info_ptr->num_text + num_text + 8;
old_text = info_ptr->text;
info_ptr->text = (_png_textp)_png_malloc_warn(_png_ptr,
(_png_size_t)(info_ptr->max_text * _png_sizeof(_png_text)));
if (info_ptr->text == NULL)
{
/* Restore to previous condition */
info_ptr->max_text = old_max_text;
info_ptr->text = old_text;
return(1);
}
_png_memcpy(info_ptr->text, old_text, (_png_size_t)(old_max_text *
_png_sizeof(_png_text)));
_png_free(_png_ptr, old_text);
}
else
{
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (_png_textp)_png_malloc_warn(_png_ptr,
(_png_size_t)(info_ptr->max_text * _png_sizeof(_png_text)));
if (info_ptr->text == NULL)
{
/* Restore to previous condition */
info_ptr->num_text = old_num_text;
info_ptr->max_text = old_max_text;
return(1);
}
info_ptr->free_me |= PNG_FREE_TEXT;
}
_png_debug1(3, "allocated %d entries for info_ptr->text",
info_ptr->max_text);
}
for (i = 0; i < num_text; i++)
{
_png_size_t text_length, key_len;
_png_size_t lang_len, lang_key_len;
_png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].key == NULL)
continue;
if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
{
_png_warning(_png_ptr, "text compression mode is out of range");
continue;
}
key_len = _png_strlen(text_ptr[i].key);
if (text_ptr[i].compression <= 0)
{
lang_len = 0;
lang_key_len = 0;
}
else
# ifdef PNG_iTXt_SUPPORTED
{
/* Set iTXt data */
if (text_ptr[i].lang != NULL)
lang_len = _png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != NULL)
lang_key_len = _png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
}
# else /* PNG_iTXt_SUPPORTED */
{
_png_warning(_png_ptr, "iTXt chunk not supported");
continue;
}
# endif
if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
{
text_length = 0;
# ifdef PNG_iTXt_SUPPORTED
if (text_ptr[i].compression > 0)
textp->compression = PNG_ITXT_COMPRESSION_NONE;
else
# endif
textp->compression = PNG_TEXT_COMPRESSION_NONE;
}
else
{
text_length = _png_strlen(text_ptr[i].text);
textp->compression = text_ptr[i].compression;
}
textp->key = (_png_charp)_png_malloc_warn(_png_ptr,
(_png_size_t)
(key_len + text_length + lang_len + lang_key_len + 4));
if (textp->key == NULL)
return(1);
_png_debug2(2, "Allocated %lu bytes at %p in _png_set_text",
(unsigned long)(_png_uint_32)
(key_len + lang_len + lang_key_len + text_length + 4),
textp->key);
_png_memcpy(textp->key, text_ptr[i].key,(_png_size_t)(key_len));
*(textp->key + key_len) = '\0';
if (text_ptr[i].compression > 0)
{
textp->lang = textp->key + key_len + 1;
_png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
*(textp->lang + lang_len) = '\0';
textp->lang_key = textp->lang + lang_len + 1;
_png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
*(textp->lang_key + lang_key_len) = '\0';
textp->text = textp->lang_key + lang_key_len + 1;
}
else
{
textp->lang=NULL;
textp->lang_key=NULL;
textp->text = textp->key + key_len + 1;
}
if (text_length)
_png_memcpy(textp->text, text_ptr[i].text,
(_png_size_t)(text_length));
*(textp->text + text_length) = '\0';
# ifdef PNG_iTXt_SUPPORTED
if (textp->compression > 0)
{
textp->text_length = 0;
textp->itxt_length = text_length;
}
else
# endif
{
textp->text_length = text_length;
textp->itxt_length = 0;
}
info_ptr->num_text++;
_png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
}
return(0);
}
#endif
#ifdef PNG_tIME_SUPPORTED
void PNGAPI
_png_set_tIME(_png_structp _png_ptr, _png_infop info_ptr, _png_const_timep mod_time)
{
_png_debug1(1, "in %s storage function", "tIME");
if (_png_ptr == NULL || info_ptr == NULL ||
(_png_ptr->mode & PNG_WROTE_tIME))
return;
if (mod_time->month == 0 || mod_time->month > 12 ||
mod_time->day == 0 || mod_time->day > 31 ||
mod_time->hour > 23 || mod_time->minute > 59 ||
mod_time->second > 60)
{
_png_warning(_png_ptr, "Ignoring invalid time value");
return;
}
_png_memcpy(&(info_ptr->mod_time), mod_time, _png_sizeof(_png_time));
info_ptr->valid |= PNG_INFO_tIME;
}
#endif
#ifdef PNG_tRNS_SUPPORTED
void PNGAPI
_png_set_tRNS(_png_structp _png_ptr, _png_infop info_ptr,
_png_const_bytep trans_alpha, int num_trans, _png_const_color_16p trans_color)
{
_png_debug1(1, "in %s storage function", "tRNS");
if (_png_ptr == NULL || info_ptr == NULL)
return;
if (num_trans < 0 || num_trans > PNG_MAX_PALETTE_LENGTH)
{
_png_warning(_png_ptr, "Ignoring invalid num_trans value");
return;
}
if (trans_alpha != NULL)
{
/* It may not actually be necessary to set _png_ptr->trans_alpha here;
* we do it for backward compatibility with the way the _png_handle_tRNS
* function used to do the allocation.
*/
_png_free_data(_png_ptr, info_ptr, PNG_FREE_TRNS, 0);
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
_png_ptr->trans_alpha = info_ptr->trans_alpha =
(_png_bytep)_png_malloc(_png_ptr, (_png_size_t)PNG_MAX_PALETTE_LENGTH);
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
_png_memcpy(info_ptr->trans_alpha, trans_alpha, (_png_size_t)num_trans);
}
if (trans_color != NULL)
{
int sample_max = (1 << info_ptr->bit_depth);
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
(int)trans_color->gray > sample_max) ||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
((int)trans_color->red > sample_max ||
(int)trans_color->green > sample_max ||
(int)trans_color->blue > sample_max)))
_png_warning(_png_ptr,
"tRNS chunk has out-of-range samples for bit_depth");
_png_memcpy(&(info_ptr->trans_color), trans_color,
_png_sizeof(_png_color_16));
if (num_trans == 0)
num_trans = 1;
}
info_ptr->num_trans = (_png_uint_16)num_trans;
if (num_trans != 0)
{
info_ptr->valid |= PNG_INFO_tRNS;
info_ptr->free_me |= PNG_FREE_TRNS;
}
}
#endif
#ifdef PNG_sPLT_SUPPORTED
void PNGAPI
_png_set_sPLT(_png_structp _png_ptr,
_png_infop info_ptr, _png_const_sPLT_tp entries, int nentries)
/*
* entries - array of _png_sPLT_t structures
* to be added to the list of palettes
* in the info structure.
*
* nentries - number of palette structures to be
* added.
*/
{
_png_sPLT_tp np;
int i;
if (_png_ptr == NULL || info_ptr == NULL)
return;
if (nentries < 0 ||
nentries > INT_MAX-info_ptr->splt_palettes_num ||
(unsigned int)/*SAFE*/(nentries +/*SAFE*/
info_ptr->splt_palettes_num) >=
PNG_SIZE_MAX/_png_sizeof(_png_sPLT_t))
np=NULL;
else
np = (_png_sPLT_tp)_png_malloc_warn(_png_ptr,
(info_ptr->splt_palettes_num + nentries) *
(_png_size_t)_png_sizeof(_png_sPLT_t));
if (np == NULL)
{
_png_warning(_png_ptr, "No memory for sPLT palettes");
return;
}
_png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * _png_sizeof(_png_sPLT_t));
_png_free(_png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes=NULL;
for (i = 0; i < nentries; i++)
{
_png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
_png_const_sPLT_tp from = entries + i;
_png_size_t length;
length = _png_strlen(from->name) + 1;
to->name = (_png_charp)_png_malloc_warn(_png_ptr, length);
if (to->name == NULL)
{
_png_warning(_png_ptr,
"Out of memory while processing sPLT chunk");
continue;
}
_png_memcpy(to->name, from->name, length);
to->entries = (_png_sPLT_entryp)_png_malloc_warn(_png_ptr,
from->nentries * _png_sizeof(_png_sPLT_entry));
if (to->entries == NULL)
{
_png_warning(_png_ptr,
"Out of memory while processing sPLT chunk");
_png_free(_png_ptr, to->name);
to->name = NULL;
continue;
}
_png_memcpy(to->entries, from->entries,
from->nentries * _png_sizeof(_png_sPLT_entry));
to->nentries = from->nentries;
to->depth = from->depth;
}
info_ptr->splt_palettes = np;
info_ptr->splt_palettes_num += nentries;
info_ptr->valid |= PNG_INFO_sPLT;
info_ptr->free_me |= PNG_FREE_SPLT;
}
#endif /* PNG_sPLT_SUPPORTED */
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
void PNGAPI
_png_set_unknown_chunks(_png_structp _png_ptr,
_png_infop info_ptr, _png_const_unknown_chunkp unknowns, int num_unknowns)
{
_png_unknown_chunkp np;
int i;
if (_png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
return;
if (num_unknowns < 0 ||
num_unknowns > INT_MAX-info_ptr->unknown_chunks_num ||
(unsigned int)/*SAFE*/(num_unknowns +/*SAFE*/
info_ptr->unknown_chunks_num) >=
PNG_SIZE_MAX/_png_sizeof(_png_unknown_chunk))
np=NULL;
else
np = (_png_unknown_chunkp)_png_malloc_warn(_png_ptr,
(_png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
_png_sizeof(_png_unknown_chunk));
if (np == NULL)
{
_png_warning(_png_ptr,
"Out of memory while processing unknown chunk");
return;
}
_png_memcpy(np, info_ptr->unknown_chunks,
(_png_size_t)info_ptr->unknown_chunks_num *
_png_sizeof(_png_unknown_chunk));
_png_free(_png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks = NULL;
for (i = 0; i < num_unknowns; i++)
{
_png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
_png_const_unknown_chunkp from = unknowns + i;
_png_memcpy(to->name, from->name, _png_sizeof(from->name));
to->name[_png_sizeof(to->name)-1] = '\0';
to->size = from->size;
/* Note our location in the read or write sequence */
to->location = (_png_byte)(_png_ptr->mode & 0xff);
if (from->size == 0)
to->data=NULL;
else
{
to->data = (_png_bytep)_png_malloc_warn(_png_ptr,
(_png_size_t)from->size);
if (to->data == NULL)
{
_png_warning(_png_ptr,
"Out of memory while processing unknown chunk");
to->size = 0;
}
else
_png_memcpy(to->data, from->data, from->size);
}
}
info_ptr->unknown_chunks = np;
info_ptr->unknown_chunks_num += num_unknowns;
info_ptr->free_me |= PNG_FREE_UNKN;
}
void PNGAPI
_png_set_unknown_chunk_location(_png_structp _png_ptr, _png_infop info_ptr,
int chunk, int location)
{
if (_png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
info_ptr->unknown_chunks_num)
info_ptr->unknown_chunks[chunk].location = (_png_byte)location;
}
#endif
#ifdef PNG_MNG_FEATURES_SUPPORTED
_png_uint_32 PNGAPI
_png_permit_mng_features (_png_structp _png_ptr, _png_uint_32 mng_features)
{
_png_debug(1, "in _png_permit_mng_features");
if (_png_ptr == NULL)
return (_png_uint_32)0;
_png_ptr->mng_features_permitted =
(_png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
return (_png_uint_32)_png_ptr->mng_features_permitted;
}
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
void PNGAPI
_png_set_keep_unknown_chunks(_png_structp _png_ptr, int keep, _png_const_bytep
chunk_list, int num_chunks)
{
_png_bytep new_list, p;
int i, old_num_chunks;
if (_png_ptr == NULL)
return;
if (num_chunks == 0)
{
if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
_png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
else
_png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
if (keep == PNG_HANDLE_CHUNK_ALWAYS)
_png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
else
_png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
return;
}
if (chunk_list == NULL)
return;
old_num_chunks = _png_ptr->num_chunk_list;
new_list=(_png_bytep)_png_malloc(_png_ptr,
(_png_size_t)(5*(num_chunks + old_num_chunks)));
if (_png_ptr->chunk_list != NULL)
{
_png_memcpy(new_list, _png_ptr->chunk_list,
(_png_size_t)(5*old_num_chunks));
_png_free(_png_ptr, _png_ptr->chunk_list);
_png_ptr->chunk_list=NULL;
}
_png_memcpy(new_list + 5*old_num_chunks, chunk_list,
(_png_size_t)(5*num_chunks));
for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
*p=(_png_byte)keep;
_png_ptr->num_chunk_list = old_num_chunks + num_chunks;
_png_ptr->chunk_list = new_list;
_png_ptr->free_me |= PNG_FREE_LIST;
}
#endif
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
void PNGAPI
_png_set_read_user_chunk_fn(_png_structp _png_ptr, _png_voidp user_chunk_ptr,
_png_user_chunk_ptr read_user_chunk_fn)
{
_png_debug(1, "in _png_set_read_user_chunk_fn");
if (_png_ptr == NULL)
return;
_png_ptr->read_user_chunk_fn = read_user_chunk_fn;
_png_ptr->user_chunk_ptr = user_chunk_ptr;
}
#endif
#ifdef PNG_INFO_IMAGE_SUPPORTED
void PNGAPI
_png_set_rows(_png_structp _png_ptr, _png_infop info_ptr, _png_bytepp row_pointers)
{
_png_debug1(1, "in %s storage function", "rows");
if (_png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
_png_free_data(_png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
if (row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
}
#endif
void PNGAPI
_png_set_compression_buffer_size(_png_structp _png_ptr, _png_size_t size)
{
if (_png_ptr == NULL)
return;
_png_free(_png_ptr, _png_ptr->zbuf);
if (size > ZLIB_IO_MAX)
{
_png_warning(_png_ptr, "Attempt to set buffer size beyond max ignored");
_png_ptr->zbuf_size = ZLIB_IO_MAX;
size = ZLIB_IO_MAX; /* must fit */
}
else
_png_ptr->zbuf_size = (uInt)size;
_png_ptr->zbuf = (_png_bytep)_png_malloc(_png_ptr, size);
/* The following ensures a relatively safe failure if this gets called while
* the buffer is actually in use.
*/
_png_ptr->zstream.next_out = _png_ptr->zbuf;
_png_ptr->zstream.avail_out = 0;
_png_ptr->zstream.avail_in = 0;
}
void PNGAPI
_png_set_invalid(_png_structp _png_ptr, _png_infop info_ptr, int mask)
{
if (_png_ptr && info_ptr)
info_ptr->valid &= ~mask;
}
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* This function was added to libpng 1.2.6 */
void PNGAPI
_png_set_user_limits (_png_structp _png_ptr, _png_uint_32 user_width_max,
_png_uint_32 user_height_max)
{
/* Images with dimensions larger than these limits will be
* rejected by _png_set_IHDR(). To accept any PNG datastream
* regardless of dimensions, set both limits to 0x7ffffffL.
*/
if (_png_ptr == NULL)
return;
_png_ptr->user_width_max = user_width_max;
_png_ptr->user_height_max = user_height_max;
}
/* This function was added to libpng 1.4.0 */
void PNGAPI
_png_set_chunk_cache_max (_png_structp _png_ptr,
_png_uint_32 user_chunk_cache_max)
{
if (_png_ptr)
_png_ptr->user_chunk_cache_max = user_chunk_cache_max;
}
/* This function was added to libpng 1.4.1 */
void PNGAPI
_png_set_chunk_malloc_max (_png_structp _png_ptr,
_png_alloc_size_t user_chunk_malloc_max)
{
if (_png_ptr)
_png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
}
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
_png_set_benign_errors(_png_structp _png_ptr, int allowed)
{
_png_debug(1, "in _png_set_benign_errors");
if (allowed)
_png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
else
_png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
}
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
/* Whether to report invalid palette index; added at libng-1.5.10
* allowed - one of 0: disable; 1: enable
*/
void PNGAPI
_png_set_check_for_invalid_index(_png_structp _png_ptr, int allowed)
{
_png_debug(1, "in _png_set_check_for_invalid_index");
if (allowed)
_png_ptr->num_palette_max = 0;
else
_png_ptr->num_palette_max = -1;
}
#endif
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
| 2.15625 | 2 |
2024-11-18T22:12:01.668065+00:00 | 2020-10-07T02:35:18 | efe8a772889e67b44aef79a833710ee1e86e37d9 | {
"blob_id": "efe8a772889e67b44aef79a833710ee1e86e37d9",
"branch_name": "refs/heads/master",
"committer_date": "2020-10-07T02:35:18",
"content_id": "d5725be3895b0544521cf1f385bd79c881e0df47",
"detected_licenses": [
"MIT"
],
"directory_id": "49acd1bf41c9651967e492f8294c8280bcf303e0",
"extension": "h",
"filename": "perfctr.h",
"fork_events_count": 1,
"gha_created_at": "2019-11-06T01:33:50",
"gha_event_created_at": "2020-10-07T02:35:19",
"gha_language": "C++",
"gha_license_id": "MIT",
"github_id": 219886102,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 16244,
"license": "MIT",
"license_type": "permissive",
"path": "/deps/dc/DreamHAL/perfctr.h",
"provenance": "stackv2-0087.json.gz:14537",
"repo_name": "einsteinx2/glex",
"revision_date": "2020-10-07T02:35:18",
"revision_id": "87c41fd03a30beb7272635efb4fe62917ab039f2",
"snapshot_id": "4ddd7a6a4937843e041ea95beec608a77a2957d8",
"src_encoding": "UTF-8",
"star_events_count": 7,
"url": "https://raw.githubusercontent.com/einsteinx2/glex/87c41fd03a30beb7272635efb4fe62917ab039f2/deps/dc/DreamHAL/perfctr.h",
"visit_date": "2021-07-17T19:28:03.085824"
} | stackv2 | // ---- perfctr.h - SH7750/SH7091 Performance Counter Module Header ----
//
// Version 1.0.4
//
// This file is part of the DreamHAL project, a hardware abstraction library
// primarily intended for use on the SH7091 found in hardware such as the SEGA
// Dreamcast game console.
//
// The performance counter module is hereby released into the public domain in
// the hope that it may prove useful. Now go profile some code and hit 60 fps! :)
//
// --Moopthehedgehog, December 2019
//
#ifndef __PERFCTR_H__
#define __PERFCTR_H__
//
// -- General SH4 Performance Counter Notes --
//
// There are 2 performance counters that can measure elapsed time. They are each
// 48-bit counters. They are part of the so-called "ASE" subsystem, which you can
// read about in chapter 13 of the "SuperH™ (SH) 32-bit RISC series SH-4, ST40
// system architecture, volume 1: system":
// https://www.st.com/content/ccc/resource/technical/document/user_manual/36/75/05/ac/e8/7e/42/2d/CD00147163.pdf/files/CD00147163.pdf/jcr:content/translations/en.CD00147163.pdf
//
// They can count cycles, so that's 199.5MHz (not 200MHz!!) a.k.a. roughly 5 ns
// increments. At 5 ns increments, a 48-bit cycle counter can run continuously
// for 16.33 days. It's actually 16 days, 7 hours, 55 minutes, and 2 seconds,
// depending on how close the bus clock is to 99.75MHz. There is also a second
// mode that counts cycles according to a ratio between the CPU frequency and
// the system bus clock, and it increments the counter by 12 every bus cycle.
// This second mode is detailed in the description for PMCR_CLOCK_TYPE in this
// file, and it is recommended for use when the CPU frequency is not a runtime
// constant.
//
// Side note: The counters don't have an overflow interrupt or overflow bit.
// (I did actually run one to 48-bit overflow in elapsed time mode using the
// ratio method to check this. They don't appear to sign-extend the upper 16
// bits in elapsed time mode, either.)
//
// The two counters are functionally identical. I would recommend using the
// PMCR_Init() function to start one (or both) up the first time.
//
// -- Configuration Address Info --
//
// Addresses for these counters can be easily seen here, in lxdream's source code:
// https://github.com/lutris/lxdream/blob/master/src/sh4/sh4mmio.h
//
// They are also on display in the Linux kernel, but at the time of writing appear
// to be set incorrectly (the clock mode at bit 0x100 is never set or cleared,
// for example, so they're at the mercy of whatever the hardware defaults are):
// http://git.lpclinux.com/cgit/linux-2.6.28.2-lpc313x/plain/arch/sh/oprofile/op_model_sh7750.c
// https://github.com/torvalds/linux/blob/master/arch/sh/kernel/cpu/sh4/perf_event.c
// ...It also appears as though they may not be handling bus ratio mode correctly,
// which appears to be the default mode on the Dreamcast in all my tests.
//
// You can also find these addresses by ripping a copy of Virtua Fighter 3 that
// you own for Dreamcast and looking at the raw byte code (or a raw disassembly)
// of its main program binary. It would appear as though they were timing a loop
// with the low half of perf counter 1 in elapsed time mode. Definitely seems
// like a good thing to do when targeting 60fps! Shenmue Disc 4 also uses the
// same configuration, but what's being timed is not as clear.
//
// Another place you can actually find both control addresses 0xFF00008x and all
// data addresses 0xFF10000x is in binaries of ancient, freely available versions
// of CodeScape. Literally all you need to do is open an SH7750-related DLL in a
// hex editor and do a search to find the control register addresses, and the
// data addresses are equally plain to see in any relevant performance profiling
// firmware. There's no effort or decryption required to find them whatsoever;
// all you need is an old trial version and a hex editor.
//
// However, something even better than all of that is if you search for "SH4
// 0xFF000084" (without quotes) online you'll find an old forum where some logs
// were posted of the terminal/command prompt output from some STMicro JTAG tool,
// which not only has the address registers but also clearly characterizes their
// size as 16-bit:
// https://www.multimediaforum.de/threads/36260834-alice-hsn-3800tw-usb-jtag-ft4232h/page2
//
// -- Event Mode Info --
//
// Specific information on each counter mode can be found in the document titled
// "SuperH™ Family E10A-USB Emulator: Additional Document for User’s Manual:
// Supplementary Information on Using the SH7750R Renesas Microcomputer Development Environment System"
// which is available on Renesas's website, in the "Documents" section of the
// E10A-USB product page:
// https://www.renesas.com/us/en/products/software-tools/tools/emulator/e10a-usb.html
// At the time of writing (12/2019), the E10A-USB adapter is still available
// for purchase, and it is priced around $1200 (USD).
//
// Appendix C of the "ST40 Micro Toolset Manual" also has these modes documented:
// https://www.st.com/content/ccc/resource/technical/document/user_manual/c5/98/11/89/50/68/41/66/CD17379953.pdf/files/CD17379953.pdf/jcr:content/translations/en.CD17379953.pdf
//
// See here for the hexadecimal values corresponding to each mode (pg. 370):
// http://www.macmadigan.com/BusaECU/Renesas%20documents/Hitachi_codescape_CS40_light_userguides.pdf
// You can also find the same "Counter Description Table" in user's guide PDFs
// bundled in ancient demo versions of CodeScape 3 from 2000 (e.g.
// CSDemo_272.exe), which can still be found in the Internet Archive.
// http://web.archive.org/web/*/http://codescape.com/dl/CSDemo/*
//
// See here for a support document on Lauterbach's SH2, SH3, and SH4 debugger,
// which contains units for each mode (e.g. which measure time and which just
// count): https://www.lauterbach.com/frames.html?home.html (It's in Downloads
// -> Trace32 Help System -> it's the file called "SH2, SH3 and SH4 Debugger"
// with the filename debugger_sh4.pdf).
//
//
// --- Performance Counter Registers ---
//
// These registers are 16 bits only and configure the performance counters
#define PMCR1_CTRL_REG 0xFF000084
#define PMCR2_CTRL_REG 0xFF000088
// These registers are 32-bits each and hold the high low parts of each counter
#define PMCTR1H_REG 0xFF100004
#define PMCTR1L_REG 0xFF100008
#define PMCTR2H_REG 0xFF10000C
#define PMCTR2L_REG 0xFF100010
//
// --- Performance Counter Configuration Flags ---
//
// These bits' functions are currently unknown, but they may simply be reserved.
// It's possible that there's a [maybe expired?] patent that details the
// configuration registers, though I haven't been able to find one. Places to
// check would be Google Patents and the Japanese Patent Office--maybe someone
// else can find something?
//
// Some notes:
// Writing 1 to all of these bits reads back as 0, so it looks like they aren't
// config bits. It's possible they are write-only like the stop bit, though,
// or that they're just reserved-write-0-only. It appears that they are always
// written with zeros in software that uses them, so that's confirmed safe to do.
//
// Also, after running counter 1 to overflow, it appears there's no overflow bit
// (maybe the designers thought 48-bits would be so much to count to that they
// didn't bother implementing one?). The upper 16-bits of the counter high
// register are also not sign-extension bits. They may be a hidden config area,
// but probably not because big endian mode would swap the byte order.
#define PMCR_UNKNOWN_BIT_0040 0x0040
#define PMCR_UNKNOWN_BIT_0080 0x0080
#define PMCR_UNKNOWN_BIT_0200 0x0200
#define PMCR_UNKNOWN_BIT_0400 0x0400
#define PMCR_UNKNOWN_BIT_0800 0x0800
#define PMCR_UNKNOWN_BIT_1000 0x1000
// PMCR_MODE_CLEAR_INVERTED just clears the event mode if it's inverted with
// '~', and event modes are listed below.
#define PMCR_MODE_CLEAR_INVERTED 0x003f
// PMCR_CLOCK_TYPE sets the counters to count clock cycles or CPU/bus ratio mode
// cycles (where T = C x B / 24 and T is time, C is count, and B is time
// of one bus cycle). Note: B = 1/99753008 or so, but it may vary, as mine is
// actually 1/99749010-ish; the target frequency is probably meant to be 99.75MHz.
//
// See the ST40 or Renesas SH7750R documents described in the above "Event Mode
// Info" section for more details about that formula.
//
// Set PMCR_CLOCK_TYPE to 0 for CPU cycle counting, where 1 count = 1 cycle, or
// set it to 1 to use the above formula. Renesas documentation recommends using
// the ratio version (set the bit to 1) when user programs alter CPU clock
// frequencies. This header has some definitions later on to help with this.
#define PMCR_CLOCK_TYPE 0x0100
#define PMCR_CLOCK_TYPE_SHIFT 8
// PMCR_STOP_COUNTER is write-only, as it always reads back as 0. It does what
// the name suggests: when this bit is written to, the counter stops. However,
// if written to while the counter is disabled or stopped, the counter's high
// and low registers are reset to 0.
//
// Using PMCR_STOP_COUNTER to stop the counter has the effect of holding the
// data in the data registers while stopped, unlike PMCR_DISABLE_COUNTER, and
// this bit needs to be written to again (e.g. on next start) in order to
// actually clear the counter data for another run. If not explicitly cleared,
// the counter will continue from where it left off before being stopped.
#define PMCR_STOP_COUNTER 0x2000
#define PMCR_RESET_COUNTER_SHIFT 13
// Bits 0xC000 both need to be set to 1 for the counters to actually begin
// counting. I have seen that the Linux kernel actually separates them out into
// two separate labelled bits (PMEN and PMST) for some reason, however they do
// not appear to do anything separately. Perhaps this is a two-bit mode where
// 1-1 is run, 1-0 and 0-1 are ???, and 0-0 is off.
#define PMCR_RUN_COUNTER 0xC000
#define PMCR_RUN_SHIFT 14
// Interestingly, the output here writes 0x6000 to the counter config registers,
// which would be the "PMST" bit and the "RESET" bit:
// https://www.multimediaforum.de/threads/36260834-alice-hsn-3800tw-usb-jtag-ft4232h/page2
// To disable a counter, just write 0 to its config register. This will not
// reset the counter to 0, as that requires an explicit clear via setting the
// PMCR_STOP_COUNTER bit. What's odd is that a disabled counter's data
// registers read back as all 0, but re-enabling it without a clear will
// continue from the last value before disabling.
#define PMCR_DISABLE_COUNTER 0x0000
// These definitions merely separate out the two PMCR_RUN_COUNTER bits, and
// they are included here for documentation purposes.
// PMST may mean PMCR START. It's consistently used to enable the counter.
// I'm just calling it PMST here for lack of a better name, since this is what
// the Linux kernel and lxdream call it. It could also have something to do with
// a mode specific to STMicroelectronics.
#define PMCR_PMST_BIT 0x4000
#define PMCR_PMST_SHIFT 14
// Likewise PMEN may mean PMCR ENABLE
#define PMCR_PMEN_BIT 0x8000
#define PMCR_PMEN_SHIFT 15
//
// --- Performance Counter Event Code Definitions ---
//
// Interestingly enough, it so happens that the SEGA Dreamcast's CPU seems to
// contain the same performance counter functionality as SH4 debug adapters for
// the SH7750R. Awesome!
//
// MODE DEFINITION VALUE MEASURMENT TYPE & NOTES
#define PMCR_INIT_NO_MODE 0x00 // None; Just here to be complete
#define PMCR_OPERAND_READ_ACCESS_MODE 0x01 // Quantity; With cache
#define PMCR_OPERAND_WRITE_ACCESS_MODE 0x02 // Quantity; With cache
#define PMCR_UTLB_MISS_MODE 0x03 // Quantity
#define PMCR_OPERAND_CACHE_READ_MISS_MODE 0x04 // Quantity
#define PMCR_OPERAND_CACHE_WRITE_MISS_MODE 0x05 // Quantity
#define PMCR_INSTRUCTION_FETCH_MODE 0x06 // Quantity; With cache
#define PMCR_INSTRUCTION_TLB_MISS_MODE 0x07 // Quantity
#define PMCR_INSTRUCTION_CACHE_MISS_MODE 0x08 // Quantity
#define PMCR_ALL_OPERAND_ACCESS_MODE 0x09 // Quantity
#define PMCR_ALL_INSTRUCTION_FETCH_MODE 0x0a // Quantity
#define PMCR_ON_CHIP_RAM_OPERAND_ACCESS_MODE 0x0b // Quantity
// No 0x0c
#define PMCR_ON_CHIP_IO_ACCESS_MODE 0x0d // Quantity
#define PMCR_OPERAND_ACCESS_MODE 0x0e // Quantity; With cache, counts both reads and writes
#define PMCR_OPERAND_CACHE_MISS_MODE 0x0f // Quantity
#define PMCR_BRANCH_ISSUED_MODE 0x10 // Quantity; Not the same as branch taken!
#define PMCR_BRANCH_TAKEN_MODE 0x11 // Quantity
#define PMCR_SUBROUTINE_ISSUED_MODE 0x12 // Quantity; Issued a BSR, BSRF, JSR, JSR/N
#define PMCR_INSTRUCTION_ISSUED_MODE 0x13 // Quantity
#define PMCR_PARALLEL_INSTRUCTION_ISSUED_MODE 0x14 // Quantity
#define PMCR_FPU_INSTRUCTION_ISSUED_MODE 0x15 // Quantity
#define PMCR_INTERRUPT_COUNTER_MODE 0x16 // Quantity
#define PMCR_NMI_COUNTER_MODE 0x17 // Quantity
#define PMCR_TRAPA_INSTRUCTION_COUNTER_MODE 0x18 // Quantity
#define PMCR_UBC_A_MATCH_MODE 0x19 // Quantity
#define PMCR_UBC_B_MATCH_MODE 0x1a // Quantity
// No 0x1b-0x20
#define PMCR_INSTRUCTION_CACHE_FILL_MODE 0x21 // Cycles
#define PMCR_OPERAND_CACHE_FILL_MODE 0x22 // Cycles
#define PMCR_ELAPSED_TIME_MODE 0x23 // Cycles; For 200MHz CPU: 5ns per count in 1 cycle = 1 count mode, or around 417.715ps per count (increments by 12) in CPU/bus ratio mode
#define PMCR_PIPELINE_FREEZE_BY_ICACHE_MISS_MODE 0x24 // Cycles
#define PMCR_PIPELINE_FREEZE_BY_DCACHE_MISS_MODE 0x25 // Cycles
// No 0x26
#define PMCR_PIPELINE_FREEZE_BY_BRANCH_MODE 0x27 // Cycles
#define PMCR_PIPELINE_FREEZE_BY_CPU_REGISTER_MODE 0x28 // Cycles
#define PMCR_PIPELINE_FREEZE_BY_FPU_MODE 0x29 // Cycles
//
// --- Performance Counter Support Definitions ---
//
// This definition can be passed as the init/enable/restart functions'
// count_type parameter to use the 1 cycle = 1 count mode. This is how the
// counter can be made to run for 16.3 days.
#define PMCR_COUNT_CPU_CYCLES 0
// Likewise this uses the CPU/bus ratio method
#define PMCR_COUNT_RATIO_CYCLES 1
// These definitions are for the enable function and specify whether to reset
// a counter to 0 or to continue from where it left off
#define PMCR_CONTINUE_COUNTER 0
#define PMCR_RESET_COUNTER 1
//
// --- Performance Counter Miscellaneous Definitions ---
//
// For convenience; assume stock bus clock of 99.75MHz
// (Bus clock is the external CPU clock, not the peripheral bus clock)
//
#define PMCR_SH4_CPU_FREQUENCY 199500000
#define PMCR_CPU_CYCLES_MAX_SECONDS 1410902
#define PMCR_SH4_BUS_FREQUENCY 99750000
#define PMCR_SH4_BUS_FREQUENCY_SCALED 2394000000 // 99.75MHz x 24
#define PMCR_BUS_RATIO_MAX_SECONDS 117575
//
// --- Performance Counter Functions ---
//
// See perfctr.c file for more details about each function and some more usage notes.
//
// Note: PMCR_Init() and PMCR_Enable() will do nothing if the perf counter is already running!
//
// Clear counter and enable
void PMCR_Init(unsigned char which, unsigned char mode, unsigned char count_type);
// Enable one or both of these "undocumented" performance counters.
void PMCR_Enable(unsigned char which, unsigned char mode, unsigned char count_type, unsigned char reset_counter);
// Disable, clear, and re-enable with new mode (or same mode)
void PMCR_Restart(unsigned char which, unsigned char mode, unsigned char count_type);
// Read a counter
// 48-bit value needs a 64-bit storage unit
// Return value of 0xffffffffffff means invalid 'which'
unsigned long long int PMCR_Read(unsigned char which);
// Get a counter's current configuration
// Return value of 0xffff means invalid 'which'
unsigned short PMCR_Get_Config(unsigned char which);
// Stop counter(s) (without clearing)
void PMCR_Stop(unsigned char which);
// Disable counter(s) (without clearing)
void PMCR_Disable(unsigned char which);
#endif /* __PERFCTR_H__ */
| 2.09375 | 2 |
2024-11-18T22:12:02.380900+00:00 | 2021-02-14T11:54:46 | 485f66c35f8b0608572e9487e7d6e1f0684f9fbf | {
"blob_id": "485f66c35f8b0608572e9487e7d6e1f0684f9fbf",
"branch_name": "refs/heads/master",
"committer_date": "2021-02-14T11:54:46",
"content_id": "1c10e702393657a5bfa56115e96aa03a3a0c9e18",
"detected_licenses": [
"ISC",
"BSD-2-Clause"
],
"directory_id": "fda858ab1b89249d8eed02cf456bc4d23b84d164",
"extension": "h",
"filename": "pca9555.h",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 327251222,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 991,
"license": "ISC,BSD-2-Clause",
"license_type": "permissive",
"path": "/libxsvf/pca9555.h",
"provenance": "stackv2-0087.json.gz:14925",
"repo_name": "lobinho/vienna-scope",
"revision_date": "2021-02-14T11:54:46",
"revision_id": "ee428efe6b8f2c4a813801c1fd826e2dcc407392",
"snapshot_id": "a34368f27f5275abdb90612b8509e50e2a088fd1",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/lobinho/vienna-scope/ee428efe6b8f2c4a813801c1fd826e2dcc407392/libxsvf/pca9555.h",
"visit_date": "2023-03-03T08:10:27.592860"
} | stackv2 | // PCA9555I2C - using only port 1
// with 100kHz we can use all jtag pins via I2C but TCK.
#define I2C_ADDRESS 0x20
#define I2C_BAUDRATE 100000
#define I2C_CMD_INPUT0 0x00
#define I2C_CMD_INPUT1 0x01
#define I2C_CMD_OUTPUT0 0x02
#define I2C_CMD_OUTPUT1 0x03
#define I2C_CMD_CONFIG0 0x06
#define I2C_CMD_CONFIG1 0x07
/*
Register addresses :
Command Register
0 Input port 0
1 Input port 1
2 Output port 0
3 Output port 1
4 Polarity Inversion port 0
5 Polarity Inversion port 1
6 Configuration port 0
7 Configuration port 1
*/
typedef union {
struct {
unsigned char FTDO : 1;
unsigned char FTDI : 1;
unsigned char FTCK : 1;
unsigned char FTMS : 1;
unsigned char FJTAGENB : 1;
unsigned char FPROG : 1;
unsigned char FINIT : 1;
unsigned char FDONE : 1;
} fields;
char byte;
} fpga_ctrl;
| 2.078125 | 2 |
2024-11-18T22:12:02.992291+00:00 | 2020-04-24T23:20:40 | 35f98a4e0718f45e4dad056de47ea1d2aa793898 | {
"blob_id": "35f98a4e0718f45e4dad056de47ea1d2aa793898",
"branch_name": "refs/heads/master",
"committer_date": "2020-04-24T23:20:40",
"content_id": "b24ccb3e8df05c0a0063a577da5a15c9d45acd76",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "48c2d779adc3ec016b996d1bb03c5f9b2605bb3f",
"extension": "c",
"filename": "caesar.c",
"fork_events_count": 0,
"gha_created_at": "2020-04-29T11:44:55",
"gha_event_created_at": "2020-04-29T11:44:56",
"gha_language": null,
"gha_license_id": null,
"github_id": 259910011,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2291,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/permutation/norx/ref/caesar.c",
"provenance": "stackv2-0087.json.gz:15698",
"repo_name": "wqweto/tinycrypt",
"revision_date": "2020-04-24T23:20:40",
"revision_id": "b6100cf07b7355643085dda326c13dcfcc804077",
"snapshot_id": "6aa72dab0fc553de87f7d925dd075fbc4347211b",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/wqweto/tinycrypt/b6100cf07b7355643085dda326c13dcfcc804077/permutation/norx/ref/caesar.c",
"visit_date": "2022-04-24T00:13:25.536111"
} | stackv2 | /*
* NORX reference source code package - reference C implementations
*
* Written 2014-2016 by:
*
* - Samuel Neves <sneves@dei.uc.pt>
* - Philipp Jovanovic <philipp@jovanovic.io>
*
* To the extent possible under law, the author(s) have dedicated all copyright
* and related and neighboring rights to this software to the public domain
* worldwide. This software is distributed without any warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication along with
* this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#if defined(SUPERCOP)
# include "crypto_aead.h"
#endif
#include "api.h"
#include "norx.h"
/*
the code for the cipher implementation goes here,
generating a ciphertext c[0],c[1],...,c[*clen-1]
from a plaintext m[0],m[1],...,m[mlen-1]
and associated data ad[0],ad[1],...,ad[adlen-1]
and secret message number nsec[0],nsec[1],...
and public message number npub[0],npub[1],...
and secret key k[0],k[1],...
*/
int crypto_aead_encrypt(
unsigned char *c, unsigned long long *clen,
const unsigned char *m, unsigned long long mlen,
const unsigned char *ad, unsigned long long adlen,
const unsigned char *nsec,
const unsigned char *npub,
const unsigned char *k
)
{
size_t outlen = 0;
norx_aead_encrypt(c, &outlen, ad, adlen, m, mlen, NULL, 0, npub, k);
*clen = outlen;
(void)nsec; /* avoid warning */
return 0;
}
/*
the code for the cipher implementation goes here,
generating a plaintext m[0],m[1],...,m[*mlen-1]
and secret message number nsec[0],nsec[1],...
from a ciphertext c[0],c[1],...,c[clen-1]
and associated data ad[0],ad[1],...,ad[adlen-1]
and public message number npub[0],npub[1],...
and secret key k[0],k[1],...
*/
int crypto_aead_decrypt(
unsigned char *m, unsigned long long *mlen,
unsigned char *nsec,
const unsigned char *c, unsigned long long clen,
const unsigned char *ad, unsigned long long adlen,
const unsigned char *npub,
const unsigned char *k
)
{
size_t outlen = 0;
int result = norx_aead_decrypt(m, &outlen, ad, adlen, c, clen, NULL, 0, npub, k);
*mlen = outlen;
(void)nsec; /* avoid warning */
return result;
}
| 2.15625 | 2 |
2024-11-18T22:12:03.091223+00:00 | 2014-06-17T16:51:31 | 5f2dd928584f149f137e4a692bd807c650eb961e | {
"blob_id": "5f2dd928584f149f137e4a692bd807c650eb961e",
"branch_name": "refs/heads/master",
"committer_date": "2014-06-17T16:51:31",
"content_id": "d7c6baab8de3b7140dbec937f68ffdff1dd04aa6",
"detected_licenses": [
"Unlicense"
],
"directory_id": "240c1c1de1011af4a3f49f296841fd1871dd7e32",
"extension": "c",
"filename": "list_double.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 903,
"license": "Unlicense",
"license_type": "permissive",
"path": "/rtmarco/src/list_double.c",
"provenance": "stackv2-0087.json.gz:15827",
"repo_name": "ChevalCorp/RayTracer",
"revision_date": "2014-06-17T16:51:31",
"revision_id": "2ddb6fa3059b2fcb6fc70e5f0d0a8ae203dde50d",
"snapshot_id": "ac129a0ef2546ee559b9f0615a63dd1b1415015c",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/ChevalCorp/RayTracer/2ddb6fa3059b2fcb6fc70e5f0d0a8ae203dde50d/rtmarco/src/list_double.c",
"visit_date": "2021-01-20T15:22:28.238544"
} | stackv2 | /*
** list_double.c for rtv1 in /home/lautel_m/rendu/MUL_2013_rtv1
**
** Made by marc-aurele lautel
** Login <lautel_m@epitech.net>
**
** Started on Fri Mar 14 11:29:06 2014 marc-aurele lautel
** Last update Sun Mar 16 21:44:52 2014 marc-aurele lautel
*/
#include "rtv1.h"
void showlist(t_rtv1 *rt)
{
t_obj *tmp;
int i;
i = 0;
tmp = rt->start;
while (i < rt->lenght)
{
tmp = tmp->next;
i++;
}
}
t_rtv1 *addlast(t_rtv1 *unelist)
{
t_obj *newelem;
if (unelist == NULL)
return (unelist);
if ((newelem = malloc(sizeof(t_obj))) != NULL)
{
newelem->next = NULL;
if (unelist->lenght == 0)
{
newelem->prev = NULL;
unelist->start = newelem;
unelist->end = newelem;
}
else
{
unelist->end->next = newelem;
newelem->prev = unelist->end;
unelist->end = newelem;
}
unelist->lenght++;
}
return (unelist);
}
| 2.75 | 3 |
2024-11-18T22:12:03.267817+00:00 | 2019-10-16T09:34:49 | b3411fa1591ad3e406739b48bb75c42236e7f35f | {
"blob_id": "b3411fa1591ad3e406739b48bb75c42236e7f35f",
"branch_name": "refs/heads/master",
"committer_date": "2019-10-16T09:34:49",
"content_id": "463139ff877542977ce787baa406778013d51392",
"detected_licenses": [
"MIT-Modern-Variant",
"ISC"
],
"directory_id": "8eeb4dc93d55619b20eba6b4fede07294240a856",
"extension": "c",
"filename": "indsprt.c",
"fork_events_count": 2,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 211876836,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1411,
"license": "MIT-Modern-Variant,ISC",
"license_type": "permissive",
"path": "/src/spice3/src/lib/dev/ind/indsprt.c",
"provenance": "stackv2-0087.json.gz:16084",
"repo_name": "space-tudelft/cacd",
"revision_date": "2019-10-16T09:34:49",
"revision_id": "8837293bb2c97edad986cf36ad8efe75387d9171",
"snapshot_id": "d7863c84e461726efeb0f5b52066eb70d02e6699",
"src_encoding": "UTF-8",
"star_events_count": 11,
"url": "https://raw.githubusercontent.com/space-tudelft/cacd/8837293bb2c97edad986cf36ad8efe75387d9171/src/spice3/src/lib/dev/ind/indsprt.c",
"visit_date": "2020-08-03T20:37:02.033704"
} | stackv2 | /**********
Copyright 1990 Regents of the University of California. All rights reserved.
Author: 1985 Thomas L. Quarles
**********/
/* Pretty print the sensitivity info for all
* the inductors in the circuit.
*/
#include "spice.h"
#include <stdio.h>
#include "util.h"
#include "smpdefs.h"
#include "cktdefs.h"
#include "inddefs.h"
#include "sperror.h"
void
INDsPrint(inModel,ckt)
GENmodel *inModel;
register CKTcircuit *ckt;
{
register INDmodel *model = (INDmodel*)inModel;
register INDinstance *here;
printf("INDUCTORS----------\n");
/* loop through all the inductor models */
for( ; model != NULL; model = model->INDnextModel ) {
printf("Model name:%s\n",(char*)model->INDmodName);
/* loop through all the instances of the model */
for (here = model->INDinstances; here != NULL ;
here=here->INDnextInstance) {
printf(" Instance name:%s\n",(char*)here->INDname);
printf(" Positive, negative nodes: %s, %s\n",
(char*)CKTnodName(ckt,here->INDposNode),(char*)CKTnodName(ckt,here->INDnegNode));
printf(" Branch Equation: %s\n",(char*)CKTnodName(ckt,here->INDbrEq));
printf(" Inductance: %g ",here->INDinduct);
printf(here->INDindGiven ? "(specified)\n" : "(default)\n");
printf(" INDsenParmNo:%d\n",here->INDsenParmNo);
}
}
}
| 2.359375 | 2 |
2024-11-18T22:12:03.391271+00:00 | 2020-01-20T16:55:41 | c58a800004a5214a1c78cf2e6083c11bef0b9e41 | {
"blob_id": "c58a800004a5214a1c78cf2e6083c11bef0b9e41",
"branch_name": "refs/heads/master",
"committer_date": "2020-01-20T16:55:41",
"content_id": "a2a68a8183e5c39c4bb6a6fbf0faa2293e08c21a",
"detected_licenses": [
"MIT"
],
"directory_id": "a440c772718c9ef87a78e321f2f435aa85751a3b",
"extension": "c",
"filename": "bench.c",
"fork_events_count": 0,
"gha_created_at": "2020-01-20T16:54:38",
"gha_event_created_at": "2020-01-20T16:54:39",
"gha_language": null,
"gha_license_id": "MIT",
"github_id": 235151073,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 8261,
"license": "MIT",
"license_type": "permissive",
"path": "/apps/wedge/bench.c",
"provenance": "stackv2-0087.json.gz:16341",
"repo_name": "xulai1001/dune",
"revision_date": "2020-01-20T16:55:41",
"revision_id": "045e64f20856405da1f286cb0ccaa049985c7962",
"snapshot_id": "3c634572ea48eb470740db5defdc3f8efad053ab",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/xulai1001/dune/045e64f20856405da1f286cb0ccaa049985c7962/apps/wedge/bench.c",
"visit_date": "2020-12-15T15:06:40.267464"
} | stackv2 | #include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <err.h>
#include <sys/syscall.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/mman.h>
#include <dune.h>
#include "sthread.h"
#define NR_REP 100
typedef void (*cb_t)(void);
static int _use_vmcall_gettimeofday;
static unsigned char *_crap;
static unsigned char *_crap2;
static unsigned char *_crappy;
static ptent_t *_pg1, *_pg2;
static int _pages;
static int usm_gettimeofday(struct timeval *tp, void *tzp)
{
int ret;
if (!_use_vmcall_gettimeofday)
return gettimeofday(tp, tzp);
asm("vmcall\n" : "=a" (ret)
: "a" (SYS_gettimeofday), "D" (tp), "S" (tzp));
return ret;
}
static int benchmark_latency(cb_t cb)
{
int i;
struct timeval a, b;
unsigned long t;
unsigned long avg = 0;
int num = 0;
int av;
for (i = 0; i < 10; i++) {
usm_gettimeofday(&a, NULL);
cb();
usm_gettimeofday(&b, NULL);
t = b.tv_sec - a.tv_sec;
if (t == 0)
t = b.tv_usec - a.tv_usec;
else {
t--;
t *= 1000 * 1000;
t += b.tv_usec;
t += 1000 * 1000 - a.tv_usec;
}
printf("Elapsed %luus\n", t);
if (i > 4) {
avg += t;
num++;
}
}
/* XXX roundf */
av = (int) ((double) avg / (double) num);
printf("Avg %d (%d samples)\n", av, num);
return av;
}
static void *thread(void* a)
{
// printf("In thread\n");
return NULL;
}
static void fork_bench(void)
{
int pid;
pid = fork();
if (pid == -1)
err(1, "fork()");
if (pid == 0) {
thread(NULL);
exit(0);
} else {
wait(NULL);
}
}
static void pthread_bench(void)
{
pthread_t pt;
if (pthread_create(&pt, NULL, thread, NULL) != 0)
err(1, "pthread_create()");
if (pthread_join(pt, NULL) != 0)
err(1, "pthread_join()");
}
static void sthread_bench(void)
{
sthread_t st;
sc_t sc;
sc_init(&sc);
if (sthread_create(&st, &sc, thread, NULL) != 0)
err(1, "sthread_create()");
if (sthread_join(st, NULL) != 0)
err(1, "sthread_join()");
}
static void http_bench(void)
{
int s;
struct sockaddr_in s_in;
char buf[1024];
char *ip = getenv("BENCH_IP");
if ((s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1)
err(1, "socket()");
memset(&s_in, 0, sizeof(s_in));
s_in.sin_family = PF_INET;
s_in.sin_port = htons(80);
s_in.sin_addr.s_addr = inet_addr(ip ? ip : "127.0.0.1");
if (connect(s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1)
err(1, "connect()");
snprintf(buf, sizeof(buf), "GET / HTTP/1.0\r\n\r\n");
if (write(s, buf, strlen(buf)) != strlen(buf))
err(1, "write()");
if (read(s, buf, sizeof(buf)) <= 0)
err(1, "read()");
close(s);
}
static void bench_http(void)
{
benchmark_latency(http_bench);
}
static void bench_sthreads(void)
{
int pid = fork();
if (pid == 0) {
printf("fork\n");
benchmark_latency(fork_bench);
printf("pthread\n");
benchmark_latency(pthread_bench);
exit(0);
} else
wait(NULL);
printf("sthread\n");
_use_vmcall_gettimeofday = 1;
if (sthread_init() == -1)
err(1, "sthread_init()");
benchmark_latency(sthread_bench);
}
static void set_assert(unsigned char *crap, unsigned char old, unsigned char new)
{
// printf("Crap [%p] is %u want %u setting %u\n", crap, *crap, old, new);
assert(*crap == old);
*crap = new;
}
static int setup_mem_cb(const void *arg, ptent_t *pte, void *va)
{
printf("PTE %lx addr %lx\n", *pte, PTE_ADDR(*pte));
*pte = (PTE_ADDR(*pte) + 4096) | PTE_P | PTE_W | PTE_U;
printf("PTE now %lx\n", *pte);
return 0;
}
static void setup_mem(void)
{
_pg1 = pgroot;
_pg2 = dune_vm_clone(_pg1);
dune_vm_page_walk(_pg1, _crap, _crap, setup_mem_cb, NULL);
}
static void no_switch(void)
{
int i;
for (i = 0; i < NR_REP; i++) {
*_crap = 0;
set_assert(_crap, 0, 1);
set_assert(_crap, 1, 2);
set_assert(_crap, 2, 3);
set_assert(_crap, 3, 4);
set_assert(_crap, 4, 5);
set_assert(_crap, 5, 6);
}
}
static void with_switch(void)
{
int i;
for (i = 0; i < NR_REP; i++) {
load_cr3((unsigned long) _pg2);
*_crap2 = 0;
set_assert(_crap2, 0, 1);
set_assert(_crap2, 1, 2);
load_cr3((unsigned long) _pg1);
set_assert(_crap, 2, 3);
set_assert(_crap, 3, 4);
load_cr3((unsigned long) _pg2);
set_assert(_crap2, 4, 5);
set_assert(_crap2, 5, 6);
}
}
static void with_switch_no_flush(void)
{
int i;
for (i = 0; i < NR_REP; i++) {
load_cr3((unsigned long) _pg2 | 1UL | CR3_NOFLUSH);
*_crap2 = 0;
set_assert(_crap2, 0, 1);
set_assert(_crap2, 1, 2);
load_cr3((unsigned long) _pg1 | 0UL | CR3_NOFLUSH);
set_assert(_crap, 2, 3);
set_assert(_crap, 3, 4);
load_cr3((unsigned long) _pg2 | 1UL | CR3_NOFLUSH);
set_assert(_crap2, 4, 5);
set_assert(_crap2, 5, 6);
}
}
static void ctx_switch(void)
{
load_cr3((unsigned long) _pg2);
set_assert(_crap2, 0, 1);
set_assert(_crap2, 1, 2);
load_cr3((unsigned long) _pg1);
set_assert(_crap, 2, 3);
set_assert(_crap, 3, 4);
load_cr3((unsigned long) _pg2);
set_assert(_crap2, 4, 5);
set_assert(_crap2, 5, 6);
}
static void syscall_handler(struct dune_tf *tf)
{
int syscall_num = (int) tf->rax;
printf("Got syscall %d\n", syscall_num);
dune_passthrough_syscall(tf);
}
static void do_pages(int p)
{
int i, j;
for (i = 0; i < NR_REP; i++) {
if (p == 0) {
} else if (p == 1) {
load_cr3((unsigned long) _pg2);
} else
load_cr3((unsigned long) _pg2 | 1UL | CR3_NOFLUSH);
for (j = 0; j < _pages; j++)
_crappy[j * 4096] = 0x69;
if (p == 0) {
} else if (p == 1) {
load_cr3((unsigned long) _pg1);
} else
load_cr3((unsigned long) _pg1 | 0UL | CR3_NOFLUSH);
for (j = 0; j < _pages; j++)
_crappy[j * 4096] = 0x69;
}
}
static void no_switch_pages(void)
{
do_pages(0);
}
static void switch_pages(void)
{
do_pages(1);
}
static void no_flush_switch_pages(void)
{
do_pages(2);
}
static void pwn_pages(int pages)
{
int a[3];
printf("Alright kids - pwning %d pages\n", pages);
_pages = pages;
_crappy = mmap(NULL, 4096 * pages, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (_crappy == MAP_FAILED)
err(1, "mmap()");
memset(_crappy, 0, 4096 * pages);
a[0] = benchmark_latency(no_switch_pages);
a[1] = benchmark_latency(switch_pages);
a[2] = benchmark_latency(no_flush_switch_pages);
printf("\n=============\n");
printf("result %d %d %d %d\n", pages, a[0], a[1], a[2]);
}
static void bench_switch(int pages, int pages_end)
{
printf("w00t\n");
_crap = mmap(NULL, 4096 * 2, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (_crap == MAP_FAILED)
err(1, "mmap()");
_crap2 = _crap + 4096;
printf("Crap %p crap2 %p\n", _crap, _crap2);
if (dune_init_and_enter())
errx(1, "dune_init_and_enter()");
_use_vmcall_gettimeofday = 1;
dune_register_syscall_handler(syscall_handler);
setup_mem();
ctx_switch();
printf("still alive\n");
printf("No switch\n");
benchmark_latency(no_switch);
printf("With switch\n");
benchmark_latency(with_switch);
printf("With switch no flush\n");
benchmark_latency(with_switch_no_flush);
if (pages) {
if (!pages_end)
pages_end = pages;
for (; pages <= pages_end; pages++)
pwn_pages(pages);
}
printf("Still ballin\n");
}
int main(int argc, char *argv[])
{
int bench = 0;
printf("w00t\n");
if (argc > 1)
bench = atoi(argv[1]);
switch (bench) {
case 0:
bench_sthreads();
break;
case 1:
bench_http();
break;
case 2:
bench_switch(atoi(argv[2]), atoi(argv[3]));
break;
}
printf("all done\n");
exit(0);
}
| 2.203125 | 2 |
2024-11-18T22:12:04.053821+00:00 | 2019-05-09T00:36:51 | 1821051aa2796a3bb22ea3744b82dca82df01fac | {
"blob_id": "1821051aa2796a3bb22ea3744b82dca82df01fac",
"branch_name": "refs/heads/master",
"committer_date": "2019-05-09T00:36:51",
"content_id": "9dc4bf6449e75c8d69abd30b1aaf4819e2700387",
"detected_licenses": [
"MIT"
],
"directory_id": "992e764ce018f62932cad1986580996838f3c4f0",
"extension": "c",
"filename": "healthbar.c",
"fork_events_count": 0,
"gha_created_at": "2019-02-22T18:59:29",
"gha_event_created_at": "2019-05-09T00:27:47",
"gha_language": "C",
"gha_license_id": "MIT",
"github_id": 172119356,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1485,
"license": "MIT",
"license_type": "permissive",
"path": "/src/game/entity/definitions/healthbar.c",
"provenance": "stackv2-0087.json.gz:16728",
"repo_name": "gravypod/it276-2d-game",
"revision_date": "2019-05-09T00:36:51",
"revision_id": "3780f46ab0817a247c72c075f76db7ee5d61f917",
"snapshot_id": "5e76778a4b8c88466fef74cba8bf719ca48a547f",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/gravypod/it276-2d-game/3780f46ab0817a247c72c075f76db7ee5d61f917/src/game/entity/definitions/healthbar.c",
"visit_date": "2020-04-24T16:43:57.717934"
} | stackv2 | #include "healthbar.h"
#include "player.h"
Sprite *health_sprite = NULL;
#define HEALTH_SPRITE_WIDTH 40
#define HEALTH_SPRITE_HEIGHT 40
void entity_healthbar_init(entity_t *entity)
{
entity->type = entity_type_healthbar;
entity->update = entity_healthbar_update;
entity->draw = entity_healthbar_draw;
entity->free = entity_healthbar_free;
// Not a world entity
entity->size.x = entity->size.y = 0;
entity->position.x = entity->position.y = 0;
if (!health_sprite) {
health_sprite = gf2d_sprite_load_image("images/kenny-nl/generic-items/genericItem_color_089.png");
}
}
void entity_healthbar_update(entity_t *entity)
{
if (player) {
entity->health = player->health;
}
}
void entity_healthbar_draw(entity_t *entity)
{
if (PLAYER_ALIVE()) {
const long max = PLAYER_MAX_HEALTH;
const long step = max / 10;
for (long i = 0; (i * step) < entity->health; i++) {
const long x = i * HEALTH_SPRITE_WIDTH, y = 10;
Vector2D position = {
.x = x,
.y = y
};
gf2d_sprite_draw(
health_sprite,
position,
NULL, NULL, NULL, NULL,
NULL,
0
);
}
}
}
void entity_healthbar_free(entity_t *entity)
{
if (health_sprite) {
gf2d_sprite_free(health_sprite);
health_sprite = NULL;
}
}
| 2.453125 | 2 |
2024-11-18T20:41:41.878229+00:00 | 2019-11-08T18:44:12 | 74405a3ab61960ccbb7f4fb819bdb5307d47ce1d | {
"blob_id": "74405a3ab61960ccbb7f4fb819bdb5307d47ce1d",
"branch_name": "refs/heads/master",
"committer_date": "2019-11-08T18:44:12",
"content_id": "52770d4219f1e84779d90a750028857bd9ec384f",
"detected_licenses": [
"MIT"
],
"directory_id": "ff17e2f2d15f0b8e47688ac377652829f639ab36",
"extension": "c",
"filename": "echolocation.c",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 219031181,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 300,
"license": "MIT",
"license_type": "permissive",
"path": "/tiebreaker/echolocation/echolocation.c",
"provenance": "stackv2-0091.json.gz:33",
"repo_name": "Vector35/csaw-2019-pwny-race",
"revision_date": "2019-11-08T18:44:12",
"revision_id": "28f2f0a9f9cdc037756fd4223852970d83bd171e",
"snapshot_id": "bfc7d68a8901e944a4c476bbbe82cd0fa3591cea",
"src_encoding": "UTF-8",
"star_events_count": 13,
"url": "https://raw.githubusercontent.com/Vector35/csaw-2019-pwny-race/28f2f0a9f9cdc037756fd4223852970d83bd171e/tiebreaker/echolocation/echolocation.c",
"visit_date": "2020-09-01T18:56:16.928393"
} | stackv2 | #include <stdio.h>
#include <stdlib.h>
void ask()
{
char buffer[128];
puts("Hello stranger, where are you?");
fflush(stdout);
gets(buffer);
printf("So you're in %s? That sounds great!", buffer);
}
int main()
{
ask();
return 0;
}
void win()
{
system("/bin/bash");
}
| 2.421875 | 2 |
2024-11-18T20:41:42.065865+00:00 | 2018-05-31T22:28:05 | 554e23fe4440de79fe12f2527bf42391c0eb5d29 | {
"blob_id": "554e23fe4440de79fe12f2527bf42391c0eb5d29",
"branch_name": "refs/heads/master",
"committer_date": "2018-05-31T22:28:05",
"content_id": "961fe1d67026915aa4909825311750321a2f60f0",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "fe0739df2526cec017a56cc78b6a14c6c1ceba38",
"extension": "c",
"filename": "dger_ejem.C",
"fork_events_count": 0,
"gha_created_at": "2018-01-30T08:25:41",
"gha_event_created_at": "2018-01-30T08:25:42",
"gha_language": null,
"gha_license_id": null,
"github_id": 119505574,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1317,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/entrega_tareas_de_C/tarea6/114535/codigo/dger_ejem.C",
"provenance": "stackv2-0091.json.gz:163",
"repo_name": "lmalpicas/analisis-numerico-computo-cientifico",
"revision_date": "2018-05-31T22:28:05",
"revision_id": "352d8501c3b7cb2dc632bc76460f5d1647e01573",
"snapshot_id": "31ef626a7056c7dbf542e911e90d958829f70c0e",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/lmalpicas/analisis-numerico-computo-cientifico/352d8501c3b7cb2dc632bc76460f5d1647e01573/entrega_tareas_de_C/tarea6/114535/codigo/dger_ejem.C",
"visit_date": "2018-07-05T19:46:44.448319"
} | stackv2 | #include<stdio.h>
#include<stdlib.h>
#include"definiciones.h"
#define A_matriz "A.txt"
#define v_vector "v.txt"
#define w_vector "w.txt"
extern void dger_( int *m, int *n, double *alpha, double *x, int *incx, double *y, int *incy, double *transpose_a, int *lda) ;
int main(int argc, char *argv[]){
arreglo_2d_T A;
arreglo_1d_T v, w;
int M=atoi(argv[1]);
int N=atoi(argv[2]);
int incx=1;
int incy=1;
int lda=M;
double ALPHA;
ALPHA = 2.0;
A=malloc(sizeof(*A));
v=malloc(sizeof(*v));
w=malloc(sizeof(*w));
renglones(A)=M;
columnas(A)=N;
renglones_vector(v)=M;
renglones_vector(w)=N;
entradas(A)=malloc(renglones(A)*columnas(A)*sizeof(double));
inicializa_matriz(A,A_matriz);
entradas_vector(v)=malloc(M*sizeof(double));
inicializa_vector(v,v_vector);
// vector A := alpha*x*y' + A,
entradas_vector(w)=malloc(N*sizeof(double));
inicializa_vector(w,w_vector);
printf("matriz A:\n");
imprime_matriz(A);
printf("------------\n");
printf("vector v :\n");
imprime_vector(v);
printf("vector w:\n");
imprime_vector(w);
dger_(&M, &N, &ALPHA, entradas_vector(v), &incx, entradas_vector(w), &incy, entradas(A), &lda);
printf("resultado 1:\n");
imprime_matriz(A);
free(entradas(A));
free(A);
free(entradas_vector(v));
free(entradas_vector(w));
free(v);
free(w);
return 0;
}
| 2.65625 | 3 |
2024-11-18T20:41:42.723162+00:00 | 2017-06-23T17:48:18 | b81911b6edd92832aee610c2d076a58fce622667 | {
"blob_id": "b81911b6edd92832aee610c2d076a58fce622667",
"branch_name": "refs/heads/master",
"committer_date": "2017-06-23T17:48:18",
"content_id": "e18f53ab2ebbac9555820e56fdd1aedbe0d0d461",
"detected_licenses": [
"MIT"
],
"directory_id": "de71ba9e10442bd6caa177e6d9d2f2c6be8425e3",
"extension": "c",
"filename": "unet-chat.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 83489604,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 6849,
"license": "MIT",
"license_type": "permissive",
"path": "/unet-chat.c",
"provenance": "stackv2-0091.json.gz:550",
"repo_name": "andymilburn/unet-helloworld",
"revision_date": "2017-06-23T17:48:18",
"revision_id": "0804c7dfb4897c6ede856b1b40ba7f9dfaa216fd",
"snapshot_id": "2b9c58023dda61f4c44bfe53f7592c7e7577e0ad",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/andymilburn/unet-helloworld/0804c7dfb4897c6ede856b1b40ba7f9dfaa216fd/unet-chat.c",
"visit_date": "2021-03-24T10:43:54.216180"
} | stackv2 | /*
* unet-chat
*
* Simple chat using unet sockets
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <getopt.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include "unet-common.h"
bool server_mode = true;
const char *server_id = "app.chat";
uint32_t message_type = 1200; /* hardcoded */
static const char usage_synopsis[] = "unet-chat [options] <server-address>";
static const char usage_short_opts[] = "m:i:hv";
static struct option const usage_long_opts[] = {
{ "mt", required_argument, NULL, 'm'},
{ "id", required_argument, NULL, 'i'},
{ "help", no_argument, NULL, 'h'},
{ "version", no_argument, NULL, 'v'},
{ NULL, no_argument, NULL, 0x0},
};
static const char * const usage_opts_help[] = {
"\n\tMessage type (default is 1200)",
"\n\tApplication id (default is app.chat)",
"\n\tPrint this help and exit",
"\n\tPrint version and exit",
NULL,
};
static void usage(const char *errmsg)
{
print_usage(errmsg, usage_synopsis, usage_short_opts,
usage_long_opts, usage_opts_help);
}
int main(int argc, char *argv[])
{
int s, err, opt, optidx, len;
struct sockaddr_unet server_sa, peer_sa, self_sa, in_sa;
char *server_ua_txt = NULL, *peer_ua_txt = NULL, *self_ua_txt = NULL, *p;
socklen_t slen;
fd_set rfds;
bool connected = false;
char line[256], buf[65536];
while ((opt = getopt_long(argc, argv, usage_short_opts,
usage_long_opts, &optidx)) != EOF) {
switch (opt) {
case 'm':
message_type = atoi(optarg);
break;
case 'i':
server_id = optarg;
break;
case 'v':
printf("Version: %s\n", PACKAGE_VERSION);
exit(EXIT_SUCCESS);
case 'h':
usage(NULL);
default:
usage("unknown option");
}
}
if (optind < argc)
server_mode = false;
memset(&server_sa, 0, sizeof(server_sa));
server_sa.sunet_family = AF_UNET;
server_sa.sunet_addr.message_type = message_type;
err = unet_str_to_addr(server_id, strlen(server_id), &server_sa.sunet_addr.addr);
if (err == -1) {
fprintf(stderr, "bad server id (%s) provided (%d:%s)\n",
server_id, errno, strerror(errno));
exit(EXIT_FAILURE);
}
s = socket(AF_UNET, SOCK_DGRAM, 0);
if (s == -1) {
perror("Failed to open unet socket (is unet enabled in your kernel?)");
exit(EXIT_FAILURE);
}
if (server_mode) {
server_ua_txt = unet_addr_to_str(&server_sa.sunet_addr.addr);
if (!server_ua_txt) {
perror("failed on unet_addr_to_str()");
exit(EXIT_FAILURE);
}
printf("server binding to '%s'\n", server_ua_txt);
free(server_ua_txt);
server_ua_txt = NULL;
err = bind(s, (struct sockaddr *)&server_sa, sizeof(server_sa));
if (err == -1) {
fprintf(stderr, "failed to bind using %s server_id (%d:%s)\n",
server_id, errno, strerror(errno));
exit(EXIT_FAILURE);
}
connected = false;
} else {
len = asprintf(&server_ua_txt, "%s:%s", argv[optind], server_id);
server_sa.sunet_family = AF_UNET;
server_sa.sunet_addr.message_type = message_type;
err = unet_str_to_addr(server_ua_txt, strlen(server_ua_txt), &server_sa.sunet_addr.addr);
if (err == -1) {
fprintf(stderr, "bad full server address (%s) provided (%d:%s)\n",
server_ua_txt, errno, strerror(errno));
exit(EXIT_FAILURE);
}
err = connect(s, (struct sockaddr *)&server_sa, sizeof(server_sa));
if (err == -1) {
fprintf(stderr, "failed to connect to full server address (%s) (%d:%s)\n",
server_ua_txt, errno, strerror(errno));
exit(EXIT_FAILURE);
}
/* now get sockname to get the full address */
memset(&peer_sa, 0, sizeof(peer_sa));
slen = sizeof(peer_sa);
err = getpeername(s,(struct sockaddr *)&peer_sa, &slen);
if (err == -1) {
perror("failed on getpeername()");
exit(EXIT_FAILURE);
}
peer_ua_txt = unet_addr_to_str(&peer_sa.sunet_addr.addr);
if (!peer_ua_txt) {
perror("failed on unet_addr_to_str()");
exit(EXIT_FAILURE);
}
connected = true;
}
/* now get sockname to get the full address */
memset(&self_sa, 0, sizeof(self_sa));
slen = sizeof(self_sa);
err = getsockname(s, (struct sockaddr *)&self_sa, &slen);
if (err == -1) {
perror("failed on getsockname()");
exit(EXIT_FAILURE);
}
self_ua_txt = unet_addr_to_str(&self_sa.sunet_addr.addr);
if (!self_ua_txt) {
perror("failed on unet_addr_to_str()");
exit(EXIT_FAILURE);
}
printf("Welcome to unet-chat; %s '%s'\n",
server_mode ? "listening for clients in" : "using server",
server_mode ? self_ua_txt : server_ua_txt);
printf("\r%s > ", self_ua_txt);
fflush(stdout);
FD_ZERO(&rfds);
for (;;) {
FD_SET(STDIN_FILENO, &rfds);
FD_SET(s, &rfds);
err = select(s + 1, &rfds, NULL, NULL, NULL);
if (err == -1) {
perror("select() failed");
exit(EXIT_FAILURE);
}
/* no data (probably EAGAIN) */
if (err == 0)
continue;
/* line read */
if (FD_ISSET(STDIN_FILENO, &rfds)) {
p = fgets(line, sizeof(line) - 1, stdin);
if (p) {
line[sizeof(line) - 1] = '\0';
len = strlen(line);
while (len > 0 && line[len-1] == '\n')
len--;
line[len] = '\0';
if (!connected) {
perror("not connected, so can't try send\n");
continue;
}
len = send(s, p, strlen(p), 0);
if (len == -1) {
perror("failed to send\n");
exit(EXIT_FAILURE);
}
}
printf("%s > ", self_ua_txt);
fflush(stdout);
} else if (FD_ISSET(s, &rfds)) {
/* first server packet */
slen = sizeof(in_sa);
len = recvfrom(s, buf, sizeof(buf) - 1, 0,
(struct sockaddr *)&in_sa, &slen);
if (len > 0) {
buf[len] = '\0';
slen = sizeof(in_sa);
if (!connected) {
memcpy(&peer_sa, &in_sa, sizeof(in_sa));
peer_ua_txt = unet_addr_to_str(&peer_sa.sunet_addr.addr);
if (!peer_ua_txt) {
perror("failed on unet_addr_to_str()");
exit(EXIT_FAILURE);
}
err = connect(s, (struct sockaddr *)&peer_sa, sizeof(peer_sa));
if (err == -1) {
fprintf(stderr, "failed to connect to peer address (%s) (%d:%s)\n",
peer_ua_txt, errno, strerror(errno));
exit(EXIT_FAILURE);
}
fprintf(stderr, "\nconnection from (%s)\n", peer_ua_txt);
connected = true;
}
/* do no allow more than one connection */
if (!unet_addr_eq(&peer_sa.sunet_addr.addr, &in_sa.sunet_addr.addr))
continue;
printf("\r%*s\r%s> %s\n", 80, "", peer_ua_txt, buf);
printf("%s > ", self_ua_txt);
fflush(stdout);
}
}
}
close(s);
if (server_ua_txt)
free(server_ua_txt);
if (peer_ua_txt)
free(peer_ua_txt);
if (self_ua_txt)
free(self_ua_txt);
return 0;
}
| 2.34375 | 2 |
2024-11-18T20:55:27.989698+00:00 | 2023-09-01T11:14:10 | 5ceadc51baa4a38652fced0459a15174016742cb | {
"blob_id": "5ceadc51baa4a38652fced0459a15174016742cb",
"branch_name": "refs/heads/main",
"committer_date": "2023-09-01T11:14:10",
"content_id": "2569aa4fded08ccfa83800aff05d512f5ba9496a",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "a41e1498e3c080f47abd8e8e57157548df3ebbf1",
"extension": "h",
"filename": "portable.h",
"fork_events_count": 18728,
"gha_created_at": "2010-08-24T01:37:33",
"gha_event_created_at": "2023-09-14T21:18:41",
"gha_language": "Python",
"gha_license_id": "BSD-3-Clause",
"github_id": 858127,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 779,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/pandas/_libs/include/pandas/portable.h",
"provenance": "stackv2-0092.json.gz:36221",
"repo_name": "pandas-dev/pandas",
"revision_date": "2023-09-01T11:14:10",
"revision_id": "c7325d7e7e77ecb4a4e57b48bc25265277c75712",
"snapshot_id": "e7e639454a298bebc272622e66faa9829ea393bb",
"src_encoding": "UTF-8",
"star_events_count": 36166,
"url": "https://raw.githubusercontent.com/pandas-dev/pandas/c7325d7e7e77ecb4a4e57b48bc25265277c75712/pandas/_libs/include/pandas/portable.h",
"visit_date": "2023-09-01T12:42:07.927176"
} | stackv2 | /*
Copyright (c) 2016, PyData Development Team
All rights reserved.
Distributed under the terms of the BSD Simplified License.
The full license is in the LICENSE file, distributed with this software.
*/
#pragma once
#include <string.h>
#if defined(_MSC_VER)
#define strcasecmp(s1, s2) _stricmp(s1, s2)
#endif
// GH-23516 - works around locale perf issues
// from MUSL libc, licence at LICENSES/MUSL_LICENSE
#define isdigit_ascii(c) (((unsigned)(c) - '0') < 10u)
#define getdigit_ascii(c, default) (isdigit_ascii(c) ? ((int)((c) - '0')) : default)
#define isspace_ascii(c) (((c) == ' ') || (((unsigned)(c) - '\t') < 5))
#define toupper_ascii(c) ((((unsigned)(c) - 'a') < 26) ? ((c) & 0x5f) : (c))
#define tolower_ascii(c) ((((unsigned)(c) - 'A') < 26) ? ((c) | 0x20) : (c))
| 2.078125 | 2 |
2024-11-18T20:55:28.627142+00:00 | 2018-10-10T02:25:09 | 051010f88cd9f69f8d42363372fe0f12129d8c74 | {
"blob_id": "051010f88cd9f69f8d42363372fe0f12129d8c74",
"branch_name": "refs/heads/master",
"committer_date": "2018-10-10T02:28:03",
"content_id": "5141271f1d9103475c7b3757bcd255ba85d3fbc1",
"detected_licenses": [
"MIT"
],
"directory_id": "56a01721a90b83844c11433438e017dd7e053101",
"extension": "c",
"filename": "SIDH.c",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 107059092,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 12321,
"license": "MIT",
"license_type": "permissive",
"path": "/SIDH.c",
"provenance": "stackv2-0092.json.gz:36995",
"repo_name": "armfazh/flor-sidh-x64",
"revision_date": "2018-10-10T02:25:09",
"revision_id": "2c690129a47ef90361c6e3351f4a75cf61484802",
"snapshot_id": "cc058facebad566bb7f61b28aebff8ea11c60ae8",
"src_encoding": "UTF-8",
"star_events_count": 10,
"url": "https://raw.githubusercontent.com/armfazh/flor-sidh-x64/2c690129a47ef90361c6e3351f4a75cf61484802/SIDH.c",
"visit_date": "2021-09-24T14:03:52.589283"
} | stackv2 | /********************************************************************************************
* SIDH: an efficient supersingular isogeny-based cryptography library for ephemeral
* Diffie-Hellman key exchange.
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*
* Abstract: supersingular elliptic curve isogeny parameters
*
*********************************************************************************************/
#include "SIDH_internal.h"
// Encoding of field elements, elements over Z_order, elements over GF(p^2) and elliptic curve points:
// --------------------------------------------------------------------------------------------------
// Elements over GF(p) and Z_order are encoded with the least significant octet (and digit) located
// at the leftmost position (i.e., little endian format).
// Elements (a+b*i) over GF(p^2), where a and b are defined over GF(p), are encoded as {b, a}, with b
// in the least significant position.
// Elliptic curve points P = (x,y) are encoded as {x, y}, with x in the least significant position.
//
// Curve isogeny system "SIDHp751". Base curve: Montgomery curve By^2 = Cx^3 + Ax^2 + Cx defined over GF(p751^2), where A=0, B=1 and C=1
//
CurveIsogenyStaticData CurveIsogeny_SIDHp751 = {
"SIDHp751", 768, 384, // Curve isogeny system ID, smallest multiple of 32 larger than the prime bitlength and smallest multiple of 32 larger than the order bitlength
751, // Bitlength of the prime
// Prime p751 = 2^372*3^239-1
{ 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xEEAFFFFFFFFFFFFF,
0xE3EC968549F878A8, 0xDA959B1A13F7CC76, 0x084E9867D6EBE876, 0x8562B5045CB25748, 0x0E12909F97BADC66, 0x00006FE5D541F71C },
// Base curve parameter "A"
{ 0 },
// Base curve parameter "C"
{ 1 },
// Order bitlength for Alice
372,
// Order of Alice's subgroup
{ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0010000000000000 },
// Order bitlength for Bob
379,
// Power of Bob's subgroup order
239,
// Order of Bob's subgroup
{ 0xC968549F878A8EEB, 0x59B1A13F7CC76E3E, 0xE9867D6EBE876DA9, 0x2B5045CB25748084, 0x2909F97BADC66856, 0x06FE5D541F71C0E1 },
// Alice's generator PA = (XPA,YPA), where XPA and YPA are defined over GF(p751)
{ 0x4B0346F5CCE233E9, 0x632646086CE3ACD5, 0x5661D14AB7347693, 0xA58A20449AF1F133, 0xB9AC2F40C56D6FA4, 0x8E561E008FA0E3F3,
0x6CAE096D5DB822C9, 0x83FDB7A4AD3E83E8, 0xB1317AD904386217, 0x3FA23F89F6BE06D2, 0x429C8D36FF46BCC9, 0x00003E82027A38E9,
0x12E0D620BFB341D5, 0x0F8EEA7370893430, 0x5A99EBEC3B5B8B00, 0x236C7FAC9E69F7FD, 0x0F147EF3BD0CFEC5, 0x8ED5950D80325A8D,
0x1E911F50BF3F721A, 0x163A7421DFA8378D, 0xC331B043DA010E6A, 0x5E15915A755883B7, 0xB6236F5F598D56EB, 0x00003BBF8DCD4E7E },
// Bob's generator PB = (XPB,YPB), where XPB and YPB are defined over GF(p751)
{ 0x76ED2325DCC93103, 0xD9E1DF566C1D26D3, 0x76AECB94B919AEED, 0xD3785AAAA4D646C5, 0xCB610E30288A7770, 0x9BD3778659023B9E,
0xD5E69CF26DF23742, 0xA3AD8E17B9F9238C, 0xE145FE2D525160E0, 0xF8D5BCE859ED725D, 0x960A01AB8FF409A2, 0x00002F1D80EF06EF,
0x91479226A0687894, 0xBBC6BAF5F6BA40BB, 0x15B529122CFE3CA6, 0x7D12754F00E898A3, 0x76EBA0C8419745E9, 0x0A94F06CDFB3EADE,
0x399A6EDB2EEB2F9B, 0xE302C5129C049EEB, 0xC35892123951D4B6, 0x15445287ED1CC55D, 0x1ACAF351F09AB55A, 0x00000127A46D082A },
// BigMont's curve parameter A24 = (A+2)/4
156113,
// BigMont's order, where BigMont is defined by y^2=x^3+A*x^2+x
{ 0xA59B73D250E58055, 0xCB063593D0BE10E1, 0xF6515CCB5D076CBB, 0x66880747EDDF5E20, 0xBA515248A6BFD4AB, 0x3B8EF00DDDDC789D,
0xB8FB25A1527E1E2A, 0xB6A566C684FDF31D, 0x0213A619F5BAFA1D, 0xA158AD41172C95D2, 0x0384A427E5EEB719, 0x00001BF975507DC7 },
// Montgomery constant Montgomery_R2 = (2^768)^2 mod p751
{ 0x233046449DAD4058, 0xDB010161A696452A, 0x5E36941472E3FD8E, 0xF40BFE2082A2E706, 0x4932CCA8904F8751 ,0x1F735F1F1EE7FC81,
0xA24F4D80C1048E18, 0xB56C383CCDB607C5, 0x441DD47B735F9C90, 0x5673ED2C6A6AC82A, 0x06C905261132294B, 0x000041AD830F1F35 },
// Montgomery constant -p751^-1 mod 2^768
{ 0x0000000000000001, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xEEB0000000000000,
0xE3EC968549F878A8, 0xDA959B1A13F7CC76, 0x084E9867D6EBE876, 0x8562B5045CB25748, 0x0E12909F97BADC66, 0x258C28E5D541F71C },
// Value one in Montgomery representation
{ 0x00000000000249ad, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x8310000000000000,
0x5527b1e4375c6c66, 0x697797bf3f4f24d0, 0xc89db7b2ac5c4e2e, 0x4ca4b439d2076956, 0x10f7926c7512c7e9, 0x00002d5b24bce5e2 }
};
// Fixed parameters for isogeny tree computation
const unsigned int splits_Alice[MAX_Alice] = {
0, 1, 1, 2, 2, 2, 3, 4, 4, 4, 4, 5, 5, 6, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 12,
11, 12, 12, 13, 14, 15, 16, 16, 16, 16, 16, 16, 17, 17, 18, 18, 17, 21, 17,
18, 21, 20, 21, 21, 21, 21, 21, 22, 25, 25, 25, 26, 27, 28, 28, 29, 30, 31,
32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 35, 36, 36, 33, 36, 35, 36, 36, 35,
36, 36, 37, 38, 38, 39, 40, 41, 42, 38, 39, 40, 41, 42, 40, 46, 42, 43, 46,
46, 46, 46, 48, 48, 48, 48, 49, 49, 48, 53, 54, 51, 52, 53, 54, 55, 56, 57,
58, 59, 59, 60, 62, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 65, 65, 65, 65,
65, 66, 67, 65, 66, 67, 66, 69, 70, 66, 67, 66, 69, 70, 69, 70, 70, 71, 72,
71, 72, 72, 74, 74, 75, 72, 72, 74, 74, 75, 72, 72, 74, 75, 75, 72, 72, 74,
75, 75, 77, 77, 79, 80, 80, 82 };
const unsigned int splits_Bob[MAX_Bob] = {
0, 1, 1, 2, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
10, 12, 12, 12, 12, 12, 12, 13, 14, 14, 15, 16, 16, 16, 16, 16, 17, 16, 16,
17, 19, 19, 20, 21, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 24, 24, 25, 27,
27, 28, 28, 29, 28, 29, 28, 28, 28, 30, 28, 28, 28, 29, 30, 33, 33, 33, 33,
34, 35, 37, 37, 37, 37, 38, 38, 37, 38, 38, 38, 38, 38, 39, 43, 38, 38, 38,
38, 43, 40, 41, 42, 43, 48, 45, 46, 47, 47, 48, 49, 49, 49, 50, 51, 50, 49,
49, 49, 49, 51, 49, 53, 50, 51, 50, 51, 51, 51, 52, 55, 55, 55, 56, 56, 56,
56, 56, 58, 58, 61, 61, 61, 63, 63, 63, 64, 65, 65, 65, 65, 66, 66, 65, 65,
66, 66, 66, 66, 66, 66, 66, 71, 66, 73, 66, 66, 71, 66, 73, 66, 66, 71, 66,
73, 68, 68, 71, 71, 73, 73, 73, 75, 75, 78, 78, 78, 80, 80, 80, 81, 81, 82,
83, 84, 85, 86, 86, 86, 86, 86, 87, 86, 88, 86, 86, 86, 86, 88, 86, 88, 86,
86, 86, 88, 88, 86, 86, 86, 93, 90, 90, 92, 92, 92, 93, 93, 93, 93, 93, 97,
97, 97, 97, 97, 97 };
const uint64_t LIST[22][NWORDS64_FIELD] = {
{ 0xC4EC4EC4EC4EDB72, 0xEC4EC4EC4EC4EC4E, 0x4EC4EC4EC4EC4EC4, 0xC4EC4EC4EC4EC4EC, 0xEC4EC4EC4EC4EC4E, 0x7464EC4EC4EC4EC4,
0x40E503E18E2D8BE1, 0x4C633882E467773F, 0x998CB725CB703B25, 0x51F8F01043ABC448, 0x70A53813C7A0B43A, 0x00006D56A7157672 },
{ 0x276276276275B6C1, 0x6276276276276276, 0x7627627627627627, 0x2762762762762762, 0x6276276276276276, 0x6377627627627627,
0x2F25DD32AAF69FE5, 0xC6FBECF3EDD1AA16, 0x29C9664A396A6297, 0x0110D8C47D20DEFD, 0x1322BABB1082C8DD, 0x00000CCBE6DE8350 },
{ 0x093B97EBDB11A7FE, 0x5093B97EBDB11A05, 0x05093B97EBDB11A0, 0xA05093B97EBDB11A, 0x1A05093B97EBDB11, 0x6F005093B97EBDB1,
0x7204A6634D6196D9, 0x1D6428F62F917BE5, 0x037CE7F8E9689A28, 0x913EC08959C36290, 0x03D1055241F89FDD, 0x000066963FEC58EB },
{ 0x98C2BA559CF4F604, 0xA98C2BA559CF516A, 0x6A98C2BA559CF516, 0x16A98C2BA559CF51, 0x516A98C2BA559CF5, 0x1A56A98C2BA559CF,
0xDD14E231C3FF5DDC, 0x5AB78BDF0FB0C987, 0x168ED3F1672906EC, 0xAEF17C4BE3A425E0, 0x6F1B34309268385F, 0x0000438BAFFC5E17 },
{ 0xA37CA5409E30BE12, 0x20D6AFD873D163ED, 0xCA5409E30BA70497, 0x6AFD873D163EDA37, 0x409E30BA7049720D, 0x7013D163EDA37CA5,
0x196C325CFB1D98A8, 0x2A83CC98457F6BB1, 0x157AA4649C505D94, 0x556B2CFA3ED1E977, 0x9C8FB301D3BE27CD, 0x0000659B5D688370 },
{ 0x437158A103E247EB, 0x23A9D7BF076A48BD, 0x158A103E256DD0AF, 0x9D7BF076A48BD437, 0xA103E256DD0AF23A, 0xD3776A48BD437158,
0xD4F7B332C1F74531, 0x6A60D92C4C627CD9, 0xC8009067FA1223C2, 0x195578D349C85ABC, 0x24DCFD2C3CE56026, 0x00001170D9C4A49E },
{ 0xBBC96234E708BFC3, 0xEE2CE77DBE4CE5A9, 0x21EF6EA93828AD37, 0x66C6ED51865018AE, 0xCB18F74253FB3379, 0x6231B31A5644369D,
0xF1831316FD5F9AD5, 0xD64412327D9D93D5, 0x2D9659AFA40085D6, 0xB872D3713E1F01AD, 0x96B929E85C90E590, 0x00002A0A122F3E1B },
{ 0x751DE109156C74F6, 0xC86993912AE79AFE, 0x96234E708BDAC04C, 0xCE77DBE4CE5A9BBC, 0xF6EA93828AD37EE2, 0x51B51865018AE21E,
0x57F8534430BDF5AF, 0xA5BA9F3225E0FA02, 0x05DBA7E2AB49759E, 0xE4706D1BDBA54763, 0xC5316BE14AF60ADD, 0x00002007A8A7A392 },
{ 0x2DEC0AC86E1972FF, 0xD121D09CA2E105D1, 0x258D13A0778EDFB2, 0x25140153000C1B6E, 0xA06B73718D440E30, 0xA46BFDEB49118BC0,
0x11C799EE82EF46CF, 0xF094D7258BE44445, 0x6B087550522BC899, 0xD4380D82ADEEA2D3, 0x2AFFEB03C6970E0B, 0x00004FF89FD0E867 },
{ 0xF48E11E080A36CD8, 0x75AA967CF316BF89, 0xED69E3E85A6CDEA8, 0x228638171449F794, 0xD4107549BB0BC6AE, 0xB7888349726731CC,
0x0589577AC89D03A2, 0x79218D005004DCD2, 0xA69CB3C82106FDB8, 0xE54D908CD9B31ED9, 0x2BB46423F8B44F5D, 0x0000158FC37F2F78 },
{ 0xA2B8F30D2D8B2266, 0x37AE9DA734F3D4D4, 0x4BC3AC46B1EE2D59, 0xA541D219D9E660D2, 0xFD629383B8C12367, 0x0E789576DA7C1E23,
0x2321F1135780B208, 0x059EED9A8BB7694E, 0x3EAC20CCA7C7B679, 0xADED37DC1395BAAB, 0xD701BA16F6CD4328, 0x0000250A355A8E3D },
{ 0x8D08D7B596C87C8E, 0xFC2B5A576AB81FA7, 0x4ED68A1C251D1EAD, 0xA6618E345258FA06, 0xB532F4F490BD3165, 0x0987A5FDBAA88699,
0x77E908F4AE484907, 0xC85226731C871CED, 0x6F3E5A699F216EC7, 0x70E42ADFCCD68C99, 0x2277864817AA0CAD, 0x000037F521DA6BAC },
{ 0xDB72B65CA8D1D274, 0x286A73457D063FD5, 0x7355642D132BA567, 0x2A970D9461C0DC41, 0x93D2A07ED36F3BCC, 0xFD59A18D2D03447E,
0xBC047FB33098286A, 0x153E65AE22E4D2F0, 0xBC3F628AF44DDCEB, 0xCF8C49463A2BEC5D, 0x64D31CBF9A0FAE5B, 0x00000E88DF789F48 },
{ 0x7E0E3CF3F602CC03, 0x240AE231C56EB636, 0x1630875FADB3CA47, 0x3FDF66239B9021FE, 0x4FA6BEA94AAE8287, 0x20BD32942BAEF1D9,
0x3DBE52BE754CD223, 0xD46D6B986A4C461E, 0x31772CCF6AB0EC49, 0x0362808B445792BE, 0xA57068B23D5D4F04, 0x0000233188CFA1F9 },
{ 0x5CFEB9EE80FF8802, 0x641C991F35243E77, 0x109BF7F4D15352D9, 0xF57027C40F2AEC39, 0x78834C224A9E8F4D, 0x3B53C38C5DDA4903,
0x2472CAD0E4A1DD20, 0x91121637EFEFBFEB, 0x555DDF1E4E875433, 0xD185E0CEBC9A6BF8, 0x247E7766FEA9846A, 0x00004E24131398C0 },
{ 0xAE911D5E41FDE1D5, 0x09FD291EAE9A7528, 0xD94DB04CE76D674F, 0xF269A050B317A36A, 0x1010C2464C5B488A, 0x165E22C0571F72CE,
0xB649686CDD7FAA40, 0xC65F833CCBC8E854, 0xA1DC607E92B4EC01, 0x6A9F6EA6C5D5598C, 0xB73B45E033D20693, 0x0000126974812437 },
{ 0x7EF889C1569E078D, 0x8B4790D31AFC6D2F, 0x24BAD80FCF2607D2, 0x13C099586804EDD0, 0x0B219830D09F67F8, 0xFEEBDD0A795A4E0D,
0x2C86D567D8A5A5C6, 0x29EFDB5516CD064B, 0xAFB0A05F0230B35C, 0x73FCFA65EC7C5CB4, 0x245E08DC310C14E1, 0x00001778AC2903DF },
{ 0xF2BF1FF8427C7315, 0x591042D093B90137, 0x23EF8D48782832C9, 0x8DFB39E92296E3D6, 0x0C39FF556BEBDD42, 0x369F6980A4270C5D,
0x901F9AD6FCBAA761, 0x0E8E81D435F5FC7F, 0x9A795B9A8409D3D3, 0xD29FB9AE4384290F, 0x3B58F53DD7270C90, 0x00001E27D50D0631 },
{ 0x838A7C8B0026C13C, 0xD38CAB350DC1F6BD, 0x426C57FE2436E928, 0xB81B289B8792A253, 0xF8EDB68037D3FB8E, 0x677EE0B4C50C01CD,
0xF43DCE6FED67139A, 0xF87EFEBF43D77877, 0x3EEA0E8543763A8A, 0x26E5A18357A35379, 0x55867648B9EA7D35, 0x000069DEC7A3C7DA },
{ 0x91CCFD3901F3F3FE, 0x2053992393125D73, 0x2129B3A10D7FF7C0, 0x74C64B3E68087A32, 0xEE46C5739B026DF9, 0x53E7B33F97EC0300,
0x14672E57801EC044, 0x18610440AA870975, 0xB6B9D9E0E0097AE6, 0x37AD3B922ED0F367, 0xA737A55936D5A8B8, 0x00005A30AF4F51DA },
{ 0xC925488939591E52, 0x8F87728BF0ED44E9, 0xF987EF64E4365147, 0x9338B89963265410, 0x340DA16F22024645, 0x5D295419E474BDC1,
0xBA0C2E509FC0510B, 0x957E35D641D5DDB5, 0x922F901AA4A236D8, 0xCBFA24C0F7E172E3, 0xB05A32F88CB5B9DC, 0x00001DC7A766A676 },
{ 0x6128F8C2B276D2A1, 0x857530A2A633CE28, 0xEB624F41494C5D1E, 0x3FA62AE33B92CCA8, 0x11BCABB4CC4FBE22, 0x91EA14743FDBAC70,
0x9876F7DF900DC277, 0x375FD25E09091CBA, 0x580F3084B099A111, 0x58E9B3FB623FB297, 0x957732F791F6C337, 0x00000B070F784B99 } }; | 2.21875 | 2 |
2024-11-18T20:55:29.361594+00:00 | 2011-06-23T19:56:21 | 5ad190ad0ca17a2f549c202d8f078bcde16ecc7b | {
"blob_id": "5ad190ad0ca17a2f549c202d8f078bcde16ecc7b",
"branch_name": "refs/heads/master",
"committer_date": "2011-06-23T19:56:21",
"content_id": "f9466e7af29a839f71b2db1b28daaed204d579f4",
"detected_licenses": [
"MIT"
],
"directory_id": "b94863b433cd7bfa38e05d94c96d62a67a541906",
"extension": "c",
"filename": "maincode.c",
"fork_events_count": 1,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 1209512,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 34147,
"license": "MIT",
"license_type": "permissive",
"path": "/OBSC/maincode.c",
"provenance": "stackv2-0092.json.gz:37381",
"repo_name": "alist/OpenSWARMS",
"revision_date": "2011-06-23T19:56:21",
"revision_id": "d0a845914b5cd1fde7731472e8aa8dbcccff277d",
"snapshot_id": "7bed80bd540086ed52a35333157a89d57331d1cd",
"src_encoding": "WINDOWS-1252",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/alist/OpenSWARMS/d0a845914b5cd1fde7731472e8aa8dbcccff277d/OBSC/maincode.c",
"visit_date": "2021-01-13T01:54:14.691480"
} | stackv2 | /*********************************************************
** All rights for this code have been reserved by their appropiate owners
** Creator and affiliated organizations have been removed to comply with
** competition regulations
** C 2008 - 2009
*///******************************************************
#include <p18f2620.h>
#include <delays.h>
#include <string.h>
#include <adc.h>
#include <pwm.h>
#include <EEP.h>
#include <usart.h>
#include "mainconfig.h"
#include "functionheaders.h"
//setup
void setup_ports(void);
void setup_device(void);
void setup_interrupts(void);
void setup_peripherals(void);
void activate_peripherals(void);
void initiate_services(void);
void InterruptHandlerHigh (void);
//test
void TestSendUSART(void);
void test_drive(void);
//procedures
int WaitForACK (void);
int set_servo_pos(char position); //sets servo location where 48 is centered >49 is right and <48 is left : returns 1 if number is out of bounds --return 0 if success
int set_drive_speed(char speed); //sets motor speed where 46 is neutral and > 48 is forward and <44 is back returns 1 if number is out of bounds --return 0 if success
void SendUSART(char byte);
void SendUSART_string (char bytes[], int size);
void input_router(char in_byte); //move the input to where it needs to be handled
void input_handler(char in_byte);
int Safe_WriteEEP(char bite_address, char bite_data); //1=success 0=fail wraps the read & write EEPs to make sure the data gets written
void Setup_Controller_Initiation(void); //setup the device for generic use
void Verbose_Mode(char ext_command); //enter textual mode
void config_utility_mode(char ext_command); //enter config mode
void TMR0Interrupt (void);
void TMR2Interrupt(void); //system tiner interrupt
void setupNextInput (void);//sets the adcon reg to be ready for next loop
void setup_mode(char ext_command);
void send_usart_text(int textId);
void toggle_settings(char letter1ofname);
void retrieve_eep_settings(void);//setup run settings
void handle_int0 (void);
void self_diag_Test (void); //self system test
char ADC_Convert_channel_8(void);
char ADC_Convert_channel_10(void);
char ADC_Convert_channel_11(void);
char get_sensor_data(char sensor); // returns current sensor value
char set_output(char output, int boolon); //sets output and returns new value
void set_number_digital_outputs(int asDigital); //go by number pin # 0,1,2,3 -- 2 sets pin 21, 22 digital -- zero sets all analog
//Omnicient variable
int current_outputs[2] = {0};
int systemIncrement = 0;
int nextAdcon = 1; //1-5 selects the next adcon to start getting
//encoder
int encoderHitsSinceLastCheck = 0;
int wheelRoundsPerCheck = 0;
int systemIsAutoSpeedCorrectingAtLevel = 0; //One if yes
int encoderLastValue = 1;
int lastSensorAN3[10] = {0};
int lastSensorAN8[10] = {0};
int lastSensorAN9[10] = {0};
int lastSensorAN10[10] = {0};
int lastSensorAN11[10] = {0};
int lastValueSetRow = 0;
void updateSensorValueSet(int anNumber, int value);
int getSensorAverage(int Sensor);
char recieve_single = 0;
char last_address = 0x00;// the spec works by addressing a peripheral
int error_state = 0; //if 1 -- system displays red led and stops working
int stopDriveOnINT0InterruptIsWaiting = 1; // if it is set to 1 then it is waiting until the timout timer can set it to zero
//motor definitions
int motor_max_f = 59;
int motor_min_b = 44;
int servo_max_r = 62;
int servo_min_l = 38;
int motor_current = 50;
int servo_current = 50;
//for eep
char read_char = 0;
char write_true_char = 'T';
char write_false_char = 'F';
int write_location = 0;
//modes
int verbose_mode_run = 0; //controls where data is routed from the usart 1= enabled
int config_utility_run = 0; //1 for enabled // non textual
char get_or_set = 'G';
int timeouts_enabled = 1; //1 for enabled of auto stop
int stopDriveOnINT0Interrupt = 0; //1 is yes
int manage_speed_mode_enabled = 0; //1 for enabled
int debug_mode_enabled = 1; //1 for enabled
int say_all_mode_enabled = 0; //dumps data while debugging
int controller_setup_mode_run = 0; //controls where data is routed from the usart 1= enabled
const far rom char system_info_text[103]= "\n\rSystem Info:\n\r8 Mghz\n\r19.2 k baud rate Serial\n\rPIC18F2620 Controller\n\rWireless Availible\n\r";
const far rom char reset_eep_setting_text[45]= "\n\rReset a setting due to an invalid value!\n\r";
const far rom char quit_text[14] = "\nResetting!\n\r";
const far rom char author_version[39] = "\n\rVr:2.03 OBSC -- Alexander List ECE\n"; //name/ version/date
const far rom char unknown_string[21] = "\n\rUnknown Command!\n";
const far rom char settings_menu_text[69] = "\n\rToggle Settings:\n\r1:Debug\n\r2:Chatty\n\r3:Timeouts\r\nQ:Quit\n";
const far rom char verbose_menu_text[77] = "\n\rVerbose:\n\r1:Setup\n\r2:Self Diagnostics\n\r3:System Info\n\r4:Design\n\rQ:Quit\n";
const far rom char sayall_mode_set_text[20] = "\n\rChatty Mode Set: ";
const far rom char debug_mode_set_text[19] = "\n\rDebug Mode Set: ";
const far rom char timeouts_set_text[23] = "\n\rMotor Timeouts Set: ";
const far rom char Ckey_continue_text[31] = "\n\rPress 'C' key to continue:\n\r";
const far rom char testing_info_text[130] = "\n\rTesting material in this order to recieve confirmations:\n\rMotor Forward/Reverse:\n\rServo Left/Right:\n\rSerial Port:\n\rLeds:\n\rEEP\n\r";
void main (void)
{
Setup_int_osc_2mhz;
setup_device();
initiate_services();
green_on; //run light on
SendUSART('R'); //ready
while (1)
{
green_on; //run light on
Delay10KTCYx(20);
while (error_state == 1)
{
red_on;
}
green_off;
yellow_off;
red_off;
Delay10KTCYx(80);
}
}
void TestSendUSART()
{
int testdata;
for (testdata = 1; testdata <255; testdata++)
{
SendUSART(testdata);
}
}
void test_drive()
{
yellow_on;
forward_slow_motor_pwm;
Delay10KTCYx(20);
set_servo_pos(58);
yellow_off;
neutral_motor_pwm;
Delay10KTCYx(150);
set_servo_pos(36);
yellow_on;
forward_medium_motor_pwm;
Delay10KTCYx(20);
yellow_off;
neutral_motor_pwm;
neutral_servo_pwm;
Delay10KTCYx(150);
}
void input_router(char in_byte)
{
if (verbose_mode_run == 1)
{
Verbose_Mode(in_byte);
}
else if (controller_setup_mode_run == 1)
{
setup_mode(in_byte);
}
else if (config_utility_run == 1)
{
config_utility_mode(in_byte);
}
else
{
input_handler(in_byte);
}
}
void input_handler(char in_byte)
{
reset_timeouts;
if (last_address != 0x00)
{
if (last_address == '1') //servo addr.
{
if (set_servo_pos(in_byte) == 1)
{
USART_ACK_BD; //bad data!
}
else
{
USART_ACK;
}
}
else if (last_address == '2') //motor add
{
if (set_drive_speed(in_byte) == 1)
{
USART_ACK_BD;
}
else
{
USART_ACK;
}
}
else if (last_address == '3') //demo
{
if (in_byte == '1')
{
USART_ACK;
test_drive();
}
else if (in_byte == '2')
{
TestSendUSART();
}
else
{
USART_ACK_BD;
}
}
else if (last_address == '4') //sensor polls
{
if (in_byte == '1') //sensor 1
{
SendUSART(get_sensor_data(1));
}
else if (in_byte == '2') //sensor 2
{
SendUSART(get_sensor_data(2));
// SendUSART(ADC_Convert_channel_10());
}
else if (in_byte == '3')//sensor 3
{
SendUSART(get_sensor_data(3));
// SendUSART(ADC_Convert_channel_8());
}
else if (in_byte == '4')//sensor 4
{
SendUSART(get_sensor_data(4));
}
else if (in_byte == '5')//sensor 5
{
SendUSART(get_sensor_data(5));
}
else if (in_byte == '6')//sensor 6
{
SendUSART(get_sensor_data(6));
}
else if (in_byte == '7')//sensor bank 7 -- ENCODER
{
SendUSART(wheelRoundsPerCheck);
}
else
{
USART_ACK_BD;
}
}
else if (last_address == '5')
{
if (in_byte == '1') //output1
{
if (current_outputs[0] == 0)
{
current_outputs[0] = 1;
set_output(1, 1); //#1 on
SendUSART('P');
}
else
{
current_outputs[0] = 0;
set_output(1, 0); //#1 off
SendUSART('F');
}
}
else if (in_byte == '2') //output 2
{
if (current_outputs[1] == 0)
{
current_outputs[1] = 1;
set_output(2, 1); //#2 on
SendUSART('P');
}
else
{
current_outputs[1] = 0;
set_output(2, 0); //#2 off
SendUSART('F');
}
}
else
{
USART_ACK_BD;
}
}
else if (last_address == 'C') //config
{
if (in_byte == 'N') //config verbose
{
Verbose_Mode(0x00);
//verbose mode
}
else if (in_byte == 'U') //config utility
{
config_utility_mode(0x00); //enter config mode
}
else
USART_ACK_BD;
}
clear_last_addr;
}
else
{
if (in_byte == 'S') //emerg_stop
{
stop_now;
error_state = 1;
USART_ACK;
}
else if (in_byte == 'A') //ack ack!
{
yellow_on;
USART_ACK;
}
else if (in_byte == 'R') //reset
{
if (debug_mode_enabled == 1)
{
send_usart_text(3);
}
USART_ACK;
stop_now;
_asm reset _endasm
}
else if (in_byte == 'N') //neutral -- different than stop -- doesnt disable
{
neutral_motor_pwm;
neutral_servo_pwm;
USART_ACK;
}
else if(in_byte == '1' || in_byte == '2' || in_byte == '3' || in_byte == '4' || in_byte == 'C' || (in_byte == '5'))
{
USART_ACK;
last_address = in_byte;
}
else //not a function -- bad data
{
if (debug_mode_enabled == 1)
{
SendUSART(in_byte);
}
else
{
USART_ACK_BD;
}
red_on;
return;
}
}
}
int Safe_WriteEEP(char bite_address, char bite_data)
{
//1=success 0=fail wraps the read & write EEP.h functions to make sure the data gets written
char testing_char;
Busy_eep ();
Write_b_eep(bite_address, bite_data);
Busy_eep ();
testing_char = Read_b_eep(bite_address);
if (bite_data == testing_char)
{
return 1;//good data
}
else
{
Busy_eep ();
Write_b_eep(bite_address, bite_data);
Busy_eep ();
testing_char = Read_b_eep(bite_address);
if (bite_data == testing_char)
{
return 1;//good data
}
}
return 0;
}
void Setup_Controller_Initiation(void)
{
//setup the device for generic use
for (write_location = 10; write_location <= 13; write_location++)
{
Safe_WriteEEP(write_location, write_false_char);
}
send_usart_text(6);
return;
}
void toggle_settings(char letterOFname) //toggle the settings with the 1 letter abr. auto string outputs
{
switch (letterOFname)
{
case 'T'://talky
EEP_Say_all_setup;
read_char = Read_b_eep(write_location);
send_usart_text(10);
if (read_char == write_true_char)
{
//set false
Safe_WriteEEP(write_location, write_false_char);
SendUSART(write_false_char);
}
else if (read_char == write_false_char)
{
//set true
Safe_WriteEEP(write_location, write_true_char);
SendUSART(write_true_char);
}
else
{
Setup_Controller_Initiation();
}
break;
case 'O': //timeouts
EEP_Timeouts_setup;
read_char = Read_b_eep(write_location);
send_usart_text(12);
if (read_char == write_true_char)
{
//set false
Safe_WriteEEP(write_location, write_false_char);
SendUSART(write_false_char);
}
else
{
//set true
Safe_WriteEEP(write_location, write_true_char);
SendUSART(write_true_char);
}
break;
case 'D': //debug mode
EEP_Debug_mode_setup;
read_char = Read_b_eep(write_location);
send_usart_text(11);
if (read_char == write_true_char)
{
//set false
Safe_WriteEEP(write_location, write_false_char);
SendUSART(write_false_char);
}
else
{
//set true
Safe_WriteEEP(write_location, write_true_char);
SendUSART(write_true_char);
}
break;
default:
break;
}
return;
}
void setup_mode(char ext_command)
{
if (last_address != 0)
{
clear_last_addr;
send_usart_text(5);
return;
}
if (ext_command == 0)
{
send_usart_text(5);
neutral_motor_pwm;
neutral_servo_pwm;
return;
}
switch(ext_command)
{
case '1':
toggle_settings('D');
//eeprom slot 1
//debug mode
break;
case '2':
toggle_settings('T');
//slot 2
//say all -- chatty mode
break;
case '3':
toggle_settings('O');
//slot 3
//drive timeouts
break;
case 'Q':
case 'q':
case 'R':
case 'r':
send_usart_text(3);
stop_now;
_asm reset _endasm
return;
break;
default:
send_usart_text(4);
break;
}
send_usart_text(5);
return;
}
void config_utility_mode(char ext_command) //enter config mode -- consol
{
if (ext_command == 'G')
{
USART_ACK;
get_or_set = 'G';
return;
}
else if (ext_command == 'S')
{
USART_ACK;
get_or_set = 'S';
return;
}
else if (ext_command == 'R')
{
stop_now;
_asm reset _endasm
return;
}
if (last_address == 0 && ext_command != 0 && get_or_set == 'S')
{
USART_ACK;
last_address = ext_command;
return;
}
if (ext_command == 0)
{
config_utility_run = 1;
USART_ACK;
clear_last_addr;
neutral_motor_pwm;
neutral_servo_pwm;
return;
}
if(get_or_set == 'G')
switch(ext_command)
{
case '1':
EEP_Debug_mode_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
//debug mode
break;
case '2':
EEP_Say_all_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
//say all -- chatty mode
break;
case '3':
EEP_Timeouts_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
//drive timeouts
break;
case '4':
//** Archaic -- does nothing!
EEP_NumberPinsDigital_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
break;
case '5':
EEP_Max_Motor_speed;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
break;
case '6':
EEP_Min_Motor_speed;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
break;
case '7':
EEP_Stop_inp1_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
break;
case '8':
EEP_Manage_Speed_setup;
read_char = Read_b_eep(write_location);
SendUSART(read_char);
break;
default:
USART_ACK_BD;
break;
}
if(get_or_set == 'S')
switch(last_address)
{
case '1':
EEP_Debug_mode_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//debug mode
break;
case '2':
EEP_Say_all_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//say all -- chatty mode
break;
case '3':
EEP_Timeouts_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//drive timeouts
break;
case '4':
EEP_NumberPinsDigital_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//ADC number of digital pins
break;
case '5':
EEP_Max_Motor_speed;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//max motor speed (unchanged)
break;
case '6':
EEP_Max_Motor_speed;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
//Maximum reverse speed -- min total
break;
case '7':
EEP_Stop_inp1_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
break;
case '8':
EEP_Manage_Speed_setup;
Safe_WriteEEP(write_location, ext_command);
USART_ACK;
break;
default:
USART_ACK_BD;
break;
}
if (last_address != ext_command)
{
clear_last_addr;
}
return;
}
void Verbose_Mode(char ext_command)
{
if (last_address != 0 && ext_command != 0)
{
/*if (last_address == '2')
{
if (ext_command == 'C')
{
send_usart_text(20);//Begin
Delay10KTCYx(254);
self_diag_Test ();
}
}
*/
clear_last_addr;
send_usart_text(2);
return;
}
if (ext_command == 0)
{
send_usart_text(2);
verbose_mode_run = 1;
Stop_Timer0;
neutral_motor_pwm;
neutral_servo_pwm;
return;
}
switch(ext_command)
{
case '1':
controller_setup_mode_run = 1;
verbose_mode_run = 0;
setup_mode(0);
break;
case '2': //self test
self_diag_Test ();
break;
case '3': //system info
send_usart_text(7);
break;
case '4'://design
send_usart_text(1);
break;
case 'Q':
case 'q':
case 'R':
case 'r':
send_usart_text(3);
stop_now;
_asm reset _endasm
return;
break;
default:
send_usart_text(4);
break;
}
if (verbose_mode_run == 1){ send_usart_text(2); } //give main menu, system doesnt live update
return;
} //enter textual mode
void self_diag_Test (void)
{
Gbl_Ints_DISABLED;
Busy_eep ();
forward_slow_motor_pwm;
SendUSART('F');
Delay10KTCYx(100);
backward_motor_pwm;
SendUSART('B');
Delay10KTCYx(100);
Busy_eep ();
set_servo_pos(62);
SendUSART('R');
Delay10KTCYx(100);
Busy_eep ();
set_servo_pos(36);
SendUSART('L');
Delay10KTCYx(100);
Busy_eep ();
TestSendUSART();
SendUSART('S');
Delay10KTCYx(100);
Busy_eep ();
green_on;
yellow_on;
red_on;
SendUSART('L');
Delay10KTCYx(254);
if(Safe_WriteEEP(1, write_true_char) == 1)
{
SendUSART('E');
Delay10KTCYx(254);
}
send_usart_text(3);
stop_now;
_asm reset _endasm
}
void SendUSART(char byte)
{
yellow_on;
while(PIR1bits.TXIF != 1)//while the previous send is not clear
{};
TXREG = byte;
yellow_off;
}
void SendUSART_string (char bytes[], int size)
{
int loop_int = 0;
for (loop_int = 0; loop_int < size; loop_int++)
{
SendUSART(bytes[loop_int]);
}
return;
}
int set_servo_pos(char position)
{
servo_current = position;
if (position > servo_max_r || position < servo_min_l)
{
neutral_servo_pwm;//48
red_on;
return 1;
}
else
{
input_servo_fix;
CCPR2L = position;
return 0;
}
}
int set_drive_speed(char speed)
{
motor_current = speed;
if (speed > motor_max_f || speed < motor_min_b )
{
neutral_motor_pwm;//46
red_on;
return 1; //bad input
}
else
{
input_speed_fix;
CCPR1L = speed;
return 0; //good input
}
}
void setup_device()
{
setup_ports();
setup_peripherals();
retrieve_eep_settings();
setup_interrupts();
}
char ADC_Convert_channel_8(void)
{
int result;
ADCON1 = 0b00000110; //setup analog/digital
ADCON0 = 0b00100000; //1000 = Channel 8 (AN8)
ADCON2 = 0b10101100; //1 = Right justified Unimplemented: Read as ‘0’ 101 = 12 TAD 100 = FOSC/4
ADCON0bits.ADON = 1; //1 = A/D Converter module is enabled
Delay10TCYx(30); // Delay for 50TCY
ADCON0bits.GO_DONE = 1; //start conversion
while(ADCON0bits.GO_DONE != 0) //wait for finnish
{
Delay1TCY(); //nop
}
result = ADRESL; //:ADRESL; // Read result
ADCON0bits.ADON = 0; //1 = A/D Converter module is enabled
return result;
}
char ADC_Convert_channel_10(void)
{
int result;
ADCON1 = 0b00000100; //setup analog/digital
ADCON0 = 0b00101000; //1010 = Channel 10 (AN10)
ADCON2 = 0b10101100; //1 = Right justified Unimplemented: Read as ‘0’ 101 = 12 TAD 100 = FOSC/4
ADCON0bits.ADON = 1; //1 = A/D Converter module is enabled
Delay10TCYx(30); // Delay for 50TCY
ADCON0bits.GO_DONE = 1; //start conversion
while(ADCON0bits.GO_DONE != 0) //wait for finnish
{
Delay1TCY(); //nop
}
result = ADRESL; //:ADRESL; // Read result
ADCON0bits.ADON = 0; //1 = A/D Converter module is enabled
return result;
}
char ADC_Convert_channel_11(void)
{
int result;
ADCON1 = 0b00000011; //setup analog/digital
ADCON0 = 0b00101100; //1011 = Channel 11 (AN11)
ADCON2 = 0b10101100; //1 = Right justified Unimplemented: Read as ‘0’ 101 = 12 TAD 100 = FOSC/4
ADCON0bits.ADON = 1; //1 = A/D Converter module is enabled
Delay10TCYx(15); // Delay for 50TCY
ADCON0bits.GO_DONE = 1; //start conversion
while(ADCON0bits.GO_DONE != 0) //wait for finnish
{
Delay1TCY(); //nop
}
result = ADRESL; //:ADRESL; // Read result
ADCON0bits.ADON = 0; //1 = A/D Converter module is enabled
return result;
}
char get_sensor_data(char sensor){
char return_char = 255;
switch(sensor)
{
case 1: //rb0
return PORTBbits.RB0;
break;
case 2: // rb1
return getSensorAverage(10);//ADC_Convert_channel_10();
break;
case 3: //rb2
return getSensorAverage(8);//ADC_Convert_channel_8();
break;
case 4: //rb4
return getSensorAverage(11);// ADC_Convert_channel_11();
break;
break;
case 5: //RA3
return getSensorAverage(3);
break;
break;
case 6: //rb3
return getSensorAverage(9);
break;
default:
break;
}
return return_char;
}
char set_output(char output, int boolon){
switch(output)
{
case 1:
//output1 = boolon
PORTAbits.RA4 = boolon;
break;
case 2:
PORTAbits.RA5 = boolon;
break;
default:
red_on;
return 2;
break;
}
return boolon;
}
void handle_int0 (void)
{
if (stopDriveOnINT0Interrupt == 1 && get_sensor_data(1) == 0)
{
if (timeouts_enabled == 0 || stopDriveOnINT0InterruptIsWaiting == 0) //if it is PRESSED and it is not waiting to refresh set
{
yellow_on;
neutral_motor_pwm;
if (timeouts_enabled == 1){ //be sure it will refresh
stopDriveOnINT0InterruptIsWaiting = 1; //wait until refreshed
}
if(debug_mode_enabled == 1 && say_all_mode_enabled == 1)
{
char timer_debug[37] = "\n\rThe input 1 motor stop occurred\n\r";
SendUSART_string (timer_debug, 37);
}
}
}
}
void retrieve_eep_settings()
{
Busy_eep ();
EEP_Timeouts_setup;
read_char = Read_b_eep(write_location);
if (read_char == write_true_char)
{
timeouts_enabled = 1;
}
else if (read_char == write_false_char)
{
timeouts_enabled = 0;
Stop_Timer0;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, write_true_char);
timeouts_enabled = 1;
send_usart_text(6);
}
Busy_eep ();
EEP_Say_all_setup;
read_char = Read_b_eep(write_location);
if (read_char == write_true_char)
{
say_all_mode_enabled = 1;
}
else if (read_char == write_false_char)
{
say_all_mode_enabled = 0;
}
else//reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, write_false_char);
say_all_mode_enabled = 0;
send_usart_text(6);
}
Busy_eep ();
EEP_Debug_mode_setup;
read_char = Read_b_eep(write_location);
if (read_char == write_true_char)
{
debug_mode_enabled = 1;
}
else if (read_char == write_false_char)
{
debug_mode_enabled = 0;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, write_false_char);
debug_mode_enabled = 0;
send_usart_text(6);
}
Busy_eep ();
EEP_Stop_inp1_setup;
read_char = Read_b_eep(write_location);
if (read_char == write_true_char)
{
stopDriveOnINT0Interrupt = 1;
}
else if (read_char == write_false_char)
{
stopDriveOnINT0Interrupt = 0;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, write_false_char);
stopDriveOnINT0Interrupt = 0;
send_usart_text(6);
}
Busy_eep ();
EEP_Manage_Speed_setup;
read_char = Read_b_eep(write_location);
if (read_char == write_true_char)
{
manage_speed_mode_enabled = 1;
}
else if (read_char == write_false_char)
{
manage_speed_mode_enabled = 0;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, write_false_char);
manage_speed_mode_enabled = 0;
send_usart_text(6);
}
Busy_eep ();
EEP_Max_Motor_speed write_location;
read_char = Read_b_eep(write_location);
if (read_char > 20 && read_char < 80)
{
motor_max_f = read_char;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, motor_max_f); //value already set so just get the defaults ...
send_usart_text(6);
}
Busy_eep ();
EEP_Min_Motor_speed write_location;
read_char = Read_b_eep(write_location);
if (read_char > 20 && read_char < 80)
{
motor_min_b = read_char;
}
else //reinitialize values
{
Busy_eep ();
Safe_WriteEEP(write_location, motor_min_b);
send_usart_text(6);
}
return;
}
void TMR0Interrupt ()
{
if (timeouts_enabled == 0)
return;
TMR0L = 0x00;
TMR0L = 0x00;
if (timeouts_enabled == 1)
{
neutral_motor_pwm;
if(debug_mode_enabled == 1 && say_all_mode_enabled == 1)
{
char timer_debug[33] = "\n\rThe timeout has triggered\n\r";
SendUSART_string (timer_debug, 33);
}
}
if (stopDriveOnINT0Interrupt == 1)
{
stopDriveOnINT0InterruptIsWaiting = 0; //so that it doesn't overrun the stop and keep going nuts!
}
}
void TMR2Interrupt(void) //system interrupt
{
int result = 0;
systemIncrement ++;
if (get_sensor_data(1) != encoderLastValue && systemIncrement % 1 == 0 && manage_speed_mode_enabled == 1)
{
encoderLastValue = !encoderLastValue;
encoderHitsSinceLastCheck ++;
}
if (systemIncrement % 80 == 0 && manage_speed_mode_enabled == 1)
{
wheelRoundsPerCheck = encoderHitsSinceLastCheck / 4;
encoderHitsSinceLastCheck = 0;
if (motor_current == 52 && wheelRoundsPerCheck == 0 && systemIsAutoSpeedCorrectingAtLevel == 0) // auto correct
{
systemIsAutoSpeedCorrectingAtLevel = 1;
set_drive_speed(53);
set_output(1, 1); //#1 on
}
else if (motor_current == 53 && systemIsAutoSpeedCorrectingAtLevel == 1 && wheelRoundsPerCheck == 0)
{
systemIsAutoSpeedCorrectingAtLevel = 2;
set_drive_speed(54);
}
else if (systemIsAutoSpeedCorrectingAtLevel > 0 && (motor_current == 53 || motor_current == 54)) //if the system is currently auto corrcting and the speed is 54 or 53 -- to make sure the drive wasn't changed
{ //corrected
systemIsAutoSpeedCorrectingAtLevel = 0;
set_drive_speed(52);
set_output(1, 0); //#1 off
}
else //auto stop correcting due to system change
{
systemIsAutoSpeedCorrectingAtLevel = 0;
set_output(1, 0); //#1 off
}
if (debug_mode_enabled == 1 && say_all_mode_enabled == 1)
{
if (wheelRoundsPerCheck == 0 )
{
SendUSART('S');
}
else
{
SendUSART('G');
}
}
}
if (systemIncrement % 1 == 0)
{
ADCON0bits.GO_DONE = 1; //start conversion
while(ADCON0bits.GO_DONE != 0) //wait for finnish
{
TMR1L = 0x00;
}
result = ADRESH; //:ADRESH; // Read high register result
switch(nextAdcon)
{
case 1: //AN8
updateSensorValueSet(8, result);;
break;
case 2://AN10
updateSensorValueSet(10, result);
break;
case 3://AN11
updateSensorValueSet(11, result);
break;
case 4://AN9
updateSensorValueSet(9, result);
break;
case 5://AN3
updateSensorValueSet(3, result);
break;
}
ADCON0bits.ADON = 0; //1 = A/D Converter module is enabled
nextAdcon ++;
setupNextInput();
}
}
void updateSensorValueSet(int anNumber, int value)
{
switch(anNumber)
{
case 3:
lastSensorAN3[lastValueSetRow] = value;
break;
case 8:
lastSensorAN8[lastValueSetRow] = value;
break;
case 9:
lastSensorAN9[lastValueSetRow] = value;
break;
case 10:
lastSensorAN10[lastValueSetRow] = value;
break;
case 11:
lastSensorAN11[lastValueSetRow] = value;
break;
}
if (anNumber == 3) //last analog in each loop --make sure each gets a value implemented
{
if (lastValueSetRow == 9)
{
lastValueSetRow = 0;
}
else
{
lastValueSetRow ++;
}
}
}
int getSensorAverage(int Sensor)
{
int result = 0;
int sum = 0;
switch(Sensor)
{
case 3:
for (result =0; result <= 9; result++)
{
sum = sum + lastSensorAN3[result];
}
break;
case 8:
for (result =0; result <= 9; result++)
{
sum = sum + lastSensorAN8[result];
}
break;
case 9:
for (result =0; result <= 9; result++)
{
sum = sum + lastSensorAN9[result];
}
break;
case 10:
for (result =0; result <= 9; result++)
{
sum = sum + lastSensorAN10[result];
}
break;
case 11:
for (result =0; result <= 9; result++)
{
sum = sum + lastSensorAN11[result];
}
break;
}
result = sum / 10;
return result;
}
void setupNextInput(void)
{
if (nextAdcon < 1 || nextAdcon >5)
nextAdcon = 1;
ADCON1 = 0b00000011; //setup analog/digital -- All digital but 12
switch(nextAdcon)
{
case 1: //AN8
ADCON0 = 0b00100000; //1000 = Channel 8 (AN8)
break;
case 2://AN10
ADCON0 = 0b00101000; //1010 = Channel 10 (AN10)
break;
case 3://AN11
ADCON0 = 0b00101100; //1011 = Channel 11 (AN11)
break;
case 4://AN9
ADCON0 = 0b00100100; //1001 = Channel 9 (AN9)
break;
case 5://AN3
ADCON0 = 0b00001100; //0011 = Channel 3 (AN3)
break;
}
ADCON2 = 0b00101100; //0 = left justified Unimplemented: Read as ‘0’ 101 = 12 TAD 100 = FOSC/4
ADCON0bits.ADON = 1; //1 = A/D Converter module is enabled
}
void initiate_services()
{
activate_peripherals();
Gbl_Ints_ENABLED;
}
void setup_ports()
{
ADCON1 = 0x0f;
ADCON0bits.ADON = 0;
PORTA = 0;
TRISA = 0;
PORTB = 0;
TRISB = 0;
PORTC = 0;
TRISC = 0;
setup_Input_Pins; //ADC!
setup_Output_Pins;
enable_portb_weekpullups;
}
void setup_peripherals()
{
//###############PWM
Setup_Motor_PWM;
neutral_motor_pwm;
neutral_servo_pwm;
//###############
//##############EUSART
OpenUSART( USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 25 );
BAUDCONbits.BRG16 = 1; // 16 bit mode
//####################
//#############Timeout Timer
Setup_Timer0;
Setup_Timer2;
//################Analog Digital Converter
}
void setup_interrupts()
{
Per_Ints_ENABLED;
High_Pri_Ints_ENABLED;
PIE1bits.RCIE = 1; //USART Receive Interrupt Enable bit
IPR1bits.RCIP = 1; //HIGH - USART Receive Interrupt Priority bit
PIE1bits.TMR2IE = 1;//1 = Enables the TMR2 & pr2 (ff for pwm) match interrupt
IPR1bits.TMR2IP = 1; // TMR1 overflow interrupt -- high priority
if (stopDriveOnINT0Interrupt == 1)
{
INTCON2bits.TMR0IP = 1; //high priority
INTCONbits.INT0IE = 1; //enable interrupts on RB0 int0 -- Input 1!
}
if (timeouts_enabled == 1)
{
INTCONbits.TMR0IE = 1; //enable timer 0 interupts
}
//INTCON2bits.INTEDG0= 0;// Interrupt on falling edge
//allways high priority on rb0 int0
}
void activate_peripherals()
{
setupNextInput ();//gets ready to use ADC
}
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
Gbl_Ints_DISABLED;
High_Pri_Ints_DISABLED;
if (debug_mode_enabled == 1)
yellow_on;
_asm
goto InterruptHandlerHigh //jump to interrupt routine
_endasm
}
//----------------------------------------------------------------------------
// High priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
if(PIR1bits.TMR2IF == 1) //timer 1 overflow
{
TMR2Interrupt();
PIR1bits.TMR2IF = 0;
}
if(INTCONbits.TMR0IF == 1) //timer 0 overflow
{
TMR0Interrupt();
INTCONbits.TMR0IF = 0;
}
if(PIR1bits.RCIF == 1) //1 = The USART receive buffer, RCREG, is full (cleared when RCREG is read)
{
yellow_on;
//RCREG is full
recieve_single = RCREG;
input_router(recieve_single);
}
if (INTCONbits.INT0IF == 1) //if the ext int is triggered and set
{
handle_int0 ();
INTCONbits.INT0IF = 0;
}
yellow_off;
Gbl_Ints_ENABLED; //re-enable interrupts
High_Pri_Ints_ENABLED;
}
void send_usart_text(int textId)
{
char string_to_output [105] = {0};
switch (textId)
{
case 1:
strcpypgm2ram (string_to_output, author_version);
SendUSART_string (string_to_output, 38);
break;
case 2:
strcpypgm2ram (string_to_output, verbose_menu_text);
SendUSART_string (string_to_output, 72);
break;
case 3:
strcpypgm2ram (string_to_output, quit_text);
SendUSART_string (string_to_output, 14);
break;
case 4:
strcpypgm2ram (string_to_output, unknown_string);
SendUSART_string (string_to_output, 21);
break;
case 5:
strcpypgm2ram (string_to_output, settings_menu_text);
SendUSART_string (string_to_output, 58);
break;
case 6: //reset_eep_setting_text
strcpypgm2ram (string_to_output, reset_eep_setting_text);
SendUSART_string (string_to_output, 45);
break;
case 7: //system info
strcpypgm2ram (string_to_output, system_info_text);
SendUSART_string (string_to_output, 103);
break;
case 10: //sayall
strcpypgm2ram (string_to_output, sayall_mode_set_text);
SendUSART_string (string_to_output, 19);
break;
case 11: //debug
strcpypgm2ram (string_to_output, debug_mode_set_text);
SendUSART_string (string_to_output, 18);
break;
case 12: //timeouts
strcpypgm2ram (string_to_output, timeouts_set_text);
SendUSART_string (string_to_output, 22);
break;
case 20: //testing info
strcpypgm2ram (string_to_output, testing_info_text);
SendUSART_string (string_to_output, 130);
break;
case 21: //press key to proceed
strcpypgm2ram (string_to_output, Ckey_continue_text);
SendUSART_string (string_to_output, 30);
break;
default:
break;
}
} | 2.125 | 2 |
2024-11-18T20:55:29.785147+00:00 | 2020-02-21T09:21:05 | c990f533af1cc2c11ca1da78e985b8970758bb79 | {
"blob_id": "c990f533af1cc2c11ca1da78e985b8970758bb79",
"branch_name": "refs/heads/master",
"committer_date": "2020-02-21T09:21:05",
"content_id": "de087aa73b9b6264246c39185cf38a24f63d56f9",
"detected_licenses": [
"MIT"
],
"directory_id": "7a07f3326ae54dacbcc636558f07c30e5bcd76ab",
"extension": "c",
"filename": "component.c",
"fork_events_count": 0,
"gha_created_at": "2020-01-16T09:06:29",
"gha_event_created_at": "2020-02-11T19:25:11",
"gha_language": "C",
"gha_license_id": null,
"github_id": 234278648,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3569,
"license": "MIT",
"license_type": "permissive",
"path": "/sources/component.c",
"provenance": "stackv2-0092.json.gz:37510",
"repo_name": "Huriumari/projet_c",
"revision_date": "2020-02-21T09:21:05",
"revision_id": "586c29a884d20ef11ffb0290a56187613be4d29c",
"snapshot_id": "56828a9f3cc29546a3cecbe1ba63f3036553e31d",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/Huriumari/projet_c/586c29a884d20ef11ffb0290a56187613be4d29c/sources/component.c",
"visit_date": "2020-12-13T01:37:57.311736"
} | stackv2 | //autor: Clement BOSSARD, Clement K-R
//date: 17/12/2019 - 12/02/2020
//Ce fichier contient les fonctions poour la creation et supression de composant
#include "logicSimButInC.h"
size_t new_component_id(size_t c){
static size_t id = 0;
if (c)
id = c + 1;
return id++;
}
void delete_component_widget(data_t * data, component_t *component){
gtk_widget_destroy(GTK_WIDGET(component->img));
if (component->is_select)
gtk_widget_destroy(component->frame);
gtk_widget_show_all(data->workingLayout);
}
void destroy_component(data_t *data, component_t *component){
delete_component_widget(data, component);
free(component->name);
if (component->parts != NULL)
free(component->parts);
free(component);
}
void add_component(data_t *data, char *path_img, double x, double y){
component_t *component;
GdkPixbuf *pb;
char buffer[255];
component = malloc(sizeof(component_t));
if (component != NULL){
component->name = malloc(sizeof(char) * (strlen(path_img) + 1));
strcpy(component->name, path_img);
component->is_select = 0;
component->next = NULL;
strcat(strcat(strcat(strcpy(buffer,get_option(data->option,"component_img_path")),"/"),path_img),".png");
component->img = gtk_image_new_from_file(buffer);
pb = gtk_image_get_pixbuf(GTK_IMAGE(component->img));
component->pos.x = x;
component->pos.y = y;
component->id = new_component_id(0);
add_action(data, "ADD", component, NULL);
component->parts = gimme_parts(component->name, &(component->number_parts), x, y);
gtk_layout_put(GTK_LAYOUT(data->workingLayout), component->img, component->pos.x - (double)gdk_pixbuf_get_width(pb) / 2, component->pos.y - (double)gdk_pixbuf_get_height(pb) / 2);
component->next = data->component;
data->component = component;
gtk_widget_show_all(data->workingLayout);
}
}
int remove_component(data_t *data, double mouse_x, double mouse_y){
component_t *component = data->component;
component_t *prev;
GdkPixbuf *pb;
double x,y;
while (component != NULL){
pb = gtk_image_get_pixbuf(GTK_IMAGE(component->img));
x = gdk_pixbuf_get_width(pb);
y = gdk_pixbuf_get_height(pb);
if ((mouse_x > component->pos.x - (double)(x/2)
&& mouse_x < component->pos.x + (double)(x/2)
&& mouse_y > component->pos.y - (double)(y/2)
&& mouse_y < component->pos.y + (double)(y/2))){
if (component == data->component){
prev = component;
data->component = data->component->next;
}else{
prev = data->component;
while (prev->next != NULL && prev->next != component)
prev = prev->next;
if (prev->next == NULL)
return 0;
prev->next = prev->next->next;
}
component->next = NULL;
add_action(data, "SUPPR", component, NULL);
destroy_component(data, component);
return 1;
}
component = component->next;
}
return 0;
}
int delete_selected_components(GtkWidget *widget, data_t *data){
component_t *component = data->component;
component_t *prev;
link_t *ptr;
if(widget)
widget++;
while (component != NULL){
if (component->is_select){
if (component == data->component){
prev = component;
data->component = data->component->next;
}else{
prev = data->component;
while (prev->next != NULL && prev->next != component)
prev = prev->next;
if (prev->next == NULL)
return 0;
prev->next = prev->next->next;
}
component->next = NULL;
ptr = get_link_linked_to(data, component->id);
add_action(data, "SUPPR", component, ptr);
destroy_component(data, component);
return 1;
}
component = component->next;
}
return 0;
} | 2.578125 | 3 |
2024-11-18T20:55:29.860922+00:00 | 2020-11-26T02:00:55 | a915b8f9ad9adc6307809ad0424a581e5b5a951a | {
"blob_id": "a915b8f9ad9adc6307809ad0424a581e5b5a951a",
"branch_name": "refs/heads/main",
"committer_date": "2020-11-26T02:00:55",
"content_id": "1e99a745725d48be909c68c22a9f4c04cf4703e6",
"detected_licenses": [
"MIT"
],
"directory_id": "66d5f881da7c02d26fc68df1f97efa8c701b8534",
"extension": "c",
"filename": "CLOCK_HANDLER.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 315214358,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1051,
"license": "MIT",
"license_type": "permissive",
"path": "/CLOCK_HANDLER.c",
"provenance": "stackv2-0092.json.gz:37638",
"repo_name": "yaxdd/RelojInt",
"revision_date": "2020-11-26T02:00:55",
"revision_id": "494ef257394ef0d5bb487ca1a38308e4beaab182",
"snapshot_id": "37863fb2d2975e30984d0b85fb9cf4f6602c38a5",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/yaxdd/RelojInt/494ef257394ef0d5bb487ca1a38308e4beaab182/CLOCK_HANDLER.c",
"visit_date": "2023-01-20T18:35:46.049422"
} | stackv2 | #include <TM4C129.h>
#include <stdio.h>
#include "CLOCK_HANDLER.h"
volatile uint16_t segundos;
volatile uint16_t minutos;
volatile uint16_t horas=12;
char textLCD[10];
void incrementarHora(){
horas++;
if(horas==24){
horas = 0;
}
}
void incrementarMinuto(){
minutos++;
if (minutos == 60){
minutos=0;
incrementarHora();
}
}
void incrementarSegundo(){
segundos++;
if (segundos == 60){
segundos=0;
incrementarMinuto();
}
}
void programarReloj(uint16_t selector,uint16_t flag){
switch(selector){
case 0:
if (flag){
horas++;
if (horas==24){
horas=0;
}
}else{
if (horas==0){
horas=23;
}else{
horas--;
}
}
break;
case 1:
if (flag){
minutos++;
if (minutos==60){
minutos=0;
}
}else{
if (minutos==0){
minutos=59;
}else{
minutos--;
}
}
break;
case 2:
if (flag){
segundos++;
if (segundos==60){
segundos=0;
}
}else{
if (segundos==0){
segundos=59;
}else{
segundos--;
}
}
break;
}
}
| 2.640625 | 3 |
2024-11-18T20:55:30.329210+00:00 | 2021-02-12T13:57:29 | 6175d1c771f5f56ad2689d819684831a2f52219a | {
"blob_id": "6175d1c771f5f56ad2689d819684831a2f52219a",
"branch_name": "refs/heads/main",
"committer_date": "2021-02-12T13:57:29",
"content_id": "9dbf0fd97a98b2cee36fca9807bee0a3771b69b8",
"detected_licenses": [
"MIT"
],
"directory_id": "c4673909b3ea2979301126a606edd2676522176d",
"extension": "c",
"filename": "derefernce_pointer.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 333468799,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 407,
"license": "MIT",
"license_type": "permissive",
"path": "/pointer/derefernce_pointer.c",
"provenance": "stackv2-0092.json.gz:37895",
"repo_name": "AAI1234S/c_programming",
"revision_date": "2021-02-12T13:57:29",
"revision_id": "d1e6fb07233e0fa1b4199c490636e948b8e412c5",
"snapshot_id": "b4d6ecba089aef603df9326de9092e55b5c82c36",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/AAI1234S/c_programming/d1e6fb07233e0fa1b4199c490636e948b8e412c5/pointer/derefernce_pointer.c",
"visit_date": "2023-08-13T22:18:26.641013"
} | stackv2 | #include<stdio.h>
#include<stdlib.h>
int main()
{
int *ip=0; // not pointing to any memmory location
int i=20;
float *fp=0;
float f=30;
// fp=&i; both gives unpredictable result due to the memory occupation of both base type is differnt
// ip=&f;
fp=&f;
ip=&i;
printf("&i=%p, ip=%p , i=%d , *ip=%d\n",&i, ip,i, *ip);
printf("&f=%p, fp=%p, f=%.2f, *fp=%.2f\n",&f, fp, f, *fp);
return 0;
}
| 2.671875 | 3 |
2024-11-18T20:55:30.912245+00:00 | 2019-04-07T12:47:40 | 637ea0b1e46af94a180462d919a22044485f937a | {
"blob_id": "637ea0b1e46af94a180462d919a22044485f937a",
"branch_name": "refs/heads/master",
"committer_date": "2019-04-07T12:47:40",
"content_id": "f0ee2544a1cb911c8dda3e1a6659057155d00e71",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "10f9f043e4d2af99c1f597fae0441fd6ab589c41",
"extension": "c",
"filename": "eptrig.c",
"fork_events_count": 1,
"gha_created_at": "2019-06-11T15:56:17",
"gha_event_created_at": "2019-06-11T15:56:18",
"gha_language": null,
"gha_license_id": null,
"github_id": 191404938,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1913,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/proto/1/eptrig.c",
"provenance": "stackv2-0092.json.gz:38154",
"repo_name": "ianezz/empower-enb-proto",
"revision_date": "2019-04-07T12:47:40",
"revision_id": "c345392a7406587270c942c0c74ab939ca8160d9",
"snapshot_id": "f9f5014f156f01e41aecc271bf53143785b12f90",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/ianezz/empower-enb-proto/c345392a7406587270c942c0c74ab939ca8160d9/proto/1/eptrig.c",
"visit_date": "2020-06-03T02:52:34.975373"
} | stackv2 | /* Copyright (c) 2019 FBK
* Designed by Roberto Riggio
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <arpa/inet.h>
#include <emproto.h>
int epf_trigger(
char * buf, unsigned int size,
ep_act_type type,
ep_op_type op)
{
ep_t_hdr * h = (ep_t_hdr *)(buf);
if(size < sizeof(ep_t_hdr)) {
ep_dbg_log(EP_DBG_1"F - TRIG: Not enough space!\n");
return -1;
}
h->type = htons(type);
h->op = (uint8_t)op;
ep_dbg_dump(EP_DBG_1"F - TRIG: ", buf, sizeof(ep_t_hdr));
return sizeof(ep_t_hdr);
}
/******************************************************************************
* Public API *
******************************************************************************/
ep_op_type epp_trigger_op(char * buf, unsigned int size)
{
ep_t_hdr * h = (ep_t_hdr *)(buf + sizeof(ep_hdr));
if(size < sizeof(ep_hdr) + sizeof(ep_t_hdr)) {
ep_dbg_log(EP_DBG_0"F - TRIG Op: Not enough space!\n");
return EP_TYPE_INVALID_MSG;
}
return (ep_act_type)h->op;
}
ep_act_type epp_trigger_type(char * buf, unsigned int size)
{
ep_t_hdr * h = (ep_t_hdr *)(buf + sizeof(ep_hdr));
if(size < sizeof(ep_hdr) + sizeof(ep_t_hdr)) {
ep_dbg_log(EP_DBG_0"F - TRIG Type: Not enough space!\n");
return EP_ACT_INVALID;
}
ep_dbg_dump(
EP_DBG_1"P - TRIG: ",
buf + sizeof(ep_hdr),
sizeof(ep_t_hdr));
return ntohs(h->type);
}
| 2.296875 | 2 |
2024-11-18T20:55:31.942687+00:00 | 2021-07-13T21:49:45 | 731cba5baf5e1061fb494360c3a1c0a1c225886e | {
"blob_id": "731cba5baf5e1061fb494360c3a1c0a1c225886e",
"branch_name": "refs/heads/main",
"committer_date": "2021-07-13T21:49:45",
"content_id": "959f274a847051c9f608d6c8b388a7c92aa00774",
"detected_licenses": [
"MIT"
],
"directory_id": "5fa2b431599c0b72304c2de5fb215c937f6c1576",
"extension": "c",
"filename": "tag.c",
"fork_events_count": 0,
"gha_created_at": "2021-07-11T21:17:32",
"gha_event_created_at": "2021-07-11T21:17:33",
"gha_language": null,
"gha_license_id": "MIT",
"github_id": 385053816,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 632,
"license": "MIT",
"license_type": "permissive",
"path": "/src/main/tag.c",
"provenance": "stackv2-0092.json.gz:38413",
"repo_name": "StarBlazeNatlus/HideNSeek",
"revision_date": "2021-07-13T21:49:45",
"revision_id": "ad02d1ffa8158276a36491607a7d741ba6aa8f65",
"snapshot_id": "08c1c4fffa06c12e78c60b514e35534731ac3108",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/StarBlazeNatlus/HideNSeek/ad02d1ffa8158276a36491607a7d741ba6aa8f65/src/main/tag.c",
"visit_date": "2023-06-24T03:34:16.711169"
} | stackv2 | #include <common.h>
#include <hidenseek.h>
#include <racedata.h>
#include <utils.h>
void HandleTags(void* something, int pid) {
// If the player is a Seeker and the chosen pid is a hider, don't display their tag
if (HideNSeekData.players[Racedata->main.scenarios[0].settings.hudPlayerIds[0]].isSeeker && !(HideNSeekData.players[pid].isSeeker)) {
// Only hide tags with Battle Glitch during the 30 second countdown
if (BtGlitch) {
if (!Have30SecondsPassed)
return;
// Otherwise hide them indiscriminately
} else
return;
}
// All checks passed, execute original function call
TagFunc(something, pid);
}
| 2.109375 | 2 |
2024-11-18T20:55:32.135327+00:00 | 2013-11-21T04:38:05 | 035da0d84c25fb2179515e571324d06d325b2de0 | {
"blob_id": "035da0d84c25fb2179515e571324d06d325b2de0",
"branch_name": "refs/heads/master",
"committer_date": "2013-11-21T04:38:05",
"content_id": "ff9dbf82ad8ad1b486e1bf4dba1707dc35605aa7",
"detected_licenses": [
"Apache-2.0"
],
"directory_id": "caf6dfd7688656e16669a20f514175a2b6ca7db3",
"extension": "c",
"filename": "inodes.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": null,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 7044,
"license": "Apache-2.0",
"license_type": "permissive",
"path": "/src/inodes.c",
"provenance": "stackv2-0092.json.gz:38799",
"repo_name": "scotthernandez/mongo-fuse",
"revision_date": "2013-11-21T04:38:05",
"revision_id": "4b26c0b4911d556d893594b76641c23993319fe6",
"snapshot_id": "59399806108da6dbaa54328e7f37139bd726cebc",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/scotthernandez/mongo-fuse/4b26c0b4911d556d893594b76641c23993319fe6/src/inodes.c",
"visit_date": "2020-12-29T00:02:00.528561"
} | stackv2 | #include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <mongo.h>
#include <stdlib.h>
#include <search.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/file.h>
#include <limits.h>
#include <time.h>
#include <pthread.h>
#include "mongo-fuse.h"
#include <osxfuse/fuse.h>
#include <execinfo.h>
extern const char * inodes_name;
extern const char * locks_name;
int inode_exists(const char * path) {
bson query, fields;
mongo * conn = get_conn();
mongo_cursor curs;
int res;
bson_init(&query);
bson_append_string(&query, "dirents", path);
bson_finish(&query);
bson_init(&fields);
bson_append_int(&fields, "dirents", 1);
bson_append_int(&fields, "_id", 0);
bson_finish(&fields);
mongo_cursor_init(&curs, conn, inodes_name);
mongo_cursor_set_query(&curs, &query);
mongo_cursor_set_fields(&curs, &fields);
mongo_cursor_set_limit(&curs, 1);
res = mongo_cursor_next(&curs);
bson_destroy(&query);
bson_destroy(&fields);
mongo_cursor_destroy(&curs);
if(res == 0)
return 0;
if(curs.err != MONGO_CURSOR_EXHAUSTED)
return -EIO;
return -ENOENT;
}
int commit_inode(struct inode * e) {
bson cond, doc;
mongo * conn = get_conn();
char istr[4];
struct dirent * cde = e->dirents;
int res;
bson_init(&doc);
bson_append_start_object(&doc, "$set");
bson_append_start_array(&doc, "dirents");
res = 0;
while(cde) {
bson_numstr(istr, res++);
bson_append_string(&doc, istr, cde->path);
cde = cde->next;
}
bson_append_finish_array(&doc);
bson_append_int(&doc, "mode", e->mode);
bson_append_long(&doc, "owner", e->owner);
bson_append_long(&doc, "group", e->group);
bson_append_long(&doc, "size", e->size);
bson_append_time_t(&doc, "created", e->created);
bson_append_time_t(&doc, "modified", e->modified);
if(e->data && e->datalen > 0)
bson_append_string_n(&doc, "data", e->data, e->datalen);
bson_append_finish_object(&doc);
bson_finish(&doc);
bson_init(&cond);
bson_append_oid(&cond, "_id", &e->oid);
bson_finish(&cond);
res = mongo_update(conn, inodes_name, &cond, &doc,
MONGO_UPDATE_UPSERT, NULL);
bson_destroy(&cond);
bson_destroy(&doc);
if(res != MONGO_OK) {
fprintf(stderr, "Error committing inode %s\n",
mongo_get_server_err_string(conn));
return -EIO;
}
return 0;
}
void init_inode(struct inode * e) {
memset(e, 0, sizeof(struct inode));
pthread_mutex_init(&e->wr_lock, NULL);
}
int read_inode(const bson * doc, struct inode * out) {
bson_iterator i, sub;
bson_type bt;
const char * key;
bson_iterator_init(&i, doc);
while((bt = bson_iterator_next(&i)) > 0) {
key = bson_iterator_key(&i);
if(strcmp(key, "_id") == 0)
memcpy(&out->oid, bson_iterator_oid(&i), sizeof(bson_oid_t));
else if(strcmp(key, "mode") == 0)
out->mode = bson_iterator_int(&i);
else if(strcmp(key, "owner") == 0)
out->owner = bson_iterator_long(&i);
else if(strcmp(key, "group") == 0)
out->group = bson_iterator_long(&i);
else if(strcmp(key, "size") == 0)
out->size = bson_iterator_long(&i);
else if(strcmp(key, "created") == 0)
out->created = bson_iterator_time_t(&i);
else if(strcmp(key, "modified") == 0)
out->modified = bson_iterator_time_t(&i);
else if(strcmp(key, "data") == 0) {
out->datalen = bson_iterator_string_len(&i);
out->data = malloc(out->datalen + 1);
strcpy(out->data, bson_iterator_string(&i));
}
else if(strcmp(key, "dirents") == 0) {
while(out->dirents) {
struct dirent * next = out->dirents->next;
free(out->dirents);
out->dirents = next;
}
bson_iterator_subiterator(&i, &sub);
while((bt = bson_iterator_next(&sub)) > 0) {
int len = bson_iterator_string_len(&sub);
struct dirent * cde = malloc(sizeof(struct dirent) + len);
if(!cde)
return -ENOMEM;
strcpy(cde->path, bson_iterator_string(&sub));
cde->len = bson_iterator_string_len(&sub);
cde->next = out->dirents;
out->dirents = cde;
out->direntcount++;
}
}
}
return 0;
}
int get_inode_impl(const char * path, struct inode * out) {
bson query, doc;
int res;
mongo * conn = get_conn();
bson_init(&query);
bson_append_string(&query, "dirents", path);
bson_finish(&query);
res = mongo_find_one(conn, inodes_name, &query,
bson_shared_empty(), &doc);
if(res != MONGO_OK) {
bson_destroy(&query);
return -ENOENT;
}
bson_destroy(&query);
res = read_inode(&doc, out);
bson_destroy(&doc);
return res;
}
int get_cached_inode(const char * path, struct inode * out) {
time_t now = time(NULL);
int res;
if(now - out->updated < 3)
return 0;
res = get_inode_impl(path, out);
if(res == 0)
out->updated = now;
return res;
}
int get_inode(const char * path, struct inode * out) {
init_inode(out);
return get_inode_impl(path, out);
}
int check_access(struct inode * e, int amode) {
const struct fuse_context * fcx = fuse_get_context();
mode_t mode = e->mode;
if(fcx->uid == 0 || amode == 0)
return 0;
if(fcx->uid == e->owner)
mode >>= 6;
else if(fcx->gid == e->group)
mode >>= 3;
return (((mode & S_IRWXO) & amode) == 0);
}
int create_inode(const char * path, mode_t mode, const char * data) {
struct inode e;
int pathlen = strlen(path);
const struct fuse_context * fcx = fuse_get_context();
int res;
res = inode_exists(path);
if(res == 0) {
fprintf(stderr, "%s already exists\n", path);
return -EEXIST;
} else if(res == -EIO)
return -EIO;
init_inode(&e);
bson_oid_gen(&e.oid);
e.dirents = malloc(sizeof(struct dirent) + pathlen);
e.dirents->len = pathlen;
strcpy(e.dirents->path, path);
e.dirents->next = NULL;
e.direntcount = 1;
e.mode = mode;
e.owner = fcx->uid;
e.group = fcx->gid;
e.created = time(NULL);
e.modified = time(NULL);
if(data) {
e.datalen = strlen(data);
e.data = strdup(data);
e.size = e.datalen;
} else {
e.data = NULL;
e.datalen = 0;
e.size = 0;
}
e.wr_extent = NULL;
e.wr_age = 0;
res = commit_inode(&e);
free_inode(&e);
return res;
}
void free_inode(struct inode *e) {
if(e->data)
free(e->data);
while(e->dirents) {
struct dirent * next = e->dirents->next;
free(e->dirents);
e->dirents = next;
}
if(e->wr_extent)
free(e->wr_extent);
}
| 2.203125 | 2 |
2024-11-18T20:55:32.204993+00:00 | 2021-12-09T23:58:01 | 9b6aaae2ba755a91f7b72c50a1bded9dfd2246b7 | {
"blob_id": "9b6aaae2ba755a91f7b72c50a1bded9dfd2246b7",
"branch_name": "refs/heads/uml-rename",
"committer_date": "2021-12-09T23:58:01",
"content_id": "04185e9557538679dd8e70ea033fab3af9bcbb12",
"detected_licenses": [
"MIT"
],
"directory_id": "f4b5721c6b3f5623e306d0aa9a95ec53461c1f89",
"extension": "h",
"filename": "openflow_config.h",
"fork_events_count": 11,
"gha_created_at": "2018-05-26T17:16:50",
"gha_event_created_at": "2022-12-08T05:20:58",
"gha_language": "Python",
"gha_license_id": "MIT",
"github_id": 134980773,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 3979,
"license": "MIT",
"license_type": "permissive",
"path": "/backend/include/openflow_config.h",
"provenance": "stackv2-0092.json.gz:38927",
"repo_name": "citelab/gini5",
"revision_date": "2021-12-09T23:58:01",
"revision_id": "d095076113c1e84c33f52ef46a3df1f8bc8ffa43",
"snapshot_id": "b53e306eb5dabf98e9a7ded3802cf2c646f32914",
"src_encoding": "UTF-8",
"star_events_count": 12,
"url": "https://raw.githubusercontent.com/citelab/gini5/d095076113c1e84c33f52ef46a3df1f8bc8ffa43/backend/include/openflow_config.h",
"visit_date": "2022-12-10T15:58:49.578271"
} | stackv2 | /**
* openflow_config.h - OpenFlow switch configuration
*/
#ifndef __OPENFLOW_CONFIG_H_
#define __OPENFLOW_CONFIG_H_
#include <stdint.h>
#include "openflow_defs.h"
/**
* Converts the specified GNET port number to an OpenFlow port number.
*
* @param gnet_port_num The GNET port number.
*
* @return The corresponding OpenFlow port number.
*/
uint16_t openflow_config_get_of_port_num(uint16_t gnet_port_num);
/**
* Converts the specified OpenFlow port number to an GNET port number.
*
* @param gnet_port_num The OpenFlow port number.
*
* @return The corresponding GNET port number.
*/
uint16_t openflow_config_get_gnet_port_num(uint16_t openflow_port_num);
/**
* Initializes the OpenFlow physical ports.
*/
void openflow_config_init_phy_ports();
/**
* Updates the specified OpenFlow physical ports to match the state
* of the corresponding GNET interface.
*
* @param The OpenFlow port number corresponding to the port to update.
*/
void openflow_config_update_phy_port(int32_t openflow_port_num);
/**
* Gets the OpenFlow ofp_phy_port corresponding to the specified
* OpenFlow port number.
*
* This function uses dynamically allocated memory that must be manually
* freed afterwards.
*
* @param openflow_port_num The specified OpenFlow port number.
*
* @return The OpenFlow physical port struct corresponding to the
* specified port number.
*/
ofp_phy_port *openflow_config_get_phy_port(uint16_t openflow_port_num);
/**
* Sets the OpenFlow ofp_phy_port struct corresponding to the specified
* OpenFlow port number.
*
* @param openflow_port_num The specified OpenFlow port number.
* @param port The new ofp_phy_port struct.
*/
void openflow_config_set_phy_port(uint16_t openflow_port_num,
ofp_phy_port *port);
/**
* Prints information associated with the specified OpenFlow physical port.
*
* @param index The index of the port to print.
*/
void openflow_config_print_port(uint32_t index);
/**
* Prints information associated with all OpenFlow physical ports.
*/
void openflow_config_print_ports();
/**
* Gets the OpenFlow physical port statistics corresponding to the specified
* OpenFlow port number.
*
* This function uses dynamically allocated memory that must be manually
* freed afterwards.
*
* @param openflow_port_num The specified OpenFlow port number.
*
* @return The OpenFlow physical port statistics corresponding to the
* specified port number.
*/
ofp_port_stats *openflow_config_get_port_stats(uint16_t openflow_port_num);
/**
* Sets the OpenFlow ofp_port_stats struct corresponding to the specified
* OpenFlow port number.
*
* @param openflow_port_num The specified OpenFlow port number.
* @param stats The new ofp_port_stats struct.
*/
void openflow_config_set_port_stats(uint16_t openflow_port_num,
ofp_port_stats *stats);
/**
* Prints the statistics for the specified OpenFlow physical port.
*
* @param index The index of the port to print.
*/
void openflow_config_print_port_stat(uint32_t index);
/**
* Prints the statistics for all OpenFlow physical ports.
*/
void openflow_config_print_port_stats();
/**
* Gets the current switch configuration flags in network byte order.
*
* @return The current switch configuration flags.
*/
uint16_t openflow_config_get_switch_config_flags();
/**
* Sets the current switch configuration flags in network byte order.
*
* @param flags The switch configuration flags to set.
*/
void openflow_config_set_switch_config_flags(uint16_t flags);
/**
* Gets the OpenFlow switch features.
*
* @return The OpenFlow switch features.
*/
ofp_switch_features openflow_config_get_switch_features();
/**
* Gets the OpenFlow description stats.
*
* @return The OpenFlow description stats.
*/
ofp_desc_stats openflow_config_get_desc_stats();
/**
* Prints the OpenFlow description stats to the console.
*/
void openflow_config_print_desc_stats();
#endif // ifndef __OPENFLOW_CONFIG_H_
| 2.375 | 2 |
2024-11-18T20:55:32.564137+00:00 | 2017-12-26T09:46:27 | 0428772ad1f0cb0a75cfdbecbada9829b7e1ddea | {
"blob_id": "0428772ad1f0cb0a75cfdbecbada9829b7e1ddea",
"branch_name": "refs/heads/master",
"committer_date": "2017-12-26T09:46:27",
"content_id": "540deb553daacb7b04dbca6db04b4c1825938b17",
"detected_licenses": [
"MIT"
],
"directory_id": "6c686851c0683c989afe0a0b93d839e354e4b085",
"extension": "c",
"filename": "readlink.c",
"fork_events_count": 0,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 108029657,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1090,
"license": "MIT",
"license_type": "permissive",
"path": "/08.File.Status.n.Directory/readlink/readlink.c",
"provenance": "stackv2-0092.json.gz:39311",
"repo_name": "r4k0nb4k0n/unix-programming-homework",
"revision_date": "2017-12-26T09:46:27",
"revision_id": "a8bdc1958a54b6b3f82669c8045fc4d9c9076099",
"snapshot_id": "fdd3132543e6d3f810385a70bf1dd33761f0b994",
"src_encoding": "UTF-8",
"star_events_count": 4,
"url": "https://raw.githubusercontent.com/r4k0nb4k0n/unix-programming-homework/a8bdc1958a54b6b3f82669c8045fc4d9c9076099/08.File.Status.n.Directory/readlink/readlink.c",
"visit_date": "2021-09-01T09:51:40.987613"
} | stackv2 | #include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
struct stat sb;
char *linkname;
ssize_t r;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pathname>\n",
argv[0]);
exit(EXIT_FAILURE);
}
if (lstat(argv[1], &sb) == -1) {
perror("lstat"); exit(EXIT_FAILURE);
}
linkname = malloc(sb.st_size + 1);
if (linkname == NULL) {
fprintf(stderr, "insufficient memory\n");
exit(EXIT_FAILURE);
}
r = readlink(argv[1], linkname, sb.st_size + 1);
if (r == -1) {
perror("readlink");
exit(EXIT_FAILURE);
}
if (r > sb.st_size) {
fprintf(stderr, "symlink increased in size "
"between lstat() and readlink()\n");
exit(EXIT_FAILURE);
}
linkname[r] = '\0';
printf("'%s' points to '%s'\n", argv[1], linkname);
free(linkname);
}
| 3.0625 | 3 |
2024-11-18T20:55:33.011131+00:00 | 2019-04-13T15:15:38 | 5f216e83f909dd6ce274e38b6854a6c5a9a2f7ea | {
"blob_id": "5f216e83f909dd6ce274e38b6854a6c5a9a2f7ea",
"branch_name": "refs/heads/master",
"committer_date": "2019-04-13T15:15:38",
"content_id": "17235b9bd858d2b78914fb584caf8146402e9890",
"detected_licenses": [
"MIT"
],
"directory_id": "181ac616c2065e780e0ee54bcd903707a4134e81",
"extension": "c",
"filename": "bintree.c",
"fork_events_count": 0,
"gha_created_at": "2019-01-12T15:45:57",
"gha_event_created_at": "2019-01-12T15:48:38",
"gha_language": "C",
"gha_license_id": null,
"github_id": 165404975,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 1493,
"license": "MIT",
"license_type": "permissive",
"path": "/bintree/bintree.c",
"provenance": "stackv2-0092.json.gz:39956",
"repo_name": "MihailSalnikov/Skiena",
"revision_date": "2019-04-13T15:15:38",
"revision_id": "35cdbba06a6c3fac31bffa26843025b32d32d385",
"snapshot_id": "d81c124ff6508ce97f4b025777f5243fc2a6e207",
"src_encoding": "UTF-8",
"star_events_count": 0,
"url": "https://raw.githubusercontent.com/MihailSalnikov/Skiena/35cdbba06a6c3fac31bffa26843025b32d32d385/bintree/bintree.c",
"visit_date": "2020-04-16T07:56:42.516299"
} | stackv2 | #include "bintree.h"
#include <stdlib.h>
bintree *search_bintree(bintree *l, int x)
{
if (l == NULL)
return NULL;
if (l->item == x)
return l;
if (x < l->item)
return search_bintree(l->left, x);
else
return search_bintree(l->right, x);
}
bintree *find_minimum(bintree *l)
{
bintree *min;
if (l == NULL)
return NULL;
min = l;
while (min->left != NULL)
min = min->left;
return min;
}
void insert_bintree(bintree **l, int x, bintree *parent)
{
bintree *p; // temp bintree
if (*l == NULL) {
p = malloc(sizeof(bintree));
p->item = x;
p->right = p->left = NULL;
p->parent = parent;
*l = p;
return;
}
if (x > (*l)->item) {
insert_bintree(&((*l)->right), x, *l);
}
else {
insert_bintree(&((*l)->left), x, *l);
}
}
void delete_bintree(int x, bintree *parent)
{
bintree *current = search_bintree(parent, x);
if (current->left != NULL && current->right != NULL) {
bintree *exc = find_minimum(current->right);
current->item = exc->item;
exc = NULL;
return;
}
else {
if (current->left == NULL) {
if (current->parent->left == current)
current->parent->left = current->right;
else
current->parent->right = current->right;
current->right->parent = current->parent;
current = NULL;
return;
}
else {
if (current->parent->left == current)
current->parent->left = current->left;
else
current->parent->right = current->left;
current->left->parent = current->parent;
current = NULL;
return;
}
}
} | 3.4375 | 3 |
2024-11-18T20:55:33.096930+00:00 | 2020-09-17T13:55:05 | b931b97e98f54bff722d9632778b8f61bc3bd6e7 | {
"blob_id": "b931b97e98f54bff722d9632778b8f61bc3bd6e7",
"branch_name": "refs/heads/master",
"committer_date": "2020-09-17T13:55:05",
"content_id": "438efcd80ef643bd6138af6ab8443f4afe917539",
"detected_licenses": [
"BSD-3-Clause"
],
"directory_id": "1e55349d14d65e5be67e2e92d9978beb0ed7a0c0",
"extension": "c",
"filename": "freertos_cm_support.c",
"fork_events_count": 0,
"gha_created_at": "2018-03-22T02:20:04",
"gha_event_created_at": "2018-09-26T02:32:18",
"gha_language": "C",
"gha_license_id": "BSD-3-Clause",
"github_id": 126267255,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 2238,
"license": "BSD-3-Clause",
"license_type": "permissive",
"path": "/libs/freertos/source/portable/ARM_CM/freertos_cm_support.c",
"provenance": "stackv2-0092.json.gz:40085",
"repo_name": "martinribelotta/cese-edu-ciaa-template",
"revision_date": "2020-09-17T13:55:05",
"revision_id": "8ff0977b104f4fe43f155d90bbc2ebbd3430fb2d",
"snapshot_id": "39b325389aff0a19dd1e14ed87088d63f3e222a8",
"src_encoding": "UTF-8",
"star_events_count": 1,
"url": "https://raw.githubusercontent.com/martinribelotta/cese-edu-ciaa-template/8ff0977b104f4fe43f155d90bbc2ebbd3430fb2d/libs/freertos/source/portable/ARM_CM/freertos_cm_support.c",
"visit_date": "2021-04-15T12:46:16.263408"
} | stackv2 | #include <stdint.h>
/* Board specifics. */
#if (BOARD == ciaa_nxp)
#include <freertos_lpc4337.h>
#elif (BOARD == edu_ciaa_nxp)
#include <freertos_lpc4337.h>
#elif (BOARD == lpcxpresso1769)
#include <freertos_lpc4337.h>
#endif
#include <freertos_cm_support.h>
typedef uint32_t (*freeRtosInterruptCallback_t)(void);
volatile freeRtosInterruptCallback_t freeRtosInterruptCallback = NULL;
/*-----------------------------------------------------------*/
/*
* Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
* Each bit can be used to represent an individual interrupt - with the first
* two bits being used for the Yield and Tick interrupts respectively.
*/
void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
{
NVIC_SetPendingIRQ( ulInterruptNumber ); // mainSW_INTERRUPT_ID
}
/*-----------------------------------------------------------*/
/*
* Install an interrupt handler to be called by the simulated interrupt handler
* thread. The interrupt number must be above any used by the kernel itself
* (at the time of writing the kernel was using interrupt numbers 0, 1, and 2
* as defined above). The number must also be lower than 32.
*
* Interrupt handler functions must return a non-zero value if executing the
* handler resulted in a task switch being required.
*/
void vPortSetInterruptHandler( uint32_t ulInterruptNumber, uint32_t (*pvHandler)( void ) )
{
if( pvHandler != NULL ) {
freeRtosInterruptCallback = pvHandler;
}
/* The interrupt service routine uses an (interrupt safe) FreeRTOS API
* function so the interrupt priority must be at or below the priority defined
* by configSYSCALL_INTERRUPT_PRIORITY. */
NVIC_SetPriority( mainSW_INTERRUPT_ID, mainSOFTWARE_INTERRUPT_PRIORITY );
/* Enable the interrupt. */
NVIC_EnableIRQ( mainSW_INTERRUPT_ID );
}
/*-----------------------------------------------------------*/
// ISR Handler
void vSoftwareInterruptHandler( void )
{
NVIC_ClearPendingIRQ( mainSW_INTERRUPT_ID );
// Execute Tick Hook function if pointer is not NULL
if( freeRtosInterruptCallback != NULL ) {
(* freeRtosInterruptCallback )();
}
}
/*-----------------------------------------------------------*/
| 2.546875 | 3 |
2024-11-18T20:55:34.327512+00:00 | 2013-10-01T08:51:29 | 7022b0c0137350f3564933ec976e306ba809fb9e | {
"blob_id": "7022b0c0137350f3564933ec976e306ba809fb9e",
"branch_name": "refs/heads/master",
"committer_date": "2013-10-01T08:51:29",
"content_id": "bbfa7a9fc7e861783118266f6d6cb6107d2cc609",
"detected_licenses": [
"BSD-2-Clause"
],
"directory_id": "596c31b047ca731e4908aaf9f056b6ec39623380",
"extension": "c",
"filename": "ecore_events.c",
"fork_events_count": 7,
"gha_created_at": null,
"gha_event_created_at": null,
"gha_language": null,
"gha_license_id": null,
"github_id": 2317070,
"is_generated": false,
"is_vendor": false,
"language": "C",
"length_bytes": 18068,
"license": "BSD-2-Clause",
"license_type": "permissive",
"path": "/ecore/src/lib/ecore/ecore_events.c",
"provenance": "stackv2-0092.json.gz:40731",
"repo_name": "kakaroto/e17",
"revision_date": "2013-10-01T08:51:29",
"revision_id": "93aef5b89a5e845d90fba2c209b548c1c1f553cf",
"snapshot_id": "0762d641749774371739852a3969f0859ddce99b",
"src_encoding": "UTF-8",
"star_events_count": 15,
"url": "https://raw.githubusercontent.com/kakaroto/e17/93aef5b89a5e845d90fba2c209b548c1c1f553cf/ecore/src/lib/ecore/ecore_events.c",
"visit_date": "2020-06-04T18:17:12.959338"
} | stackv2 | #ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include "Ecore.h"
#include "ecore_private.h"
static int inpurge = 0;
struct _Ecore_Event_Handler
{
EINA_INLIST;
ECORE_MAGIC;
int type;
Ecore_Event_Handler_Cb func;
void *data;
int references;
Eina_Bool delete_me : 1;
};
GENERIC_ALLOC_SIZE_DECLARE(Ecore_Event_Handler);
struct _Ecore_Event_Filter
{
EINA_INLIST;
ECORE_MAGIC;
Ecore_Data_Cb func_start;
Ecore_Filter_Cb func_filter;
Ecore_End_Cb func_end;
void *loop_data;
void *data;
int references;
Eina_Bool delete_me : 1;
};
GENERIC_ALLOC_SIZE_DECLARE(Ecore_Event_Filter);
struct _Ecore_Event
{
EINA_INLIST;
ECORE_MAGIC;
int type;
void *event;
Ecore_End_Cb func_free;
void *data;
int references;
Eina_Bool delete_me : 1;
};
GENERIC_ALLOC_SIZE_DECLARE(Ecore_Event);
static int events_num = 0;
static Ecore_Event *events = NULL;
static Ecore_Event *event_current = NULL;
static Ecore_Event *purge_events = NULL;
static Ecore_Event_Handler **event_handlers = NULL;
static Ecore_Event_Handler *event_handler_current = NULL;
static int event_handlers_num = 0;
static int event_handlers_alloc_num = 0;
static Eina_List *event_handlers_delete_list = NULL;
static Ecore_Event_Handler *event_handlers_add_list = NULL;
static Ecore_Event_Filter *event_filters = NULL;
static Ecore_Event_Filter *event_filter_current = NULL;
static Ecore_Event *event_filter_event_current = NULL;
static int event_filters_delete_me = 0;
static int event_id_max = ECORE_EVENT_COUNT;
static int ecore_raw_event_type = ECORE_EVENT_NONE;
static void *ecore_raw_event_event = NULL;
static void _ecore_event_purge_deleted(void);
static void *_ecore_event_del(Ecore_Event *event);
EAPI Ecore_Event_Handler *
ecore_event_handler_add(int type,
Ecore_Event_Handler_Cb func,
const void *data)
{
Ecore_Event_Handler *eh = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!func) goto unlock;
if ((type <= ECORE_EVENT_NONE) || (type >= event_id_max)) goto unlock;
eh = ecore_event_handler_calloc(1);
if (!eh) goto unlock;
ECORE_MAGIC_SET(eh, ECORE_MAGIC_EVENT_HANDLER);
eh->type = type;
eh->func = func;
eh->data = (void *)data;
if (type >= (event_handlers_num - 1))
{
int p_alloc_num;
p_alloc_num = event_handlers_alloc_num;
event_handlers_num = type + 1;
if (event_handlers_num > event_handlers_alloc_num)
{
Ecore_Event_Handler **new_handlers;
int i;
event_handlers_alloc_num = ((event_handlers_num + 16) / 16) * 16;
new_handlers = realloc(event_handlers, event_handlers_alloc_num * sizeof(Ecore_Event_Handler *));
if (!new_handlers)
{
ecore_event_handler_mp_free(eh);
goto unlock;
}
event_handlers = new_handlers;
for (i = p_alloc_num; i < event_handlers_alloc_num; i++)
event_handlers[i] = NULL;
}
}
if (ecore_raw_event_type == type)
event_handlers_add_list = (Ecore_Event_Handler *)eina_inlist_append(EINA_INLIST_GET(event_handlers_add_list), EINA_INLIST_GET(eh));
else if (type < event_handlers_alloc_num)
event_handlers[type] = (Ecore_Event_Handler *)eina_inlist_append(EINA_INLIST_GET(event_handlers[type]), EINA_INLIST_GET(eh));
unlock:
_ecore_unlock();
return eh;
}
EAPI void *
ecore_event_handler_del(Ecore_Event_Handler *event_handler)
{
void *data = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!ECORE_MAGIC_CHECK(event_handler, ECORE_MAGIC_EVENT_HANDLER))
{
ECORE_MAGIC_FAIL(event_handler, ECORE_MAGIC_EVENT_HANDLER,
"ecore_event_handler_del");
goto unlock;
}
data = _ecore_event_handler_del(event_handler);
unlock:
_ecore_unlock();
return data;
}
EAPI void *
ecore_event_handler_data_get(Ecore_Event_Handler *eh)
{
void *data = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!ECORE_MAGIC_CHECK(eh, ECORE_MAGIC_EVENT_HANDLER))
{
ECORE_MAGIC_FAIL(eh, ECORE_MAGIC_EVENT_HANDLER, "ecore_event_handler_data_get");
goto unlock;
}
data = eh->data;
unlock:
_ecore_unlock();
return data;
}
EAPI void *
ecore_event_handler_data_set(Ecore_Event_Handler *eh,
const void *data)
{
void *old = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!ECORE_MAGIC_CHECK(eh, ECORE_MAGIC_EVENT_HANDLER))
{
ECORE_MAGIC_FAIL(eh, ECORE_MAGIC_EVENT_HANDLER, "ecore_event_handler_data_set");
goto unlock;
}
old = eh->data;
eh->data = (void *)data;
unlock:
_ecore_unlock();
return old;
}
static void
_ecore_event_generic_free(void *data __UNUSED__,
void *event)
{ /* DO NOT MEMPOOL FREE THIS */
free(event);
}
EAPI Ecore_Event *
ecore_event_add(int type,
void *ev,
Ecore_End_Cb func_free,
void *data)
{
Ecore_Event *event = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
/* if (!ev) goto unlock; */
if (type <= ECORE_EVENT_NONE) goto unlock;
if (type >= event_id_max) goto unlock;
if ((ev) && (!func_free)) func_free = _ecore_event_generic_free;
event = _ecore_event_add(type, ev, func_free, data);
unlock:
_ecore_unlock();
return event;
}
EAPI void *
ecore_event_del(Ecore_Event *event)
{
void *data = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!ECORE_MAGIC_CHECK(event, ECORE_MAGIC_EVENT))
{
ECORE_MAGIC_FAIL(event, ECORE_MAGIC_EVENT, "ecore_event_del");
goto unlock;
}
EINA_SAFETY_ON_TRUE_GOTO(event->delete_me, unlock);
event->delete_me = 1;
data = event->data;
unlock:
_ecore_unlock();
return data;
}
EAPI int
ecore_event_type_new(void)
{
int id;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
_ecore_lock();
id = event_id_max++;
_ecore_unlock();
return id;
}
EAPI Ecore_Event_Filter *
ecore_event_filter_add(Ecore_Data_Cb func_start,
Ecore_Filter_Cb func_filter,
Ecore_End_Cb func_end,
const void *data)
{
Ecore_Event_Filter *ef = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!func_filter) goto unlock;
ef = ecore_event_filter_calloc(1);
if (!ef) goto unlock;
ECORE_MAGIC_SET(ef, ECORE_MAGIC_EVENT_FILTER);
ef->func_start = func_start;
ef->func_filter = func_filter;
ef->func_end = func_end;
ef->data = (void *)data;
event_filters = (Ecore_Event_Filter *)eina_inlist_append(EINA_INLIST_GET(event_filters), EINA_INLIST_GET(ef));
unlock:
_ecore_unlock();
return ef;
}
EAPI void *
ecore_event_filter_del(Ecore_Event_Filter *ef)
{
void *data = NULL;
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
_ecore_lock();
if (!ECORE_MAGIC_CHECK(ef, ECORE_MAGIC_EVENT_FILTER))
{
ECORE_MAGIC_FAIL(ef, ECORE_MAGIC_EVENT_FILTER, "ecore_event_filter_del");
goto unlock;
}
EINA_SAFETY_ON_TRUE_GOTO(ef->delete_me, unlock);
ef->delete_me = 1;
event_filters_delete_me = 1;
data = ef->data;
unlock:
_ecore_unlock();
return data;
}
EAPI int
ecore_event_current_type_get(void)
{
EINA_MAIN_LOOP_CHECK_RETURN_VAL(0);
return ecore_raw_event_type;
}
EAPI void *
ecore_event_current_event_get(void)
{
EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL);
return ecore_raw_event_event;
}
EAPI void *
_ecore_event_handler_del(Ecore_Event_Handler *event_handler)
{
EINA_SAFETY_ON_TRUE_RETURN_VAL(event_handler->delete_me, NULL);
event_handler->delete_me = 1;
event_handlers_delete_list = eina_list_append(event_handlers_delete_list, event_handler);
return event_handler->data;
}
void
_ecore_event_shutdown(void)
{
int i;
Ecore_Event_Handler *eh;
Ecore_Event_Filter *ef;
while (events) _ecore_event_del(events);
event_current = NULL;
for (i = 0; i < event_handlers_num; i++)
{
while ((eh = event_handlers[i]))
{
event_handlers[i] = (Ecore_Event_Handler *)eina_inlist_remove(EINA_INLIST_GET(event_handlers[i]), EINA_INLIST_GET(event_handlers[i]));
ECORE_MAGIC_SET(eh, ECORE_MAGIC_NONE);
if (!eh->delete_me) ecore_event_handler_mp_free(eh);
}
}
EINA_LIST_FREE(event_handlers_delete_list, eh)
ecore_event_handler_mp_free(eh);
if (event_handlers) free(event_handlers);
event_handlers = NULL;
event_handlers_num = 0;
event_handlers_alloc_num = 0;
while ((ef = event_filters))
{
event_filters = (Ecore_Event_Filter *)eina_inlist_remove(EINA_INLIST_GET(event_filters), EINA_INLIST_GET(event_filters));
ECORE_MAGIC_SET(ef, ECORE_MAGIC_NONE);
ecore_event_filter_mp_free(ef);
}
event_filters_delete_me = 0;
event_filter_current = NULL;
event_filter_event_current = NULL;
}
int
_ecore_event_exist(void)
{
Ecore_Event *e;
EINA_INLIST_FOREACH(events, e)
if (!e->delete_me) return 1;
return 0;
}
Ecore_Event *
_ecore_event_add(int type,
void *ev,
Ecore_End_Cb func_free,
void *data)
{
Ecore_Event *e;
e = ecore_event_calloc(1);
if (!e) return NULL;
ECORE_MAGIC_SET(e, ECORE_MAGIC_EVENT);
e->type = type;
e->event = ev;
e->func_free = func_free;
e->data = data;
if (inpurge > 0)
{
purge_events = (Ecore_Event *)eina_inlist_append(EINA_INLIST_GET(purge_events), EINA_INLIST_GET(e));
events_num++;
}
else
{
events = (Ecore_Event *)eina_inlist_append(EINA_INLIST_GET(events), EINA_INLIST_GET(e));
events_num++;
}
return e;
}
void *
_ecore_event_del(Ecore_Event *event)
{
void *data;
data = event->data;
if (event->func_free) _ecore_call_end_cb(event->func_free, event->data, event->event);
events = (Ecore_Event *)eina_inlist_remove(EINA_INLIST_GET(events), EINA_INLIST_GET(event));
ECORE_MAGIC_SET(event, ECORE_MAGIC_NONE);
ecore_event_mp_free(event);
events_num--;
return data;
}
static void
_ecore_event_purge_deleted(void)
{
Ecore_Event *itr = events;
inpurge++;
while (itr)
{
Ecore_Event *next = (Ecore_Event *)EINA_INLIST_GET(itr)->next;
if ((!itr->references) && (itr->delete_me))
_ecore_event_del(itr);
itr = next;
}
inpurge--;
while (purge_events)
{
Ecore_Event *e = purge_events;
purge_events = (Ecore_Event *)eina_inlist_remove(EINA_INLIST_GET(purge_events), EINA_INLIST_GET(purge_events));
events = (Ecore_Event *)eina_inlist_append(EINA_INLIST_GET(events), EINA_INLIST_GET(e));
}
}
static inline void
_ecore_event_filters_apply()
{
if (!event_filter_current)
{
/* regular main loop, start from head */
event_filter_current = event_filters;
}
else
{
/* recursive main loop, continue from where we were */
event_filter_current = (Ecore_Event_Filter *)EINA_INLIST_GET(event_filter_current)->next;
}
while (event_filter_current)
{
Ecore_Event_Filter *ef = event_filter_current;
if (!ef->delete_me)
{
ef->references++;
if (ef->func_start)
ef->loop_data = _ecore_call_data_cb(ef->func_start, ef->data);
if (!event_filter_event_current)
{
/* regular main loop, start from head */
event_filter_event_current = events;
}
else
{
/* recursive main loop, continue from where we were */
event_filter_event_current = (Ecore_Event *)EINA_INLIST_GET(event_filter_event_current)->next;
}
while (event_filter_event_current)
{
Ecore_Event *e = event_filter_event_current;
if (!_ecore_call_filter_cb(ef->func_filter, ef->data,
ef->loop_data, e->type, e->event))
{
ecore_event_del(e);
}
if (event_filter_event_current) /* may have changed in recursive main loops */
event_filter_event_current = (Ecore_Event *)EINA_INLIST_GET(event_filter_event_current)->next;
}
if (ef->func_end)
_ecore_call_end_cb(ef->func_end, ef->data, ef->loop_data);
ef->references--;
}
if (event_filter_current) /* may have changed in recursive main loops */
event_filter_current = (Ecore_Event_Filter *)EINA_INLIST_GET(event_filter_current)->next;
}
if (event_filters_delete_me)
{
int deleted_in_use = 0;
Ecore_Event_Filter *l;
for (l = event_filters; l; )
{
Ecore_Event_Filter *ef = l;
l = (Ecore_Event_Filter *)EINA_INLIST_GET(l)->next;
if (ef->delete_me)
{
if (ef->references)
{
deleted_in_use++;
continue;
}
event_filters = (Ecore_Event_Filter *)eina_inlist_remove(EINA_INLIST_GET(event_filters), EINA_INLIST_GET(ef));
ECORE_MAGIC_SET(ef, ECORE_MAGIC_NONE);
ecore_event_filter_mp_free(ef);
}
}
if (!deleted_in_use)
event_filters_delete_me = 0;
}
}
void
_ecore_event_call(void)
{
Eina_List *l, *l_next;
Ecore_Event_Handler *eh;
_ecore_event_filters_apply();
if (!event_current)
{
/* regular main loop, start from head */
event_current = events;
event_handler_current = NULL;
}
while (event_current)
{
Ecore_Event *e = event_current;
int handle_count = 0;
if (e->delete_me)
{
event_current = (Ecore_Event *)EINA_INLIST_GET(event_current)->next;
continue;
}
ecore_raw_event_type = e->type;
ecore_raw_event_event = e->event;
e->references++;
if ((e->type >= 0) && (e->type < event_handlers_num))
{
if (!event_handler_current)
{
/* regular main loop, start from head */
event_handler_current = event_handlers[e->type];
}
else
{
/* recursive main loop, continue from where we were */
event_handler_current = (Ecore_Event_Handler *)EINA_INLIST_GET(event_handler_current)->next;
}
while ((event_handler_current) && (!e->delete_me))
{
eh = event_handler_current;
if (!eh->delete_me)
{
Eina_Bool ret;
handle_count++;
eh->references++;
ret = _ecore_call_handler_cb(eh->func, eh->data, e->type, e->event);
eh->references--;
if (!ret)
{
event_handler_current = NULL;
break; /* 0 == "call no further handlers" */
}
}
if (event_handler_current) /* may have changed in recursive main loops */
event_handler_current = (Ecore_Event_Handler *)EINA_INLIST_GET(event_handler_current)->next;
}
}
while (event_handlers_add_list)
{
eh = event_handlers_add_list;
event_handlers_add_list = (Ecore_Event_Handler *)eina_inlist_remove(EINA_INLIST_GET(event_handlers_add_list), EINA_INLIST_GET(eh));
event_handlers[eh->type] = (Ecore_Event_Handler *)eina_inlist_append(EINA_INLIST_GET(event_handlers[eh->type]), EINA_INLIST_GET(eh));
}
/* if no handlers were set for EXIT signal - then default is */
/* to quit the main loop */
if ((e->type == ECORE_EVENT_SIGNAL_EXIT) && (handle_count == 0))
ecore_main_loop_quit();
e->references--;
e->delete_me = 1;
if (event_current) /* may have changed in recursive main loops */
event_current = (Ecore_Event *)EINA_INLIST_GET(event_current)->next;
}
ecore_raw_event_type = ECORE_EVENT_NONE;
ecore_raw_event_event = NULL;
_ecore_event_purge_deleted();
EINA_LIST_FOREACH_SAFE(event_handlers_delete_list, l, l_next, eh)
{
if (eh->references) continue;
event_handlers_delete_list = eina_list_remove_list(event_handlers_delete_list, l);
event_handlers[eh->type] = (Ecore_Event_Handler *)eina_inlist_remove(EINA_INLIST_GET(event_handlers[eh->type]), EINA_INLIST_GET(eh));
ECORE_MAGIC_SET(eh, ECORE_MAGIC_NONE);
ecore_event_handler_mp_free(eh);
}
}
void *
_ecore_event_signal_user_new(void)
{
Ecore_Event_Signal_User *e;
e = calloc(1, sizeof(Ecore_Event_Signal_User));
return e;
}
void *
_ecore_event_signal_hup_new(void)
{
Ecore_Event_Signal_Hup *e;
e = calloc(1, sizeof(Ecore_Event_Signal_Hup));
return e;
}
void *
_ecore_event_signal_exit_new(void)
{
Ecore_Event_Signal_Exit *e;
e = calloc(1, sizeof(Ecore_Event_Signal_Exit));
return e;
}
void *
_ecore_event_signal_power_new(void)
{
Ecore_Event_Signal_Power *e;
e = calloc(1, sizeof(Ecore_Event_Signal_Power));
return e;
}
void *
_ecore_event_signal_realtime_new(void)
{
return calloc(1, sizeof(Ecore_Event_Signal_Realtime));
}
| 2.078125 | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.