blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
2
268
content_id
stringlengths
40
40
detected_licenses
listlengths
0
58
license_type
stringclasses
2 values
repo_name
stringlengths
5
118
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
816 values
visit_date
timestamp[us]
revision_date
timestamp[us]
committer_date
timestamp[us]
github_id
int64
2.31k
677M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
23 values
gha_event_created_at
timestamp[us]
gha_created_at
timestamp[us]
gha_language
stringclasses
151 values
src_encoding
stringclasses
33 values
language
stringclasses
1 value
is_vendor
bool
2 classes
is_generated
bool
2 classes
length_bytes
int64
3
10.3M
extension
stringclasses
119 values
content
stringlengths
3
10.3M
authors
listlengths
1
1
author_id
stringlengths
0
228
304181f37da995141b8b9bb074e5f52ebc62d7d8
4aca3d3cdd148c665be67d4b30425ef7f6d06fa5
/projects/pca301_rfm69_regreg/pinkie_cfg.h
55fdc5504d19d326648d36e2ce0de9d123409e2c
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
sven/pinkie
41ef3600bfb9749c9bc2f2a26ea554261b8a39ca
265a3a3e0a289e354aa8a1c60e1420f2461a3ae0
refs/heads/main
2021-11-24T19:59:51.012873
2021-11-07T13:02:32
2021-11-07T13:02:32
130,580,701
0
0
null
null
null
null
UTF-8
C
false
false
666
h
/** * @brief Pinkie - Configuration Header * * Copyright (c) 2017-2018, Sven Bachmann <dev@mcbachmann.de> * * Licensed under the MIT license, see LICENSE for details. */ #ifndef PINKIE_CFG_H #define PINKIE_CFG_H /* Configure the highest integer width that must be supported by printf. * * Allowed values are: * 1 - 8-bit * 2 - 16-bit * 4 - 32-bit * 8 - 64-bit */ #define PINKIE_CFG_PRINTF_MAX_INT 8 /* Configure the highest integer width that must be supported by sscanf. * * Allowed values are: * 1 - 8-bit * 2 - 16-bit * 4 - 32-bit * 8 - 64-bit */ #define PINKIE_CFG_SSCANF_MAX_INT 8 #endif /* PINKIE_CFG_H */
[ "dev@mcbachmann.de" ]
dev@mcbachmann.de
af99b4d29d80d92528fd551388f1364889ac5014
a4bb67e3fcafb43b46610675801a3db90e63a329
/tests/upd765-test.c
4ffce2a48bf1ed898cd1935c274198289938164a
[ "MIT" ]
permissive
kimstacy/chips-test
25673a79f554fee66d149f57acd157ac72f10840
f63750b9195e0bc2cc7ba01eccadce00d7e55680
refs/heads/master
2023-06-22T06:26:28.241449
2021-07-17T17:28:53
2021-07-17T17:28:53
null
0
0
null
null
null
null
UTF-8
C
false
false
5,016
c
//------------------------------------------------------------------------------ // upd765-test.c //------------------------------------------------------------------------------ #define CHIPS_IMPL #include "chips/upd765.h" #include "utest.h" #define T(b) ASSERT_TRUE(b) static upd765_t upd; static int cur_track[4]; static uint8_t status(void) { uint64_t pins = UPD765_CS|UPD765_RD; pins = upd765_iorq(&upd, pins); return UPD765_GET_DATA(pins); } static void wr(uint8_t val) { uint64_t pins = UPD765_CS|UPD765_WR|UPD765_A0; UPD765_SET_DATA(pins, val); upd765_iorq(&upd, pins); } static uint8_t rd(void) { uint64_t pins = UPD765_CS|UPD765_RD|UPD765_A0; pins = upd765_iorq(&upd, pins); return UPD765_GET_DATA(pins); } static int seek_track(int drive, int track, void* user_data) { (void)user_data; assert((drive >= 0) && (drive < 4)); cur_track[drive] = track; return UPD765_RESULT_SUCCESS; } static int seek_sector(int drive, upd765_sectorinfo_t* inout_info, void* user_data) { // FIXME (void)drive; (void)inout_info; (void)user_data; return UPD765_RESULT_SUCCESS; } static int read_data(int drive, uint8_t h, void* user_data, uint8_t* out_data) { (void)drive; (void)h; (void)user_data; *out_data = 0; return UPD765_RESULT_SUCCESS; } static int trackinfo(int drive, int side, void* user_data, upd765_sectorinfo_t* out_info) { (void)user_data; out_info->physical_track = cur_track[drive]; out_info->c = cur_track[drive]; out_info->h = side; out_info->r = 0xC1; out_info->n = 2; out_info->st1 = 0; out_info->st2 = 0; return UPD765_RESULT_SUCCESS; } static void driveinfo(int drive, void* user_data, upd765_driveinfo_t* out_info) { (void)user_data; out_info->physical_track = cur_track[drive]; out_info->sides = 1; out_info->head = 0; out_info->ready = true; out_info->write_protected = false; out_info->fault = false; } static void init() { upd765_init(&upd, &(upd765_desc_t){ .seektrack_cb = seek_track, .seeksector_cb = seek_sector, .trackinfo_cb = trackinfo, .read_cb = read_data, .driveinfo_cb = driveinfo }); } UTEST(upd765, init) { init(); T(upd.phase == UPD765_PHASE_IDLE); T(UPD765_PHASE_IDLE == upd.phase); T(0 == upd.fifo_pos); T(UPD765_STATUS_RQM == status()); } UTEST(upd765, invalid_command) { init(); wr(0x01); T(UPD765_PHASE_RESULT == upd.phase); T((UPD765_STATUS_RQM|UPD765_STATUS_CB|UPD765_STATUS_DIO) == status()); T(0x80 == upd.fifo[0]); T(0x80 == rd()); T(UPD765_PHASE_IDLE == upd.phase); T(UPD765_STATUS_RQM == status()); } UTEST(upd765, specify_command) { init(); /* this is what the Amstrad CPC sends after boot to configure the floppy controller */ wr(0x03); T(UPD765_PHASE_COMMAND == upd.phase); T((UPD765_STATUS_RQM|UPD765_STATUS_CB) == status()); T(0x03 == upd.fifo[0]); T(1 == upd.fifo_pos); wr(0xA1); T(UPD765_PHASE_COMMAND == upd.phase); T((UPD765_STATUS_RQM|UPD765_STATUS_CB) == status()); T(0xA1 == upd.fifo[1]); T(2 == upd.fifo_pos); wr(0x03); T(UPD765_PHASE_IDLE == upd.phase); T(UPD765_STATUS_RQM == status()); T(0x03 == upd.fifo[2]); T(3 == upd.fifo_pos); } #define DO_RECALIBRATE() \ cur_track[0] = 10; \ wr(0x07); \ T(UPD765_PHASE_COMMAND == upd.phase); \ T((UPD765_STATUS_RQM|UPD765_STATUS_CB) == status()); \ T(0x07 == upd.fifo[0]); \ T(1 == upd.fifo_pos); \ wr(0x00); \ T(UPD765_PHASE_IDLE == upd.phase); \ T(UPD765_STATUS_RQM == status()); \ T(UPD765_ST0_SE == upd.st[0]); \ T(cur_track[0] == 0); #define DO_SENSE_INTERRUPT_STATUS() \ wr(0x08); \ T(UPD765_PHASE_RESULT == upd.phase); \ T((UPD765_STATUS_RQM|UPD765_STATUS_CB|UPD765_STATUS_DIO) == status()); \ T(UPD765_ST0_SE == upd.st[0]); \ T(2 == upd.fifo_num); \ T(UPD765_ST0_SE == upd.fifo[0]); \ T(0 == upd.fifo[1]); \ T(UPD765_ST0_SE == rd()); \ T(0 == rd()); \ T(UPD765_PHASE_IDLE == upd.phase); \ T(UPD765_STATUS_RQM == status()); #define DO_READ_ID() \ wr(0x0A); \ T(UPD765_PHASE_COMMAND == upd.phase); \ T((UPD765_STATUS_RQM|UPD765_STATUS_CB) == status()); \ T(0x0A == upd.fifo[0]); \ T(1 == upd.fifo_pos); \ T(2 == upd.fifo_num); \ wr(0x00); \ T(UPD765_PHASE_RESULT == upd.phase); \ T((UPD765_STATUS_RQM|UPD765_STATUS_CB|UPD765_STATUS_DIO) == status()); \ T(7 == upd.fifo_num); \ UTEST(upd765, recalibrate) { init(); DO_RECALIBRATE(); } UTEST(upd765, sense_interrupt_status) { init(); DO_RECALIBRATE(); DO_SENSE_INTERRUPT_STATUS(); } UTEST(upd765, read_id) { init(); DO_RECALIBRATE(); DO_SENSE_INTERRUPT_STATUS(); DO_READ_ID(); }
[ "floooh@gmail.com" ]
floooh@gmail.com
9689fd7b5798f34014a60f2ba01001577e125440
06497d8c2f1dc5cfab493d1d6a6345c2c3fd3e1f
/sw/nRF51_SDK_10.0.0_dc26b5e/components/ant/ant_key_manager/ant_key_manager.h
0c571a8b586bc34ed728985d011f8dd4e6608cd4
[ "Apache-2.0" ]
permissive
kevin-ledinh/banana-tree
6ab403bac511dd0205c79d55a8d0f0bfefc03bfc
3e022bf5a88edab57efd8902d511b337389290a4
refs/heads/master
2020-05-21T13:30:49.107162
2017-02-26T15:38:27
2017-02-26T15:38:27
46,086,866
1
1
null
null
null
null
UTF-8
C
false
false
1,864
h
/* Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved. * * The information contained herein is property of Nordic Semiconductor ASA. * Terms and conditions of usage are described in detail in NORDIC * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. * * Licensees are granted free, non-transferable use of the information. NO * WARRANTY of ANY KIND is provided. This heading must NOT be removed from * the file. * */ #ifndef ANT_KEY_MANAGER_H__ #define ANT_KEY_MANAGER_H__ #include "stdint.h" /** * @file */ /** * @defgroup ant_key_manager ANT key manager * @{ * @ingroup ant_sdk_utils * @brief Module for registering common and custom ANT network keys. */ /**@brief Function for registering a custom network key. * * @param[in] network_number Network key number. * @param[in] p_network_key Pointer to the custom ANT network key. * * @return A SoftDevice error code. */ uint32_t ant_custom_key_set(uint8_t network_number, uint8_t * p_network_key); /**@brief Function for registering an ANT+ network key. * * The key must be defined by @ref ANT_PLUS_NETWORK_KEY. * * @note The ANT+ Network Key is available for ANT+ Adopters. Go to http://thisisant.com * to become an ANT+ Adopter and access the key. * * @param[in] network_number Network key number. * * @return A SoftDevice error code. */ uint32_t ant_plus_key_set(uint8_t network_number); /**@brief Function for registering an ANT-FS network key. * * The key must be defined by @ref ANT_FS_NETWORK_KEY. * * @note The ANT+ Network Key is available for ANT+ Adopters. Go to http://thisisant.com * to become an ANT+ Adopter and access the key. * * @param[in] network_number Network key number. * * @return A SoftDevice error code. */ uint32_t ant_fs_key_set(uint8_t network_number); /** * @} */ #endif // ANT_KEY_MANAGER_H__
[ "tcnhan2512@gmail.com" ]
tcnhan2512@gmail.com
4c4b582aefe2a7b5f95dfe375358cba7f3600455
758c274c2c15af089c1ff966732851e5b418626f
/chap19/exercise4a/stack.c
5f01b27da69f14fb2d534f50daf8e0b8b2fc9114
[]
no_license
drguildo/csolutions
4ae213df3fa53a51457a076b309cc36f0a5d1c1e
93d079411e0138bb0c89f68354cab5d79c91cb0d
refs/heads/master
2021-01-01T18:42:39.450981
2008-06-25T19:04:02
2008-06-25T19:04:02
117,727
1
0
null
2014-03-22T18:05:43
2009-01-30T00:18:27
null
UTF-8
C
false
false
609
c
#include <stdio.h> #include "stack.h" #ifndef TRUE #define TRUE 1 #endif #ifndef FALSE #define FALSE 0 #endif static int is_full(Stack *); void make_empty(Stack *s) { s->top = 0; } int is_empty(Stack *s) { return s->top == 0; } void push(Stack *s, int n) { if (is_full(s)) { puts("error: stack full"); } else { s->contents[s->top++] = n; } } int pop(Stack *s) { if (is_empty(s)) { puts("error: stack empty"); return -1; } else { return s->contents[--s->top]; } } static int is_full(Stack *s) { return s->top == STACK_SIZE; }
[ "sjm@spamcop.net" ]
sjm@spamcop.net
7eaf87fa88c82950bacce95b13e5112842c9a1e8
38927d2cbbcaa32b5056a3965025d8bd3d6cadb8
/src/game_tab_setup.c
1531c1feecc59036576b075f931e2521c0e50697
[]
no_license
alaborde29/Epitech_navy
8c73158cf52299e45518d2b17a394f3e5d63c816
a67d0eeb7f00c446d3ef5177b73af5cb7f49bfd0
refs/heads/master
2023-06-06T08:55:44.082724
2021-06-29T09:34:28
2021-06-29T09:34:28
381,301,856
0
0
null
null
null
null
UTF-8
C
false
false
1,547
c
/* ** EPITECH PROJECT, 2020 ** B-PSU-101-NAN-1-1-navy-enzo.bonato ** File description: ** game_tab_setup */ #include "my.h" #include "navy.h" void put_this_boat(char **array, char *boat) { vector2i_t pos1 = create_vetor2i(boat[2] - 'A', boat[3] - '0' - 1); vector2i_t pos2 = create_vetor2i(boat[5] - 'A', boat[6] - '0' - 1); int boat_orientation = find_boat_orientation(boat); if (boat_orientation == 1) { if (pos2.y < pos1.y) my_swap(&pos2.y, &pos1.y); for (int n = pos1.y + 2; n != pos2.y + 3; n++) { array[n][pos1.x * 2 + 2] = boat[0]; } } if (boat_orientation == 2) { if (pos2.x < pos1.x) my_swap(&pos2.y, &pos1.y); for (int n = pos1.x; n != pos2.x + 1; n++) array[pos1.y + 2][n * 2 + 2] = boat[0]; } return ; } void put_boats_in_tab(char **array, char *pos_path) { char *pos = 0; char **pos_tab = 0; pos = read_file(pos_path, pos); pos_tab = split_lines(pos, 5); for (int i = 0; i != 4; i++) { put_this_boat(array, pos_tab[i]); } return ; } char **setup_blank_tab(void) { char **tab = malloc(sizeof(char *) * 19); char stamp[19] = "X|. . . . . . . .\0"; for (int i = 0; i != 10; i++) { tab[i] = malloc(sizeof(char) * 19); tab[i][10] = '\0'; } tab[0] = " |A B C D E F G H\0"; tab[1] = "-+---------------\0"; for (int j = 2; j != 10; j++) { my_strdup(stamp, tab[j]); tab[j][0] = j - 1 + '0'; } return (tab); }
[ "alaborde@localhost.localdomain" ]
alaborde@localhost.localdomain
d7068c2a56b4c7ebd12da854273cb9cba44f174f
467b89b95c9e599f41f6535b15248614776964c5
/util.c
1bda842a89f4017a830478f2e839d7ff3e97bbcd
[ "Artistic-1.0-Perl" ]
permissive
rhesa/AutoTest
8b80df38efa6d6bc776d17aca11bb13dc1e2a96b
1d7a70f807187e9c1630ef9861e75f9e1d6cc485
refs/heads/master
2021-01-17T07:57:55.092463
2012-07-25T01:31:24
2012-07-25T01:31:24
null
0
0
null
null
null
null
UTF-8
C
false
false
1,551
c
#include "auto_test.h" bool match(const char *from, const char *to) { bool ret = false; size_t from_size = strlen(from) + 1; size_t to_size = strlen(to) + 1; if (from_size == to_size && !strncmp(from, to, to_size)) { ret = true; } return ret; } bool find(const char *targ, char c) { bool ret = false; size_t size = strlen(targ); int i = 0; for (i = 0; i < size; i++) { if (targ[i] == c) { ret = true; break; } } return ret; } static int memory_leaks = 0; void *safe_malloc(size_t size) { void *ret = malloc(size); if (!ret) { fprintf(stderr, "ERROR!!:cannot allocate memory\n"); exit(EXIT_FAILURE); } memset(ret, 0, size); memory_leaks += size; return ret; } void safe_free(void *ptr, size_t size) { if (ptr) { free(ptr); memory_leaks -= size; ptr = NULL; } } int leaks(void) { return memory_leaks; } void write_space(FILE *fp, int space_num, bool comment_out_flag) { int i = 0; if (comment_out_flag) fprintf(fp, "#"); for (i = 0; i < space_num; i++) { fprintf(fp, " "); } } char *cwb; int cwb_idx = 0; inline void write_cwb(char *buf) { size_t buf_size = strlen(buf); strncpy(cwb + cwb_idx, buf, buf_size); cwb_idx += buf_size; if (cwb_idx > MAX_CWB_SIZE) { fprintf(stderr, "ERROR: cwb_idx = [%d] > %d\n", cwb_idx, MAX_CWB_SIZE); memset(cwb, 0, MAX_CWB_SIZE); cwb_idx = 0; longjmp(jbuf, 1); } }
[ "goccy54@gmail.com" ]
goccy54@gmail.com
aeab7fc4c042c8131983bdc7ff149e87a5263e63
01fbaa8ef4ebea31f9760281217e2d3e5627dc75
/recoThread.h
b5b3d9641b5b75230b35986075254e33771a9445
[]
no_license
cgoutorbe/parseAisTest
2d11b6ef4cda71b6317a72cabeec7f8cfe766af9
941648a28573679818b0d0ca22633ee24bf10dd1
refs/heads/master
2021-09-19T09:22:13.412500
2018-07-26T10:41:11
2018-07-26T10:41:11
null
0
0
null
null
null
null
UTF-8
C
false
false
228
h
int connect_socket(int sock, struct sockaddr_in* adr,int size); int adr_init(struct sockaddr_in* adr); int receive_NMEA(int sock, char* buffer); int is_disconnected(int sock); int use_buffer(char* buffer); int reception_loop();
[ "charlie.goutorbe@gmail.com" ]
charlie.goutorbe@gmail.com
3735934204087af7bd902137b90d55e080f01835
8a01fb267f58c8fc993cca431248980be22626a9
/peek-build/m23/csw-system/drv_core/abb/bspTwl3029_UsbOtg.c
e4a81b6008794a068b48edc02575ab534ca3c664
[]
no_license
WA9ACE/PeekLinux
bd3a223ae3e9f0d59f21cf94849ad688befa4809
24327182a829108dc2625a8c6ff4ad6e5e6d5a60
refs/heads/master
2022-11-29T23:44:14.601896
2020-08-08T16:52:35
2020-08-08T16:52:35
286,082,137
2
1
null
null
null
null
UTF-8
C
false
false
8,183
c
/****************************************************************************** * WIRELESS COMMUNICATION SYSTEM DEVELOPMENT * * (C) 2004 Texas Instruments France. All rights reserved * * Author : Mary TOOHER * * * Important Note * -------------- * * This S/W is a preliminary version. It contains information on a product * under development and is issued for evaluation purposes only. Features * characteristics, data and other information are subject to change. * * The S/W is furnished under Non Disclosure Agreement and may be used or * copied only in accordance with the terms of the agreement. It is an offence * to copy the software in any way except as specifically set out in the * agreement. No part of this document may be reproduced or transmitted in any * form or by any means, electronic or mechanical, including photocopying and * recording, for any purpose without the express written permission of Texas * Instruments Inc. * ****************************************************************************** * * FILE NAME: UsbOtg.c * * * PURPOSE: All Twl3029 ( Triton ) USB Transceiver related functions * * FILE REFERENCES: * * Name IO Description * ------------- -- --------------------------------------------- * * * * EXTERNAL VARIABLES: * * Source: * * Name Type IO Description * ------------- --------------- -- ------------------------------ * * d_ram_loader T_RAM_LOADER IO RAM loader structure * * * EXTERNAL REFERENCES: * * Name Description * ------------------ ------------------------------------------------------- * * * * ABNORMAL TERMINATION CONDITIONS, ERROR AND WARNING MESSAGES: * * * * ASSUMPTION, CONSTRAINTS, RESTRICTIONS: * * * * NOTES: * * * * REQUIREMENTS/FUNCTIONAL SPECIFICATION REFERENCES: * * * * * DEVELOPMENT HISTORY: * * Date Name(s) Version Description * ---------- -------------- ------- -------------------------------------- * 29/11/2004 Mary Tooher V1.0.0 First implementation */ /******************************************************************************* * includes */ #include "types.h" #include "bspTwl3029.h" #include "bspTwl3029_Int_Map.h" #include "bspTwl3029_Aux_Map.h" #include "bspTwl3029_Aux_Llif.h" #include "bspTwl3029_Pwr_Map.h" #include "bspTwl3029_Pwr_Llif.h" #include "bspTwl3029_I2c.h" #include "bspTwl3029_Intc.h" #include "bspI2c.h" #include "bspTwl3029_UsbOtg.h" /******************************************************************************* * Defines and Macros */ /******************************************************************************* * Local Data */ /******************************************************************************** * Local function declarations */ /********************************************************************************* * Private (Local) Functions */ /********************************************************************************* * Public Functions */ /*============================================================================= * Function: bspTwl3029_UsbOtg_getVendorId * * Description: * reads the two vendor registers and returns 16 bit vendor ID * * Inputs: none * * * Returns: BspTwl3029_UsbVendorRegister - 16 bit vendor ID * * Notes: this function requires no callback arg shadow register * ( not h/w ) are read */ BspTwl3029_UsbVendorRegister bspTwl3029_UsbOtg_getVendorId(void) { /* just read from shadow registers */ BspTwl3029_UsbVendorRegister regValue; BspTwl3029_I2C_RegData tmpCtrlRegData_Lsb, tmpCtrlRegData_Msb; /* just read from shadow registers */ /* read shadow registers */ BspTwl3029_I2c_shadowRegRead(BSP_TWL3029_I2C_USB, BSP_TWL3029_MAP_USB_VENDOR_ID_LSB_OFFSET, &tmpCtrlRegData_Lsb); /* read shadow registers */ BspTwl3029_I2c_shadowRegRead(BSP_TWL3029_I2C_USB, BSP_TWL3029_MAP_USB_VENDOR_ID_MSB_OFFSET, &tmpCtrlRegData_Msb); regValue = (((BspTwl3029_UsbIdRegister)tmpCtrlRegData_Msb << 8) |((BspTwl3029_UsbIdRegister)tmpCtrlRegData_Lsb )); return regValue; } /*============================================================================= * Function: bspTwl3029_UsbOtg_getProductId * * Description: * reads the two vendor registers and returns 16 bit product ID * * Inputs: none * * * Returns: BspTwl3029_UsbIdRegister - 16 bit product ID * * Notes: this function requires no callback arg shadow register * ( not h/w ) are read */ BspTwl3029_UsbIdRegister bspTwl3029_UsbOtg_getProductId(void) { BspTwl3029_I2C_RegData tmpCtrlRegData_Lsb, tmpCtrlRegData_Msb; /* just read from shadow registers */ BspTwl3029_UsbIdRegister regValue; /* read shadow registers */ BspTwl3029_I2c_shadowRegRead(BSP_TWL3029_I2C_USB, BSP_TWL3029_MAP_USB_PRODUCT_ID_LSB_OFFSET, &tmpCtrlRegData_Lsb); /* read shadow registers */ BspTwl3029_I2c_shadowRegRead(BSP_TWL3029_I2C_USB, BSP_TWL3029_MAP_USB_PRODUCT_ID_MSB_OFFSET, &tmpCtrlRegData_Msb); regValue = (((BspTwl3029_UsbIdRegister)tmpCtrlRegData_Msb << 8) |((BspTwl3029_UsbIdRegister)tmpCtrlRegData_Lsb )); return regValue; } /*============================================================================= * Fucntion bspTwl3029_UsbOtg_TransceiverEnable * * Description: switchs on/off analog and /or digital parts of USB transceiver */ BspTwl3029_ReturnCode bspTwl3029_UsbOtg_TransceiverEnable(BspTwl3029_I2C_CallbackPtr callbackFuncPtr, BspTwl3029_UsbOtg_Enable enable, BspTwl3029_UsbOtg_pwrResource pwr) { BspTwl3029_ReturnCode returnVal = BSP_TWL3029_RETURN_CODE_FAILURE; /* I2C array */ Bsp_Twl3029_I2cTransReqArray i2cTransArray; Bsp_Twl3029_I2cTransReqArrayPtr i2cTransArrayPtr= &i2cTransArray; /* twl3029 I2C reg info struct */ BspTwl3029_I2C_RegisterInfo regInfo[8] ; BspTwl3029_I2C_RegisterInfo* regInfoPtr = regInfo; BspTwl3029_I2C_RegData tmpAuxToggle1Data , tmpAuxToggle2Data = 0; Uint8 togbSetShift = 0; Uint16 count = 0; /* check validity of args */ if ((enable > BSP_TWL3029_USBOTG_ENABLE) ||( pwr > 3)) { return returnVal; } /* config callback function struct */ if (callbackFuncPtr != NULL) { i2cTransArrayPtr = (Bsp_Twl3029_I2cTransReqArrayPtr)callbackFuncPtr->i2cTransArrayPtr; } /* note: Power is set/reset through TOGB register and powerstaus is given in PWRONSTATUS register */ if ( enable == BSP_TWL3029_USBOTG_DISABLE ) { togbSetShift = 0; /* reset shift*/ } else { /*set shift The "set" bits in TOGGLE register is the same as the 'reset' bit shifted by 1*/ togbSetShift = 1; } if ( pwr & 1) { tmpAuxToggle1Data = ( 1 << (BSP_TWL3029_LLIF_AUX_REG_TOGGLE1_USBDR_OFFSET + togbSetShift )); returnVal= BspTwl3029_I2c_regQueWrite(BSP_TWL3029_I2C_AUD,BSP_TWL3029_MAP_AUX_REG_TOGGLE1_OFFSET, tmpAuxToggle1Data, regInfoPtr++) ; count++; } if ( pwr & 2) { tmpAuxToggle2Data = ( 1 << (BSP_TWL3029_LLIF_AUX_REG_TOGGLE2_USBAR_OFFSET + togbSetShift )); returnVal= BspTwl3029_I2c_regQueWrite(BSP_TWL3029_I2C_AUD,BSP_TWL3029_MAP_AUX_REG_TOGGLE2_OFFSET, tmpAuxToggle2Data, regInfoPtr++) ; count++; } /* now request to I2C manager to write to Triton AUX_TOGGLE registers */ if ((count > 0 ) && (returnVal != BSP_TWL3029_RETURN_CODE_FAILURE)) { returnVal = BspTwl3029_I2c_regInfoSend(regInfo,(Uint16)count,callbackFuncPtr, (BspI2c_TransactionRequest*)i2cTransArrayPtr); } return returnVal; }
[ "andrey@e6eaa9d7-a8e6-4b40-915f-875ea51fe5d1" ]
andrey@e6eaa9d7-a8e6-4b40-915f-875ea51fe5d1
9aac7bcfe5467b03455c3f234fbf96941d7ae48e
f83daaad4ecab1290db19d33c59d3b52613ff547
/2AHME/ue14_felder/main.c
b54c30e9b52a282b0d617f5eb421781748fda91e
[ "MIT" ]
permissive
kosphm18/aiit
4a62a98eea0c6713c1fcb1aa57cffe6d7edcadac
1ac9a6253ee7af8191f8d709bc6ddce82f7e3336
refs/heads/master
2021-07-02T17:14:52.206666
2021-02-04T08:44:48
2021-02-04T08:44:48
220,440,331
0
0
null
null
null
null
UTF-8
C
false
false
4,962
c
#include <stdio.h> double *print1DimFeld(double feld[], int anzahl) { printf("print1DimFeld:\n"); // for (int i = 0; i < sizeof(feld) / sizeof(double); i++) { // sizeof(feld) => 40? // sizeof(feld) => 8 // sizeof(double) => 8 for (int i = 0; i < anzahl; i++) { printf("feld[%d] %p => %f\n", i, &feld[i], feld[i]); } printf("\n\n"); return &feld[0]; } void eindimensionalesFeld() { char text1[] = "Hi"; // -128..127, ASCII 0..127 <-> Zeichen printf("%s\n", text1); printf("text1: sizeof(text1) = %d Bytes\n", (int)sizeof(text1)); for (int i = 0; i < sizeof(text1); i++) { printf(" %d", (int)text1[i]); } // 1.Feldelement -> Index 0 ! // 2.Feldelement -> Index 1 printf("\n\n"); char text2[] = { 'H', 'i', 0}; printf("text2: %s\n", text2); printf("sizeof(text2) = %d Bytes\n", (int)sizeof(text2)); for (int i = 0; i < sizeof(text2); i++) { printf(" %d", (int)text2[i]); } printf("\n\n"); char text3[10] = { 'H', 'i', 0}; printf("text3: %s\n", text3); printf("text3: %s\n", text3); printf("sizeof(text3) = %d Bytes\n", (int)sizeof(text3)); for (int i = 0; i < sizeof(text3); i++) { printf(" %d", (int)text3[i]); } printf("\n\n"); double df1[] = { 1.0, 2.0, 3.0}; printf("sizeof(df1) = %d Bytes\n", (int)sizeof(df1)); for (int i = 0; i < sizeof(df1) / sizeof(double); i++) { printf(" %f", df1[i]); } printf("\n\n"); double df2[5] = { 1.0, 2.0, 3.0, 4.0 }; printf("sizeof(df2) = %d Bytes\n", (int)sizeof(df2)); for (int i = 0; i < sizeof(df2) / sizeof(df2[0]); i++) { printf(" %f", df2[i]); } printf("\n\n"); // ---------------------------------------------- // text1 = "Ha"; // rext1 = { 'H' , 'a', '0' }; text1[0] = 'H'; text1[1] = 'a'; text1[2] = 0; printf("%s\n", text1); // ---------------------------------------------- double *df3 = print1DimFeld(df2, sizeof(df2) / sizeof(double)); printf("sizeof(df3) = %d Bytes\n", (int)sizeof(df3)); for (int i = 0; i < 5; i++) { printf(" %f", df3[i]); } printf("\n\n"); } void print2DimFeld(double f[][3], int anzahl) { printf("print2DimFeld:\n"); for (int i = 0; i < anzahl; i++) { for (int j = 0; j < 3; j++) { printf("feld[%d][%d] %p => %f\n", i, j, &f[i][j], f[i][j]); } } printf("\n\n"); } void zweidimensionaleFelder() { // xx-Achse & y-Achse // 4 * 3 = 12 Elemente -> 12 * 8 = 96 double f[4][3] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } }; printf("\n\n2 Dimensionen:\n"); printf("sizeof(f) = %d Bytes\n", (int)sizeof(f)); printf("f[0][0] %p => %f\n", &f[0][0], f[0][0]); printf("f[0][1] %p => %f\n", &f[0][1], f[0][1]); printf("f[0][2] %p => %f\n", &f[0][2], f[0][2]); printf("f[1][0] %p => %f\n", &f[1][0], f[1][0]); printf("f[1][1] %p => %f\n", &f[1][1], f[1][1]); printf("f[1][2] %p => %f\n", &f[1][2], f[1][2]); printf("f[2][0] %p => %f\n", &f[2][0], f[2][0]); printf("f[2][1] %p => %f\n", &f[2][1], f[2][1]); printf("f[2][2] %p => %f\n", &f[2][2], f[2][2]); printf("f[3][0] %p => %f\n", &f[3][0], f[3][0]); printf("f[3][1] %p => %f\n", &f[3][1], f[3][1]); printf("f[3][2] %p => %f\n", &f[3][2], f[3][2]); // f = { { 1, 2, 3 } }; // nicht moeglich, nur bei Initialisierung erlaubt f[2][0] = 7; f[2][1] = 8; f[2][2] = 9; f[2][3] = 10; print2DimFeld(f, 4); } void print3DimFeld(double x[][3][4], int anzahl) { printf("print3DimFeld:\n"); for (int i = 0; i < anzahl; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 4; k++) { printf("x[%d][%d][%d] %p => %f\n", i, j, k, &x[i][j][k], x[i][j][k]); } } } printf("\n\n"); } void dreidimensionalesFeld() { double f[2][3][4] = { { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 } }, { { 13, 14, 15, 16 }, { 17, 18, 19, 20 }, { 21, 22, 23, 24 } } }; printf("\n\n3 Dimensionen:\n"); printf("sizeof(f) = %d Bytes\n", (int)sizeof(f)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 4; k++) { printf("feld[%d][%d] %p => %f\n", i, j, k, &f[i][j][k], f[i][j][k]); } } } printf("\n\n"); print3DimFeld(f, 2); } int main() { // eindimensionalesFeld(); // zweidimensionaleFelder(); dreidimensionalesFeld(); return 0; }
[ "noreply@github.com" ]
kosphm18.noreply@github.com
59ca1993679901e3b9f3dff6ccfa74c75a4c1d54
7550905c5efaaec2010ab56adda078d03d6a04e3
/archive/master/v0.0.0-2477-gc3cd0ad/arty/net/mor1kx/software/include/generated/csr.h
00146c37e252d460237a711d1dae9cd671770254
[ "MIT", "BSD-2-Clause" ]
permissive
stefanor/HDMI2USB-firmware-prebuilt
9844dd4aaf8ec174417b9a4acbd73f543e0b3bae
2e7dc4e3dcfac6fa947769e4d9477f4aa57a7852
refs/heads/master
2022-01-30T11:04:10.549876
2019-07-21T00:51:32
2019-07-21T00:51:32
115,801,134
0
0
null
2017-12-30T14:14:36
2017-12-30T14:14:36
null
UTF-8
C
false
false
33,964
h
//-------------------------------------------------------------------------------- // Auto-generated by Migen (562c046) & LiteX (113f7f40) on 2019-07-20 22:04:15 //-------------------------------------------------------------------------------- #ifndef __GENERATED_CSR_H #define __GENERATED_CSR_H #include <stdint.h> #ifdef CSR_ACCESSORS_DEFINED extern void csr_writeb(uint8_t value, unsigned long addr); extern uint8_t csr_readb(unsigned long addr); extern void csr_writew(uint16_t value, unsigned long addr); extern uint16_t csr_readw(unsigned long addr); extern void csr_writel(uint32_t value, unsigned long addr); extern uint32_t csr_readl(unsigned long addr); #else /* ! CSR_ACCESSORS_DEFINED */ #include <hw/common.h> #endif /* ! CSR_ACCESSORS_DEFINED */ /* cas */ #define CSR_CAS_BASE 0xe0006800L #define CSR_CAS_LEDS_OUT_ADDR 0xe0006800L #define CSR_CAS_LEDS_OUT_SIZE 1 static inline unsigned char cas_leds_out_read(void) { unsigned char r = csr_readl(0xe0006800L); return r; } static inline void cas_leds_out_write(unsigned char value) { csr_writel(value, 0xe0006800L); } #define CSR_CAS_SWITCHES_IN_ADDR 0xe0006804L #define CSR_CAS_SWITCHES_IN_SIZE 1 static inline unsigned char cas_switches_in_read(void) { unsigned char r = csr_readl(0xe0006804L); return r; } #define CSR_CAS_BUTTONS_EV_STATUS_ADDR 0xe0006808L #define CSR_CAS_BUTTONS_EV_STATUS_SIZE 1 static inline unsigned char cas_buttons_ev_status_read(void) { unsigned char r = csr_readl(0xe0006808L); return r; } static inline void cas_buttons_ev_status_write(unsigned char value) { csr_writel(value, 0xe0006808L); } #define CSR_CAS_BUTTONS_EV_PENDING_ADDR 0xe000680cL #define CSR_CAS_BUTTONS_EV_PENDING_SIZE 1 static inline unsigned char cas_buttons_ev_pending_read(void) { unsigned char r = csr_readl(0xe000680cL); return r; } static inline void cas_buttons_ev_pending_write(unsigned char value) { csr_writel(value, 0xe000680cL); } #define CSR_CAS_BUTTONS_EV_ENABLE_ADDR 0xe0006810L #define CSR_CAS_BUTTONS_EV_ENABLE_SIZE 1 static inline unsigned char cas_buttons_ev_enable_read(void) { unsigned char r = csr_readl(0xe0006810L); return r; } static inline void cas_buttons_ev_enable_write(unsigned char value) { csr_writel(value, 0xe0006810L); } /* ctrl */ #define CSR_CTRL_BASE 0xe0000000L #define CSR_CTRL_RESET_ADDR 0xe0000000L #define CSR_CTRL_RESET_SIZE 1 static inline unsigned char ctrl_reset_read(void) { unsigned char r = csr_readl(0xe0000000L); return r; } static inline void ctrl_reset_write(unsigned char value) { csr_writel(value, 0xe0000000L); } #define CSR_CTRL_SCRATCH_ADDR 0xe0000004L #define CSR_CTRL_SCRATCH_SIZE 4 static inline unsigned int ctrl_scratch_read(void) { unsigned int r = csr_readl(0xe0000004L); r <<= 8; r |= csr_readl(0xe0000008L); r <<= 8; r |= csr_readl(0xe000000cL); r <<= 8; r |= csr_readl(0xe0000010L); return r; } static inline void ctrl_scratch_write(unsigned int value) { csr_writel(value >> 24, 0xe0000004L); csr_writel(value >> 16, 0xe0000008L); csr_writel(value >> 8, 0xe000000cL); csr_writel(value, 0xe0000010L); } #define CSR_CTRL_BUS_ERRORS_ADDR 0xe0000014L #define CSR_CTRL_BUS_ERRORS_SIZE 4 static inline unsigned int ctrl_bus_errors_read(void) { unsigned int r = csr_readl(0xe0000014L); r <<= 8; r |= csr_readl(0xe0000018L); r <<= 8; r |= csr_readl(0xe000001cL); r <<= 8; r |= csr_readl(0xe0000020L); return r; } /* ddrphy */ #define CSR_DDRPHY_BASE 0xe0005800L #define CSR_DDRPHY_HALF_SYS8X_TAPS_ADDR 0xe0005800L #define CSR_DDRPHY_HALF_SYS8X_TAPS_SIZE 1 static inline unsigned char ddrphy_half_sys8x_taps_read(void) { unsigned char r = csr_readl(0xe0005800L); return r; } static inline void ddrphy_half_sys8x_taps_write(unsigned char value) { csr_writel(value, 0xe0005800L); } #define CSR_DDRPHY_CDLY_RST_ADDR 0xe0005804L #define CSR_DDRPHY_CDLY_RST_SIZE 1 static inline unsigned char ddrphy_cdly_rst_read(void) { unsigned char r = csr_readl(0xe0005804L); return r; } static inline void ddrphy_cdly_rst_write(unsigned char value) { csr_writel(value, 0xe0005804L); } #define CSR_DDRPHY_CDLY_INC_ADDR 0xe0005808L #define CSR_DDRPHY_CDLY_INC_SIZE 1 static inline unsigned char ddrphy_cdly_inc_read(void) { unsigned char r = csr_readl(0xe0005808L); return r; } static inline void ddrphy_cdly_inc_write(unsigned char value) { csr_writel(value, 0xe0005808L); } #define CSR_DDRPHY_DLY_SEL_ADDR 0xe000580cL #define CSR_DDRPHY_DLY_SEL_SIZE 1 static inline unsigned char ddrphy_dly_sel_read(void) { unsigned char r = csr_readl(0xe000580cL); return r; } static inline void ddrphy_dly_sel_write(unsigned char value) { csr_writel(value, 0xe000580cL); } #define CSR_DDRPHY_RDLY_DQ_RST_ADDR 0xe0005810L #define CSR_DDRPHY_RDLY_DQ_RST_SIZE 1 static inline unsigned char ddrphy_rdly_dq_rst_read(void) { unsigned char r = csr_readl(0xe0005810L); return r; } static inline void ddrphy_rdly_dq_rst_write(unsigned char value) { csr_writel(value, 0xe0005810L); } #define CSR_DDRPHY_RDLY_DQ_INC_ADDR 0xe0005814L #define CSR_DDRPHY_RDLY_DQ_INC_SIZE 1 static inline unsigned char ddrphy_rdly_dq_inc_read(void) { unsigned char r = csr_readl(0xe0005814L); return r; } static inline void ddrphy_rdly_dq_inc_write(unsigned char value) { csr_writel(value, 0xe0005814L); } #define CSR_DDRPHY_RDLY_DQ_BITSLIP_RST_ADDR 0xe0005818L #define CSR_DDRPHY_RDLY_DQ_BITSLIP_RST_SIZE 1 static inline unsigned char ddrphy_rdly_dq_bitslip_rst_read(void) { unsigned char r = csr_readl(0xe0005818L); return r; } static inline void ddrphy_rdly_dq_bitslip_rst_write(unsigned char value) { csr_writel(value, 0xe0005818L); } #define CSR_DDRPHY_RDLY_DQ_BITSLIP_ADDR 0xe000581cL #define CSR_DDRPHY_RDLY_DQ_BITSLIP_SIZE 1 static inline unsigned char ddrphy_rdly_dq_bitslip_read(void) { unsigned char r = csr_readl(0xe000581cL); return r; } static inline void ddrphy_rdly_dq_bitslip_write(unsigned char value) { csr_writel(value, 0xe000581cL); } /* ethmac */ #define CSR_ETHMAC_BASE 0xe0007800L #define CSR_ETHMAC_SRAM_WRITER_SLOT_ADDR 0xe0007800L #define CSR_ETHMAC_SRAM_WRITER_SLOT_SIZE 1 static inline unsigned char ethmac_sram_writer_slot_read(void) { unsigned char r = csr_readl(0xe0007800L); return r; } #define CSR_ETHMAC_SRAM_WRITER_LENGTH_ADDR 0xe0007804L #define CSR_ETHMAC_SRAM_WRITER_LENGTH_SIZE 4 static inline unsigned int ethmac_sram_writer_length_read(void) { unsigned int r = csr_readl(0xe0007804L); r <<= 8; r |= csr_readl(0xe0007808L); r <<= 8; r |= csr_readl(0xe000780cL); r <<= 8; r |= csr_readl(0xe0007810L); return r; } #define CSR_ETHMAC_SRAM_WRITER_ERRORS_ADDR 0xe0007814L #define CSR_ETHMAC_SRAM_WRITER_ERRORS_SIZE 4 static inline unsigned int ethmac_sram_writer_errors_read(void) { unsigned int r = csr_readl(0xe0007814L); r <<= 8; r |= csr_readl(0xe0007818L); r <<= 8; r |= csr_readl(0xe000781cL); r <<= 8; r |= csr_readl(0xe0007820L); return r; } #define CSR_ETHMAC_SRAM_WRITER_EV_STATUS_ADDR 0xe0007824L #define CSR_ETHMAC_SRAM_WRITER_EV_STATUS_SIZE 1 static inline unsigned char ethmac_sram_writer_ev_status_read(void) { unsigned char r = csr_readl(0xe0007824L); return r; } static inline void ethmac_sram_writer_ev_status_write(unsigned char value) { csr_writel(value, 0xe0007824L); } #define CSR_ETHMAC_SRAM_WRITER_EV_PENDING_ADDR 0xe0007828L #define CSR_ETHMAC_SRAM_WRITER_EV_PENDING_SIZE 1 static inline unsigned char ethmac_sram_writer_ev_pending_read(void) { unsigned char r = csr_readl(0xe0007828L); return r; } static inline void ethmac_sram_writer_ev_pending_write(unsigned char value) { csr_writel(value, 0xe0007828L); } #define CSR_ETHMAC_SRAM_WRITER_EV_ENABLE_ADDR 0xe000782cL #define CSR_ETHMAC_SRAM_WRITER_EV_ENABLE_SIZE 1 static inline unsigned char ethmac_sram_writer_ev_enable_read(void) { unsigned char r = csr_readl(0xe000782cL); return r; } static inline void ethmac_sram_writer_ev_enable_write(unsigned char value) { csr_writel(value, 0xe000782cL); } #define CSR_ETHMAC_SRAM_READER_START_ADDR 0xe0007830L #define CSR_ETHMAC_SRAM_READER_START_SIZE 1 static inline unsigned char ethmac_sram_reader_start_read(void) { unsigned char r = csr_readl(0xe0007830L); return r; } static inline void ethmac_sram_reader_start_write(unsigned char value) { csr_writel(value, 0xe0007830L); } #define CSR_ETHMAC_SRAM_READER_READY_ADDR 0xe0007834L #define CSR_ETHMAC_SRAM_READER_READY_SIZE 1 static inline unsigned char ethmac_sram_reader_ready_read(void) { unsigned char r = csr_readl(0xe0007834L); return r; } #define CSR_ETHMAC_SRAM_READER_LEVEL_ADDR 0xe0007838L #define CSR_ETHMAC_SRAM_READER_LEVEL_SIZE 1 static inline unsigned char ethmac_sram_reader_level_read(void) { unsigned char r = csr_readl(0xe0007838L); return r; } #define CSR_ETHMAC_SRAM_READER_SLOT_ADDR 0xe000783cL #define CSR_ETHMAC_SRAM_READER_SLOT_SIZE 1 static inline unsigned char ethmac_sram_reader_slot_read(void) { unsigned char r = csr_readl(0xe000783cL); return r; } static inline void ethmac_sram_reader_slot_write(unsigned char value) { csr_writel(value, 0xe000783cL); } #define CSR_ETHMAC_SRAM_READER_LENGTH_ADDR 0xe0007840L #define CSR_ETHMAC_SRAM_READER_LENGTH_SIZE 2 static inline unsigned short int ethmac_sram_reader_length_read(void) { unsigned short int r = csr_readl(0xe0007840L); r <<= 8; r |= csr_readl(0xe0007844L); return r; } static inline void ethmac_sram_reader_length_write(unsigned short int value) { csr_writel(value >> 8, 0xe0007840L); csr_writel(value, 0xe0007844L); } #define CSR_ETHMAC_SRAM_READER_EV_STATUS_ADDR 0xe0007848L #define CSR_ETHMAC_SRAM_READER_EV_STATUS_SIZE 1 static inline unsigned char ethmac_sram_reader_ev_status_read(void) { unsigned char r = csr_readl(0xe0007848L); return r; } static inline void ethmac_sram_reader_ev_status_write(unsigned char value) { csr_writel(value, 0xe0007848L); } #define CSR_ETHMAC_SRAM_READER_EV_PENDING_ADDR 0xe000784cL #define CSR_ETHMAC_SRAM_READER_EV_PENDING_SIZE 1 static inline unsigned char ethmac_sram_reader_ev_pending_read(void) { unsigned char r = csr_readl(0xe000784cL); return r; } static inline void ethmac_sram_reader_ev_pending_write(unsigned char value) { csr_writel(value, 0xe000784cL); } #define CSR_ETHMAC_SRAM_READER_EV_ENABLE_ADDR 0xe0007850L #define CSR_ETHMAC_SRAM_READER_EV_ENABLE_SIZE 1 static inline unsigned char ethmac_sram_reader_ev_enable_read(void) { unsigned char r = csr_readl(0xe0007850L); return r; } static inline void ethmac_sram_reader_ev_enable_write(unsigned char value) { csr_writel(value, 0xe0007850L); } #define CSR_ETHMAC_PREAMBLE_CRC_ADDR 0xe0007854L #define CSR_ETHMAC_PREAMBLE_CRC_SIZE 1 static inline unsigned char ethmac_preamble_crc_read(void) { unsigned char r = csr_readl(0xe0007854L); return r; } #define CSR_ETHMAC_PREAMBLE_ERRORS_ADDR 0xe0007858L #define CSR_ETHMAC_PREAMBLE_ERRORS_SIZE 4 static inline unsigned int ethmac_preamble_errors_read(void) { unsigned int r = csr_readl(0xe0007858L); r <<= 8; r |= csr_readl(0xe000785cL); r <<= 8; r |= csr_readl(0xe0007860L); r <<= 8; r |= csr_readl(0xe0007864L); return r; } #define CSR_ETHMAC_CRC_ERRORS_ADDR 0xe0007868L #define CSR_ETHMAC_CRC_ERRORS_SIZE 4 static inline unsigned int ethmac_crc_errors_read(void) { unsigned int r = csr_readl(0xe0007868L); r <<= 8; r |= csr_readl(0xe000786cL); r <<= 8; r |= csr_readl(0xe0007870L); r <<= 8; r |= csr_readl(0xe0007874L); return r; } /* ethphy */ #define CSR_ETHPHY_BASE 0xe0007000L #define CSR_ETHPHY_CRG_RESET_ADDR 0xe0007000L #define CSR_ETHPHY_CRG_RESET_SIZE 1 static inline unsigned char ethphy_crg_reset_read(void) { unsigned char r = csr_readl(0xe0007000L); return r; } static inline void ethphy_crg_reset_write(unsigned char value) { csr_writel(value, 0xe0007000L); } #define CSR_ETHPHY_MDIO_W_ADDR 0xe0007004L #define CSR_ETHPHY_MDIO_W_SIZE 1 static inline unsigned char ethphy_mdio_w_read(void) { unsigned char r = csr_readl(0xe0007004L); return r; } static inline void ethphy_mdio_w_write(unsigned char value) { csr_writel(value, 0xe0007004L); } #define CSR_ETHPHY_MDIO_R_ADDR 0xe0007008L #define CSR_ETHPHY_MDIO_R_SIZE 1 static inline unsigned char ethphy_mdio_r_read(void) { unsigned char r = csr_readl(0xe0007008L); return r; } /* info */ #define CSR_INFO_BASE 0xe0006000L #define CSR_INFO_DNA_ID_ADDR 0xe0006000L #define CSR_INFO_DNA_ID_SIZE 8 static inline unsigned long long int info_dna_id_read(void) { unsigned long long int r = csr_readl(0xe0006000L); r <<= 8; r |= csr_readl(0xe0006004L); r <<= 8; r |= csr_readl(0xe0006008L); r <<= 8; r |= csr_readl(0xe000600cL); r <<= 8; r |= csr_readl(0xe0006010L); r <<= 8; r |= csr_readl(0xe0006014L); r <<= 8; r |= csr_readl(0xe0006018L); r <<= 8; r |= csr_readl(0xe000601cL); return r; } #define CSR_INFO_GIT_COMMIT_ADDR 0xe0006020L #define CSR_INFO_GIT_COMMIT_SIZE 20 #define CSR_INFO_PLATFORM_PLATFORM_ADDR 0xe0006070L #define CSR_INFO_PLATFORM_PLATFORM_SIZE 8 static inline unsigned long long int info_platform_platform_read(void) { unsigned long long int r = csr_readl(0xe0006070L); r <<= 8; r |= csr_readl(0xe0006074L); r <<= 8; r |= csr_readl(0xe0006078L); r <<= 8; r |= csr_readl(0xe000607cL); r <<= 8; r |= csr_readl(0xe0006080L); r <<= 8; r |= csr_readl(0xe0006084L); r <<= 8; r |= csr_readl(0xe0006088L); r <<= 8; r |= csr_readl(0xe000608cL); return r; } #define CSR_INFO_PLATFORM_TARGET_ADDR 0xe0006090L #define CSR_INFO_PLATFORM_TARGET_SIZE 8 static inline unsigned long long int info_platform_target_read(void) { unsigned long long int r = csr_readl(0xe0006090L); r <<= 8; r |= csr_readl(0xe0006094L); r <<= 8; r |= csr_readl(0xe0006098L); r <<= 8; r |= csr_readl(0xe000609cL); r <<= 8; r |= csr_readl(0xe00060a0L); r <<= 8; r |= csr_readl(0xe00060a4L); r <<= 8; r |= csr_readl(0xe00060a8L); r <<= 8; r |= csr_readl(0xe00060acL); return r; } #define CSR_INFO_XADC_TEMPERATURE_ADDR 0xe00060b0L #define CSR_INFO_XADC_TEMPERATURE_SIZE 2 static inline unsigned short int info_xadc_temperature_read(void) { unsigned short int r = csr_readl(0xe00060b0L); r <<= 8; r |= csr_readl(0xe00060b4L); return r; } #define CSR_INFO_XADC_VCCINT_ADDR 0xe00060b8L #define CSR_INFO_XADC_VCCINT_SIZE 2 static inline unsigned short int info_xadc_vccint_read(void) { unsigned short int r = csr_readl(0xe00060b8L); r <<= 8; r |= csr_readl(0xe00060bcL); return r; } #define CSR_INFO_XADC_VCCAUX_ADDR 0xe00060c0L #define CSR_INFO_XADC_VCCAUX_SIZE 2 static inline unsigned short int info_xadc_vccaux_read(void) { unsigned short int r = csr_readl(0xe00060c0L); r <<= 8; r |= csr_readl(0xe00060c4L); return r; } #define CSR_INFO_XADC_VCCBRAM_ADDR 0xe00060c8L #define CSR_INFO_XADC_VCCBRAM_SIZE 2 static inline unsigned short int info_xadc_vccbram_read(void) { unsigned short int r = csr_readl(0xe00060c8L); r <<= 8; r |= csr_readl(0xe00060ccL); return r; } /* sdram */ #define CSR_SDRAM_BASE 0xe0004000L #define CSR_SDRAM_DFII_CONTROL_ADDR 0xe0004000L #define CSR_SDRAM_DFII_CONTROL_SIZE 1 static inline unsigned char sdram_dfii_control_read(void) { unsigned char r = csr_readl(0xe0004000L); return r; } static inline void sdram_dfii_control_write(unsigned char value) { csr_writel(value, 0xe0004000L); } #define CSR_SDRAM_DFII_PI0_COMMAND_ADDR 0xe0004004L #define CSR_SDRAM_DFII_PI0_COMMAND_SIZE 1 static inline unsigned char sdram_dfii_pi0_command_read(void) { unsigned char r = csr_readl(0xe0004004L); return r; } static inline void sdram_dfii_pi0_command_write(unsigned char value) { csr_writel(value, 0xe0004004L); } #define CSR_SDRAM_DFII_PI0_COMMAND_ISSUE_ADDR 0xe0004008L #define CSR_SDRAM_DFII_PI0_COMMAND_ISSUE_SIZE 1 static inline unsigned char sdram_dfii_pi0_command_issue_read(void) { unsigned char r = csr_readl(0xe0004008L); return r; } static inline void sdram_dfii_pi0_command_issue_write(unsigned char value) { csr_writel(value, 0xe0004008L); } #define CSR_SDRAM_DFII_PI0_ADDRESS_ADDR 0xe000400cL #define CSR_SDRAM_DFII_PI0_ADDRESS_SIZE 2 static inline unsigned short int sdram_dfii_pi0_address_read(void) { unsigned short int r = csr_readl(0xe000400cL); r <<= 8; r |= csr_readl(0xe0004010L); return r; } static inline void sdram_dfii_pi0_address_write(unsigned short int value) { csr_writel(value >> 8, 0xe000400cL); csr_writel(value, 0xe0004010L); } #define CSR_SDRAM_DFII_PI0_BADDRESS_ADDR 0xe0004014L #define CSR_SDRAM_DFII_PI0_BADDRESS_SIZE 1 static inline unsigned char sdram_dfii_pi0_baddress_read(void) { unsigned char r = csr_readl(0xe0004014L); return r; } static inline void sdram_dfii_pi0_baddress_write(unsigned char value) { csr_writel(value, 0xe0004014L); } #define CSR_SDRAM_DFII_PI0_WRDATA_ADDR 0xe0004018L #define CSR_SDRAM_DFII_PI0_WRDATA_SIZE 4 static inline unsigned int sdram_dfii_pi0_wrdata_read(void) { unsigned int r = csr_readl(0xe0004018L); r <<= 8; r |= csr_readl(0xe000401cL); r <<= 8; r |= csr_readl(0xe0004020L); r <<= 8; r |= csr_readl(0xe0004024L); return r; } static inline void sdram_dfii_pi0_wrdata_write(unsigned int value) { csr_writel(value >> 24, 0xe0004018L); csr_writel(value >> 16, 0xe000401cL); csr_writel(value >> 8, 0xe0004020L); csr_writel(value, 0xe0004024L); } #define CSR_SDRAM_DFII_PI0_RDDATA_ADDR 0xe0004028L #define CSR_SDRAM_DFII_PI0_RDDATA_SIZE 4 static inline unsigned int sdram_dfii_pi0_rddata_read(void) { unsigned int r = csr_readl(0xe0004028L); r <<= 8; r |= csr_readl(0xe000402cL); r <<= 8; r |= csr_readl(0xe0004030L); r <<= 8; r |= csr_readl(0xe0004034L); return r; } #define CSR_SDRAM_DFII_PI1_COMMAND_ADDR 0xe0004038L #define CSR_SDRAM_DFII_PI1_COMMAND_SIZE 1 static inline unsigned char sdram_dfii_pi1_command_read(void) { unsigned char r = csr_readl(0xe0004038L); return r; } static inline void sdram_dfii_pi1_command_write(unsigned char value) { csr_writel(value, 0xe0004038L); } #define CSR_SDRAM_DFII_PI1_COMMAND_ISSUE_ADDR 0xe000403cL #define CSR_SDRAM_DFII_PI1_COMMAND_ISSUE_SIZE 1 static inline unsigned char sdram_dfii_pi1_command_issue_read(void) { unsigned char r = csr_readl(0xe000403cL); return r; } static inline void sdram_dfii_pi1_command_issue_write(unsigned char value) { csr_writel(value, 0xe000403cL); } #define CSR_SDRAM_DFII_PI1_ADDRESS_ADDR 0xe0004040L #define CSR_SDRAM_DFII_PI1_ADDRESS_SIZE 2 static inline unsigned short int sdram_dfii_pi1_address_read(void) { unsigned short int r = csr_readl(0xe0004040L); r <<= 8; r |= csr_readl(0xe0004044L); return r; } static inline void sdram_dfii_pi1_address_write(unsigned short int value) { csr_writel(value >> 8, 0xe0004040L); csr_writel(value, 0xe0004044L); } #define CSR_SDRAM_DFII_PI1_BADDRESS_ADDR 0xe0004048L #define CSR_SDRAM_DFII_PI1_BADDRESS_SIZE 1 static inline unsigned char sdram_dfii_pi1_baddress_read(void) { unsigned char r = csr_readl(0xe0004048L); return r; } static inline void sdram_dfii_pi1_baddress_write(unsigned char value) { csr_writel(value, 0xe0004048L); } #define CSR_SDRAM_DFII_PI1_WRDATA_ADDR 0xe000404cL #define CSR_SDRAM_DFII_PI1_WRDATA_SIZE 4 static inline unsigned int sdram_dfii_pi1_wrdata_read(void) { unsigned int r = csr_readl(0xe000404cL); r <<= 8; r |= csr_readl(0xe0004050L); r <<= 8; r |= csr_readl(0xe0004054L); r <<= 8; r |= csr_readl(0xe0004058L); return r; } static inline void sdram_dfii_pi1_wrdata_write(unsigned int value) { csr_writel(value >> 24, 0xe000404cL); csr_writel(value >> 16, 0xe0004050L); csr_writel(value >> 8, 0xe0004054L); csr_writel(value, 0xe0004058L); } #define CSR_SDRAM_DFII_PI1_RDDATA_ADDR 0xe000405cL #define CSR_SDRAM_DFII_PI1_RDDATA_SIZE 4 static inline unsigned int sdram_dfii_pi1_rddata_read(void) { unsigned int r = csr_readl(0xe000405cL); r <<= 8; r |= csr_readl(0xe0004060L); r <<= 8; r |= csr_readl(0xe0004064L); r <<= 8; r |= csr_readl(0xe0004068L); return r; } #define CSR_SDRAM_DFII_PI2_COMMAND_ADDR 0xe000406cL #define CSR_SDRAM_DFII_PI2_COMMAND_SIZE 1 static inline unsigned char sdram_dfii_pi2_command_read(void) { unsigned char r = csr_readl(0xe000406cL); return r; } static inline void sdram_dfii_pi2_command_write(unsigned char value) { csr_writel(value, 0xe000406cL); } #define CSR_SDRAM_DFII_PI2_COMMAND_ISSUE_ADDR 0xe0004070L #define CSR_SDRAM_DFII_PI2_COMMAND_ISSUE_SIZE 1 static inline unsigned char sdram_dfii_pi2_command_issue_read(void) { unsigned char r = csr_readl(0xe0004070L); return r; } static inline void sdram_dfii_pi2_command_issue_write(unsigned char value) { csr_writel(value, 0xe0004070L); } #define CSR_SDRAM_DFII_PI2_ADDRESS_ADDR 0xe0004074L #define CSR_SDRAM_DFII_PI2_ADDRESS_SIZE 2 static inline unsigned short int sdram_dfii_pi2_address_read(void) { unsigned short int r = csr_readl(0xe0004074L); r <<= 8; r |= csr_readl(0xe0004078L); return r; } static inline void sdram_dfii_pi2_address_write(unsigned short int value) { csr_writel(value >> 8, 0xe0004074L); csr_writel(value, 0xe0004078L); } #define CSR_SDRAM_DFII_PI2_BADDRESS_ADDR 0xe000407cL #define CSR_SDRAM_DFII_PI2_BADDRESS_SIZE 1 static inline unsigned char sdram_dfii_pi2_baddress_read(void) { unsigned char r = csr_readl(0xe000407cL); return r; } static inline void sdram_dfii_pi2_baddress_write(unsigned char value) { csr_writel(value, 0xe000407cL); } #define CSR_SDRAM_DFII_PI2_WRDATA_ADDR 0xe0004080L #define CSR_SDRAM_DFII_PI2_WRDATA_SIZE 4 static inline unsigned int sdram_dfii_pi2_wrdata_read(void) { unsigned int r = csr_readl(0xe0004080L); r <<= 8; r |= csr_readl(0xe0004084L); r <<= 8; r |= csr_readl(0xe0004088L); r <<= 8; r |= csr_readl(0xe000408cL); return r; } static inline void sdram_dfii_pi2_wrdata_write(unsigned int value) { csr_writel(value >> 24, 0xe0004080L); csr_writel(value >> 16, 0xe0004084L); csr_writel(value >> 8, 0xe0004088L); csr_writel(value, 0xe000408cL); } #define CSR_SDRAM_DFII_PI2_RDDATA_ADDR 0xe0004090L #define CSR_SDRAM_DFII_PI2_RDDATA_SIZE 4 static inline unsigned int sdram_dfii_pi2_rddata_read(void) { unsigned int r = csr_readl(0xe0004090L); r <<= 8; r |= csr_readl(0xe0004094L); r <<= 8; r |= csr_readl(0xe0004098L); r <<= 8; r |= csr_readl(0xe000409cL); return r; } #define CSR_SDRAM_DFII_PI3_COMMAND_ADDR 0xe00040a0L #define CSR_SDRAM_DFII_PI3_COMMAND_SIZE 1 static inline unsigned char sdram_dfii_pi3_command_read(void) { unsigned char r = csr_readl(0xe00040a0L); return r; } static inline void sdram_dfii_pi3_command_write(unsigned char value) { csr_writel(value, 0xe00040a0L); } #define CSR_SDRAM_DFII_PI3_COMMAND_ISSUE_ADDR 0xe00040a4L #define CSR_SDRAM_DFII_PI3_COMMAND_ISSUE_SIZE 1 static inline unsigned char sdram_dfii_pi3_command_issue_read(void) { unsigned char r = csr_readl(0xe00040a4L); return r; } static inline void sdram_dfii_pi3_command_issue_write(unsigned char value) { csr_writel(value, 0xe00040a4L); } #define CSR_SDRAM_DFII_PI3_ADDRESS_ADDR 0xe00040a8L #define CSR_SDRAM_DFII_PI3_ADDRESS_SIZE 2 static inline unsigned short int sdram_dfii_pi3_address_read(void) { unsigned short int r = csr_readl(0xe00040a8L); r <<= 8; r |= csr_readl(0xe00040acL); return r; } static inline void sdram_dfii_pi3_address_write(unsigned short int value) { csr_writel(value >> 8, 0xe00040a8L); csr_writel(value, 0xe00040acL); } #define CSR_SDRAM_DFII_PI3_BADDRESS_ADDR 0xe00040b0L #define CSR_SDRAM_DFII_PI3_BADDRESS_SIZE 1 static inline unsigned char sdram_dfii_pi3_baddress_read(void) { unsigned char r = csr_readl(0xe00040b0L); return r; } static inline void sdram_dfii_pi3_baddress_write(unsigned char value) { csr_writel(value, 0xe00040b0L); } #define CSR_SDRAM_DFII_PI3_WRDATA_ADDR 0xe00040b4L #define CSR_SDRAM_DFII_PI3_WRDATA_SIZE 4 static inline unsigned int sdram_dfii_pi3_wrdata_read(void) { unsigned int r = csr_readl(0xe00040b4L); r <<= 8; r |= csr_readl(0xe00040b8L); r <<= 8; r |= csr_readl(0xe00040bcL); r <<= 8; r |= csr_readl(0xe00040c0L); return r; } static inline void sdram_dfii_pi3_wrdata_write(unsigned int value) { csr_writel(value >> 24, 0xe00040b4L); csr_writel(value >> 16, 0xe00040b8L); csr_writel(value >> 8, 0xe00040bcL); csr_writel(value, 0xe00040c0L); } #define CSR_SDRAM_DFII_PI3_RDDATA_ADDR 0xe00040c4L #define CSR_SDRAM_DFII_PI3_RDDATA_SIZE 4 static inline unsigned int sdram_dfii_pi3_rddata_read(void) { unsigned int r = csr_readl(0xe00040c4L); r <<= 8; r |= csr_readl(0xe00040c8L); r <<= 8; r |= csr_readl(0xe00040ccL); r <<= 8; r |= csr_readl(0xe00040d0L); return r; } #define CSR_SDRAM_CONTROLLER_BANDWIDTH_UPDATE_ADDR 0xe00040d4L #define CSR_SDRAM_CONTROLLER_BANDWIDTH_UPDATE_SIZE 1 static inline unsigned char sdram_controller_bandwidth_update_read(void) { unsigned char r = csr_readl(0xe00040d4L); return r; } static inline void sdram_controller_bandwidth_update_write(unsigned char value) { csr_writel(value, 0xe00040d4L); } #define CSR_SDRAM_CONTROLLER_BANDWIDTH_NREADS_ADDR 0xe00040d8L #define CSR_SDRAM_CONTROLLER_BANDWIDTH_NREADS_SIZE 3 static inline unsigned int sdram_controller_bandwidth_nreads_read(void) { unsigned int r = csr_readl(0xe00040d8L); r <<= 8; r |= csr_readl(0xe00040dcL); r <<= 8; r |= csr_readl(0xe00040e0L); return r; } #define CSR_SDRAM_CONTROLLER_BANDWIDTH_NWRITES_ADDR 0xe00040e4L #define CSR_SDRAM_CONTROLLER_BANDWIDTH_NWRITES_SIZE 3 static inline unsigned int sdram_controller_bandwidth_nwrites_read(void) { unsigned int r = csr_readl(0xe00040e4L); r <<= 8; r |= csr_readl(0xe00040e8L); r <<= 8; r |= csr_readl(0xe00040ecL); return r; } #define CSR_SDRAM_CONTROLLER_BANDWIDTH_DATA_WIDTH_ADDR 0xe00040f0L #define CSR_SDRAM_CONTROLLER_BANDWIDTH_DATA_WIDTH_SIZE 1 static inline unsigned char sdram_controller_bandwidth_data_width_read(void) { unsigned char r = csr_readl(0xe00040f0L); return r; } /* spiflash */ #define CSR_SPIFLASH_BASE 0xe0005000L #define CSR_SPIFLASH_BITBANG_ADDR 0xe0005000L #define CSR_SPIFLASH_BITBANG_SIZE 1 static inline unsigned char spiflash_bitbang_read(void) { unsigned char r = csr_readl(0xe0005000L); return r; } static inline void spiflash_bitbang_write(unsigned char value) { csr_writel(value, 0xe0005000L); } #define CSR_SPIFLASH_MISO_ADDR 0xe0005004L #define CSR_SPIFLASH_MISO_SIZE 1 static inline unsigned char spiflash_miso_read(void) { unsigned char r = csr_readl(0xe0005004L); return r; } #define CSR_SPIFLASH_BITBANG_EN_ADDR 0xe0005008L #define CSR_SPIFLASH_BITBANG_EN_SIZE 1 static inline unsigned char spiflash_bitbang_en_read(void) { unsigned char r = csr_readl(0xe0005008L); return r; } static inline void spiflash_bitbang_en_write(unsigned char value) { csr_writel(value, 0xe0005008L); } /* timer0 */ #define CSR_TIMER0_BASE 0xe0002800L #define CSR_TIMER0_LOAD_ADDR 0xe0002800L #define CSR_TIMER0_LOAD_SIZE 4 static inline unsigned int timer0_load_read(void) { unsigned int r = csr_readl(0xe0002800L); r <<= 8; r |= csr_readl(0xe0002804L); r <<= 8; r |= csr_readl(0xe0002808L); r <<= 8; r |= csr_readl(0xe000280cL); return r; } static inline void timer0_load_write(unsigned int value) { csr_writel(value >> 24, 0xe0002800L); csr_writel(value >> 16, 0xe0002804L); csr_writel(value >> 8, 0xe0002808L); csr_writel(value, 0xe000280cL); } #define CSR_TIMER0_RELOAD_ADDR 0xe0002810L #define CSR_TIMER0_RELOAD_SIZE 4 static inline unsigned int timer0_reload_read(void) { unsigned int r = csr_readl(0xe0002810L); r <<= 8; r |= csr_readl(0xe0002814L); r <<= 8; r |= csr_readl(0xe0002818L); r <<= 8; r |= csr_readl(0xe000281cL); return r; } static inline void timer0_reload_write(unsigned int value) { csr_writel(value >> 24, 0xe0002810L); csr_writel(value >> 16, 0xe0002814L); csr_writel(value >> 8, 0xe0002818L); csr_writel(value, 0xe000281cL); } #define CSR_TIMER0_EN_ADDR 0xe0002820L #define CSR_TIMER0_EN_SIZE 1 static inline unsigned char timer0_en_read(void) { unsigned char r = csr_readl(0xe0002820L); return r; } static inline void timer0_en_write(unsigned char value) { csr_writel(value, 0xe0002820L); } #define CSR_TIMER0_UPDATE_VALUE_ADDR 0xe0002824L #define CSR_TIMER0_UPDATE_VALUE_SIZE 1 static inline unsigned char timer0_update_value_read(void) { unsigned char r = csr_readl(0xe0002824L); return r; } static inline void timer0_update_value_write(unsigned char value) { csr_writel(value, 0xe0002824L); } #define CSR_TIMER0_VALUE_ADDR 0xe0002828L #define CSR_TIMER0_VALUE_SIZE 4 static inline unsigned int timer0_value_read(void) { unsigned int r = csr_readl(0xe0002828L); r <<= 8; r |= csr_readl(0xe000282cL); r <<= 8; r |= csr_readl(0xe0002830L); r <<= 8; r |= csr_readl(0xe0002834L); return r; } #define CSR_TIMER0_EV_STATUS_ADDR 0xe0002838L #define CSR_TIMER0_EV_STATUS_SIZE 1 static inline unsigned char timer0_ev_status_read(void) { unsigned char r = csr_readl(0xe0002838L); return r; } static inline void timer0_ev_status_write(unsigned char value) { csr_writel(value, 0xe0002838L); } #define CSR_TIMER0_EV_PENDING_ADDR 0xe000283cL #define CSR_TIMER0_EV_PENDING_SIZE 1 static inline unsigned char timer0_ev_pending_read(void) { unsigned char r = csr_readl(0xe000283cL); return r; } static inline void timer0_ev_pending_write(unsigned char value) { csr_writel(value, 0xe000283cL); } #define CSR_TIMER0_EV_ENABLE_ADDR 0xe0002840L #define CSR_TIMER0_EV_ENABLE_SIZE 1 static inline unsigned char timer0_ev_enable_read(void) { unsigned char r = csr_readl(0xe0002840L); return r; } static inline void timer0_ev_enable_write(unsigned char value) { csr_writel(value, 0xe0002840L); } /* uart */ #define CSR_UART_BASE 0xe0001800L #define CSR_UART_RXTX_ADDR 0xe0001800L #define CSR_UART_RXTX_SIZE 1 static inline unsigned char uart_rxtx_read(void) { unsigned char r = csr_readl(0xe0001800L); return r; } static inline void uart_rxtx_write(unsigned char value) { csr_writel(value, 0xe0001800L); } #define CSR_UART_TXFULL_ADDR 0xe0001804L #define CSR_UART_TXFULL_SIZE 1 static inline unsigned char uart_txfull_read(void) { unsigned char r = csr_readl(0xe0001804L); return r; } #define CSR_UART_RXEMPTY_ADDR 0xe0001808L #define CSR_UART_RXEMPTY_SIZE 1 static inline unsigned char uart_rxempty_read(void) { unsigned char r = csr_readl(0xe0001808L); return r; } #define CSR_UART_EV_STATUS_ADDR 0xe000180cL #define CSR_UART_EV_STATUS_SIZE 1 static inline unsigned char uart_ev_status_read(void) { unsigned char r = csr_readl(0xe000180cL); return r; } static inline void uart_ev_status_write(unsigned char value) { csr_writel(value, 0xe000180cL); } #define CSR_UART_EV_PENDING_ADDR 0xe0001810L #define CSR_UART_EV_PENDING_SIZE 1 static inline unsigned char uart_ev_pending_read(void) { unsigned char r = csr_readl(0xe0001810L); return r; } static inline void uart_ev_pending_write(unsigned char value) { csr_writel(value, 0xe0001810L); } #define CSR_UART_EV_ENABLE_ADDR 0xe0001814L #define CSR_UART_EV_ENABLE_SIZE 1 static inline unsigned char uart_ev_enable_read(void) { unsigned char r = csr_readl(0xe0001814L); return r; } static inline void uart_ev_enable_write(unsigned char value) { csr_writel(value, 0xe0001814L); } /* uart_phy */ #define CSR_UART_PHY_BASE 0xe0001000L #define CSR_UART_PHY_TUNING_WORD_ADDR 0xe0001000L #define CSR_UART_PHY_TUNING_WORD_SIZE 4 static inline unsigned int uart_phy_tuning_word_read(void) { unsigned int r = csr_readl(0xe0001000L); r <<= 8; r |= csr_readl(0xe0001004L); r <<= 8; r |= csr_readl(0xe0001008L); r <<= 8; r |= csr_readl(0xe000100cL); return r; } static inline void uart_phy_tuning_word_write(unsigned int value) { csr_writel(value >> 24, 0xe0001000L); csr_writel(value >> 16, 0xe0001004L); csr_writel(value >> 8, 0xe0001008L); csr_writel(value, 0xe000100cL); } /* identifier_mem */ #define CSR_IDENTIFIER_MEM_BASE 0xe0002000L /* constants */ #define ETHMAC_INTERRUPT 3 static inline int ethmac_interrupt_read(void) { return 3; } #define NMI_INTERRUPT 0 static inline int nmi_interrupt_read(void) { return 0; } #define TIMER0_INTERRUPT 2 static inline int timer0_interrupt_read(void) { return 2; } #define UART_INTERRUPT 1 static inline int uart_interrupt_read(void) { return 1; } #define CSR_DATA_WIDTH 8 static inline int csr_data_width_read(void) { return 8; } #define SYSTEM_CLOCK_FREQUENCY 100000000 static inline int system_clock_frequency_read(void) { return 100000000; } #define SPIFLASH_PAGE_SIZE 256 static inline int spiflash_page_size_read(void) { return 256; } #define SPIFLASH_SECTOR_SIZE 65536 static inline int spiflash_sector_size_read(void) { return 65536; } #define READ_LEVELING_BITSLIP 3 static inline int read_leveling_bitslip_read(void) { return 3; } #define READ_LEVELING_DELAY 14 static inline int read_leveling_delay_read(void) { return 14; } #define L2_SIZE 8192 static inline int l2_size_read(void) { return 8192; } #define LOCALIP1 192 static inline int localip1_read(void) { return 192; } #define LOCALIP2 168 static inline int localip2_read(void) { return 168; } #define LOCALIP3 100 static inline int localip3_read(void) { return 100; } #define LOCALIP4 50 static inline int localip4_read(void) { return 50; } #define REMOTEIP1 192 static inline int remoteip1_read(void) { return 192; } #define REMOTEIP2 168 static inline int remoteip2_read(void) { return 168; } #define REMOTEIP3 100 static inline int remoteip3_read(void) { return 100; } #define REMOTEIP4 100 static inline int remoteip4_read(void) { return 100; } #define CAS_LEDS_COUNT 4 static inline int cas_leds_count_read(void) { return 4; } #define CAS_SWITCHES_COUNT 4 static inline int cas_switches_count_read(void) { return 4; } #define CAS_BUTTONS_COUNT 4 static inline int cas_buttons_count_read(void) { return 4; } #define ETHMAC_RX_SLOTS 2 static inline int ethmac_rx_slots_read(void) { return 2; } #define ETHMAC_TX_SLOTS 2 static inline int ethmac_tx_slots_read(void) { return 2; } #define ETHMAC_SLOT_SIZE 2048 static inline int ethmac_slot_size_read(void) { return 2048; } #define CONFIG_CLOCK_FREQUENCY 100000000 static inline int config_clock_frequency_read(void) { return 100000000; } #define CONFIG_CPU_RESET_ADDR 0 static inline int config_cpu_reset_addr_read(void) { return 0; } #define CONFIG_CPU_TYPE "MOR1KX" static inline const char * config_cpu_type_read(void) { return "MOR1KX"; } #define CONFIG_CSR_DATA_WIDTH 8 static inline int config_csr_data_width_read(void) { return 8; } #endif
[ "github@rivera.za.net" ]
github@rivera.za.net
92628a575866f826d035dc0b8d63fd653804ed6b
20e81b5499fbc425d3653688e15a860714737432
/recipes-extended/lwip/lwip-echo/main.c
7280b3b2dbd5448e27b1fa17c160940e030e9ec8
[ "MIT" ]
permissive
tzanussi/meta-micro-galileo
49919a165c168f3e7d07f632e2dbc8e94c96e4cf
6fb8ac9ab3f2d852e8407ac7c0a1d1e5c53897f7
refs/heads/dizzy
2021-01-06T20:38:12.021964
2015-03-18T22:36:12
2015-03-19T20:57:41
26,054,395
0
1
null
2015-03-13T06:04:23
2014-11-01T15:31:53
Diff
UTF-8
C
false
false
5,919
c
/* * Copyright (c) 2001-2003 Swedish Institute of Computer Science. * 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. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. * * This file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels <adam@sics.se> * RT timer modifications by Christiaan Simons */ #include <unistd.h> #include <getopt.h> #include "lwip/init.h" #include "lwip/debug.h" #include "lwip/mem.h" #include "lwip/memp.h" #include "lwip/sys.h" #include "lwip/stats.h" #include "lwip/ip.h" #include "lwip/ip_frag.h" #include "lwip/udp.h" #include "lwip/tcp_impl.h" #include "packetif.h" #include "netif/etharp.h" #include "timer.h" #include <signal.h> #include "echo.h" /* (manual) host IP configuration */ static ip_addr_t ipaddr, netmask, gw; /* nonstatic debug cmd option, exported in lwipopts.h */ unsigned char debug_flags; static struct option longopts[] = { /* turn on debugging output (if build with LWIP_DEBUG) */ {"debug", no_argument, NULL, 'd'}, /* help */ {"help", no_argument, NULL, 'h'}, /* gateway address */ {"gateway", required_argument, NULL, 'g'}, /* ip address */ {"ipaddr", required_argument, NULL, 'i'}, /* netmask */ {"netmask", required_argument, NULL, 'm'}, /* ping destination */ {NULL, 0, NULL, 0} }; #define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1) void usage(void) { unsigned char i; printf("options:\n"); for (i = 0; i < NUM_OPTS; i++) { printf("-%c --%s\n",longopts[i].val, longopts[i].name); } } int main(int argc, char **argv) { struct netif netif; sigset_t mask, oldmask, empty; int ch; char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0}; char *eth_dev = "eth0"; /* startup defaults (may be overridden by one or more opts) */ IP4_ADDR(&gw, 192,168,1,0); IP4_ADDR(&ipaddr, 192,168,1,111); IP4_ADDR(&netmask, 255,255,255,0); /* use debug flags defined by debug.h */ debug_flags = LWIP_DBG_OFF; while ((ch = getopt_long(argc, argv, "dhg:i:m:e:", longopts, NULL)) != -1) { switch (ch) { case 'd': debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT); break; case 'h': usage(); exit(0); break; case 'g': ipaddr_aton(optarg, &gw); break; case 'i': ipaddr_aton(optarg, &ipaddr); break; case 'm': ipaddr_aton(optarg, &netmask); break; case 't': eth_dev = optarg; break; default: usage(); break; } } argc -= optind; argv += optind; strncpy(ip_str, ipaddr_ntoa(&ipaddr), sizeof(ip_str)); strncpy(nm_str, ipaddr_ntoa(&netmask), sizeof(nm_str)); strncpy(gw_str, ipaddr_ntoa(&gw), sizeof(gw_str)); printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str); #ifdef PERF perf_init("/tmp/minimal.perf"); #endif /* PERF */ dump_start("packetdump.txt"); lwip_init(); printf("TCP/IP initialized.\n"); netif_add(&netif, &ipaddr, &netmask, &gw, eth_dev, packetif_init, ethernet_input); netif_set_default(&netif); netif_set_up(&netif); #if LWIP_IPV6 netif_create_ip6_linklocal_address(&netif, 1); #endif echo_init(); timer_init(); timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10); timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10); #if IP_REASSEMBLY timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10); #endif printf("Applications started.\n"); while (1) { /* poll for input packet and ensure select() or read() arn't interrupted */ sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &oldmask); /* start of critical section, poll netif, pass packet to lwIP */ if (packetif_select(&netif) > 0) { /* work, immediatly end critical section hoping lwIP ended quickly ... */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } else { /* no work, wait a little (10 msec) for SIGALRM */ sigemptyset(&empty); sigsuspend(&empty); /* ... end critical section */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } if(timer_testclr_evt(TIMER_EVT_TCPTMR)) { tcp_tmr(); } #if IP_REASSEMBLY if(timer_testclr_evt(TIMER_EVT_IPREASSTMR)) { ip_reass_tmr(); } #endif if(timer_testclr_evt(TIMER_EVT_ETHARPTMR)) { etharp_tmr(); } } dump_stop(); return 0; }
[ "tom.zanussi@linux.intel.com" ]
tom.zanussi@linux.intel.com
f640832763fd3f05a53560db7005f952a6d41839
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/drivers/net/ethernet/netronome/nfp/bpf/extr_jit.c_nfp_bpf_optimize.c
d4495931bce53065b734f082a679353739a4c7d9
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,110
c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ struct nfp_prog {int dummy; } ; /* Variables and functions */ int /*<<< orphan*/ nfp_bpf_opt_ld_mask (struct nfp_prog*) ; int /*<<< orphan*/ nfp_bpf_opt_ld_shift (struct nfp_prog*) ; int /*<<< orphan*/ nfp_bpf_opt_ldst_gather (struct nfp_prog*) ; int /*<<< orphan*/ nfp_bpf_opt_neg_add_sub (struct nfp_prog*) ; int /*<<< orphan*/ nfp_bpf_opt_pkt_cache (struct nfp_prog*) ; int /*<<< orphan*/ nfp_bpf_opt_reg_init (struct nfp_prog*) ; __attribute__((used)) static int nfp_bpf_optimize(struct nfp_prog *nfp_prog) { nfp_bpf_opt_reg_init(nfp_prog); nfp_bpf_opt_neg_add_sub(nfp_prog); nfp_bpf_opt_ld_mask(nfp_prog); nfp_bpf_opt_ld_shift(nfp_prog); nfp_bpf_opt_ldst_gather(nfp_prog); nfp_bpf_opt_pkt_cache(nfp_prog); return 0; }
[ "brenocfg@gmail.com" ]
brenocfg@gmail.com
fdf2b25590aff8bbdbb73fcf5dcc384370607f48
d741d9d85b4f0197f7551c0867b6f92689990344
/optimization/mainBFit.c
66607a57199a278e95b13b9e244b132effe345fa
[]
no_license
Hjojo/numericProg
9d15eecfb5ce254ad33db243c62445a9cc70c3ab
2a358270b356c4da13e29236eeed13d47d4807e8
refs/heads/master
2021-01-18T22:53:02.907386
2017-06-29T21:21:46
2017-06-29T21:21:46
87,078,511
0
0
null
null
null
null
UTF-8
C
false
false
2,549
c
#include <stdio.h> #include <math.h> #include <gsl/gsl_vector.h> #include <gsl/gsl_matrix.h> #include <gsl/gsl_blas.h> int quasiNewton( double f(gsl_vector *x), void gradient(gsl_vector *x, gsl_vector *df), gsl_vector *xStart, double eps ); double function(double t, gsl_vector *params) { double A = gsl_vector_get(params,0); double T = gsl_vector_get(params,1); double B = gsl_vector_get(params,2); return A*exp(-t/T)+B; } double objective(gsl_vector *x) { double A = gsl_vector_get(x,0); double T = gsl_vector_get(x,1); double B = gsl_vector_get(x,2); double t[] = {0.23,1.29,2.35,3.41,4.47,5.53,6.59,7.65,8.71,9.77}; double y[] = {4.64,3.38,3.01,2.55,2.29,1.67,1.59,1.69,1.38,1.46}; double e[] = {0.42,0.37,0.34,0.31,0.29,0.27,0.26,0.25,0.24,0.24}; int n = sizeof(t)/sizeof(t[0]); double result = 0; for( int i = 0; i < n; i++) { result += pow( (A*exp(-t[i]/T)+B-y[i])/e[i] , 2 ); } return result; } void objectiveGradient(gsl_vector *x, gsl_vector* df) { double A = gsl_vector_get(x,0); double T = gsl_vector_get(x,1); double B = gsl_vector_get(x,2); double t[] = {0.23,1.29,2.35,3.41,4.47,5.53,6.59,7.65,8.71,9.77}; double y[] = {4.64,3.38,3.01,2.55,2.29,1.67,1.59,1.69,1.38,1.46}; double e[] = {0.42,0.37,0.34,0.31,0.29,0.27,0.26,0.25,0.24,0.24}; int n = sizeof(t)/sizeof(t[0]); double result1 = 0, result2 = 0, result3 = 0, temp; for( int i = 0; i < n; i++) { temp = 2*(A*exp(-t[i]/T)+B-y[i])/pow(e[i],2); result1 += exp(-t[i]/T)*temp; result2 += A*t[i]/pow(T,2)*exp(-t[i]/T)*temp; result3 += temp; } gsl_vector_set(df,0,result1); gsl_vector_set(df,1,result2); gsl_vector_set(df,2,result3); } int main(void) { int noParams = 3; gsl_vector *xStart = gsl_vector_alloc(noParams); gsl_vector_set(xStart,0,5); gsl_vector_set(xStart,1,10); gsl_vector_set(xStart,2,0.5); double eps = 1e-6; quasiNewton( &objective, &objectiveGradient, xStart, eps ); double t[] = {0.23,1.29,2.35,3.41,4.47,5.53,6.59,7.65,8.71,9.77}; double y[] = {4.64,3.38,3.01,2.55,2.29,1.67,1.59,1.69,1.38,1.46}; double e[] = {0.42,0.37,0.34,0.31,0.29,0.27,0.26,0.25,0.24,0.24}; int n = sizeof(t)/sizeof(t[0]); printf("# t \t y \t e\n"); for(int i = 0; i < n; i++) { printf("%g \t %g \t %g \n",t[i],y[i],e[i]); } printf("\n\n# t \t y \t with A = %.2g, T = %.2g, B = %.2g\n", gsl_vector_get(xStart,0), gsl_vector_get(xStart,1), gsl_vector_get(xStart,2)); for(double t = 0; t < 10; t += 0.01) { printf("%g \t %g\n",t,function(t,xStart)); } gsl_vector_free(xStart); return 0; }
[ "jonas1601@gmail.com" ]
jonas1601@gmail.com
993924edf7bbba7839e9ff0613ca50fec393d7c6
75fd1a30c15754b0642238001996ac7f7c28ec4b
/Embeded C/Generated_Source/PSoC5/M2_D1_aliases.h
ee8241eb5da48f742fc28d4ee19309b38f1d8516
[]
no_license
rdso323/COMPSYS-301
646c3764711938645ac99626d2870ab477241161
6f49ea4cd3775ebe768159ff0a64d8d61356be5e
refs/heads/master
2020-05-05T09:19:25.265954
2018-08-07T11:19:20
2018-08-07T11:19:20
179,899,429
1
0
null
null
null
null
UTF-8
C
false
false
1,270
h
/******************************************************************************* * File Name: M2_D1.h * Version 2.20 * * Description: * This file contains the Alias definitions for Per-Pin APIs in cypins.h. * Information on using these APIs can be found in the System Reference Guide. * * Note: * ******************************************************************************** * Copyright 2008-2015, Cypress Semiconductor Corporation. All rights reserved. * You may use this file only in accordance with the license, terms, conditions, * disclaimers, and limitations in the end user license agreement accompanying * the software package with which this file was provided. *******************************************************************************/ #if !defined(CY_PINS_M2_D1_ALIASES_H) /* Pins M2_D1_ALIASES_H */ #define CY_PINS_M2_D1_ALIASES_H #include "cytypes.h" #include "cyfitter.h" /*************************************** * Constants ***************************************/ #define M2_D1_0 (M2_D1__0__PC) #define M2_D1_0_INTR ((uint16)((uint16)0x0001u << M2_D1__0__SHIFT)) #define M2_D1_INTR_ALL ((uint16)(M2_D1_0_INTR)) #endif /* End Pins M2_D1_ALIASES_H */ /* [] END OF FILE */
[ "prashamjhaveri@Prashams-MacBook-Air.local" ]
prashamjhaveri@Prashams-MacBook-Air.local
c8e1f0678ce6702358bc4cabeaeb4030e27ee78a
712e2c48c07f3343cd307b9ee06b1e5f4aab3f1b
/infod/InfoModules/JMigratePIM.h
83446b14847afc621c718f6cb633506ce484e494
[ "BSD-3-Clause" ]
permissive
liororama/gossimon
02f1b3284f450457f878628ca41334a61f285ea3
5d0d266677153c7d0f330438c8ee4942a98ae4e4
refs/heads/master
2020-05-20T06:49:29.390899
2014-01-02T06:15:12
2014-01-02T06:15:12
2,347,339
3
2
null
null
null
null
UTF-8
C
false
false
1,314
h
/*============================================================================ gossimon - Gossip based resource usage monitoring for Linux clusters Copyright 2003-2010 Amnon Barak Distributed under the OSI-approved BSD License (the "License"); see accompanying file Copyright.txt for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more information. ============================================================================*/ /****************************************************************************** * * Author(s): Amar Lior * *****************************************************************************/ #ifndef __JMIGRATE_INFO_PIM #define __JMIGRATE_INFO_PIM #include <infoModuleManager.h> // If file mtime is more than 30 seconds the jmigrate is considered as dead #define JMIG_FILE_MAX_AGE (30) int jmig_pim_init(void **module_data, void *init_data); int jmig_pim_free(void **module_data); int jmig_pim_update(void *module_data); int jmig_pim_get(void *module_data, void *data, int *size); int jmig_pim_desc(void *module_data, char *desc); // A function to register the whole module int jmig_pim_register(pim_entry_t *pim_arr, int maxSize); #endif
[ "liororama@gmail.com" ]
liororama@gmail.com
739da875cb8b5a7ce9873093e115cdaa31826954
fabd37b88c41fe465f533c1e11e6f7f8cbb85754
/recipes-hello/hello/files/hello.c
a84cc25735b0871ca2a383bd55de5e41f872ea87
[ "MIT" ]
permissive
JohnyDev42/yocto
aa06499ecc6bb2e796caa95a803c65e76ef750a3
e279b1fec567a9afb00ce42afac49847286cf192
refs/heads/master
2023-09-04T21:30:22.076141
2021-11-21T14:21:47
2021-11-21T14:21:47
425,897,276
0
0
null
null
null
null
UTF-8
C
false
false
70
c
#include<stdio.h> int main(){ printf("Hello Yocto!\n"); return 0; }
[ "arunsahu44@gmail.com" ]
arunsahu44@gmail.com
6463d75199bc99e97d1a421a1e2fc6b110361719
e803a924d59d7a13774f3615f5ec7d6de5df9dd5
/dwm.c
40074987847ffdb8fd255e6182df81811341e03c
[ "MIT" ]
permissive
guosongjun/modwm
4cdb3b6b0fece80e522bf47547b66ed967af8b43
749ddfbd0b5c1babbc82b6615607186799a0eda8
refs/heads/master
2023-03-23T02:52:00.435180
2021-03-23T05:53:22
2021-03-23T05:53:22
null
0
0
null
null
null
null
UTF-8
C
false
false
116,968
c
/* ___ ______________ _ ____ ___ * | \/ | _ | _ | | | | \/ | * | . . | | | | | | | | | | . . | * | |\/| | | | | | | | |/\| | |\/| | * | | | \ \_/ | |/ /\ /\ | | | | * \_| |_/\___/|___/ \/ \/\_| |_/ * * MODWM - Modular Dynamic Window Manager. * --------------------------------------- * See LICENSE file for copyright and license details. */ /* dynamic window manager is designed like any other X client as well. It is * driven through handling X events. In contrast to other X clients, a window * manager selects SubstructureRedirectMask on the root window, to receive * events about window (dis-)appearance. Only one X connection at a time is * allowed to select for this event mask. * * The event handlers of dwm are organized in an array which is accessed * whenever a new event has been fetched. This allows event dispatching * in O(1) time. * * Each child of the root window is called a client, except windows which have * set the override_redirect flag. Clients are organized in a linked client * list on each monitor, the focus history is remembered through a stack list * on each monitor. Each client contains a bit array to indicate the tags of a * client. * * Keys and tagging rules are organized as arrays and defined in config.h. * * To understand everything else, start reading main(). */ #include <errno.h> #include <locale.h> #include <signal.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <X11/cursorfont.h> #include <X11/keysym.h> #include <X11/Xatom.h> #include <X11/Xlib.h> #include <X11/Xproto.h> #include <X11/Xutil.h> #ifdef XINERAMA #include <X11/extensions/Xinerama.h> #endif /* XINERAMA */ #include <X11/Xft/Xft.h> #include "patches.h" #include "drw.h" #include "util.h" #if BAR_FLEXWINTITLE_PATCH #ifndef FLEXTILE_DELUXE_LAYOUT #define FLEXTILE_DELUXE_LAYOUT 1 #endif #endif #if BAR_PANGO_PATCH #include <pango/pango.h> #endif // BAR_PANGO_PATCH #if SPAWNCMD_PATCH #include <assert.h> #include <libgen.h> #include <sys/stat.h> #define SPAWN_CWD_DELIM " []{}()<>\"':" #endif // SPAWNCMD_PATCH /* macros */ #define Button6 6 #define Button7 7 #define Button8 8 #define Button9 9 #define NUMTAGS 9 #define BARRULES 20 #define BUTTONMASK (ButtonPressMask|ButtonReleaseMask) #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) #if ATTACHASIDE_PATCH && STICKY_PATCH #define ISVISIBLEONTAG(C, T) ((C->tags & T) || C->issticky) #define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags]) #elif ATTACHASIDE_PATCH #define ISVISIBLEONTAG(C, T) ((C->tags & T)) #define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags]) #elif STICKY_PATCH #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky) #else #define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) #endif // ATTACHASIDE_PATCH #define LENGTH(X) (sizeof X / sizeof X[0]) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X) ((X)->w + 2 * (X)->bw) #define HEIGHT(X) ((X)->h + 2 * (X)->bw) #define WTYPE "_NET_WM_WINDOW_TYPE_" #if SCRATCHPADS_PATCH #define TOTALTAGS (NUMTAGS + LENGTH(scratchpads)) #define TAGMASK ((1 << TOTALTAGS) - 1) #define SPTAG(i) ((1 << NUMTAGS) << (i)) #define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << NUMTAGS) #else #define TAGMASK ((1 << NUMTAGS) - 1) #endif // SCRATCHPADS_PATCH #define TEXTWM(X) (drw_fontset_getwidth(drw, (X), True) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X), False) + lrpad) #define HIDDEN(C) ((getstate(C->win) == IconicState)) /* enums */ enum { #if RESIZEPOINT_PATCH || RESIZECORNERS_PATCH CurResizeBR, CurResizeBL, CurResizeTR, CurResizeTL, #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH #if DRAGMFACT_PATCH CurResizeHorzArrow, CurResizeVertArrow, #endif // DRAGMFACT_PATCH #if DRAGCFACT_PATCH CurIronCross, #endif // DRAGCFACT_PATCH CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel, SchemeTitleNorm, SchemeTitleSel, SchemeTagsNorm, SchemeTagsSel, SchemeHid, SchemeUrg, #if BAR_FLEXWINTITLE_PATCH SchemeFlexActTTB, SchemeFlexActLTR, SchemeFlexActMONO, SchemeFlexActGRID, SchemeFlexActGRD1, SchemeFlexActGRD2, SchemeFlexActGRDM, SchemeFlexActHGRD, SchemeFlexActDWDL, SchemeFlexActSPRL, SchemeFlexInaTTB, SchemeFlexInaLTR, SchemeFlexInaMONO, SchemeFlexInaGRID, SchemeFlexInaGRD1, SchemeFlexInaGRD2, SchemeFlexInaGRDM, SchemeFlexInaHGRD, SchemeFlexInaDWDL, SchemeFlexInaSPRL, SchemeFlexSelTTB, SchemeFlexSelLTR, SchemeFlexSelMONO, SchemeFlexSelGRID, SchemeFlexSelGRD1, SchemeFlexSelGRD2, SchemeFlexSelGRDM, SchemeFlexSelHGRD, SchemeFlexSelDWDL, SchemeFlexSelSPRL, SchemeFlexActFloat, SchemeFlexInaFloat, SchemeFlexSelFloat, #endif // BAR_FLEXWINTITLE_PATCH }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, #if BAR_SYSTRAY_PATCH NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayVisual, NetWMWindowTypeDock, NetSystemTrayOrientationHorz, #endif // BAR_SYSTRAY_PATCH #if BAR_EWMHTAGS_PATCH NetDesktopNames, NetDesktopViewport, NetNumberOfDesktops, NetCurrentDesktop, #endif // BAR_EWMHTAGS_PATCH NetClientList, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, #if WINDOWROLERULE_PATCH WMWindowRole, #endif // WINDOWROLERULE_PATCH WMLast }; /* default atoms */ enum { #if BAR_STATUSBUTTON_PATCH ClkButton, #endif // BAR_STATUSBUTTON_PATCH ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ enum { BAR_ALIGN_LEFT, BAR_ALIGN_CENTER, BAR_ALIGN_RIGHT, BAR_ALIGN_LEFT_LEFT, BAR_ALIGN_LEFT_RIGHT, BAR_ALIGN_LEFT_CENTER, BAR_ALIGN_NONE, BAR_ALIGN_RIGHT_LEFT, BAR_ALIGN_RIGHT_RIGHT, BAR_ALIGN_RIGHT_CENTER, BAR_ALIGN_LAST }; /* bar alignment */ #if IPC_PATCH typedef struct TagState TagState; struct TagState { int selected; int occupied; int urgent; }; typedef struct ClientState ClientState; struct ClientState { int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; }; #endif // IPC_PATCH typedef union { #if IPC_PATCH long i; unsigned long ui; #else int i; unsigned int ui; #endif // IPC_PATCH float f; const void *v; } Arg; typedef struct Monitor Monitor; typedef struct Bar Bar; struct Bar { Window win; Monitor *mon; Bar *next; int idx; int showbar; int topbar; int borderpx; int borderscheme; int bx, by, bw, bh; /* bar geometry */ int w[BARRULES]; // width, array length == barrules, then use r index for lookup purposes int x[BARRULES]; // x position, array length == ^ }; typedef struct { int x; int y; int h; int w; } BarArg; typedef struct { int monitor; int bar; int alignment; // see bar alignment enum int (*widthfunc)(Bar *bar, BarArg *a); int (*drawfunc)(Bar *bar, BarArg *a); int (*clickfunc)(Bar *bar, Arg *arg, BarArg *a); char *name; // for debugging int x, w; // position, width for internal use } BarRule; typedef struct { unsigned int click; unsigned int mask; unsigned int button; void (*func)(const Arg *arg); const Arg arg; } Button; typedef struct Client Client; struct Client { char name[256]; float mina, maxa; #if CFACTS_PATCH float cfact; #endif // CFACTS_PATCH int x, y, w, h; #if SAVEFLOATS_PATCH || EXRESIZE_PATCH int sfx, sfy, sfw, sfh; /* stored float geometry, used on mode revert */ #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH int oldx, oldy, oldw, oldh; int basew, baseh, incw, inch, maxw, maxh, minw, minh; int bw, oldbw; unsigned int tags; #if SWITCHTAG_PATCH unsigned int switchtag; #endif // SWITCHTAG_PATCH int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; #if !FAKEFULLSCREEN_PATCH && FAKEFULLSCREEN_CLIENT_PATCH int fakefullscreen; #endif // FAKEFULLSCREEN_CLIENT_PATCH #if EXRESIZE_PATCH unsigned char expandmask; int expandx1, expandy1, expandx2, expandy2; #if !MAXIMIZE_PATCH int wasfloating; #endif // MAXIMIZE_PATCH #endif // EXRESIZE_PATCH #if MAXIMIZE_PATCH int ismax, wasfloating; #endif // MAXIMIZE_PATCH #if AUTORESIZE_PATCH int needresize; #endif // AUTORESIZE_PATCH #if CENTER_PATCH int iscentered; #endif // CENTER_PATCH #if ISPERMANENT_PATCH int ispermanent; #endif // ISPERMANENT_PATCH #if SWALLOW_PATCH int isterminal, noswallow; pid_t pid; #endif // SWALLOW_PATCH #if STEAM_PATCH int issteam; #endif // STEAM_PATCH #if STICKY_PATCH int issticky; #endif // STICKY_PATCH Client *next; Client *snext; #if SWALLOW_PATCH Client *swallowing; #endif // SWALLOW_PATCH Monitor *mon; Window win; #if IPC_PATCH ClientState prevstate; #endif // IPC_PATCH }; typedef struct { unsigned int mod; KeySym keysym; void (*func)(const Arg *); const Arg arg; } Key; #if FLEXTILE_DELUXE_LAYOUT typedef struct { int nmaster; int nstack; int layout; int masteraxis; // master stack area int stack1axis; // primary stack area int stack2axis; // secondary stack area, e.g. centered master void (*symbolfunc)(Monitor *, unsigned int); } LayoutPreset; #endif // FLEXTILE_DELUXE_LAYOUT typedef struct { const char *symbol; void (*arrange)(Monitor *); #if FLEXTILE_DELUXE_LAYOUT LayoutPreset preset; #endif // FLEXTILE_DELUXE_LAYOUT } Layout; #if INSETS_PATCH typedef struct { int x; int y; int w; int h; } Inset; #endif // INSETS_PATCH #if PERTAG_PATCH typedef struct Pertag Pertag; #endif // PERTAG_PATCH struct Monitor { int index; char ltsymbol[16]; float mfact; #if FLEXTILE_DELUXE_LAYOUT int ltaxis[4]; int nstack; #endif // FLEXTILE_DELUXE_LAYOUT int nmaster; int num; int mx, my, mw, mh; /* screen size */ int wx, wy, ww, wh; /* window area */ #if VANITYGAPS_PATCH int gappih; /* horizontal gap between windows */ int gappiv; /* vertical gap between windows */ int gappoh; /* horizontal outer gaps */ int gappov; /* vertical outer gaps */ #endif // VANITYGAPS_PATCH #if SETBORDERPX_PATCH unsigned int borderpx; #endif // SETBORDERPX_PATCH unsigned int seltags; unsigned int sellt; unsigned int tagset[2]; int showbar; Client *clients; Client *sel; Client *stack; Monitor *next; Bar *bar; const Layout *lt[2]; #if BAR_ALTERNATIVE_TAGS_PATCH unsigned int alttag; #endif // BAR_ALTERNATIVE_TAGS_PATCH #if PERTAG_PATCH Pertag *pertag; #endif // PERTAG_PATCH #if INSETS_PATCH Inset inset; #endif // INSETS_PATCH #if IPC_PATCH char lastltsymbol[16]; TagState tagstate; Client *lastsel; const Layout *lastlt; #endif // IPC_PATCH }; typedef struct { const char *class; #if WINDOWROLERULE_PATCH const char *role; #endif // WINDOWROLERULE_PATCH const char *instance; const char *title; const char *wintype; unsigned int tags; #if SWITCHTAG_PATCH int switchtag; #endif // SWITCHTAG_PATCH #if CENTER_PATCH int iscentered; #endif // CENTER_PATCH int isfloating; #if ISPERMANENT_PATCH int ispermanent; #endif // ISPERMANENT_PATCH #if SWALLOW_PATCH int isterminal; int noswallow; #endif // SWALLOW_PATCH #if FLOATPOS_PATCH const char *floatpos; #endif // FLOATPOS_PATCH int monitor; } Rule; #define RULE(...) { .monitor = -1, ##__VA_ARGS__ }, /* Cross patch compatibility rule macro helper macros */ #define FLOATING , .isfloating = 1 #if CENTER_PATCH #define CENTERED , .iscentered = 1 #else #define CENTERED #endif // CENTER_PATCH #if ISPERMANENT_PATCH #define PERMANENT , .ispermanent = 1 #else #define PERMANENT #endif // ISPERMANENT_PATCH #if SWALLOW_PATCH #define NOSWALLOW , .noswallow = 1 #define TERMINAL , .isterminal = 1 #else #define NOSWALLOW #define TERMINAL #endif // SWALLOW_PATCH #if SWITCHTAG_PATCH #define SWITCHTAG , .switchtag = 1 #else #define SWITCHTAG #endif // SWITCHTAG_PATCH #if MONITOR_RULES_PATCH typedef struct { int monitor; #if PERTAG_PATCH int tag; #endif // PERTAG_PATCH int layout; float mfact; int nmaster; int showbar; int topbar; } MonitorRule; #endif // MONITOR_RULES_PATCH /* function declarations */ static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); static void attachstack(Client *c); static void buttonpress(XEvent *e); static void checkotherwm(void); static void cleanup(void); static void cleanupmon(Monitor *mon); static void clientmessage(XEvent *e); static void configure(Client *c); static void configurenotify(XEvent *e); static void configurerequest(XEvent *e); static Monitor *createmon(void); static void destroynotify(XEvent *e); static void detach(Client *c); static void detachstack(Client *c); static Monitor *dirtomon(int dir); static void drawbar(Monitor *m); static void drawbars(void); static void drawbarwin(Bar *bar); #if !FOCUSONCLICK_PATCH static void enternotify(XEvent *e); #endif // FOCUSONCLICK_PATCH static void expose(XEvent *e); static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); #if !STACKER_PATCH static void focusstack(const Arg *arg); #endif // STACKER_PATCH static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); static void grabbuttons(Client *c, int focused); #if KEYMODES_PATCH static void grabdefkeys(void); #else static void grabkeys(void); #endif // KEYMODES_PATCH static void incnmaster(const Arg *arg); #if KEYMODES_PATCH static void keydefpress(XEvent *e); #else static void keypress(XEvent *e); #endif // KEYMODES_PATCH static void killclient(const Arg *arg); static void layoutmenu(const Arg *arg); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); static void maprequest(XEvent *e); #if !FOCUSONCLICK_PATCH static void motionnotify(XEvent *e); #endif // FOCUSONCLICK_PATCH static void movemouse(const Arg *arg); static Client *nexttiled(Client *c); #if !ZOOMSWAP_PATCH || TAGINTOSTACK_ALLMASTER_PATCH || TAGINTOSTACK_ONEMASTER_PATCH static void pop(Client *); #endif // !ZOOMSWAP_PATCH / TAGINTOSTACK_ALLMASTER_PATCH / TAGINTOSTACK_ONEMASTER_PATCH static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void restack(Monitor *m); static void run(void); static void scan(void); #if BAR_SYSTRAY_PATCH static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4); #else static int sendevent(Client *c, Atom proto); #endif // BAR_SYSTRAY_PATCH static void sendmon(Client *c, Monitor *m); static void setclientstate(Client *c, long state); static void setfocus(Client *c); static void setfullscreen(Client *c, int fullscreen); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void sigchld(int unused); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus, Client *nextfocus); static void unmanage(Client *c, int destroyed); static void unmapnotify(XEvent *e); static void updatebarpos(Monitor *m); static void updatebars(void); static void updateclientlist(void); static int updategeom(void); static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatestatus(void); static void updatetitle(Client *c); static void updatewmhints(Client *c); static void view(const Arg *arg); static Client *wintoclient(Window w); static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); /* bar functions */ #include "patch/include.h" /* variables */ static const char broken[] = "broken"; #if BAR_PANGO_PATCH || BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH static char stext[1024]; #else static char stext[512]; #endif // BAR_PANGO_PATCH | BAR_STATUS2D_PATCH #if BAR_EXTRASTATUS_PATCH || BAR_STATUSCMD_PATCH #if BAR_STATUS2D_PATCH static char rawstext[1024]; #else static char rawstext[512]; #endif // BAR_STATUS2D_PATCH #endif // BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH #if BAR_EXTRASTATUS_PATCH #if BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH static char estext[1024]; #else static char estext[512]; #endif // BAR_STATUS2D_PATCH #if BAR_STATUSCMD_PATCH static char rawestext[1024]; #endif // BAR_STATUS2D_PATCH | BAR_STATUSCMD_PATCH #endif // BAR_EXTRASTATUS_PATCH static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh; /* bar geometry */ static int lrpad; /* sum of left and right padding for text */ static int (*xerrorxlib)(Display *, XErrorEvent *); static unsigned int numlockmask = 0; static void (*handler[LASTEvent]) (XEvent *) = { [ButtonPress] = buttonpress, #if COMBO_PATCH || BAR_HOLDBAR_PATCH [ButtonRelease] = keyrelease, #endif // COMBO_PATCH / BAR_HOLDBAR_PATCH [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, [ConfigureNotify] = configurenotify, [DestroyNotify] = destroynotify, #if !FOCUSONCLICK_PATCH [EnterNotify] = enternotify, #endif // FOCUSONCLICK_PATCH [Expose] = expose, [FocusIn] = focusin, [KeyPress] = keypress, #if COMBO_PATCH || BAR_HOLDBAR_PATCH [KeyRelease] = keyrelease, #endif // COMBO_PATCH / BAR_HOLDBAR_PATCH [MappingNotify] = mappingnotify, [MapRequest] = maprequest, #if !FOCUSONCLICK_PATCH [MotionNotify] = motionnotify, #endif // FOCUSONCLICK_PATCH [PropertyNotify] = propertynotify, #if BAR_SYSTRAY_PATCH [ResizeRequest] = resizerequest, #endif // BAR_SYSTRAY_PATCH [UnmapNotify] = unmapnotify }; #if BAR_SYSTRAY_PATCH static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast]; #else static Atom wmatom[WMLast], netatom[NetLast]; #endif // BAR_SYSTRAY_PATCH static int running = 1; static Cur *cursor[CurLast]; static Clr **scheme; static Display *dpy; static Drw *drw; static Monitor *mons, *selmon; static Window root, wmcheckwin; /* configuration, allows nested code to access above variables */ #include "config.h" #include "patch/include.c" /* compile-time check if all tags fit into an unsigned int bit array. */ #if SCRATCHPAD_ALT_1_PATCH struct NumTags { char limitexceeded[NUMTAGS > 30 ? -1 : 1]; }; #else struct NumTags { char limitexceeded[NUMTAGS > 31 ? -1 : 1]; }; #endif // SCRATCHPAD_ALT_1_PATCH /* function implementations */ void applyrules(Client *c) { const char *class, *instance; Atom wintype; #if WINDOWROLERULE_PATCH char role[64]; #endif // WINDOWROLERULE_PATCH unsigned int i; #if SWITCHTAG_PATCH unsigned int newtagset; #endif // SWITCHTAG_PATCH const Rule *r; Monitor *m; XClassHint ch = { NULL, NULL }; /* rule matching */ c->isfloating = 0; c->tags = 0; XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; wintype = getatomprop(c, netatom[NetWMWindowType]); #if WINDOWROLERULE_PATCH gettextprop(c->win, wmatom[WMWindowRole], role, sizeof(role)); #endif // WINDOWROLERULE_PATCH #if STEAM_PATCH if (strstr(class, "Steam") || strstr(class, "steam_app_")) c->issteam = 1; #endif // STEAM_PATCH for (i = 0; i < LENGTH(rules); i++) { r = &rules[i]; if ((!r->title || strstr(c->name, r->title)) && (!r->class || strstr(class, r->class)) #if WINDOWROLERULE_PATCH && (!r->role || strstr(role, r->role)) #endif // WINDOWROLERULE_PATCH && (!r->instance || strstr(instance, r->instance)) && (!r->wintype || wintype == XInternAtom(dpy, r->wintype, False))) { #if CENTER_PATCH c->iscentered = r->iscentered; #endif // CENTER_PATCH #if ISPERMANENT_PATCH c->ispermanent = r->ispermanent; #endif // ISPERMANENT_PATCH #if SWALLOW_PATCH c->isterminal = r->isterminal; c->noswallow = r->noswallow; #endif // SWALLOW_PATCH c->isfloating = r->isfloating; c->tags |= r->tags; #if SCRATCHPADS_PATCH if ((r->tags & SPTAGMASK) && r->isfloating) { c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); } #endif // SCRATCHPADS_PATCH for (m = mons; m && m->num != r->monitor; m = m->next); if (m) c->mon = m; #if FLOATPOS_PATCH if (c->isfloating && r->floatpos) setfloatpos(c, r->floatpos); #endif // FLOATPOS_PATCH #if SWITCHTAG_PATCH #if SWALLOW_PATCH if (r->switchtag && (c->noswallow || !termforwin(c))) #else if (r->switchtag) #endif // SWALLOW_PATCH { selmon = c->mon; if (r->switchtag == 2 || r->switchtag == 4) newtagset = c->mon->tagset[c->mon->seltags] ^ c->tags; else newtagset = c->tags; /* Switch to the client's tag, but only if that tag is not already shown */ if (newtagset && !(c->tags & c->mon->tagset[c->mon->seltags])) { if (r->switchtag == 3 || r->switchtag == 4) c->switchtag = c->mon->tagset[c->mon->seltags]; if (r->switchtag == 1 || r->switchtag == 3) { #if PERTAG_PATCH pertagview(&((Arg) { .ui = newtagset })); arrange(c->mon); #else view(&((Arg) { .ui = newtagset })); #endif // PERTAG_PATCH } else { c->mon->tagset[c->mon->seltags] = newtagset; arrange(c->mon); } } } #endif // SWITCHTAG_PATCH } } if (ch.res_class) XFree(ch.res_class); if (ch.res_name) XFree(ch.res_name); #if EMPTYVIEW_PATCH if (c->tags & TAGMASK) c->tags = c->tags & TAGMASK; #if SCRATCHPADS_PATCH else if (c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags] & ~SPTAGMASK; #elif SCRATCHPAD_ALT_1_PATCH else if (c->tags != SCRATCHPAD_MASK && c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags]; #else else if (c->mon->tagset[c->mon->seltags]) c->tags = c->mon->tagset[c->mon->seltags]; #endif // SCRATCHPADS_PATCH else c->tags = 1; #elif SCRATCHPADS_PATCH c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : (c->mon->tagset[c->mon->seltags] & ~SPTAGMASK); #elif SCRATCHPAD_ALT_1_PATCH if (c->tags != SCRATCHPAD_MASK) c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; #else c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; #endif // EMPTYVIEW_PATCH } int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) { int baseismin; Monitor *m = c->mon; /* set minimum possible */ *w = MAX(1, *w); *h = MAX(1, *h); if (interact) { if (*x > sw) *x = sw - WIDTH(c); if (*y > sh) *y = sh - HEIGHT(c); if (*x + *w + 2 * c->bw < 0) *x = 0; if (*y + *h + 2 * c->bw < 0) *y = 0; } else { if (*x >= m->wx + m->ww) *x = m->wx + m->ww - WIDTH(c); if (*y >= m->wy + m->wh) *y = m->wy + m->wh - HEIGHT(c); if (*x + *w + 2 * c->bw <= m->wx) *x = m->wx; if (*y + *h + 2 * c->bw <= m->wy) *y = m->wy; } if (*h < bh) *h = bh; if (*w < bh) *w = bh; if (resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) { /* see last two sentences in ICCCM 4.1.2.3 */ baseismin = c->basew == c->minw && c->baseh == c->minh; if (!baseismin) { /* temporarily remove base dimensions */ *w -= c->basew; *h -= c->baseh; } /* adjust for aspect limits */ if (c->mina > 0 && c->maxa > 0) { if (c->maxa < (float)*w / *h) *w = *h * c->maxa + 0.5; else if (c->mina < (float)*h / *w) *h = *w * c->mina + 0.5; } if (baseismin) { /* increment calculation requires this */ *w -= c->basew; *h -= c->baseh; } /* adjust for increment value */ if (c->incw) *w -= *w % c->incw; if (c->inch) *h -= *h % c->inch; /* restore base dimensions */ *w = MAX(*w + c->basew, c->minw); *h = MAX(*h + c->baseh, c->minh); if (c->maxw) *w = MIN(*w, c->maxw); if (c->maxh) *h = MIN(*h, c->maxh); } return *x != c->x || *y != c->y || *w != c->w || *h != c->h; } void arrange(Monitor *m) { if (m) showhide(m->stack); else for (m = mons; m; m = m->next) showhide(m->stack); if (m) { arrangemon(m); restack(m); } else for (m = mons; m; m = m->next) arrangemon(m); } void arrangemon(Monitor *m) { strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); #if ROUNDED_CORNERS_PATCH Client *c; for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) drawroundedcorners(c); #endif // ROUNDED_CORNERS_PATCH } void attach(Client *c) { c->next = c->mon->clients; c->mon->clients = c; } void attachstack(Client *c) { c->snext = c->mon->stack; c->mon->stack = c; } void buttonpress(XEvent *e) { int click, i, r; Arg arg = {0}; Client *c; Monitor *m; Bar *bar; XButtonPressedEvent *ev = &e->xbutton; const BarRule *br; BarArg carg = { 0, 0, 0, 0 }; click = ClkRootWin; /* focus monitor if necessary */ if ((m = wintomon(ev->window)) && m != selmon #if FOCUSONCLICK_PATCH && (focusonwheel || (ev->button != Button4 && ev->button != Button5)) #endif // FOCUSONCLICK_PATCH ) { unfocus(selmon->sel, 1, NULL); selmon = m; focus(NULL); } for (bar = selmon->bar; bar; bar = bar->next) { if (ev->window == bar->win) { for (r = 0; r < LENGTH(barrules); r++) { br = &barrules[r]; if (br->bar != bar->idx || (br->monitor == 'A' && m != selmon) || br->clickfunc == NULL) continue; if (br->monitor != 'A' && br->monitor != -1 && br->monitor != bar->mon->index) continue; if (bar->x[r] <= ev->x && ev->x <= bar->x[r] + bar->w[r]) { carg.x = ev->x - bar->x[r]; carg.y = ev->y - bar->borderpx; carg.w = bar->w[r]; carg.h = bar->bh - 2 * bar->borderpx; click = br->clickfunc(bar, &arg, &carg); if (click < 0) return; break; } } break; } } if (click == ClkRootWin && (c = wintoclient(ev->window))) { #if FOCUSONCLICK_PATCH if (focusonwheel || (ev->button != Button4 && ev->button != Button5)) focus(c); #else focus(c); restack(selmon); #endif // FOCUSONCLICK_PATCH XAllowEvents(dpy, ReplayPointer, CurrentTime); click = ClkClientWin; } for (i = 0; i < LENGTH(buttons); i++) { if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state)) { #if BAR_WINTITLEACTIONS_PATCH buttons[i].func((click == ClkTagBar || click == ClkWinTitle) && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); #else buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); #endif // BAR_WINTITLEACTIONS_PATCH } } } void checkotherwm(void) { xerrorxlib = XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); XSync(dpy, False); XSetErrorHandler(xerror); XSync(dpy, False); } void cleanup(void) { Arg a = {.ui = ~0}; Layout foo = { "", NULL }; Monitor *m; size_t i; view(&a); selmon->lt[selmon->sellt] = &foo; for (m = mons; m; m = m->next) while (m->stack) unmanage(m->stack, 0); XUngrabKey(dpy, AnyKey, AnyModifier, root); while (mons) cleanupmon(mons); #if BAR_SYSTRAY_PATCH if (showsystray && systray) { if (systray->win) { XUnmapWindow(dpy, systray->win); XDestroyWindow(dpy, systray->win); } free(systray); } #endif // BAR_SYSTRAY_PATCH for (i = 0; i < CurLast; i++) drw_cur_free(drw, cursor[i]); #if BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH for (i = 0; i < LENGTH(colors) + 1; i++) #else for (i = 0; i < LENGTH(colors); i++) #endif // BAR_STATUS2D_PATCH free(scheme[i]); free(scheme); XDestroyWindow(dpy, wmcheckwin); drw_free(drw); XSync(dpy, False); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); #if IPC_PATCH ipc_cleanup(); if (close(epoll_fd) < 0) fprintf(stderr, "Failed to close epoll file descriptor\n"); #endif // IPC_PATCH } void cleanupmon(Monitor *mon) { Monitor *m; Bar *bar; if (mon == mons) mons = mons->next; else { for (m = mons; m && m->next != mon; m = m->next); m->next = mon->next; } for (bar = mon->bar; bar; bar = mon->bar) { XUnmapWindow(dpy, bar->win); XDestroyWindow(dpy, bar->win); mon->bar = bar->next; free(bar); } free(mon); } void clientmessage(XEvent *e) { #if BAR_SYSTRAY_PATCH XWindowAttributes wa; XSetWindowAttributes swa; #endif // BAR_SYSTRAY_PATCH XClientMessageEvent *cme = &e->xclient; Client *c = wintoclient(cme->window); #if FOCUSONNETACTIVE_PATCH unsigned int i; #endif // FOCUSONNETACTIVE_PATCH #if BAR_SYSTRAY_PATCH if (showsystray && systray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) { /* add systray icons */ if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) { if (!(c = (Client *)calloc(1, sizeof(Client)))) die("fatal: could not malloc() %u bytes\n", sizeof(Client)); if (!(c->win = cme->data.l[2])) { free(c); return; } c->mon = selmon; c->next = systray->icons; systray->icons = c; XGetWindowAttributes(dpy, c->win, &wa); c->x = c->oldx = c->y = c->oldy = 0; c->w = c->oldw = wa.width; c->h = c->oldh = wa.height; c->oldbw = wa.border_width; c->bw = 0; c->isfloating = True; /* reuse tags field as mapped status */ c->tags = 1; updatesizehints(c); updatesystrayicongeom(c, wa.width, wa.height); XAddToSaveSet(dpy, c->win); XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); XClassHint ch = {"dwmsystray", "dwmsystray"}; XSetClassHint(dpy, c->win, &ch); XReparentWindow(dpy, c->win, systray->win, 0, 0); /* use parents background color */ swa.background_pixel = scheme[SchemeNorm][ColBg].pixel; XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa); sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION); XSync(dpy, False); setclientstate(c, NormalState); } return; } #endif // BAR_SYSTRAY_PATCH if (!c) return; if (cme->message_type == netatom[NetWMState]) { if (cme->data.l[1] == netatom[NetWMFullscreen] || cme->data.l[2] == netatom[NetWMFullscreen]) { #if !FAKEFULLSCREEN_PATCH && FAKEFULLSCREEN_CLIENT_PATCH if (c->fakefullscreen == 1) resizeclient(c, c->x, c->y, c->w, c->h); else setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen ))); #else setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ #if !FAKEFULLSCREEN_PATCH && !c->isfullscreen #endif // !FAKEFULLSCREEN_PATCH ))); #endif // FAKEFULLSCREEN_CLIENT_PATCH } } else if (cme->message_type == netatom[NetActiveWindow]) { #if FOCUSONNETACTIVE_PATCH if (c->tags & c->mon->tagset[c->mon->seltags]) { selmon = c->mon; focus(c); } else { for (i = 0; i < NUMTAGS && !((1 << i) & c->tags); i++); if (i < NUMTAGS) { selmon = c->mon; if (((1 << i) & TAGMASK) != selmon->tagset[selmon->seltags]) view(&((Arg) { .ui = 1 << i })); focus(c); restack(selmon); } } #else if (c != selmon->sel && !c->isurgent) seturgent(c, 1); #endif // FOCUSONNETACTIVE_PATCH } } void configure(Client *c) { XConfigureEvent ce; ce.type = ConfigureNotify; ce.display = dpy; ce.event = c->win; ce.window = c->win; ce.x = c->x; ce.y = c->y; ce.width = c->w; ce.height = c->h; ce.border_width = c->bw; ce.above = None; ce.override_redirect = False; XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce); } void configurenotify(XEvent *e) { Monitor *m; Bar *bar; #if !FAKEFULLSCREEN_PATCH Client *c; #endif // !FAKEFULLSCREEN_PATCH XConfigureEvent *ev = &e->xconfigure; int dirty; /* TODO: updategeom handling sucks, needs to be simplified */ if (ev->window == root) { dirty = (sw != ev->width || sh != ev->height); sw = ev->width; sh = ev->height; if (updategeom() || dirty) { drw_resize(drw, sw, bh); updatebars(); for (m = mons; m; m = m->next) { #if !FAKEFULLSCREEN_PATCH for (c = m->clients; c; c = c->next) #if FAKEFULLSCREEN_CLIENT_PATCH if (c->isfullscreen && c->fakefullscreen != 1) #else if (c->isfullscreen) #endif // FAKEFULLSCREEN_CLIENT_PATCH resizeclient(c, m->mx, m->my, m->mw, m->mh); #endif // !FAKEFULLSCREEN_PATCH for (bar = m->bar; bar; bar = bar->next) XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); } focus(NULL); arrange(NULL); } } } void configurerequest(XEvent *e) { Client *c; Monitor *m; XConfigureRequestEvent *ev = &e->xconfigurerequest; XWindowChanges wc; if ((c = wintoclient(ev->window))) { if (ev->value_mask & CWBorderWidth) c->bw = ev->border_width; else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) { m = c->mon; #if STEAM_PATCH if (!c->issteam) { if (ev->value_mask & CWX) { c->oldx = c->x; c->x = m->mx + ev->x; } if (ev->value_mask & CWY) { c->oldy = c->y; c->y = m->my + ev->y; } } #else if (ev->value_mask & CWX) { c->oldx = c->x; c->x = m->mx + ev->x; } if (ev->value_mask & CWY) { c->oldy = c->y; c->y = m->my + ev->y; } #endif // STEAM_PATCH if (ev->value_mask & CWWidth) { c->oldw = c->w; c->w = ev->width; } if (ev->value_mask & CWHeight) { c->oldh = c->h; c->h = ev->height; } if ((c->x + c->w) > m->mx + m->mw && c->isfloating) c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */ if ((c->y + c->h) > m->my + m->mh && c->isfloating) c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */ if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) configure(c); if (ISVISIBLE(c)) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); #if AUTORESIZE_PATCH else c->needresize = 1; #endif // AUTORESIZE_PATCH } else configure(c); } else { wc.x = ev->x; wc.y = ev->y; wc.width = ev->width; wc.height = ev->height; wc.border_width = ev->border_width; wc.sibling = ev->above; wc.stack_mode = ev->detail; XConfigureWindow(dpy, ev->window, ev->value_mask, &wc); } XSync(dpy, False); } Monitor * createmon(void) { Monitor *m, *mon; int i, n, mi, max_bars = 2, istopbar = topbar; #if MONITOR_RULES_PATCH int layout; #endif // MONITOR_RULES_PATCH const BarRule *br; Bar *bar; #if MONITOR_RULES_PATCH int j; const MonitorRule *mr; #endif // MONITOR_RULES_PATCH m = ecalloc(1, sizeof(Monitor)); #if EMPTYVIEW_PATCH m->tagset[0] = m->tagset[1] = 0; #else m->tagset[0] = m->tagset[1] = 1; #endif // EMPTYVIEW_PATCH m->mfact = mfact; m->nmaster = nmaster; #if FLEXTILE_DELUXE_LAYOUT m->nstack = nstack; #endif // FLEXTILE_DELUXE_LAYOUT m->showbar = showbar; #if SETBORDERPX_PATCH m->borderpx = borderpx; #endif // SETBORDERPX_PATCH #if VANITYGAPS_PATCH m->gappih = gappih; m->gappiv = gappiv; m->gappoh = gappoh; m->gappov = gappov; #endif // VANITYGAPS_PATCH for (mi = 0, mon = mons; mon; mon = mon->next, mi++); // monitor index m->index = mi; #if MONITOR_RULES_PATCH for (j = 0; j < LENGTH(monrules); j++) { mr = &monrules[j]; if ((mr->monitor == -1 || mr->monitor == mi) #if PERTAG_PATCH && (mr->tag <= 0 || (m->tagset[0] & (1 << (mr->tag - 1)))) #endif // PERTAG_PATCH ) { layout = MAX(mr->layout, 0); layout = MIN(layout, LENGTH(layouts) - 1); m->lt[0] = &layouts[layout]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; strncpy(m->ltsymbol, layouts[layout].symbol, sizeof m->ltsymbol); if (mr->mfact > -1) m->mfact = mr->mfact; if (mr->nmaster > -1) m->nmaster = mr->nmaster; if (mr->showbar > -1) m->showbar = mr->showbar; if (mr->topbar > -1) istopbar = mr->topbar; break; } } #else m->lt[0] = &layouts[0]; m->lt[1] = &layouts[1 % LENGTH(layouts)]; strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); #endif // MONITOR_RULES_PATCH /* Derive the number of bars for this monitor based on bar rules */ for (n = -1, i = 0; i < LENGTH(barrules); i++) { br = &barrules[i]; if (br->monitor == 'A' || br->monitor == -1 || br->monitor == mi) n = MAX(br->bar, n); } for (i = 0; i <= n && i < max_bars; i++) { bar = ecalloc(1, sizeof(Bar)); bar->mon = m; bar->idx = i; bar->next = m->bar; bar->topbar = istopbar; m->bar = bar; istopbar = !istopbar; bar->showbar = 1; #if BAR_BORDER_PATCH bar->borderpx = borderpx; #else bar->borderpx = 0; #endif // BAR_BORDER_PATCH bar->borderscheme = SchemeNorm; } #if FLEXTILE_DELUXE_LAYOUT m->ltaxis[LAYOUT] = m->lt[0]->preset.layout; m->ltaxis[MASTER] = m->lt[0]->preset.masteraxis; m->ltaxis[STACK] = m->lt[0]->preset.stack1axis; m->ltaxis[STACK2] = m->lt[0]->preset.stack2axis; #endif // FLEXTILE_DELUXE_LAYOUT #if PERTAG_PATCH if (!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag)))) die("fatal: could not malloc() %u bytes\n", sizeof(Pertag)); m->pertag->curtag = m->pertag->prevtag = 1; for (i = 0; i <= NUMTAGS; i++) { #if FLEXTILE_DELUXE_LAYOUT m->pertag->nstacks[i] = m->nstack; #endif // FLEXTILE_DELUXE_LAYOUT #if !MONITOR_RULES_PATCH /* init nmaster */ m->pertag->nmasters[i] = m->nmaster; /* init mfacts */ m->pertag->mfacts[i] = m->mfact; #if PERTAGBAR_PATCH /* init showbar */ m->pertag->showbars[i] = m->showbar; #endif // PERTAGBAR_PATCH #endif // MONITOR_RULES_PATCH #if ZOOMSWAP_PATCH m->pertag->prevzooms[i] = NULL; #endif // ZOOMSWAP_PATCH /* init layouts */ #if MONITOR_RULES_PATCH for (j = 0; j < LENGTH(monrules); j++) { mr = &monrules[j]; if ((mr->monitor == -1 || mr->monitor == mi) && (mr->tag == -1 || mr->tag == i)) { layout = MAX(mr->layout, 0); layout = MIN(layout, LENGTH(layouts) - 1); m->pertag->ltidxs[i][0] = &layouts[layout]; m->pertag->ltidxs[i][1] = m->lt[0]; m->pertag->nmasters[i] = (mr->nmaster > -1 ? mr->nmaster : m->nmaster); m->pertag->mfacts[i] = (mr->mfact > -1 ? mr->mfact : m->mfact); #if PERTAGBAR_PATCH m->pertag->showbars[i] = (mr->showbar > -1 ? mr->showbar : m->showbar); #endif // PERTAGBAR_PATCH #if FLEXTILE_DELUXE_LAYOUT m->pertag->ltaxis[i][LAYOUT] = m->pertag->ltidxs[i][0]->preset.layout; m->pertag->ltaxis[i][MASTER] = m->pertag->ltidxs[i][0]->preset.masteraxis; m->pertag->ltaxis[i][STACK] = m->pertag->ltidxs[i][0]->preset.stack1axis; m->pertag->ltaxis[i][STACK2] = m->pertag->ltidxs[i][0]->preset.stack2axis; #endif // FLEXTILE_DELUXE_LAYOUT break; } } #else m->pertag->ltidxs[i][0] = m->lt[0]; m->pertag->ltidxs[i][1] = m->lt[1]; #if FLEXTILE_DELUXE_LAYOUT /* init flextile axes */ m->pertag->ltaxis[i][LAYOUT] = m->ltaxis[LAYOUT]; m->pertag->ltaxis[i][MASTER] = m->ltaxis[MASTER]; m->pertag->ltaxis[i][STACK] = m->ltaxis[STACK]; m->pertag->ltaxis[i][STACK2] = m->ltaxis[STACK2]; #endif // FLEXTILE_DELUXE_LAYOUT #endif // MONITOR_RULES_PATCH m->pertag->sellts[i] = m->sellt; #if VANITYGAPS_PATCH m->pertag->enablegaps[i] = 1; #endif // VANITYGAPS_PATCH } #endif // PERTAG_PATCH #if INSETS_PATCH m->inset = default_inset; #endif // INSETS_PATCH return m; } void destroynotify(XEvent *e) { Client *c; XDestroyWindowEvent *ev = &e->xdestroywindow; if ((c = wintoclient(ev->window))) unmanage(c, 1); #if SWALLOW_PATCH else if ((c = swallowingclient(ev->window))) unmanage(c->swallowing, 1); #endif // SWALLOW_PATCH #if BAR_SYSTRAY_PATCH else if (showsystray && (c = wintosystrayicon(ev->window))) { removesystrayicon(c); drawbarwin(systray->bar); } #endif // BAR_SYSTRAY_PATCH } void detach(Client *c) { Client **tc; for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next); *tc = c->next; } void detachstack(Client *c) { Client **tc, *t; for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext); *tc = c->snext; if (c == c->mon->sel) { for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext); c->mon->sel = t; } } Monitor * dirtomon(int dir) { Monitor *m = NULL; if (dir > 0) { if (!(m = selmon->next)) m = mons; } else if (selmon == mons) for (m = mons; m->next; m = m->next); else for (m = mons; m->next != selmon; m = m->next); return m; } void drawbar(Monitor *m) { Bar *bar; for (bar = m->bar; bar; bar = bar->next) drawbarwin(bar); } void drawbars(void) { Monitor *m; for (m = mons; m; m = m->next) drawbar(m); } void drawbarwin(Bar *bar) { if (!bar->win) return; int r, w, total_drawn = 0; int rx, lx, rw, lw; // bar size, split between left and right if a center module is added const BarRule *br; if (bar->borderpx) { XSetForeground(drw->dpy, drw->gc, scheme[bar->borderscheme][ColBorder].pixel); XFillRectangle(drw->dpy, drw->drawable, drw->gc, 0, 0, bar->bw, bar->bh); } BarArg warg = { 0 }; BarArg darg = { 0 }; warg.h = bar->bh - 2 * bar->borderpx; rw = lw = bar->bw - 2 * bar->borderpx; rx = lx = bar->borderpx; drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, lx, bar->borderpx, lw, bar->bh - 2 * bar->borderpx, 1, 1); for (r = 0; r < LENGTH(barrules); r++) { br = &barrules[r]; if (br->bar != bar->idx || !br->widthfunc || (br->monitor == 'A' && bar->mon != selmon)) continue; if (br->monitor != 'A' && br->monitor != -1 && br->monitor != bar->mon->index) continue; drw_setscheme(drw, scheme[SchemeNorm]); warg.w = (br->alignment < BAR_ALIGN_RIGHT_LEFT ? lw : rw); w = br->widthfunc(bar, &warg); w = MIN(warg.w, w); if (lw <= 0) { // if left is exhausted then switch to right side, and vice versa lw = rw; lx = rx; } else if (rw <= 0) { rw = lw; rx = lx; } switch(br->alignment) { default: case BAR_ALIGN_NONE: case BAR_ALIGN_LEFT_LEFT: case BAR_ALIGN_LEFT: bar->x[r] = lx; if (lx == rx) { rx += w; rw -= w; } lx += w; lw -= w; break; case BAR_ALIGN_LEFT_RIGHT: case BAR_ALIGN_RIGHT: bar->x[r] = lx + lw - w; if (lx == rx) rw -= w; lw -= w; break; case BAR_ALIGN_LEFT_CENTER: case BAR_ALIGN_CENTER: bar->x[r] = lx + lw / 2 - w / 2; if (lx == rx) { rw = rx + rw - bar->x[r] - w; rx = bar->x[r] + w; } lw = bar->x[r] - lx; break; case BAR_ALIGN_RIGHT_LEFT: bar->x[r] = rx; if (lx == rx) { lx += w; lw -= w; } rx += w; rw -= w; break; case BAR_ALIGN_RIGHT_RIGHT: bar->x[r] = rx + rw - w; if (lx == rx) lw -= w; rw -= w; break; case BAR_ALIGN_RIGHT_CENTER: bar->x[r] = rx + rw / 2 - w / 2; if (lx == rx) { lw = lx + lw - bar->x[r] + w; lx = bar->x[r] + w; } rw = bar->x[r] - rx; break; } bar->w[r] = w; darg.x = bar->x[r]; darg.y = bar->borderpx; darg.h = bar->bh - 2 * bar->borderpx; darg.w = bar->w[r]; if (br->drawfunc) total_drawn += br->drawfunc(bar, &darg); } if (total_drawn == 0 && bar->showbar) { bar->showbar = 0; updatebarpos(bar->mon); XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); arrange(bar->mon); } else if (total_drawn > 0 && !bar->showbar) { bar->showbar = 1; updatebarpos(bar->mon); XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh); arrange(bar->mon); } else drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh); } #if !FOCUSONCLICK_PATCH void enternotify(XEvent *e) { Client *c; #if LOSEFULLSCREEN_PATCH Client *sel; #endif // LOSEFULLSCREEN_PATCH Monitor *m; XCrossingEvent *ev = &e->xcrossing; if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return; c = wintoclient(ev->window); m = c ? c->mon : wintomon(ev->window); if (m != selmon) { #if LOSEFULLSCREEN_PATCH sel = selmon->sel; selmon = m; unfocus(sel, 1, c); #else unfocus(selmon->sel, 1, c); selmon = m; #endif // LOSEFULLSCREEN_PATCH } else if (!c || c == selmon->sel) return; focus(c); } #endif // FOCUSONCLICK_PATCH void expose(XEvent *e) { Monitor *m; XExposeEvent *ev = &e->xexpose; if (ev->count == 0 && (m = wintomon(ev->window))) drawbar(m); } void focus(Client *c) { if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); if (selmon->sel && selmon->sel != c) unfocus(selmon->sel, 0, c); if (c) { if (c->mon != selmon) selmon = c->mon; if (c->isurgent) seturgent(c, 0); detachstack(c); attachstack(c); grabbuttons(c, 1); #if !BAR_FLEXWINTITLE_PATCH if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); #endif // BAR_FLEXWINTITLE_PATCH setfocus(c); } else { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } selmon->sel = c; drawbars(); } /* there are some broken focus acquiring clients needing extra handling */ void focusin(XEvent *e) { XFocusChangeEvent *ev = &e->xfocus; if (selmon->sel && ev->window != selmon->sel->win) setfocus(selmon->sel); } void focusmon(const Arg *arg) { Monitor *m; #if LOSEFULLSCREEN_PATCH Client *sel; #endif // LOSEFULLSCREEN_PATCH if (!mons->next) return; if ((m = dirtomon(arg->i)) == selmon) return; #if LOSEFULLSCREEN_PATCH sel = selmon->sel; selmon = m; unfocus(sel, 0, NULL); #else unfocus(selmon->sel, 0, NULL); selmon = m; #endif // LOSEFULLSCREEN_PATCH focus(NULL); #if WARP_PATCH warp(selmon->sel); #endif // WARP_PATCH } #if !STACKER_PATCH void focusstack(const Arg *arg) { Client *c = NULL, *i; if (!selmon->sel) return; #if ALWAYSFULLSCREEN_PATCH if (selmon->sel->isfullscreen) return; #endif // ALWAYSFULLSCREEN_PATCH #if BAR_WINTITLEACTIONS_PATCH if (arg->i > 0) { for (c = selmon->sel->next; c && (!ISVISIBLE(c) || (arg->i == 1 && HIDDEN(c))); c = c->next); if (!c) for (c = selmon->clients; c && (!ISVISIBLE(c) || (arg->i == 1 && HIDDEN(c))); c = c->next); } else { for (i = selmon->clients; i != selmon->sel; i = i->next) if (ISVISIBLE(i) && !(arg->i == -1 && HIDDEN(i))) c = i; if (!c) for (; i; i = i->next) if (ISVISIBLE(i) && !(arg->i == -1 && HIDDEN(i))) c = i; } #else if (arg->i > 0) { for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next); if (!c) for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next); } else { for (i = selmon->clients; i != selmon->sel; i = i->next) if (ISVISIBLE(i)) c = i; if (!c) for (; i; i = i->next) if (ISVISIBLE(i)) c = i; } #endif // BAR_WINTITLEACTIONS_PATCH if (c) { focus(c); restack(selmon); } } #endif // STACKER_PATCH Atom getatomprop(Client *c, Atom prop) { int di; unsigned long dl; unsigned char *p = NULL; Atom da, atom = None; #if BAR_SYSTRAY_PATCH /* FIXME getatomprop should return the number of items and a pointer to * the stored data instead of this workaround */ Atom req = XA_ATOM; if (prop == xatom[XembedInfo]) req = xatom[XembedInfo]; if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, req, &da, &di, &dl, &dl, &p) == Success && p) { atom = *(Atom *)p; if (da == xatom[XembedInfo] && dl == 2) atom = ((Atom *)p)[1]; XFree(p); } #else if (XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, &da, &di, &dl, &dl, &p) == Success && p) { atom = *(Atom *)p; XFree(p); } #endif // BAR_SYSTRAY_PATCH return atom; } int getrootptr(int *x, int *y) { int di; unsigned int dui; Window dummy; return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui); } long getstate(Window w) { int format; long result = -1; unsigned char *p = NULL; unsigned long n, extra; Atom real; if (XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], &real, &format, &n, &extra, (unsigned char **)&p) != Success) return -1; if (n != 0) result = *p; XFree(p); return result; } int gettextprop(Window w, Atom atom, char *text, unsigned int size) { char **list = NULL; int n; XTextProperty name; if (!text || size == 0) return 0; text[0] = '\0'; if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems) return 0; if (name.encoding == XA_STRING) strncpy(text, (char *)name.value, size - 1); else { if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success && n > 0 && *list) { strncpy(text, *list, size - 1); XFreeStringList(list); } } text[size - 1] = '\0'; XFree(name.value); return 1; } void grabbuttons(Client *c, int focused) { updatenumlockmask(); { unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; XUngrabButton(dpy, AnyButton, AnyModifier, c->win); if (!focused) XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, GrabModeSync, GrabModeSync, None, None); for (i = 0; i < LENGTH(buttons); i++) if (buttons[i].click == ClkClientWin) for (j = 0; j < LENGTH(modifiers); j++) XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None); } } void #if KEYMODES_PATCH grabdefkeys(void) #else grabkeys(void) #endif // KEYMODES_PATCH { updatenumlockmask(); { unsigned int i, j; unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; KeyCode code; XUngrabKey(dpy, AnyKey, AnyModifier, root); for (i = 0; i < LENGTH(keys); i++) if ((code = XKeysymToKeycode(dpy, keys[i].keysym))) for (j = 0; j < LENGTH(modifiers); j++) XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, GrabModeAsync, GrabModeAsync); } } void incnmaster(const Arg *arg) { #if PERTAG_PATCH selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0); #else selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); #endif // PERTAG_PATCH arrange(selmon); } #ifdef XINERAMA static int isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) { while (n--) if (unique[n].x_org == info->x_org && unique[n].y_org == info->y_org && unique[n].width == info->width && unique[n].height == info->height) return 0; return 1; } #endif /* XINERAMA */ void #if KEYMODES_PATCH keydefpress(XEvent *e) #else keypress(XEvent *e) #endif // KEYMODES_PATCH { unsigned int i; KeySym keysym; XKeyEvent *ev; ev = &e->xkey; keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); for (i = 0; i < LENGTH(keys); i++) if (keysym == keys[i].keysym && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state) && keys[i].func) keys[i].func(&(keys[i].arg)); } void killclient(const Arg *arg) { #if ISPERMANENT_PATCH if (!selmon->sel || selmon->sel->ispermanent) #else if (!selmon->sel) #endif // ISPERMANENT_PATCH return; #if BAR_SYSTRAY_PATCH if (!sendevent(selmon->sel->win, wmatom[WMDelete], NoEventMask, wmatom[WMDelete], CurrentTime, 0, 0, 0)) { #else if (!sendevent(selmon->sel, wmatom[WMDelete])) { #endif // BAR_SYSTRAY_PATCH XGrabServer(dpy); XSetErrorHandler(xerrordummy); XSetCloseDownMode(dpy, DestroyAll); XKillClient(dpy, selmon->sel->win); XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); } #if SWAPFOCUS_PATCH && PERTAG_PATCH selmon->pertag->prevclient[selmon->pertag->curtag] = NULL; #endif // SWAPFOCUS_PATCH } void layoutmenu(const Arg *arg) { FILE *p; char c[3], *s; int i; if (!(p = popen(layoutmenu_cmd, "r"))) return; s = fgets(c, sizeof(c), p); pclose(p); if (!s || *s == '\0' || c == '\0') return; i = atoi(c); setlayout(&((Arg) { .v = &layouts[i] })); } void manage(Window w, XWindowAttributes *wa) { Client *c, *t = NULL; #if SWALLOW_PATCH Client *term = NULL; #endif // SWALLOW_PATCH Window trans = None; XWindowChanges wc; c = ecalloc(1, sizeof(Client)); c->win = w; #if SWALLOW_PATCH c->pid = winpid(w); #endif // SWALLOW_PATCH /* geometry */ c->x = c->oldx = wa->x; c->y = c->oldy = wa->y; c->w = c->oldw = wa->width; c->h = c->oldh = wa->height; c->oldbw = wa->border_width; #if CFACTS_PATCH c->cfact = 1.0; #endif // CFACTS_PATCH updatetitle(c); if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { c->mon = t->mon; c->tags = t->tags; #if FLOATPOS_PATCH #if SETBORDERPX_PATCH c->bw = c->mon->borderpx; #else c->bw = borderpx; #endif // SETBORDERPX_PATCH #endif // FLOATPOS_PATCH #if CENTER_TRANSIENT_WINDOWS_BY_PARENT_PATCH c->x = t->x + WIDTH(t) / 2 - WIDTH(c) / 2; c->y = t->y + HEIGHT(t) / 2 - HEIGHT(c) / 2; #elif CENTER_TRANSIENT_WINDOWS_PATCH c->x = c->mon->wx + (c->mon->ww - WIDTH(c)) / 2; c->y = c->mon->wy + (c->mon->wh - HEIGHT(c)) / 2; #endif // CENTER_TRANSIENT_WINDOWS_PATCH | CENTER_TRANSIENT_WINDOWS_BY_PARENT_PATCH } else { c->mon = selmon; #if FLOATPOS_PATCH #if SETBORDERPX_PATCH c->bw = c->mon->borderpx; #else c->bw = borderpx; #endif // SETBORDERPX_PATCH #endif // FLOATPOS_PATCH applyrules(c); #if SWALLOW_PATCH term = termforwin(c); #endif // SWALLOW_PATCH } if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) c->x = c->mon->mx + c->mon->mw - WIDTH(c); if (c->y + HEIGHT(c) > c->mon->my + c->mon->mh) c->y = c->mon->my + c->mon->mh - HEIGHT(c); c->x = MAX(c->x, c->mon->mx); /* only fix client y-offset, if the client center might cover the bar */ c->y = MAX(c->y, ((c->mon->bar->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx) && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); #if !FLOATPOS_PATCH #if SETBORDERPX_PATCH c->bw = c->mon->borderpx; #else c->bw = borderpx; #endif // SETBORDERPX_PATCH #endif // FLOATPOS_PATCH wc.border_width = c->bw; XConfigureWindow(dpy, w, CWBorderWidth, &wc); #if !BAR_FLEXWINTITLE_PATCH if (c->isfloating) XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColFloat].pixel); else XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); #endif // BAR_FLEXWINTITLE_PATCH configure(c); /* propagates border_width, if size doesn't change */ #if !FLOATPOS_PATCH updatesizehints(c); #endif // FLOATPOS_PATCH if (getatomprop(c, netatom[NetWMState]) == netatom[NetWMFullscreen]) setfullscreen(c, 1); updatewmhints(c); #if DECORATION_HINTS_PATCH updatemotifhints(c); #endif // DECORATION_HINTS_PATCH #if CENTER_PATCH if (c->iscentered) { c->x = c->mon->wx + (c->mon->ww - WIDTH(c)) / 2; c->y = c->mon->wy + (c->mon->wh - HEIGHT(c)) / 2; } #endif // CENTER_PATCH #if SAVEFLOATS_PATCH || EXRESIZE_PATCH c->sfx = -9999; c->sfy = -9999; c->sfw = c->w; c->sfh = c->h; #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); #if MAXIMIZE_PATCH c->wasfloating = 0; c->ismax = 0; #elif EXRESIZE_PATCH c->wasfloating = 0; #endif // MAXIMIZE_PATCH / EXRESIZE_PATCH if (!c->isfloating) c->isfloating = c->oldstate = trans != None || c->isfixed; if (c->isfloating) { XRaiseWindow(dpy, c->win); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColFloat].pixel); } #if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH attachx(c); #else attach(c); #endif attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char *) &(c->win), 1); XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ #if BAR_WINTITLEACTIONS_PATCH if (!HIDDEN(c)) setclientstate(c, NormalState); #else setclientstate(c, NormalState); #endif // BAR_WINTITLEACTIONS_PATCH if (c->mon == selmon) unfocus(selmon->sel, 0, c); c->mon->sel = c; arrange(c->mon); #if BAR_WINTITLEACTIONS_PATCH if (!HIDDEN(c)) XMapWindow(dpy, c->win); #else XMapWindow(dpy, c->win); #endif // BAR_WINTITLEACTIONS_PATCH #if SWALLOW_PATCH if (term) swallow(term, c); #endif // SWALLOW_PATCH focus(NULL); } void mappingnotify(XEvent *e) { XMappingEvent *ev = &e->xmapping; XRefreshKeyboardMapping(ev); if (ev->request == MappingKeyboard) grabkeys(); } void maprequest(XEvent *e) { static XWindowAttributes wa; XMapRequestEvent *ev = &e->xmaprequest; #if BAR_SYSTRAY_PATCH Client *i; if (showsystray && systray && (i = wintosystrayicon(ev->window))) { sendevent(i->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0, systray->win, XEMBED_EMBEDDED_VERSION); drawbarwin(systray->bar); } #endif // BAR_SYSTRAY_PATCH if (!XGetWindowAttributes(dpy, ev->window, &wa)) return; if (wa.override_redirect) return; if (!wintoclient(ev->window)) manage(ev->window, &wa); } #if !FOCUSONCLICK_PATCH void motionnotify(XEvent *e) { static Monitor *mon = NULL; Monitor *m; #if LOSEFULLSCREEN_PATCH Client *sel; #endif // LOSEFULLSCREEN_PATCH XMotionEvent *ev = &e->xmotion; if (ev->window != root) return; if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { #if LOSEFULLSCREEN_PATCH sel = selmon->sel; selmon = m; unfocus(sel, 1, NULL); #else unfocus(selmon->sel, 1, NULL); selmon = m; #endif // LOSEFULLSCREEN_PATCH focus(NULL); } mon = m; } #endif // FOCUSONCLICK_PATCH void movemouse(const Arg *arg) { int x, y, ocx, ocy, nx, ny; Client *c; Monitor *m; XEvent ev; Time lasttime = 0; if (!(c = selmon->sel)) return; #if !FAKEFULLSCREEN_PATCH #if FAKEFULLSCREEN_CLIENT_PATCH if (c->isfullscreen && c->fakefullscreen != 1) /* no support moving fullscreen windows by mouse */ return; #else if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ return; #endif // FAKEFULLSCREEN_CLIENT_PATCH #endif // FAKEFULLSCREEN_PATCH restack(selmon); ocx = c->x; ocy = c->y; if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurMove]->cursor, CurrentTime) != GrabSuccess) return; if (!getrootptr(&x, &y)) return; do { XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch(ev.type) { case ConfigureRequest: case Expose: case MapRequest: handler[ev.type](&ev); break; case MotionNotify: if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue; lasttime = ev.xmotion.time; nx = ocx + (ev.xmotion.x - x); ny = ocy + (ev.xmotion.y - y); if (abs(selmon->wx - nx) < snap) nx = selmon->wx; else if (abs((selmon->wx + selmon->ww) - (nx + WIDTH(c))) < snap) nx = selmon->wx + selmon->ww - WIDTH(c); if (abs(selmon->wy - ny) < snap) ny = selmon->wy; else if (abs((selmon->wy + selmon->wh) - (ny + HEIGHT(c))) < snap) ny = selmon->wy + selmon->wh - HEIGHT(c); if (!c->isfloating && selmon->lt[selmon->sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) togglefloating(NULL); if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) { #if SAVEFLOATS_PATCH || EXRESIZE_PATCH resize(c, nx, ny, c->w, c->h, 1); /* save last known float coordinates */ c->sfx = nx; c->sfy = ny; #else resize(c, nx, ny, c->w, c->h, 1); #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH } #if ROUNDED_CORNERS_PATCH drawroundedcorners(c); #endif // ROUNDED_CORNERS_PATCH break; } } while (ev.type != ButtonRelease); XUngrabPointer(dpy, CurrentTime); if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { sendmon(c, m); selmon = m; focus(NULL); } #if ROUNDED_CORNERS_PATCH drawroundedcorners(c); #endif // ROUNDED_CORNERS_PATCH } Client * nexttiled(Client *c) { #if BAR_WINTITLEACTIONS_PATCH for (; c && (c->isfloating || !ISVISIBLE(c) || HIDDEN(c)); c = c->next); #else for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); #endif // BAR_WINTITLEACTIONS_PATCH return c; } #if !ZOOMSWAP_PATCH || TAGINTOSTACK_ALLMASTER_PATCH || TAGINTOSTACK_ONEMASTER_PATCH void pop(Client *c) { detach(c); attach(c); focus(c); arrange(c->mon); } #endif // !ZOOMSWAP_PATCH / TAGINTOSTACK_ALLMASTER_PATCH / TAGINTOSTACK_ONEMASTER_PATCH void propertynotify(XEvent *e) { Client *c; Window trans; XPropertyEvent *ev = &e->xproperty; #if BAR_SYSTRAY_PATCH if (showsystray && (c = wintosystrayicon(ev->window))) { if (ev->atom == XA_WM_NORMAL_HINTS) { updatesizehints(c); updatesystrayicongeom(c, c->w, c->h); } else updatesystrayiconstate(c, ev); drawbarwin(systray->bar); } #endif // BAR_SYSTRAY_PATCH if ((ev->window == root) && (ev->atom == XA_WM_NAME)) { #if DWMC_PATCH || FSIGNAL_PATCH if (!fake_signal()) updatestatus(); #else updatestatus(); #endif // DWMC_PATCH / FSIGNAL_PATCH } else if (ev->state == PropertyDelete) { return; /* ignore */ } else if ((c = wintoclient(ev->window))) { switch(ev->atom) { default: break; case XA_WM_TRANSIENT_FOR: if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && (c->isfloating = (wintoclient(trans)) != NULL)) arrange(c->mon); break; case XA_WM_NORMAL_HINTS: updatesizehints(c); break; case XA_WM_HINTS: updatewmhints(c); if (c->isurgent) drawbars(); break; } if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); if (c == c->mon->sel) drawbar(c->mon); } #if DECORATION_HINTS_PATCH if (ev->atom == motifatom) updatemotifhints(c); #endif // DECORATION_HINTS_PATCH } } void quit(const Arg *arg) { #if COOL_AUTOSTART_PATCH size_t i; #endif // COOL_AUTOSTART_PATCH #if ONLYQUITONEMPTY_PATCH unsigned int n; Window *junk = malloc(1); XQueryTree(dpy, root, junk, junk, &junk, &n); #if COOL_AUTOSTART_PATCH if (n - autostart_len <= quit_empty_window_count) #else if (n <= quit_empty_window_count) #endif // COOL_AUTOSTART_PATCH { #if RESTARTSIG_PATCH if (arg->i) restart = 1; #endif // RESTARTSIG_PATCH running = 0; } else printf("[dwm] not exiting (n=%d)\n", n); free(junk); #else #if RESTARTSIG_PATCH if (arg->i) restart = 1; #endif // RESTARTSIG_PATCH running = 0; #endif // ONLYQUITONEMPTY_PATCH #if COOL_AUTOSTART_PATCH /* kill child processes */ for (i = 0; i < autostart_len; i++) { if (0 < autostart_pids[i]) { kill(autostart_pids[i], SIGTERM); waitpid(autostart_pids[i], NULL, 0); } } #endif // COOL_AUTOSTART_PATCH } Monitor * recttomon(int x, int y, int w, int h) { Monitor *m, *r = selmon; int a, area = 0; for (m = mons; m; m = m->next) if ((a = INTERSECT(x, y, w, h, m)) > area) { area = a; r = m; } return r; } void resize(Client *c, int x, int y, int w, int h, int interact) { if (applysizehints(c, &x, &y, &w, &h, interact)) resizeclient(c, x, y, w, h); } void resizeclient(Client *c, int x, int y, int w, int h) { XWindowChanges wc; c->oldx = c->x; c->x = wc.x = x; c->oldy = c->y; c->y = wc.y = y; c->oldw = c->w; c->w = wc.width = w; c->oldh = c->h; c->h = wc.height = h; #if EXRESIZE_PATCH c->expandmask = 0; #endif // EXRESIZE_PATCH wc.border_width = c->bw; #if NOBORDER_PATCH if (((nexttiled(c->mon->clients) == c && !nexttiled(c->next)) #if MONOCLE_LAYOUT || &monocle == c->mon->lt[c->mon->sellt]->arrange #endif // MONOCLE_LAYOUT ) #if FAKEFULLSCREEN_CLIENT_PATCH && (c->fakefullscreen == 1 || !c->isfullscreen) && c->fakefullscreen #else && !c->isfullscreen #endif // FAKEFULLSCREEN_CLIENT_PATCH && !c->isfloating && c->mon->lt[c->mon->sellt]->arrange) { c->w = wc.width += c->bw * 2; c->h = wc.height += c->bw * 2; wc.border_width = 0; } #endif // NOBORDER_PATCH XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); #if FAKEFULLSCREEN_CLIENT_PATCH if (c->fakefullscreen == 1) XSync(dpy, True); else XSync(dpy, False); #else XSync(dpy, False); #endif // FAKEFULLSCREEN_CLIENT_PATCH } void resizemouse(const Arg *arg) { int ocx, ocy, nw, nh; #if RESIZEPOINT_PATCH || RESIZECORNERS_PATCH int opx, opy, och, ocw, nx, ny; int horizcorner, vertcorner; unsigned int dui; Window dummy; #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH Client *c; Monitor *m; XEvent ev; Time lasttime = 0; if (!(c = selmon->sel)) return; #if !FAKEFULLSCREEN_PATCH #if FAKEFULLSCREEN_CLIENT_PATCH if (c->isfullscreen && c->fakefullscreen != 1) /* no support resizing fullscreen windows by mouse */ return; #else if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ return; #endif // FAKEFULLSCREEN_CLIENT_PATCH #endif // !FAKEFULLSCREEN_PATCH restack(selmon); ocx = c->x; ocy = c->y; #if RESIZEPOINT_PATCH och = c->h; ocw = c->w; #elif RESIZECORNERS_PATCH och = c->y + c->h; ocw = c->x + c->w; #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH #if RESIZEPOINT_PATCH || RESIZECORNERS_PATCH if (!XQueryPointer(dpy, c->win, &dummy, &dummy, &opx, &opy, &nx, &ny, &dui)) return; horizcorner = nx < c->w / 2; vertcorner = ny < c->h / 2; if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[horizcorner | (vertcorner << 1)]->cursor, CurrentTime) != GrabSuccess) return; #if RESIZECORNERS_PATCH XWarpPointer (dpy, None, c->win, 0, 0, 0, 0, horizcorner ? (-c->bw) : (c->w + c->bw - 1), vertcorner ? (-c->bw) : (c->h + c->bw - 1)); #endif // RESIZECORNERS_PATCH #else if (XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, None, cursor[CurResize]->cursor, CurrentTime) != GrabSuccess) return; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH do { XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev); switch(ev.type) { case ConfigureRequest: case Expose: case MapRequest: handler[ev.type](&ev); break; case MotionNotify: if ((ev.xmotion.time - lasttime) <= (1000 / 60)) continue; lasttime = ev.xmotion.time; #if RESIZEPOINT_PATCH nx = horizcorner ? (ocx + ev.xmotion.x - opx) : c->x; ny = vertcorner ? (ocy + ev.xmotion.y - opy) : c->y; nw = MAX(horizcorner ? (ocx + ocw - nx) : (ocw + (ev.xmotion.x - opx)), 1); nh = MAX(vertcorner ? (ocy + och - ny) : (och + (ev.xmotion.y - opy)), 1); #elif RESIZECORNERS_PATCH nx = horizcorner ? ev.xmotion.x : c->x; ny = vertcorner ? ev.xmotion.y : c->y; nw = MAX(horizcorner ? (ocw - nx) : (ev.xmotion.x - ocx - 2 * c->bw + 1), 1); nh = MAX(vertcorner ? (och - ny) : (ev.xmotion.y - ocy - 2 * c->bw + 1), 1); #else nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1); nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1); #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH if (c->mon->wx + nw >= selmon->wx && c->mon->wx + nw <= selmon->wx + selmon->ww && c->mon->wy + nh >= selmon->wy && c->mon->wy + nh <= selmon->wy + selmon->wh) { if (!c->isfloating && selmon->lt[selmon->sellt]->arrange && (abs(nw - c->w) > snap || abs(nh - c->h) > snap)) togglefloating(NULL); } if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) { #if RESIZECORNERS_PATCH || RESIZEPOINT_PATCH resizeclient(c, nx, ny, nw, nh); #if SAVEFLOATS_PATCH || EXRESIZE_PATCH /* save last known float dimensions */ c->sfx = nx; c->sfy = ny; c->sfw = nw; c->sfh = nh; #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH #else resize(c, c->x, c->y, nw, nh, 1); #if SAVEFLOATS_PATCH || EXRESIZE_PATCH c->sfx = c->x; c->sfy = c->y; c->sfw = nw; c->sfh = nh; #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH #endif // RESIZECORNERS_PATCH #if ROUNDED_CORNERS_PATCH drawroundedcorners(c); #endif // ROUNDED_CORNERS_PATCH } break; } } while (ev.type != ButtonRelease); #if !RESIZEPOINT_PATCH #if RESIZECORNERS_PATCH XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, horizcorner ? (-c->bw) : (c->w + c->bw - 1), vertcorner ? (-c->bw) : (c->h + c->bw - 1)); #else XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1); #endif // RESIZECORNERS_PATCH #endif // RESIZEPOINT_PATCH XUngrabPointer(dpy, CurrentTime); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); if ((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) { sendmon(c, m); selmon = m; focus(NULL); } } void restack(Monitor *m) { Client *c; XEvent ev; XWindowChanges wc; #if WARP_PATCH && FLEXTILE_DELUXE_LAYOUT int n; #endif // WARP_PATCH drawbar(m); if (!m->sel) return; if (m->sel->isfloating || !m->lt[m->sellt]->arrange) XRaiseWindow(dpy, m->sel->win); if (m->lt[m->sellt]->arrange) { wc.stack_mode = Below; wc.sibling = m->bar->win; for (c = m->stack; c; c = c->snext) if (!c->isfloating && ISVISIBLE(c)) { XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); wc.sibling = c->win; } } XSync(dpy, False); while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); #if WARP_PATCH && FLEXTILE_DELUXE_LAYOUT || WARP_PATCH && MONOCLE_LAYOUT #if FLEXTILE_DELUXE_LAYOUT for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); #endif // FLEXTILE_DELUXE_LAYOUT if (m == selmon && (m->tagset[m->seltags] & m->sel->tags) && ( #if MONOCLE_LAYOUT && FLEXTILE_DELUXE_LAYOUT (m->lt[m->sellt]->arrange != &monocle && !(m->ltaxis[MASTER] == MONOCLE && (abs(m->ltaxis[LAYOUT] == NO_SPLIT || !m->nmaster || n <= m->nmaster)))) #elif MONOCLE_LAYOUT m->lt[m->sellt]->arrange == &monocle #else !(m->ltaxis[MASTER] == MONOCLE && (abs(m->ltaxis[LAYOUT] == NO_SPLIT || !m->nmaster || n <= m->nmaster))) #endif // FLEXTILE_DELUXE_LAYOUT || m->sel->isfloating) ) warp(m->sel); #endif // WARP_PATCH } #if IPC_PATCH void run(void) { int event_count = 0; const int MAX_EVENTS = 10; struct epoll_event events[MAX_EVENTS]; XSync(dpy, False); /* main event loop */ while (running) { event_count = epoll_wait(epoll_fd, events, MAX_EVENTS, -1); for (int i = 0; i < event_count; i++) { int event_fd = events[i].data.fd; DEBUG("Got event from fd %d\n", event_fd); if (event_fd == dpy_fd) { // -1 means EPOLLHUP if (handlexevent(events + i) == -1) return; } else if (event_fd == ipc_get_sock_fd()) { ipc_handle_socket_epoll_event(events + i); } else if (ipc_is_client_registered(event_fd)) { if (ipc_handle_client_epoll_event(events + i, mons, &lastselmon, selmon, NUMTAGS, layouts, LENGTH(layouts)) < 0) { fprintf(stderr, "Error handling IPC event on fd %d\n", event_fd); } } else { fprintf(stderr, "Got event from unknown fd %d, ptr %p, u32 %d, u64 %lu", event_fd, events[i].data.ptr, events[i].data.u32, events[i].data.u64); fprintf(stderr, " with events %d\n", events[i].events); return; } } } } #else void run(void) { XEvent ev; /* main event loop */ XSync(dpy, False); while (running && !XNextEvent(dpy, &ev)) if (handler[ev.type]) handler[ev.type](&ev); /* call handler */ } #endif // IPC_PATCH void scan(void) { unsigned int i, num; Window d1, d2, *wins = NULL; XWindowAttributes wa; if (XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { for (i = 0; i < num; i++) { if (!XGetWindowAttributes(dpy, wins[i], &wa) || wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) continue; if (wa.map_state == IsViewable || getstate(wins[i]) == IconicState) manage(wins[i], &wa); } for (i = 0; i < num; i++) { /* now the transients */ if (!XGetWindowAttributes(dpy, wins[i], &wa)) continue; if (XGetTransientForHint(dpy, wins[i], &d1) && (wa.map_state == IsViewable || getstate(wins[i]) == IconicState)) manage(wins[i], &wa); } XFree(wins); } } void sendmon(Client *c, Monitor *m) { #if EXRESIZE_PATCH Monitor *oldm = selmon; #endif // EXRESIZE_PATCH if (c->mon == m) return; #if SENDMON_KEEPFOCUS_PATCH && !EXRESIZE_PATCH int hadfocus = (c == selmon->sel); #endif // SENDMON_KEEPFOCUS_PATCH unfocus(c, 1, NULL); detach(c); detachstack(c); #if SENDMON_KEEPFOCUS_PATCH && !EXRESIZE_PATCH arrange(c->mon); #endif // SENDMON_KEEPFOCUS_PATCH c->mon = m; #if SCRATCHPADS_PATCH if (!(c->tags & SPTAGMASK)) #endif // SCRATCHPADS_PATCH #if EMPTYVIEW_PATCH c->tags = (m->tagset[m->seltags] ? m->tagset[m->seltags] : 1); #else c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ #endif // EMPTYVIEW_PATCH #if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH attachx(c); #else attach(c); #endif attachstack(c); #if EXRESIZE_PATCH if (oldm != m) arrange(oldm); arrange(m); focus(c); restack(m); #elif SENDMON_KEEPFOCUS_PATCH arrange(m); if (hadfocus) { focus(c); restack(m); } else focus(NULL); #else focus(NULL); arrange(NULL); #endif // EXRESIZE_PATCH / SENDMON_KEEPFOCUS_PATCH #if SWITCHTAG_PATCH if (c->switchtag) c->switchtag = 0; #endif // SWITCHTAG_PATCH } void setclientstate(Client *c, long state) { long data[] = { state, None }; XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, PropModeReplace, (unsigned char *)data, 2); } int #if BAR_SYSTRAY_PATCH sendevent(Window w, Atom proto, int mask, long d0, long d1, long d2, long d3, long d4) #else sendevent(Client *c, Atom proto) #endif // BAR_SYSTRAY_PATCH { int n; Atom *protocols; #if BAR_SYSTRAY_PATCH Atom mt; #endif // BAR_SYSTRAY_PATCH int exists = 0; XEvent ev; #if BAR_SYSTRAY_PATCH if (proto == wmatom[WMTakeFocus] || proto == wmatom[WMDelete]) { mt = wmatom[WMProtocols]; if (XGetWMProtocols(dpy, w, &protocols, &n)) { while (!exists && n--) exists = protocols[n] == proto; XFree(protocols); } } else { exists = True; mt = proto; } #else if (XGetWMProtocols(dpy, c->win, &protocols, &n)) { while (!exists && n--) exists = protocols[n] == proto; XFree(protocols); } #endif // BAR_SYSTRAY_PATCH if (exists) { #if BAR_SYSTRAY_PATCH ev.type = ClientMessage; ev.xclient.window = w; ev.xclient.message_type = mt; ev.xclient.format = 32; ev.xclient.data.l[0] = d0; ev.xclient.data.l[1] = d1; ev.xclient.data.l[2] = d2; ev.xclient.data.l[3] = d3; ev.xclient.data.l[4] = d4; XSendEvent(dpy, w, False, mask, &ev); #else ev.type = ClientMessage; ev.xclient.window = c->win; ev.xclient.message_type = wmatom[WMProtocols]; ev.xclient.format = 32; ev.xclient.data.l[0] = proto; ev.xclient.data.l[1] = CurrentTime; XSendEvent(dpy, c->win, False, NoEventMask, &ev); #endif // BAR_SYSTRAY_PATCH } return exists; } void setfocus(Client *c) { if (!c->neverfocus) { XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &(c->win), 1); } #if BAR_SYSTRAY_PATCH sendevent(c->win, wmatom[WMTakeFocus], NoEventMask, wmatom[WMTakeFocus], CurrentTime, 0, 0, 0); #else sendevent(c, wmatom[WMTakeFocus]); #endif // BAR_SYSTRAY_PATCH } void setfullscreen(Client *c, int fullscreen) { if (fullscreen && !c->isfullscreen) { XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); c->isfullscreen = 1; #if !FAKEFULLSCREEN_PATCH c->oldbw = c->bw; #if FAKEFULLSCREEN_CLIENT_PATCH if (c->fakefullscreen == 1) return; #endif // FAKEFULLSCREEN_CLIENT_PATCH c->oldstate = c->isfloating; c->bw = 0; c->isfloating = 1; resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); XRaiseWindow(dpy, c->win); #endif // !FAKEFULLSCREEN_PATCH } else if (!fullscreen && c->isfullscreen){ XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (unsigned char*)0, 0); c->isfullscreen = 0; #if !FAKEFULLSCREEN_PATCH c->bw = c->oldbw; #if FAKEFULLSCREEN_CLIENT_PATCH if (c->fakefullscreen == 1) return; if (c->fakefullscreen == 2) c->fakefullscreen = 1; #endif // FAKEFULLSCREEN_CLIENT_PATCH c->isfloating = c->oldstate; c->x = c->oldx; c->y = c->oldy; c->w = c->oldw; c->h = c->oldh; resizeclient(c, c->x, c->y, c->w, c->h); arrange(c->mon); #endif // !FAKEFULLSCREEN_PATCH } } void setlayout(const Arg *arg) { if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) { #if PERTAG_PATCH selmon->pertag->sellts[selmon->pertag->curtag] ^= 1; selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; #else selmon->sellt ^= 1; #endif // PERTAG_PATCH #if EXRESIZE_PATCH if (!selmon->lt[selmon->sellt]->arrange) { for (Client *c = selmon->clients ; c ; c = c->next) { if (!c->isfloating) { /*restore last known float dimensions*/ resize(c, selmon->mx + c->sfx, selmon->my + c->sfy, c->sfw, c->sfh, False); } } } #endif // EXRESIZE_PATCH } if (arg && arg->v) #if PERTAG_PATCH selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; #else selmon->lt[selmon->sellt] = (Layout *)arg->v; #endif // PERTAG_PATCH #if FLEXTILE_DELUXE_LAYOUT if (selmon->lt[selmon->sellt]->preset.nmaster && selmon->lt[selmon->sellt]->preset.nmaster != -1) selmon->nmaster = selmon->lt[selmon->sellt]->preset.nmaster; if (selmon->lt[selmon->sellt]->preset.nstack && selmon->lt[selmon->sellt]->preset.nstack != -1) selmon->nstack = selmon->lt[selmon->sellt]->preset.nstack; selmon->ltaxis[LAYOUT] = selmon->lt[selmon->sellt]->preset.layout; selmon->ltaxis[MASTER] = selmon->lt[selmon->sellt]->preset.masteraxis; selmon->ltaxis[STACK] = selmon->lt[selmon->sellt]->preset.stack1axis; selmon->ltaxis[STACK2] = selmon->lt[selmon->sellt]->preset.stack2axis; #if PERTAG_PATCH selmon->pertag->ltaxis[selmon->pertag->curtag][LAYOUT] = selmon->ltaxis[LAYOUT]; selmon->pertag->ltaxis[selmon->pertag->curtag][MASTER] = selmon->ltaxis[MASTER]; selmon->pertag->ltaxis[selmon->pertag->curtag][STACK] = selmon->ltaxis[STACK]; selmon->pertag->ltaxis[selmon->pertag->curtag][STACK2] = selmon->ltaxis[STACK2]; #endif // PERTAG_PATCH #endif // FLEXTILE_DELUXE_LAYOUT strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); if (selmon->sel) arrange(selmon); else drawbar(selmon); } /* arg > 1.0 will set mfact absolutely */ void setmfact(const Arg *arg) { float f; if (!arg || !selmon->lt[selmon->sellt]->arrange) return; f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; if (f < 0.05 || f > 0.95) return; #if PERTAG_PATCH selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f; #else selmon->mfact = f; #endif // PERTAG_PATCH arrange(selmon); } void setup(void) { int i; XSetWindowAttributes wa; Atom utf8string; /* clean up any zombies immediately */ sigchld(0); #if RESTARTSIG_PATCH signal(SIGHUP, sighup); signal(SIGTERM, sigterm); #endif // RESTARTSIG_PATCH /* init screen */ screen = DefaultScreen(dpy); sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); #if BAR_ALPHA_PATCH xinitvisual(); drw = drw_create(dpy, screen, root, sw, sh, visual, depth, cmap); #else drw = drw_create(dpy, screen, root, sw, sh); #endif // BAR_ALPHA_PATCH #if BAR_PANGO_PATCH if (!drw_font_create(drw, font)) #else if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) #endif // BAR_PANGO_PATCH die("no fonts could be loaded."); #if BAR_STATUSPADDING_PATCH lrpad = drw->fonts->h + horizpadbar; bh = drw->fonts->h + vertpadbar; #else lrpad = drw->fonts->h; #if BAR_HEIGHT_PATCH bh = bar_height ? bar_height : drw->fonts->h + 2; #else bh = drw->fonts->h + 2; #endif // BAR_HEIGHT_PATCH #endif // BAR_STATUSPADDING_PATCH updategeom(); /* init atoms */ utf8string = XInternAtom(dpy, "UTF8_STRING", False); wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False); #if WINDOWROLERULE_PATCH wmatom[WMWindowRole] = XInternAtom(dpy, "WM_WINDOW_ROLE", False); #endif // WINDOWROLERULE_PATCH netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); #if BAR_SYSTRAY_PATCH netatom[NetSystemTray] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_S0", False); netatom[NetSystemTrayOP] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_OPCODE", False); netatom[NetSystemTrayOrientation] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION", False); netatom[NetSystemTrayOrientationHorz] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_ORIENTATION_HORZ", False); netatom[NetSystemTrayVisual] = XInternAtom(dpy, "_NET_SYSTEM_TRAY_VISUAL", False); netatom[NetWMWindowTypeDock] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); xatom[Manager] = XInternAtom(dpy, "MANAGER", False); xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False); xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False); #endif // BAR_SYSTRAY_PATCH #if BAR_EWMHTAGS_PATCH netatom[NetDesktopViewport] = XInternAtom(dpy, "_NET_DESKTOP_VIEWPORT", False); netatom[NetNumberOfDesktops] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False); netatom[NetCurrentDesktop] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False); netatom[NetDesktopNames] = XInternAtom(dpy, "_NET_DESKTOP_NAMES", False); #endif // BAR_EWMHTAGS_PATCH netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); #if DECORATION_HINTS_PATCH motifatom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False); #endif // DECORATION_HINTS_PATCH /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurResize] = drw_cur_create(drw, XC_sizing); #if RESIZEPOINT_PATCH || RESIZECORNERS_PATCH cursor[CurResizeBR] = drw_cur_create(drw, XC_bottom_right_corner); cursor[CurResizeBL] = drw_cur_create(drw, XC_bottom_left_corner); cursor[CurResizeTR] = drw_cur_create(drw, XC_top_right_corner); cursor[CurResizeTL] = drw_cur_create(drw, XC_top_left_corner); #endif // RESIZEPOINT_PATCH | RESIZECORNERS_PATCH #if DRAGMFACT_PATCH cursor[CurResizeHorzArrow] = drw_cur_create(drw, XC_sb_h_double_arrow); cursor[CurResizeVertArrow] = drw_cur_create(drw, XC_sb_v_double_arrow); #endif // DRAGMFACT_PATCH #if DRAGCFACT_PATCH cursor[CurIronCross] = drw_cur_create(drw, XC_iron_cross); #endif // DRAGCFACT_PATCH cursor[CurMove] = drw_cur_create(drw, XC_fleur); /* init appearance */ #if BAR_VTCOLORS_PATCH get_vt_colors(); if (get_luminance(colors[SchemeTagsNorm][ColBg]) > 50) { strcpy(colors[SchemeTitleNorm][ColBg], title_bg_light); strcpy(colors[SchemeTitleSel][ColBg], title_bg_light); } else { strcpy(colors[SchemeTitleNorm][ColBg], title_bg_dark); strcpy(colors[SchemeTitleSel][ColBg], title_bg_dark); } #endif // BAR_VTCOLORS_PATCH #if BAR_STATUS2D_PATCH && !BAR_STATUSCOLORS_PATCH scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); #if BAR_ALPHA_PATCH scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], alphas[0], ColCount); #else scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], ColCount); #endif // BAR_ALPHA_PATCH #else scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); #endif // BAR_STATUS2D_PATCH for (i = 0; i < LENGTH(colors); i++) #if BAR_ALPHA_PATCH scheme[i] = drw_scm_create(drw, colors[i], alphas[i], ColCount); #else scheme[i] = drw_scm_create(drw, colors[i], ColCount); #endif // BAR_ALPHA_PATCH #if BAR_POWERLINE_STATUS_PATCH statusscheme = ecalloc(LENGTH(statuscolors), sizeof(Clr *)); for (i = 0; i < LENGTH(statuscolors); i++) #if BAR_ALPHA_PATCH statusscheme[i] = drw_scm_create(drw, statuscolors[i], alphas[0], ColCount); #else statusscheme[i] = drw_scm_create(drw, statuscolors[i], ColCount); #endif // BAR_ALPHA_PATCH #endif // BAR_POWERLINE_STATUS_PATCH updatebars(); updatestatus(); /* supporting window for NetWMCheck */ wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &wmcheckwin, 1); XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8, PropModeReplace, (unsigned char *) "dwm", 3); XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char *) &wmcheckwin, 1); /* EWMH support per view */ XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); #if BAR_EWMHTAGS_PATCH setnumdesktops(); setcurrentdesktop(); setdesktopnames(); setviewport(); #endif // BAR_EWMHTAGS_PATCH XDeleteProperty(dpy, root, netatom[NetClientList]); /* select events */ wa.cursor = cursor[CurNormal]->cursor; wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask |ButtonPressMask|PointerMotionMask|EnterWindowMask |LeaveWindowMask|StructureNotifyMask|PropertyChangeMask; XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); grabkeys(); focus(NULL); #if IPC_PATCH setupepoll(); #endif // IPC_PATCH } void seturgent(Client *c, int urg) { XWMHints *wmh; c->isurgent = urg; if (!(wmh = XGetWMHints(dpy, c->win))) return; wmh->flags = urg ? (wmh->flags | XUrgencyHint) : (wmh->flags & ~XUrgencyHint); XSetWMHints(dpy, c->win, wmh); XFree(wmh); } void showhide(Client *c) { if (!c) return; if (ISVISIBLE(c)) { #if SCRATCHPADS_PATCH && SCRATCHPADS_KEEP_POSITION_AND_SIZE_PATCH if ( (c->tags & SPTAGMASK) && c->isfloating && ( c->x < c->mon->mx || c->x > c->mon->mx + c->mon->mw || c->y < c->mon->my || c->y > c->mon->my + c->mon->mh ) ) { c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); } #elif SCRATCHPADS_PATCH if ((c->tags & SPTAGMASK) && c->isfloating) { c->x = c->mon->wx + (c->mon->ww / 2 - WIDTH(c) / 2); c->y = c->mon->wy + (c->mon->wh / 2 - HEIGHT(c) / 2); } #endif // SCRATCHPADS_KEEP_POSITION_AND_SIZE_PATCH | SCRATCHPADS_PATCH /* show clients top down */ #if SAVEFLOATS_PATCH || EXRESIZE_PATCH if (!c->mon->lt[c->mon->sellt]->arrange && c->sfx != -9999 && !c->isfullscreen) { XMoveWindow(dpy, c->win, c->sfx, c->sfy); resize(c, c->sfx, c->sfy, c->sfw, c->sfh, 0); showhide(c->snext); return; } #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH #if AUTORESIZE_PATCH if (c->needresize) { c->needresize = 0; XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else { XMoveWindow(dpy, c->win, c->x, c->y); } #else XMoveWindow(dpy, c->win, c->x, c->y); #endif // AUTORESIZE_PATCH if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) #if !FAKEFULLSCREEN_PATCH && !c->isfullscreen #endif // !FAKEFULLSCREEN_PATCH ) resize(c, c->x, c->y, c->w, c->h, 0); showhide(c->snext); } else { /* hide clients bottom up */ showhide(c->snext); XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); } } void sigchld(int unused) { #if COOL_AUTOSTART_PATCH pid_t pid; #endif // COOL_AUTOSTART_PATCH if (signal(SIGCHLD, sigchld) == SIG_ERR) die("can't install SIGCHLD handler:"); #if COOL_AUTOSTART_PATCH while (0 < (pid = waitpid(-1, NULL, WNOHANG))) { pid_t *p, *lim; if (!(p = autostart_pids)) continue; lim = &p[autostart_len]; for (; p < lim; p++) { if (*p == pid) { *p = -1; break; } } } #else while (0 < waitpid(-1, NULL, WNOHANG)); #endif // COOL_AUTOSTART_PATCH } void spawn(const Arg *arg) { #if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH char *cmd = NULL; #endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH #if !NODMENU_PATCH if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; #endif // NODMENU_PATCH #if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH #if !NODMENU_PATCH else if (arg->v == statuscmd) #else if (arg->v == statuscmd) #endif // NODMENU_PATCH { int len = strlen(statuscmds[statuscmdn]) + 1; if (!(cmd = malloc(sizeof(char)*len + sizeof(statusexport)))) die("malloc:"); strcpy(cmd, statusexport); strcat(cmd, statuscmds[statuscmdn]); cmd[LENGTH(statusexport)-3] = '0' + lastbutton; statuscmd[2] = cmd; } #endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); #if SPAWNCMD_PATCH if (selmon->sel) { const char* const home = getenv("HOME"); assert(home && strchr(home, '/')); const size_t homelen = strlen(home); char *cwd, *pathbuf = NULL; struct stat statbuf; cwd = strtok(selmon->sel->name, SPAWN_CWD_DELIM); /* NOTE: strtok() alters selmon->sel->name in-place, * but that does not matter because we are going to * exec() below anyway; nothing else will use it */ while (cwd) { if (*cwd == '~') { /* replace ~ with $HOME */ if (!(pathbuf = malloc(homelen + strlen(cwd)))) /* ~ counts for NULL term */ die("fatal: could not malloc() %u bytes\n", homelen + strlen(cwd)); strcpy(strcpy(pathbuf, home) + homelen, cwd + 1); cwd = pathbuf; } if (strchr(cwd, '/') && !stat(cwd, &statbuf)) { if (!S_ISDIR(statbuf.st_mode)) cwd = dirname(cwd); if (!chdir(cwd)) break; } cwd = strtok(NULL, SPAWN_CWD_DELIM); } free(pathbuf); } #endif // SPAWNCMD_PATCH setsid(); execvp(((char **)arg->v)[0], (char **)arg->v); fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[0]); perror(" failed"); exit(EXIT_SUCCESS); } #if BAR_STATUSCMD_PATCH && !BAR_DWMBLOCKS_PATCH free(cmd); #endif // BAR_STATUSCMD_PATCH | BAR_DWMBLOCKS_PATCH } void tag(const Arg *arg) { #if SWAPFOCUS_PATCH && PERTAG_PATCH unsigned int tagmask, tagindex; #endif // SWAPFOCUS_PATCH if (selmon->sel && arg->ui & TAGMASK) { selmon->sel->tags = arg->ui & TAGMASK; #if SWITCHTAG_PATCH if (selmon->sel->switchtag) selmon->sel->switchtag = 0; #endif // SWITCHTAG_PATCH focus(NULL); #if SWAPFOCUS_PATCH && PERTAG_PATCH selmon->pertag->prevclient[selmon->pertag->curtag] = NULL; for (tagmask = arg->ui & TAGMASK, tagindex = 1; tagmask!=0; tagmask >>= 1, tagindex++) if (tagmask & 1) selmon->pertag->prevclient[tagindex] = NULL; #endif // SWAPFOCUS_PATCH arrange(selmon); #if VIEWONTAG_PATCH if ((arg->ui & TAGMASK) != selmon->tagset[selmon->seltags]) view(arg); #endif // VIEWONTAG_PATCH } } void tagmon(const Arg *arg) { #if TAGMONFIXFS_PATCH Client *c = selmon->sel; if (!c || !mons->next) return; if (c->isfullscreen) { c->isfullscreen = 0; sendmon(c, dirtomon(arg->i)); c->isfullscreen = 1; #if !FAKEFULLSCREEN_PATCH && FAKEFULLSCREEN_CLIENT_PATCH if (c->fakefullscreen != 1) { resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); XRaiseWindow(dpy, c->win); } #elif !FAKEFULLSCREEN_PATCH resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); XRaiseWindow(dpy, c->win); #endif // FAKEFULLSCREEN_CLIENT_PATCH } else sendmon(c, dirtomon(arg->i)); #else if (!selmon->sel || !mons->next) return; sendmon(selmon->sel, dirtomon(arg->i)); #endif // TAGMONFIXFS_PATCH } void togglebar(const Arg *arg) { Bar *bar; #if BAR_HOLDBAR_PATCH && PERTAG_PATCH && PERTAGBAR_PATCH selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = (selmon->showbar == 2 ? 1 : !selmon->showbar); #elif BAR_HOLDBAR_PATCH selmon->showbar = (selmon->showbar == 2 ? 1 : !selmon->showbar); #elif PERTAG_PATCH && PERTAGBAR_PATCH selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar; #else selmon->showbar = !selmon->showbar; #endif // BAR_HOLDBAR_PATCH | PERTAG_PATCH updatebarpos(selmon); for (bar = selmon->bar; bar; bar = bar->next) XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); arrange(selmon); } void togglefloating(const Arg *arg) { Client *c = selmon->sel; if (arg && arg->v) c = (Client*)arg->v; if (!c) return; #if !FAKEFULLSCREEN_PATCH #if FAKEFULLSCREEN_CLIENT_PATCH if (c->isfullscreen && c->fakefullscreen != 1) /* no support for fullscreen windows */ return; #else if (c->isfullscreen) /* no support for fullscreen windows */ return; #endif // FAKEFULLSCREEN_CLIENT_PATCH #endif // !FAKEFULLSCREEN_PATCH c->isfloating = !c->isfloating || c->isfixed; #if !BAR_FLEXWINTITLE_PATCH if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); #endif // BAR_FLEXWINTITLE_PATCH if (c->isfloating) { #if SAVEFLOATS_PATCH || EXRESIZE_PATCH if (c->sfx != -9999) { /* restore last known float dimensions */ resize(c, c->sfx, c->sfy, c->sfw, c->sfh, 0); arrange(c->mon); return; } #endif // SAVEFLOATS_PATCH // EXRESIZE_PATCH resize(c, c->x, c->y, c->w, c->h, 0); #if SAVEFLOATS_PATCH || EXRESIZE_PATCH } else { /* save last known float dimensions */ c->sfx = c->x; c->sfy = c->y; c->sfw = c->w; c->sfh = c->h; #endif // SAVEFLOATS_PATCH / EXRESIZE_PATCH } arrange(c->mon); } void toggletag(const Arg *arg) { unsigned int newtags; #if SWAPFOCUS_PATCH && PERTAG_PATCH unsigned int tagmask, tagindex; #endif // SWAPFOCUS_PATCH if (!selmon->sel) return; newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); if (newtags) { selmon->sel->tags = newtags; focus(NULL); #if SWAPFOCUS_PATCH && PERTAG_PATCH for (tagmask = arg->ui & TAGMASK, tagindex = 1; tagmask!=0; tagmask >>= 1, tagindex++) if (tagmask & 1) selmon->pertag->prevclient[tagindex] = NULL; #endif // SWAPFOCUS_PATCH arrange(selmon); } #if BAR_EWMHTAGS_PATCH updatecurrentdesktop(); #endif // BAR_EWMHTAGS_PATCH } void toggleview(const Arg *arg) { unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); #if PERTAG_PATCH int i; #endif // PERTAG_PATCH #if TAGINTOSTACK_ALLMASTER_PATCH Client *const selected = selmon->sel; // clients in the master area should be the same after we add a new tag Client **const masters = calloc(selmon->nmaster, sizeof(Client *)); if (!masters) { die("fatal: could not calloc() %u bytes \n", selmon->nmaster * sizeof(Client *)); } // collect (from last to first) references to all clients in the master area Client *c; size_t j; for (c = nexttiled(selmon->clients), j = 0; c && j < selmon->nmaster; c = nexttiled(c->next), ++j) masters[selmon->nmaster - (j + 1)] = c; // put the master clients at the front of the list // > go from the 'last' master to the 'first' for (j = 0; j < selmon->nmaster; ++j) if (masters[j]) pop(masters[j]); free(masters); // we also want to be sure not to mutate the focus focus(selected); #elif TAGINTOSTACK_ONEMASTER_PATCH // the first visible client should be the same after we add a new tag // we also want to be sure not to mutate the focus Client *const c = nexttiled(selmon->clients); if (c) { Client * const selected = selmon->sel; pop(c); focus(selected); } #endif // TAGINTOSTACK_ALLMASTER_PATCH / TAGINTOSTACK_ONEMASTER_PATCH #if !EMPTYVIEW_PATCH if (newtagset) { #endif // EMPTYVIEW_PATCH selmon->tagset[selmon->seltags] = newtagset; #if PERTAG_PATCH if (newtagset == ~0) { selmon->pertag->prevtag = selmon->pertag->curtag; selmon->pertag->curtag = 0; } /* test if the user did not select the same tag */ if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) { selmon->pertag->prevtag = selmon->pertag->curtag; for (i=0; !(newtagset & 1 << i); i++) ; selmon->pertag->curtag = i + 1; } /* apply settings for this view */ selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; #if PERTAGBAR_PATCH if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) togglebar(NULL); #endif // PERTAGBAR_PATCH #endif // PERTAG_PATCH focus(NULL); arrange(selmon); #if !EMPTYVIEW_PATCH } #endif // EMPTYVIEW_PATCH #if BAR_EWMHTAGS_PATCH updatecurrentdesktop(); #endif // BAR_EWMHTAGS_PATCH } void unfocus(Client *c, int setfocus, Client *nextfocus) { if (!c) return; #if SWAPFOCUS_PATCH && PERTAG_PATCH selmon->pertag->prevclient[selmon->pertag->curtag] = c; #endif // SWAPFOCUS_PATCH #if LOSEFULLSCREEN_PATCH if (c->isfullscreen && ISVISIBLE(c) && c->mon == selmon && nextfocus && !nextfocus->isfloating) { #if !FAKEFULLSCREEN_PATCH && FAKEFULLSCREEN_CLIENT_PATCH if (!c->fakefullscreen) setfullscreen(c, 0); else if (c->fakefullscreen == 2) { c->fakefullscreen = 0; togglefakefullscreen(NULL); } #else setfullscreen(c, 0); #endif // FAKEFULLSCREEN_CLIENT_PATCH } #endif // LOSEFULLSCREEN_PATCH grabbuttons(c, 0); #if !BAR_FLEXWINTITLE_PATCH if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); #endif // BAR_FLEXWINTITLE_PATCH if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } } void unmanage(Client *c, int destroyed) { Monitor *m = c->mon; #if SWITCHTAG_PATCH unsigned int switchtag = c->switchtag; #endif // SWITCHTAG_PATCH XWindowChanges wc; #if SWALLOW_PATCH if (c->swallowing) { unswallow(c); return; } Client *s = swallowingclient(c->win); if (s) { free(s->swallowing); s->swallowing = NULL; arrange(m); focus(NULL); return; } #endif // SWALLOW_PATCH detach(c); detachstack(c); if (!destroyed) { wc.border_width = c->oldbw; XGrabServer(dpy); /* avoid race conditions */ XSetErrorHandler(xerrordummy); XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ XUngrabButton(dpy, AnyButton, AnyModifier, c->win); setclientstate(c, WithdrawnState); XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); } free(c); #if SWALLOW_PATCH if (s) return; #endif // SWALLOW_PATCH focus(NULL); updateclientlist(); arrange(m); #if SWITCHTAG_PATCH if (switchtag && ((switchtag & TAGMASK) != selmon->tagset[selmon->seltags])) view(&((Arg) { .ui = switchtag })); #endif // SWITCHTAG_PATCH } void unmapnotify(XEvent *e) { Client *c; XUnmapEvent *ev = &e->xunmap; if ((c = wintoclient(ev->window))) { if (ev->send_event) setclientstate(c, WithdrawnState); else unmanage(c, 0); #if BAR_SYSTRAY_PATCH } else if (showsystray && (c = wintosystrayicon(ev->window))) { /* KLUDGE! sometimes icons occasionally unmap their windows, but do * _not_ destroy them. We map those windows back */ XMapRaised(dpy, c->win); removesystrayicon(c); drawbarwin(systray->bar); #endif // BAR_SYSTRAY_PATCH } } void updatebars(void) { Bar *bar; Monitor *m; XSetWindowAttributes wa = { .override_redirect = True, #if BAR_ALPHA_PATCH .background_pixel = 0, .border_pixel = 0, .colormap = cmap, #else .background_pixmap = ParentRelative, #endif // BAR_ALPHA_PATCH .event_mask = ButtonPressMask|ExposureMask }; XClassHint ch = {"dwm", "dwm"}; for (m = mons; m; m = m->next) { for (bar = m->bar; bar; bar = bar->next) { if (!bar->win) { #if BAR_ALPHA_PATCH bar->win = XCreateWindow(dpy, root, bar->bx, bar->by, bar->bw, bar->bh, 0, depth, InputOutput, visual, CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa); #else bar->win = XCreateWindow(dpy, root, bar->bx, bar->by, bar->bw, bar->bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); #endif // BAR_ALPHA_PATCH XDefineCursor(dpy, bar->win, cursor[CurNormal]->cursor); XMapRaised(dpy, bar->win); XSetClassHint(dpy, bar->win, &ch); } } } } void updatebarpos(Monitor *m) { m->wx = m->mx; m->wy = m->my; m->ww = m->mw; m->wh = m->mh; Bar *bar; #if BAR_PADDING_PATCH int y_pad = vertpad; int x_pad = sidepad; #else int y_pad = 0; int x_pad = 0; #endif // BAR_PADDING_PATCH #if INSETS_PATCH // Custom insets Inset inset = m->inset; m->wx += inset.x; m->wy += inset.y; m->ww -= inset.w + inset.x; m->wh -= inset.h + inset.y; #endif // INSETS_PATCH for (bar = m->bar; bar; bar = bar->next) { bar->bx = m->wx + x_pad; bar->bw = m->ww - 2 * x_pad; bar->bh = bh + bar->borderpx * 2; } for (bar = m->bar; bar; bar = bar->next) if (!m->showbar || !bar->showbar) bar->by = -bh - bar->borderpx * 2 - y_pad; if (!m->showbar) return; for (bar = m->bar; bar; bar = bar->next) { if (!bar->showbar) continue; if (bar->topbar) m->wy = m->wy + bh + bar->borderpx * 2 + y_pad; m->wh -= y_pad + bh + bar->borderpx * 2; } for (bar = m->bar; bar; bar = bar->next) bar->by = (bar->topbar ? m->wy - bh - bar->borderpx * 2 : m->wy + m->wh); } void updateclientlist() { Client *c; Monitor *m; XDeleteProperty(dpy, root, netatom[NetClientList]); for (m = mons; m; m = m->next) for (c = m->clients; c; c = c->next) XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char *) &(c->win), 1); } int updategeom(void) { int dirty = 0; #ifdef XINERAMA if (XineramaIsActive(dpy)) { int i, j, n, nn; Client *c; Monitor *m; XineramaScreenInfo *info = XineramaQueryScreens(dpy, &nn); XineramaScreenInfo *unique = NULL; for (n = 0, m = mons; m; m = m->next, n++); /* only consider unique geometries as separate screens */ unique = ecalloc(nn, sizeof(XineramaScreenInfo)); for (i = 0, j = 0; i < nn; i++) if (isuniquegeom(unique, j, &info[i])) memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); XFree(info); nn = j; #if SORTSCREENS_PATCH sortscreens(unique, nn); #endif // SORTSCREENS_PATCH if (n <= nn) { /* new monitors available */ for (i = 0; i < (nn - n); i++) { for (m = mons; m && m->next; m = m->next); if (m) m->next = createmon(); else mons = createmon(); } for (i = 0, m = mons; i < nn && m; m = m->next, i++) { if (i >= n || unique[i].x_org != m->mx || unique[i].y_org != m->my || unique[i].width != m->mw || unique[i].height != m->mh) { dirty = 1; m->num = i; m->mx = m->wx = unique[i].x_org; m->my = m->wy = unique[i].y_org; m->mw = m->ww = unique[i].width; m->mh = m->wh = unique[i].height; updatebarpos(m); } } } else { /* less monitors available nn < n */ for (i = nn; i < n; i++) { for (m = mons; m && m->next; m = m->next); while ((c = m->clients)) { dirty = 1; m->clients = c->next; detachstack(c); c->mon = mons; attach(c); attachstack(c); } if (m == selmon) selmon = mons; cleanupmon(m); } } for (i = 0, m = mons; m; m = m->next, i++) m->index = i; free(unique); } else #endif /* XINERAMA */ { /* default monitor setup */ if (!mons) mons = createmon(); if (mons->mw != sw || mons->mh != sh) { dirty = 1; mons->mw = mons->ww = sw; mons->mh = mons->wh = sh; updatebarpos(mons); } } if (dirty) { selmon = mons; selmon = wintomon(root); } return dirty; } void updatenumlockmask(void) { unsigned int i, j; XModifierKeymap *modmap; numlockmask = 0; modmap = XGetModifierMapping(dpy); for (i = 0; i < 8; i++) for (j = 0; j < modmap->max_keypermod; j++) if (modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) numlockmask = (1 << i); XFreeModifiermap(modmap); } void updatesizehints(Client *c) { long msize; XSizeHints size; if (!XGetWMNormalHints(dpy, c->win, &size, &msize)) /* size is uninitialized, ensure that size.flags aren't used */ #if SIZEHINTS_PATCH || SIZEHINTS_RULED_PATCH size.flags = 0; #else size.flags = PSize; #endif // SIZEHINTS_PATCH | SIZEHINTS_RULED_PATCH if (size.flags & PBaseSize) { c->basew = size.base_width; c->baseh = size.base_height; } else if (size.flags & PMinSize) { c->basew = size.min_width; c->baseh = size.min_height; } else c->basew = c->baseh = 0; if (size.flags & PResizeInc) { c->incw = size.width_inc; c->inch = size.height_inc; } else c->incw = c->inch = 0; if (size.flags & PMaxSize) { c->maxw = size.max_width; c->maxh = size.max_height; } else c->maxw = c->maxh = 0; if (size.flags & PMinSize) { c->minw = size.min_width; c->minh = size.min_height; } else if (size.flags & PBaseSize) { c->minw = size.base_width; c->minh = size.base_height; } else c->minw = c->minh = 0; if (size.flags & PAspect) { c->mina = (float)size.min_aspect.y / size.min_aspect.x; c->maxa = (float)size.max_aspect.x / size.max_aspect.y; } else c->maxa = c->mina = 0.0; #if SIZEHINTS_PATCH || SIZEHINTS_RULED_PATCH if (size.flags & PSize) { c->basew = size.base_width; c->baseh = size.base_height; c->isfloating = 1; } #if SIZEHINTS_RULED_PATCH checkfloatingrules(c); #endif // SIZEHINTS_RULED_PATCH #endif // SIZEHINTS_PATCH c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); } void updatestatus(void) { Monitor *m; #if BAR_EXTRASTATUS_PATCH if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) { strcpy(stext, "dwm-"VERSION); estext[0] = '\0'; } else { char *e = strchr(rawstext, statussep); if (e) { *e = '\0'; e++; #if BAR_STATUSCMD_PATCH strncpy(rawestext, e, sizeof(estext) - 1); copyvalidchars(estext, rawestext); #else strncpy(estext, e, sizeof(estext) - 1); #endif // BAR_STATUSCMD_PATCH } else { estext[0] = '\0'; } #if BAR_STATUSCMD_PATCH copyvalidchars(stext, rawstext); #else strncpy(stext, rawstext, sizeof(stext) - 1); #endif // BAR_STATUSCMD_PATCH } #elif BAR_STATUSCMD_PATCH if (!gettextprop(root, XA_WM_NAME, rawstext, sizeof(rawstext))) strcpy(stext, "dwm-"VERSION); else copyvalidchars(stext, rawstext); #else if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) strcpy(stext, "dwm-"VERSION); #endif // BAR_EXTRASTATUS_PATCH | BAR_STATUSCMD_PATCH for (m = mons; m; m = m->next) drawbar(m); } void updatetitle(Client *c) { #if IPC_PATCH char oldname[sizeof(c->name)]; strcpy(oldname, c->name); #endif // IPC_PATCH if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); if (c->name[0] == '\0') /* hack to mark broken clients */ strcpy(c->name, broken); #if IPC_PATCH for (Monitor *m = mons; m; m = m->next) { if (m->sel == c && strcmp(oldname, c->name) != 0) ipc_focused_title_change_event(m->num, c->win, oldname, c->name); } #endif // IPC_PATCH } void updatewmhints(Client *c) { XWMHints *wmh; if ((wmh = XGetWMHints(dpy, c->win))) { if (c == selmon->sel && wmh->flags & XUrgencyHint) { wmh->flags &= ~XUrgencyHint; XSetWMHints(dpy, c->win, wmh); } else c->isurgent = (wmh->flags & XUrgencyHint) ? 1 : 0; if (c->isurgent) { if (c->isfloating) XSetWindowBorder(dpy, c->win, scheme[SchemeUrg][ColFloat].pixel); else XSetWindowBorder(dpy, c->win, scheme[SchemeUrg][ColBorder].pixel); } if (wmh->flags & InputHint) c->neverfocus = !wmh->input; else c->neverfocus = 0; XFree(wmh); } } void view(const Arg *arg) { #if EMPTYVIEW_PATCH if (arg->ui && (arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) #else if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) #endif // EMPTYVIEW_PATCH { #if VIEW_SAME_TAG_GIVES_PREVIOUS_TAG_PATCH view(&((Arg) { .ui = 0 })); #endif // VIEW_SAME_TAG_GIVES_PREVIOUS_TAG_PATCH return; } selmon->seltags ^= 1; /* toggle sel tagset */ #if PERTAG_PATCH pertagview(arg); #if SWAPFOCUS_PATCH Client *unmodified = selmon->pertag->prevclient[selmon->pertag->curtag]; #endif // SWAPFOCUS_PATCH #else if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; #endif // PERTAG_PATCH focus(NULL); #if SWAPFOCUS_PATCH && PERTAG_PATCH selmon->pertag->prevclient[selmon->pertag->curtag] = unmodified; #endif // SWAPFOCUS_PATCH arrange(selmon); #if BAR_EWMHTAGS_PATCH updatecurrentdesktop(); #endif // BAR_EWMHTAGS_PATCH } Client * wintoclient(Window w) { Client *c; Monitor *m; for (m = mons; m; m = m->next) for (c = m->clients; c; c = c->next) if (c->win == w) return c; return NULL; } Monitor * wintomon(Window w) { int x, y; Client *c; Monitor *m; Bar *bar; if (w == root && getrootptr(&x, &y)) return recttomon(x, y, 1, 1); for (m = mons; m; m = m->next) for (bar = m->bar; bar; bar = bar->next) if (w == bar->win) return m; if ((c = wintoclient(w))) return c->mon; return selmon; } /* There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). Other types of errors call Xlibs * default error handler, which may call exit. */ int xerror(Display *dpy, XErrorEvent *ee) { if (ee->error_code == BadWindow || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) || (ee->request_code == X_GrabButton && ee->error_code == BadAccess) || (ee->request_code == X_GrabKey && ee->error_code == BadAccess) || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) return 0; fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", ee->request_code, ee->error_code); return xerrorxlib(dpy, ee); /* may call exit */ } int xerrordummy(Display *dpy, XErrorEvent *ee) { return 0; } /* Startup Error handler to check if another window manager * is already running. */ int xerrorstart(Display *dpy, XErrorEvent *ee) { die("dwm: another window manager is already running"); return -1; } void zoom(const Arg *arg) { Client *c = selmon->sel; if (arg && arg->v) c = (Client*)arg->v; if (!c) return; #if ZOOMSWAP_PATCH Client *at = NULL, *cold, *cprevious = NULL, *p; #endif // ZOOMSWAP_PATCH #if ZOOMFLOATING_PATCH if (c && c->isfloating) togglefloating(&((Arg) { .v = c })); #endif // ZOOMFLOATING_PATCH #if SWAPFOCUS_PATCH && PERTAG_PATCH c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->mon->clients); #endif // SWAPFOCUS_PATCH if (!c->mon->lt[c->mon->sellt]->arrange || (c && c->isfloating) #if ZOOMSWAP_PATCH || !c #endif // ZOOMSWAP_PATCH ) return; #if ZOOMSWAP_PATCH if (c == nexttiled(c->mon->clients)) { #if PERTAG_PATCH p = c->mon->pertag->prevzooms[c->mon->pertag->curtag]; #else p = prevzoom; #endif // PERTAG_PATCH at = findbefore(p); if (at) cprevious = nexttiled(at->next); if (!cprevious || cprevious != p) { #if PERTAG_PATCH c->mon->pertag->prevzooms[c->mon->pertag->curtag] = NULL; #else prevzoom = NULL; #endif // PERTAG_PATCH #if SWAPFOCUS_PATCH && PERTAG_PATCH if (!c || !(c = c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->next))) #else if (!c || !(c = nexttiled(c->next))) #endif // SWAPFOCUS_PATCH return; } else #if SWAPFOCUS_PATCH && PERTAG_PATCH c = c->mon->pertag->prevclient[c->mon->pertag->curtag] = cprevious; #else c = cprevious; #endif // SWAPFOCUS_PATCH } cold = nexttiled(c->mon->clients); if (c != cold && !at) at = findbefore(c); detach(c); attach(c); /* swap windows instead of pushing the previous one down */ if (c != cold && at) { #if PERTAG_PATCH c->mon->pertag->prevzooms[c->mon->pertag->curtag] = cold; #else prevzoom = cold; #endif // PERTAG_PATCH if (cold && at != cold) { detach(cold); cold->next = at->next; at->next = cold; } } focus(c); arrange(c->mon); #else if (c == nexttiled(c->mon->clients)) #if SWAPFOCUS_PATCH && PERTAG_PATCH if (!c || !(c = c->mon->pertag->prevclient[c->mon->pertag->curtag] = nexttiled(c->next))) #else if (!c || !(c = nexttiled(c->next))) #endif // SWAPFOCUS_PATCH return; pop(c); #endif // ZOOMSWAP_PATCH } int main(int argc, char *argv[]) { #if CMDCUSTOMIZE_PATCH for (int i=1;i<argc;i+=1) if (!strcmp("-v", argv[i])) die("dwm-"VERSION); else if (!strcmp("-h", argv[i]) || !strcmp("--help", argv[i])) die(help()); else if (!strcmp("-fn", argv[i])) /* font set */ #if BAR_PANGO_PATCH strcpy(font, argv[++i]); #else fonts[0] = argv[++i]; #endif // BAR_PANGO_PATCH #if !BAR_VTCOLORS_PATCH else if (!strcmp("-nb", argv[i])) /* normal background color */ colors[SchemeNorm][1] = argv[++i]; else if (!strcmp("-nf", argv[i])) /* normal foreground color */ colors[SchemeNorm][0] = argv[++i]; else if (!strcmp("-sb", argv[i])) /* selected background color */ colors[SchemeSel][1] = argv[++i]; else if (!strcmp("-sf", argv[i])) /* selected foreground color */ colors[SchemeSel][0] = argv[++i]; #endif // !BAR_VTCOLORS_PATCH #if NODMENU_PATCH else if (!strcmp("-df", argv[i])) /* dmenu font */ dmenucmd[2] = argv[++i]; else if (!strcmp("-dnb", argv[i])) /* dmenu normal background color */ dmenucmd[4] = argv[++i]; else if (!strcmp("-dnf", argv[i])) /* dmenu normal foreground color */ dmenucmd[6] = argv[++i]; else if (!strcmp("-dsb", argv[i])) /* dmenu selected background color */ dmenucmd[8] = argv[++i]; else if (!strcmp("-dsf", argv[i])) /* dmenu selected foreground color */ dmenucmd[10] = argv[++i]; #else else if (!strcmp("-df", argv[i])) /* dmenu font */ dmenucmd[4] = argv[++i]; else if (!strcmp("-dnb", argv[i])) /* dmenu normal background color */ dmenucmd[6] = argv[++i]; else if (!strcmp("-dnf", argv[i])) /* dmenu normal foreground color */ dmenucmd[8] = argv[++i]; else if (!strcmp("-dsb", argv[i])) /* dmenu selected background color */ dmenucmd[10] = argv[++i]; else if (!strcmp("-dsf", argv[i])) /* dmenu selected foreground color */ dmenucmd[12] = argv[++i]; #endif // NODMENU_PATCH else die(help()); #else if (argc == 2 && !strcmp("-v", argv[1])) die("dwm-"VERSION); else if (argc != 1 && strcmp("-s", argv[1])) die("usage: dwm [-v]"); #endif // CMDCUSTOMIZE_PATCH if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("warning: no locale support\n", stderr); if (!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display"); if (argc > 1 && !strcmp("-s", argv[1])) { XStoreName(dpy, RootWindow(dpy, DefaultScreen(dpy)), argv[2]); XCloseDisplay(dpy); return 0; } #if SWALLOW_PATCH if (!(xcon = XGetXCBConnection(dpy))) die("dwm: cannot get xcb connection\n"); #endif // SWALLOW_PATCH checkotherwm(); #if XRDB_PATCH && !BAR_VTCOLORS_PATCH XrmInitialize(); loadxrdb(); #endif // XRDB_PATCH && !BAR_VTCOLORS_PATCH #if COOL_AUTOSTART_PATCH autostart_exec(); #endif // COOL_AUTOSTART_PATCH setup(); #ifdef __OpenBSD__ if (pledge("stdio rpath proc exec", NULL) == -1) die("pledge"); #endif /* __OpenBSD__ */ scan(); #if AUTOSTART_PATCH runautostart(); #endif run(); #if RESTARTSIG_PATCH if (restart) execvp(argv[0], argv); #endif // RESTARTSIG_PATCH cleanup(); XCloseDisplay(dpy); return EXIT_SUCCESS; }
[ "chrisjoelgarvin@gmail.com" ]
chrisjoelgarvin@gmail.com
3a9f83c1c6f290d45371ff6598ad12a8a7635c4c
a2470cbf61e63ced335890144854ef9e4e21ca57
/Hazel/src/Hazel.h
c2505c673b324ab004652bbc1688de73a3b3d3e1
[]
no_license
TheFern2/Hazel-Tut
4b6f537432113230844362aebd14db84161dfbea
8ff6dde69e9115ae5f1e7eb6e8541db6fe7bbb7a
refs/heads/master
2022-05-31T16:19:46.043945
2020-04-30T13:01:17
2020-04-30T13:01:17
null
0
0
null
null
null
null
UTF-8
C
false
false
222
h
#pragma once // For use by Hazel applications #include "Hazel/Application.h" #include "Hazel/Log.h" // --- Entry Point ------------------------ #include "Hazel/EntryPoint.h" // ----------------------------------------
[ "ic3balandran@yahoo.com" ]
ic3balandran@yahoo.com
e850ab699d78f718dcd555922f75e08789b603e8
2c166a6ccbe23d625a5555b02c3600f8f9ab44ec
/kernel/libk/source/kstdlib/kstdlib.c
88afb9505f6a5572d5a50b94d07561e7671ff696
[]
no_license
StoicSquid/Operating-System
8ed574bf97ded5f35547fc1445e834f0b575cd8d
d3749587490209fb331a5ae708c1093e8c0450fc
refs/heads/main
2023-08-29T07:42:47.542246
2021-10-31T00:22:51
2021-10-31T00:22:51
null
0
0
null
null
null
null
UTF-8
C
false
false
370
c
#include <kstdlib.h> void *kmemset(char *__dest, char __src, size_t __size) { char *ret_block = __dest; while (__size--) { *__dest++ = __src; } return ret_block; } void *kmemcpy(char *__dest, char *__src, size_t __size) { char *ret_block = __dest; while (__size--) { *__dest++ = *__src++; } return ret_block; }
[ "nofilqasim@gmail.com" ]
nofilqasim@gmail.com
e62ac957ee4d2128ef16d515af64e4222b3db741
7a054280ee7a1e7d6ca60f697713bb9e72ff88d0
/ProgramasC/Secao08/secao08Exercicio03.c
731148f8433135d0616ea78d143592577b9ef8e9
[]
no_license
dieg0palma/AlgLogic
9849b1ed44381c6110a33a8966819cebadf7336a
a43c262ef6f2af866c61e41d2862456a64b88a04
refs/heads/master
2021-05-21T21:10:56.289579
2020-04-03T18:18:03
2020-04-03T18:18:03
252,802,726
0
0
null
null
null
null
ISO-8859-1
C
false
false
308
c
#include <stdio.h> int main() { int vetor[10]; for (int i = 0; i < 10; i++) { printf("Insira um número no vetor: "); fflush(stdout); scanf("%d", &vetor[i]); } for (int i = 0; i < 10; i++) { printf("O número %d está na posição %d do vetor. \n", vetor[i], i); } }
[ "noreply@github.com" ]
dieg0palma.noreply@github.com
acfe8bac3042523c8c337ae203ebf3ffc0dec55a
ca66dbbc31fb7a302ee6b97ffb4a6c987836805e
/Source/SBBase.h
00cc977f668db991636dde5f5f9aa0b7f1710cc0
[ "Apache-2.0" ]
permissive
prezi/SheenBidi
a44b35e32f62b3bd629f1499349b7fcca52b2c92
f7b367531f52b6aad4e729cd7e625daed3619a36
refs/heads/master
2023-04-13T20:07:54.786284
2021-03-14T03:32:38
2021-03-14T03:32:38
265,934,100
0
1
Apache-2.0
2023-04-07T09:25:31
2020-05-21T19:27:08
C
UTF-8
C
false
false
3,855
h
/* * Copyright (C) 2016-2019 Muhammad Tayyab Akram * * 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 _SB_INTERNAL_BASE_H #define _SB_INTERNAL_BASE_H #include <SBBase.h> #include <SBBidiType.h> #include <SBCodepoint.h> #include <SBConfig.h> #include <SBGeneralCategory.h> #include <SBScript.h> /** * A value that indicates an invalid unsigned index. */ #define SBInvalidIndex (SBUInteger)(-1) SB_INTERNAL void SBUIntegerNormalizeRange(SBUInteger actualLength, SBUInteger *rangeOffset, SBUInteger *rangeLength); SB_INTERNAL SBBoolean SBUIntegerVerifyRange(SBUInteger actualLength, SBUInteger rangeOffset, SBUInteger rangeLength); #define SBNumberGetMax(first, second) \ ( \ (first) > (second) \ ? (first) \ : (second) \ ) #define SBNumberLimitIncrement(number, limit) \ ( \ (number) < (limit) \ ? (number) + (1) \ : (limit) \ ) #define SBNumberLimitDecrement(number, limit) \ ( \ (number) > (limit) \ ? (number) - (1) \ : (limit) \ ) #define SBNumberRingAdd(number, count, capacity) \ (((number) + (count)) % (capacity)) #define SBNumberRingIncrement(number, capacity) \ SBNumberRingAdd(number, 1, capacity) #define SBNumberRingSubtract(number, count, capacity) \ (((number) + (capacity) - (count)) % (capacity)) #define SBNumberRingDecrement(number, capacity) \ SBNumberRingSubtract(number, 1, capacity) #define SBLevelAsNormalBidiType(level) \ ( \ ((level) & 1) \ ? SBBidiTypeR \ : SBBidiTypeL \ ) #define SBLevelAsOppositeBidiType(level) \ ( \ ((level) & 1) \ ? SBBidiTypeL \ : SBBidiTypeR \ ) #define SBBidiTypeIsEqual(t1, t2) ((t1) == (t2)) #define SBBidiTypeIsNumber(t) SBUInt8InRange(t, SBBidiTypeAN, SBBidiTypeEN) #define SBBidiTypeIsIsolate(t) SBUInt8InRange(t, SBBidiTypeLRI, SBBidiTypePDI) #define SBBidiTypeIsStrongOrNumber(t) (SBBidiTypeIsStrong(t) || SBBidiTypeIsNumber(t)) #define SBBidiTypeIsNumberSeparator(t) SBUInt8InRange(t, SBBidiTypeES, SBBidiTypeCS) #define SBBidiTypeIsIsolateInitiator(t) SBUInt8InRange(t, SBBidiTypeLRI, SBBidiTypeFSI) #define SBBidiTypeIsIsolateTerminator(t) SBBidiTypeIsEqual(t, SBBidiTypePDI) #define SBBidiTypeIsNeutralOrIsolate(t) SBUInt8InRange(t, SBBidiTypeWS, SBBidiTypePDI) #define SBCodepointMax 0x10FFFF #define SBCodepointInRange(v, s, e) SBUInt32InRange(v, s, e) #define SBCodepointIsSurrogate(c) SBCodepointInRange(c, 0xD800, 0xDFFF) #define SBCodepointIsValid(c) (!SBCodepointIsSurrogate(c) && (c) <= SBCodepointMax) #define SBScriptIsCommonOrInherited(s) ((s) <= SBScriptZYYY) #endif
[ "dear_tayyab@yahoo.com" ]
dear_tayyab@yahoo.com
f92391c19966ba72561552a34a3a2c2ad18498de
0acace81433043d274bbeb5628fc150cc0f2d072
/Sources/Emulator/src/mame/machine/ticket.c
46aacfafaac61778d2f3bf2b2cf35ef318bb3030
[]
no_license
SonnyJim/MAMEHub
b11780c6e022b47b0be97e4670c49b15a55ec052
aeaa71c5ebdcf33c06d56625810913a99d3a4a66
refs/heads/master
2020-12-03T03:36:28.729082
2014-07-11T13:04:23
2014-07-11T13:04:23
null
0
0
null
null
null
null
UTF-8
C
false
false
7,483
c
/*************************************************************************** ticket.c Generic ticket dispensing device. **************************************************************************** Copyright Aaron Giles 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. * Neither the name 'MAME' nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY AARON GILES ''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 AARON GILES 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 "emu.h" #include "machine/ticket.h" //************************************************************************** // DEBUGGING //************************************************************************** #define DEBUG_TICKET 0 #define LOG(x) do { if (DEBUG_TICKET) logerror x; } while (0) //************************************************************************** // GLOBAL VARIABLES //************************************************************************** // device type definition const device_type TICKET_DISPENSER = &device_creator<ticket_dispenser_device>; //************************************************************************** // LIVE DEVICE //************************************************************************** //------------------------------------------------- // ticket_dispenser_device - constructor //------------------------------------------------- ticket_dispenser_device::ticket_dispenser_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, TICKET_DISPENSER, "Ticket Dispenser", tag, owner, clock, "ticket_dispenser", __FILE__), m_motor_sense(TICKET_MOTOR_ACTIVE_LOW), m_status_sense(TICKET_STATUS_ACTIVE_LOW), m_period(attotime::from_msec(100)), m_active_bit(0x80), m_motoron(0), m_ticketdispensed(0), m_ticketnotdispensed(0), m_status(0), m_power(0), m_timer(NULL) { } //------------------------------------------------- // ~ticket_dispenser_device - destructor //------------------------------------------------- ticket_dispenser_device::~ticket_dispenser_device() { } //************************************************************************** // CONFIGURATION HELPERS //************************************************************************** //------------------------------------------------- // static_set_period - configure the clock period // for dispensing //------------------------------------------------- void ticket_dispenser_device::static_set_period(device_t &device, attotime period) { downcast<ticket_dispenser_device &>(device).m_period = period; } //------------------------------------------------- // static_set_senses - configure the senses of // the motor and status bits //------------------------------------------------- void ticket_dispenser_device::static_set_senses(device_t &device, UINT8 motor_sense, UINT8 status_sense) { ticket_dispenser_device &ticket = downcast<ticket_dispenser_device &>(device); ticket.m_motor_sense = motor_sense; ticket.m_status_sense = status_sense; } //************************************************************************** // READ/WRITE HANDLERS //************************************************************************** //------------------------------------------------- // read - read the status line via the active bit //------------------------------------------------- READ8_MEMBER( ticket_dispenser_device::read ) { LOG(("%s: Ticket Status Read = %02X\n", machine().describe_context(), m_status)); return m_status; } //------------------------------------------------- // line_r - read the status line as a proper line //------------------------------------------------- READ_LINE_MEMBER( ticket_dispenser_device::line_r ) { return m_status ? 1 : 0; } //------------------------------------------------- // write - write the control line via the active // bit //------------------------------------------------- WRITE8_MEMBER( ticket_dispenser_device::write ) { // On an activate signal, start dispensing! if ((data & m_active_bit) == m_motoron) { if (!m_power) { LOG(("%s: Ticket Power On\n", machine().describe_context())); m_timer->adjust(m_period); m_power = 1; m_status = m_ticketnotdispensed; } } else { if (m_power) { LOG(("%s: Ticket Power Off\n", machine().describe_context())); m_timer->adjust(attotime::never); set_led_status(machine(), 2,0); m_power = 0; } } } //************************************************************************** // DEVICE INTERFACE //************************************************************************** //------------------------------------------------- // device_start - handle device startup //------------------------------------------------- void ticket_dispenser_device::device_start() { m_active_bit = 0x80; m_motoron = (m_motor_sense == TICKET_MOTOR_ACTIVE_HIGH) ? m_active_bit : 0; m_ticketdispensed = (m_status_sense == TICKET_STATUS_ACTIVE_HIGH) ? m_active_bit : 0; m_ticketnotdispensed = m_ticketdispensed ^ m_active_bit; m_timer = timer_alloc(); save_item(NAME(m_status)); save_item(NAME(m_power)); } //------------------------------------------------- // device_reset - handle device startup //------------------------------------------------- void ticket_dispenser_device::device_reset() { m_status = m_ticketnotdispensed; m_power = 0x00; } //------------------------------------------------- // device_timer - handle timer callbacks //------------------------------------------------- void ticket_dispenser_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { // if we still have power, keep toggling ticket states if (m_power) { m_status ^= m_active_bit; LOG(("Ticket Status Changed to %02X\n", m_status)); m_timer->adjust(m_period); } // update LED status (fixme: should map to an output) set_led_status(machine(), 2, (m_status == m_ticketdispensed)); // if we just dispensed, increment global count if (m_status == m_ticketdispensed) { increment_dispensed_tickets(machine(), 1); LOG(("Ticket Dispensed\n")); } }
[ "jgmath2000@gmail.com" ]
jgmath2000@gmail.com
30a46e918c3b4cf7e45df14746277d4bb9b5a924
b546c383d6ac3163629b8bdaa42bab420c3bf4d0
/Edk/Foundation/Library/EdkIIGlueLib/Library/BasePeCoffLib/BasePeCoff.c
4c2c10a9b30e2cbd5e5239859c5e6f91bf1cdee3
[]
no_license
matsufan/efidevkit
0570d3efaa4182c524bfa441d65c01947b8540e2
84cbd5045793eb6b44db8e07587964003c97a0cb
refs/heads/master
2020-05-29T19:54:50.323153
2012-11-19T07:25:45
2012-11-19T07:25:45
null
0
0
null
null
null
null
UTF-8
C
false
false
47,980
c
/*++ Copyright (c) 2004 - 2006, Intel Corporation All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: EdkIIGlueDxeDriverEntryPoint.c Abstract: Pe/Coff loader --*/ #include "BasePeCoffLibInternals.h" /** Retrieves the magic value from the PE/COFF header. @param Hdr The buffer in which to return the PE32, PE32+, or TE header. @return EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC - Image is PE32 @return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC - Image is PE32+ **/ UINT16 PeCoffLoaderGetPeHeaderMagicValue ( IN EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr ) { // // NOTE: Some versions of Linux ELILO for Itanium have an incorrect magic value // in the PE/COFF Header. If the MachineType is Itanium(IA64) and the // Magic value in the OptionalHeader is EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC // then override the returned value to EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC // if (Hdr.Pe32->FileHeader.Machine == EFI_IMAGE_MACHINE_IA64 && Hdr.Pe32->OptionalHeader.Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { return EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; } // // Return the magic value from the PC/COFF Optional Header // return Hdr.Pe32->OptionalHeader.Magic; } /** Retrieves the PE or TE Header from a PE/COFF or TE image. @param ImageContext The context of the image being loaded. @param Hdr The buffer in which to return the PE32, PE32+, or TE header. @retval RETURN_SUCCESS The PE or TE Header is read. @retval Other The error status from reading the PE/COFF or TE image using the ImageRead function. **/ RETURN_STATUS GluePeCoffLoaderGetPeHeader ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr ) { RETURN_STATUS Status; EFI_IMAGE_DOS_HEADER DosHdr; UINTN Size; UINT16 Magic; // // Read the DOS image header to check for it's existance // Size = sizeof (EFI_IMAGE_DOS_HEADER); Status = ImageContext->ImageRead ( ImageContext->Handle, 0, &Size, &DosHdr ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } ImageContext->PeCoffHeaderOffset = 0; if (DosHdr.e_magic == EFI_IMAGE_DOS_SIGNATURE) { // // DOS image header is present, so read the PE header after the DOS image // header // ImageContext->PeCoffHeaderOffset = DosHdr.e_lfanew; } // // Read the PE/COFF Header. For PE32 (32-bit) this will read in too much // data, but that should not hurt anythine. Hdr.Pe32->OptionalHeader.Magic // determins if this is a PE32 or PE32+ image. The magic is in the same // location in both images. // Size = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION); Status = ImageContext->ImageRead ( ImageContext->Handle, ImageContext->PeCoffHeaderOffset, &Size, Hdr.Pe32 ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } // // Use Signature to figure out if we understand the image format // if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) { ImageContext->IsTeImage = TRUE; ImageContext->Machine = Hdr.Te->Machine; ImageContext->ImageType = (UINT16)(Hdr.Te->Subsystem); ImageContext->ImageSize = 0; ImageContext->SectionAlignment = 4096; ImageContext->SizeOfHeaders = sizeof (EFI_TE_IMAGE_HEADER) + (UINTN)Hdr.Te->BaseOfCode - (UINTN)Hdr.Te->StrippedSize; } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) { ImageContext->IsTeImage = FALSE; ImageContext->Machine = Hdr.Pe32->FileHeader.Machine; Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // ImageContext->ImageType = Hdr.Pe32->OptionalHeader.Subsystem; ImageContext->ImageSize = (UINT64)Hdr.Pe32->OptionalHeader.SizeOfImage; ImageContext->SectionAlignment = Hdr.Pe32->OptionalHeader.SectionAlignment; ImageContext->SizeOfHeaders = Hdr.Pe32->OptionalHeader.SizeOfHeaders; } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { // // Use PE32+ offset // ImageContext->ImageType = Hdr.Pe32Plus->OptionalHeader.Subsystem; ImageContext->ImageSize = (UINT64) Hdr.Pe32Plus->OptionalHeader.SizeOfImage; ImageContext->SectionAlignment = Hdr.Pe32Plus->OptionalHeader.SectionAlignment; ImageContext->SizeOfHeaders = Hdr.Pe32Plus->OptionalHeader.SizeOfHeaders; } else { ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE; return RETURN_UNSUPPORTED; } } else { ImageContext->ImageError = IMAGE_ERROR_INVALID_MACHINE_TYPE; return RETURN_UNSUPPORTED; } if (!PeCoffLoaderImageFormatSupported (ImageContext->Machine)) { // // If the PE/COFF loader does not support the image type return // unsupported. This library can suport lots of types of images // this does not mean the user of this library can call the entry // point of the image. // return RETURN_UNSUPPORTED; } return RETURN_SUCCESS; } /** Retrieves information about a PE/COFF image. Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView, PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER. If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while computing the fields of ImageContext, then the error status is returned in the ImageError field of ImageContext. @param ImageContext Pointer to the image context structure that describes the PE/COFF image that needs to be examined by this function. @retval RETURN_SUCCESS The information on the PE/COFF image was collected. @retval RETURN_INVALID_PARAMETER ImageContext is NULL. @retval RETURN_UNSUPPORTED The PE/COFF image is not supported. **/ RETURN_STATUS EFIAPI GluePeCoffLoaderGetImageInfo ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; EFI_IMAGE_DATA_DIRECTORY *DebugDirectoryEntry; UINTN Size; UINTN Index; UINTN DebugDirectoryEntryRva; UINTN DebugDirectoryEntryFileOffset; UINTN SectionHeaderOffset; EFI_IMAGE_SECTION_HEADER SectionHeader; EFI_IMAGE_DEBUG_DIRECTORY_ENTRY DebugEntry; UINT32 NumberOfRvaAndSizes; UINT16 Magic; if (NULL == ImageContext) { return RETURN_INVALID_PARAMETER; } // // Assume success // ImageContext->ImageError = IMAGE_ERROR_SUCCESS; Hdr.Union = &HdrData; Status = PeCoffLoaderGetPeHeader (ImageContext, Hdr); if (RETURN_ERROR (Status)) { return Status; } Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); // // Retrieve the base address of the image // if (!(ImageContext->IsTeImage)) { if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // ImageContext->ImageAddress = Hdr.Pe32->OptionalHeader.ImageBase; } else { // // Use PE32+ offset // ImageContext->ImageAddress = Hdr.Pe32Plus->OptionalHeader.ImageBase; } } else { ImageContext->ImageAddress = (PHYSICAL_ADDRESS)(Hdr.Te->ImageBase + Hdr.Te->StrippedSize - sizeof (EFI_TE_IMAGE_HEADER)); } // // Initialize the alternate destination address to 0 indicating that it // should not be used. // ImageContext->DestinationAddress = 0; // // Initialize the codeview pointer. // ImageContext->CodeView = NULL; ImageContext->PdbPointer = NULL; // // Three cases with regards to relocations: // - Image has base relocs, RELOCS_STRIPPED==0 => image is relocatable // - Image has no base relocs, RELOCS_STRIPPED==1 => Image is not relocatable // - Image has no base relocs, RELOCS_STRIPPED==0 => Image is relocatable but // has no base relocs to apply // Obviously having base relocations with RELOCS_STRIPPED==1 is invalid. // // Look at the file header to determine if relocations have been stripped, and // save this info in the image context for later use. // if ((!(ImageContext->IsTeImage)) && ((Hdr.Pe32->FileHeader.Characteristics & EFI_IMAGE_FILE_RELOCS_STRIPPED) != 0)) { ImageContext->RelocationsStripped = TRUE; } else { ImageContext->RelocationsStripped = FALSE; } if (!(ImageContext->IsTeImage)) { if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes; DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); } else { // // Use PE32+ offset // NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes; DebugDirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]); } if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) { DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress; // // Determine the file offset of the debug directory... This means we walk // the sections to find which section contains the RVA of the debug // directory // DebugDirectoryEntryFileOffset = 0; SectionHeaderOffset = (UINTN)( ImageContext->PeCoffHeaderOffset + sizeof (UINT32) + sizeof (EFI_IMAGE_FILE_HEADER) + Hdr.Pe32->FileHeader.SizeOfOptionalHeader ); for (Index = 0; Index < Hdr.Pe32->FileHeader.NumberOfSections; Index++) { // // Read section header from file // Size = sizeof (EFI_IMAGE_SECTION_HEADER); Status = ImageContext->ImageRead ( ImageContext->Handle, SectionHeaderOffset, &Size, &SectionHeader ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } if (DebugDirectoryEntryRva >= SectionHeader.VirtualAddress && DebugDirectoryEntryRva < SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize) { DebugDirectoryEntryFileOffset = DebugDirectoryEntryRva - SectionHeader.VirtualAddress + SectionHeader.PointerToRawData; break; } SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER); } if (DebugDirectoryEntryFileOffset != 0) { for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) { // // Read next debug directory entry // Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); Status = ImageContext->ImageRead ( ImageContext->Handle, DebugDirectoryEntryFileOffset, &Size, &DebugEntry ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } if (DebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { ImageContext->DebugDirectoryEntryRva = (UINT32) (DebugDirectoryEntryRva + Index); if (DebugEntry.RVA == 0 && DebugEntry.FileOffset != 0) { ImageContext->ImageSize += DebugEntry.SizeOfData; } return RETURN_SUCCESS; } } } } } else { DebugDirectoryEntry = &Hdr.Te->DataDirectory[1]; DebugDirectoryEntryRva = DebugDirectoryEntry->VirtualAddress; SectionHeaderOffset = (UINTN)(sizeof (EFI_TE_IMAGE_HEADER)); DebugDirectoryEntryFileOffset = 0; for (Index = 0; Index < Hdr.Te->NumberOfSections;) { // // Read section header from file // Size = sizeof (EFI_IMAGE_SECTION_HEADER); Status = ImageContext->ImageRead ( ImageContext->Handle, SectionHeaderOffset, &Size, &SectionHeader ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } if (DebugDirectoryEntryRva >= SectionHeader.VirtualAddress && DebugDirectoryEntryRva < SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize) { DebugDirectoryEntryFileOffset = DebugDirectoryEntryRva - SectionHeader.VirtualAddress + SectionHeader.PointerToRawData + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize; // // File offset of the debug directory was found, if this is not the last // section, then skip to the last section for calculating the image size. // if (Index < (UINTN) Hdr.Te->NumberOfSections - 1) { SectionHeaderOffset += (Hdr.Te->NumberOfSections - 1 - Index) * sizeof (EFI_IMAGE_SECTION_HEADER); Index = Hdr.Te->NumberOfSections - 1; continue; } } // // In Te image header there is not a field to describe the ImageSize. // Actually, the ImageSize equals the RVA plus the VirtualSize of // the last section mapped into memory (Must be rounded up to // a mulitple of Section Alignment). Per the PE/COFF specification, the // section headers in the Section Table must appear in order of the RVA // values for the corresponding sections. So the ImageSize can be determined // by the RVA and the VirtualSize of the last section header in the // Section Table. // if ((++Index) == (UINTN)Hdr.Te->NumberOfSections) { ImageContext->ImageSize = (SectionHeader.VirtualAddress + SectionHeader.Misc.VirtualSize + ImageContext->SectionAlignment - 1) & ~(ImageContext->SectionAlignment - 1); } SectionHeaderOffset += sizeof (EFI_IMAGE_SECTION_HEADER); } if (DebugDirectoryEntryFileOffset != 0) { for (Index = 0; Index < DebugDirectoryEntry->Size; Index += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY)) { // // Read next debug directory entry // Size = sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); Status = ImageContext->ImageRead ( ImageContext->Handle, DebugDirectoryEntryFileOffset, &Size, &DebugEntry ); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } if (DebugEntry.Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) { ImageContext->DebugDirectoryEntryRva = (UINT32) (DebugDirectoryEntryRva + Index); return RETURN_SUCCESS; } } } } return RETURN_SUCCESS; } /** Converts an image address to the loaded address. @param ImageContext The context of the image being loaded. @param Address The address to be converted to the loaded address. @return The converted address or NULL if the address can not be converted. **/ VOID * GluePeCoffLoaderImageAddress ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext, IN UINTN Address ) { // // @bug Check to make sure ImageSize is correct for the relocated image. // it may only work for the file we start with and not the relocated image // if (Address >= ImageContext->ImageSize) { ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS; return NULL; } return (CHAR8 *)((UINTN) ImageContext->ImageAddress + Address); } /** Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage(). If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of ImageContext as the relocation base address. Otherwise, use the DestinationAddress field of ImageContext as the relocation base address. The caller must allocate the relocation fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function. If ImageContext is NULL, then ASSERT(). @param ImageContext Pointer to the image context structure that describes the PE/COFF image that is being relocated. @retval RETURN_SUCCESS The PE/COFF image was relocated. Extended status information is in the ImageError field of ImageContext. @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image. Extended status information is in the ImageError field of ImageContext. @retval RETURN_UNSUPPORTED A relocation record type is not supported. Extended status information is in the ImageError field of ImageContext. **/ RETURN_STATUS EFIAPI GluePeCoffLoaderRelocateImage ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; EFI_IMAGE_DATA_DIRECTORY *RelocDir; UINT64 Adjust; EFI_IMAGE_BASE_RELOCATION *RelocBase; EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd; UINT16 *Reloc; UINT16 *RelocEnd; CHAR8 *Fixup; CHAR8 *FixupBase; UINT16 *F16; UINT32 *F32; UINT64 *F64; CHAR8 *FixupData; PHYSICAL_ADDRESS BaseAddress; UINT32 NumberOfRvaAndSizes; UINT16 Magic; ASSERT (ImageContext != NULL); // // Assume success // ImageContext->ImageError = IMAGE_ERROR_SUCCESS; // // If there are no relocation entries, then we are done // if (ImageContext->RelocationsStripped) { return RETURN_SUCCESS; } // // If the destination address is not 0, use that rather than the // image address as the relocation target. // if (ImageContext->DestinationAddress != 0) { BaseAddress = ImageContext->DestinationAddress; } else if (!(ImageContext->IsTeImage)) { BaseAddress = ImageContext->ImageAddress; } else { Hdr.Te = (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->ImageAddress); BaseAddress = ImageContext->ImageAddress + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize; } if (!(ImageContext->IsTeImage)) { Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset); Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // Adjust = (UINT64)BaseAddress - Hdr.Pe32->OptionalHeader.ImageBase; Hdr.Pe32->OptionalHeader.ImageBase = (UINT32)BaseAddress; NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes; RelocDir = &Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; } else { // // Use PE32+ offset // Adjust = (UINT64) BaseAddress - Hdr.Pe32Plus->OptionalHeader.ImageBase; Hdr.Pe32Plus->OptionalHeader.ImageBase = (UINT64)BaseAddress; NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes; RelocDir = &Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; } // // Find the relocation block // Per the PE/COFF spec, you can't assume that a given data directory // is present in the image. You have to check the NumberOfRvaAndSizes in // the optional header to verify a desired directory entry is there. // if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { RelocBase = PeCoffLoaderImageAddress (ImageContext, RelocDir->VirtualAddress); RelocBaseEnd = PeCoffLoaderImageAddress ( ImageContext, RelocDir->VirtualAddress + RelocDir->Size - 1 ); } else { // // Set base and end to bypass processing below. // RelocBase = RelocBaseEnd = 0; } } else { Hdr.Te = (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->ImageAddress); Adjust = (UINT64) (BaseAddress - Hdr.Te->ImageBase); Hdr.Te->ImageBase = (UINT64) (BaseAddress); // // Find the relocation block // RelocDir = &Hdr.Te->DataDirectory[0]; RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)( ImageContext->ImageAddress + RelocDir->VirtualAddress + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize ); RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *) ((UINTN) RelocBase + (UINTN) RelocDir->Size - 1); } // // Run the relocation information and apply the fixups // FixupData = ImageContext->FixupData; while (RelocBase < RelocBaseEnd) { Reloc = (UINT16 *) ((CHAR8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION)); RelocEnd = (UINT16 *) ((CHAR8 *) RelocBase + RelocBase->SizeOfBlock); if (!(ImageContext->IsTeImage)) { FixupBase = PeCoffLoaderImageAddress (ImageContext, RelocBase->VirtualAddress); } else { FixupBase = (CHAR8 *)(UINTN)(ImageContext->ImageAddress + RelocBase->VirtualAddress + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize ); } if ((CHAR8 *) RelocEnd < (CHAR8 *) ((UINTN) ImageContext->ImageAddress) || (CHAR8 *) RelocEnd > (CHAR8 *)((UINTN)ImageContext->ImageAddress + (UINTN)ImageContext->ImageSize)) { ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; return RETURN_LOAD_ERROR; } // // Run this relocation record // while (Reloc < RelocEnd) { Fixup = FixupBase + (*Reloc & 0xFFF); switch ((*Reloc) >> 12) { case EFI_IMAGE_REL_BASED_ABSOLUTE: break; case EFI_IMAGE_REL_BASED_HIGH: F16 = (UINT16 *) Fixup; *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16))); if (FixupData != NULL) { *(UINT16 *) FixupData = *F16; FixupData = FixupData + sizeof (UINT16); } break; case EFI_IMAGE_REL_BASED_LOW: F16 = (UINT16 *) Fixup; *F16 = (UINT16) (*F16 + (UINT16) Adjust); if (FixupData != NULL) { *(UINT16 *) FixupData = *F16; FixupData = FixupData + sizeof (UINT16); } break; case EFI_IMAGE_REL_BASED_HIGHLOW: F32 = (UINT32 *) Fixup; *F32 = *F32 + (UINT32) Adjust; if (FixupData != NULL) { FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32)); *(UINT32 *)FixupData = *F32; FixupData = FixupData + sizeof (UINT32); } break; case EFI_IMAGE_REL_BASED_DIR64: F64 = (UINT64 *) Fixup; *F64 = *F64 + (UINT64) Adjust; if (FixupData != NULL) { FixupData = ALIGN_POINTER (FixupData, sizeof(UINT64)); *(UINT64 *)(FixupData) = *F64; FixupData = FixupData + sizeof(UINT64); } break; default: // // The common code does not handle some of the stranger IPF relocations // PeCoffLoaderRelocateImageEx () addes support for these complex fixups // on IPF and is a No-Op on other archtiectures. // Status = PeCoffLoaderRelocateImageEx (Reloc, Fixup, &FixupData, Adjust); if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_FAILED_RELOCATION; return Status; } } // // Next relocation record // Reloc += 1; } // // Next reloc block // RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; } return RETURN_SUCCESS; } /** Loads a PE/COFF image into memory. Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function. The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed. If ImageContext is NULL, then ASSERT(). @param ImageContext Pointer to the image context structure that describes the PE/COFF image that is being loaded. @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by the ImageAddress and ImageSize fields of ImageContext. Extended status information is in the ImageError field of ImageContext. @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer. Extended status information is in the ImageError field of ImageContext. @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations. Extended status information is in the ImageError field of ImageContext. @retval RETURN_INVALID_PARAMETER The image address is invalid. Extended status information is in the ImageError field of ImageContext. **/ RETURN_STATUS EFIAPI GluePeCoffLoaderLoadImage ( IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext ) { RETURN_STATUS Status; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; PE_COFF_LOADER_IMAGE_CONTEXT CheckContext; EFI_IMAGE_SECTION_HEADER *FirstSection; EFI_IMAGE_SECTION_HEADER *Section; UINTN NumberOfSections; UINTN Index; CHAR8 *Base; CHAR8 *End; CHAR8 *MaxEnd; EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry; UINTN Size; UINT32 TempDebugEntryRva; UINT32 NumberOfRvaAndSizes; UINT16 Magic; ASSERT (ImageContext != NULL); // // Assume success // ImageContext->ImageError = IMAGE_ERROR_SUCCESS; // // Copy the provided context info into our local version, get what we // can from the original image, and then use that to make sure everything // is legit. // CopyMem (&CheckContext, ImageContext, sizeof (PE_COFF_LOADER_IMAGE_CONTEXT)); Status = PeCoffLoaderGetImageInfo (&CheckContext); if (RETURN_ERROR (Status)) { return Status; } // // Make sure there is enough allocated space for the image being loaded // if (ImageContext->ImageSize < CheckContext.ImageSize) { ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_SIZE; return RETURN_BUFFER_TOO_SMALL; } if (ImageContext->ImageAddress == 0) { // // Image cannot be loaded into 0 address. // ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS; return RETURN_INVALID_PARAMETER; } // // If there's no relocations, then make sure it's not a runtime driver, // and that it's being loaded at the linked address. // if (CheckContext.RelocationsStripped) { // // If the image does not contain relocations and it is a runtime driver // then return an error. // if (CheckContext.ImageType == EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER) { ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM; return RETURN_LOAD_ERROR; } // // If the image does not contain relocations, and the requested load address // is not the linked address, then return an error. // if (CheckContext.ImageAddress != ImageContext->ImageAddress) { ImageContext->ImageError = IMAGE_ERROR_INVALID_IMAGE_ADDRESS; return RETURN_INVALID_PARAMETER; } } // // Make sure the allocated space has the proper section alignment // if (!(ImageContext->IsTeImage)) { if ((ImageContext->ImageAddress & (CheckContext.SectionAlignment - 1)) != 0) { ImageContext->ImageError = IMAGE_ERROR_INVALID_SECTION_ALIGNMENT; return RETURN_INVALID_PARAMETER; } } // // Read the entire PE/COFF or TE header into memory // if (!(ImageContext->IsTeImage)) { Status = ImageContext->ImageRead ( ImageContext->Handle, 0, &ImageContext->SizeOfHeaders, (VOID *) (UINTN) ImageContext->ImageAddress ); Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset); FirstSection = (EFI_IMAGE_SECTION_HEADER *) ( (UINTN)ImageContext->ImageAddress + ImageContext->PeCoffHeaderOffset + sizeof(UINT32) + sizeof(EFI_IMAGE_FILE_HEADER) + Hdr.Pe32->FileHeader.SizeOfOptionalHeader ); NumberOfSections = (UINTN) (Hdr.Pe32->FileHeader.NumberOfSections); } else { Status = ImageContext->ImageRead ( ImageContext->Handle, 0, &ImageContext->SizeOfHeaders, (void *)(UINTN)ImageContext->ImageAddress ); Hdr.Te = (EFI_TE_IMAGE_HEADER *)(UINTN)(ImageContext->ImageAddress); FirstSection = (EFI_IMAGE_SECTION_HEADER *) ( (UINTN)ImageContext->ImageAddress + sizeof(EFI_TE_IMAGE_HEADER) ); NumberOfSections = (UINTN) (Hdr.Te->NumberOfSections); } if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return RETURN_LOAD_ERROR; } // // Load each section of the image // Section = FirstSection; for (Index = 0, MaxEnd = NULL; Index < NumberOfSections; Index++) { // // Compute sections address // Base = PeCoffLoaderImageAddress (ImageContext, Section->VirtualAddress); End = PeCoffLoaderImageAddress ( ImageContext, Section->VirtualAddress + Section->Misc.VirtualSize - 1 ); if (ImageContext->IsTeImage) { Base = (CHAR8 *)((UINTN) Base + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN)Hdr.Te->StrippedSize); End = (CHAR8 *)((UINTN) End + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN)Hdr.Te->StrippedSize); } if (End > MaxEnd) { MaxEnd = End; } // // If the base start or end address resolved to 0, then fail. // if ((Base == NULL) || (End == NULL)) { ImageContext->ImageError = IMAGE_ERROR_SECTION_NOT_LOADED; return RETURN_LOAD_ERROR; } // // Read the section // Size = (UINTN) Section->Misc.VirtualSize; if ((Size == 0) || (Size > Section->SizeOfRawData)) { Size = (UINTN) Section->SizeOfRawData; } if (Section->SizeOfRawData) { if (!(ImageContext->IsTeImage)) { Status = ImageContext->ImageRead ( ImageContext->Handle, Section->PointerToRawData, &Size, Base ); } else { Status = ImageContext->ImageRead ( ImageContext->Handle, Section->PointerToRawData + sizeof (EFI_TE_IMAGE_HEADER) - (UINTN)Hdr.Te->StrippedSize, &Size, Base ); } if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return Status; } } // // If raw size is less then virt size, zero fill the remaining // if (Size < Section->Misc.VirtualSize) { ZeroMem (Base + Size, Section->Misc.VirtualSize - Size); } // // Next Section // Section += 1; } // // Get image's entry point // Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (!(ImageContext->IsTeImage)) { // // Sizes of AddressOfEntryPoint are different so we need to do this safely // if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // ImageContext->EntryPoint = (PHYSICAL_ADDRESS)(UINTN)PeCoffLoaderImageAddress ( ImageContext, (UINTN)Hdr.Pe32->OptionalHeader.AddressOfEntryPoint ); } else { // // Use PE32+ offset // ImageContext->EntryPoint = (PHYSICAL_ADDRESS)(UINTN)PeCoffLoaderImageAddress ( ImageContext, (UINTN)Hdr.Pe32Plus->OptionalHeader.AddressOfEntryPoint ); } } else { ImageContext->EntryPoint = (PHYSICAL_ADDRESS) ( (UINTN)ImageContext->ImageAddress + (UINTN)Hdr.Te->AddressOfEntryPoint + (UINTN)sizeof(EFI_TE_IMAGE_HEADER) - (UINTN)Hdr.Te->StrippedSize ); } // // Determine the size of the fixup data // // Per the PE/COFF spec, you can't assume that a given data directory // is present in the image. You have to check the NumberOfRvaAndSizes in // the optional header to verify a desired directory entry is there. // if (!(ImageContext->IsTeImage)) { if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes; DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; } else { // // Use PE32+ offset // NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes; DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC]; } if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN); } else { ImageContext->FixupDataSize = 0; } } else { DirectoryEntry = &Hdr.Te->DataDirectory[0]; ImageContext->FixupDataSize = DirectoryEntry->Size / sizeof (UINT16) * sizeof (UINTN); } // // Consumer must allocate a buffer for the relocation fixup log. // Only used for runtime drivers. // ImageContext->FixupData = NULL; // // Load the Codeview info if present // if (ImageContext->DebugDirectoryEntryRva != 0) { if (!(ImageContext->IsTeImage)) { DebugEntry = PeCoffLoaderImageAddress ( ImageContext, ImageContext->DebugDirectoryEntryRva ); } else { DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)(UINTN)( ImageContext->ImageAddress + ImageContext->DebugDirectoryEntryRva + sizeof(EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize ); } if (DebugEntry != NULL) { TempDebugEntryRva = DebugEntry->RVA; if (DebugEntry->RVA == 0 && DebugEntry->FileOffset != 0) { Section--; if ((UINTN)Section->SizeOfRawData < Section->Misc.VirtualSize) { TempDebugEntryRva = Section->VirtualAddress + Section->Misc.VirtualSize; } else { TempDebugEntryRva = Section->VirtualAddress + Section->SizeOfRawData; } } if (TempDebugEntryRva != 0) { if (!(ImageContext->IsTeImage)) { ImageContext->CodeView = PeCoffLoaderImageAddress (ImageContext, TempDebugEntryRva); } else { ImageContext->CodeView = (VOID *)( (UINTN)ImageContext->ImageAddress + (UINTN)TempDebugEntryRva + (UINTN)sizeof (EFI_TE_IMAGE_HEADER) - (UINTN) Hdr.Te->StrippedSize ); } if (ImageContext->CodeView == NULL) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return RETURN_LOAD_ERROR; } if (DebugEntry->RVA == 0) { Size = DebugEntry->SizeOfData; if (!(ImageContext->IsTeImage)) { Status = ImageContext->ImageRead ( ImageContext->Handle, DebugEntry->FileOffset, &Size, ImageContext->CodeView ); } else { Status = ImageContext->ImageRead ( ImageContext->Handle, DebugEntry->FileOffset + sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize, &Size, ImageContext->CodeView ); // // Should we apply fix up to this field according to the size difference between PE and TE? // Because now we maintain TE header fields unfixed, this field will also remain as they are // in original PE image. // } if (RETURN_ERROR (Status)) { ImageContext->ImageError = IMAGE_ERROR_IMAGE_READ; return RETURN_LOAD_ERROR; } DebugEntry->RVA = TempDebugEntryRva; } switch (*(UINT32 *) ImageContext->CodeView) { case CODEVIEW_SIGNATURE_NB10: ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY); break; case CODEVIEW_SIGNATURE_RSDS: ImageContext->PdbPointer = (CHAR8 *)ImageContext->CodeView + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY); break; default: break; } } } } return Status; } /** Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI runtime. PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply the fixups with a virtual mapping. @param ImageBase Base address of relocated image @param VirtImageBase Virtual mapping for ImageBase @param ImageSize Size of the image to relocate @param RelocationData Location to place results of read **/ VOID EFIAPI PeCoffLoaderRelocateImageForRuntime ( IN PHYSICAL_ADDRESS ImageBase, IN PHYSICAL_ADDRESS VirtImageBase, IN UINTN ImageSize, IN VOID *RelocationData ) { CHAR8 *OldBase; CHAR8 *NewBase; EFI_IMAGE_DOS_HEADER *DosHdr; EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr; UINT32 NumberOfRvaAndSizes; EFI_IMAGE_DATA_DIRECTORY *DataDirectory; EFI_IMAGE_DATA_DIRECTORY *RelocDir; EFI_IMAGE_BASE_RELOCATION *RelocBase; EFI_IMAGE_BASE_RELOCATION *RelocBaseEnd; UINT16 *Reloc; UINT16 *RelocEnd; CHAR8 *Fixup; CHAR8 *FixupBase; UINT16 *F16; UINT32 *F32; UINT64 *F64; CHAR8 *FixupData; UINTN Adjust; RETURN_STATUS Status; UINT16 Magic; OldBase = (CHAR8 *)((UINTN)ImageBase); NewBase = (CHAR8 *)((UINTN)VirtImageBase); Adjust = (UINTN) NewBase - (UINTN) OldBase; // // Find the image's relocate dir info // DosHdr = (EFI_IMAGE_DOS_HEADER *)OldBase; if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) { // // Valid DOS header so get address of PE header // Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(((CHAR8 *)DosHdr) + DosHdr->e_lfanew); } else { // // No Dos header so assume image starts with PE header. // Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)OldBase; } if (Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) { // // Not a valid PE image so Exit // return ; } Magic = PeCoffLoaderGetPeHeaderMagicValue (Hdr); if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { // // Use PE32 offset // NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes; DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[0]); } else { // // Use PE32+ offset // NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes; DataDirectory = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[0]); } // // Find the relocation block // // Per the PE/COFF spec, you can't assume that a given data directory // is present in the image. You have to check the NumberOfRvaAndSizes in // the optional header to verify a desired directory entry is there. // if (NumberOfRvaAndSizes > EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC) { RelocDir = DataDirectory + EFI_IMAGE_DIRECTORY_ENTRY_BASERELOC; RelocBase = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress); RelocBaseEnd = (EFI_IMAGE_BASE_RELOCATION *)(UINTN)(ImageBase + RelocDir->VirtualAddress + RelocDir->Size); } else { // // Cannot find relocations, cannot continue // ASSERT (FALSE); return ; } ASSERT (RelocBase != NULL && RelocBaseEnd != NULL); // // Run the whole relocation block. And re-fixup data that has not been // modified. The FixupData is used to see if the image has been modified // since it was relocated. This is so data sections that have been updated // by code will not be fixed up, since that would set them back to // defaults. // FixupData = RelocationData; while (RelocBase < RelocBaseEnd) { Reloc = (UINT16 *) ((UINT8 *) RelocBase + sizeof (EFI_IMAGE_BASE_RELOCATION)); RelocEnd = (UINT16 *) ((UINT8 *) RelocBase + RelocBase->SizeOfBlock); FixupBase = (CHAR8 *) ((UINTN)ImageBase) + RelocBase->VirtualAddress; // // Run this relocation record // while (Reloc < RelocEnd) { Fixup = FixupBase + (*Reloc & 0xFFF); switch ((*Reloc) >> 12) { case EFI_IMAGE_REL_BASED_ABSOLUTE: break; case EFI_IMAGE_REL_BASED_HIGH: F16 = (UINT16 *) Fixup; if (*(UINT16 *) FixupData == *F16) { *F16 = (UINT16) (*F16 + ((UINT16) ((UINT32) Adjust >> 16))); } FixupData = FixupData + sizeof (UINT16); break; case EFI_IMAGE_REL_BASED_LOW: F16 = (UINT16 *) Fixup; if (*(UINT16 *) FixupData == *F16) { *F16 = (UINT16) (*F16 + ((UINT16) Adjust & 0xffff)); } FixupData = FixupData + sizeof (UINT16); break; case EFI_IMAGE_REL_BASED_HIGHLOW: F32 = (UINT32 *) Fixup; FixupData = ALIGN_POINTER (FixupData, sizeof (UINT32)); if (*(UINT32 *) FixupData == *F32) { *F32 = *F32 + (UINT32) Adjust; } FixupData = FixupData + sizeof (UINT32); break; case EFI_IMAGE_REL_BASED_DIR64: F64 = (UINT64 *)Fixup; FixupData = ALIGN_POINTER (FixupData, sizeof (UINT64)); if (*(UINT64 *) FixupData == *F64) { *F64 = *F64 + (UINT64)Adjust; } FixupData = FixupData + sizeof (UINT64); break; case EFI_IMAGE_REL_BASED_HIGHADJ: // // Not implemented, but not used in EFI 1.0 // ASSERT (FALSE); break; default: // // Only Itanium requires ConvertPeImage_Ex // Status = PeHotRelocateImageEx (Reloc, Fixup, &FixupData, Adjust); if (RETURN_ERROR (Status)) { return ; } } // // Next relocation record // Reloc += 1; } // // next reloc block // RelocBase = (EFI_IMAGE_BASE_RELOCATION *) RelocEnd; } } /** ImageRead function that operates on a memory buffer whos base is passed into FileHandle. @param FileHandle Ponter to baes of the input stream @param FileOffset Offset to the start of the buffer @param ReadSize Number of bytes to copy into the buffer @param Buffer Location to place results of read @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into the buffer. **/ RETURN_STATUS EFIAPI PeCoffLoaderImageReadFromMemory ( IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer ) { CopyMem (Buffer, ((UINT8 *)FileHandle) + FileOffset, *ReadSize); return RETURN_SUCCESS; }
[ "hche10x@d4c01ab0-1994-4ed3-9bc5-3ada14f9202f" ]
hche10x@d4c01ab0-1994-4ed3-9bc5-3ada14f9202f
c0544c1fb5d4c520baa0b38c9d5f10a00a759e18
4101d8c5631fa2febac04f146f10978436cfd3bb
/04_blinking_bm/src/04_blinking_bm.c
d6c215a8bd12fd20fe104c91609b9cded64595e6
[]
no_license
RosaCruzMendoza/RosaCruzMendoza
75c680bee37ddcc0ded34047258e15d2499a3730
bd6aeaefd9ca37ecd78710a2eb3eed296b404930
refs/heads/master
2021-01-18T23:14:31.234872
2016-11-26T14:24:15
2016-11-26T14:24:15
72,654,509
0
0
null
null
null
null
UTF-8
C
false
false
5,107
c
/* Copyright 2016, XXXX * * * All rights reserved. * * This file is part of CIAA Firmware. * * 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. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * 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. * */ /** \brief Blinking Bare Metal example source file ** ** This is a mini example of the CIAA Firmware. ** **/ /** \addtogroup CIAA_Firmware CIAA Firmware ** @{ */ /** \addtogroup Examples CIAA Firmware Examples ** @{ */ /** \addtogroup Baremetal Bare Metal example source file ** @{ */ /* * Initials Name * --------------------------- * */ /* * modification history (new versions first) * ----------------------------------------------------------- * yyyymmdd v0.0.1 initials initial version */ /*==================[inclusions]=============================================*/ #include "04_blinking_bm.h" /* <= own header */ const uint16_t senial[] = {512,544,576,608,639,670,700,730,759,786,813,838,862,885,907,926,944,961,975,988,999,1008,1015,1020,1023,1024,1023,1020,1015,1008,999,988,975,961,944,926,907,885,862,838,813,786,759,730,700,670,639,608,576,544,512,480,448,416,385,354,324,294,265,238,211,186,162,139,117,98,80,63,49,36,25,16,9,4,1,0,1,4,9,16,25,36,49,63,80,98,117,139,162,186,211,238,265,294,324,354,385,416,448,480}; /*==================[macros and definitions]=================================*/ void Generar_senial(void) { static uint8_t i=0; update_DAC_value(senial[i]); i++; if(i==100)//hay 100 muestras i=0; } /*==================[internal data declaration]==============================*/ /*==================[internal functions declaration]=========================*/ /*==================[internal data definition]===============================*/ #define PERIODO_LED 3000000 #define MAX_PERIODO 1 //valor para frecuencia de 10khz #define MIN_PERIODO 100 //valor para frecuencia de 100khz /*==================[external data definition]===============================*/ /*==================[internal functions definition]==========================*/ /*==================[external functions definition]==========================*/ void delay(uint32_t periodo) { uint64_t i; for(i=periodo;i!=0;i--); } /** \brief Main function * * This is the main entry point of the software. * * \returns 0 * * \remarks This function never returns. Return value is only to avoid compiler * warnings or errors. */ int main(void) { /* inicializaciones */ void (*pfunc)();//estructura que define un puntero a funcion uint32_t periodo_blinking=PERIODO_LED; uint8_t tecla; uint8_t Sonido; Init_Switches(); init_DAC_EDUCIAA(); pfunc=&Generar_senial; timer0Init(1,pfunc);//trabaja con frecuencias usegundos uint8_t periodo_muestreo=100;//100 muestras por segundo while(1) { do{ tecla=Read_Switches(); } while(tecla==0); delay(PERIODO_LED); if (tecla==Read_Switches()) { if(tecla==TEC1) { if (periodo_muestreo<MIN_PERIODO) { periodo_muestreo++; timer0Init(periodo_muestreo,pfunc); } } if(tecla==TEC2) { if (periodo_muestreo>MAX_PERIODO) { periodo_muestreo--; timer0Init(periodo_muestreo,pfunc); } else { periodo_muestreo; } } } }; return 0; } /** @} doxygen end group definition */ /** @} doxygen end group definition */ /** @} doxygen end group definition */ /*==================[end of file]============================================*/
[ "rosa.cruzmendoza.1990@ieee.org" ]
rosa.cruzmendoza.1990@ieee.org
505cdfe5e66d6ba8fcd3934e8bf191bce95d8d20
788da62dce9041878fd098e5347408fbf0679ace
/qcom/proprietary/mm-camera/mm-camera2/media-controller/modules/sensors/actuators/0301/actuator_libs/iu074/camcorder/iu074_camcorder_lib.h
fd2b7da99794625ff413c81f1f5cd5355f8cfca6
[]
no_license
Snapdragon-Computer-Vision-Engine-Team/msm8974-sources2
e7daa0bf3096e09286fd6e9f3a4e078774e49565
8e8a1d7b8b840a7c93e39634d61614665974acb1
refs/heads/master
2021-12-15T03:28:26.619350
2017-07-25T06:50:38
2017-07-25T06:50:38
null
0
0
null
null
null
null
WINDOWS-1250
C
false
false
50,043
h
/*============================================================================ Copyright (c) 2012-2014 Qualcomm Technologies, Inc. All Rights Reserved. Qualcomm Technologies Proprietary and Confidential. ============================================================================*/ { /* af_header_info_t */ { /* header_version */ 0x301, /* module_name */ "sony", /* actuator_name */ "iu074", }, /* af_header_info_t */ /* af_tuning_algo_t */ { /* Variable name: af_process_type. * Defines which AF algorithm to use - * Exhaustive/Slope-predictive/Continuous. * 3A version: * Default value: AF_EXHAUSTIVE_SEARCH. * Data range: based on af_algo_type */ AF_EXHAUSTIVE_SEARCH, /* Variable name: position_near_end. * Used to control how far lens can move away from mechanical stop. It * is defined in term of indices, where position_far_end > * position_near_end. * 3A version: * Default value: 0. * Data range: 0 to (position_far_end – 1). * Constraints: Less than position_far_end. Total steps for AF lens to * travel = position_far_end - position_near_end. For * sanity check, it should be more than 20 steps. * Effect: Non-zero means we are limiting AF travel range even more than * the values obtained from AF tuning. For example, if AF lens * on the final production modules move 8 steps beyond the * necessary MACRO focused distance, we can reduce travel range * by setting position_near_end to 8 (or less to account for * module-to-module variation). */ 22, /* Variable name: position_default_in_macro. * Gives default rest position of lens when focus mode is Macro. * 3A version: * Default value: 0. * Data range: 0 to position_far_end. */ 32, /* Variable name: position_boundary. * Used to control how far lens can move away from mechanical stop in * NORMAL search mode. * 3A version: * Default value: 0. * Data range: 0 to (position_far_end – 1). * Constraints: Less than position_far_end. * Effect: The closer it is to position_far_end, the less steps AF lens is allowed * to travel in NORMAL search mode. */ 15, /* Variable name: position_default_in_normal. * Gives default rest position of lens when focus mode is Normal/Auto. * mode. * 3A version: * Default value: position_far_end. * Data range: 0 to position_far_end. */ 41, /* Variable name: position_far_end. * Used to control how far lens can move away from mechanical stop. It is * defined in term of indices, where position_far_end > position_near_end. * 3A version: * Default value: actuator infinity position * Data range: 1 to infinty * Constraints: * Effect: Non-zero means we are limiting AF travel range even more than the * values obtained from AF tuning. */ 41, /* Variable name: position_normal_hyperfocal. * Gives default position of lens when focus mode is Normal/Auto and * focus fails. * 3A version: * Default value: position_far_end. * Data range: 0 to position_far_end. */ 41, /* Variable name: position_macro_rgn. * Starting lens position of macro region. * 3A version: * Default value: tunable.. * Data range: 0 to position_far_end. */ 29, /* Variable name: undershoot_protect. * Boolean flag to enable/disable the feature * 3A version: * Default value: 0 (disable) * Data range: 0 (enable) or 1 (disable) * Constraints: the degree of protection from undershoot will be depends * on undershoot_adjust variable * Effect: If this feature is enabled, lens will move more in one * direction over the other direction. This is needed when * it is determined that AF actuator has severe hysteresis on * its movement during characterization process. The feature * compensate hysteresis by moving the lens more * in either forward or backward direction. */ 1, /* Variable name: undershoot_adjust. * Used when undershoot protection is enabled. * 3A version: * Default value: 0 * Data range: 0 to (coarse step size - 1) * Constraints: As noted above, number greater than or equal to coarse * step size is not recommended. * Effect: When feature is turned on, the feature will compensate the * undershoot movement of lens (mainly due to severe hysteresis) * by moving extra step specified in this variable. */ 0, /* Variable name: min_max_ratio_th. * If focus value drops below this much of maximum fv, search forward * is stopped. * 3A version: * Default value: 0.5 * Data range: 0 to less than 1 * Constraints: Value less than 0.75 is recommended. * Effect: Increasing this value makes it easier to stop the search * forward. */ 0.87, /* Variable name: lef_af_assist_enable. * Enable or disable the LED assist for auto focus feature. * 3A version: * Default value: 0.5 * Data range: 1 or 0. * Constraints: None * Effect: LED auto focus assist is enabled. */ 1, /* Variable name: led_af_assist_trigger_idx. * Lux Index at which LED assist for autofocus is enabled. * 3A version: * Default value: wLED Trigger Index (calculated) * Data range: 0 to 1000 * Constraints: None * Effect: Selects scene brightness level at which LED auto focus assist * can be enabled. */ 367, /* Variable name: lens_reset_frame_skip_cnt * How many frames to skip after resetting the lens * 3A version: * Default value: 2 * Data range: 2 - 6 * Constraints: Integers * Effect: Bigger in value represents longer waiting time. */ 1, /* Variable name: low_light_gain_th * When the aec gain is above this threshold, we assume it's low light condition. * 3A version: * Default value: 10 * Data range: * Constraints: * Effect: */ 10, /* Variable name: base_delay_adj_th * Threshold to check while adjusting base delay for CAF. When fps drops * we'll need to reduce the base delay. * 3A version: * Default value: 0.034 (note this value has to be larger than 0.033 which matches 30 fps) * Data range: * Constraints: * Effect: */ 0.034f, /* af_tuning_continuous_t */ { /* Variable name: enable * Enable/disable continuous autofocus. * 3A version: * Default value: 1 * Data range: 0 or 1 * Constraints: None * Effect: Continuous AF is enabled if set to 1. */ 1, /* Variable name: scene_change_detection_ratio * FV change to trigger a target change, following with a new focus search. * 3A version: * Default value: 4 * Data range: 0 to 60 * Constraints: None * Effect: Higher value makes it easier to trigger a new search. * Smaller value makes it harder to trigger a search due * to FV change. */ 2, /* Variable name: panning_stable_fv_change_trigger * FV change vs. past frame FV to trigger to determine if scene * is stable. * If ( |FV[i]-FV[i-1]|*t > FV[i-1]), not stable. * 3A version: * Constraints: None * Effect: Higher value makes it harder for scene to be determined * as stable. */ 0.0f, /* Variable name: panning_stable_fvavg_to_fv_change_trigger * FV change vs. average of 10 past frame's FV to trigger to determine * if scene is stable. * If ( |FV[i]-FVavg|*t > Fvavg), not stable. * 3A version: * Constraints: None * Effect: Higher value makes it harder for scene to be determined * as stable. */ 25.0f, /* Variable name: panning_unstable_trigger_cnt * How many panning unstable detections before triggering a * scene change. * 3A version: * Constraints: None * Effect: Higher value makes it harder for scene to be determined * as stable. */ 16000, /* Variable name: panning_stable_trigger_cnt * Number of consecutive stable frames after panning to required to trigger new search * 3A version: * Default value: 5 * Data range: 0 to 150 * Constraints: None * Effect: Higher values makes CAF harder to start a new search, for * example, it is useful when a scene has movement but do not want to * trigger a new CAF search. */ 8, /* Variable name: downhill_allowance * Number of extra steps to search once peak FV is found * 3A version: * Default value: 3 * Data range: 0 to 10 * Constraints: None * Effect: Higher value will cause focus search to go beyond peak this * amount of frames then return. Higher values is less prone to * get AF stuck in local maximum but it takes longer and user * experience is reduced. Smaller values has better user * experience and time but may cause AF to focus on local * maximum. */ 1, /* Variable name: uphill_allowance * Number of steps we move if FV keeps increasing. * 3A version: * Default value: 3 * Data range: 0 to 10 * Constraints: None */ 3, /* Variable name: base_frame_delay * How many frames to wait after lens move. * 3A version: * Default value: 2 * Data range: 2 - 6 * Constraints: Integers * Effect: Bigger in value represents longer waiting time. */ 2, /* Variable name: scene_change_luma_threshold * Threshold above which the change of lux will trigger the * continuous AF search. * 3A version: * Default value: 10 * Data range: > 0 * Constraints: None * Effect: Refocusing is needed when exp change > threshold. */ 12, /* Variable name: luma_settled_threshold * AF calculates AEC settled condition as follows * if abs(Prev AF Luma - Current AF Luma) < luma_settled_threshold * then CAF can begin focus search without waiting for AEC to * completely settle * 3A version: * Default value: 10 * Data range: > 0 * Constraints: None * Effect: Smaller value represents longer wait time for AEC to settle */ 25, /* Variable name: noise_level_th * Determine if the variation in FV is caused by noise. * 3A version: * Default value: 0.05 * Data range: > 0 * Constraints: Float * Effect: (FV1 - FV0)/FV1 (FV1>FV0), noise if this value < threshold, * otherwise, start FV search. */ 0.060f, /* Variable name: search_step_size * Single step size while moving lens in continuous AF. * 3A version: * Default value: 2 * Data range: 2 to 6 * Constraints: Integer * Effect: Larger value would move lens faster but can cause jerkiness. */ 1, /* Variable name: init_search_type * When continuous af starts we run this algorithm to keep lens in * known position and enter monitor mode. * 3A version: * Default value: AF_EXHAUSTIVE_SEARCH * Data range: NA * Constraints: Should be valid algo type. */ AF_EXHAUSTIVE_SEARCH, /* Variable name: search_type * When scene change is detected, we use this algorithm to find maximum * fv position. * 3A version: * Default value: AF_CONTINUOUS_SEARCH * Data range: NA * Constraints: Should be valid algo type. */ AF_CONTINUOUS_SEARCH, /* Variable name: low_light_wait * How many extra frames to skip under low light condition * 3A version: * Default value: 0 * Data range: 0 to 6 * Constraints: */ 3, /* Variable name: max_indecision_cnt * maximum number of times to stay in make decision state while trying * to determine which direction to start new search in. * 3A version: * Default value: 1 * Data range: 0 to 6 * Constraints: * Effect: Higher value might give better result; trade-off is * performance. */ 1, /* Variable name: flat_fv_confidence_level * Used for flat field detection. Determine how confidence we are that we * don't have flat FV curve by comparing min and max FV. * 3A version: * Default value: 0.95 * Data range: * Constraints: * Effect: */ 0.97, /* af_tuning_sad_t */ { /* Variable name: enable * enable/disable SAD scene-detection mechanism. * 3A version: * Default value: 1 * Data range: 0 or 1 * Constraints: * Effect: */ 1, /* Variable name: gain_min * minimum gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 2.0, /* Variable name: gain_max * maximum gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 30, /* Variable name: ref_gain_min * minimum reference gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 2.0, /* Variable name: ref_gain_max * minimum reference gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 30, /* Variable name: threshold_min * threshold when current gain is less than min gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 3, /* Variable name: threshold_max * threshold when current gain is more than max gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 2, /* Variable name: ref_threshold_min * threshold when current gain is less than min reference gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 4, /* Variable name: ref_threshold_max * threshold when current gain is more than max reference gain * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 2, /* Variable name: frames_to_wait * frames to wait before storing reference luma * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 5, } , /* af_tuning_sad_t */ /* af_tuning_gyro_t */ { /* Variable name: enable * enable/disable gyro assisted CAF. * 3A version: * Default value: 1 * Data range: 0 or 1 * Constraints: * Effect: */ 0, /* Variable name: min_movement_threshold * threshold above this means device is moving. * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 1.4, /* Variable name: stable_detected_threshold * device is be stable if above this threshold after panning. * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 0.12, /* Variable name: unstable_count_th * number of frames device was above movement threshold * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 3, /* Variable name: stable_count_th * number of frames we need to be stable after panning. * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 5, /* Variable name: fast_pan_threshold * Threshold to be consider as fast panning, comparing to * gyro_data->sqr * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 0.1, /* Variable name: slow_pan_threshold * Threshold to be consider as slow panning, comparing to * gyro_data->sqr * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 0.04, /* Variable name: fast_pan_count_threshold * Threshold of fast panning cnt to trigger refocusing * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 8, /* Variable name: sum_return_to_orig_pos_threshold * apart from fast panning count, if the gyro data sum is * pass the threshold, it will trigger refocus * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 15, /* Variable name: stable_count_delay * Number of stable frame from gyro to be consider stable * long enough * 3A version: * Default value: * Data range: * Constraints: * Effect: */ 6, } , /* af_tuning_gyro_t */ } , /* af_tuning_continuous_t */ /* af_tuning_exhaustive_t */ { /* Variable name: num_gross_steps_between_stat_points * Used to control how rough initial AF search (coarse search) is. * 3A version: * Default value: 4 * Data range: 3 to 6 * Constraints: None * Effect: Larger value means more displacement between initial sampled * points. This would require more num_fine_search_points during * subsequent search (fine search) to locate optimal ending AF lens * position. */ 4, /* Variable name: num_fine_steps_between_stat_points * Used to control how precise subsequent AF search (fine search) is. * 3A version: * Default value: 1 * Data range: 1 o 2 * Constraints: Less than num_gross_steps_between_stat_points * Effect: The bigger the value is, the less likely AF lens ends in * optimal position. */ 1, /* Variable name: num_fine_search_points * Used to control how many search points to be gather in fine search * 3A version: * Default value: 8 * Data range: Fixed * Constraints: It is set to 2 * num_gross_steps_between_stat_points to * cover entire range of coarse search's neighboring sampled points. * Effect: If it is less than 2*num_gross_steps_between_stat_points, AF * precision maybe lost. */ 8, /* Variable name: downhill_allowance * Number of extra steps to search once peak FV is found * 3A version: * Default value: 3 * Data range: 0 to 10 * Constraints: None * Effect: Higher value will cause focus search to go beyond peak this * amount of frames then return. Higher values is less prone to get * AF stuck in local maximum but it takes longer and user experience * is reduced. Smaller valueshas better user experience and time but * may cause AF to focus on local maximum.. */ 2, /* Variable name: uphill_allowance * Number of steps we move if FV keeps increasing. * 3A version: * Default value: 3 * Data range: 0 to 10 * Constraints: None */ 3, /* Variable name: base_frame_delay * Number of frames to skip after lens move is complete * 3A version: * Default value: 3 * Data range: 0 to 10 * Constraints: None * Effect: Lower value gives faster response but jerkier. Higher value * gives smooth response. */ 0, /* Variable name: coarse_frame_delay * Number of frames to skip after lens move is complete in coarse search * 3A version: * Default value: 0 * Data range: 0 to 10 * Constraints: None * Effect: Lower value gives faster response but jerkier. Higher value * gives smooth response. */ 0, /* Variable name: fine_frame_delay * Number of frames to skip after lens move is complete in fine search * 3A version: * Default value: 0 * Data range: 0 to 10 * Constraints: None * Effect: Lower value gives faster response but jerkier. Higher value * gives smooth response. */ 0, /* Variable name: coarse_to_fine_frame_delay * Number of frames to skip after lens move is complete in coarse search * and before starting the fine search * 3A version: * Default value: 1 * Data range: 0 to 10 * Constraints: None * Effect: Lower value gives faster response but jerkier. Higher value * gives smooth response. */ 1, /* Variable name: noise_level_th * Variation between last and current FV should be above this threshold, * otherwise the variation is considered to be due to noise. * 3A version: * Default value: 0.02 * Data range: * Constraints: * Effect: */ 0.016f, /* Variable name: flat_fv_confidence_level * Used for flat field detection. Determine how confidence we are that we * don't have flat FV curve by comparing min and max FV. * 3A version: * Default value: 0.95 * Data range: * Constraints: * Effect: */ 0.97f, /* Variable name: climb_ratio_th * Used for flat field detection. Cumulative focus curve inflections * less than this threshold denotes flat fv curve. * 3A version: * Default value: greater than 1 * Data range: * Constraints: * Effect: */ 1.1f, /* Variable name: low_light_luma_th * Used for flat field detection. When the luma gets below this threshold, we * assume it's too dark to focus and report failure. * 3A version: * Default value: 4 * Data range: * Constraints: * Effect: */ 7, /* Variable name: enable_multiwindow * Enable Flag for using Multi window or Single window AF stats. * 3A version: * Default value: 4 * Data range: * Constraints: * Effect: 0 = Single Window, 1 = MultiWindow */ 0, /* Variable name: gain_thresh * Gain Threshold for triggering multi window AF stats * 3A version: * Default value: 4 * Data range: * Constraints: * Effect: 0 = Single Window, 1 = MultiWindow */ 0, } , /* af_tuning_exhaustive_t */ /* af_tuning_fullsweep_t */{ /* Variable name: num_steps_between_stat_points * Used to control how many steps to move the lens at a time during * search. * 3A version: * Default value: 1 * Data range: 1 to max steps * Constraints: None * Effect: Should always be 1, but for some tests could be more. */ 1, /* Variable name: frame_delay_inf * Number of frames to skip after lens move to initial (inf) position. * 3A version: * Default value: 2 * Data range: 0 to 10 * Constraints: None * Effect: Bigger value will give more time for the lens to settle * after going into the inf. position. */ 2, /* Variable name: frame_delay_norm * Number of frames to skip after lens move to the next position. * 3A version: * Default value: 2 * Data range: 0 to 10 * Constraints: None * Effect: Bigger value will give more time for the lens to settle * between steps. */ 2, /* Variable name: frame_delay_final * Number of frames to skip after lens move to its final position where * the maximum FV is registered. * 3A version: * Default value: 2 * Data range: 0 to 10 * Constraints: None * Effect: Bigger value will give more time for the lens to settle * after going into the final position, so the FV can be observed in * the logs. */ 2, } , /* af_tuning_fullsweep_t */ /* af_tuning_sp_t */ { /* Variable name: fv_curve_flat_threshold * threshold to determine if FV curve is flat * 3A version: * Default value: 0.9 * Data range: 0 to 1 * Constraints: None * Effect: */ 0.9, /* Variable name: slope_threshold1 * sp threshold 1 * 3A version: * Default value: 0.9 * Data range: 0 to 1 * Constraints: None * Effect: */ 0.9, /* Variable name: slope_threshold2 * sp threshold 2 * 3A version: * Default value: 1.1 * Data range: * Constraints: None * Effect: */ 1.1, /* Variable name: slope_threshold3 * sp threshold 3 * 3A version: * Default value: 0.5 * Data range: * Constraints: None * Effect: */ 0.5, /* Variable name: slope_threshold4 * sp threshold 4 * 3A version: * Default value: 3 * Data range: * Constraints: None * Effect: */ 3, /* Variable name: lens_pos_0 * Lens poisiton when the object is at 3m * 3A version: * Default value: Calculated * Data range: * Constraints: None * Effect: */ 36, /* Variable name: lens_pos_1 * Lens poisiton when the object is at 70cm * 3A version: * Default value: Calculated * Data range: * Constraints: less than lens_pos_0 * Effect: */ 32, /* Variable name: lens_pos_2 * Lens poisiton when the object is at 30cm * 3A version: * Default value: Calculated * Data range: * Constraints: less than lens_pos_1 * Effect: */ 24, /* Variable name: lens_pos_3 * Lens poisiton when the object is at 20cm * 3A version: * Default value: Calculated * Data range: * Constraints: less than lens_pos_2 * Effect: */ 12, /* Variable name: lens_pos_4 * Lens poisiton when the object is at 10cm * 3A version: * Default value: Calculated * Data range: * Constraints: less than lens_pos_3 * Effect: */ 8, /* Variable name: lens_pos_5 * Lens poisiton when the object is at macro * 3A version: * Default value: Calculated * Data range: * Constraints: less than lens_pos_3 * Effect: */ 4, /* Variable name: frame_delay * Number of frames to skip after lens move is complete * 3A version: * Default value: calculated * Data range: * Constraints: less than lens_pos_4 * Effect: Lower value gives faster response but jerkier. Higher value * gives smooth response. */ 1, /* Variable name: downhill_allowance * max number of consecutive downhill in the first 4 or 6 samples. * 3A version: * Default value: 2 * Data range: 0 to 10 * Constraints: None * Effect: Higher value will cause focus search to go beyond peak this * amount of frames then return. Higher values is less prone to get * AF stuck in local maximum but it takes longer and user experience * is reduced. Smaller valueshas better user experience and time but * may cause AF to focus on local maximum.. */ 2, /* Variable name: downhill_allowance_1 * max number of consecutive downhill in the first 2nd or 3rd round. * 3A version: * Default value: 1 * Data range: 0 to 10 * Constraints: None * Effect: Higher value will cause focus search to go beyond peak this * amount of frames then return. Higher values is less prone to get * AF stuck in local maximum but it takes longer and user experience * is reduced. Smaller valueshas better user experience and time but * may cause AF to focus on local maximum.. */ 1, }, /* af_tuning_sp_t */ /* af_shake_resistant_t */ { /* Variable name: enable * Enables and disables the feature. * 3A version: * Default value: 1 * Data range: 0 or 1 * Constraints: None * Effect: Enables or disables the featue. */ 0, /* Variable name: max_gain * Used to define the maximum gain allowed when the gain is boosted * under low light. * 3A version: * Default value: 4 * Max Exposure Table Gain (Calculated) * Data range: 4 to 10X max preview gain of exp table. * Constraints: This value will limit the max_af_tradeoff_ratio applied. * Effect: The bigger the value, the shorter the exposure time will be, * increasing the noise level. */ 4.000000f, /* Variable name: min_frame_luma * The minimum frame luma allowed below which shake-resistant AF will * be disabled. * 3A version: * Default value: 0 (to be tuned later). * Data range: 0~luma_target. * Constraints: It should be greater than the value at which the frame * is too dark for AF to work successfully. * Effect: The smaller this value is set, the darker lighting * condition under which shake-resistant AF will be turned off. */ 0, /* Variable name: tradeoff_ratio * Used to define how much the exposure time should be reduced. * 3A version: * Default value: 4 * Data range: 1~4 * Constraints: The value should be greater than or equal to 1. * Effect: The bigger the value is, the smaller the adjusted exposure * time would be. */ 4.000000f, /* Variable name: toggle_frame_skip * Sets number of frames to skip or drop from preview when this * feature is called. * 3A version: * Default value: 2 * Data range: 0 to 4 * Constraints: None * Effect: Will appear as preview is frozen for amount of frames * set whenever AF is started and finished. */ 2, }, /* af_shake_resistant_t */ /* af_motion_sensor_t */ { /* Variable name: af_gyro_trigger * Used to control how scene change should be detected for AF. * 3A version: * Default value: 0.0 * Data range: -16000.0 to +16000.0 * Constraints: None * Effect: The bigger the value is, the less sensitive AF response to * gyro output value. */ 0.000000f, /* Variable name: af_accelerometer_trigger * Used to control how scene change should be detected for AF. * 3A version: * Default value: 0.0 * Data range: -16000.0 to +16000.0 * Constraints: None * Effect: The bigger the value is, the less sensitive AF response to * gyro output value. */ 0.000000f, /* Variable name: af_magnetometer_trigger * Used to control how scene change should be detected for AF. * 3A version: * Default value: 0.0 * Data range: -16000.0 to +16000.0 * Constraints: None * Effect: The bigger the value is, the less sensitive AF response to * gyro output value. */ 0.000000f, /* Variable name: af_dis_motion_vector_trigger * Used to control how scene change should be detected for AF. * 3A version: * Default value: 0.0 * Data range: -16000.0 to +16000.0 * Constraints: None * Effect: The bigger the value is, the less sensitive AF response to * gyro output value. */ 0.000000f, }, /* af_motion_sensor_t */ /* af_fd_priority_caf_t */ { /* Variable name: pos_change_th * Controls when to reconfigure ROI when position has changed * with respect to last stable ROI. * 3A version: * Default value: * Data range: * Constraints: None * Effect: The bigger the value is, the less sensitive AF to * face position change */ 10.0, /* Variable name: pos_stable_th_hi * percentage differnce between last and current position above * this indicate face is moving and not stable to trigger new search. * 3A version: * Default value: 0.0 * Data range: * Constraints: None * Effect: */ 1.3f, /* Variable name: pos_stable_th_low * position is deemed stable only after face position change * is less than this threshold. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 0.5f, /* Variable name: size_change_th * threshold to check if size change has decreased enough to be * considered stable. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 4.0f, /* Variable name: old_new_size_diff_th * percentage difference between last biggest face and current * biggest face to check if we should start focusing on new face. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 2.0f, /* Variable name: stable_count_size * number of frames face size should remain stable to trigger * new search. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 3, /* Variable name: stable_count_pos * number of frames face position should remain stable to trigger * new search. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 3, /* Variable name: no_face_wait_th * number of frames to wait to reset default ROI once face disappears. * 3A version: * Default value: * Data range: * Constraints: None * Effect: */ 3, /* Variable name: fps_adjustment_th * if current fps falls below this threshold we'll adjust stability counts. * 3A version: * Default value: 15 * Data range: * Constraints: None * Effect: */ 15, }, /* af_fd_priority_caf_t */ }, /* af_tuning_algo_t */ /* af_tuning_vfe_t */ { /* Variable name: fv_metric * Focus value metric - 0 means sum and 1 means Max. * 3A version: * Default value: 0 * Data range: * Constraints: * Effect: */ 0, /* af_vfe_config_t */ { /* Variable name: fv_min * Minimum focus value for each pixel below which it'll be ignored. * Required for AF stats hardware configuration. * 3A version: * Default value: tunable * Data range: * Constraints: * Effect: */ 31, /* Variable name: max_h_num * maximum number of horizontal grids configurable in each ROI. * 3A version: * Default value: 18 * Data range: * Constraints: * Effect: */ 5, /* Variable name: max_v_num * maximum number of vertical grids configurable in each ROI. * 3A version: * Default value: 14 * Data range: * Constraints: * Effect: */ 5, /* Variable name: max_block_width * maximum width of each block in the grids. * 3A version: * Default value: to be read from datasheet * Data range: * Constraints: * Effect: */ 336, /* Variable name: max_block_height * maximum height of each block in the grids. * 3A version: * Default value: to be read from datasheet * Data range: * Constraints: * Effect: */ 252, /* Variable name: min_block_width * minimum width of each block in the grids. * 3A version: * Default value: to be read from datasheet * Data range: * Constraints: * Effect: */ 64, /* Variable name: min_block_height * minimum height of each block in the grids. * 3A version: * Default value: to be read from datasheet * Data range: * Constraints: * Effect: */ 48, /* Variable name: h_offset_ratio_normal_light * Horizontal location of first pixel in terms of the ratio to the * whole frame size. For example, image width is 1000, we want to use * the middle 500 as AF window. Horizontal offset ratio is * 250/1000=0.25. * 3A version: * Default value: 0.25 * Data range: * Constraints: * Effect: */ 0.30f, /* Variable name: v_offset_ratio_normal_light * Similar to Horizontal Offset Ratio, but this is in the veritcal direction. * whole frame size. * 3A version: * Default value: 0.25 * Data range: * Constraints: * Effect: */ 0.30f, /* Variable name: h_clip_ratio_normal_light * AF window horizontal size in terms of ratio to the whole image. For the * same example above, Horizontal Clip Ratio is 500/1000=0.5. * 3A version: * Default value: 0.5 * Data range: * Constraints: * Effect: */ 0.40f, /* Variable name: v_clip_ratio_normal_light * AF window veritical size in terms of ratio to the whole image. For the * same example above, Vertical Clip Ratio is 500/1000=0.5. * 3A version: * Default value: 0.5 * Data range: * Constraints: * Effect: */ 0.40f, /* Variable name: h_offset_ratio_low_light * Horizontal location of first pixel in terms of the ratio to the * whole frame size. For example, image width is 1000, we want to use * the middle 500 as AF window. Horizontal offset ratio is * 250/1000=0.25. * 3A version: * Default value: 0.25 * Data range: * Constraints: * Effect: */ 0.30f, /* Variable name: v_offset_ratio_low_light * Similar to Horizontal Offset Ratio, but this is in the veritcal direction. * whole frame size. * 3A version: * Default value: 0.25 * Data range: * Constraints: * Effect: */ 0.30f, /* Variable name: h_clip_ratio_low_light * AF window horizontal size in terms of ratio to the whole image. For the * same example above, Horizontal Clip Ratio is 500/1000=0.5. * 3A version: * Default value: 0.5 * Data range: * Constraints: * Effect: */ 0.40f, /* Variable name: v_clip_ratio_low_light * AF window veritical size in terms of ratio to the whole image. For the * same example above, Vertical Clip Ratio is 500/1000=0.5. * 3A version: * Default value: 0.5 * Data range: * Constraints: * Effect: */ 0.40f, /* Variable name: touch_scaling_factor_ normal_light * Factor by how much we will reduce the touch AF roi in addition to * clip ratio. * 3A version: * Default value: 0.5 * Data range: * Constraints: * Effect: */ 0.75f, /* Variable name: touch_scaling_factor_ low_light * Factor by how much we will reduce the touch AF roi in addition to * clip ratio. * 3A version: * Default value: 1.0 * Data range: * Constraints: * Effect: */ 0.75f, } , /* af_vfe_config_t */ /* af_vfe_hpf_t */ { /* af_vfe_legacy_hpf_t */ { /* Variable name: * Highpass filter coeffs used for focus value calculation. For 3x5 * kernel. Only 8 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -4, /* a00 */ -2, /* a02 */ -4, /* a04 */ -1, /* a20 */ -1, /* a21 */ 14, /* a22 */ -1, /* a23 */ -1, /* a24 */ }, /* af_vfe_legacy_hpf_t */ /* af_vfe_bayer_hpf_t */ { /* Variable name: * Highpass filter coeffs used for focus value calculation. For 2x5 * kernel, all 10 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -3, /* a00 */ 0, /* a01 */ 0, /* a02 */ 0, /* a03 */ -2, /* a04 */ 15, /* a10 */ 0, /* a11 */ 0, /* a12 */ 0, /* a13 */ -10, /* a14 */ }, /* af_vfe_bayer_hpf_t */ }, /* af_vfe_hpf_t default*/ /* af_vfe_hpf_t face*/ { /* af_vfe_legacy_hpf_t */ { /* Variable name: * Highpass filter coeffs used for focus value calculation. For 3x5 * kernel. Only 8 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -3, /* a00 */ 0, /* a02 */ -2, /* a04 */ 15, /* a20 */ 0, /* a21 */ 0, /* a22 */ 0, /* a23 */ -10, /* a24 */ } , /* af_vfe_legacy_hpf_t */ /* af_vfe_bayer_hpf_t */{ /* Variable name: * Highpass filter coeffs used for focus value calculation. For 2x5 * kernel, all 10 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -3, /* a00 */ 0, /* a01 */ 0, /* a02 */ 0, /* a03 */ -2, /* a04 */ 15, /* a10 */ 0, /* a11 */ 0, /* a12 */ 0, /* a13 */ -10, /* a14 */ } , /* af_vfe_bayer_hpf_t */ } , /* af_vfe_hpf_t face*/ /* af_vfe_hpf_t low_light*/ { /* af_vfe_legacy_hpf_t */ { /* Variable name: * Highpass filter coeffs used for focus value calculation. For 3x5 * kernel. Only 8 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -3, /* a00 */ 0, /* a02 */ -2, /* a04 */ 15, /* a20 */ 0, /* a21 */ 0, /* a22 */ 0, /* a23 */ -10, /* a24 */ } , /* af_vfe_legacy_hpf_t */ /* af_vfe_bayer_hpf_t */{ /* Variable name: * Highpass filter coeffs used for focus value calculation. For 2x5 * kernel, all 10 parameters are configurable. * 3A version: * Default value: * Data range: -16 to 15 * Constraints: * Effect: */ -4, /* a00 */ 0, /* a01 */ -2, /* a02 */ 0, /* a03 */ -4, /* a04 */ -1, /* a10 */ -1, /* a11 */ 14, /* a12 */ -1, /* a13 */ -1, /* a14 */ } , /* af_vfe_bayer_hpf_t */ } , /* af_vfe_hpf_t low_light*/ }, /*af_tuning_vfe_t */ /* actuator_params_t */ { /* i2c_addr */ 0xE4, /* i2c_data_type */ MSM_ACTUATOR_BYTE_DATA, /* i2c_addr_type */ MSM_ACTUATOR_BYTE_ADDR, /* act_type */ ACTUATOR_PIEZO, /* data_size */ 8, /* af_restore_pos */ 0, /* msm_actuator_reg_tbl_t */ { /* reg_tbl_size */ 1, /* msm_actuator_reg_params_t */ { /* reg_write_type;hw_mask; reg_addr; hw_shift >>; data_shift << */ {MSM_ACTUATOR_WRITE_DAC, 0x00000080, 0x0000, 0, 0}, }, }, /* init_setting_size */ 8, /* init_settings */ { {0x01, 0xA9}, {0x02, 0xD2}, {0x03, 0x0C}, {0x04, 0x14}, {0x05, 0xB6}, {0x06, 0x4F}, {0x00, 0x7F}, {0x00, 0x7F}, }, }, /* actuator_params_t */ /* actuator_tuned_params_t */ { /* scenario_size */ { /* scenario_size[MOVE_NEAR] */ 1, /* scenario_size[MOVE_FAR] */ 1, }, /* ringing_scenario */ { /* ringing_scenario[MOVE_NEAR] */ { 41, }, /* ringing_scenario[MOVE_FAR] */ { 41, }, }, /* intial_code */ 0x7F, /* region_size */ 1, /* near_end_lens_offset (in microns) */ 74, /* far_end_lens_offset (in microns) */ 41, /* region_params */ { /* step_bound[0] - macro side boundary */ /* step_bound[1] - infinity side boundary */ /* region 1 */ { .step_bound = {41, 0}, .code_per_step = 2, }, }, { /* damping */ { /* damping[MOVE_NEAR] */ { /* scenario 1 */ { /* region 1 */ { .damping_step = 0xFF, .damping_delay = 1500, .hw_params = 0x80, }, }, }, }, { /* damping[MOVE_FAR] */ { /* scenario 1 */ { /* region 1 */ { .damping_step = 0xFF, .damping_delay = 1500, .hw_params = 0x00, }, }, }, }, }, }, /* actuator_tuned_params_t */ },
[ "xinhe.jiang@itel-mobile.com" ]
xinhe.jiang@itel-mobile.com
b6dde019516be7e5a6b44901ab9e6c5361e9f4df
b0fc8ce34d5f52a314c481e91694f9e06efb7ab1
/src/player_a.c
febed3da2340664a0b7f7c1156a65717ad92d76b
[]
no_license
magalieV/Navy
e826e20beaa0a7a89c2e5a071477e3064dcf8e85
8a96720b4166812832e501ae857050173614807f
refs/heads/master
2022-04-08T13:04:17.014603
2020-02-29T22:04:42
2020-02-29T22:04:42
null
0
0
null
null
null
null
UTF-8
C
false
false
2,230
c
/* ** EPITECH PROJECT, 2019 ** player_a.c ** File description: ** first player doing */ #include "navi.h" static int const (*ps)(char *) = &my_putstr; static int const (*pf)(char *, ...) = &my_printf; static char * const (*rf)(char *, ...) = &my_rprintf; static char * const (*fr)(char *, ...) = &my_frprintf; extern int flux; int hit_or_miss_igtnm(int pid, int attack, char *line, char **map[2]) { send_msg(pid, attack); get_msg(pid); if (flux) { pf("%s: hit\n", line); map[1][(attack & 7) + 2][2 + (attack >> 3) * 2] = 'x'; return (1); } pf("%s: missed\n", line); map[1][(attack & 7) + 2][2 + (attack >> 3) * 2] = 'o'; return (0); } int play_turn(int pid, char **map[2], int w_value[2], int n) { char *tmp; char *line = rf(""); int attack = -1; while (attack == -1) { ps("attack: "); tmp = get_next_line(0); if (!tmp) return (send_msg(pid, 64) + 1); line = rf("%0!%!", line, tmp); if (my_strlen(line) == 2 && line[0] > 64 && line[0] < 73 && line[1] > 48 && line[1] < 57) attack = ((line[0] - 65) << 3) + line[1] - 49; else ps("wrong position\n"); } w_value[0] += hit_or_miss_igtnm(pid, attack, line, map); if (n) write(1, "\n", 1); return (free(line), 0); } int do_turn(int pid, char **map[2], int w_value[2], int n) { char cell; if (n) write(1, "\n", 1); ps("waiting for enemy's attack...\n"); get_msg(pid); if (flux == 64) return (1); cell = map[0][(flux & 7) + 2][2 + (flux >> 3) * 2]; if (cell > 49 && cell < 54) { pf("%c%d: hit\n\n", (flux >> 3) + 65, (flux & 7) + 1, w_value[1]++); map[0][(flux & 7) + 2][2 + (flux >> 3) * 2] = 'x'; send_msg(pid, 1); } else { pf("%c%d: missed\n\n", (flux >> 3) + 65, (flux & 7) + 1); if (cell != 'x') map[0][(flux & 7) + 2][2 + (flux >> 3) * 2] = 'o'; send_msg(pid, 0); } return (0); } int win(int pid, char **map[2], int w_value[2]) { if (w_value[0] == 14) { display_map(map); ps("I won\n"); flux = 0; return (1); } return (0); }
[ "magalie.vandenbriele@epitech.eu" ]
magalie.vandenbriele@epitech.eu
112beb73da3c61e94dc5a787282814bea996db9e
9338d2030e65d625fcb0a3fe7abaaa3e83a9bee9
/F407VG_TFT/TFT_fonts/Arial12x12.h
fe792cd0ea3f486740a2a9d424f173cfc918d8b6
[ "MIT" ]
permissive
jphuc96/F407VG_Codes
b6b01c4d6527c6b7307699295f1c625c1d2eaa97
d1e01ec7d86a4f984748ca8439c2f79bb6349f14
refs/heads/master
2021-04-12T12:04:40.117747
2018-04-21T07:18:46
2018-04-21T07:18:46
126,513,720
0
1
null
null
null
null
UTF-8
C
false
false
17,418
h
//GLCD FontName : Arial12x12 //GLCD FontSize : 12 x 12 /** Arial Font with 12*12 matrix to use with SPI_TFT lib */ const unsigned char Arial12x12[] __attribute__((aligned (2))) = { 25,12,12,2, // Length,horz,vert,byte/vert 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 0x02, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ! 0x03, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char " 0x07, 0x24, 0x00, 0xA4, 0x01, 0x7C, 0x00, 0xA7, 0x01, 0x7C, 0x00, 0x27, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char # 0x06, 0x00, 0x00, 0xCE, 0x00, 0x11, 0x01, 0xFF, 0x03, 0x11, 0x01, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char $ 0x0A, 0x00, 0x00, 0x0E, 0x00, 0x11, 0x00, 0x11, 0x01, 0xCE, 0x00, 0x38, 0x00, 0xE6, 0x00, 0x11, 0x01, 0x10, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char % 0x08, 0x00, 0x00, 0xE0, 0x00, 0x1E, 0x01, 0x11, 0x01, 0x29, 0x01, 0xC6, 0x00, 0xA0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char & 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ' 0x04, 0x00, 0x00, 0xF8, 0x00, 0x06, 0x03, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ( 0x03, 0x01, 0x04, 0x06, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ) 0x05, 0x02, 0x00, 0x0A, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char * 0x06, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7C, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char + 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char , 0x03, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char - 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char . 0x03, 0x80, 0x01, 0x7C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char / 0x06, 0x00, 0x00, 0xFE, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 0 0x06, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 1 0x06, 0x00, 0x00, 0x02, 0x01, 0x81, 0x01, 0x41, 0x01, 0x31, 0x01, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 2 0x06, 0x00, 0x00, 0x82, 0x00, 0x01, 0x01, 0x11, 0x01, 0x11, 0x01, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 3 0x06, 0x00, 0x00, 0x60, 0x00, 0x58, 0x00, 0x46, 0x00, 0xFF, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 4 0x06, 0x00, 0x00, 0x9C, 0x00, 0x0B, 0x01, 0x09, 0x01, 0x09, 0x01, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 5 0x06, 0x00, 0x00, 0xFE, 0x00, 0x11, 0x01, 0x09, 0x01, 0x09, 0x01, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 6 0x06, 0x00, 0x00, 0x01, 0x00, 0xC1, 0x01, 0x39, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 7 0x06, 0x00, 0x00, 0xEE, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 8 0x06, 0x00, 0x00, 0x9E, 0x00, 0x21, 0x01, 0x21, 0x01, 0x11, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 9 0x02, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char : 0x02, 0x00, 0x00, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ; 0x06, 0x00, 0x00, 0x10, 0x00, 0x28, 0x00, 0x28, 0x00, 0x44, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char < 0x06, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char = 0x06, 0x00, 0x00, 0x44, 0x00, 0x44, 0x00, 0x28, 0x00, 0x28, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char > 0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x61, 0x01, 0x11, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ? 0x0C, 0x00, 0x00, 0xF0, 0x01, 0x0C, 0x02, 0xE2, 0x04, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0xF1, 0x09, 0x19, 0x09, 0x02, 0x05, 0x86, 0x04, 0x78, 0x02, // Code for char @ 0x07, 0x80, 0x01, 0x70, 0x00, 0x2E, 0x00, 0x21, 0x00, 0x2E, 0x00, 0x70, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char A 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char B 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char C 0x08, 0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char D 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char E 0x06, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char F 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x92, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char G 0x08, 0x00, 0x00, 0xFF, 0x01, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char H 0x02, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char I 0x05, 0xC0, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char J 0x08, 0x00, 0x00, 0xFF, 0x01, 0x20, 0x00, 0x10, 0x00, 0x28, 0x00, 0x44, 0x00, 0x82, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char K 0x07, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char L 0x08, 0x00, 0x00, 0xFF, 0x01, 0x06, 0x00, 0x78, 0x00, 0x80, 0x01, 0x78, 0x00, 0x06, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char M 0x08, 0x00, 0x00, 0xFF, 0x01, 0x02, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x60, 0x00, 0x80, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char N 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char O 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char P 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x41, 0x01, 0x41, 0x01, 0x82, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Q 0x08, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x31, 0x00, 0xD1, 0x00, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char R 0x07, 0x00, 0x00, 0xCE, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char S 0x07, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char T 0x08, 0x00, 0x00, 0x7F, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x80, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char U 0x07, 0x03, 0x00, 0x1C, 0x00, 0x60, 0x00, 0x80, 0x01, 0x60, 0x00, 0x1C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char V 0x0B, 0x07, 0x00, 0x78, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x70, 0x00, 0x80, 0x01, 0x7C, 0x00, 0x03, 0x00, 0x00, 0x00, // Code for char W 0x07, 0x01, 0x01, 0xC6, 0x00, 0x28, 0x00, 0x10, 0x00, 0x28, 0x00, 0xC6, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char X 0x07, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0xF0, 0x01, 0x08, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Y 0x07, 0x00, 0x01, 0x81, 0x01, 0x61, 0x01, 0x11, 0x01, 0x0D, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Z 0x03, 0x00, 0x00, 0xFF, 0x07, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char [ 0x03, 0x03, 0x00, 0x7C, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char BackSlash 0x02, 0x01, 0x04, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ] 0x05, 0x18, 0x00, 0x06, 0x00, 0x01, 0x00, 0x06, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ^ 0x07, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char _ 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ` 0x06, 0x00, 0x00, 0xC8, 0x00, 0x24, 0x01, 0x24, 0x01, 0xA4, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char a 0x06, 0x00, 0x00, 0xFF, 0x01, 0x88, 0x00, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char b 0x05, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char c 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x08, 0x01, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char d 0x06, 0x00, 0x00, 0xF8, 0x00, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char e 0x04, 0x04, 0x00, 0xFE, 0x01, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char f 0x06, 0x00, 0x00, 0xF8, 0x04, 0x04, 0x05, 0x04, 0x05, 0x88, 0x04, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char g 0x06, 0x00, 0x00, 0xFF, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char h 0x02, 0x00, 0x00, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char i 0x02, 0x00, 0x04, 0xFD, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char j 0x06, 0x00, 0x00, 0xFF, 0x01, 0x20, 0x00, 0x30, 0x00, 0xC8, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char k 0x02, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char l 0x0A, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, // Code for char m 0x06, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char n 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char o 0x06, 0x00, 0x00, 0xFC, 0x07, 0x88, 0x00, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char p 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x88, 0x00, 0xFC, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char q 0x04, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char r 0x06, 0x00, 0x00, 0x98, 0x00, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char s 0x03, 0x04, 0x00, 0xFF, 0x01, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char t 0x06, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char u 0x05, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char v 0x09, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char w 0x05, 0x04, 0x01, 0xD8, 0x00, 0x20, 0x00, 0xD8, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char x 0x05, 0x0C, 0x00, 0x70, 0x04, 0x80, 0x03, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char y 0x05, 0x04, 0x01, 0xC4, 0x01, 0x24, 0x01, 0x1C, 0x01, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char z 0x03, 0x20, 0x00, 0xDE, 0x03, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char { 0x02, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char | 0x04, 0x00, 0x00, 0x01, 0x04, 0xDE, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char } 0x07, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x10, 0x00, 0x20, 0x00, 0x20, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ~ 0x08, 0x00, 0x00, 0xFE, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char  };
[ "jphuc96@gmail.com" ]
jphuc96@gmail.com
0a05bb2cb07de2fc0ba7b2a6e7ba72b8bec3566f
909df5e29f5249b7ee1b12a3668148f8b5436fd4
/lib/fudge/ring.h
09208bf75b5d2be92325d3781949944709923461
[ "MIT" ]
permissive
jezze/fudge
4d9965a87c937ee0bd8feb505179cc2bd61e655a
7407284297b87c3005428adaaa1d1e0c55d4d6fe
refs/heads/master
2023-08-02T14:34:04.859847
2023-08-01T17:54:29
2023-08-01T17:54:29
229,070
72
15
MIT
2022-07-23T19:10:57
2009-06-16T22:24:23
C
UTF-8
C
false
false
1,782
h
struct ring { char *buffer; unsigned int capacity; unsigned int head; unsigned int tail; }; unsigned int ring_count(struct ring *ring); unsigned int ring_avail(struct ring *ring); unsigned int ring_isempty(struct ring *ring); unsigned int ring_isfull(struct ring *ring); unsigned int ring_skip(struct ring *ring, unsigned int count); unsigned int ring_skip_reverse(struct ring *ring, unsigned int count); unsigned int ring_read(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_read_all(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_read_reverse(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_read_allreverse(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_readcopy(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_write(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_write_all(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_write_reverse(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_write_allreverse(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_overwrite(struct ring *ring, void *buffer, unsigned int count); unsigned int ring_move(struct ring *to, struct ring *from); unsigned int ring_overmove(struct ring *to, struct ring *from); unsigned int ring_copy(struct ring *to, struct ring *from); unsigned int ring_overcopy(struct ring *to, struct ring *from); unsigned int ring_each(struct ring *ring, char value); unsigned int ring_find(struct ring *ring, char value); unsigned int ring_find_reverse(struct ring *ring, char value); void ring_reset(struct ring *ring); void ring_init(struct ring *ring, unsigned int capacity, void *buffer);
[ "jens.nyberg@gmail.com" ]
jens.nyberg@gmail.com
14786e69a60777d22ddb7e268d17c3c9f6bee4c0
3a010a5439665eaac793a9248b322d1f6b3fbe84
/Src/Math/mathtool.h
1bc2358ce82100ec0c1508e62872e60dd4afb587
[]
no_license
Huasheng-hou/Algorithms
a3df7830c81a90c51fce70a2c7cc602568a007cb
e13b1592a6c2974005f7734646e1d3a42e86eda3
refs/heads/master
2020-04-16T04:00:52.636942
2019-07-06T08:35:22
2019-07-06T08:35:22
165,252,421
0
0
null
null
null
null
UTF-8
C
false
false
216
h
// // mathtool.h // Algorithms // // Created by apple on 2019/5/31. // Copyright © 2019 华生侯. All rights reserved. // #ifndef mathtool_h #define mathtool_h int gcd(int a, int b); #endif /* mathtool_h */
[ "331292108@qq.com" ]
331292108@qq.com
c53939460643e158ebf32ff6c3f646c00b48f3bf
3079356ad80009d009782a2386a6bdc2ef59f2fd
/Xilinxs/LR1/isim/Test_top_isim_beh.exe.sim/work/m_00000000000530879313_2412534358.c
0b240e17e54d502d81e6e61d412657663168a1ff
[]
no_license
mrkriv/Laboratory
3cadd98b805e316a2e3f8dc262ec4c85f0c55d4f
f453bdf7381c4b06dcb423778a2292b80e7a685c
refs/heads/master
2020-05-21T12:27:47.820844
2017-10-01T15:07:44
2017-10-01T15:07:44
54,062,460
1
2
null
null
null
null
UTF-8
C
false
false
109,144
c
/**********************************************************************/ /* ____ ____ */ /* / /\/ / */ /* /___/ \ / */ /* \ \ \/ */ /* \ \ Copyright (c) 2003-2009 Xilinx, Inc. */ /* / / All Right Reserved. */ /* /---/ /\ */ /* \ \ / \ */ /* \___\/\___\ */ /***********************************************************************/ /* This file is designed for use with ISim build 0x7708f090 */ #define XSI_HIDE_SYMBOL_SPEC true #include "xsi.h" #include <memory.h> #ifdef __GNUC__ #include <stdlib.h> #else #include <malloc.h> #define alloca _alloca #endif static const char *ng0 = "C:/Users/admin/Documents/Visual Studio 2015/Projects/Laboratory/Xilinxs/LR1_K/KNF.v"; static void Cont_8_0(char *t0) { char t3[8]; char t5[8]; char t30[8]; char t33[8]; char t58[8]; char t88[8]; char t96[8]; char t99[8]; char t124[8]; char t154[8]; char t162[8]; char t190[8]; char t222[8]; char t225[8]; char t252[8]; char t260[8]; char t290[8]; char t298[8]; char t326[8]; char t358[8]; char t361[8]; char t386[8]; char t389[8]; char t414[8]; char t442[8]; char t445[8]; char t470[8]; char t498[8]; char *t1; char *t2; char *t4; char *t6; unsigned int t7; unsigned int t8; unsigned int t9; unsigned int t10; unsigned int t11; unsigned int t12; char *t13; unsigned int t14; unsigned int t15; unsigned int t16; unsigned int t17; unsigned int t18; char *t19; char *t20; char *t21; unsigned int t22; unsigned int t23; unsigned int t24; unsigned int t25; unsigned int t26; unsigned int t27; unsigned int t28; unsigned int t29; char *t31; char *t32; char *t34; unsigned int t35; unsigned int t36; unsigned int t37; unsigned int t38; unsigned int t39; unsigned int t40; char *t41; unsigned int t42; unsigned int t43; unsigned int t44; unsigned int t45; unsigned int t46; char *t47; char *t48; char *t49; unsigned int t50; unsigned int t51; unsigned int t52; unsigned int t53; unsigned int t54; unsigned int t55; unsigned int t56; unsigned int t57; unsigned int t59; unsigned int t60; unsigned int t61; char *t62; char *t63; char *t64; unsigned int t65; unsigned int t66; unsigned int t67; unsigned int t68; unsigned int t69; unsigned int t70; unsigned int t71; char *t72; char *t73; unsigned int t74; unsigned int t75; unsigned int t76; int t77; unsigned int t78; unsigned int t79; unsigned int t80; int t81; unsigned int t82; unsigned int t83; unsigned int t84; unsigned int t85; char *t86; char *t87; char *t89; unsigned int t90; unsigned int t91; unsigned int t92; unsigned int t93; unsigned int t94; unsigned int t95; char *t97; char *t98; char *t100; unsigned int t101; unsigned int t102; unsigned int t103; unsigned int t104; unsigned int t105; unsigned int t106; char *t107; unsigned int t108; unsigned int t109; unsigned int t110; unsigned int t111; unsigned int t112; char *t113; char *t114; char *t115; unsigned int t116; unsigned int t117; unsigned int t118; unsigned int t119; unsigned int t120; unsigned int t121; unsigned int t122; unsigned int t123; unsigned int t125; unsigned int t126; unsigned int t127; char *t128; char *t129; char *t130; unsigned int t131; unsigned int t132; unsigned int t133; unsigned int t134; unsigned int t135; unsigned int t136; unsigned int t137; char *t138; char *t139; unsigned int t140; unsigned int t141; unsigned int t142; int t143; unsigned int t144; unsigned int t145; unsigned int t146; int t147; unsigned int t148; unsigned int t149; unsigned int t150; unsigned int t151; char *t152; char *t153; char *t155; unsigned int t156; unsigned int t157; unsigned int t158; unsigned int t159; unsigned int t160; unsigned int t161; unsigned int t163; unsigned int t164; unsigned int t165; char *t166; char *t167; char *t168; unsigned int t169; unsigned int t170; unsigned int t171; unsigned int t172; unsigned int t173; unsigned int t174; unsigned int t175; char *t176; char *t177; unsigned int t178; unsigned int t179; unsigned int t180; int t181; unsigned int t182; unsigned int t183; unsigned int t184; int t185; unsigned int t186; unsigned int t187; unsigned int t188; unsigned int t189; unsigned int t191; unsigned int t192; unsigned int t193; char *t194; char *t195; char *t196; unsigned int t197; unsigned int t198; unsigned int t199; unsigned int t200; unsigned int t201; unsigned int t202; unsigned int t203; char *t204; char *t205; unsigned int t206; unsigned int t207; unsigned int t208; unsigned int t209; unsigned int t210; unsigned int t211; unsigned int t212; unsigned int t213; int t214; int t215; unsigned int t216; unsigned int t217; unsigned int t218; unsigned int t219; unsigned int t220; unsigned int t221; char *t223; char *t224; char *t226; unsigned int t227; unsigned int t228; unsigned int t229; unsigned int t230; unsigned int t231; unsigned int t232; char *t233; unsigned int t234; unsigned int t235; unsigned int t236; unsigned int t237; unsigned int t238; char *t239; char *t240; char *t241; unsigned int t242; unsigned int t243; unsigned int t244; unsigned int t245; unsigned int t246; unsigned int t247; unsigned int t248; unsigned int t249; char *t250; char *t251; char *t253; unsigned int t254; unsigned int t255; unsigned int t256; unsigned int t257; unsigned int t258; unsigned int t259; unsigned int t261; unsigned int t262; unsigned int t263; char *t264; char *t265; char *t266; unsigned int t267; unsigned int t268; unsigned int t269; unsigned int t270; unsigned int t271; unsigned int t272; unsigned int t273; char *t274; char *t275; unsigned int t276; unsigned int t277; unsigned int t278; int t279; unsigned int t280; unsigned int t281; unsigned int t282; int t283; unsigned int t284; unsigned int t285; unsigned int t286; unsigned int t287; char *t288; char *t289; char *t291; unsigned int t292; unsigned int t293; unsigned int t294; unsigned int t295; unsigned int t296; unsigned int t297; unsigned int t299; unsigned int t300; unsigned int t301; char *t302; char *t303; char *t304; unsigned int t305; unsigned int t306; unsigned int t307; unsigned int t308; unsigned int t309; unsigned int t310; unsigned int t311; char *t312; char *t313; unsigned int t314; unsigned int t315; unsigned int t316; int t317; unsigned int t318; unsigned int t319; unsigned int t320; int t321; unsigned int t322; unsigned int t323; unsigned int t324; unsigned int t325; unsigned int t327; unsigned int t328; unsigned int t329; char *t330; char *t331; char *t332; unsigned int t333; unsigned int t334; unsigned int t335; unsigned int t336; unsigned int t337; unsigned int t338; unsigned int t339; char *t340; char *t341; unsigned int t342; unsigned int t343; unsigned int t344; unsigned int t345; unsigned int t346; unsigned int t347; unsigned int t348; unsigned int t349; int t350; int t351; unsigned int t352; unsigned int t353; unsigned int t354; unsigned int t355; unsigned int t356; unsigned int t357; char *t359; char *t360; char *t362; unsigned int t363; unsigned int t364; unsigned int t365; unsigned int t366; unsigned int t367; unsigned int t368; char *t369; unsigned int t370; unsigned int t371; unsigned int t372; unsigned int t373; unsigned int t374; char *t375; char *t376; char *t377; unsigned int t378; unsigned int t379; unsigned int t380; unsigned int t381; unsigned int t382; unsigned int t383; unsigned int t384; unsigned int t385; char *t387; char *t388; char *t390; unsigned int t391; unsigned int t392; unsigned int t393; unsigned int t394; unsigned int t395; unsigned int t396; char *t397; unsigned int t398; unsigned int t399; unsigned int t400; unsigned int t401; unsigned int t402; char *t403; char *t404; char *t405; unsigned int t406; unsigned int t407; unsigned int t408; unsigned int t409; unsigned int t410; unsigned int t411; unsigned int t412; unsigned int t413; unsigned int t415; unsigned int t416; unsigned int t417; char *t418; char *t419; char *t420; unsigned int t421; unsigned int t422; unsigned int t423; unsigned int t424; unsigned int t425; unsigned int t426; unsigned int t427; char *t428; char *t429; unsigned int t430; unsigned int t431; unsigned int t432; int t433; unsigned int t434; unsigned int t435; unsigned int t436; int t437; unsigned int t438; unsigned int t439; unsigned int t440; unsigned int t441; char *t443; char *t444; char *t446; unsigned int t447; unsigned int t448; unsigned int t449; unsigned int t450; unsigned int t451; unsigned int t452; char *t453; unsigned int t454; unsigned int t455; unsigned int t456; unsigned int t457; unsigned int t458; char *t459; char *t460; char *t461; unsigned int t462; unsigned int t463; unsigned int t464; unsigned int t465; unsigned int t466; unsigned int t467; unsigned int t468; unsigned int t469; unsigned int t471; unsigned int t472; unsigned int t473; char *t474; char *t475; char *t476; unsigned int t477; unsigned int t478; unsigned int t479; unsigned int t480; unsigned int t481; unsigned int t482; unsigned int t483; char *t484; char *t485; unsigned int t486; unsigned int t487; unsigned int t488; int t489; unsigned int t490; unsigned int t491; unsigned int t492; int t493; unsigned int t494; unsigned int t495; unsigned int t496; unsigned int t497; unsigned int t499; unsigned int t500; unsigned int t501; char *t502; char *t503; char *t504; unsigned int t505; unsigned int t506; unsigned int t507; unsigned int t508; unsigned int t509; unsigned int t510; unsigned int t511; char *t512; char *t513; unsigned int t514; unsigned int t515; unsigned int t516; unsigned int t517; unsigned int t518; unsigned int t519; unsigned int t520; unsigned int t521; int t522; int t523; unsigned int t524; unsigned int t525; unsigned int t526; unsigned int t527; unsigned int t528; unsigned int t529; char *t530; char *t531; char *t532; char *t533; char *t534; unsigned int t535; unsigned int t536; char *t537; unsigned int t538; unsigned int t539; char *t540; unsigned int t541; unsigned int t542; char *t543; LAB0: t1 = (t0 + 2368U); t2 = *((char **)t1); if (t2 == 0) goto LAB2; LAB3: goto *t2; LAB2: xsi_set_current_line(8, ng0); t2 = (t0 + 1048U); t4 = *((char **)t2); memset(t5, 0, 8); t2 = (t5 + 4); t6 = (t4 + 4); t7 = *((unsigned int *)t4); t8 = (t7 >> 2); t9 = (t8 & 1); *((unsigned int *)t5) = t9; t10 = *((unsigned int *)t6); t11 = (t10 >> 2); t12 = (t11 & 1); *((unsigned int *)t2) = t12; memset(t3, 0, 8); t13 = (t5 + 4); t14 = *((unsigned int *)t13); t15 = (~(t14)); t16 = *((unsigned int *)t5); t17 = (t16 & t15); t18 = (t17 & 1U); if (t18 != 0) goto LAB7; LAB5: if (*((unsigned int *)t13) == 0) goto LAB4; LAB6: t19 = (t3 + 4); *((unsigned int *)t3) = 1; *((unsigned int *)t19) = 1; LAB7: t20 = (t3 + 4); t21 = (t5 + 4); t22 = *((unsigned int *)t5); t23 = (~(t22)); *((unsigned int *)t3) = t23; *((unsigned int *)t20) = 0; if (*((unsigned int *)t21) != 0) goto LAB9; LAB8: t28 = *((unsigned int *)t3); *((unsigned int *)t3) = (t28 & 1U); t29 = *((unsigned int *)t20); *((unsigned int *)t20) = (t29 & 1U); t31 = (t0 + 1048U); t32 = *((char **)t31); memset(t33, 0, 8); t31 = (t33 + 4); t34 = (t32 + 4); t35 = *((unsigned int *)t32); t36 = (t35 >> 0); t37 = (t36 & 1); *((unsigned int *)t33) = t37; t38 = *((unsigned int *)t34); t39 = (t38 >> 0); t40 = (t39 & 1); *((unsigned int *)t31) = t40; memset(t30, 0, 8); t41 = (t33 + 4); t42 = *((unsigned int *)t41); t43 = (~(t42)); t44 = *((unsigned int *)t33); t45 = (t44 & t43); t46 = (t45 & 1U); if (t46 != 0) goto LAB13; LAB11: if (*((unsigned int *)t41) == 0) goto LAB10; LAB12: t47 = (t30 + 4); *((unsigned int *)t30) = 1; *((unsigned int *)t47) = 1; LAB13: t48 = (t30 + 4); t49 = (t33 + 4); t50 = *((unsigned int *)t33); t51 = (~(t50)); *((unsigned int *)t30) = t51; *((unsigned int *)t48) = 0; if (*((unsigned int *)t49) != 0) goto LAB15; LAB14: t56 = *((unsigned int *)t30); *((unsigned int *)t30) = (t56 & 1U); t57 = *((unsigned int *)t48); *((unsigned int *)t48) = (t57 & 1U); t59 = *((unsigned int *)t3); t60 = *((unsigned int *)t30); t61 = (t59 | t60); *((unsigned int *)t58) = t61; t62 = (t3 + 4); t63 = (t30 + 4); t64 = (t58 + 4); t65 = *((unsigned int *)t62); t66 = *((unsigned int *)t63); t67 = (t65 | t66); *((unsigned int *)t64) = t67; t68 = *((unsigned int *)t64); t69 = (t68 != 0); if (t69 == 1) goto LAB16; LAB17: LAB18: t86 = (t0 + 1048U); t87 = *((char **)t86); memset(t88, 0, 8); t86 = (t88 + 4); t89 = (t87 + 4); t90 = *((unsigned int *)t87); t91 = (t90 >> 2); t92 = (t91 & 1); *((unsigned int *)t88) = t92; t93 = *((unsigned int *)t89); t94 = (t93 >> 2); t95 = (t94 & 1); *((unsigned int *)t86) = t95; t97 = (t0 + 1048U); t98 = *((char **)t97); memset(t99, 0, 8); t97 = (t99 + 4); t100 = (t98 + 4); t101 = *((unsigned int *)t98); t102 = (t101 >> 1); t103 = (t102 & 1); *((unsigned int *)t99) = t103; t104 = *((unsigned int *)t100); t105 = (t104 >> 1); t106 = (t105 & 1); *((unsigned int *)t97) = t106; memset(t96, 0, 8); t107 = (t99 + 4); t108 = *((unsigned int *)t107); t109 = (~(t108)); t110 = *((unsigned int *)t99); t111 = (t110 & t109); t112 = (t111 & 1U); if (t112 != 0) goto LAB22; LAB20: if (*((unsigned int *)t107) == 0) goto LAB19; LAB21: t113 = (t96 + 4); *((unsigned int *)t96) = 1; *((unsigned int *)t113) = 1; LAB22: t114 = (t96 + 4); t115 = (t99 + 4); t116 = *((unsigned int *)t99); t117 = (~(t116)); *((unsigned int *)t96) = t117; *((unsigned int *)t114) = 0; if (*((unsigned int *)t115) != 0) goto LAB24; LAB23: t122 = *((unsigned int *)t96); *((unsigned int *)t96) = (t122 & 1U); t123 = *((unsigned int *)t114); *((unsigned int *)t114) = (t123 & 1U); t125 = *((unsigned int *)t88); t126 = *((unsigned int *)t96); t127 = (t125 | t126); *((unsigned int *)t124) = t127; t128 = (t88 + 4); t129 = (t96 + 4); t130 = (t124 + 4); t131 = *((unsigned int *)t128); t132 = *((unsigned int *)t129); t133 = (t131 | t132); *((unsigned int *)t130) = t133; t134 = *((unsigned int *)t130); t135 = (t134 != 0); if (t135 == 1) goto LAB25; LAB26: LAB27: t152 = (t0 + 1048U); t153 = *((char **)t152); memset(t154, 0, 8); t152 = (t154 + 4); t155 = (t153 + 4); t156 = *((unsigned int *)t153); t157 = (t156 >> 0); t158 = (t157 & 1); *((unsigned int *)t154) = t158; t159 = *((unsigned int *)t155); t160 = (t159 >> 0); t161 = (t160 & 1); *((unsigned int *)t152) = t161; t163 = *((unsigned int *)t124); t164 = *((unsigned int *)t154); t165 = (t163 | t164); *((unsigned int *)t162) = t165; t166 = (t124 + 4); t167 = (t154 + 4); t168 = (t162 + 4); t169 = *((unsigned int *)t166); t170 = *((unsigned int *)t167); t171 = (t169 | t170); *((unsigned int *)t168) = t171; t172 = *((unsigned int *)t168); t173 = (t172 != 0); if (t173 == 1) goto LAB28; LAB29: LAB30: t191 = *((unsigned int *)t58); t192 = *((unsigned int *)t162); t193 = (t191 & t192); *((unsigned int *)t190) = t193; t194 = (t58 + 4); t195 = (t162 + 4); t196 = (t190 + 4); t197 = *((unsigned int *)t194); t198 = *((unsigned int *)t195); t199 = (t197 | t198); *((unsigned int *)t196) = t199; t200 = *((unsigned int *)t196); t201 = (t200 != 0); if (t201 == 1) goto LAB31; LAB32: LAB33: t223 = (t0 + 1048U); t224 = *((char **)t223); memset(t225, 0, 8); t223 = (t225 + 4); t226 = (t224 + 4); t227 = *((unsigned int *)t224); t228 = (t227 >> 3); t229 = (t228 & 1); *((unsigned int *)t225) = t229; t230 = *((unsigned int *)t226); t231 = (t230 >> 3); t232 = (t231 & 1); *((unsigned int *)t223) = t232; memset(t222, 0, 8); t233 = (t225 + 4); t234 = *((unsigned int *)t233); t235 = (~(t234)); t236 = *((unsigned int *)t225); t237 = (t236 & t235); t238 = (t237 & 1U); if (t238 != 0) goto LAB37; LAB35: if (*((unsigned int *)t233) == 0) goto LAB34; LAB36: t239 = (t222 + 4); *((unsigned int *)t222) = 1; *((unsigned int *)t239) = 1; LAB37: t240 = (t222 + 4); t241 = (t225 + 4); t242 = *((unsigned int *)t225); t243 = (~(t242)); *((unsigned int *)t222) = t243; *((unsigned int *)t240) = 0; if (*((unsigned int *)t241) != 0) goto LAB39; LAB38: t248 = *((unsigned int *)t222); *((unsigned int *)t222) = (t248 & 1U); t249 = *((unsigned int *)t240); *((unsigned int *)t240) = (t249 & 1U); t250 = (t0 + 1048U); t251 = *((char **)t250); memset(t252, 0, 8); t250 = (t252 + 4); t253 = (t251 + 4); t254 = *((unsigned int *)t251); t255 = (t254 >> 2); t256 = (t255 & 1); *((unsigned int *)t252) = t256; t257 = *((unsigned int *)t253); t258 = (t257 >> 2); t259 = (t258 & 1); *((unsigned int *)t250) = t259; t261 = *((unsigned int *)t222); t262 = *((unsigned int *)t252); t263 = (t261 | t262); *((unsigned int *)t260) = t263; t264 = (t222 + 4); t265 = (t252 + 4); t266 = (t260 + 4); t267 = *((unsigned int *)t264); t268 = *((unsigned int *)t265); t269 = (t267 | t268); *((unsigned int *)t266) = t269; t270 = *((unsigned int *)t266); t271 = (t270 != 0); if (t271 == 1) goto LAB40; LAB41: LAB42: t288 = (t0 + 1048U); t289 = *((char **)t288); memset(t290, 0, 8); t288 = (t290 + 4); t291 = (t289 + 4); t292 = *((unsigned int *)t289); t293 = (t292 >> 0); t294 = (t293 & 1); *((unsigned int *)t290) = t294; t295 = *((unsigned int *)t291); t296 = (t295 >> 0); t297 = (t296 & 1); *((unsigned int *)t288) = t297; t299 = *((unsigned int *)t260); t300 = *((unsigned int *)t290); t301 = (t299 | t300); *((unsigned int *)t298) = t301; t302 = (t260 + 4); t303 = (t290 + 4); t304 = (t298 + 4); t305 = *((unsigned int *)t302); t306 = *((unsigned int *)t303); t307 = (t305 | t306); *((unsigned int *)t304) = t307; t308 = *((unsigned int *)t304); t309 = (t308 != 0); if (t309 == 1) goto LAB43; LAB44: LAB45: t327 = *((unsigned int *)t190); t328 = *((unsigned int *)t298); t329 = (t327 & t328); *((unsigned int *)t326) = t329; t330 = (t190 + 4); t331 = (t298 + 4); t332 = (t326 + 4); t333 = *((unsigned int *)t330); t334 = *((unsigned int *)t331); t335 = (t333 | t334); *((unsigned int *)t332) = t335; t336 = *((unsigned int *)t332); t337 = (t336 != 0); if (t337 == 1) goto LAB46; LAB47: LAB48: t359 = (t0 + 1048U); t360 = *((char **)t359); memset(t361, 0, 8); t359 = (t361 + 4); t362 = (t360 + 4); t363 = *((unsigned int *)t360); t364 = (t363 >> 3); t365 = (t364 & 1); *((unsigned int *)t361) = t365; t366 = *((unsigned int *)t362); t367 = (t366 >> 3); t368 = (t367 & 1); *((unsigned int *)t359) = t368; memset(t358, 0, 8); t369 = (t361 + 4); t370 = *((unsigned int *)t369); t371 = (~(t370)); t372 = *((unsigned int *)t361); t373 = (t372 & t371); t374 = (t373 & 1U); if (t374 != 0) goto LAB52; LAB50: if (*((unsigned int *)t369) == 0) goto LAB49; LAB51: t375 = (t358 + 4); *((unsigned int *)t358) = 1; *((unsigned int *)t375) = 1; LAB52: t376 = (t358 + 4); t377 = (t361 + 4); t378 = *((unsigned int *)t361); t379 = (~(t378)); *((unsigned int *)t358) = t379; *((unsigned int *)t376) = 0; if (*((unsigned int *)t377) != 0) goto LAB54; LAB53: t384 = *((unsigned int *)t358); *((unsigned int *)t358) = (t384 & 1U); t385 = *((unsigned int *)t376); *((unsigned int *)t376) = (t385 & 1U); t387 = (t0 + 1048U); t388 = *((char **)t387); memset(t389, 0, 8); t387 = (t389 + 4); t390 = (t388 + 4); t391 = *((unsigned int *)t388); t392 = (t391 >> 1); t393 = (t392 & 1); *((unsigned int *)t389) = t393; t394 = *((unsigned int *)t390); t395 = (t394 >> 1); t396 = (t395 & 1); *((unsigned int *)t387) = t396; memset(t386, 0, 8); t397 = (t389 + 4); t398 = *((unsigned int *)t397); t399 = (~(t398)); t400 = *((unsigned int *)t389); t401 = (t400 & t399); t402 = (t401 & 1U); if (t402 != 0) goto LAB58; LAB56: if (*((unsigned int *)t397) == 0) goto LAB55; LAB57: t403 = (t386 + 4); *((unsigned int *)t386) = 1; *((unsigned int *)t403) = 1; LAB58: t404 = (t386 + 4); t405 = (t389 + 4); t406 = *((unsigned int *)t389); t407 = (~(t406)); *((unsigned int *)t386) = t407; *((unsigned int *)t404) = 0; if (*((unsigned int *)t405) != 0) goto LAB60; LAB59: t412 = *((unsigned int *)t386); *((unsigned int *)t386) = (t412 & 1U); t413 = *((unsigned int *)t404); *((unsigned int *)t404) = (t413 & 1U); t415 = *((unsigned int *)t358); t416 = *((unsigned int *)t386); t417 = (t415 | t416); *((unsigned int *)t414) = t417; t418 = (t358 + 4); t419 = (t386 + 4); t420 = (t414 + 4); t421 = *((unsigned int *)t418); t422 = *((unsigned int *)t419); t423 = (t421 | t422); *((unsigned int *)t420) = t423; t424 = *((unsigned int *)t420); t425 = (t424 != 0); if (t425 == 1) goto LAB61; LAB62: LAB63: t443 = (t0 + 1048U); t444 = *((char **)t443); memset(t445, 0, 8); t443 = (t445 + 4); t446 = (t444 + 4); t447 = *((unsigned int *)t444); t448 = (t447 >> 0); t449 = (t448 & 1); *((unsigned int *)t445) = t449; t450 = *((unsigned int *)t446); t451 = (t450 >> 0); t452 = (t451 & 1); *((unsigned int *)t443) = t452; memset(t442, 0, 8); t453 = (t445 + 4); t454 = *((unsigned int *)t453); t455 = (~(t454)); t456 = *((unsigned int *)t445); t457 = (t456 & t455); t458 = (t457 & 1U); if (t458 != 0) goto LAB67; LAB65: if (*((unsigned int *)t453) == 0) goto LAB64; LAB66: t459 = (t442 + 4); *((unsigned int *)t442) = 1; *((unsigned int *)t459) = 1; LAB67: t460 = (t442 + 4); t461 = (t445 + 4); t462 = *((unsigned int *)t445); t463 = (~(t462)); *((unsigned int *)t442) = t463; *((unsigned int *)t460) = 0; if (*((unsigned int *)t461) != 0) goto LAB69; LAB68: t468 = *((unsigned int *)t442); *((unsigned int *)t442) = (t468 & 1U); t469 = *((unsigned int *)t460); *((unsigned int *)t460) = (t469 & 1U); t471 = *((unsigned int *)t414); t472 = *((unsigned int *)t442); t473 = (t471 | t472); *((unsigned int *)t470) = t473; t474 = (t414 + 4); t475 = (t442 + 4); t476 = (t470 + 4); t477 = *((unsigned int *)t474); t478 = *((unsigned int *)t475); t479 = (t477 | t478); *((unsigned int *)t476) = t479; t480 = *((unsigned int *)t476); t481 = (t480 != 0); if (t481 == 1) goto LAB70; LAB71: LAB72: t499 = *((unsigned int *)t326); t500 = *((unsigned int *)t470); t501 = (t499 & t500); *((unsigned int *)t498) = t501; t502 = (t326 + 4); t503 = (t470 + 4); t504 = (t498 + 4); t505 = *((unsigned int *)t502); t506 = *((unsigned int *)t503); t507 = (t505 | t506); *((unsigned int *)t504) = t507; t508 = *((unsigned int *)t504); t509 = (t508 != 0); if (t509 == 1) goto LAB73; LAB74: LAB75: t530 = (t0 + 3560); t531 = (t530 + 56U); t532 = *((char **)t531); t533 = (t532 + 56U); t534 = *((char **)t533); memset(t534, 0, 8); t535 = 1U; t536 = t535; t537 = (t498 + 4); t538 = *((unsigned int *)t498); t535 = (t535 & t538); t539 = *((unsigned int *)t537); t536 = (t536 & t539); t540 = (t534 + 4); t541 = *((unsigned int *)t534); *((unsigned int *)t534) = (t541 | t535); t542 = *((unsigned int *)t540); *((unsigned int *)t540) = (t542 | t536); xsi_driver_vfirst_trans(t530, 0, 0); t543 = (t0 + 3432); *((int *)t543) = 1; LAB1: return; LAB4: *((unsigned int *)t3) = 1; goto LAB7; LAB9: t24 = *((unsigned int *)t3); t25 = *((unsigned int *)t21); *((unsigned int *)t3) = (t24 | t25); t26 = *((unsigned int *)t20); t27 = *((unsigned int *)t21); *((unsigned int *)t20) = (t26 | t27); goto LAB8; LAB10: *((unsigned int *)t30) = 1; goto LAB13; LAB15: t52 = *((unsigned int *)t30); t53 = *((unsigned int *)t49); *((unsigned int *)t30) = (t52 | t53); t54 = *((unsigned int *)t48); t55 = *((unsigned int *)t49); *((unsigned int *)t48) = (t54 | t55); goto LAB14; LAB16: t70 = *((unsigned int *)t58); t71 = *((unsigned int *)t64); *((unsigned int *)t58) = (t70 | t71); t72 = (t3 + 4); t73 = (t30 + 4); t74 = *((unsigned int *)t72); t75 = (~(t74)); t76 = *((unsigned int *)t3); t77 = (t76 & t75); t78 = *((unsigned int *)t73); t79 = (~(t78)); t80 = *((unsigned int *)t30); t81 = (t80 & t79); t82 = (~(t77)); t83 = (~(t81)); t84 = *((unsigned int *)t64); *((unsigned int *)t64) = (t84 & t82); t85 = *((unsigned int *)t64); *((unsigned int *)t64) = (t85 & t83); goto LAB18; LAB19: *((unsigned int *)t96) = 1; goto LAB22; LAB24: t118 = *((unsigned int *)t96); t119 = *((unsigned int *)t115); *((unsigned int *)t96) = (t118 | t119); t120 = *((unsigned int *)t114); t121 = *((unsigned int *)t115); *((unsigned int *)t114) = (t120 | t121); goto LAB23; LAB25: t136 = *((unsigned int *)t124); t137 = *((unsigned int *)t130); *((unsigned int *)t124) = (t136 | t137); t138 = (t88 + 4); t139 = (t96 + 4); t140 = *((unsigned int *)t138); t141 = (~(t140)); t142 = *((unsigned int *)t88); t143 = (t142 & t141); t144 = *((unsigned int *)t139); t145 = (~(t144)); t146 = *((unsigned int *)t96); t147 = (t146 & t145); t148 = (~(t143)); t149 = (~(t147)); t150 = *((unsigned int *)t130); *((unsigned int *)t130) = (t150 & t148); t151 = *((unsigned int *)t130); *((unsigned int *)t130) = (t151 & t149); goto LAB27; LAB28: t174 = *((unsigned int *)t162); t175 = *((unsigned int *)t168); *((unsigned int *)t162) = (t174 | t175); t176 = (t124 + 4); t177 = (t154 + 4); t178 = *((unsigned int *)t176); t179 = (~(t178)); t180 = *((unsigned int *)t124); t181 = (t180 & t179); t182 = *((unsigned int *)t177); t183 = (~(t182)); t184 = *((unsigned int *)t154); t185 = (t184 & t183); t186 = (~(t181)); t187 = (~(t185)); t188 = *((unsigned int *)t168); *((unsigned int *)t168) = (t188 & t186); t189 = *((unsigned int *)t168); *((unsigned int *)t168) = (t189 & t187); goto LAB30; LAB31: t202 = *((unsigned int *)t190); t203 = *((unsigned int *)t196); *((unsigned int *)t190) = (t202 | t203); t204 = (t58 + 4); t205 = (t162 + 4); t206 = *((unsigned int *)t58); t207 = (~(t206)); t208 = *((unsigned int *)t204); t209 = (~(t208)); t210 = *((unsigned int *)t162); t211 = (~(t210)); t212 = *((unsigned int *)t205); t213 = (~(t212)); t214 = (t207 & t209); t215 = (t211 & t213); t216 = (~(t214)); t217 = (~(t215)); t218 = *((unsigned int *)t196); *((unsigned int *)t196) = (t218 & t216); t219 = *((unsigned int *)t196); *((unsigned int *)t196) = (t219 & t217); t220 = *((unsigned int *)t190); *((unsigned int *)t190) = (t220 & t216); t221 = *((unsigned int *)t190); *((unsigned int *)t190) = (t221 & t217); goto LAB33; LAB34: *((unsigned int *)t222) = 1; goto LAB37; LAB39: t244 = *((unsigned int *)t222); t245 = *((unsigned int *)t241); *((unsigned int *)t222) = (t244 | t245); t246 = *((unsigned int *)t240); t247 = *((unsigned int *)t241); *((unsigned int *)t240) = (t246 | t247); goto LAB38; LAB40: t272 = *((unsigned int *)t260); t273 = *((unsigned int *)t266); *((unsigned int *)t260) = (t272 | t273); t274 = (t222 + 4); t275 = (t252 + 4); t276 = *((unsigned int *)t274); t277 = (~(t276)); t278 = *((unsigned int *)t222); t279 = (t278 & t277); t280 = *((unsigned int *)t275); t281 = (~(t280)); t282 = *((unsigned int *)t252); t283 = (t282 & t281); t284 = (~(t279)); t285 = (~(t283)); t286 = *((unsigned int *)t266); *((unsigned int *)t266) = (t286 & t284); t287 = *((unsigned int *)t266); *((unsigned int *)t266) = (t287 & t285); goto LAB42; LAB43: t310 = *((unsigned int *)t298); t311 = *((unsigned int *)t304); *((unsigned int *)t298) = (t310 | t311); t312 = (t260 + 4); t313 = (t290 + 4); t314 = *((unsigned int *)t312); t315 = (~(t314)); t316 = *((unsigned int *)t260); t317 = (t316 & t315); t318 = *((unsigned int *)t313); t319 = (~(t318)); t320 = *((unsigned int *)t290); t321 = (t320 & t319); t322 = (~(t317)); t323 = (~(t321)); t324 = *((unsigned int *)t304); *((unsigned int *)t304) = (t324 & t322); t325 = *((unsigned int *)t304); *((unsigned int *)t304) = (t325 & t323); goto LAB45; LAB46: t338 = *((unsigned int *)t326); t339 = *((unsigned int *)t332); *((unsigned int *)t326) = (t338 | t339); t340 = (t190 + 4); t341 = (t298 + 4); t342 = *((unsigned int *)t190); t343 = (~(t342)); t344 = *((unsigned int *)t340); t345 = (~(t344)); t346 = *((unsigned int *)t298); t347 = (~(t346)); t348 = *((unsigned int *)t341); t349 = (~(t348)); t350 = (t343 & t345); t351 = (t347 & t349); t352 = (~(t350)); t353 = (~(t351)); t354 = *((unsigned int *)t332); *((unsigned int *)t332) = (t354 & t352); t355 = *((unsigned int *)t332); *((unsigned int *)t332) = (t355 & t353); t356 = *((unsigned int *)t326); *((unsigned int *)t326) = (t356 & t352); t357 = *((unsigned int *)t326); *((unsigned int *)t326) = (t357 & t353); goto LAB48; LAB49: *((unsigned int *)t358) = 1; goto LAB52; LAB54: t380 = *((unsigned int *)t358); t381 = *((unsigned int *)t377); *((unsigned int *)t358) = (t380 | t381); t382 = *((unsigned int *)t376); t383 = *((unsigned int *)t377); *((unsigned int *)t376) = (t382 | t383); goto LAB53; LAB55: *((unsigned int *)t386) = 1; goto LAB58; LAB60: t408 = *((unsigned int *)t386); t409 = *((unsigned int *)t405); *((unsigned int *)t386) = (t408 | t409); t410 = *((unsigned int *)t404); t411 = *((unsigned int *)t405); *((unsigned int *)t404) = (t410 | t411); goto LAB59; LAB61: t426 = *((unsigned int *)t414); t427 = *((unsigned int *)t420); *((unsigned int *)t414) = (t426 | t427); t428 = (t358 + 4); t429 = (t386 + 4); t430 = *((unsigned int *)t428); t431 = (~(t430)); t432 = *((unsigned int *)t358); t433 = (t432 & t431); t434 = *((unsigned int *)t429); t435 = (~(t434)); t436 = *((unsigned int *)t386); t437 = (t436 & t435); t438 = (~(t433)); t439 = (~(t437)); t440 = *((unsigned int *)t420); *((unsigned int *)t420) = (t440 & t438); t441 = *((unsigned int *)t420); *((unsigned int *)t420) = (t441 & t439); goto LAB63; LAB64: *((unsigned int *)t442) = 1; goto LAB67; LAB69: t464 = *((unsigned int *)t442); t465 = *((unsigned int *)t461); *((unsigned int *)t442) = (t464 | t465); t466 = *((unsigned int *)t460); t467 = *((unsigned int *)t461); *((unsigned int *)t460) = (t466 | t467); goto LAB68; LAB70: t482 = *((unsigned int *)t470); t483 = *((unsigned int *)t476); *((unsigned int *)t470) = (t482 | t483); t484 = (t414 + 4); t485 = (t442 + 4); t486 = *((unsigned int *)t484); t487 = (~(t486)); t488 = *((unsigned int *)t414); t489 = (t488 & t487); t490 = *((unsigned int *)t485); t491 = (~(t490)); t492 = *((unsigned int *)t442); t493 = (t492 & t491); t494 = (~(t489)); t495 = (~(t493)); t496 = *((unsigned int *)t476); *((unsigned int *)t476) = (t496 & t494); t497 = *((unsigned int *)t476); *((unsigned int *)t476) = (t497 & t495); goto LAB72; LAB73: t510 = *((unsigned int *)t498); t511 = *((unsigned int *)t504); *((unsigned int *)t498) = (t510 | t511); t512 = (t326 + 4); t513 = (t470 + 4); t514 = *((unsigned int *)t326); t515 = (~(t514)); t516 = *((unsigned int *)t512); t517 = (~(t516)); t518 = *((unsigned int *)t470); t519 = (~(t518)); t520 = *((unsigned int *)t513); t521 = (~(t520)); t522 = (t515 & t517); t523 = (t519 & t521); t524 = (~(t522)); t525 = (~(t523)); t526 = *((unsigned int *)t504); *((unsigned int *)t504) = (t526 & t524); t527 = *((unsigned int *)t504); *((unsigned int *)t504) = (t527 & t525); t528 = *((unsigned int *)t498); *((unsigned int *)t498) = (t528 & t524); t529 = *((unsigned int *)t498); *((unsigned int *)t498) = (t529 & t525); goto LAB75; } static void Cont_9_1(char *t0) { char t3[8]; char t5[8]; char t32[8]; char t40[8]; char t70[8]; char t78[8]; char t81[8]; char t106[8]; char t134[8]; char t137[8]; char t162[8]; char t190[8]; char t224[8]; char t232[8]; char t235[8]; char t260[8]; char t288[8]; char t291[8]; char t316[8]; char t344[8]; char t376[8]; char t379[8]; char t406[8]; char t414[8]; char t444[8]; char t452[8]; char t480[8]; char *t1; char *t2; char *t4; char *t6; unsigned int t7; unsigned int t8; unsigned int t9; unsigned int t10; unsigned int t11; unsigned int t12; char *t13; unsigned int t14; unsigned int t15; unsigned int t16; unsigned int t17; unsigned int t18; char *t19; char *t20; char *t21; unsigned int t22; unsigned int t23; unsigned int t24; unsigned int t25; unsigned int t26; unsigned int t27; unsigned int t28; unsigned int t29; char *t30; char *t31; char *t33; unsigned int t34; unsigned int t35; unsigned int t36; unsigned int t37; unsigned int t38; unsigned int t39; unsigned int t41; unsigned int t42; unsigned int t43; char *t44; char *t45; char *t46; unsigned int t47; unsigned int t48; unsigned int t49; unsigned int t50; unsigned int t51; unsigned int t52; unsigned int t53; char *t54; char *t55; unsigned int t56; unsigned int t57; unsigned int t58; int t59; unsigned int t60; unsigned int t61; unsigned int t62; int t63; unsigned int t64; unsigned int t65; unsigned int t66; unsigned int t67; char *t68; char *t69; char *t71; unsigned int t72; unsigned int t73; unsigned int t74; unsigned int t75; unsigned int t76; unsigned int t77; char *t79; char *t80; char *t82; unsigned int t83; unsigned int t84; unsigned int t85; unsigned int t86; unsigned int t87; unsigned int t88; char *t89; unsigned int t90; unsigned int t91; unsigned int t92; unsigned int t93; unsigned int t94; char *t95; char *t96; char *t97; unsigned int t98; unsigned int t99; unsigned int t100; unsigned int t101; unsigned int t102; unsigned int t103; unsigned int t104; unsigned int t105; unsigned int t107; unsigned int t108; unsigned int t109; char *t110; char *t111; char *t112; unsigned int t113; unsigned int t114; unsigned int t115; unsigned int t116; unsigned int t117; unsigned int t118; unsigned int t119; char *t120; char *t121; unsigned int t122; unsigned int t123; unsigned int t124; int t125; unsigned int t126; unsigned int t127; unsigned int t128; int t129; unsigned int t130; unsigned int t131; unsigned int t132; unsigned int t133; char *t135; char *t136; char *t138; unsigned int t139; unsigned int t140; unsigned int t141; unsigned int t142; unsigned int t143; unsigned int t144; char *t145; unsigned int t146; unsigned int t147; unsigned int t148; unsigned int t149; unsigned int t150; char *t151; char *t152; char *t153; unsigned int t154; unsigned int t155; unsigned int t156; unsigned int t157; unsigned int t158; unsigned int t159; unsigned int t160; unsigned int t161; unsigned int t163; unsigned int t164; unsigned int t165; char *t166; char *t167; char *t168; unsigned int t169; unsigned int t170; unsigned int t171; unsigned int t172; unsigned int t173; unsigned int t174; unsigned int t175; char *t176; char *t177; unsigned int t178; unsigned int t179; unsigned int t180; int t181; unsigned int t182; unsigned int t183; unsigned int t184; int t185; unsigned int t186; unsigned int t187; unsigned int t188; unsigned int t189; unsigned int t191; unsigned int t192; unsigned int t193; char *t194; char *t195; char *t196; unsigned int t197; unsigned int t198; unsigned int t199; unsigned int t200; unsigned int t201; unsigned int t202; unsigned int t203; char *t204; char *t205; unsigned int t206; unsigned int t207; unsigned int t208; unsigned int t209; unsigned int t210; unsigned int t211; unsigned int t212; unsigned int t213; int t214; int t215; unsigned int t216; unsigned int t217; unsigned int t218; unsigned int t219; unsigned int t220; unsigned int t221; char *t222; char *t223; char *t225; unsigned int t226; unsigned int t227; unsigned int t228; unsigned int t229; unsigned int t230; unsigned int t231; char *t233; char *t234; char *t236; unsigned int t237; unsigned int t238; unsigned int t239; unsigned int t240; unsigned int t241; unsigned int t242; char *t243; unsigned int t244; unsigned int t245; unsigned int t246; unsigned int t247; unsigned int t248; char *t249; char *t250; char *t251; unsigned int t252; unsigned int t253; unsigned int t254; unsigned int t255; unsigned int t256; unsigned int t257; unsigned int t258; unsigned int t259; unsigned int t261; unsigned int t262; unsigned int t263; char *t264; char *t265; char *t266; unsigned int t267; unsigned int t268; unsigned int t269; unsigned int t270; unsigned int t271; unsigned int t272; unsigned int t273; char *t274; char *t275; unsigned int t276; unsigned int t277; unsigned int t278; int t279; unsigned int t280; unsigned int t281; unsigned int t282; int t283; unsigned int t284; unsigned int t285; unsigned int t286; unsigned int t287; char *t289; char *t290; char *t292; unsigned int t293; unsigned int t294; unsigned int t295; unsigned int t296; unsigned int t297; unsigned int t298; char *t299; unsigned int t300; unsigned int t301; unsigned int t302; unsigned int t303; unsigned int t304; char *t305; char *t306; char *t307; unsigned int t308; unsigned int t309; unsigned int t310; unsigned int t311; unsigned int t312; unsigned int t313; unsigned int t314; unsigned int t315; unsigned int t317; unsigned int t318; unsigned int t319; char *t320; char *t321; char *t322; unsigned int t323; unsigned int t324; unsigned int t325; unsigned int t326; unsigned int t327; unsigned int t328; unsigned int t329; char *t330; char *t331; unsigned int t332; unsigned int t333; unsigned int t334; int t335; unsigned int t336; unsigned int t337; unsigned int t338; int t339; unsigned int t340; unsigned int t341; unsigned int t342; unsigned int t343; unsigned int t345; unsigned int t346; unsigned int t347; char *t348; char *t349; char *t350; unsigned int t351; unsigned int t352; unsigned int t353; unsigned int t354; unsigned int t355; unsigned int t356; unsigned int t357; char *t358; char *t359; unsigned int t360; unsigned int t361; unsigned int t362; unsigned int t363; unsigned int t364; unsigned int t365; unsigned int t366; unsigned int t367; int t368; int t369; unsigned int t370; unsigned int t371; unsigned int t372; unsigned int t373; unsigned int t374; unsigned int t375; char *t377; char *t378; char *t380; unsigned int t381; unsigned int t382; unsigned int t383; unsigned int t384; unsigned int t385; unsigned int t386; char *t387; unsigned int t388; unsigned int t389; unsigned int t390; unsigned int t391; unsigned int t392; char *t393; char *t394; char *t395; unsigned int t396; unsigned int t397; unsigned int t398; unsigned int t399; unsigned int t400; unsigned int t401; unsigned int t402; unsigned int t403; char *t404; char *t405; char *t407; unsigned int t408; unsigned int t409; unsigned int t410; unsigned int t411; unsigned int t412; unsigned int t413; unsigned int t415; unsigned int t416; unsigned int t417; char *t418; char *t419; char *t420; unsigned int t421; unsigned int t422; unsigned int t423; unsigned int t424; unsigned int t425; unsigned int t426; unsigned int t427; char *t428; char *t429; unsigned int t430; unsigned int t431; unsigned int t432; int t433; unsigned int t434; unsigned int t435; unsigned int t436; int t437; unsigned int t438; unsigned int t439; unsigned int t440; unsigned int t441; char *t442; char *t443; char *t445; unsigned int t446; unsigned int t447; unsigned int t448; unsigned int t449; unsigned int t450; unsigned int t451; unsigned int t453; unsigned int t454; unsigned int t455; char *t456; char *t457; char *t458; unsigned int t459; unsigned int t460; unsigned int t461; unsigned int t462; unsigned int t463; unsigned int t464; unsigned int t465; char *t466; char *t467; unsigned int t468; unsigned int t469; unsigned int t470; int t471; unsigned int t472; unsigned int t473; unsigned int t474; int t475; unsigned int t476; unsigned int t477; unsigned int t478; unsigned int t479; unsigned int t481; unsigned int t482; unsigned int t483; char *t484; char *t485; char *t486; unsigned int t487; unsigned int t488; unsigned int t489; unsigned int t490; unsigned int t491; unsigned int t492; unsigned int t493; char *t494; char *t495; unsigned int t496; unsigned int t497; unsigned int t498; unsigned int t499; unsigned int t500; unsigned int t501; unsigned int t502; unsigned int t503; int t504; int t505; unsigned int t506; unsigned int t507; unsigned int t508; unsigned int t509; unsigned int t510; unsigned int t511; char *t512; char *t513; char *t514; char *t515; char *t516; unsigned int t517; unsigned int t518; char *t519; unsigned int t520; unsigned int t521; char *t522; unsigned int t523; unsigned int t524; char *t525; LAB0: t1 = (t0 + 2616U); t2 = *((char **)t1); if (t2 == 0) goto LAB2; LAB3: goto *t2; LAB2: xsi_set_current_line(9, ng0); t2 = (t0 + 1048U); t4 = *((char **)t2); memset(t5, 0, 8); t2 = (t5 + 4); t6 = (t4 + 4); t7 = *((unsigned int *)t4); t8 = (t7 >> 3); t9 = (t8 & 1); *((unsigned int *)t5) = t9; t10 = *((unsigned int *)t6); t11 = (t10 >> 3); t12 = (t11 & 1); *((unsigned int *)t2) = t12; memset(t3, 0, 8); t13 = (t5 + 4); t14 = *((unsigned int *)t13); t15 = (~(t14)); t16 = *((unsigned int *)t5); t17 = (t16 & t15); t18 = (t17 & 1U); if (t18 != 0) goto LAB7; LAB5: if (*((unsigned int *)t13) == 0) goto LAB4; LAB6: t19 = (t3 + 4); *((unsigned int *)t3) = 1; *((unsigned int *)t19) = 1; LAB7: t20 = (t3 + 4); t21 = (t5 + 4); t22 = *((unsigned int *)t5); t23 = (~(t22)); *((unsigned int *)t3) = t23; *((unsigned int *)t20) = 0; if (*((unsigned int *)t21) != 0) goto LAB9; LAB8: t28 = *((unsigned int *)t3); *((unsigned int *)t3) = (t28 & 1U); t29 = *((unsigned int *)t20); *((unsigned int *)t20) = (t29 & 1U); t30 = (t0 + 1048U); t31 = *((char **)t30); memset(t32, 0, 8); t30 = (t32 + 4); t33 = (t31 + 4); t34 = *((unsigned int *)t31); t35 = (t34 >> 1); t36 = (t35 & 1); *((unsigned int *)t32) = t36; t37 = *((unsigned int *)t33); t38 = (t37 >> 1); t39 = (t38 & 1); *((unsigned int *)t30) = t39; t41 = *((unsigned int *)t3); t42 = *((unsigned int *)t32); t43 = (t41 | t42); *((unsigned int *)t40) = t43; t44 = (t3 + 4); t45 = (t32 + 4); t46 = (t40 + 4); t47 = *((unsigned int *)t44); t48 = *((unsigned int *)t45); t49 = (t47 | t48); *((unsigned int *)t46) = t49; t50 = *((unsigned int *)t46); t51 = (t50 != 0); if (t51 == 1) goto LAB10; LAB11: LAB12: t68 = (t0 + 1048U); t69 = *((char **)t68); memset(t70, 0, 8); t68 = (t70 + 4); t71 = (t69 + 4); t72 = *((unsigned int *)t69); t73 = (t72 >> 3); t74 = (t73 & 1); *((unsigned int *)t70) = t74; t75 = *((unsigned int *)t71); t76 = (t75 >> 3); t77 = (t76 & 1); *((unsigned int *)t68) = t77; t79 = (t0 + 1048U); t80 = *((char **)t79); memset(t81, 0, 8); t79 = (t81 + 4); t82 = (t80 + 4); t83 = *((unsigned int *)t80); t84 = (t83 >> 1); t85 = (t84 & 1); *((unsigned int *)t81) = t85; t86 = *((unsigned int *)t82); t87 = (t86 >> 1); t88 = (t87 & 1); *((unsigned int *)t79) = t88; memset(t78, 0, 8); t89 = (t81 + 4); t90 = *((unsigned int *)t89); t91 = (~(t90)); t92 = *((unsigned int *)t81); t93 = (t92 & t91); t94 = (t93 & 1U); if (t94 != 0) goto LAB16; LAB14: if (*((unsigned int *)t89) == 0) goto LAB13; LAB15: t95 = (t78 + 4); *((unsigned int *)t78) = 1; *((unsigned int *)t95) = 1; LAB16: t96 = (t78 + 4); t97 = (t81 + 4); t98 = *((unsigned int *)t81); t99 = (~(t98)); *((unsigned int *)t78) = t99; *((unsigned int *)t96) = 0; if (*((unsigned int *)t97) != 0) goto LAB18; LAB17: t104 = *((unsigned int *)t78); *((unsigned int *)t78) = (t104 & 1U); t105 = *((unsigned int *)t96); *((unsigned int *)t96) = (t105 & 1U); t107 = *((unsigned int *)t70); t108 = *((unsigned int *)t78); t109 = (t107 | t108); *((unsigned int *)t106) = t109; t110 = (t70 + 4); t111 = (t78 + 4); t112 = (t106 + 4); t113 = *((unsigned int *)t110); t114 = *((unsigned int *)t111); t115 = (t113 | t114); *((unsigned int *)t112) = t115; t116 = *((unsigned int *)t112); t117 = (t116 != 0); if (t117 == 1) goto LAB19; LAB20: LAB21: t135 = (t0 + 1048U); t136 = *((char **)t135); memset(t137, 0, 8); t135 = (t137 + 4); t138 = (t136 + 4); t139 = *((unsigned int *)t136); t140 = (t139 >> 0); t141 = (t140 & 1); *((unsigned int *)t137) = t141; t142 = *((unsigned int *)t138); t143 = (t142 >> 0); t144 = (t143 & 1); *((unsigned int *)t135) = t144; memset(t134, 0, 8); t145 = (t137 + 4); t146 = *((unsigned int *)t145); t147 = (~(t146)); t148 = *((unsigned int *)t137); t149 = (t148 & t147); t150 = (t149 & 1U); if (t150 != 0) goto LAB25; LAB23: if (*((unsigned int *)t145) == 0) goto LAB22; LAB24: t151 = (t134 + 4); *((unsigned int *)t134) = 1; *((unsigned int *)t151) = 1; LAB25: t152 = (t134 + 4); t153 = (t137 + 4); t154 = *((unsigned int *)t137); t155 = (~(t154)); *((unsigned int *)t134) = t155; *((unsigned int *)t152) = 0; if (*((unsigned int *)t153) != 0) goto LAB27; LAB26: t160 = *((unsigned int *)t134); *((unsigned int *)t134) = (t160 & 1U); t161 = *((unsigned int *)t152); *((unsigned int *)t152) = (t161 & 1U); t163 = *((unsigned int *)t106); t164 = *((unsigned int *)t134); t165 = (t163 | t164); *((unsigned int *)t162) = t165; t166 = (t106 + 4); t167 = (t134 + 4); t168 = (t162 + 4); t169 = *((unsigned int *)t166); t170 = *((unsigned int *)t167); t171 = (t169 | t170); *((unsigned int *)t168) = t171; t172 = *((unsigned int *)t168); t173 = (t172 != 0); if (t173 == 1) goto LAB28; LAB29: LAB30: t191 = *((unsigned int *)t40); t192 = *((unsigned int *)t162); t193 = (t191 & t192); *((unsigned int *)t190) = t193; t194 = (t40 + 4); t195 = (t162 + 4); t196 = (t190 + 4); t197 = *((unsigned int *)t194); t198 = *((unsigned int *)t195); t199 = (t197 | t198); *((unsigned int *)t196) = t199; t200 = *((unsigned int *)t196); t201 = (t200 != 0); if (t201 == 1) goto LAB31; LAB32: LAB33: t222 = (t0 + 1048U); t223 = *((char **)t222); memset(t224, 0, 8); t222 = (t224 + 4); t225 = (t223 + 4); t226 = *((unsigned int *)t223); t227 = (t226 >> 3); t228 = (t227 & 1); *((unsigned int *)t224) = t228; t229 = *((unsigned int *)t225); t230 = (t229 >> 3); t231 = (t230 & 1); *((unsigned int *)t222) = t231; t233 = (t0 + 1048U); t234 = *((char **)t233); memset(t235, 0, 8); t233 = (t235 + 4); t236 = (t234 + 4); t237 = *((unsigned int *)t234); t238 = (t237 >> 2); t239 = (t238 & 1); *((unsigned int *)t235) = t239; t240 = *((unsigned int *)t236); t241 = (t240 >> 2); t242 = (t241 & 1); *((unsigned int *)t233) = t242; memset(t232, 0, 8); t243 = (t235 + 4); t244 = *((unsigned int *)t243); t245 = (~(t244)); t246 = *((unsigned int *)t235); t247 = (t246 & t245); t248 = (t247 & 1U); if (t248 != 0) goto LAB37; LAB35: if (*((unsigned int *)t243) == 0) goto LAB34; LAB36: t249 = (t232 + 4); *((unsigned int *)t232) = 1; *((unsigned int *)t249) = 1; LAB37: t250 = (t232 + 4); t251 = (t235 + 4); t252 = *((unsigned int *)t235); t253 = (~(t252)); *((unsigned int *)t232) = t253; *((unsigned int *)t250) = 0; if (*((unsigned int *)t251) != 0) goto LAB39; LAB38: t258 = *((unsigned int *)t232); *((unsigned int *)t232) = (t258 & 1U); t259 = *((unsigned int *)t250); *((unsigned int *)t250) = (t259 & 1U); t261 = *((unsigned int *)t224); t262 = *((unsigned int *)t232); t263 = (t261 | t262); *((unsigned int *)t260) = t263; t264 = (t224 + 4); t265 = (t232 + 4); t266 = (t260 + 4); t267 = *((unsigned int *)t264); t268 = *((unsigned int *)t265); t269 = (t267 | t268); *((unsigned int *)t266) = t269; t270 = *((unsigned int *)t266); t271 = (t270 != 0); if (t271 == 1) goto LAB40; LAB41: LAB42: t289 = (t0 + 1048U); t290 = *((char **)t289); memset(t291, 0, 8); t289 = (t291 + 4); t292 = (t290 + 4); t293 = *((unsigned int *)t290); t294 = (t293 >> 1); t295 = (t294 & 1); *((unsigned int *)t291) = t295; t296 = *((unsigned int *)t292); t297 = (t296 >> 1); t298 = (t297 & 1); *((unsigned int *)t289) = t298; memset(t288, 0, 8); t299 = (t291 + 4); t300 = *((unsigned int *)t299); t301 = (~(t300)); t302 = *((unsigned int *)t291); t303 = (t302 & t301); t304 = (t303 & 1U); if (t304 != 0) goto LAB46; LAB44: if (*((unsigned int *)t299) == 0) goto LAB43; LAB45: t305 = (t288 + 4); *((unsigned int *)t288) = 1; *((unsigned int *)t305) = 1; LAB46: t306 = (t288 + 4); t307 = (t291 + 4); t308 = *((unsigned int *)t291); t309 = (~(t308)); *((unsigned int *)t288) = t309; *((unsigned int *)t306) = 0; if (*((unsigned int *)t307) != 0) goto LAB48; LAB47: t314 = *((unsigned int *)t288); *((unsigned int *)t288) = (t314 & 1U); t315 = *((unsigned int *)t306); *((unsigned int *)t306) = (t315 & 1U); t317 = *((unsigned int *)t260); t318 = *((unsigned int *)t288); t319 = (t317 | t318); *((unsigned int *)t316) = t319; t320 = (t260 + 4); t321 = (t288 + 4); t322 = (t316 + 4); t323 = *((unsigned int *)t320); t324 = *((unsigned int *)t321); t325 = (t323 | t324); *((unsigned int *)t322) = t325; t326 = *((unsigned int *)t322); t327 = (t326 != 0); if (t327 == 1) goto LAB49; LAB50: LAB51: t345 = *((unsigned int *)t190); t346 = *((unsigned int *)t316); t347 = (t345 & t346); *((unsigned int *)t344) = t347; t348 = (t190 + 4); t349 = (t316 + 4); t350 = (t344 + 4); t351 = *((unsigned int *)t348); t352 = *((unsigned int *)t349); t353 = (t351 | t352); *((unsigned int *)t350) = t353; t354 = *((unsigned int *)t350); t355 = (t354 != 0); if (t355 == 1) goto LAB52; LAB53: LAB54: t377 = (t0 + 1048U); t378 = *((char **)t377); memset(t379, 0, 8); t377 = (t379 + 4); t380 = (t378 + 4); t381 = *((unsigned int *)t378); t382 = (t381 >> 3); t383 = (t382 & 1); *((unsigned int *)t379) = t383; t384 = *((unsigned int *)t380); t385 = (t384 >> 3); t386 = (t385 & 1); *((unsigned int *)t377) = t386; memset(t376, 0, 8); t387 = (t379 + 4); t388 = *((unsigned int *)t387); t389 = (~(t388)); t390 = *((unsigned int *)t379); t391 = (t390 & t389); t392 = (t391 & 1U); if (t392 != 0) goto LAB58; LAB56: if (*((unsigned int *)t387) == 0) goto LAB55; LAB57: t393 = (t376 + 4); *((unsigned int *)t376) = 1; *((unsigned int *)t393) = 1; LAB58: t394 = (t376 + 4); t395 = (t379 + 4); t396 = *((unsigned int *)t379); t397 = (~(t396)); *((unsigned int *)t376) = t397; *((unsigned int *)t394) = 0; if (*((unsigned int *)t395) != 0) goto LAB60; LAB59: t402 = *((unsigned int *)t376); *((unsigned int *)t376) = (t402 & 1U); t403 = *((unsigned int *)t394); *((unsigned int *)t394) = (t403 & 1U); t404 = (t0 + 1048U); t405 = *((char **)t404); memset(t406, 0, 8); t404 = (t406 + 4); t407 = (t405 + 4); t408 = *((unsigned int *)t405); t409 = (t408 >> 2); t410 = (t409 & 1); *((unsigned int *)t406) = t410; t411 = *((unsigned int *)t407); t412 = (t411 >> 2); t413 = (t412 & 1); *((unsigned int *)t404) = t413; t415 = *((unsigned int *)t376); t416 = *((unsigned int *)t406); t417 = (t415 | t416); *((unsigned int *)t414) = t417; t418 = (t376 + 4); t419 = (t406 + 4); t420 = (t414 + 4); t421 = *((unsigned int *)t418); t422 = *((unsigned int *)t419); t423 = (t421 | t422); *((unsigned int *)t420) = t423; t424 = *((unsigned int *)t420); t425 = (t424 != 0); if (t425 == 1) goto LAB61; LAB62: LAB63: t442 = (t0 + 1048U); t443 = *((char **)t442); memset(t444, 0, 8); t442 = (t444 + 4); t445 = (t443 + 4); t446 = *((unsigned int *)t443); t447 = (t446 >> 0); t448 = (t447 & 1); *((unsigned int *)t444) = t448; t449 = *((unsigned int *)t445); t450 = (t449 >> 0); t451 = (t450 & 1); *((unsigned int *)t442) = t451; t453 = *((unsigned int *)t414); t454 = *((unsigned int *)t444); t455 = (t453 | t454); *((unsigned int *)t452) = t455; t456 = (t414 + 4); t457 = (t444 + 4); t458 = (t452 + 4); t459 = *((unsigned int *)t456); t460 = *((unsigned int *)t457); t461 = (t459 | t460); *((unsigned int *)t458) = t461; t462 = *((unsigned int *)t458); t463 = (t462 != 0); if (t463 == 1) goto LAB64; LAB65: LAB66: t481 = *((unsigned int *)t344); t482 = *((unsigned int *)t452); t483 = (t481 & t482); *((unsigned int *)t480) = t483; t484 = (t344 + 4); t485 = (t452 + 4); t486 = (t480 + 4); t487 = *((unsigned int *)t484); t488 = *((unsigned int *)t485); t489 = (t487 | t488); *((unsigned int *)t486) = t489; t490 = *((unsigned int *)t486); t491 = (t490 != 0); if (t491 == 1) goto LAB67; LAB68: LAB69: t512 = (t0 + 3624); t513 = (t512 + 56U); t514 = *((char **)t513); t515 = (t514 + 56U); t516 = *((char **)t515); memset(t516, 0, 8); t517 = 1U; t518 = t517; t519 = (t480 + 4); t520 = *((unsigned int *)t480); t517 = (t517 & t520); t521 = *((unsigned int *)t519); t518 = (t518 & t521); t522 = (t516 + 4); t523 = *((unsigned int *)t516); *((unsigned int *)t516) = (t523 | t517); t524 = *((unsigned int *)t522); *((unsigned int *)t522) = (t524 | t518); xsi_driver_vfirst_trans(t512, 1, 1); t525 = (t0 + 3448); *((int *)t525) = 1; LAB1: return; LAB4: *((unsigned int *)t3) = 1; goto LAB7; LAB9: t24 = *((unsigned int *)t3); t25 = *((unsigned int *)t21); *((unsigned int *)t3) = (t24 | t25); t26 = *((unsigned int *)t20); t27 = *((unsigned int *)t21); *((unsigned int *)t20) = (t26 | t27); goto LAB8; LAB10: t52 = *((unsigned int *)t40); t53 = *((unsigned int *)t46); *((unsigned int *)t40) = (t52 | t53); t54 = (t3 + 4); t55 = (t32 + 4); t56 = *((unsigned int *)t54); t57 = (~(t56)); t58 = *((unsigned int *)t3); t59 = (t58 & t57); t60 = *((unsigned int *)t55); t61 = (~(t60)); t62 = *((unsigned int *)t32); t63 = (t62 & t61); t64 = (~(t59)); t65 = (~(t63)); t66 = *((unsigned int *)t46); *((unsigned int *)t46) = (t66 & t64); t67 = *((unsigned int *)t46); *((unsigned int *)t46) = (t67 & t65); goto LAB12; LAB13: *((unsigned int *)t78) = 1; goto LAB16; LAB18: t100 = *((unsigned int *)t78); t101 = *((unsigned int *)t97); *((unsigned int *)t78) = (t100 | t101); t102 = *((unsigned int *)t96); t103 = *((unsigned int *)t97); *((unsigned int *)t96) = (t102 | t103); goto LAB17; LAB19: t118 = *((unsigned int *)t106); t119 = *((unsigned int *)t112); *((unsigned int *)t106) = (t118 | t119); t120 = (t70 + 4); t121 = (t78 + 4); t122 = *((unsigned int *)t120); t123 = (~(t122)); t124 = *((unsigned int *)t70); t125 = (t124 & t123); t126 = *((unsigned int *)t121); t127 = (~(t126)); t128 = *((unsigned int *)t78); t129 = (t128 & t127); t130 = (~(t125)); t131 = (~(t129)); t132 = *((unsigned int *)t112); *((unsigned int *)t112) = (t132 & t130); t133 = *((unsigned int *)t112); *((unsigned int *)t112) = (t133 & t131); goto LAB21; LAB22: *((unsigned int *)t134) = 1; goto LAB25; LAB27: t156 = *((unsigned int *)t134); t157 = *((unsigned int *)t153); *((unsigned int *)t134) = (t156 | t157); t158 = *((unsigned int *)t152); t159 = *((unsigned int *)t153); *((unsigned int *)t152) = (t158 | t159); goto LAB26; LAB28: t174 = *((unsigned int *)t162); t175 = *((unsigned int *)t168); *((unsigned int *)t162) = (t174 | t175); t176 = (t106 + 4); t177 = (t134 + 4); t178 = *((unsigned int *)t176); t179 = (~(t178)); t180 = *((unsigned int *)t106); t181 = (t180 & t179); t182 = *((unsigned int *)t177); t183 = (~(t182)); t184 = *((unsigned int *)t134); t185 = (t184 & t183); t186 = (~(t181)); t187 = (~(t185)); t188 = *((unsigned int *)t168); *((unsigned int *)t168) = (t188 & t186); t189 = *((unsigned int *)t168); *((unsigned int *)t168) = (t189 & t187); goto LAB30; LAB31: t202 = *((unsigned int *)t190); t203 = *((unsigned int *)t196); *((unsigned int *)t190) = (t202 | t203); t204 = (t40 + 4); t205 = (t162 + 4); t206 = *((unsigned int *)t40); t207 = (~(t206)); t208 = *((unsigned int *)t204); t209 = (~(t208)); t210 = *((unsigned int *)t162); t211 = (~(t210)); t212 = *((unsigned int *)t205); t213 = (~(t212)); t214 = (t207 & t209); t215 = (t211 & t213); t216 = (~(t214)); t217 = (~(t215)); t218 = *((unsigned int *)t196); *((unsigned int *)t196) = (t218 & t216); t219 = *((unsigned int *)t196); *((unsigned int *)t196) = (t219 & t217); t220 = *((unsigned int *)t190); *((unsigned int *)t190) = (t220 & t216); t221 = *((unsigned int *)t190); *((unsigned int *)t190) = (t221 & t217); goto LAB33; LAB34: *((unsigned int *)t232) = 1; goto LAB37; LAB39: t254 = *((unsigned int *)t232); t255 = *((unsigned int *)t251); *((unsigned int *)t232) = (t254 | t255); t256 = *((unsigned int *)t250); t257 = *((unsigned int *)t251); *((unsigned int *)t250) = (t256 | t257); goto LAB38; LAB40: t272 = *((unsigned int *)t260); t273 = *((unsigned int *)t266); *((unsigned int *)t260) = (t272 | t273); t274 = (t224 + 4); t275 = (t232 + 4); t276 = *((unsigned int *)t274); t277 = (~(t276)); t278 = *((unsigned int *)t224); t279 = (t278 & t277); t280 = *((unsigned int *)t275); t281 = (~(t280)); t282 = *((unsigned int *)t232); t283 = (t282 & t281); t284 = (~(t279)); t285 = (~(t283)); t286 = *((unsigned int *)t266); *((unsigned int *)t266) = (t286 & t284); t287 = *((unsigned int *)t266); *((unsigned int *)t266) = (t287 & t285); goto LAB42; LAB43: *((unsigned int *)t288) = 1; goto LAB46; LAB48: t310 = *((unsigned int *)t288); t311 = *((unsigned int *)t307); *((unsigned int *)t288) = (t310 | t311); t312 = *((unsigned int *)t306); t313 = *((unsigned int *)t307); *((unsigned int *)t306) = (t312 | t313); goto LAB47; LAB49: t328 = *((unsigned int *)t316); t329 = *((unsigned int *)t322); *((unsigned int *)t316) = (t328 | t329); t330 = (t260 + 4); t331 = (t288 + 4); t332 = *((unsigned int *)t330); t333 = (~(t332)); t334 = *((unsigned int *)t260); t335 = (t334 & t333); t336 = *((unsigned int *)t331); t337 = (~(t336)); t338 = *((unsigned int *)t288); t339 = (t338 & t337); t340 = (~(t335)); t341 = (~(t339)); t342 = *((unsigned int *)t322); *((unsigned int *)t322) = (t342 & t340); t343 = *((unsigned int *)t322); *((unsigned int *)t322) = (t343 & t341); goto LAB51; LAB52: t356 = *((unsigned int *)t344); t357 = *((unsigned int *)t350); *((unsigned int *)t344) = (t356 | t357); t358 = (t190 + 4); t359 = (t316 + 4); t360 = *((unsigned int *)t190); t361 = (~(t360)); t362 = *((unsigned int *)t358); t363 = (~(t362)); t364 = *((unsigned int *)t316); t365 = (~(t364)); t366 = *((unsigned int *)t359); t367 = (~(t366)); t368 = (t361 & t363); t369 = (t365 & t367); t370 = (~(t368)); t371 = (~(t369)); t372 = *((unsigned int *)t350); *((unsigned int *)t350) = (t372 & t370); t373 = *((unsigned int *)t350); *((unsigned int *)t350) = (t373 & t371); t374 = *((unsigned int *)t344); *((unsigned int *)t344) = (t374 & t370); t375 = *((unsigned int *)t344); *((unsigned int *)t344) = (t375 & t371); goto LAB54; LAB55: *((unsigned int *)t376) = 1; goto LAB58; LAB60: t398 = *((unsigned int *)t376); t399 = *((unsigned int *)t395); *((unsigned int *)t376) = (t398 | t399); t400 = *((unsigned int *)t394); t401 = *((unsigned int *)t395); *((unsigned int *)t394) = (t400 | t401); goto LAB59; LAB61: t426 = *((unsigned int *)t414); t427 = *((unsigned int *)t420); *((unsigned int *)t414) = (t426 | t427); t428 = (t376 + 4); t429 = (t406 + 4); t430 = *((unsigned int *)t428); t431 = (~(t430)); t432 = *((unsigned int *)t376); t433 = (t432 & t431); t434 = *((unsigned int *)t429); t435 = (~(t434)); t436 = *((unsigned int *)t406); t437 = (t436 & t435); t438 = (~(t433)); t439 = (~(t437)); t440 = *((unsigned int *)t420); *((unsigned int *)t420) = (t440 & t438); t441 = *((unsigned int *)t420); *((unsigned int *)t420) = (t441 & t439); goto LAB63; LAB64: t464 = *((unsigned int *)t452); t465 = *((unsigned int *)t458); *((unsigned int *)t452) = (t464 | t465); t466 = (t414 + 4); t467 = (t444 + 4); t468 = *((unsigned int *)t466); t469 = (~(t468)); t470 = *((unsigned int *)t414); t471 = (t470 & t469); t472 = *((unsigned int *)t467); t473 = (~(t472)); t474 = *((unsigned int *)t444); t475 = (t474 & t473); t476 = (~(t471)); t477 = (~(t475)); t478 = *((unsigned int *)t458); *((unsigned int *)t458) = (t478 & t476); t479 = *((unsigned int *)t458); *((unsigned int *)t458) = (t479 & t477); goto LAB66; LAB67: t492 = *((unsigned int *)t480); t493 = *((unsigned int *)t486); *((unsigned int *)t480) = (t492 | t493); t494 = (t344 + 4); t495 = (t452 + 4); t496 = *((unsigned int *)t344); t497 = (~(t496)); t498 = *((unsigned int *)t494); t499 = (~(t498)); t500 = *((unsigned int *)t452); t501 = (~(t500)); t502 = *((unsigned int *)t495); t503 = (~(t502)); t504 = (t497 & t499); t505 = (t501 & t503); t506 = (~(t504)); t507 = (~(t505)); t508 = *((unsigned int *)t486); *((unsigned int *)t486) = (t508 & t506); t509 = *((unsigned int *)t486); *((unsigned int *)t486) = (t509 & t507); t510 = *((unsigned int *)t480); *((unsigned int *)t480) = (t510 & t506); t511 = *((unsigned int *)t480); *((unsigned int *)t480) = (t511 & t507); goto LAB69; } static void Cont_10_2(char *t0) { char t4[8]; char t12[8]; char t15[8]; char t40[8]; char t68[8]; char t71[8]; char t98[8]; char t106[8]; char t134[8]; char t166[8]; char t169[8]; char t196[8]; char t204[8]; char t232[8]; char t235[8]; char t260[8]; char t288[8]; char *t1; char *t2; char *t3; char *t5; unsigned int t6; unsigned int t7; unsigned int t8; unsigned int t9; unsigned int t10; unsigned int t11; char *t13; char *t14; char *t16; unsigned int t17; unsigned int t18; unsigned int t19; unsigned int t20; unsigned int t21; unsigned int t22; char *t23; unsigned int t24; unsigned int t25; unsigned int t26; unsigned int t27; unsigned int t28; char *t29; char *t30; char *t31; unsigned int t32; unsigned int t33; unsigned int t34; unsigned int t35; unsigned int t36; unsigned int t37; unsigned int t38; unsigned int t39; unsigned int t41; unsigned int t42; unsigned int t43; char *t44; char *t45; char *t46; unsigned int t47; unsigned int t48; unsigned int t49; unsigned int t50; unsigned int t51; unsigned int t52; unsigned int t53; char *t54; char *t55; unsigned int t56; unsigned int t57; unsigned int t58; int t59; unsigned int t60; unsigned int t61; unsigned int t62; int t63; unsigned int t64; unsigned int t65; unsigned int t66; unsigned int t67; char *t69; char *t70; char *t72; unsigned int t73; unsigned int t74; unsigned int t75; unsigned int t76; unsigned int t77; unsigned int t78; char *t79; unsigned int t80; unsigned int t81; unsigned int t82; unsigned int t83; unsigned int t84; char *t85; char *t86; char *t87; unsigned int t88; unsigned int t89; unsigned int t90; unsigned int t91; unsigned int t92; unsigned int t93; unsigned int t94; unsigned int t95; char *t96; char *t97; char *t99; unsigned int t100; unsigned int t101; unsigned int t102; unsigned int t103; unsigned int t104; unsigned int t105; unsigned int t107; unsigned int t108; unsigned int t109; char *t110; char *t111; char *t112; unsigned int t113; unsigned int t114; unsigned int t115; unsigned int t116; unsigned int t117; unsigned int t118; unsigned int t119; char *t120; char *t121; unsigned int t122; unsigned int t123; unsigned int t124; int t125; unsigned int t126; unsigned int t127; unsigned int t128; int t129; unsigned int t130; unsigned int t131; unsigned int t132; unsigned int t133; unsigned int t135; unsigned int t136; unsigned int t137; char *t138; char *t139; char *t140; unsigned int t141; unsigned int t142; unsigned int t143; unsigned int t144; unsigned int t145; unsigned int t146; unsigned int t147; char *t148; char *t149; unsigned int t150; unsigned int t151; unsigned int t152; unsigned int t153; unsigned int t154; unsigned int t155; unsigned int t156; unsigned int t157; int t158; int t159; unsigned int t160; unsigned int t161; unsigned int t162; unsigned int t163; unsigned int t164; unsigned int t165; char *t167; char *t168; char *t170; unsigned int t171; unsigned int t172; unsigned int t173; unsigned int t174; unsigned int t175; unsigned int t176; char *t177; unsigned int t178; unsigned int t179; unsigned int t180; unsigned int t181; unsigned int t182; char *t183; char *t184; char *t185; unsigned int t186; unsigned int t187; unsigned int t188; unsigned int t189; unsigned int t190; unsigned int t191; unsigned int t192; unsigned int t193; char *t194; char *t195; char *t197; unsigned int t198; unsigned int t199; unsigned int t200; unsigned int t201; unsigned int t202; unsigned int t203; unsigned int t205; unsigned int t206; unsigned int t207; char *t208; char *t209; char *t210; unsigned int t211; unsigned int t212; unsigned int t213; unsigned int t214; unsigned int t215; unsigned int t216; unsigned int t217; char *t218; char *t219; unsigned int t220; unsigned int t221; unsigned int t222; int t223; unsigned int t224; unsigned int t225; unsigned int t226; int t227; unsigned int t228; unsigned int t229; unsigned int t230; unsigned int t231; char *t233; char *t234; char *t236; unsigned int t237; unsigned int t238; unsigned int t239; unsigned int t240; unsigned int t241; unsigned int t242; char *t243; unsigned int t244; unsigned int t245; unsigned int t246; unsigned int t247; unsigned int t248; char *t249; char *t250; char *t251; unsigned int t252; unsigned int t253; unsigned int t254; unsigned int t255; unsigned int t256; unsigned int t257; unsigned int t258; unsigned int t259; unsigned int t261; unsigned int t262; unsigned int t263; char *t264; char *t265; char *t266; unsigned int t267; unsigned int t268; unsigned int t269; unsigned int t270; unsigned int t271; unsigned int t272; unsigned int t273; char *t274; char *t275; unsigned int t276; unsigned int t277; unsigned int t278; int t279; unsigned int t280; unsigned int t281; unsigned int t282; int t283; unsigned int t284; unsigned int t285; unsigned int t286; unsigned int t287; unsigned int t289; unsigned int t290; unsigned int t291; char *t292; char *t293; char *t294; unsigned int t295; unsigned int t296; unsigned int t297; unsigned int t298; unsigned int t299; unsigned int t300; unsigned int t301; char *t302; char *t303; unsigned int t304; unsigned int t305; unsigned int t306; unsigned int t307; unsigned int t308; unsigned int t309; unsigned int t310; unsigned int t311; int t312; int t313; unsigned int t314; unsigned int t315; unsigned int t316; unsigned int t317; unsigned int t318; unsigned int t319; char *t320; char *t321; char *t322; char *t323; char *t324; unsigned int t325; unsigned int t326; char *t327; unsigned int t328; unsigned int t329; char *t330; unsigned int t331; unsigned int t332; char *t333; LAB0: t1 = (t0 + 2864U); t2 = *((char **)t1); if (t2 == 0) goto LAB2; LAB3: goto *t2; LAB2: xsi_set_current_line(10, ng0); t2 = (t0 + 1048U); t3 = *((char **)t2); memset(t4, 0, 8); t2 = (t4 + 4); t5 = (t3 + 4); t6 = *((unsigned int *)t3); t7 = (t6 >> 1); t8 = (t7 & 1); *((unsigned int *)t4) = t8; t9 = *((unsigned int *)t5); t10 = (t9 >> 1); t11 = (t10 & 1); *((unsigned int *)t2) = t11; t13 = (t0 + 1048U); t14 = *((char **)t13); memset(t15, 0, 8); t13 = (t15 + 4); t16 = (t14 + 4); t17 = *((unsigned int *)t14); t18 = (t17 >> 0); t19 = (t18 & 1); *((unsigned int *)t15) = t19; t20 = *((unsigned int *)t16); t21 = (t20 >> 0); t22 = (t21 & 1); *((unsigned int *)t13) = t22; memset(t12, 0, 8); t23 = (t15 + 4); t24 = *((unsigned int *)t23); t25 = (~(t24)); t26 = *((unsigned int *)t15); t27 = (t26 & t25); t28 = (t27 & 1U); if (t28 != 0) goto LAB7; LAB5: if (*((unsigned int *)t23) == 0) goto LAB4; LAB6: t29 = (t12 + 4); *((unsigned int *)t12) = 1; *((unsigned int *)t29) = 1; LAB7: t30 = (t12 + 4); t31 = (t15 + 4); t32 = *((unsigned int *)t15); t33 = (~(t32)); *((unsigned int *)t12) = t33; *((unsigned int *)t30) = 0; if (*((unsigned int *)t31) != 0) goto LAB9; LAB8: t38 = *((unsigned int *)t12); *((unsigned int *)t12) = (t38 & 1U); t39 = *((unsigned int *)t30); *((unsigned int *)t30) = (t39 & 1U); t41 = *((unsigned int *)t4); t42 = *((unsigned int *)t12); t43 = (t41 | t42); *((unsigned int *)t40) = t43; t44 = (t4 + 4); t45 = (t12 + 4); t46 = (t40 + 4); t47 = *((unsigned int *)t44); t48 = *((unsigned int *)t45); t49 = (t47 | t48); *((unsigned int *)t46) = t49; t50 = *((unsigned int *)t46); t51 = (t50 != 0); if (t51 == 1) goto LAB10; LAB11: LAB12: t69 = (t0 + 1048U); t70 = *((char **)t69); memset(t71, 0, 8); t69 = (t71 + 4); t72 = (t70 + 4); t73 = *((unsigned int *)t70); t74 = (t73 >> 3); t75 = (t74 & 1); *((unsigned int *)t71) = t75; t76 = *((unsigned int *)t72); t77 = (t76 >> 3); t78 = (t77 & 1); *((unsigned int *)t69) = t78; memset(t68, 0, 8); t79 = (t71 + 4); t80 = *((unsigned int *)t79); t81 = (~(t80)); t82 = *((unsigned int *)t71); t83 = (t82 & t81); t84 = (t83 & 1U); if (t84 != 0) goto LAB16; LAB14: if (*((unsigned int *)t79) == 0) goto LAB13; LAB15: t85 = (t68 + 4); *((unsigned int *)t68) = 1; *((unsigned int *)t85) = 1; LAB16: t86 = (t68 + 4); t87 = (t71 + 4); t88 = *((unsigned int *)t71); t89 = (~(t88)); *((unsigned int *)t68) = t89; *((unsigned int *)t86) = 0; if (*((unsigned int *)t87) != 0) goto LAB18; LAB17: t94 = *((unsigned int *)t68); *((unsigned int *)t68) = (t94 & 1U); t95 = *((unsigned int *)t86); *((unsigned int *)t86) = (t95 & 1U); t96 = (t0 + 1048U); t97 = *((char **)t96); memset(t98, 0, 8); t96 = (t98 + 4); t99 = (t97 + 4); t100 = *((unsigned int *)t97); t101 = (t100 >> 1); t102 = (t101 & 1); *((unsigned int *)t98) = t102; t103 = *((unsigned int *)t99); t104 = (t103 >> 1); t105 = (t104 & 1); *((unsigned int *)t96) = t105; t107 = *((unsigned int *)t68); t108 = *((unsigned int *)t98); t109 = (t107 | t108); *((unsigned int *)t106) = t109; t110 = (t68 + 4); t111 = (t98 + 4); t112 = (t106 + 4); t113 = *((unsigned int *)t110); t114 = *((unsigned int *)t111); t115 = (t113 | t114); *((unsigned int *)t112) = t115; t116 = *((unsigned int *)t112); t117 = (t116 != 0); if (t117 == 1) goto LAB19; LAB20: LAB21: t135 = *((unsigned int *)t40); t136 = *((unsigned int *)t106); t137 = (t135 & t136); *((unsigned int *)t134) = t137; t138 = (t40 + 4); t139 = (t106 + 4); t140 = (t134 + 4); t141 = *((unsigned int *)t138); t142 = *((unsigned int *)t139); t143 = (t141 | t142); *((unsigned int *)t140) = t143; t144 = *((unsigned int *)t140); t145 = (t144 != 0); if (t145 == 1) goto LAB22; LAB23: LAB24: t167 = (t0 + 1048U); t168 = *((char **)t167); memset(t169, 0, 8); t167 = (t169 + 4); t170 = (t168 + 4); t171 = *((unsigned int *)t168); t172 = (t171 >> 3); t173 = (t172 & 1); *((unsigned int *)t169) = t173; t174 = *((unsigned int *)t170); t175 = (t174 >> 3); t176 = (t175 & 1); *((unsigned int *)t167) = t176; memset(t166, 0, 8); t177 = (t169 + 4); t178 = *((unsigned int *)t177); t179 = (~(t178)); t180 = *((unsigned int *)t169); t181 = (t180 & t179); t182 = (t181 & 1U); if (t182 != 0) goto LAB28; LAB26: if (*((unsigned int *)t177) == 0) goto LAB25; LAB27: t183 = (t166 + 4); *((unsigned int *)t166) = 1; *((unsigned int *)t183) = 1; LAB28: t184 = (t166 + 4); t185 = (t169 + 4); t186 = *((unsigned int *)t169); t187 = (~(t186)); *((unsigned int *)t166) = t187; *((unsigned int *)t184) = 0; if (*((unsigned int *)t185) != 0) goto LAB30; LAB29: t192 = *((unsigned int *)t166); *((unsigned int *)t166) = (t192 & 1U); t193 = *((unsigned int *)t184); *((unsigned int *)t184) = (t193 & 1U); t194 = (t0 + 1048U); t195 = *((char **)t194); memset(t196, 0, 8); t194 = (t196 + 4); t197 = (t195 + 4); t198 = *((unsigned int *)t195); t199 = (t198 >> 2); t200 = (t199 & 1); *((unsigned int *)t196) = t200; t201 = *((unsigned int *)t197); t202 = (t201 >> 2); t203 = (t202 & 1); *((unsigned int *)t194) = t203; t205 = *((unsigned int *)t166); t206 = *((unsigned int *)t196); t207 = (t205 | t206); *((unsigned int *)t204) = t207; t208 = (t166 + 4); t209 = (t196 + 4); t210 = (t204 + 4); t211 = *((unsigned int *)t208); t212 = *((unsigned int *)t209); t213 = (t211 | t212); *((unsigned int *)t210) = t213; t214 = *((unsigned int *)t210); t215 = (t214 != 0); if (t215 == 1) goto LAB31; LAB32: LAB33: t233 = (t0 + 1048U); t234 = *((char **)t233); memset(t235, 0, 8); t233 = (t235 + 4); t236 = (t234 + 4); t237 = *((unsigned int *)t234); t238 = (t237 >> 0); t239 = (t238 & 1); *((unsigned int *)t235) = t239; t240 = *((unsigned int *)t236); t241 = (t240 >> 0); t242 = (t241 & 1); *((unsigned int *)t233) = t242; memset(t232, 0, 8); t243 = (t235 + 4); t244 = *((unsigned int *)t243); t245 = (~(t244)); t246 = *((unsigned int *)t235); t247 = (t246 & t245); t248 = (t247 & 1U); if (t248 != 0) goto LAB37; LAB35: if (*((unsigned int *)t243) == 0) goto LAB34; LAB36: t249 = (t232 + 4); *((unsigned int *)t232) = 1; *((unsigned int *)t249) = 1; LAB37: t250 = (t232 + 4); t251 = (t235 + 4); t252 = *((unsigned int *)t235); t253 = (~(t252)); *((unsigned int *)t232) = t253; *((unsigned int *)t250) = 0; if (*((unsigned int *)t251) != 0) goto LAB39; LAB38: t258 = *((unsigned int *)t232); *((unsigned int *)t232) = (t258 & 1U); t259 = *((unsigned int *)t250); *((unsigned int *)t250) = (t259 & 1U); t261 = *((unsigned int *)t204); t262 = *((unsigned int *)t232); t263 = (t261 | t262); *((unsigned int *)t260) = t263; t264 = (t204 + 4); t265 = (t232 + 4); t266 = (t260 + 4); t267 = *((unsigned int *)t264); t268 = *((unsigned int *)t265); t269 = (t267 | t268); *((unsigned int *)t266) = t269; t270 = *((unsigned int *)t266); t271 = (t270 != 0); if (t271 == 1) goto LAB40; LAB41: LAB42: t289 = *((unsigned int *)t134); t290 = *((unsigned int *)t260); t291 = (t289 & t290); *((unsigned int *)t288) = t291; t292 = (t134 + 4); t293 = (t260 + 4); t294 = (t288 + 4); t295 = *((unsigned int *)t292); t296 = *((unsigned int *)t293); t297 = (t295 | t296); *((unsigned int *)t294) = t297; t298 = *((unsigned int *)t294); t299 = (t298 != 0); if (t299 == 1) goto LAB43; LAB44: LAB45: t320 = (t0 + 3688); t321 = (t320 + 56U); t322 = *((char **)t321); t323 = (t322 + 56U); t324 = *((char **)t323); memset(t324, 0, 8); t325 = 1U; t326 = t325; t327 = (t288 + 4); t328 = *((unsigned int *)t288); t325 = (t325 & t328); t329 = *((unsigned int *)t327); t326 = (t326 & t329); t330 = (t324 + 4); t331 = *((unsigned int *)t324); *((unsigned int *)t324) = (t331 | t325); t332 = *((unsigned int *)t330); *((unsigned int *)t330) = (t332 | t326); xsi_driver_vfirst_trans(t320, 2, 2); t333 = (t0 + 3464); *((int *)t333) = 1; LAB1: return; LAB4: *((unsigned int *)t12) = 1; goto LAB7; LAB9: t34 = *((unsigned int *)t12); t35 = *((unsigned int *)t31); *((unsigned int *)t12) = (t34 | t35); t36 = *((unsigned int *)t30); t37 = *((unsigned int *)t31); *((unsigned int *)t30) = (t36 | t37); goto LAB8; LAB10: t52 = *((unsigned int *)t40); t53 = *((unsigned int *)t46); *((unsigned int *)t40) = (t52 | t53); t54 = (t4 + 4); t55 = (t12 + 4); t56 = *((unsigned int *)t54); t57 = (~(t56)); t58 = *((unsigned int *)t4); t59 = (t58 & t57); t60 = *((unsigned int *)t55); t61 = (~(t60)); t62 = *((unsigned int *)t12); t63 = (t62 & t61); t64 = (~(t59)); t65 = (~(t63)); t66 = *((unsigned int *)t46); *((unsigned int *)t46) = (t66 & t64); t67 = *((unsigned int *)t46); *((unsigned int *)t46) = (t67 & t65); goto LAB12; LAB13: *((unsigned int *)t68) = 1; goto LAB16; LAB18: t90 = *((unsigned int *)t68); t91 = *((unsigned int *)t87); *((unsigned int *)t68) = (t90 | t91); t92 = *((unsigned int *)t86); t93 = *((unsigned int *)t87); *((unsigned int *)t86) = (t92 | t93); goto LAB17; LAB19: t118 = *((unsigned int *)t106); t119 = *((unsigned int *)t112); *((unsigned int *)t106) = (t118 | t119); t120 = (t68 + 4); t121 = (t98 + 4); t122 = *((unsigned int *)t120); t123 = (~(t122)); t124 = *((unsigned int *)t68); t125 = (t124 & t123); t126 = *((unsigned int *)t121); t127 = (~(t126)); t128 = *((unsigned int *)t98); t129 = (t128 & t127); t130 = (~(t125)); t131 = (~(t129)); t132 = *((unsigned int *)t112); *((unsigned int *)t112) = (t132 & t130); t133 = *((unsigned int *)t112); *((unsigned int *)t112) = (t133 & t131); goto LAB21; LAB22: t146 = *((unsigned int *)t134); t147 = *((unsigned int *)t140); *((unsigned int *)t134) = (t146 | t147); t148 = (t40 + 4); t149 = (t106 + 4); t150 = *((unsigned int *)t40); t151 = (~(t150)); t152 = *((unsigned int *)t148); t153 = (~(t152)); t154 = *((unsigned int *)t106); t155 = (~(t154)); t156 = *((unsigned int *)t149); t157 = (~(t156)); t158 = (t151 & t153); t159 = (t155 & t157); t160 = (~(t158)); t161 = (~(t159)); t162 = *((unsigned int *)t140); *((unsigned int *)t140) = (t162 & t160); t163 = *((unsigned int *)t140); *((unsigned int *)t140) = (t163 & t161); t164 = *((unsigned int *)t134); *((unsigned int *)t134) = (t164 & t160); t165 = *((unsigned int *)t134); *((unsigned int *)t134) = (t165 & t161); goto LAB24; LAB25: *((unsigned int *)t166) = 1; goto LAB28; LAB30: t188 = *((unsigned int *)t166); t189 = *((unsigned int *)t185); *((unsigned int *)t166) = (t188 | t189); t190 = *((unsigned int *)t184); t191 = *((unsigned int *)t185); *((unsigned int *)t184) = (t190 | t191); goto LAB29; LAB31: t216 = *((unsigned int *)t204); t217 = *((unsigned int *)t210); *((unsigned int *)t204) = (t216 | t217); t218 = (t166 + 4); t219 = (t196 + 4); t220 = *((unsigned int *)t218); t221 = (~(t220)); t222 = *((unsigned int *)t166); t223 = (t222 & t221); t224 = *((unsigned int *)t219); t225 = (~(t224)); t226 = *((unsigned int *)t196); t227 = (t226 & t225); t228 = (~(t223)); t229 = (~(t227)); t230 = *((unsigned int *)t210); *((unsigned int *)t210) = (t230 & t228); t231 = *((unsigned int *)t210); *((unsigned int *)t210) = (t231 & t229); goto LAB33; LAB34: *((unsigned int *)t232) = 1; goto LAB37; LAB39: t254 = *((unsigned int *)t232); t255 = *((unsigned int *)t251); *((unsigned int *)t232) = (t254 | t255); t256 = *((unsigned int *)t250); t257 = *((unsigned int *)t251); *((unsigned int *)t250) = (t256 | t257); goto LAB38; LAB40: t272 = *((unsigned int *)t260); t273 = *((unsigned int *)t266); *((unsigned int *)t260) = (t272 | t273); t274 = (t204 + 4); t275 = (t232 + 4); t276 = *((unsigned int *)t274); t277 = (~(t276)); t278 = *((unsigned int *)t204); t279 = (t278 & t277); t280 = *((unsigned int *)t275); t281 = (~(t280)); t282 = *((unsigned int *)t232); t283 = (t282 & t281); t284 = (~(t279)); t285 = (~(t283)); t286 = *((unsigned int *)t266); *((unsigned int *)t266) = (t286 & t284); t287 = *((unsigned int *)t266); *((unsigned int *)t266) = (t287 & t285); goto LAB42; LAB43: t300 = *((unsigned int *)t288); t301 = *((unsigned int *)t294); *((unsigned int *)t288) = (t300 | t301); t302 = (t134 + 4); t303 = (t260 + 4); t304 = *((unsigned int *)t134); t305 = (~(t304)); t306 = *((unsigned int *)t302); t307 = (~(t306)); t308 = *((unsigned int *)t260); t309 = (~(t308)); t310 = *((unsigned int *)t303); t311 = (~(t310)); t312 = (t305 & t307); t313 = (t309 & t311); t314 = (~(t312)); t315 = (~(t313)); t316 = *((unsigned int *)t294); *((unsigned int *)t294) = (t316 & t314); t317 = *((unsigned int *)t294); *((unsigned int *)t294) = (t317 & t315); t318 = *((unsigned int *)t288); *((unsigned int *)t288) = (t318 & t314); t319 = *((unsigned int *)t288); *((unsigned int *)t288) = (t319 & t315); goto LAB45; } static void Cont_11_3(char *t0) { char t4[8]; char t14[8]; char t22[8]; char t52[8]; char t60[8]; char t63[8]; char t88[8]; char t116[8]; char t150[8]; char t158[8]; char t161[8]; char t186[8]; char t216[8]; char t224[8]; char t252[8]; char *t1; char *t2; char *t3; char *t5; unsigned int t6; unsigned int t7; unsigned int t8; unsigned int t9; unsigned int t10; unsigned int t11; char *t12; char *t13; char *t15; unsigned int t16; unsigned int t17; unsigned int t18; unsigned int t19; unsigned int t20; unsigned int t21; unsigned int t23; unsigned int t24; unsigned int t25; char *t26; char *t27; char *t28; unsigned int t29; unsigned int t30; unsigned int t31; unsigned int t32; unsigned int t33; unsigned int t34; unsigned int t35; char *t36; char *t37; unsigned int t38; unsigned int t39; unsigned int t40; int t41; unsigned int t42; unsigned int t43; unsigned int t44; int t45; unsigned int t46; unsigned int t47; unsigned int t48; unsigned int t49; char *t50; char *t51; char *t53; unsigned int t54; unsigned int t55; unsigned int t56; unsigned int t57; unsigned int t58; unsigned int t59; char *t61; char *t62; char *t64; unsigned int t65; unsigned int t66; unsigned int t67; unsigned int t68; unsigned int t69; unsigned int t70; char *t71; unsigned int t72; unsigned int t73; unsigned int t74; unsigned int t75; unsigned int t76; char *t77; char *t78; char *t79; unsigned int t80; unsigned int t81; unsigned int t82; unsigned int t83; unsigned int t84; unsigned int t85; unsigned int t86; unsigned int t87; unsigned int t89; unsigned int t90; unsigned int t91; char *t92; char *t93; char *t94; unsigned int t95; unsigned int t96; unsigned int t97; unsigned int t98; unsigned int t99; unsigned int t100; unsigned int t101; char *t102; char *t103; unsigned int t104; unsigned int t105; unsigned int t106; int t107; unsigned int t108; unsigned int t109; unsigned int t110; int t111; unsigned int t112; unsigned int t113; unsigned int t114; unsigned int t115; unsigned int t117; unsigned int t118; unsigned int t119; char *t120; char *t121; char *t122; unsigned int t123; unsigned int t124; unsigned int t125; unsigned int t126; unsigned int t127; unsigned int t128; unsigned int t129; char *t130; char *t131; unsigned int t132; unsigned int t133; unsigned int t134; unsigned int t135; unsigned int t136; unsigned int t137; unsigned int t138; unsigned int t139; int t140; int t141; unsigned int t142; unsigned int t143; unsigned int t144; unsigned int t145; unsigned int t146; unsigned int t147; char *t148; char *t149; char *t151; unsigned int t152; unsigned int t153; unsigned int t154; unsigned int t155; unsigned int t156; unsigned int t157; char *t159; char *t160; char *t162; unsigned int t163; unsigned int t164; unsigned int t165; unsigned int t166; unsigned int t167; unsigned int t168; char *t169; unsigned int t170; unsigned int t171; unsigned int t172; unsigned int t173; unsigned int t174; char *t175; char *t176; char *t177; unsigned int t178; unsigned int t179; unsigned int t180; unsigned int t181; unsigned int t182; unsigned int t183; unsigned int t184; unsigned int t185; unsigned int t187; unsigned int t188; unsigned int t189; char *t190; char *t191; char *t192; unsigned int t193; unsigned int t194; unsigned int t195; unsigned int t196; unsigned int t197; unsigned int t198; unsigned int t199; char *t200; char *t201; unsigned int t202; unsigned int t203; unsigned int t204; int t205; unsigned int t206; unsigned int t207; unsigned int t208; int t209; unsigned int t210; unsigned int t211; unsigned int t212; unsigned int t213; char *t214; char *t215; char *t217; unsigned int t218; unsigned int t219; unsigned int t220; unsigned int t221; unsigned int t222; unsigned int t223; unsigned int t225; unsigned int t226; unsigned int t227; char *t228; char *t229; char *t230; unsigned int t231; unsigned int t232; unsigned int t233; unsigned int t234; unsigned int t235; unsigned int t236; unsigned int t237; char *t238; char *t239; unsigned int t240; unsigned int t241; unsigned int t242; int t243; unsigned int t244; unsigned int t245; unsigned int t246; int t247; unsigned int t248; unsigned int t249; unsigned int t250; unsigned int t251; unsigned int t253; unsigned int t254; unsigned int t255; char *t256; char *t257; char *t258; unsigned int t259; unsigned int t260; unsigned int t261; unsigned int t262; unsigned int t263; unsigned int t264; unsigned int t265; char *t266; char *t267; unsigned int t268; unsigned int t269; unsigned int t270; unsigned int t271; unsigned int t272; unsigned int t273; unsigned int t274; unsigned int t275; int t276; int t277; unsigned int t278; unsigned int t279; unsigned int t280; unsigned int t281; unsigned int t282; unsigned int t283; char *t284; char *t285; char *t286; char *t287; char *t288; unsigned int t289; unsigned int t290; char *t291; unsigned int t292; unsigned int t293; char *t294; unsigned int t295; unsigned int t296; char *t297; LAB0: t1 = (t0 + 3112U); t2 = *((char **)t1); if (t2 == 0) goto LAB2; LAB3: goto *t2; LAB2: xsi_set_current_line(11, ng0); t2 = (t0 + 1048U); t3 = *((char **)t2); memset(t4, 0, 8); t2 = (t4 + 4); t5 = (t3 + 4); t6 = *((unsigned int *)t3); t7 = (t6 >> 3); t8 = (t7 & 1); *((unsigned int *)t4) = t8; t9 = *((unsigned int *)t5); t10 = (t9 >> 3); t11 = (t10 & 1); *((unsigned int *)t2) = t11; t12 = (t0 + 1048U); t13 = *((char **)t12); memset(t14, 0, 8); t12 = (t14 + 4); t15 = (t13 + 4); t16 = *((unsigned int *)t13); t17 = (t16 >> 0); t18 = (t17 & 1); *((unsigned int *)t14) = t18; t19 = *((unsigned int *)t15); t20 = (t19 >> 0); t21 = (t20 & 1); *((unsigned int *)t12) = t21; t23 = *((unsigned int *)t4); t24 = *((unsigned int *)t14); t25 = (t23 | t24); *((unsigned int *)t22) = t25; t26 = (t4 + 4); t27 = (t14 + 4); t28 = (t22 + 4); t29 = *((unsigned int *)t26); t30 = *((unsigned int *)t27); t31 = (t29 | t30); *((unsigned int *)t28) = t31; t32 = *((unsigned int *)t28); t33 = (t32 != 0); if (t33 == 1) goto LAB4; LAB5: LAB6: t50 = (t0 + 1048U); t51 = *((char **)t50); memset(t52, 0, 8); t50 = (t52 + 4); t53 = (t51 + 4); t54 = *((unsigned int *)t51); t55 = (t54 >> 1); t56 = (t55 & 1); *((unsigned int *)t52) = t56; t57 = *((unsigned int *)t53); t58 = (t57 >> 1); t59 = (t58 & 1); *((unsigned int *)t50) = t59; t61 = (t0 + 1048U); t62 = *((char **)t61); memset(t63, 0, 8); t61 = (t63 + 4); t64 = (t62 + 4); t65 = *((unsigned int *)t62); t66 = (t65 >> 0); t67 = (t66 & 1); *((unsigned int *)t63) = t67; t68 = *((unsigned int *)t64); t69 = (t68 >> 0); t70 = (t69 & 1); *((unsigned int *)t61) = t70; memset(t60, 0, 8); t71 = (t63 + 4); t72 = *((unsigned int *)t71); t73 = (~(t72)); t74 = *((unsigned int *)t63); t75 = (t74 & t73); t76 = (t75 & 1U); if (t76 != 0) goto LAB10; LAB8: if (*((unsigned int *)t71) == 0) goto LAB7; LAB9: t77 = (t60 + 4); *((unsigned int *)t60) = 1; *((unsigned int *)t77) = 1; LAB10: t78 = (t60 + 4); t79 = (t63 + 4); t80 = *((unsigned int *)t63); t81 = (~(t80)); *((unsigned int *)t60) = t81; *((unsigned int *)t78) = 0; if (*((unsigned int *)t79) != 0) goto LAB12; LAB11: t86 = *((unsigned int *)t60); *((unsigned int *)t60) = (t86 & 1U); t87 = *((unsigned int *)t78); *((unsigned int *)t78) = (t87 & 1U); t89 = *((unsigned int *)t52); t90 = *((unsigned int *)t60); t91 = (t89 | t90); *((unsigned int *)t88) = t91; t92 = (t52 + 4); t93 = (t60 + 4); t94 = (t88 + 4); t95 = *((unsigned int *)t92); t96 = *((unsigned int *)t93); t97 = (t95 | t96); *((unsigned int *)t94) = t97; t98 = *((unsigned int *)t94); t99 = (t98 != 0); if (t99 == 1) goto LAB13; LAB14: LAB15: t117 = *((unsigned int *)t22); t118 = *((unsigned int *)t88); t119 = (t117 & t118); *((unsigned int *)t116) = t119; t120 = (t22 + 4); t121 = (t88 + 4); t122 = (t116 + 4); t123 = *((unsigned int *)t120); t124 = *((unsigned int *)t121); t125 = (t123 | t124); *((unsigned int *)t122) = t125; t126 = *((unsigned int *)t122); t127 = (t126 != 0); if (t127 == 1) goto LAB16; LAB17: LAB18: t148 = (t0 + 1048U); t149 = *((char **)t148); memset(t150, 0, 8); t148 = (t150 + 4); t151 = (t149 + 4); t152 = *((unsigned int *)t149); t153 = (t152 >> 2); t154 = (t153 & 1); *((unsigned int *)t150) = t154; t155 = *((unsigned int *)t151); t156 = (t155 >> 2); t157 = (t156 & 1); *((unsigned int *)t148) = t157; t159 = (t0 + 1048U); t160 = *((char **)t159); memset(t161, 0, 8); t159 = (t161 + 4); t162 = (t160 + 4); t163 = *((unsigned int *)t160); t164 = (t163 >> 1); t165 = (t164 & 1); *((unsigned int *)t161) = t165; t166 = *((unsigned int *)t162); t167 = (t166 >> 1); t168 = (t167 & 1); *((unsigned int *)t159) = t168; memset(t158, 0, 8); t169 = (t161 + 4); t170 = *((unsigned int *)t169); t171 = (~(t170)); t172 = *((unsigned int *)t161); t173 = (t172 & t171); t174 = (t173 & 1U); if (t174 != 0) goto LAB22; LAB20: if (*((unsigned int *)t169) == 0) goto LAB19; LAB21: t175 = (t158 + 4); *((unsigned int *)t158) = 1; *((unsigned int *)t175) = 1; LAB22: t176 = (t158 + 4); t177 = (t161 + 4); t178 = *((unsigned int *)t161); t179 = (~(t178)); *((unsigned int *)t158) = t179; *((unsigned int *)t176) = 0; if (*((unsigned int *)t177) != 0) goto LAB24; LAB23: t184 = *((unsigned int *)t158); *((unsigned int *)t158) = (t184 & 1U); t185 = *((unsigned int *)t176); *((unsigned int *)t176) = (t185 & 1U); t187 = *((unsigned int *)t150); t188 = *((unsigned int *)t158); t189 = (t187 | t188); *((unsigned int *)t186) = t189; t190 = (t150 + 4); t191 = (t158 + 4); t192 = (t186 + 4); t193 = *((unsigned int *)t190); t194 = *((unsigned int *)t191); t195 = (t193 | t194); *((unsigned int *)t192) = t195; t196 = *((unsigned int *)t192); t197 = (t196 != 0); if (t197 == 1) goto LAB25; LAB26: LAB27: t214 = (t0 + 1048U); t215 = *((char **)t214); memset(t216, 0, 8); t214 = (t216 + 4); t217 = (t215 + 4); t218 = *((unsigned int *)t215); t219 = (t218 >> 0); t220 = (t219 & 1); *((unsigned int *)t216) = t220; t221 = *((unsigned int *)t217); t222 = (t221 >> 0); t223 = (t222 & 1); *((unsigned int *)t214) = t223; t225 = *((unsigned int *)t186); t226 = *((unsigned int *)t216); t227 = (t225 | t226); *((unsigned int *)t224) = t227; t228 = (t186 + 4); t229 = (t216 + 4); t230 = (t224 + 4); t231 = *((unsigned int *)t228); t232 = *((unsigned int *)t229); t233 = (t231 | t232); *((unsigned int *)t230) = t233; t234 = *((unsigned int *)t230); t235 = (t234 != 0); if (t235 == 1) goto LAB28; LAB29: LAB30: t253 = *((unsigned int *)t116); t254 = *((unsigned int *)t224); t255 = (t253 & t254); *((unsigned int *)t252) = t255; t256 = (t116 + 4); t257 = (t224 + 4); t258 = (t252 + 4); t259 = *((unsigned int *)t256); t260 = *((unsigned int *)t257); t261 = (t259 | t260); *((unsigned int *)t258) = t261; t262 = *((unsigned int *)t258); t263 = (t262 != 0); if (t263 == 1) goto LAB31; LAB32: LAB33: t284 = (t0 + 3752); t285 = (t284 + 56U); t286 = *((char **)t285); t287 = (t286 + 56U); t288 = *((char **)t287); memset(t288, 0, 8); t289 = 1U; t290 = t289; t291 = (t252 + 4); t292 = *((unsigned int *)t252); t289 = (t289 & t292); t293 = *((unsigned int *)t291); t290 = (t290 & t293); t294 = (t288 + 4); t295 = *((unsigned int *)t288); *((unsigned int *)t288) = (t295 | t289); t296 = *((unsigned int *)t294); *((unsigned int *)t294) = (t296 | t290); xsi_driver_vfirst_trans(t284, 3, 3); t297 = (t0 + 3480); *((int *)t297) = 1; LAB1: return; LAB4: t34 = *((unsigned int *)t22); t35 = *((unsigned int *)t28); *((unsigned int *)t22) = (t34 | t35); t36 = (t4 + 4); t37 = (t14 + 4); t38 = *((unsigned int *)t36); t39 = (~(t38)); t40 = *((unsigned int *)t4); t41 = (t40 & t39); t42 = *((unsigned int *)t37); t43 = (~(t42)); t44 = *((unsigned int *)t14); t45 = (t44 & t43); t46 = (~(t41)); t47 = (~(t45)); t48 = *((unsigned int *)t28); *((unsigned int *)t28) = (t48 & t46); t49 = *((unsigned int *)t28); *((unsigned int *)t28) = (t49 & t47); goto LAB6; LAB7: *((unsigned int *)t60) = 1; goto LAB10; LAB12: t82 = *((unsigned int *)t60); t83 = *((unsigned int *)t79); *((unsigned int *)t60) = (t82 | t83); t84 = *((unsigned int *)t78); t85 = *((unsigned int *)t79); *((unsigned int *)t78) = (t84 | t85); goto LAB11; LAB13: t100 = *((unsigned int *)t88); t101 = *((unsigned int *)t94); *((unsigned int *)t88) = (t100 | t101); t102 = (t52 + 4); t103 = (t60 + 4); t104 = *((unsigned int *)t102); t105 = (~(t104)); t106 = *((unsigned int *)t52); t107 = (t106 & t105); t108 = *((unsigned int *)t103); t109 = (~(t108)); t110 = *((unsigned int *)t60); t111 = (t110 & t109); t112 = (~(t107)); t113 = (~(t111)); t114 = *((unsigned int *)t94); *((unsigned int *)t94) = (t114 & t112); t115 = *((unsigned int *)t94); *((unsigned int *)t94) = (t115 & t113); goto LAB15; LAB16: t128 = *((unsigned int *)t116); t129 = *((unsigned int *)t122); *((unsigned int *)t116) = (t128 | t129); t130 = (t22 + 4); t131 = (t88 + 4); t132 = *((unsigned int *)t22); t133 = (~(t132)); t134 = *((unsigned int *)t130); t135 = (~(t134)); t136 = *((unsigned int *)t88); t137 = (~(t136)); t138 = *((unsigned int *)t131); t139 = (~(t138)); t140 = (t133 & t135); t141 = (t137 & t139); t142 = (~(t140)); t143 = (~(t141)); t144 = *((unsigned int *)t122); *((unsigned int *)t122) = (t144 & t142); t145 = *((unsigned int *)t122); *((unsigned int *)t122) = (t145 & t143); t146 = *((unsigned int *)t116); *((unsigned int *)t116) = (t146 & t142); t147 = *((unsigned int *)t116); *((unsigned int *)t116) = (t147 & t143); goto LAB18; LAB19: *((unsigned int *)t158) = 1; goto LAB22; LAB24: t180 = *((unsigned int *)t158); t181 = *((unsigned int *)t177); *((unsigned int *)t158) = (t180 | t181); t182 = *((unsigned int *)t176); t183 = *((unsigned int *)t177); *((unsigned int *)t176) = (t182 | t183); goto LAB23; LAB25: t198 = *((unsigned int *)t186); t199 = *((unsigned int *)t192); *((unsigned int *)t186) = (t198 | t199); t200 = (t150 + 4); t201 = (t158 + 4); t202 = *((unsigned int *)t200); t203 = (~(t202)); t204 = *((unsigned int *)t150); t205 = (t204 & t203); t206 = *((unsigned int *)t201); t207 = (~(t206)); t208 = *((unsigned int *)t158); t209 = (t208 & t207); t210 = (~(t205)); t211 = (~(t209)); t212 = *((unsigned int *)t192); *((unsigned int *)t192) = (t212 & t210); t213 = *((unsigned int *)t192); *((unsigned int *)t192) = (t213 & t211); goto LAB27; LAB28: t236 = *((unsigned int *)t224); t237 = *((unsigned int *)t230); *((unsigned int *)t224) = (t236 | t237); t238 = (t186 + 4); t239 = (t216 + 4); t240 = *((unsigned int *)t238); t241 = (~(t240)); t242 = *((unsigned int *)t186); t243 = (t242 & t241); t244 = *((unsigned int *)t239); t245 = (~(t244)); t246 = *((unsigned int *)t216); t247 = (t246 & t245); t248 = (~(t243)); t249 = (~(t247)); t250 = *((unsigned int *)t230); *((unsigned int *)t230) = (t250 & t248); t251 = *((unsigned int *)t230); *((unsigned int *)t230) = (t251 & t249); goto LAB30; LAB31: t264 = *((unsigned int *)t252); t265 = *((unsigned int *)t258); *((unsigned int *)t252) = (t264 | t265); t266 = (t116 + 4); t267 = (t224 + 4); t268 = *((unsigned int *)t116); t269 = (~(t268)); t270 = *((unsigned int *)t266); t271 = (~(t270)); t272 = *((unsigned int *)t224); t273 = (~(t272)); t274 = *((unsigned int *)t267); t275 = (~(t274)); t276 = (t269 & t271); t277 = (t273 & t275); t278 = (~(t276)); t279 = (~(t277)); t280 = *((unsigned int *)t258); *((unsigned int *)t258) = (t280 & t278); t281 = *((unsigned int *)t258); *((unsigned int *)t258) = (t281 & t279); t282 = *((unsigned int *)t252); *((unsigned int *)t252) = (t282 & t278); t283 = *((unsigned int *)t252); *((unsigned int *)t252) = (t283 & t279); goto LAB33; } extern void work_m_00000000000530879313_2412534358_init() { static char *pe[] = {(void *)Cont_8_0,(void *)Cont_9_1,(void *)Cont_10_2,(void *)Cont_11_3}; xsi_register_didat("work_m_00000000000530879313_2412534358", "isim/Test_top_isim_beh.exe.sim/work/m_00000000000530879313_2412534358.didat"); xsi_register_executes(pe); }
[ "virus_450@mail.ru" ]
virus_450@mail.ru
7129e0f780514ffc8909450f5e03adc8fea61af5
5b6c21515ae82a7dd12fde0082362215f59cf78b
/main.c
e2a2ad3b42a60658f76d67cd797a353d05518d59
[]
no_license
ltz0302/Linklist
1637dc523ee5040577af5b9ce98d812402710992
6b72eb1e7c4e4bdc1f3b26e6b05957f4d4128923
refs/heads/master
2020-07-28T05:52:49.816304
2019-09-18T14:31:34
2019-09-18T14:31:34
209,326,504
0
0
null
null
null
null
UTF-8
C
false
false
298
c
#include <stdlib.h> #include "list.h" int main() { int len; Node* list; list=creatMyList(NULL); list=InsertOtherNode(list,11,3,1); len=GetMyListLen(list); printf("The Len is %d\n",len); PrintfListDataNode(list); SearchData(list,3); return 0; }
[ "ltz0302@gmail.com" ]
ltz0302@gmail.com
ffc53f9543094f7ac3ba79822478d23480ebc1ad
aaad70e69d37f92c160c07e4ca03de80becf2c51
/filesystem/usr/src/linux-headers-4.15.0-20/include/linux/hwmon-vid.h
abaedc696b60de24e1d76fe2b2a42832918bdb0c
[]
no_license
OSWatcher/ubuntu-server
9b4dcad9ced1bff52ec9cdb4f96d4bdba0ad3bb9
17cb333124c8d48cf47bb9cec1b4e1305626b17a
refs/heads/master
2023-02-10T18:39:43.682708
2020-12-26T01:02:54
2020-12-26T01:02:54
null
0
0
null
null
null
null
UTF-8
C
false
false
165
h
{ "MIME": "text/x-c", "inode_type": "REG", "magic_type": "C source, ASCII text", "mode": "-rw-r--r--", "sha1": "ad8ac79f6acd0bdcde2a5385d9d9e2a4d2a718ea" }
[ "mathieu.tarral@protonmail.com" ]
mathieu.tarral@protonmail.com
2fcbf8f77c0444458c2db5ff9aff9aace5993545
dac106e2ae63671c630b0b54890414efea1ff206
/hal/micro/cortexm3/em35x/em3596/micro-features.h
a7b5750c3611400b468d48f5480f529b14648454
[]
no_license
whitevirus/ZigBee_em358x
4aa70c2eff6cca5b68f59fa736bcbf5a2251c7d1
91e4fbbf5ef12d2e043e6c74980405bbda2442f1
refs/heads/master
2020-11-25T20:24:15.177781
2015-02-06T06:50:03
2015-02-06T06:50:03
null
0
0
null
null
null
null
UTF-8
C
false
false
1,039
h
/** @file hal/micro/cortexm3/em35x/em3596/micro-features.h * * @brief * Constants to indicate which features the em3596 has available * * THIS IS A GENERATED FILE. DO NOT EDIT. * * <!-- Copyright 2014 Silicon Laboratories, Inc. *80*--> */ #ifndef __MICRO_FEATURES_H__ #define __MICRO_FEATURES_H__ #define CORTEXM3_EM35X_GEN4 1 // Masks of which GPIO this chip has on which ports #define EMBER_MICRO_PORT_A_GPIO 0xFF // 7 6 5 4 3 2 1 0 #define EMBER_MICRO_PORT_B_GPIO 0xFF // 7 6 5 4 3 2 1 0 #define EMBER_MICRO_PORT_C_GPIO 0xFF // 7 6 5 4 3 2 1 0 #define EMBER_MICRO_PORT_D_GPIO 0x1E // 4 3 2 1 #define EMBER_MICRO_PORT_E_GPIO 0x0F // 3 2 1 0 // Which physical serial ports are available #define EMBER_MICRO_HAS_SC1 1 #define EMBER_MICRO_HAS_SC2 1 #define EMBER_MICRO_HAS_SC3 1 #define EMBER_MICRO_HAS_SC4 1 #define EMBER_MICRO_SERIAL_CONTROLLERS_MASK 0x0F #ifndef NO_USB #define CORTEXM3_EM35X_USB 1 #endif // NO_USB #endif // __MICRO_FEATURES_H__
[ "yaxx99@homtial.com" ]
yaxx99@homtial.com
61b384b4f255c6e7e131e85921ac0ee2c3e17a52
191707dd19837f7abd6f4255cd42b78d3ca741c5
/X11R5/contrib/examples/PEX/tristrip2.c
f03d3ba2e81a05388a87aa1efdeb03601efc7467
[]
no_license
yoya/x.org
4709089f97b1b48f7de2cfbeff1881c59ea1d28e
fb9e6d4bd0c880cfc674d4697322331fe39864d9
refs/heads/master
2023-08-08T02:00:51.277615
2023-07-25T14:05:05
2023-07-25T14:05:05
163,954,490
2
0
null
null
null
null
UTF-8
C
false
false
2,632
c
/* $XConsortium: tristrip2.c,v 5.1 91/02/16 09:32:36 rws Exp $ */ /*********************************************************** Copyright (c) 1991 by Sun Microsystems, Inc. and the X Consortium. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the names of Sun Microsystems, the X Consortium, and MIT not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, 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. ******************************************************************/ #ifdef BWEE The following program draws some triangle strips with reflectange equation setting = PREFL_AMBIENT. It is expected that the triangle strips be rendered with the current interior colour since the current light source state is empty This program originated from a bug report created by the InsPEX test group. #endif #include "phigs/phigs.h" main(argc,argv) int argc; char **argv; { static Ppoint3 pts1[] = {0.3,0.6,0.0, 0.5,0.5,0.5, 0.7,0.6,0.0, 0.7,0.4,0.0}; static Ppoint3 pts2[] = {0.3,0.6,0.0, 0.5,0.5,0.5, 0.3,0.4,0.0, 0.7,0.4,0.0}; Pfacet_vdata_arr3 vdata1; Pfacet_vdata_arr3 vdata2; static Ppoint3 farea[]= {0.2,0.9,0.0, 0.1,0.7,0.0, 0.0,0.8,0.0}; Ppoint_list3 fset; vdata1.points = pts1; vdata2.points = pts2; fset.num_points = 3; fset.points = farea; popen_phigs(NULL,0); popen_ws(1,NULL,phigs_ws_type_x_tool); popen_struct(1); pset_int_style(PSTYLE_SOLID); pset_int_colr_ind(3); pset_int_shad_meth(PSD_NONE); pset_refl_eqn(PREFL_AMBIENT); if (argc == 1) { ptri_strip3_data(PFACET_NONE,PVERT_COORD,PMODEL_RGB,4,NULL,&vdata1); ptri_strip3_data(PFACET_NONE,PVERT_COORD,PMODEL_RGB,4,NULL,&vdata2); } else { pfill_area_set3(1,&fset); } ppost_struct(1,1,1.0); if (argc == 1) { printf("a triangle strip. press return..."); } else { printf("a fill area set with the same attributes. press return..."); } getchar(); }
[ "yoya@awm.jp" ]
yoya@awm.jp
0d6806d843e291f30ba179ddad1574ce31648651
da171f1e0354f018d26ed8c2e7da1757ddaf5581
/sandeep/2 - Trees/TreeHeight/TreeHeight.c
b0748588b328a281bcded846f097b138dacb54ad
[]
no_license
haeSunshim/Practice-Algorithm
c050cf9c0062ecaa473dd105e1e3104e7a017199
503304fd55a0a1f46f5e5e19c329492a9e15a64d
refs/heads/master
2022-07-16T19:29:00.452024
2020-05-18T10:51:00
2020-05-18T10:51:00
260,959,386
0
1
null
2020-05-18T10:48:36
2020-05-03T15:26:49
C
UTF-8
C
false
false
310
c
#include <stdlib.h> #include "tree.h" int max(int a, int b) {return a > b ? a : b;} int TreeHeight(Tree t) { if (t == NULL) return -1; int left = TreeHeight(t->left) + 1; int right = TreeHeight(t->right) + 1; return max(left, right); } // int TreeHeight(Tree t) { // return -1; // }
[ "das.yaegar@gmail.com" ]
das.yaegar@gmail.com
d39f26b449f10ee1643231bde59c6b620c220350
75c747300761cfe87c424ce431ae16a58fe1abff
/srd/code/registers/iphone11-workinprogress-register-rwx-unit-test.c
26049319c53e6c76ebdeb40db3f38399323111ad
[ "Unlicense", "LicenseRef-scancode-public-domain" ]
permissive
xsscx/ios-arm-research
db421123efb1ce6dda2d344d576ea763f9531a6f
2b23ffc4261d548cc4b3f460a6ce650add51db88
refs/heads/main
2023-06-16T17:29:53.116426
2021-07-12T01:30:24
2021-07-12T01:30:24
332,619,677
12
2
null
null
null
null
UTF-8
C
false
false
5,122
c
/* Original Code by Sven Peter for M1 Apple Silicon Modified by SRD0009 | @h02332 | David Hoyt to run on iPhone 11 and iOS 14.3 or greater OPEN SOURCE - PUBLIC DOMAIN This Code HANGS at -> can_read when reading the PTR. What is the correct address? */ #define _XOPEN_SOURCE #include <signal.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <sys/utsname.h> #include <ucontext.h> static void sev_handler(int signo, siginfo_t *info, void *cx_) { /* printf("Now in sev_handler)\n"); */ (void)signo; (void)info; ucontext_t *cx = cx_; cx->uc_mcontext->__ss.__x[0] = 0xdeadbeef; cx->uc_mcontext->__ss.__opaque_pc = cx->uc_mcontext->__ss.__opaque_lr; } static void bus_handler(int signo, siginfo_t *info, void *cx_) { /* printf("Now in bus_handler\n"); */ (void)signo; (void)info; ucontext_t *cx = cx_; cx->uc_mcontext->__ss.__x[0] = 0xdeadbeef; cx->uc_mcontext->__ss.__opaque_pc += 4; } static void write_sprr_perm(uint64_t v) { printf("Now in write_sprr_perm\n"); __asm__ __volatile__("msr {REGISTER}, %0\n" "isb sy\n" ::"r"(v) :); printf("Now past write_sprr_perm\n"); } static uint64_t read_sprr_perm(void) { printf("Now in read_sprr_perm\n"); uint64_t v; __asm__ __volatile__("isb sy\n" "mrs %0, {REGISTER}\n" : "=r"(v)::"memory"); return v; } static bool can_read(void *ptr) { printf("Now in can_read\n"); uint64_t v = 0; __asm__ __volatile__("ldr x0, [%0]\n" "mov %0, x0\n" : "=r"(v) : "r"(ptr) : "memory", "x0"); if (v == 0xdeadbeef) return false; return true; } static bool can_write(void *ptr) { printf("Now in can_write\n"); uint64_t v = 0; __asm__ __volatile__("str x0, [%0]\n" "mov %0, x0\n" : "=r"(v) : "r"(ptr + 4) : "memory", "x0"); if (v == 0xdeadbeef) return false; return true; } static bool can_exec(void *ptr) { printf("Now in can exec\n"); uint64_t (*fun_ptr)(uint64_t) = ptr; uint64_t res = fun_ptr(0); if (res == 0xdeadbeef) return false; return true; } static void sprr_test(void *ptr, uint64_t v) { printf("Now in sprr_test\n"); uint64_t a, b; a = read_sprr_perm(); printf("after a = read_sprr_perm a:%llx\n", a); write_sprr_perm(v); printf("after write_sprr_perm(v) v:%llx\n", v); b = read_sprr_perm(); printf("after b = write_sprr_perm b:%llx\n", b); printf("Final Value:%llx: %c%c%c\n", b, can_read(ptr) ? 'r' : '-', can_write(ptr) ? 'w' : '-', can_exec(ptr) ? 'x' : '-'); /* printf("----begin added printfs-----\n\r"); printf("ptr: %u\n", ptr); printf("a:%llx\n", a); printf("v:%llx\n", v); printf("memory:%llu\n", "memory"); printf("bv %02d: %016llx\n", b, v); printf("va:%c%c%c\n %u\n", v, a); printf("b:%c\n", b); printf("a:%llx\n", a); printf("----end added printfs-----\n\r"); */ /* printf("bit %02d: %016llx\n", i, read_sprr()); */ } static uint64_t make_sprr_val(uint8_t nibble) { uint64_t res = 0; for (int i = 0; i < 16; ++i) res |= ((uint64_t)nibble) << (4 * i); return res; } uint64_t read_sprr(void) { uint64_t v; __asm__ __volatile__("isb sy\n" "mrs %0, {REGISTER}\n" : "=r"(v)::"memory"); return v; } int main(int argc, char *argv[]) { printf("Start inside Main\n"); (void)argc; (void)argv; printf("Now hitting struct sigaction\n"); struct sigaction sa; printf("Now hitting sigfillset(&sa.sa_mask)\n"); sigfillset(&sa.sa_mask); printf("Now hitting sa.sa_sigaction = bus_handler\n"); sa.sa_sigaction = bus_handler; printf("Now hitting sa.sa_flags = SA_RESTART | SA_SIGINFO\n"); sa.sa_flags = SA_RESTART | SA_SIGINFO; printf("Now hitting sigaction(SIGBUS, &sa, 0)\n"); sigaction(SIGBUS, &sa, 0); printf("Now hitting sa.sa_sigaction = sev_handler\n"); sa.sa_sigaction = sev_handler; printf("Now hitting sigaction(SIGSEGV, &sa\n"); sigaction(SIGSEGV, &sa, 0); printf("Now hitting uint32_t *ptr = mmap(NULL, 0x4000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT, -1, 0)\n"); uint32_t *ptr = mmap(NULL, 0x4000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS | MAP_JIT, -1, 0); write_sprr_perm(0x3333333333333333); printf("Now hitting main at RET ptr[0] 0xD65F03C0\n"); ptr[0] = 0xD65F03C0; // ret // ptr[0] = 0x00201420; // ret printf("Now past main at RET ptr[0] 0xD65F03C0\n"); printf("Hitting for (int i = 0; i < 4; ++i)\n"); for (int i = 0; i < 4; ++i) sprr_test(ptr, make_sprr_val(i)); printf("Bottom of main{}\n"); /* return 0; */ }
[ "xss@xss.cx" ]
xss@xss.cx
f422523f73266c31b9a6ab288d9caeb1e51ddf7f
4dd7f261cc1334b7e966aaeefa7911510d50ad3c
/athena_signal/kernels/dios_ssp_aec/dios_ssp_aec_tde/dios_ssp_aec_tde_ring_buffer.c
c15183566fda6d885418a9ab2757c5793947a86d
[ "Apache-2.0" ]
permissive
ishine/athena-signal
bd721349610c246d0b1c9604677adedbe7b79b7a
570be321de35697fd954ef268184ac77a32d628c
refs/heads/master
2021-09-14T16:50:05.470130
2021-08-17T09:28:00
2021-08-17T09:28:00
239,663,241
1
0
Apache-2.0
2021-04-23T07:11:19
2020-02-11T02:58:48
C
UTF-8
C
false
false
2,126
c
/* Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Description: some codes of this file refers to Webrtc (https://webrtc.org/) which is an open source. this file aims to make a a ring buffer to hold arbitrary data. Provides no thread safety. Unless otherwise specified, functions return 0 on success and -1 on error. ==============================================================================*/ /* include file */ #include "dios_ssp_aec_tde_ring_buffer.h" enum Wrap { SAME_WRAP }; struct RingBuffer { size_t read_pos; size_t write_pos; size_t element_count; size_t element_size; enum Wrap rw_wrap; char* data; }; RingBuffer* dios_ssp_aec_tde_creatbuffer(size_t element_count, size_t element_size) { RingBuffer* self = NULL; if (element_count == 0 || element_size == 0) { return NULL; } self = (RingBuffer*)calloc(1, sizeof(RingBuffer)); if (!self) { return NULL; } self->data = (char*)calloc(element_count * element_size, sizeof(char)); if (!self->data) { free(self); self = NULL; return NULL; } self->element_count = element_count; self->element_size = element_size; return self; } int dios_ssp_aec_tde_initbuffer(RingBuffer* self) { if (!self) { return -1; } self->read_pos = 0; self->write_pos = 0; self->rw_wrap = SAME_WRAP; // Initialize buffer to zeros memset(self->data, 0, self->element_count * self->element_size); return 0; } void dios_ssp_aec_tde_freebuffer(void* handle) { RingBuffer* self = (RingBuffer*)handle; if (!self) { return; } free(self->data); free(self); }
[ "ml-350.com" ]
ml-350.com
ee0847f760aa9088c807911cb1fb1e6190611918
d724bf68946436e970549a588e71a89e467cb2b3
/1.1_CTS/report/source/functions/G30232.c
9816199dcef820af39b96a164cf127b40e040755
[ "Apache-2.0" ]
permissive
neiltrevett/OpenVG-CTS
414a64b04dd5303b600dc2b2011a356027e535f9
75cdf231eb34cb89c2082d9cf065ec5938f5464c
refs/heads/master
2022-07-28T12:50:45.459085
2020-02-19T10:52:32
2020-02-19T10:52:32
266,667,754
0
0
Apache-2.0
2020-05-25T02:45:15
2020-05-25T02:45:15
null
UTF-8
C
false
false
2,348
c
/*------------------------------------------------------------------------------ Copyright (c) 2008 The Khronos Group Inc. All Rights Reserved. This code is protected by copyright laws and contains material proprietary to the Khronos Group, Inc. This is UNPUBLISHED PROPRIETARY SOURCE CODE that may not be disclosed in whole or in part to third parties, and may not be reproduced, republished, distributed, transmitted, displayed, broadcast or otherwise exploited in any manner without the express prior written permission of Khronos Group. The receipt or possession of this code does not convey any rights to reproduce, disclose, or distribute its contents, or to manufacture, use, or sell anything that it may describe, in whole or in part other than under the terms of the Khronos Adopters Agreement or Khronos Conformance Test Source License Agreement as executed between Khronos and the recipient. For the avoidance of doubt, this code when provided: a) under the Khronos Conformance Test Source License Agreement is for the sole purpose of creating conformance tests for delivery to Khronos and does not provide for formally testing products or use of Khronos trademarks on conformant products; b) under the Khronos Adopters Agreement is for the sole purpose of formally administering tests to products pursuant to the Khronos Conformance Process Document. Khronos, OpenKODE, OpenVG, OpenWF, glFX, OpenMAX and OpenSL ES are trademarks of the Khronos Group Inc. COLLADA is a trademark of Sony Computer Entertainment Inc. used by permission by Khronos. OpenGL and OpenML are registered trademarks and the OpenGL ES logo is a trademark of Silicon Graphics Inc. used by permission by Khronos. Use, duplication or disclosure by the Government is subject to restrictions as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at DFARS 252.227-7013, and/or in similar or successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished rights reserved under the Copyright Laws of the United States and other countries. ------------------------------------------------------------------------------*/ #include "../main.h" #include "../util/util.h" CT_Result G30232_PathStroking_by_ATI (CT_File AnsFile, CT_File RefFile) { return (int)PyramidDiff_by_HYBRID(AnsFile.tga, RefFile.tga); }
[ "hwan@ajou.ac.kr" ]
hwan@ajou.ac.kr
47c33aba4ab157522510eccf106f4a383b219fe0
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/fs/ceph/extr_mds_client.c_parse_reply_info.c
ec1649ee2b37152b194072b4faa14c39e953330a
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
2,169
c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_2__ TYPE_1__ ; /* Type definitions */ typedef int /*<<< orphan*/ u64 ; typedef scalar_t__ u32 ; struct TYPE_2__ {int iov_len; void* iov_base; } ; struct ceph_msg {TYPE_1__ front; } ; struct ceph_mds_reply_info_parsed {void* snapblob; scalar_t__ snapblob_len; void* head; } ; struct ceph_mds_reply_head {int dummy; } ; /* Variables and functions */ int EIO ; int /*<<< orphan*/ bad ; int /*<<< orphan*/ ceph_decode_32_safe (void**,void*,scalar_t__,int /*<<< orphan*/ ) ; int /*<<< orphan*/ ceph_decode_need (void**,void*,scalar_t__,int /*<<< orphan*/ ) ; int parse_reply_info_extra (void**,void*,struct ceph_mds_reply_info_parsed*,int /*<<< orphan*/ ) ; int parse_reply_info_trace (void**,void*,struct ceph_mds_reply_info_parsed*,int /*<<< orphan*/ ) ; int /*<<< orphan*/ pr_err (char*,int) ; __attribute__((used)) static int parse_reply_info(struct ceph_msg *msg, struct ceph_mds_reply_info_parsed *info, u64 features) { void *p, *end; u32 len; int err; info->head = msg->front.iov_base; p = msg->front.iov_base + sizeof(struct ceph_mds_reply_head); end = p + msg->front.iov_len - sizeof(struct ceph_mds_reply_head); /* trace */ ceph_decode_32_safe(&p, end, len, bad); if (len > 0) { ceph_decode_need(&p, end, len, bad); err = parse_reply_info_trace(&p, p+len, info, features); if (err < 0) goto out_bad; } /* extra */ ceph_decode_32_safe(&p, end, len, bad); if (len > 0) { ceph_decode_need(&p, end, len, bad); err = parse_reply_info_extra(&p, p+len, info, features); if (err < 0) goto out_bad; } /* snap blob */ ceph_decode_32_safe(&p, end, len, bad); info->snapblob_len = len; info->snapblob = p; p += len; if (p != end) goto bad; return 0; bad: err = -EIO; out_bad: pr_err("mds parse_reply err %d\n", err); return err; }
[ "brenocfg@gmail.com" ]
brenocfg@gmail.com
d0a2e82287d8db6fd6fe348572e2c9c532d24632
23a4889166bde810bfea2c22c5759e4099cd31ca
/src/mbyte.c
9b788b0d5e59ec40df4de6831b9bf702d350c398
[ "Vim" ]
permissive
zhoujian1210/vim
f423abbe43ad75e9be58d53e438f8be7636d2a83
3f54fd319f6641b4bed478bcc90cdb39ede68e31
refs/heads/master
2021-04-27T00:10:07.216072
2018-03-03T20:29:55
2018-03-03T20:29:55
null
0
0
null
null
null
null
UTF-8
C
false
false
169,720
c
/* vi:set ts=8 sts=4 sw=4 noet: * * VIM - Vi IMproved by Bram Moolenaar * Multibyte extensions partly by Sung-Hoon Baek * * Do ":help uganda" in Vim to read copying and usage conditions. * Do ":help credits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. */ /* * mbyte.c: Code specifically for handling multi-byte characters. * * The encoding used in the core is set with 'encoding'. When 'encoding' is * changed, the following four variables are set (for speed). * Currently these types of character encodings are supported: * * "enc_dbcs" When non-zero it tells the type of double byte character * encoding (Chinese, Korean, Japanese, etc.). * The cell width on the display is equal to the number of * bytes. (exception: DBCS_JPNU with first byte 0x8e) * Recognizing the first or second byte is difficult, it * requires checking a byte sequence from the start. * "enc_utf8" When TRUE use Unicode characters in UTF-8 encoding. * The cell width on the display needs to be determined from * the character value. * Recognizing bytes is easy: 0xxx.xxxx is a single-byte * char, 10xx.xxxx is a trailing byte, 11xx.xxxx is a leading * byte of a multi-byte character. * To make things complicated, up to six composing characters * are allowed. These are drawn on top of the first char. * For most editing the sequence of bytes with composing * characters included is considered to be one character. * "enc_unicode" When 2 use 16-bit Unicode characters (or UTF-16). * When 4 use 32-but Unicode characters. * Internally characters are stored in UTF-8 encoding to * avoid NUL bytes. Conversion happens when doing I/O. * "enc_utf8" will also be TRUE. * * "has_mbyte" is set when "enc_dbcs" or "enc_utf8" is non-zero. * * If none of these is TRUE, 8-bit bytes are used for a character. The * encoding isn't currently specified (TODO). * * 'encoding' specifies the encoding used in the core. This is in registers, * text manipulation, buffers, etc. Conversion has to be done when characters * in another encoding are received or send: * * clipboard * ^ * | (2) * V * +---------------+ * (1) | | (3) * keyboard ----->| core |-----> display * | | * +---------------+ * ^ * | (4) * V * file * * (1) Typed characters arrive in the current locale. Conversion is to be * done when 'encoding' is different from 'termencoding'. * (2) Text will be made available with the encoding specified with * 'encoding'. If this is not sufficient, system-specific conversion * might be required. * (3) For the GUI the correct font must be selected, no conversion done. * Otherwise, conversion is to be done when 'encoding' differs from * 'termencoding'. (Different in the GTK+ 2 port -- 'termencoding' * is always used for both input and output and must always be set to * "utf-8". gui_mch_init() does this automatically.) * (4) The encoding of the file is specified with 'fileencoding'. Conversion * is to be done when it's different from 'encoding'. * * The viminfo file is a special case: Only text is converted, not file names. * Vim scripts may contain an ":encoding" command. This has an effect for * some commands, like ":menutrans" */ #include "vim.h" #ifdef WIN32UNIX # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif # if defined(FEAT_GUI) || defined(FEAT_XCLIPBOARD) # include <X11/Xwindows.h> # define WINBYTE wBYTE # else # include <windows.h> # define WINBYTE BYTE # endif # ifdef WIN32 # undef WIN32 /* Some windows.h define WIN32, we don't want that here. */ # endif #else # define WINBYTE BYTE #endif #if (defined(WIN3264) || defined(WIN32UNIX)) && !defined(__MINGW32__) # include <winnls.h> #endif #ifdef FEAT_GUI_X11 # include <X11/Intrinsic.h> #endif #ifdef X_LOCALE # include <X11/Xlocale.h> # if !defined(HAVE_MBLEN) && !defined(mblen) # define mblen _Xmblen # endif #endif #if defined(FEAT_GUI_GTK) && defined(FEAT_XIM) # if GTK_CHECK_VERSION(3,0,0) # include <gdk/gdkkeysyms-compat.h> # else # include <gdk/gdkkeysyms.h> # endif # ifdef WIN3264 # include <gdk/gdkwin32.h> # else # include <gdk/gdkx.h> # endif #endif #ifdef HAVE_WCHAR_H # include <wchar.h> #endif #if 0 /* This has been disabled, because several people reported problems with the * wcwidth() and iswprint() library functions, esp. for Hebrew. */ # ifdef __STDC_ISO_10646__ # define USE_WCHAR_FUNCTIONS # endif #endif #if defined(FEAT_MBYTE) || defined(PROTO) static int enc_canon_search(char_u *name); static int dbcs_char2len(int c); static int dbcs_char2bytes(int c, char_u *buf); static int dbcs_ptr2len(char_u *p); static int dbcs_ptr2len_len(char_u *p, int size); static int utf_ptr2cells_len(char_u *p, int size); static int dbcs_char2cells(int c); static int dbcs_ptr2cells_len(char_u *p, int size); static int dbcs_ptr2char(char_u *p); static int utf_safe_read_char_adv(char_u **s, size_t *n); /* * Lookup table to quickly get the length in bytes of a UTF-8 character from * the first byte of a UTF-8 string. * Bytes which are illegal when used as the first byte have a 1. * The NUL byte has length 1. */ static char utf8len_tab[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,1,1, }; /* * Like utf8len_tab above, but using a zero for illegal lead bytes. */ static char utf8len_tab_zero[256] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,6,6,0,0, }; /* * XIM often causes trouble. Define XIM_DEBUG to get a log of XIM callbacks * in the "xim.log" file. */ /* #define XIM_DEBUG */ #ifdef XIM_DEBUG static void xim_log(char *s, ...) { va_list arglist; static FILE *fd = NULL; if (fd == (FILE *)-1) return; if (fd == NULL) { fd = mch_fopen("xim.log", "w"); if (fd == NULL) { EMSG("Cannot open xim.log"); fd = (FILE *)-1; return; } } va_start(arglist, s); vfprintf(fd, s, arglist); va_end(arglist); } #endif #endif #if defined(FEAT_MBYTE) || defined(FEAT_POSTSCRIPT) || defined(PROTO) /* * Canonical encoding names and their properties. * "iso-8859-n" is handled by enc_canonize() directly. */ static struct { char *name; int prop; int codepage;} enc_canon_table[] = { #define IDX_LATIN_1 0 {"latin1", ENC_8BIT + ENC_LATIN1, 1252}, #define IDX_ISO_2 1 {"iso-8859-2", ENC_8BIT, 0}, #define IDX_ISO_3 2 {"iso-8859-3", ENC_8BIT, 0}, #define IDX_ISO_4 3 {"iso-8859-4", ENC_8BIT, 0}, #define IDX_ISO_5 4 {"iso-8859-5", ENC_8BIT, 0}, #define IDX_ISO_6 5 {"iso-8859-6", ENC_8BIT, 0}, #define IDX_ISO_7 6 {"iso-8859-7", ENC_8BIT, 0}, #define IDX_ISO_8 7 {"iso-8859-8", ENC_8BIT, 0}, #define IDX_ISO_9 8 {"iso-8859-9", ENC_8BIT, 0}, #define IDX_ISO_10 9 {"iso-8859-10", ENC_8BIT, 0}, #define IDX_ISO_11 10 {"iso-8859-11", ENC_8BIT, 0}, #define IDX_ISO_13 11 {"iso-8859-13", ENC_8BIT, 0}, #define IDX_ISO_14 12 {"iso-8859-14", ENC_8BIT, 0}, #define IDX_ISO_15 13 {"iso-8859-15", ENC_8BIT + ENC_LATIN9, 0}, #define IDX_KOI8_R 14 {"koi8-r", ENC_8BIT, 0}, #define IDX_KOI8_U 15 {"koi8-u", ENC_8BIT, 0}, #define IDX_UTF8 16 {"utf-8", ENC_UNICODE, 0}, #define IDX_UCS2 17 {"ucs-2", ENC_UNICODE + ENC_ENDIAN_B + ENC_2BYTE, 0}, #define IDX_UCS2LE 18 {"ucs-2le", ENC_UNICODE + ENC_ENDIAN_L + ENC_2BYTE, 0}, #define IDX_UTF16 19 {"utf-16", ENC_UNICODE + ENC_ENDIAN_B + ENC_2WORD, 0}, #define IDX_UTF16LE 20 {"utf-16le", ENC_UNICODE + ENC_ENDIAN_L + ENC_2WORD, 0}, #define IDX_UCS4 21 {"ucs-4", ENC_UNICODE + ENC_ENDIAN_B + ENC_4BYTE, 0}, #define IDX_UCS4LE 22 {"ucs-4le", ENC_UNICODE + ENC_ENDIAN_L + ENC_4BYTE, 0}, /* For debugging DBCS encoding on Unix. */ #define IDX_DEBUG 23 {"debug", ENC_DBCS, DBCS_DEBUG}, #define IDX_EUC_JP 24 {"euc-jp", ENC_DBCS, DBCS_JPNU}, #define IDX_SJIS 25 {"sjis", ENC_DBCS, DBCS_JPN}, #define IDX_EUC_KR 26 {"euc-kr", ENC_DBCS, DBCS_KORU}, #define IDX_EUC_CN 27 {"euc-cn", ENC_DBCS, DBCS_CHSU}, #define IDX_EUC_TW 28 {"euc-tw", ENC_DBCS, DBCS_CHTU}, #define IDX_BIG5 29 {"big5", ENC_DBCS, DBCS_CHT}, /* MS-DOS and MS-Windows codepages are included here, so that they can be * used on Unix too. Most of them are similar to ISO-8859 encodings, but * not exactly the same. */ #define IDX_CP437 30 {"cp437", ENC_8BIT, 437}, /* like iso-8859-1 */ #define IDX_CP737 31 {"cp737", ENC_8BIT, 737}, /* like iso-8859-7 */ #define IDX_CP775 32 {"cp775", ENC_8BIT, 775}, /* Baltic */ #define IDX_CP850 33 {"cp850", ENC_8BIT, 850}, /* like iso-8859-4 */ #define IDX_CP852 34 {"cp852", ENC_8BIT, 852}, /* like iso-8859-1 */ #define IDX_CP855 35 {"cp855", ENC_8BIT, 855}, /* like iso-8859-2 */ #define IDX_CP857 36 {"cp857", ENC_8BIT, 857}, /* like iso-8859-5 */ #define IDX_CP860 37 {"cp860", ENC_8BIT, 860}, /* like iso-8859-9 */ #define IDX_CP861 38 {"cp861", ENC_8BIT, 861}, /* like iso-8859-1 */ #define IDX_CP862 39 {"cp862", ENC_8BIT, 862}, /* like iso-8859-1 */ #define IDX_CP863 40 {"cp863", ENC_8BIT, 863}, /* like iso-8859-8 */ #define IDX_CP865 41 {"cp865", ENC_8BIT, 865}, /* like iso-8859-1 */ #define IDX_CP866 42 {"cp866", ENC_8BIT, 866}, /* like iso-8859-5 */ #define IDX_CP869 43 {"cp869", ENC_8BIT, 869}, /* like iso-8859-7 */ #define IDX_CP874 44 {"cp874", ENC_8BIT, 874}, /* Thai */ #define IDX_CP932 45 {"cp932", ENC_DBCS, DBCS_JPN}, #define IDX_CP936 46 {"cp936", ENC_DBCS, DBCS_CHS}, #define IDX_CP949 47 {"cp949", ENC_DBCS, DBCS_KOR}, #define IDX_CP950 48 {"cp950", ENC_DBCS, DBCS_CHT}, #define IDX_CP1250 49 {"cp1250", ENC_8BIT, 1250}, /* Czech, Polish, etc. */ #define IDX_CP1251 50 {"cp1251", ENC_8BIT, 1251}, /* Cyrillic */ /* cp1252 is considered to be equal to latin1 */ #define IDX_CP1253 51 {"cp1253", ENC_8BIT, 1253}, /* Greek */ #define IDX_CP1254 52 {"cp1254", ENC_8BIT, 1254}, /* Turkish */ #define IDX_CP1255 53 {"cp1255", ENC_8BIT, 1255}, /* Hebrew */ #define IDX_CP1256 54 {"cp1256", ENC_8BIT, 1256}, /* Arabic */ #define IDX_CP1257 55 {"cp1257", ENC_8BIT, 1257}, /* Baltic */ #define IDX_CP1258 56 {"cp1258", ENC_8BIT, 1258}, /* Vietnamese */ #define IDX_MACROMAN 57 {"macroman", ENC_8BIT + ENC_MACROMAN, 0}, /* Mac OS */ #define IDX_DECMCS 58 {"dec-mcs", ENC_8BIT, 0}, /* DEC MCS */ #define IDX_HPROMAN8 59 {"hp-roman8", ENC_8BIT, 0}, /* HP Roman8 */ #define IDX_COUNT 60 }; /* * Aliases for encoding names. */ static struct { char *name; int canon;} enc_alias_table[] = { {"ansi", IDX_LATIN_1}, {"iso-8859-1", IDX_LATIN_1}, {"latin2", IDX_ISO_2}, {"latin3", IDX_ISO_3}, {"latin4", IDX_ISO_4}, {"cyrillic", IDX_ISO_5}, {"arabic", IDX_ISO_6}, {"greek", IDX_ISO_7}, #ifdef WIN3264 {"hebrew", IDX_CP1255}, #else {"hebrew", IDX_ISO_8}, #endif {"latin5", IDX_ISO_9}, {"turkish", IDX_ISO_9}, /* ? */ {"latin6", IDX_ISO_10}, {"nordic", IDX_ISO_10}, /* ? */ {"thai", IDX_ISO_11}, /* ? */ {"latin7", IDX_ISO_13}, {"latin8", IDX_ISO_14}, {"latin9", IDX_ISO_15}, {"utf8", IDX_UTF8}, {"unicode", IDX_UCS2}, {"ucs2", IDX_UCS2}, {"ucs2be", IDX_UCS2}, {"ucs-2be", IDX_UCS2}, {"ucs2le", IDX_UCS2LE}, {"utf16", IDX_UTF16}, {"utf16be", IDX_UTF16}, {"utf-16be", IDX_UTF16}, {"utf16le", IDX_UTF16LE}, {"ucs4", IDX_UCS4}, {"ucs4be", IDX_UCS4}, {"ucs-4be", IDX_UCS4}, {"ucs4le", IDX_UCS4LE}, {"utf32", IDX_UCS4}, {"utf-32", IDX_UCS4}, {"utf32be", IDX_UCS4}, {"utf-32be", IDX_UCS4}, {"utf32le", IDX_UCS4LE}, {"utf-32le", IDX_UCS4LE}, {"932", IDX_CP932}, {"949", IDX_CP949}, {"936", IDX_CP936}, {"gbk", IDX_CP936}, {"950", IDX_CP950}, {"eucjp", IDX_EUC_JP}, {"unix-jis", IDX_EUC_JP}, {"ujis", IDX_EUC_JP}, {"shift-jis", IDX_SJIS}, {"pck", IDX_SJIS}, /* Sun: PCK */ {"euckr", IDX_EUC_KR}, {"5601", IDX_EUC_KR}, /* Sun: KS C 5601 */ {"euccn", IDX_EUC_CN}, {"gb2312", IDX_EUC_CN}, {"euctw", IDX_EUC_TW}, #if defined(WIN3264) || defined(WIN32UNIX) || defined(MACOS_X) {"japan", IDX_CP932}, {"korea", IDX_CP949}, {"prc", IDX_CP936}, {"chinese", IDX_CP936}, {"taiwan", IDX_CP950}, {"big5", IDX_CP950}, #else {"japan", IDX_EUC_JP}, {"korea", IDX_EUC_KR}, {"prc", IDX_EUC_CN}, {"chinese", IDX_EUC_CN}, {"taiwan", IDX_EUC_TW}, {"cp950", IDX_BIG5}, {"950", IDX_BIG5}, #endif {"mac", IDX_MACROMAN}, {"mac-roman", IDX_MACROMAN}, {NULL, 0} }; #ifndef CP_UTF8 # define CP_UTF8 65001 /* magic number from winnls.h */ #endif /* * Find encoding "name" in the list of canonical encoding names. * Returns -1 if not found. */ static int enc_canon_search(char_u *name) { int i; for (i = 0; i < IDX_COUNT; ++i) if (STRCMP(name, enc_canon_table[i].name) == 0) return i; return -1; } #endif #if defined(FEAT_MBYTE) || defined(PROTO) /* * Find canonical encoding "name" in the list and return its properties. * Returns 0 if not found. */ int enc_canon_props(char_u *name) { int i; i = enc_canon_search(name); if (i >= 0) return enc_canon_table[i].prop; #ifdef WIN3264 if (name[0] == 'c' && name[1] == 'p' && VIM_ISDIGIT(name[2])) { CPINFO cpinfo; /* Get info on this codepage to find out what it is. */ if (GetCPInfo(atoi((char *)name + 2), &cpinfo) != 0) { if (cpinfo.MaxCharSize == 1) /* some single-byte encoding */ return ENC_8BIT; if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) /* must be a DBCS encoding */ return ENC_DBCS; } return 0; } #endif if (STRNCMP(name, "2byte-", 6) == 0) return ENC_DBCS; if (STRNCMP(name, "8bit-", 5) == 0 || STRNCMP(name, "iso-8859-", 9) == 0) return ENC_8BIT; return 0; } /* * Set up for using multi-byte characters. * Called in three cases: * - by main() to initialize (p_enc == NULL) * - by set_init_1() after 'encoding' was set to its default. * - by do_set() when 'encoding' has been set. * p_enc must have been passed through enc_canonize() already. * Sets the "enc_unicode", "enc_utf8", "enc_dbcs" and "has_mbyte" flags. * Fills mb_bytelen_tab[] and returns NULL when there are no problems. * When there is something wrong: Returns an error message and doesn't change * anything. */ char_u * mb_init(void) { int i; int idx; int n; int enc_dbcs_new = 0; #if defined(USE_ICONV) && !defined(WIN3264) && !defined(WIN32UNIX) \ && !defined(MACOS_CONVERT) # define LEN_FROM_CONV vimconv_T vimconv; char_u *p; #endif if (p_enc == NULL) { /* Just starting up: set the whole table to one's. */ for (i = 0; i < 256; ++i) mb_bytelen_tab[i] = 1; input_conv.vc_type = CONV_NONE; input_conv.vc_factor = 1; output_conv.vc_type = CONV_NONE; return NULL; } #ifdef WIN3264 if (p_enc[0] == 'c' && p_enc[1] == 'p' && VIM_ISDIGIT(p_enc[2])) { CPINFO cpinfo; /* Get info on this codepage to find out what it is. */ if (GetCPInfo(atoi((char *)p_enc + 2), &cpinfo) != 0) { if (cpinfo.MaxCharSize == 1) { /* some single-byte encoding */ enc_unicode = 0; enc_utf8 = FALSE; } else if (cpinfo.MaxCharSize == 2 && (cpinfo.LeadByte[0] != 0 || cpinfo.LeadByte[1] != 0)) { /* must be a DBCS encoding, check below */ enc_dbcs_new = atoi((char *)p_enc + 2); } else goto codepage_invalid; } else if (GetLastError() == ERROR_INVALID_PARAMETER) { codepage_invalid: return (char_u *)N_("E543: Not a valid codepage"); } } #endif else if (STRNCMP(p_enc, "8bit-", 5) == 0 || STRNCMP(p_enc, "iso-8859-", 9) == 0) { /* Accept any "8bit-" or "iso-8859-" name. */ enc_unicode = 0; enc_utf8 = FALSE; } else if (STRNCMP(p_enc, "2byte-", 6) == 0) { #ifdef WIN3264 /* Windows: accept only valid codepage numbers, check below. */ if (p_enc[6] != 'c' || p_enc[7] != 'p' || (enc_dbcs_new = atoi((char *)p_enc + 8)) == 0) return e_invarg; #else /* Unix: accept any "2byte-" name, assume current locale. */ enc_dbcs_new = DBCS_2BYTE; #endif } else if ((idx = enc_canon_search(p_enc)) >= 0) { i = enc_canon_table[idx].prop; if (i & ENC_UNICODE) { /* Unicode */ enc_utf8 = TRUE; if (i & (ENC_2BYTE | ENC_2WORD)) enc_unicode = 2; else if (i & ENC_4BYTE) enc_unicode = 4; else enc_unicode = 0; } else if (i & ENC_DBCS) { /* 2byte, handle below */ enc_dbcs_new = enc_canon_table[idx].codepage; } else { /* Must be 8-bit. */ enc_unicode = 0; enc_utf8 = FALSE; } } else /* Don't know what encoding this is, reject it. */ return e_invarg; if (enc_dbcs_new != 0) { #ifdef WIN3264 /* Check if the DBCS code page is OK. */ if (!IsValidCodePage(enc_dbcs_new)) goto codepage_invalid; #endif enc_unicode = 0; enc_utf8 = FALSE; } enc_dbcs = enc_dbcs_new; has_mbyte = (enc_dbcs != 0 || enc_utf8); #if defined(WIN3264) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD) enc_codepage = encname2codepage(p_enc); enc_latin9 = (STRCMP(p_enc, "iso-8859-15") == 0); #endif /* Detect an encoding that uses latin1 characters. */ enc_latin1like = (enc_utf8 || STRCMP(p_enc, "latin1") == 0 || STRCMP(p_enc, "iso-8859-15") == 0); /* * Set the function pointers. */ if (enc_utf8) { mb_ptr2len = utfc_ptr2len; mb_ptr2len_len = utfc_ptr2len_len; mb_char2len = utf_char2len; mb_char2bytes = utf_char2bytes; mb_ptr2cells = utf_ptr2cells; mb_ptr2cells_len = utf_ptr2cells_len; mb_char2cells = utf_char2cells; mb_off2cells = utf_off2cells; mb_ptr2char = utf_ptr2char; mb_head_off = utf_head_off; } else if (enc_dbcs != 0) { mb_ptr2len = dbcs_ptr2len; mb_ptr2len_len = dbcs_ptr2len_len; mb_char2len = dbcs_char2len; mb_char2bytes = dbcs_char2bytes; mb_ptr2cells = dbcs_ptr2cells; mb_ptr2cells_len = dbcs_ptr2cells_len; mb_char2cells = dbcs_char2cells; mb_off2cells = dbcs_off2cells; mb_ptr2char = dbcs_ptr2char; mb_head_off = dbcs_head_off; } else { mb_ptr2len = latin_ptr2len; mb_ptr2len_len = latin_ptr2len_len; mb_char2len = latin_char2len; mb_char2bytes = latin_char2bytes; mb_ptr2cells = latin_ptr2cells; mb_ptr2cells_len = latin_ptr2cells_len; mb_char2cells = latin_char2cells; mb_off2cells = latin_off2cells; mb_ptr2char = latin_ptr2char; mb_head_off = latin_head_off; } /* * Fill the mb_bytelen_tab[] for MB_BYTE2LEN(). */ #ifdef LEN_FROM_CONV /* When 'encoding' is different from the current locale mblen() won't * work. Use conversion to "utf-8" instead. */ vimconv.vc_type = CONV_NONE; if (enc_dbcs) { p = enc_locale(); if (p == NULL || STRCMP(p, p_enc) != 0) { convert_setup(&vimconv, p_enc, (char_u *)"utf-8"); vimconv.vc_fail = TRUE; } vim_free(p); } #endif for (i = 0; i < 256; ++i) { /* Our own function to reliably check the length of UTF-8 characters, * independent of mblen(). */ if (enc_utf8) n = utf8len_tab[i]; else if (enc_dbcs == 0) n = 1; else { #if defined(WIN3264) || defined(WIN32UNIX) /* enc_dbcs is set by setting 'fileencoding'. It becomes a Windows * CodePage identifier, which we can pass directly in to Windows * API */ n = IsDBCSLeadByteEx(enc_dbcs, (WINBYTE)i) ? 2 : 1; #else # if defined(__amigaos4__) || defined(__ANDROID__) || \ !(defined(HAVE_MBLEN) || defined(X_LOCALE)) /* * if mblen() is not available, character which MSB is turned on * are treated as leading byte character. (note : This assumption * is not always true.) */ n = (i & 0x80) ? 2 : 1; # else char buf[MB_MAXBYTES + 1]; if (i == NUL) /* just in case mblen() can't handle "" */ n = 1; else { buf[0] = i; buf[1] = 0; # ifdef LEN_FROM_CONV if (vimconv.vc_type != CONV_NONE) { /* * string_convert() should fail when converting the first * byte of a double-byte character. */ p = string_convert(&vimconv, (char_u *)buf, NULL); if (p != NULL) { vim_free(p); n = 1; } else n = 2; } else # endif { /* * mblen() should return -1 for invalid (means the leading * multibyte) character. However there are some platforms * where mblen() returns 0 for invalid character. * Therefore, following condition includes 0. */ ignored = mblen(NULL, 0); /* First reset the state. */ if (mblen(buf, (size_t)1) <= 0) n = 2; else n = 1; } } # endif #endif } mb_bytelen_tab[i] = n; } #ifdef LEN_FROM_CONV convert_setup(&vimconv, NULL, NULL); #endif /* The cell width depends on the type of multi-byte characters. */ (void)init_chartab(); /* When enc_utf8 is set or reset, (de)allocate ScreenLinesUC[] */ screenalloc(FALSE); /* When using Unicode, set default for 'fileencodings'. */ if (enc_utf8 && !option_was_set((char_u *)"fencs")) set_string_option_direct((char_u *)"fencs", -1, (char_u *)"ucs-bom,utf-8,default,latin1", OPT_FREE, 0); #if defined(HAVE_BIND_TEXTDOMAIN_CODESET) && defined(FEAT_GETTEXT) /* GNU gettext 0.10.37 supports this feature: set the codeset used for * translated messages independently from the current locale. */ (void)bind_textdomain_codeset(VIMPACKAGE, enc_utf8 ? "utf-8" : (char *)p_enc); #endif #ifdef WIN32 /* When changing 'encoding' while starting up, then convert the command * line arguments from the active codepage to 'encoding'. */ if (starting != 0) fix_arg_enc(); #endif #ifdef FEAT_AUTOCMD /* Fire an autocommand to let people do custom font setup. This must be * after Vim has been setup for the new encoding. */ apply_autocmds(EVENT_ENCODINGCHANGED, NULL, (char_u *)"", FALSE, curbuf); #endif #ifdef FEAT_SPELL /* Need to reload spell dictionaries */ spell_reload(); #endif return NULL; } /* * Return the size of the BOM for the current buffer: * 0 - no BOM * 2 - UCS-2 or UTF-16 BOM * 4 - UCS-4 BOM * 3 - UTF-8 BOM */ int bomb_size(void) { int n = 0; if (curbuf->b_p_bomb && !curbuf->b_p_bin) { if (*curbuf->b_p_fenc == NUL) { if (enc_utf8) { if (enc_unicode != 0) n = enc_unicode; else n = 3; } } else if (STRCMP(curbuf->b_p_fenc, "utf-8") == 0) n = 3; else if (STRNCMP(curbuf->b_p_fenc, "ucs-2", 5) == 0 || STRNCMP(curbuf->b_p_fenc, "utf-16", 6) == 0) n = 2; else if (STRNCMP(curbuf->b_p_fenc, "ucs-4", 5) == 0) n = 4; } return n; } /* * Remove all BOM from "s" by moving remaining text. */ void remove_bom(char_u *s) { if (enc_utf8) { char_u *p = s; while ((p = vim_strbyte(p, 0xef)) != NULL) { if (p[1] == 0xbb && p[2] == 0xbf) STRMOVE(p, p + 3); else ++p; } } } /* * Get class of pointer: * 0 for blank or NUL * 1 for punctuation * 2 for an (ASCII) word character * >2 for other word characters */ int mb_get_class(char_u *p) { return mb_get_class_buf(p, curbuf); } int mb_get_class_buf(char_u *p, buf_T *buf) { if (MB_BYTE2LEN(p[0]) == 1) { if (p[0] == NUL || VIM_ISWHITE(p[0])) return 0; if (vim_iswordc_buf(p[0], buf)) return 2; return 1; } if (enc_dbcs != 0 && p[0] != NUL && p[1] != NUL) return dbcs_class(p[0], p[1]); if (enc_utf8) return utf_class_buf(utf_ptr2char(p), buf); return 0; } /* * Get class of a double-byte character. This always returns 3 or bigger. * TODO: Should return 1 for punctuation. */ int dbcs_class(unsigned lead, unsigned trail) { switch (enc_dbcs) { /* please add classify routine for your language in here */ case DBCS_JPNU: /* ? */ case DBCS_JPN: { /* JIS code classification */ unsigned char lb = lead; unsigned char tb = trail; /* convert process code to JIS */ # if defined(WIN3264) || defined(WIN32UNIX) || defined(MACOS_X) /* process code is SJIS */ if (lb <= 0x9f) lb = (lb - 0x81) * 2 + 0x21; else lb = (lb - 0xc1) * 2 + 0x21; if (tb <= 0x7e) tb -= 0x1f; else if (tb <= 0x9e) tb -= 0x20; else { tb -= 0x7e; lb += 1; } # else /* * XXX: Code page identification can not use with all * system! So, some other encoding information * will be needed. * In japanese: SJIS,EUC,UNICODE,(JIS) * Note that JIS-code system don't use as * process code in most system because it uses * escape sequences(JIS is context depend encoding). */ /* assume process code is JAPANESE-EUC */ lb &= 0x7f; tb &= 0x7f; # endif /* exceptions */ switch (lb << 8 | tb) { case 0x2121: /* ZENKAKU space */ return 0; case 0x2122: /* TOU-TEN (Japanese comma) */ case 0x2123: /* KU-TEN (Japanese period) */ case 0x2124: /* ZENKAKU comma */ case 0x2125: /* ZENKAKU period */ return 1; case 0x213c: /* prolongedsound handled as KATAKANA */ return 13; } /* sieved by KU code */ switch (lb) { case 0x21: case 0x22: /* special symbols */ return 10; case 0x23: /* alpha-numeric */ return 11; case 0x24: /* hiragana */ return 12; case 0x25: /* katakana */ return 13; case 0x26: /* greek */ return 14; case 0x27: /* russian */ return 15; case 0x28: /* lines */ return 16; default: /* kanji */ return 17; } } case DBCS_KORU: /* ? */ case DBCS_KOR: { /* KS code classification */ unsigned char c1 = lead; unsigned char c2 = trail; /* * 20 : Hangul * 21 : Hanja * 22 : Symbols * 23 : Alpha-numeric/Roman Letter (Full width) * 24 : Hangul Letter(Alphabet) * 25 : Roman Numeral/Greek Letter * 26 : Box Drawings * 27 : Unit Symbols * 28 : Circled/Parenthesized Letter * 29 : Hiragana/Katakana * 30 : Cyrillic Letter */ if (c1 >= 0xB0 && c1 <= 0xC8) /* Hangul */ return 20; #if defined(WIN3264) || defined(WIN32UNIX) else if (c1 <= 0xA0 || c2 <= 0xA0) /* Extended Hangul Region : MS UHC(Unified Hangul Code) */ /* c1: 0x81-0xA0 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xFE * c1: 0xA1-0xC6 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xA0 */ return 20; #endif else if (c1 >= 0xCA && c1 <= 0xFD) /* Hanja */ return 21; else switch (c1) { case 0xA1: case 0xA2: /* Symbols */ return 22; case 0xA3: /* Alpha-numeric */ return 23; case 0xA4: /* Hangul Letter(Alphabet) */ return 24; case 0xA5: /* Roman Numeral/Greek Letter */ return 25; case 0xA6: /* Box Drawings */ return 26; case 0xA7: /* Unit Symbols */ return 27; case 0xA8: case 0xA9: if (c2 <= 0xAF) return 25; /* Roman Letter */ else if (c2 >= 0xF6) return 22; /* Symbols */ else /* Circled/Parenthesized Letter */ return 28; case 0xAA: case 0xAB: /* Hiragana/Katakana */ return 29; case 0xAC: /* Cyrillic Letter */ return 30; } } default: break; } return 3; } /* * mb_char2len() function pointer. * Return length in bytes of character "c". * Returns 1 for a single-byte character. */ int latin_char2len(int c UNUSED) { return 1; } static int dbcs_char2len( int c) { if (c >= 0x100) return 2; return 1; } /* * mb_char2bytes() function pointer. * Convert a character to its bytes. * Returns the length in bytes. */ int latin_char2bytes(int c, char_u *buf) { buf[0] = c; return 1; } static int dbcs_char2bytes(int c, char_u *buf) { if (c >= 0x100) { buf[0] = (unsigned)c >> 8; buf[1] = c; /* Never use a NUL byte, it causes lots of trouble. It's an invalid * character anyway. */ if (buf[1] == NUL) buf[1] = '\n'; return 2; } buf[0] = c; return 1; } /* * mb_ptr2len() function pointer. * Get byte length of character at "*p" but stop at a NUL. * For UTF-8 this includes following composing characters. * Returns 0 when *p is NUL. */ int latin_ptr2len(char_u *p) { return MB_BYTE2LEN(*p); } static int dbcs_ptr2len( char_u *p) { int len; /* Check if second byte is not missing. */ len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; return len; } /* * mb_ptr2len_len() function pointer. * Like mb_ptr2len(), but limit to read "size" bytes. * Returns 0 for an empty string. * Returns 1 for an illegal char or an incomplete byte sequence. */ int latin_ptr2len_len(char_u *p, int size) { if (size < 1 || *p == NUL) return 0; return 1; } static int dbcs_ptr2len_len(char_u *p, int size) { int len; if (size < 1 || *p == NUL) return 0; if (size == 1) return 1; /* Check that second byte is not missing. */ len = MB_BYTE2LEN(*p); if (len == 2 && p[1] == NUL) len = 1; return len; } struct interval { long first; long last; }; /* * Return TRUE if "c" is in "table[size / sizeof(struct interval)]". */ static int intable(struct interval *table, size_t size, int c) { int mid, bot, top; /* first quick check for Latin1 etc. characters */ if (c < table[0].first) return FALSE; /* binary search in table */ bot = 0; top = (int)(size / sizeof(struct interval) - 1); while (top >= bot) { mid = (bot + top) / 2; if (table[mid].last < c) bot = mid + 1; else if (table[mid].first > c) top = mid - 1; else return TRUE; } return FALSE; } /* Sorted list of non-overlapping intervals of East Asian Ambiguous * characters, generated with ../runtime/tools/unicode.vim. */ static struct interval ambiguous[] = { {0x00a1, 0x00a1}, {0x00a4, 0x00a4}, {0x00a7, 0x00a8}, {0x00aa, 0x00aa}, {0x00ad, 0x00ae}, {0x00b0, 0x00b4}, {0x00b6, 0x00ba}, {0x00bc, 0x00bf}, {0x00c6, 0x00c6}, {0x00d0, 0x00d0}, {0x00d7, 0x00d8}, {0x00de, 0x00e1}, {0x00e6, 0x00e6}, {0x00e8, 0x00ea}, {0x00ec, 0x00ed}, {0x00f0, 0x00f0}, {0x00f2, 0x00f3}, {0x00f7, 0x00fa}, {0x00fc, 0x00fc}, {0x00fe, 0x00fe}, {0x0101, 0x0101}, {0x0111, 0x0111}, {0x0113, 0x0113}, {0x011b, 0x011b}, {0x0126, 0x0127}, {0x012b, 0x012b}, {0x0131, 0x0133}, {0x0138, 0x0138}, {0x013f, 0x0142}, {0x0144, 0x0144}, {0x0148, 0x014b}, {0x014d, 0x014d}, {0x0152, 0x0153}, {0x0166, 0x0167}, {0x016b, 0x016b}, {0x01ce, 0x01ce}, {0x01d0, 0x01d0}, {0x01d2, 0x01d2}, {0x01d4, 0x01d4}, {0x01d6, 0x01d6}, {0x01d8, 0x01d8}, {0x01da, 0x01da}, {0x01dc, 0x01dc}, {0x0251, 0x0251}, {0x0261, 0x0261}, {0x02c4, 0x02c4}, {0x02c7, 0x02c7}, {0x02c9, 0x02cb}, {0x02cd, 0x02cd}, {0x02d0, 0x02d0}, {0x02d8, 0x02db}, {0x02dd, 0x02dd}, {0x02df, 0x02df}, {0x0300, 0x036f}, {0x0391, 0x03a1}, {0x03a3, 0x03a9}, {0x03b1, 0x03c1}, {0x03c3, 0x03c9}, {0x0401, 0x0401}, {0x0410, 0x044f}, {0x0451, 0x0451}, {0x2010, 0x2010}, {0x2013, 0x2016}, {0x2018, 0x2019}, {0x201c, 0x201d}, {0x2020, 0x2022}, {0x2024, 0x2027}, {0x2030, 0x2030}, {0x2032, 0x2033}, {0x2035, 0x2035}, {0x203b, 0x203b}, {0x203e, 0x203e}, {0x2074, 0x2074}, {0x207f, 0x207f}, {0x2081, 0x2084}, {0x20ac, 0x20ac}, {0x2103, 0x2103}, {0x2105, 0x2105}, {0x2109, 0x2109}, {0x2113, 0x2113}, {0x2116, 0x2116}, {0x2121, 0x2122}, {0x2126, 0x2126}, {0x212b, 0x212b}, {0x2153, 0x2154}, {0x215b, 0x215e}, {0x2160, 0x216b}, {0x2170, 0x2179}, {0x2189, 0x2189}, {0x2190, 0x2199}, {0x21b8, 0x21b9}, {0x21d2, 0x21d2}, {0x21d4, 0x21d4}, {0x21e7, 0x21e7}, {0x2200, 0x2200}, {0x2202, 0x2203}, {0x2207, 0x2208}, {0x220b, 0x220b}, {0x220f, 0x220f}, {0x2211, 0x2211}, {0x2215, 0x2215}, {0x221a, 0x221a}, {0x221d, 0x2220}, {0x2223, 0x2223}, {0x2225, 0x2225}, {0x2227, 0x222c}, {0x222e, 0x222e}, {0x2234, 0x2237}, {0x223c, 0x223d}, {0x2248, 0x2248}, {0x224c, 0x224c}, {0x2252, 0x2252}, {0x2260, 0x2261}, {0x2264, 0x2267}, {0x226a, 0x226b}, {0x226e, 0x226f}, {0x2282, 0x2283}, {0x2286, 0x2287}, {0x2295, 0x2295}, {0x2299, 0x2299}, {0x22a5, 0x22a5}, {0x22bf, 0x22bf}, {0x2312, 0x2312}, {0x2460, 0x24e9}, {0x24eb, 0x254b}, {0x2550, 0x2573}, {0x2580, 0x258f}, {0x2592, 0x2595}, {0x25a0, 0x25a1}, {0x25a3, 0x25a9}, {0x25b2, 0x25b3}, {0x25b6, 0x25b7}, {0x25bc, 0x25bd}, {0x25c0, 0x25c1}, {0x25c6, 0x25c8}, {0x25cb, 0x25cb}, {0x25ce, 0x25d1}, {0x25e2, 0x25e5}, {0x25ef, 0x25ef}, {0x2605, 0x2606}, {0x2609, 0x2609}, {0x260e, 0x260f}, {0x261c, 0x261c}, {0x261e, 0x261e}, {0x2640, 0x2640}, {0x2642, 0x2642}, {0x2660, 0x2661}, {0x2663, 0x2665}, {0x2667, 0x266a}, {0x266c, 0x266d}, {0x266f, 0x266f}, {0x269e, 0x269f}, {0x26bf, 0x26bf}, {0x26c6, 0x26cd}, {0x26cf, 0x26d3}, {0x26d5, 0x26e1}, {0x26e3, 0x26e3}, {0x26e8, 0x26e9}, {0x26eb, 0x26f1}, {0x26f4, 0x26f4}, {0x26f6, 0x26f9}, {0x26fb, 0x26fc}, {0x26fe, 0x26ff}, {0x273d, 0x273d}, {0x2776, 0x277f}, {0x2b56, 0x2b59}, {0x3248, 0x324f}, {0xe000, 0xf8ff}, {0xfe00, 0xfe0f}, {0xfffd, 0xfffd}, {0x1f100, 0x1f10a}, {0x1f110, 0x1f12d}, {0x1f130, 0x1f169}, {0x1f170, 0x1f18d}, {0x1f18f, 0x1f190}, {0x1f19b, 0x1f1ac}, {0xe0100, 0xe01ef}, {0xf0000, 0xffffd}, {0x100000, 0x10fffd} }; #if defined(FEAT_TERMINAL) || defined(PROTO) /* * utf_char2cells() with different argument type for libvterm. */ int utf_uint2cells(UINT32_T c) { if (c >= 0x100 && utf_iscomposing((int)c)) return 0; return utf_char2cells((int)c); } #endif /* * For UTF-8 character "c" return 2 for a double-width character, 1 for others. * Returns 4 or 6 for an unprintable character. * Is only correct for characters >= 0x80. * When p_ambw is "double", return 2 for a character with East Asian Width * class 'A'(mbiguous). */ int utf_char2cells(int c) { /* Sorted list of non-overlapping intervals of East Asian double width * characters, generated with ../runtime/tools/unicode.vim. */ static struct interval doublewidth[] = { {0x1100, 0x115f}, {0x231a, 0x231b}, {0x2329, 0x232a}, {0x23e9, 0x23ec}, {0x23f0, 0x23f0}, {0x23f3, 0x23f3}, {0x25fd, 0x25fe}, {0x2614, 0x2615}, {0x2648, 0x2653}, {0x267f, 0x267f}, {0x2693, 0x2693}, {0x26a1, 0x26a1}, {0x26aa, 0x26ab}, {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26ce, 0x26ce}, {0x26d4, 0x26d4}, {0x26ea, 0x26ea}, {0x26f2, 0x26f3}, {0x26f5, 0x26f5}, {0x26fa, 0x26fa}, {0x26fd, 0x26fd}, {0x2705, 0x2705}, {0x270a, 0x270b}, {0x2728, 0x2728}, {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, {0x2757, 0x2757}, {0x2795, 0x2797}, {0x27b0, 0x27b0}, {0x27bf, 0x27bf}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, {0x2b55, 0x2b55}, {0x2e80, 0x2e99}, {0x2e9b, 0x2ef3}, {0x2f00, 0x2fd5}, {0x2ff0, 0x2ffb}, {0x3000, 0x303e}, {0x3041, 0x3096}, {0x3099, 0x30ff}, {0x3105, 0x312e}, {0x3131, 0x318e}, {0x3190, 0x31ba}, {0x31c0, 0x31e3}, {0x31f0, 0x321e}, {0x3220, 0x3247}, {0x3250, 0x32fe}, {0x3300, 0x4dbf}, {0x4e00, 0xa48c}, {0xa490, 0xa4c6}, {0xa960, 0xa97c}, {0xac00, 0xd7a3}, {0xf900, 0xfaff}, {0xfe10, 0xfe19}, {0xfe30, 0xfe52}, {0xfe54, 0xfe66}, {0xfe68, 0xfe6b}, {0xff01, 0xff60}, {0xffe0, 0xffe6}, {0x16fe0, 0x16fe1}, {0x17000, 0x187ec}, {0x18800, 0x18af2}, {0x1b000, 0x1b11e}, {0x1b170, 0x1b2fb}, {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f18e, 0x1f18e}, {0x1f191, 0x1f19a}, {0x1f200, 0x1f202}, {0x1f210, 0x1f23b}, {0x1f240, 0x1f248}, {0x1f250, 0x1f251}, {0x1f260, 0x1f265}, {0x1f300, 0x1f320}, {0x1f32d, 0x1f335}, {0x1f337, 0x1f37c}, {0x1f37e, 0x1f393}, {0x1f3a0, 0x1f3ca}, {0x1f3cf, 0x1f3d3}, {0x1f3e0, 0x1f3f0}, {0x1f3f4, 0x1f3f4}, {0x1f3f8, 0x1f43e}, {0x1f440, 0x1f440}, {0x1f442, 0x1f4fc}, {0x1f4ff, 0x1f53d}, {0x1f54b, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f57a, 0x1f57a}, {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a4}, {0x1f5fb, 0x1f64f}, {0x1f680, 0x1f6c5}, {0x1f6cc, 0x1f6cc}, {0x1f6d0, 0x1f6d2}, {0x1f6eb, 0x1f6ec}, {0x1f6f4, 0x1f6f8}, {0x1f910, 0x1f93e}, {0x1f940, 0x1f94c}, {0x1f950, 0x1f96b}, {0x1f980, 0x1f997}, {0x1f9c0, 0x1f9c0}, {0x1f9d0, 0x1f9e6}, {0x20000, 0x2fffd}, {0x30000, 0x3fffd} }; /* Sorted list of non-overlapping intervals of Emoji characters that don't * have ambiguous or double width, * based on http://unicode.org/emoji/charts/emoji-list.html */ static struct interval emoji_width[] = { {0x1f1e6, 0x1f1ff}, {0x1f321, 0x1f321}, {0x1f324, 0x1f32c}, {0x1f336, 0x1f336}, {0x1f37d, 0x1f37d}, {0x1f396, 0x1f397}, {0x1f399, 0x1f39b}, {0x1f39e, 0x1f39f}, {0x1f3cb, 0x1f3ce}, {0x1f3d4, 0x1f3df}, {0x1f3f3, 0x1f3f5}, {0x1f3f7, 0x1f3f7}, {0x1f43f, 0x1f43f}, {0x1f441, 0x1f441}, {0x1f4fd, 0x1f4fd}, {0x1f549, 0x1f54a}, {0x1f56f, 0x1f570}, {0x1f573, 0x1f579}, {0x1f587, 0x1f587}, {0x1f58a, 0x1f58d}, {0x1f590, 0x1f590}, {0x1f5a5, 0x1f5a5}, {0x1f5a8, 0x1f5a8}, {0x1f5b1, 0x1f5b2}, {0x1f5bc, 0x1f5bc}, {0x1f5c2, 0x1f5c4}, {0x1f5d1, 0x1f5d3}, {0x1f5dc, 0x1f5de}, {0x1f5e1, 0x1f5e1}, {0x1f5e3, 0x1f5e3}, {0x1f5e8, 0x1f5e8}, {0x1f5ef, 0x1f5ef}, {0x1f5f3, 0x1f5f3}, {0x1f5fa, 0x1f5fa}, {0x1f6cb, 0x1f6cf}, {0x1f6e0, 0x1f6e5}, {0x1f6e9, 0x1f6e9}, {0x1f6f0, 0x1f6f0}, {0x1f6f3, 0x1f6f3} }; if (c >= 0x100) { #ifdef USE_WCHAR_FUNCTIONS /* * Assume the library function wcwidth() works better than our own * stuff. It should return 1 for ambiguous width chars! */ int n = wcwidth(c); if (n < 0) return 6; /* unprintable, displays <xxxx> */ if (n > 1) return n; #else if (!utf_printable(c)) return 6; /* unprintable, displays <xxxx> */ if (intable(doublewidth, sizeof(doublewidth), c)) return 2; #endif if (p_emoji && intable(emoji_width, sizeof(emoji_width), c)) return 2; } /* Characters below 0x100 are influenced by 'isprint' option */ else if (c >= 0x80 && !vim_isprintc(c)) return 4; /* unprintable, displays <xx> */ if (c >= 0x80 && *p_ambw == 'd' && intable(ambiguous, sizeof(ambiguous), c)) return 2; return 1; } /* * mb_ptr2cells() function pointer. * Return the number of display cells character at "*p" occupies. * This doesn't take care of unprintable characters, use ptr2cells() for that. */ int latin_ptr2cells(char_u *p UNUSED) { return 1; } int utf_ptr2cells( char_u *p) { int c; /* Need to convert to a wide character. */ if (*p >= 0x80) { c = utf_ptr2char(p); /* An illegal byte is displayed as <xx>. */ if (utf_ptr2len(p) == 1 || c == NUL) return 4; /* If the char is ASCII it must be an overlong sequence. */ if (c < 0x80) return char2cells(c); return utf_char2cells(c); } return 1; } int dbcs_ptr2cells(char_u *p) { /* Number of cells is equal to number of bytes, except for euc-jp when * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && *p == 0x8e) return 1; return MB_BYTE2LEN(*p); } /* * mb_ptr2cells_len() function pointer. * Like mb_ptr2cells(), but limit string length to "size". * For an empty string or truncated character returns 1. */ int latin_ptr2cells_len(char_u *p UNUSED, int size UNUSED) { return 1; } static int utf_ptr2cells_len(char_u *p, int size) { int c; /* Need to convert to a wide character. */ if (size > 0 && *p >= 0x80) { if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) return 1; /* truncated */ c = utf_ptr2char(p); /* An illegal byte is displayed as <xx>. */ if (utf_ptr2len(p) == 1 || c == NUL) return 4; /* If the char is ASCII it must be an overlong sequence. */ if (c < 0x80) return char2cells(c); return utf_char2cells(c); } return 1; } static int dbcs_ptr2cells_len(char_u *p, int size) { /* Number of cells is equal to number of bytes, except for euc-jp when * the first byte is 0x8e. */ if (size <= 1 || (enc_dbcs == DBCS_JPNU && *p == 0x8e)) return 1; return MB_BYTE2LEN(*p); } /* * mb_char2cells() function pointer. * Return the number of display cells character "c" occupies. * Only takes care of multi-byte chars, not "^C" and such. */ int latin_char2cells(int c UNUSED) { return 1; } static int dbcs_char2cells(int c) { /* Number of cells is equal to number of bytes, except for euc-jp when * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && ((unsigned)c >> 8) == 0x8e) return 1; /* use the first byte */ return MB_BYTE2LEN((unsigned)c >> 8); } /* * Return the number of cells occupied by string "p". * Stop at a NUL character. When "len" >= 0 stop at character "p[len]". */ int mb_string2cells(char_u *p, int len) { int i; int clen = 0; for (i = 0; (len < 0 || i < len) && p[i] != NUL; i += (*mb_ptr2len)(p + i)) clen += (*mb_ptr2cells)(p + i); return clen; } /* * mb_off2cells() function pointer. * Return number of display cells for char at ScreenLines[off]. * We make sure that the offset used is less than "max_off". */ int latin_off2cells(unsigned off UNUSED, unsigned max_off UNUSED) { return 1; } int dbcs_off2cells(unsigned off, unsigned max_off) { /* never check beyond end of the line */ if (off >= max_off) return 1; /* Number of cells is equal to number of bytes, except for euc-jp when * the first byte is 0x8e. */ if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) return 1; return MB_BYTE2LEN(ScreenLines[off]); } int utf_off2cells(unsigned off, unsigned max_off) { return (off + 1 < max_off && ScreenLines[off + 1] == 0) ? 2 : 1; } /* * mb_ptr2char() function pointer. * Convert a byte sequence into a character. */ int latin_ptr2char(char_u *p) { return *p; } static int dbcs_ptr2char(char_u *p) { if (MB_BYTE2LEN(*p) > 1 && p[1] != NUL) return (p[0] << 8) + p[1]; return *p; } /* * Convert a UTF-8 byte sequence to a wide character. * If the sequence is illegal or truncated by a NUL the first byte is * returned. * For an overlong sequence this may return zero. * Does not include composing characters, of course. */ int utf_ptr2char(char_u *p) { int len; if (p[0] < 0x80) /* be quick for ASCII */ return p[0]; len = utf8len_tab_zero[p[0]]; if (len > 1 && (p[1] & 0xc0) == 0x80) { if (len == 2) return ((p[0] & 0x1f) << 6) + (p[1] & 0x3f); if ((p[2] & 0xc0) == 0x80) { if (len == 3) return ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f); if ((p[3] & 0xc0) == 0x80) { if (len == 4) return ((p[0] & 0x07) << 18) + ((p[1] & 0x3f) << 12) + ((p[2] & 0x3f) << 6) + (p[3] & 0x3f); if ((p[4] & 0xc0) == 0x80) { if (len == 5) return ((p[0] & 0x03) << 24) + ((p[1] & 0x3f) << 18) + ((p[2] & 0x3f) << 12) + ((p[3] & 0x3f) << 6) + (p[4] & 0x3f); if ((p[5] & 0xc0) == 0x80 && len == 6) return ((p[0] & 0x01) << 30) + ((p[1] & 0x3f) << 24) + ((p[2] & 0x3f) << 18) + ((p[3] & 0x3f) << 12) + ((p[4] & 0x3f) << 6) + (p[5] & 0x3f); } } } } /* Illegal value, just return the first byte */ return p[0]; } /* * Convert a UTF-8 byte sequence to a wide character. * String is assumed to be terminated by NUL or after "n" bytes, whichever * comes first. * The function is safe in the sense that it never accesses memory beyond the * first "n" bytes of "s". * * On success, returns decoded codepoint, advances "s" to the beginning of * next character and decreases "n" accordingly. * * If end of string was reached, returns 0 and, if "n" > 0, advances "s" past * NUL byte. * * If byte sequence is illegal or incomplete, returns -1 and does not advance * "s". */ static int utf_safe_read_char_adv(char_u **s, size_t *n) { int c, k; if (*n == 0) /* end of buffer */ return 0; k = utf8len_tab_zero[**s]; if (k == 1) { /* ASCII character or NUL */ (*n)--; return *(*s)++; } if ((size_t)k <= *n) { /* We have a multibyte sequence and it isn't truncated by buffer * limits so utf_ptr2char() is safe to use. Or the first byte is * illegal (k=0), and it's also safe to use utf_ptr2char(). */ c = utf_ptr2char(*s); /* On failure, utf_ptr2char() returns the first byte, so here we * check equality with the first byte. The only non-ASCII character * which equals the first byte of its own UTF-8 representation is * U+00C3 (UTF-8: 0xC3 0x83), so need to check that special case too. * It's safe even if n=1, else we would have k=2 > n. */ if (c != (int)(**s) || (c == 0xC3 && (*s)[1] == 0x83)) { /* byte sequence was successfully decoded */ *s += k; *n -= k; return c; } } /* byte sequence is incomplete or illegal */ return -1; } /* * Get character at **pp and advance *pp to the next character. * Note: composing characters are skipped! */ int mb_ptr2char_adv(char_u **pp) { int c; c = (*mb_ptr2char)(*pp); *pp += (*mb_ptr2len)(*pp); return c; } /* * Get character at **pp and advance *pp to the next character. * Note: composing characters are returned as separate characters. */ int mb_cptr2char_adv(char_u **pp) { int c; c = (*mb_ptr2char)(*pp); if (enc_utf8) *pp += utf_ptr2len(*pp); else *pp += (*mb_ptr2len)(*pp); return c; } #if defined(FEAT_ARABIC) || defined(PROTO) /* * Check whether we are dealing with Arabic combining characters. * Note: these are NOT really composing characters! */ int arabic_combine( int one, /* first character */ int two) /* character just after "one" */ { if (one == a_LAM) return arabic_maycombine(two); return FALSE; } /* * Check whether we are dealing with a character that could be regarded as an * Arabic combining character, need to check the character before this. */ int arabic_maycombine(int two) { if (p_arshape && !p_tbidi) return (two == a_ALEF_MADDA || two == a_ALEF_HAMZA_ABOVE || two == a_ALEF_HAMZA_BELOW || two == a_ALEF); return FALSE; } /* * Check if the character pointed to by "p2" is a composing character when it * comes after "p1". For Arabic sometimes "ab" is replaced with "c", which * behaves like a composing character. */ int utf_composinglike(char_u *p1, char_u *p2) { int c2; c2 = utf_ptr2char(p2); if (utf_iscomposing(c2)) return TRUE; if (!arabic_maycombine(c2)) return FALSE; return arabic_combine(utf_ptr2char(p1), c2); } #endif /* * Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO * composing characters. */ int utfc_ptr2char( char_u *p, int *pcc) /* return: composing chars, last one is 0 */ { int len; int c; int cc; int i = 0; c = utf_ptr2char(p); len = utf_ptr2len(p); /* Only accept a composing char when the first char isn't illegal. */ if ((len > 1 || *p < 0x80) && p[len] >= 0x80 && UTF_COMPOSINGLIKE(p, p + len)) { cc = utf_ptr2char(p + len); for (;;) { pcc[i++] = cc; if (i == MAX_MCO) break; len += utf_ptr2len(p + len); if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) break; } } if (i < MAX_MCO) /* last composing char must be 0 */ pcc[i] = 0; return c; } /* * Convert a UTF-8 byte string to a wide character. Also get up to MAX_MCO * composing characters. Use no more than p[maxlen]. */ int utfc_ptr2char_len( char_u *p, int *pcc, /* return: composing chars, last one is 0 */ int maxlen) { int len; int c; int cc; int i = 0; c = utf_ptr2char(p); len = utf_ptr2len_len(p, maxlen); /* Only accept a composing char when the first char isn't illegal. */ if ((len > 1 || *p < 0x80) && len < maxlen && p[len] >= 0x80 && UTF_COMPOSINGLIKE(p, p + len)) { cc = utf_ptr2char(p + len); for (;;) { pcc[i++] = cc; if (i == MAX_MCO) break; len += utf_ptr2len_len(p + len, maxlen - len); if (len >= maxlen || p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) break; } } if (i < MAX_MCO) /* last composing char must be 0 */ pcc[i] = 0; return c; } /* * Convert the character at screen position "off" to a sequence of bytes. * Includes the composing characters. * "buf" must at least have the length MB_MAXBYTES + 1. * Only to be used when ScreenLinesUC[off] != 0. * Returns the produced number of bytes. */ int utfc_char2bytes(int off, char_u *buf) { int len; int i; len = utf_char2bytes(ScreenLinesUC[off], buf); for (i = 0; i < Screen_mco; ++i) { if (ScreenLinesC[i][off] == 0) break; len += utf_char2bytes(ScreenLinesC[i][off], buf + len); } return len; } /* * Get the length of a UTF-8 byte sequence, not including any following * composing characters. * Returns 0 for "". * Returns 1 for an illegal byte sequence. */ int utf_ptr2len(char_u *p) { int len; int i; if (*p == NUL) return 0; len = utf8len_tab[*p]; for (i = 1; i < len; ++i) if ((p[i] & 0xc0) != 0x80) return 1; return len; } /* * Return length of UTF-8 character, obtained from the first byte. * "b" must be between 0 and 255! * Returns 1 for an invalid first byte value. */ int utf_byte2len(int b) { return utf8len_tab[b]; } /* * Get the length of UTF-8 byte sequence "p[size]". Does not include any * following composing characters. * Returns 1 for "". * Returns 1 for an illegal byte sequence (also in incomplete byte seq.). * Returns number > "size" for an incomplete byte sequence. * Never returns zero. */ int utf_ptr2len_len(char_u *p, int size) { int len; int i; int m; len = utf8len_tab[*p]; if (len == 1) return 1; /* NUL, ascii or illegal lead byte */ if (len > size) m = size; /* incomplete byte sequence. */ else m = len; for (i = 1; i < m; ++i) if ((p[i] & 0xc0) != 0x80) return 1; return len; } /* * Return the number of bytes the UTF-8 encoding of the character at "p" takes. * This includes following composing characters. */ int utfc_ptr2len(char_u *p) { int len; int b0 = *p; #ifdef FEAT_ARABIC int prevlen; #endif if (b0 == NUL) return 0; if (b0 < 0x80 && p[1] < 0x80) /* be quick for ASCII */ return 1; /* Skip over first UTF-8 char, stopping at a NUL byte. */ len = utf_ptr2len(p); /* Check for illegal byte. */ if (len == 1 && b0 >= 0x80) return 1; /* * Check for composing characters. We can handle only the first six, but * skip all of them (otherwise the cursor would get stuck). */ #ifdef FEAT_ARABIC prevlen = 0; #endif for (;;) { if (p[len] < 0x80 || !UTF_COMPOSINGLIKE(p + prevlen, p + len)) return len; /* Skip over composing char */ #ifdef FEAT_ARABIC prevlen = len; #endif len += utf_ptr2len(p + len); } } /* * Return the number of bytes the UTF-8 encoding of the character at "p[size]" * takes. This includes following composing characters. * Returns 0 for an empty string. * Returns 1 for an illegal char or an incomplete byte sequence. */ int utfc_ptr2len_len(char_u *p, int size) { int len; #ifdef FEAT_ARABIC int prevlen; #endif if (size < 1 || *p == NUL) return 0; if (p[0] < 0x80 && (size == 1 || p[1] < 0x80)) /* be quick for ASCII */ return 1; /* Skip over first UTF-8 char, stopping at a NUL byte. */ len = utf_ptr2len_len(p, size); /* Check for illegal byte and incomplete byte sequence. */ if ((len == 1 && p[0] >= 0x80) || len > size) return 1; /* * Check for composing characters. We can handle only the first six, but * skip all of them (otherwise the cursor would get stuck). */ #ifdef FEAT_ARABIC prevlen = 0; #endif while (len < size) { int len_next_char; if (p[len] < 0x80) break; /* * Next character length should not go beyond size to ensure that * UTF_COMPOSINGLIKE(...) does not read beyond size. */ len_next_char = utf_ptr2len_len(p + len, size - len); if (len_next_char > size - len) break; if (!UTF_COMPOSINGLIKE(p + prevlen, p + len)) break; /* Skip over composing char */ #ifdef FEAT_ARABIC prevlen = len; #endif len += len_next_char; } return len; } /* * Return the number of bytes the UTF-8 encoding of character "c" takes. * This does not include composing characters. */ int utf_char2len(int c) { if (c < 0x80) return 1; if (c < 0x800) return 2; if (c < 0x10000) return 3; if (c < 0x200000) return 4; if (c < 0x4000000) return 5; return 6; } /* * Convert Unicode character "c" to UTF-8 string in "buf[]". * Returns the number of bytes. */ int utf_char2bytes(int c, char_u *buf) { if (c < 0x80) /* 7 bits */ { buf[0] = c; return 1; } if (c < 0x800) /* 11 bits */ { buf[0] = 0xc0 + ((unsigned)c >> 6); buf[1] = 0x80 + (c & 0x3f); return 2; } if (c < 0x10000) /* 16 bits */ { buf[0] = 0xe0 + ((unsigned)c >> 12); buf[1] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[2] = 0x80 + (c & 0x3f); return 3; } if (c < 0x200000) /* 21 bits */ { buf[0] = 0xf0 + ((unsigned)c >> 18); buf[1] = 0x80 + (((unsigned)c >> 12) & 0x3f); buf[2] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[3] = 0x80 + (c & 0x3f); return 4; } if (c < 0x4000000) /* 26 bits */ { buf[0] = 0xf8 + ((unsigned)c >> 24); buf[1] = 0x80 + (((unsigned)c >> 18) & 0x3f); buf[2] = 0x80 + (((unsigned)c >> 12) & 0x3f); buf[3] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[4] = 0x80 + (c & 0x3f); return 5; } /* 31 bits */ buf[0] = 0xfc + ((unsigned)c >> 30); buf[1] = 0x80 + (((unsigned)c >> 24) & 0x3f); buf[2] = 0x80 + (((unsigned)c >> 18) & 0x3f); buf[3] = 0x80 + (((unsigned)c >> 12) & 0x3f); buf[4] = 0x80 + (((unsigned)c >> 6) & 0x3f); buf[5] = 0x80 + (c & 0x3f); return 6; } #if defined(FEAT_TERMINAL) || defined(PROTO) /* * utf_iscomposing() with different argument type for libvterm. */ int utf_iscomposing_uint(UINT32_T c) { return utf_iscomposing((int)c); } #endif /* * Return TRUE if "c" is a composing UTF-8 character. This means it will be * drawn on top of the preceding character. * Based on code from Markus Kuhn. */ int utf_iscomposing(int c) { /* Sorted list of non-overlapping intervals. * Generated by ../runtime/tools/unicode.vim. */ static struct interval combining[] = { {0x0300, 0x036f}, {0x0483, 0x0489}, {0x0591, 0x05bd}, {0x05bf, 0x05bf}, {0x05c1, 0x05c2}, {0x05c4, 0x05c5}, {0x05c7, 0x05c7}, {0x0610, 0x061a}, {0x064b, 0x065f}, {0x0670, 0x0670}, {0x06d6, 0x06dc}, {0x06df, 0x06e4}, {0x06e7, 0x06e8}, {0x06ea, 0x06ed}, {0x0711, 0x0711}, {0x0730, 0x074a}, {0x07a6, 0x07b0}, {0x07eb, 0x07f3}, {0x0816, 0x0819}, {0x081b, 0x0823}, {0x0825, 0x0827}, {0x0829, 0x082d}, {0x0859, 0x085b}, {0x08d4, 0x08e1}, {0x08e3, 0x0903}, {0x093a, 0x093c}, {0x093e, 0x094f}, {0x0951, 0x0957}, {0x0962, 0x0963}, {0x0981, 0x0983}, {0x09bc, 0x09bc}, {0x09be, 0x09c4}, {0x09c7, 0x09c8}, {0x09cb, 0x09cd}, {0x09d7, 0x09d7}, {0x09e2, 0x09e3}, {0x0a01, 0x0a03}, {0x0a3c, 0x0a3c}, {0x0a3e, 0x0a42}, {0x0a47, 0x0a48}, {0x0a4b, 0x0a4d}, {0x0a51, 0x0a51}, {0x0a70, 0x0a71}, {0x0a75, 0x0a75}, {0x0a81, 0x0a83}, {0x0abc, 0x0abc}, {0x0abe, 0x0ac5}, {0x0ac7, 0x0ac9}, {0x0acb, 0x0acd}, {0x0ae2, 0x0ae3}, {0x0afa, 0x0aff}, {0x0b01, 0x0b03}, {0x0b3c, 0x0b3c}, {0x0b3e, 0x0b44}, {0x0b47, 0x0b48}, {0x0b4b, 0x0b4d}, {0x0b56, 0x0b57}, {0x0b62, 0x0b63}, {0x0b82, 0x0b82}, {0x0bbe, 0x0bc2}, {0x0bc6, 0x0bc8}, {0x0bca, 0x0bcd}, {0x0bd7, 0x0bd7}, {0x0c00, 0x0c03}, {0x0c3e, 0x0c44}, {0x0c46, 0x0c48}, {0x0c4a, 0x0c4d}, {0x0c55, 0x0c56}, {0x0c62, 0x0c63}, {0x0c81, 0x0c83}, {0x0cbc, 0x0cbc}, {0x0cbe, 0x0cc4}, {0x0cc6, 0x0cc8}, {0x0cca, 0x0ccd}, {0x0cd5, 0x0cd6}, {0x0ce2, 0x0ce3}, {0x0d00, 0x0d03}, {0x0d3b, 0x0d3c}, {0x0d3e, 0x0d44}, {0x0d46, 0x0d48}, {0x0d4a, 0x0d4d}, {0x0d57, 0x0d57}, {0x0d62, 0x0d63}, {0x0d82, 0x0d83}, {0x0dca, 0x0dca}, {0x0dcf, 0x0dd4}, {0x0dd6, 0x0dd6}, {0x0dd8, 0x0ddf}, {0x0df2, 0x0df3}, {0x0e31, 0x0e31}, {0x0e34, 0x0e3a}, {0x0e47, 0x0e4e}, {0x0eb1, 0x0eb1}, {0x0eb4, 0x0eb9}, {0x0ebb, 0x0ebc}, {0x0ec8, 0x0ecd}, {0x0f18, 0x0f19}, {0x0f35, 0x0f35}, {0x0f37, 0x0f37}, {0x0f39, 0x0f39}, {0x0f3e, 0x0f3f}, {0x0f71, 0x0f84}, {0x0f86, 0x0f87}, {0x0f8d, 0x0f97}, {0x0f99, 0x0fbc}, {0x0fc6, 0x0fc6}, {0x102b, 0x103e}, {0x1056, 0x1059}, {0x105e, 0x1060}, {0x1062, 0x1064}, {0x1067, 0x106d}, {0x1071, 0x1074}, {0x1082, 0x108d}, {0x108f, 0x108f}, {0x109a, 0x109d}, {0x135d, 0x135f}, {0x1712, 0x1714}, {0x1732, 0x1734}, {0x1752, 0x1753}, {0x1772, 0x1773}, {0x17b4, 0x17d3}, {0x17dd, 0x17dd}, {0x180b, 0x180d}, {0x1885, 0x1886}, {0x18a9, 0x18a9}, {0x1920, 0x192b}, {0x1930, 0x193b}, {0x1a17, 0x1a1b}, {0x1a55, 0x1a5e}, {0x1a60, 0x1a7c}, {0x1a7f, 0x1a7f}, {0x1ab0, 0x1abe}, {0x1b00, 0x1b04}, {0x1b34, 0x1b44}, {0x1b6b, 0x1b73}, {0x1b80, 0x1b82}, {0x1ba1, 0x1bad}, {0x1be6, 0x1bf3}, {0x1c24, 0x1c37}, {0x1cd0, 0x1cd2}, {0x1cd4, 0x1ce8}, {0x1ced, 0x1ced}, {0x1cf2, 0x1cf4}, {0x1cf7, 0x1cf9}, {0x1dc0, 0x1df9}, {0x1dfb, 0x1dff}, {0x20d0, 0x20f0}, {0x2cef, 0x2cf1}, {0x2d7f, 0x2d7f}, {0x2de0, 0x2dff}, {0x302a, 0x302f}, {0x3099, 0x309a}, {0xa66f, 0xa672}, {0xa674, 0xa67d}, {0xa69e, 0xa69f}, {0xa6f0, 0xa6f1}, {0xa802, 0xa802}, {0xa806, 0xa806}, {0xa80b, 0xa80b}, {0xa823, 0xa827}, {0xa880, 0xa881}, {0xa8b4, 0xa8c5}, {0xa8e0, 0xa8f1}, {0xa926, 0xa92d}, {0xa947, 0xa953}, {0xa980, 0xa983}, {0xa9b3, 0xa9c0}, {0xa9e5, 0xa9e5}, {0xaa29, 0xaa36}, {0xaa43, 0xaa43}, {0xaa4c, 0xaa4d}, {0xaa7b, 0xaa7d}, {0xaab0, 0xaab0}, {0xaab2, 0xaab4}, {0xaab7, 0xaab8}, {0xaabe, 0xaabf}, {0xaac1, 0xaac1}, {0xaaeb, 0xaaef}, {0xaaf5, 0xaaf6}, {0xabe3, 0xabea}, {0xabec, 0xabed}, {0xfb1e, 0xfb1e}, {0xfe00, 0xfe0f}, {0xfe20, 0xfe2f}, {0x101fd, 0x101fd}, {0x102e0, 0x102e0}, {0x10376, 0x1037a}, {0x10a01, 0x10a03}, {0x10a05, 0x10a06}, {0x10a0c, 0x10a0f}, {0x10a38, 0x10a3a}, {0x10a3f, 0x10a3f}, {0x10ae5, 0x10ae6}, {0x11000, 0x11002}, {0x11038, 0x11046}, {0x1107f, 0x11082}, {0x110b0, 0x110ba}, {0x11100, 0x11102}, {0x11127, 0x11134}, {0x11173, 0x11173}, {0x11180, 0x11182}, {0x111b3, 0x111c0}, {0x111ca, 0x111cc}, {0x1122c, 0x11237}, {0x1123e, 0x1123e}, {0x112df, 0x112ea}, {0x11300, 0x11303}, {0x1133c, 0x1133c}, {0x1133e, 0x11344}, {0x11347, 0x11348}, {0x1134b, 0x1134d}, {0x11357, 0x11357}, {0x11362, 0x11363}, {0x11366, 0x1136c}, {0x11370, 0x11374}, {0x11435, 0x11446}, {0x114b0, 0x114c3}, {0x115af, 0x115b5}, {0x115b8, 0x115c0}, {0x115dc, 0x115dd}, {0x11630, 0x11640}, {0x116ab, 0x116b7}, {0x1171d, 0x1172b}, {0x11a01, 0x11a0a}, {0x11a33, 0x11a39}, {0x11a3b, 0x11a3e}, {0x11a47, 0x11a47}, {0x11a51, 0x11a5b}, {0x11a8a, 0x11a99}, {0x11c2f, 0x11c36}, {0x11c38, 0x11c3f}, {0x11c92, 0x11ca7}, {0x11ca9, 0x11cb6}, {0x11d31, 0x11d36}, {0x11d3a, 0x11d3a}, {0x11d3c, 0x11d3d}, {0x11d3f, 0x11d45}, {0x11d47, 0x11d47}, {0x16af0, 0x16af4}, {0x16b30, 0x16b36}, {0x16f51, 0x16f7e}, {0x16f8f, 0x16f92}, {0x1bc9d, 0x1bc9e}, {0x1d165, 0x1d169}, {0x1d16d, 0x1d172}, {0x1d17b, 0x1d182}, {0x1d185, 0x1d18b}, {0x1d1aa, 0x1d1ad}, {0x1d242, 0x1d244}, {0x1da00, 0x1da36}, {0x1da3b, 0x1da6c}, {0x1da75, 0x1da75}, {0x1da84, 0x1da84}, {0x1da9b, 0x1da9f}, {0x1daa1, 0x1daaf}, {0x1e000, 0x1e006}, {0x1e008, 0x1e018}, {0x1e01b, 0x1e021}, {0x1e023, 0x1e024}, {0x1e026, 0x1e02a}, {0x1e8d0, 0x1e8d6}, {0x1e944, 0x1e94a}, {0xe0100, 0xe01ef} }; return intable(combining, sizeof(combining), c); } /* * Return TRUE for characters that can be displayed in a normal way. * Only for characters of 0x100 and above! */ int utf_printable(int c) { #ifdef USE_WCHAR_FUNCTIONS /* * Assume the iswprint() library function works better than our own stuff. */ return iswprint(c); #else /* Sorted list of non-overlapping intervals. * 0xd800-0xdfff is reserved for UTF-16, actually illegal. */ static struct interval nonprint[] = { {0x070f, 0x070f}, {0x180b, 0x180e}, {0x200b, 0x200f}, {0x202a, 0x202e}, {0x206a, 0x206f}, {0xd800, 0xdfff}, {0xfeff, 0xfeff}, {0xfff9, 0xfffb}, {0xfffe, 0xffff} }; return !intable(nonprint, sizeof(nonprint), c); #endif } /* Sorted list of non-overlapping intervals of all Emoji characters, * based on http://unicode.org/emoji/charts/emoji-list.html */ static struct interval emoji_all[] = { {0x203c, 0x203c}, {0x2049, 0x2049}, {0x2122, 0x2122}, {0x2139, 0x2139}, {0x2194, 0x2199}, {0x21a9, 0x21aa}, {0x231a, 0x231b}, {0x2328, 0x2328}, {0x23cf, 0x23cf}, {0x23e9, 0x23f3}, {0x23f8, 0x23fa}, {0x24c2, 0x24c2}, {0x25aa, 0x25ab}, {0x25b6, 0x25b6}, {0x25c0, 0x25c0}, {0x25fb, 0x25fe}, {0x2600, 0x2604}, {0x260e, 0x260e}, {0x2611, 0x2611}, {0x2614, 0x2615}, {0x2618, 0x2618}, {0x261d, 0x261d}, {0x2620, 0x2620}, {0x2622, 0x2623}, {0x2626, 0x2626}, {0x262a, 0x262a}, {0x262e, 0x262f}, {0x2638, 0x263a}, {0x2640, 0x2640}, {0x2642, 0x2642}, {0x2648, 0x2653}, {0x2660, 0x2660}, {0x2663, 0x2663}, {0x2665, 0x2666}, {0x2668, 0x2668}, {0x267b, 0x267b}, {0x267f, 0x267f}, {0x2692, 0x2697}, {0x2699, 0x2699}, {0x269b, 0x269c}, {0x26a0, 0x26a1}, {0x26aa, 0x26ab}, {0x26b0, 0x26b1}, {0x26bd, 0x26be}, {0x26c4, 0x26c5}, {0x26c8, 0x26c8}, {0x26ce, 0x26cf}, {0x26d1, 0x26d1}, {0x26d3, 0x26d4}, {0x26e9, 0x26ea}, {0x26f0, 0x26f5}, {0x26f7, 0x26fa}, {0x26fd, 0x26fd}, {0x2702, 0x2702}, {0x2705, 0x2705}, {0x2708, 0x270d}, {0x270f, 0x270f}, {0x2712, 0x2712}, {0x2714, 0x2714}, {0x2716, 0x2716}, {0x271d, 0x271d}, {0x2721, 0x2721}, {0x2728, 0x2728}, {0x2733, 0x2734}, {0x2744, 0x2744}, {0x2747, 0x2747}, {0x274c, 0x274c}, {0x274e, 0x274e}, {0x2753, 0x2755}, {0x2757, 0x2757}, {0x2763, 0x2764}, {0x2795, 0x2797}, {0x27a1, 0x27a1}, {0x27b0, 0x27b0}, {0x27bf, 0x27bf}, {0x2934, 0x2935}, {0x2b05, 0x2b07}, {0x2b1b, 0x2b1c}, {0x2b50, 0x2b50}, {0x2b55, 0x2b55}, {0x3030, 0x3030}, {0x303d, 0x303d}, {0x3297, 0x3297}, {0x3299, 0x3299}, {0x1f004, 0x1f004}, {0x1f0cf, 0x1f0cf}, {0x1f170, 0x1f171}, {0x1f17e, 0x1f17f}, {0x1f18e, 0x1f18e}, {0x1f191, 0x1f19a}, {0x1f1e6, 0x1f1ff}, {0x1f201, 0x1f202}, {0x1f21a, 0x1f21a}, {0x1f22f, 0x1f22f}, {0x1f232, 0x1f23a}, {0x1f250, 0x1f251}, {0x1f300, 0x1f321}, {0x1f324, 0x1f393}, {0x1f396, 0x1f397}, {0x1f399, 0x1f39b}, {0x1f39e, 0x1f3f0}, {0x1f3f3, 0x1f3f5}, {0x1f3f7, 0x1f4fd}, {0x1f4ff, 0x1f53d}, {0x1f549, 0x1f54e}, {0x1f550, 0x1f567}, {0x1f56f, 0x1f570}, {0x1f573, 0x1f57a}, {0x1f587, 0x1f587}, {0x1f58a, 0x1f58d}, {0x1f590, 0x1f590}, {0x1f595, 0x1f596}, {0x1f5a4, 0x1f5a5}, {0x1f5a8, 0x1f5a8}, {0x1f5b1, 0x1f5b2}, {0x1f5bc, 0x1f5bc}, {0x1f5c2, 0x1f5c4}, {0x1f5d1, 0x1f5d3}, {0x1f5dc, 0x1f5de}, {0x1f5e1, 0x1f5e1}, {0x1f5e3, 0x1f5e3}, {0x1f5e8, 0x1f5e8}, {0x1f5ef, 0x1f5ef}, {0x1f5f3, 0x1f5f3}, {0x1f5fa, 0x1f64f}, {0x1f680, 0x1f6c5}, {0x1f6cb, 0x1f6d2}, {0x1f6e0, 0x1f6e5}, {0x1f6e9, 0x1f6e9}, {0x1f6eb, 0x1f6ec}, {0x1f6f0, 0x1f6f0}, {0x1f6f3, 0x1f6f8}, {0x1f910, 0x1f93a}, {0x1f93c, 0x1f93e}, {0x1f940, 0x1f945}, {0x1f947, 0x1f94c}, {0x1f950, 0x1f96b}, {0x1f980, 0x1f997}, {0x1f9c0, 0x1f9c0}, {0x1f9d0, 0x1f9e6} }; /* * Get class of a Unicode character. * 0: white space * 1: punctuation * 2 or bigger: some class of word character. */ int utf_class(int c) { return utf_class_buf(c, curbuf); } int utf_class_buf(int c, buf_T *buf) { /* sorted list of non-overlapping intervals */ static struct clinterval { unsigned int first; unsigned int last; unsigned int class; } classes[] = { {0x037e, 0x037e, 1}, /* Greek question mark */ {0x0387, 0x0387, 1}, /* Greek ano teleia */ {0x055a, 0x055f, 1}, /* Armenian punctuation */ {0x0589, 0x0589, 1}, /* Armenian full stop */ {0x05be, 0x05be, 1}, {0x05c0, 0x05c0, 1}, {0x05c3, 0x05c3, 1}, {0x05f3, 0x05f4, 1}, {0x060c, 0x060c, 1}, {0x061b, 0x061b, 1}, {0x061f, 0x061f, 1}, {0x066a, 0x066d, 1}, {0x06d4, 0x06d4, 1}, {0x0700, 0x070d, 1}, /* Syriac punctuation */ {0x0964, 0x0965, 1}, {0x0970, 0x0970, 1}, {0x0df4, 0x0df4, 1}, {0x0e4f, 0x0e4f, 1}, {0x0e5a, 0x0e5b, 1}, {0x0f04, 0x0f12, 1}, {0x0f3a, 0x0f3d, 1}, {0x0f85, 0x0f85, 1}, {0x104a, 0x104f, 1}, /* Myanmar punctuation */ {0x10fb, 0x10fb, 1}, /* Georgian punctuation */ {0x1361, 0x1368, 1}, /* Ethiopic punctuation */ {0x166d, 0x166e, 1}, /* Canadian Syl. punctuation */ {0x1680, 0x1680, 0}, {0x169b, 0x169c, 1}, {0x16eb, 0x16ed, 1}, {0x1735, 0x1736, 1}, {0x17d4, 0x17dc, 1}, /* Khmer punctuation */ {0x1800, 0x180a, 1}, /* Mongolian punctuation */ {0x2000, 0x200b, 0}, /* spaces */ {0x200c, 0x2027, 1}, /* punctuation and symbols */ {0x2028, 0x2029, 0}, {0x202a, 0x202e, 1}, /* punctuation and symbols */ {0x202f, 0x202f, 0}, {0x2030, 0x205e, 1}, /* punctuation and symbols */ {0x205f, 0x205f, 0}, {0x2060, 0x27ff, 1}, /* punctuation and symbols */ {0x2070, 0x207f, 0x2070}, /* superscript */ {0x2080, 0x2094, 0x2080}, /* subscript */ {0x20a0, 0x27ff, 1}, /* all kinds of symbols */ {0x2800, 0x28ff, 0x2800}, /* braille */ {0x2900, 0x2998, 1}, /* arrows, brackets, etc. */ {0x29d8, 0x29db, 1}, {0x29fc, 0x29fd, 1}, {0x2e00, 0x2e7f, 1}, /* supplemental punctuation */ {0x3000, 0x3000, 0}, /* ideographic space */ {0x3001, 0x3020, 1}, /* ideographic punctuation */ {0x3030, 0x3030, 1}, {0x303d, 0x303d, 1}, {0x3040, 0x309f, 0x3040}, /* Hiragana */ {0x30a0, 0x30ff, 0x30a0}, /* Katakana */ {0x3300, 0x9fff, 0x4e00}, /* CJK Ideographs */ {0xac00, 0xd7a3, 0xac00}, /* Hangul Syllables */ {0xf900, 0xfaff, 0x4e00}, /* CJK Ideographs */ {0xfd3e, 0xfd3f, 1}, {0xfe30, 0xfe6b, 1}, /* punctuation forms */ {0xff00, 0xff0f, 1}, /* half/fullwidth ASCII */ {0xff1a, 0xff20, 1}, /* half/fullwidth ASCII */ {0xff3b, 0xff40, 1}, /* half/fullwidth ASCII */ {0xff5b, 0xff65, 1}, /* half/fullwidth ASCII */ {0x20000, 0x2a6df, 0x4e00}, /* CJK Ideographs */ {0x2a700, 0x2b73f, 0x4e00}, /* CJK Ideographs */ {0x2b740, 0x2b81f, 0x4e00}, /* CJK Ideographs */ {0x2f800, 0x2fa1f, 0x4e00}, /* CJK Ideographs */ }; int bot = 0; int top = sizeof(classes) / sizeof(struct clinterval) - 1; int mid; /* First quick check for Latin1 characters, use 'iskeyword'. */ if (c < 0x100) { if (c == ' ' || c == '\t' || c == NUL || c == 0xa0) return 0; /* blank */ if (vim_iswordc_buf(c, buf)) return 2; /* word character */ return 1; /* punctuation */ } /* binary search in table */ while (top >= bot) { mid = (bot + top) / 2; if (classes[mid].last < (unsigned int)c) bot = mid + 1; else if (classes[mid].first > (unsigned int)c) top = mid - 1; else return (int)classes[mid].class; } /* emoji */ if (intable(emoji_all, sizeof(emoji_all), c)) return 3; /* most other characters are "word" characters */ return 2; } int utf_ambiguous_width(int c) { return c >= 0x80 && (intable(ambiguous, sizeof(ambiguous), c) || intable(emoji_all, sizeof(emoji_all), c)); } /* * Code for Unicode case-dependent operations. Based on notes in * http://www.unicode.org/Public/UNIDATA/CaseFolding.txt * This code uses simple case folding, not full case folding. * Last updated for Unicode 5.2. */ /* * The following tables are built by ../runtime/tools/unicode.vim. * They must be in numeric order, because we use binary search. * An entry such as {0x41,0x5a,1,32} means that Unicode characters in the * range from 0x41 to 0x5a inclusive, stepping by 1, are changed to * folded/upper/lower by adding 32. */ typedef struct { int rangeStart; int rangeEnd; int step; int offset; } convertStruct; static convertStruct foldCase[] = { {0x41,0x5a,1,32}, {0xb5,0xb5,-1,775}, {0xc0,0xd6,1,32}, {0xd8,0xde,1,32}, {0x100,0x12e,2,1}, {0x132,0x136,2,1}, {0x139,0x147,2,1}, {0x14a,0x176,2,1}, {0x178,0x178,-1,-121}, {0x179,0x17d,2,1}, {0x17f,0x17f,-1,-268}, {0x181,0x181,-1,210}, {0x182,0x184,2,1}, {0x186,0x186,-1,206}, {0x187,0x187,-1,1}, {0x189,0x18a,1,205}, {0x18b,0x18b,-1,1}, {0x18e,0x18e,-1,79}, {0x18f,0x18f,-1,202}, {0x190,0x190,-1,203}, {0x191,0x191,-1,1}, {0x193,0x193,-1,205}, {0x194,0x194,-1,207}, {0x196,0x196,-1,211}, {0x197,0x197,-1,209}, {0x198,0x198,-1,1}, {0x19c,0x19c,-1,211}, {0x19d,0x19d,-1,213}, {0x19f,0x19f,-1,214}, {0x1a0,0x1a4,2,1}, {0x1a6,0x1a6,-1,218}, {0x1a7,0x1a7,-1,1}, {0x1a9,0x1a9,-1,218}, {0x1ac,0x1ac,-1,1}, {0x1ae,0x1ae,-1,218}, {0x1af,0x1af,-1,1}, {0x1b1,0x1b2,1,217}, {0x1b3,0x1b5,2,1}, {0x1b7,0x1b7,-1,219}, {0x1b8,0x1bc,4,1}, {0x1c4,0x1c4,-1,2}, {0x1c5,0x1c5,-1,1}, {0x1c7,0x1c7,-1,2}, {0x1c8,0x1c8,-1,1}, {0x1ca,0x1ca,-1,2}, {0x1cb,0x1db,2,1}, {0x1de,0x1ee,2,1}, {0x1f1,0x1f1,-1,2}, {0x1f2,0x1f4,2,1}, {0x1f6,0x1f6,-1,-97}, {0x1f7,0x1f7,-1,-56}, {0x1f8,0x21e,2,1}, {0x220,0x220,-1,-130}, {0x222,0x232,2,1}, {0x23a,0x23a,-1,10795}, {0x23b,0x23b,-1,1}, {0x23d,0x23d,-1,-163}, {0x23e,0x23e,-1,10792}, {0x241,0x241,-1,1}, {0x243,0x243,-1,-195}, {0x244,0x244,-1,69}, {0x245,0x245,-1,71}, {0x246,0x24e,2,1}, {0x345,0x345,-1,116}, {0x370,0x372,2,1}, {0x376,0x376,-1,1}, {0x37f,0x37f,-1,116}, {0x386,0x386,-1,38}, {0x388,0x38a,1,37}, {0x38c,0x38c,-1,64}, {0x38e,0x38f,1,63}, {0x391,0x3a1,1,32}, {0x3a3,0x3ab,1,32}, {0x3c2,0x3c2,-1,1}, {0x3cf,0x3cf,-1,8}, {0x3d0,0x3d0,-1,-30}, {0x3d1,0x3d1,-1,-25}, {0x3d5,0x3d5,-1,-15}, {0x3d6,0x3d6,-1,-22}, {0x3d8,0x3ee,2,1}, {0x3f0,0x3f0,-1,-54}, {0x3f1,0x3f1,-1,-48}, {0x3f4,0x3f4,-1,-60}, {0x3f5,0x3f5,-1,-64}, {0x3f7,0x3f7,-1,1}, {0x3f9,0x3f9,-1,-7}, {0x3fa,0x3fa,-1,1}, {0x3fd,0x3ff,1,-130}, {0x400,0x40f,1,80}, {0x410,0x42f,1,32}, {0x460,0x480,2,1}, {0x48a,0x4be,2,1}, {0x4c0,0x4c0,-1,15}, {0x4c1,0x4cd,2,1}, {0x4d0,0x52e,2,1}, {0x531,0x556,1,48}, {0x10a0,0x10c5,1,7264}, {0x10c7,0x10cd,6,7264}, {0x13f8,0x13fd,1,-8}, {0x1c80,0x1c80,-1,-6222}, {0x1c81,0x1c81,-1,-6221}, {0x1c82,0x1c82,-1,-6212}, {0x1c83,0x1c84,1,-6210}, {0x1c85,0x1c85,-1,-6211}, {0x1c86,0x1c86,-1,-6204}, {0x1c87,0x1c87,-1,-6180}, {0x1c88,0x1c88,-1,35267}, {0x1e00,0x1e94,2,1}, {0x1e9b,0x1e9b,-1,-58}, {0x1e9e,0x1e9e,-1,-7615}, {0x1ea0,0x1efe,2,1}, {0x1f08,0x1f0f,1,-8}, {0x1f18,0x1f1d,1,-8}, {0x1f28,0x1f2f,1,-8}, {0x1f38,0x1f3f,1,-8}, {0x1f48,0x1f4d,1,-8}, {0x1f59,0x1f5f,2,-8}, {0x1f68,0x1f6f,1,-8}, {0x1f88,0x1f8f,1,-8}, {0x1f98,0x1f9f,1,-8}, {0x1fa8,0x1faf,1,-8}, {0x1fb8,0x1fb9,1,-8}, {0x1fba,0x1fbb,1,-74}, {0x1fbc,0x1fbc,-1,-9}, {0x1fbe,0x1fbe,-1,-7173}, {0x1fc8,0x1fcb,1,-86}, {0x1fcc,0x1fcc,-1,-9}, {0x1fd8,0x1fd9,1,-8}, {0x1fda,0x1fdb,1,-100}, {0x1fe8,0x1fe9,1,-8}, {0x1fea,0x1feb,1,-112}, {0x1fec,0x1fec,-1,-7}, {0x1ff8,0x1ff9,1,-128}, {0x1ffa,0x1ffb,1,-126}, {0x1ffc,0x1ffc,-1,-9}, {0x2126,0x2126,-1,-7517}, {0x212a,0x212a,-1,-8383}, {0x212b,0x212b,-1,-8262}, {0x2132,0x2132,-1,28}, {0x2160,0x216f,1,16}, {0x2183,0x2183,-1,1}, {0x24b6,0x24cf,1,26}, {0x2c00,0x2c2e,1,48}, {0x2c60,0x2c60,-1,1}, {0x2c62,0x2c62,-1,-10743}, {0x2c63,0x2c63,-1,-3814}, {0x2c64,0x2c64,-1,-10727}, {0x2c67,0x2c6b,2,1}, {0x2c6d,0x2c6d,-1,-10780}, {0x2c6e,0x2c6e,-1,-10749}, {0x2c6f,0x2c6f,-1,-10783}, {0x2c70,0x2c70,-1,-10782}, {0x2c72,0x2c75,3,1}, {0x2c7e,0x2c7f,1,-10815}, {0x2c80,0x2ce2,2,1}, {0x2ceb,0x2ced,2,1}, {0x2cf2,0xa640,31054,1}, {0xa642,0xa66c,2,1}, {0xa680,0xa69a,2,1}, {0xa722,0xa72e,2,1}, {0xa732,0xa76e,2,1}, {0xa779,0xa77b,2,1}, {0xa77d,0xa77d,-1,-35332}, {0xa77e,0xa786,2,1}, {0xa78b,0xa78b,-1,1}, {0xa78d,0xa78d,-1,-42280}, {0xa790,0xa792,2,1}, {0xa796,0xa7a8,2,1}, {0xa7aa,0xa7aa,-1,-42308}, {0xa7ab,0xa7ab,-1,-42319}, {0xa7ac,0xa7ac,-1,-42315}, {0xa7ad,0xa7ad,-1,-42305}, {0xa7ae,0xa7ae,-1,-42308}, {0xa7b0,0xa7b0,-1,-42258}, {0xa7b1,0xa7b1,-1,-42282}, {0xa7b2,0xa7b2,-1,-42261}, {0xa7b3,0xa7b3,-1,928}, {0xa7b4,0xa7b6,2,1}, {0xab70,0xabbf,1,-38864}, {0xff21,0xff3a,1,32}, {0x10400,0x10427,1,40}, {0x104b0,0x104d3,1,40}, {0x10c80,0x10cb2,1,64}, {0x118a0,0x118bf,1,32}, {0x1e900,0x1e921,1,34} }; static int utf_convert(int a, convertStruct table[], int tableSize); static int utf_strnicmp(char_u *s1, char_u *s2, size_t n1, size_t n2); /* * Generic conversion function for case operations. * Return the converted equivalent of "a", which is a UCS-4 character. Use * the given conversion "table". Uses binary search on "table". */ static int utf_convert( int a, convertStruct table[], int tableSize) { int start, mid, end; /* indices into table */ int entries = tableSize / sizeof(convertStruct); start = 0; end = entries; while (start < end) { /* need to search further */ mid = (end + start) / 2; if (table[mid].rangeEnd < a) start = mid + 1; else end = mid; } if (start < entries && table[start].rangeStart <= a && a <= table[start].rangeEnd && (a - table[start].rangeStart) % table[start].step == 0) return (a + table[start].offset); else return a; } /* * Return the folded-case equivalent of "a", which is a UCS-4 character. Uses * simple case folding. */ int utf_fold(int a) { if (a < 0x80) /* be fast for ASCII */ return a >= 0x41 && a <= 0x5a ? a + 32 : a; return utf_convert(a, foldCase, (int)sizeof(foldCase)); } static convertStruct toLower[] = { {0x41,0x5a,1,32}, {0xc0,0xd6,1,32}, {0xd8,0xde,1,32}, {0x100,0x12e,2,1}, {0x130,0x130,-1,-199}, {0x132,0x136,2,1}, {0x139,0x147,2,1}, {0x14a,0x176,2,1}, {0x178,0x178,-1,-121}, {0x179,0x17d,2,1}, {0x181,0x181,-1,210}, {0x182,0x184,2,1}, {0x186,0x186,-1,206}, {0x187,0x187,-1,1}, {0x189,0x18a,1,205}, {0x18b,0x18b,-1,1}, {0x18e,0x18e,-1,79}, {0x18f,0x18f,-1,202}, {0x190,0x190,-1,203}, {0x191,0x191,-1,1}, {0x193,0x193,-1,205}, {0x194,0x194,-1,207}, {0x196,0x196,-1,211}, {0x197,0x197,-1,209}, {0x198,0x198,-1,1}, {0x19c,0x19c,-1,211}, {0x19d,0x19d,-1,213}, {0x19f,0x19f,-1,214}, {0x1a0,0x1a4,2,1}, {0x1a6,0x1a6,-1,218}, {0x1a7,0x1a7,-1,1}, {0x1a9,0x1a9,-1,218}, {0x1ac,0x1ac,-1,1}, {0x1ae,0x1ae,-1,218}, {0x1af,0x1af,-1,1}, {0x1b1,0x1b2,1,217}, {0x1b3,0x1b5,2,1}, {0x1b7,0x1b7,-1,219}, {0x1b8,0x1bc,4,1}, {0x1c4,0x1c4,-1,2}, {0x1c5,0x1c5,-1,1}, {0x1c7,0x1c7,-1,2}, {0x1c8,0x1c8,-1,1}, {0x1ca,0x1ca,-1,2}, {0x1cb,0x1db,2,1}, {0x1de,0x1ee,2,1}, {0x1f1,0x1f1,-1,2}, {0x1f2,0x1f4,2,1}, {0x1f6,0x1f6,-1,-97}, {0x1f7,0x1f7,-1,-56}, {0x1f8,0x21e,2,1}, {0x220,0x220,-1,-130}, {0x222,0x232,2,1}, {0x23a,0x23a,-1,10795}, {0x23b,0x23b,-1,1}, {0x23d,0x23d,-1,-163}, {0x23e,0x23e,-1,10792}, {0x241,0x241,-1,1}, {0x243,0x243,-1,-195}, {0x244,0x244,-1,69}, {0x245,0x245,-1,71}, {0x246,0x24e,2,1}, {0x370,0x372,2,1}, {0x376,0x376,-1,1}, {0x37f,0x37f,-1,116}, {0x386,0x386,-1,38}, {0x388,0x38a,1,37}, {0x38c,0x38c,-1,64}, {0x38e,0x38f,1,63}, {0x391,0x3a1,1,32}, {0x3a3,0x3ab,1,32}, {0x3cf,0x3cf,-1,8}, {0x3d8,0x3ee,2,1}, {0x3f4,0x3f4,-1,-60}, {0x3f7,0x3f7,-1,1}, {0x3f9,0x3f9,-1,-7}, {0x3fa,0x3fa,-1,1}, {0x3fd,0x3ff,1,-130}, {0x400,0x40f,1,80}, {0x410,0x42f,1,32}, {0x460,0x480,2,1}, {0x48a,0x4be,2,1}, {0x4c0,0x4c0,-1,15}, {0x4c1,0x4cd,2,1}, {0x4d0,0x52e,2,1}, {0x531,0x556,1,48}, {0x10a0,0x10c5,1,7264}, {0x10c7,0x10cd,6,7264}, {0x13a0,0x13ef,1,38864}, {0x13f0,0x13f5,1,8}, {0x1e00,0x1e94,2,1}, {0x1e9e,0x1e9e,-1,-7615}, {0x1ea0,0x1efe,2,1}, {0x1f08,0x1f0f,1,-8}, {0x1f18,0x1f1d,1,-8}, {0x1f28,0x1f2f,1,-8}, {0x1f38,0x1f3f,1,-8}, {0x1f48,0x1f4d,1,-8}, {0x1f59,0x1f5f,2,-8}, {0x1f68,0x1f6f,1,-8}, {0x1f88,0x1f8f,1,-8}, {0x1f98,0x1f9f,1,-8}, {0x1fa8,0x1faf,1,-8}, {0x1fb8,0x1fb9,1,-8}, {0x1fba,0x1fbb,1,-74}, {0x1fbc,0x1fbc,-1,-9}, {0x1fc8,0x1fcb,1,-86}, {0x1fcc,0x1fcc,-1,-9}, {0x1fd8,0x1fd9,1,-8}, {0x1fda,0x1fdb,1,-100}, {0x1fe8,0x1fe9,1,-8}, {0x1fea,0x1feb,1,-112}, {0x1fec,0x1fec,-1,-7}, {0x1ff8,0x1ff9,1,-128}, {0x1ffa,0x1ffb,1,-126}, {0x1ffc,0x1ffc,-1,-9}, {0x2126,0x2126,-1,-7517}, {0x212a,0x212a,-1,-8383}, {0x212b,0x212b,-1,-8262}, {0x2132,0x2132,-1,28}, {0x2160,0x216f,1,16}, {0x2183,0x2183,-1,1}, {0x24b6,0x24cf,1,26}, {0x2c00,0x2c2e,1,48}, {0x2c60,0x2c60,-1,1}, {0x2c62,0x2c62,-1,-10743}, {0x2c63,0x2c63,-1,-3814}, {0x2c64,0x2c64,-1,-10727}, {0x2c67,0x2c6b,2,1}, {0x2c6d,0x2c6d,-1,-10780}, {0x2c6e,0x2c6e,-1,-10749}, {0x2c6f,0x2c6f,-1,-10783}, {0x2c70,0x2c70,-1,-10782}, {0x2c72,0x2c75,3,1}, {0x2c7e,0x2c7f,1,-10815}, {0x2c80,0x2ce2,2,1}, {0x2ceb,0x2ced,2,1}, {0x2cf2,0xa640,31054,1}, {0xa642,0xa66c,2,1}, {0xa680,0xa69a,2,1}, {0xa722,0xa72e,2,1}, {0xa732,0xa76e,2,1}, {0xa779,0xa77b,2,1}, {0xa77d,0xa77d,-1,-35332}, {0xa77e,0xa786,2,1}, {0xa78b,0xa78b,-1,1}, {0xa78d,0xa78d,-1,-42280}, {0xa790,0xa792,2,1}, {0xa796,0xa7a8,2,1}, {0xa7aa,0xa7aa,-1,-42308}, {0xa7ab,0xa7ab,-1,-42319}, {0xa7ac,0xa7ac,-1,-42315}, {0xa7ad,0xa7ad,-1,-42305}, {0xa7ae,0xa7ae,-1,-42308}, {0xa7b0,0xa7b0,-1,-42258}, {0xa7b1,0xa7b1,-1,-42282}, {0xa7b2,0xa7b2,-1,-42261}, {0xa7b3,0xa7b3,-1,928}, {0xa7b4,0xa7b6,2,1}, {0xff21,0xff3a,1,32}, {0x10400,0x10427,1,40}, {0x104b0,0x104d3,1,40}, {0x10c80,0x10cb2,1,64}, {0x118a0,0x118bf,1,32}, {0x1e900,0x1e921,1,34} }; static convertStruct toUpper[] = { {0x61,0x7a,1,-32}, {0xb5,0xb5,-1,743}, {0xe0,0xf6,1,-32}, {0xf8,0xfe,1,-32}, {0xff,0xff,-1,121}, {0x101,0x12f,2,-1}, {0x131,0x131,-1,-232}, {0x133,0x137,2,-1}, {0x13a,0x148,2,-1}, {0x14b,0x177,2,-1}, {0x17a,0x17e,2,-1}, {0x17f,0x17f,-1,-300}, {0x180,0x180,-1,195}, {0x183,0x185,2,-1}, {0x188,0x18c,4,-1}, {0x192,0x192,-1,-1}, {0x195,0x195,-1,97}, {0x199,0x199,-1,-1}, {0x19a,0x19a,-1,163}, {0x19e,0x19e,-1,130}, {0x1a1,0x1a5,2,-1}, {0x1a8,0x1ad,5,-1}, {0x1b0,0x1b4,4,-1}, {0x1b6,0x1b9,3,-1}, {0x1bd,0x1bd,-1,-1}, {0x1bf,0x1bf,-1,56}, {0x1c5,0x1c5,-1,-1}, {0x1c6,0x1c6,-1,-2}, {0x1c8,0x1c8,-1,-1}, {0x1c9,0x1c9,-1,-2}, {0x1cb,0x1cb,-1,-1}, {0x1cc,0x1cc,-1,-2}, {0x1ce,0x1dc,2,-1}, {0x1dd,0x1dd,-1,-79}, {0x1df,0x1ef,2,-1}, {0x1f2,0x1f2,-1,-1}, {0x1f3,0x1f3,-1,-2}, {0x1f5,0x1f9,4,-1}, {0x1fb,0x21f,2,-1}, {0x223,0x233,2,-1}, {0x23c,0x23c,-1,-1}, {0x23f,0x240,1,10815}, {0x242,0x247,5,-1}, {0x249,0x24f,2,-1}, {0x250,0x250,-1,10783}, {0x251,0x251,-1,10780}, {0x252,0x252,-1,10782}, {0x253,0x253,-1,-210}, {0x254,0x254,-1,-206}, {0x256,0x257,1,-205}, {0x259,0x259,-1,-202}, {0x25b,0x25b,-1,-203}, {0x25c,0x25c,-1,42319}, {0x260,0x260,-1,-205}, {0x261,0x261,-1,42315}, {0x263,0x263,-1,-207}, {0x265,0x265,-1,42280}, {0x266,0x266,-1,42308}, {0x268,0x268,-1,-209}, {0x269,0x269,-1,-211}, {0x26a,0x26a,-1,42308}, {0x26b,0x26b,-1,10743}, {0x26c,0x26c,-1,42305}, {0x26f,0x26f,-1,-211}, {0x271,0x271,-1,10749}, {0x272,0x272,-1,-213}, {0x275,0x275,-1,-214}, {0x27d,0x27d,-1,10727}, {0x280,0x283,3,-218}, {0x287,0x287,-1,42282}, {0x288,0x288,-1,-218}, {0x289,0x289,-1,-69}, {0x28a,0x28b,1,-217}, {0x28c,0x28c,-1,-71}, {0x292,0x292,-1,-219}, {0x29d,0x29d,-1,42261}, {0x29e,0x29e,-1,42258}, {0x345,0x345,-1,84}, {0x371,0x373,2,-1}, {0x377,0x377,-1,-1}, {0x37b,0x37d,1,130}, {0x3ac,0x3ac,-1,-38}, {0x3ad,0x3af,1,-37}, {0x3b1,0x3c1,1,-32}, {0x3c2,0x3c2,-1,-31}, {0x3c3,0x3cb,1,-32}, {0x3cc,0x3cc,-1,-64}, {0x3cd,0x3ce,1,-63}, {0x3d0,0x3d0,-1,-62}, {0x3d1,0x3d1,-1,-57}, {0x3d5,0x3d5,-1,-47}, {0x3d6,0x3d6,-1,-54}, {0x3d7,0x3d7,-1,-8}, {0x3d9,0x3ef,2,-1}, {0x3f0,0x3f0,-1,-86}, {0x3f1,0x3f1,-1,-80}, {0x3f2,0x3f2,-1,7}, {0x3f3,0x3f3,-1,-116}, {0x3f5,0x3f5,-1,-96}, {0x3f8,0x3fb,3,-1}, {0x430,0x44f,1,-32}, {0x450,0x45f,1,-80}, {0x461,0x481,2,-1}, {0x48b,0x4bf,2,-1}, {0x4c2,0x4ce,2,-1}, {0x4cf,0x4cf,-1,-15}, {0x4d1,0x52f,2,-1}, {0x561,0x586,1,-48}, {0x13f8,0x13fd,1,-8}, {0x1c80,0x1c80,-1,-6254}, {0x1c81,0x1c81,-1,-6253}, {0x1c82,0x1c82,-1,-6244}, {0x1c83,0x1c84,1,-6242}, {0x1c85,0x1c85,-1,-6243}, {0x1c86,0x1c86,-1,-6236}, {0x1c87,0x1c87,-1,-6181}, {0x1c88,0x1c88,-1,35266}, {0x1d79,0x1d79,-1,35332}, {0x1d7d,0x1d7d,-1,3814}, {0x1e01,0x1e95,2,-1}, {0x1e9b,0x1e9b,-1,-59}, {0x1ea1,0x1eff,2,-1}, {0x1f00,0x1f07,1,8}, {0x1f10,0x1f15,1,8}, {0x1f20,0x1f27,1,8}, {0x1f30,0x1f37,1,8}, {0x1f40,0x1f45,1,8}, {0x1f51,0x1f57,2,8}, {0x1f60,0x1f67,1,8}, {0x1f70,0x1f71,1,74}, {0x1f72,0x1f75,1,86}, {0x1f76,0x1f77,1,100}, {0x1f78,0x1f79,1,128}, {0x1f7a,0x1f7b,1,112}, {0x1f7c,0x1f7d,1,126}, {0x1f80,0x1f87,1,8}, {0x1f90,0x1f97,1,8}, {0x1fa0,0x1fa7,1,8}, {0x1fb0,0x1fb1,1,8}, {0x1fb3,0x1fb3,-1,9}, {0x1fbe,0x1fbe,-1,-7205}, {0x1fc3,0x1fc3,-1,9}, {0x1fd0,0x1fd1,1,8}, {0x1fe0,0x1fe1,1,8}, {0x1fe5,0x1fe5,-1,7}, {0x1ff3,0x1ff3,-1,9}, {0x214e,0x214e,-1,-28}, {0x2170,0x217f,1,-16}, {0x2184,0x2184,-1,-1}, {0x24d0,0x24e9,1,-26}, {0x2c30,0x2c5e,1,-48}, {0x2c61,0x2c61,-1,-1}, {0x2c65,0x2c65,-1,-10795}, {0x2c66,0x2c66,-1,-10792}, {0x2c68,0x2c6c,2,-1}, {0x2c73,0x2c76,3,-1}, {0x2c81,0x2ce3,2,-1}, {0x2cec,0x2cee,2,-1}, {0x2cf3,0x2cf3,-1,-1}, {0x2d00,0x2d25,1,-7264}, {0x2d27,0x2d2d,6,-7264}, {0xa641,0xa66d,2,-1}, {0xa681,0xa69b,2,-1}, {0xa723,0xa72f,2,-1}, {0xa733,0xa76f,2,-1}, {0xa77a,0xa77c,2,-1}, {0xa77f,0xa787,2,-1}, {0xa78c,0xa791,5,-1}, {0xa793,0xa797,4,-1}, {0xa799,0xa7a9,2,-1}, {0xa7b5,0xa7b7,2,-1}, {0xab53,0xab53,-1,-928}, {0xab70,0xabbf,1,-38864}, {0xff41,0xff5a,1,-32}, {0x10428,0x1044f,1,-40}, {0x104d8,0x104fb,1,-40}, {0x10cc0,0x10cf2,1,-64}, {0x118c0,0x118df,1,-32}, {0x1e922,0x1e943,1,-34} }; /* * Return the upper-case equivalent of "a", which is a UCS-4 character. Use * simple case folding. */ int utf_toupper(int a) { /* If 'casemap' contains "keepascii" use ASCII style toupper(). */ if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOUPPER_ASC(a); #if defined(HAVE_TOWUPPER) && defined(__STDC_ISO_10646__) /* If towupper() is available and handles Unicode, use it. */ if (!(cmp_flags & CMP_INTERNAL)) return towupper(a); #endif /* For characters below 128 use locale sensitive toupper(). */ if (a < 128) return TOUPPER_LOC(a); /* For any other characters use the above mapping table. */ return utf_convert(a, toUpper, (int)sizeof(toUpper)); } int utf_islower(int a) { /* German sharp s is lower case but has no upper case equivalent. */ return (utf_toupper(a) != a) || a == 0xdf; } /* * Return the lower-case equivalent of "a", which is a UCS-4 character. Use * simple case folding. */ int utf_tolower(int a) { /* If 'casemap' contains "keepascii" use ASCII style tolower(). */ if (a < 128 && (cmp_flags & CMP_KEEPASCII)) return TOLOWER_ASC(a); #if defined(HAVE_TOWLOWER) && defined(__STDC_ISO_10646__) /* If towlower() is available and handles Unicode, use it. */ if (!(cmp_flags & CMP_INTERNAL)) return towlower(a); #endif /* For characters below 128 use locale sensitive tolower(). */ if (a < 128) return TOLOWER_LOC(a); /* For any other characters use the above mapping table. */ return utf_convert(a, toLower, (int)sizeof(toLower)); } int utf_isupper(int a) { return (utf_tolower(a) != a); } static int utf_strnicmp( char_u *s1, char_u *s2, size_t n1, size_t n2) { int c1, c2, cdiff; char_u buffer[6]; for (;;) { c1 = utf_safe_read_char_adv(&s1, &n1); c2 = utf_safe_read_char_adv(&s2, &n2); if (c1 <= 0 || c2 <= 0) break; if (c1 == c2) continue; cdiff = utf_fold(c1) - utf_fold(c2); if (cdiff != 0) return cdiff; } /* some string ended or has an incomplete/illegal character sequence */ if (c1 == 0 || c2 == 0) { /* some string ended. shorter string is smaller */ if (c1 == 0 && c2 == 0) return 0; return c1 == 0 ? -1 : 1; } /* Continue with bytewise comparison to produce some result that * would make comparison operations involving this function transitive. * * If only one string had an error, comparison should be made with * folded version of the other string. In this case it is enough * to fold just one character to determine the result of comparison. */ if (c1 != -1 && c2 == -1) { n1 = utf_char2bytes(utf_fold(c1), buffer); s1 = buffer; } else if (c2 != -1 && c1 == -1) { n2 = utf_char2bytes(utf_fold(c2), buffer); s2 = buffer; } while (n1 > 0 && n2 > 0 && *s1 != NUL && *s2 != NUL) { cdiff = (int)(*s1) - (int)(*s2); if (cdiff != 0) return cdiff; s1++; s2++; n1--; n2--; } if (n1 > 0 && *s1 == NUL) n1 = 0; if (n2 > 0 && *s2 == NUL) n2 = 0; if (n1 == 0 && n2 == 0) return 0; return n1 == 0 ? -1 : 1; } /* * Version of strnicmp() that handles multi-byte characters. * Needed for Big5, Shift-JIS and UTF-8 encoding. Other DBCS encodings can * probably use strnicmp(), because there are no ASCII characters in the * second byte. * Returns zero if s1 and s2 are equal (ignoring case), the difference between * two characters otherwise. */ int mb_strnicmp(char_u *s1, char_u *s2, size_t nn) { int i, l; int cdiff; int n = (int)nn; if (enc_utf8) { return utf_strnicmp(s1, s2, nn, nn); } else { for (i = 0; i < n; i += l) { if (s1[i] == NUL && s2[i] == NUL) /* both strings end */ return 0; l = (*mb_ptr2len)(s1 + i); if (l <= 1) { /* Single byte: first check normally, then with ignore case. */ if (s1[i] != s2[i]) { cdiff = MB_TOLOWER(s1[i]) - MB_TOLOWER(s2[i]); if (cdiff != 0) return cdiff; } } else { /* For non-Unicode multi-byte don't ignore case. */ if (l > n - i) l = n - i; cdiff = STRNCMP(s1 + i, s2 + i, l); if (cdiff != 0) return cdiff; } } } return 0; } /* * "g8": show bytes of the UTF-8 char under the cursor. Doesn't matter what * 'encoding' has been set to. */ void show_utf8(void) { int len; int rlen = 0; char_u *line; int clen; int i; /* Get the byte length of the char under the cursor, including composing * characters. */ line = ml_get_cursor(); len = utfc_ptr2len(line); if (len == 0) { MSG("NUL"); return; } clen = 0; for (i = 0; i < len; ++i) { if (clen == 0) { /* start of (composing) character, get its length */ if (i > 0) { STRCPY(IObuff + rlen, "+ "); rlen += 2; } clen = utf_ptr2len(line + i); } sprintf((char *)IObuff + rlen, "%02x ", (line[i] == NL) ? NUL : line[i]); /* NUL is stored as NL */ --clen; rlen += (int)STRLEN(IObuff + rlen); if (rlen > IOSIZE - 20) break; } msg(IObuff); } /* * mb_head_off() function pointer. * Return offset from "p" to the first byte of the character it points into. * If "p" points to the NUL at the end of the string return 0. * Returns 0 when already at the first byte of a character. */ int latin_head_off(char_u *base UNUSED, char_u *p UNUSED) { return 0; } int dbcs_head_off(char_u *base, char_u *p) { char_u *q; /* It can't be a trailing byte when not using DBCS, at the start of the * string or the previous byte can't start a double-byte. */ if (p <= base || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; /* This is slow: need to start at the base and go forward until the * byte we are looking for. Return 1 when we went past it, 0 otherwise. */ q = base; while (q < p) q += dbcs_ptr2len(q); return (q == p) ? 0 : 1; } /* * Special version of dbcs_head_off() that works for ScreenLines[], where * single-width DBCS_JPNU characters are stored separately. */ int dbcs_screen_head_off(char_u *base, char_u *p) { char_u *q; /* It can't be a trailing byte when not using DBCS, at the start of the * string or the previous byte can't start a double-byte. * For euc-jp an 0x8e byte in the previous cell always means we have a * lead byte in the current cell. */ if (p <= base || (enc_dbcs == DBCS_JPNU && p[-1] == 0x8e) || MB_BYTE2LEN(p[-1]) == 1 || *p == NUL) return 0; /* This is slow: need to start at the base and go forward until the * byte we are looking for. Return 1 when we went past it, 0 otherwise. * For DBCS_JPNU look out for 0x8e, which means the second byte is not * stored as the next byte. */ q = base; while (q < p) { if (enc_dbcs == DBCS_JPNU && *q == 0x8e) ++q; else q += dbcs_ptr2len(q); } return (q == p) ? 0 : 1; } int utf_head_off(char_u *base, char_u *p) { char_u *q; char_u *s; int c; int len; #ifdef FEAT_ARABIC char_u *j; #endif if (*p < 0x80) /* be quick for ASCII */ return 0; /* Skip backwards over trailing bytes: 10xx.xxxx * Skip backwards again if on a composing char. */ for (q = p; ; --q) { /* Move s to the last byte of this char. */ for (s = q; (s[1] & 0xc0) == 0x80; ++s) ; /* Move q to the first byte of this char. */ while (q > base && (*q & 0xc0) == 0x80) --q; /* Check for illegal sequence. Do allow an illegal byte after where we * started. */ len = utf8len_tab[*q]; if (len != (int)(s - q + 1) && len != (int)(p - q + 1)) return 0; if (q <= base) break; c = utf_ptr2char(q); if (utf_iscomposing(c)) continue; #ifdef FEAT_ARABIC if (arabic_maycombine(c)) { /* Advance to get a sneak-peak at the next char */ j = q; --j; /* Move j to the first byte of this char. */ while (j > base && (*j & 0xc0) == 0x80) --j; if (arabic_combine(utf_ptr2char(j), c)) continue; } #endif break; } return (int)(p - q); } /* * Copy a character from "*fp" to "*tp" and advance the pointers. */ void mb_copy_char(char_u **fp, char_u **tp) { int l = (*mb_ptr2len)(*fp); mch_memmove(*tp, *fp, (size_t)l); *tp += l; *fp += l; } /* * Return the offset from "p" to the first byte of a character. When "p" is * at the start of a character 0 is returned, otherwise the offset to the next * character. Can start anywhere in a stream of bytes. */ int mb_off_next(char_u *base, char_u *p) { int i; int j; if (enc_utf8) { if (*p < 0x80) /* be quick for ASCII */ return 0; /* Find the next character that isn't 10xx.xxxx */ for (i = 0; (p[i] & 0xc0) == 0x80; ++i) ; if (i > 0) { /* Check for illegal sequence. */ for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; if (utf8len_tab[p[-j]] != i + j) return 0; } return i; } /* Only need to check if we're on a trail byte, it doesn't matter if we * want the offset to the next or current character. */ return (*mb_head_off)(base, p); } /* * Return the offset from "p" to the last byte of the character it points * into. Can start anywhere in a stream of bytes. */ int mb_tail_off(char_u *base, char_u *p) { int i; int j; if (*p == NUL) return 0; if (enc_utf8) { /* Find the last character that is 10xx.xxxx */ for (i = 0; (p[i + 1] & 0xc0) == 0x80; ++i) ; /* Check for illegal sequence. */ for (j = 0; p - j > base; ++j) if ((p[-j] & 0xc0) != 0x80) break; if (utf8len_tab[p[-j]] != i + j + 1) return 0; return i; } /* It can't be the first byte if a double-byte when not using DBCS, at the * end of the string or the byte can't start a double-byte. */ if (enc_dbcs == 0 || p[1] == NUL || MB_BYTE2LEN(*p) == 1) return 0; /* Return 1 when on the lead byte, 0 when on the tail byte. */ return 1 - dbcs_head_off(base, p); } /* * Find the next illegal byte sequence. */ void utf_find_illegal(void) { pos_T pos = curwin->w_cursor; char_u *p; int len; vimconv_T vimconv; char_u *tofree = NULL; vimconv.vc_type = CONV_NONE; if (enc_utf8 && (enc_canon_props(curbuf->b_p_fenc) & ENC_8BIT)) { /* 'encoding' is "utf-8" but we are editing a 8-bit encoded file, * possibly a utf-8 file with illegal bytes. Setup for conversion * from utf-8 to 'fileencoding'. */ convert_setup(&vimconv, p_enc, curbuf->b_p_fenc); } #ifdef FEAT_VIRTUALEDIT curwin->w_cursor.coladd = 0; #endif for (;;) { p = ml_get_cursor(); if (vimconv.vc_type != CONV_NONE) { vim_free(tofree); tofree = string_convert(&vimconv, p, NULL); if (tofree == NULL) break; p = tofree; } while (*p != NUL) { /* Illegal means that there are not enough trail bytes (checked by * utf_ptr2len()) or too many of them (overlong sequence). */ len = utf_ptr2len(p); if (*p >= 0x80 && (len == 1 || utf_char2len(utf_ptr2char(p)) != len)) { if (vimconv.vc_type == CONV_NONE) curwin->w_cursor.col += (colnr_T)(p - ml_get_cursor()); else { int l; len = (int)(p - tofree); for (p = ml_get_cursor(); *p != NUL && len-- > 0; p += l) { l = utf_ptr2len(p); curwin->w_cursor.col += l; } } goto theend; } p += len; } if (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) break; ++curwin->w_cursor.lnum; curwin->w_cursor.col = 0; } /* didn't find it: don't move and beep */ curwin->w_cursor = pos; beep_flush(); theend: vim_free(tofree); convert_setup(&vimconv, NULL, NULL); } #if defined(FEAT_GUI_GTK) || defined(PROTO) /* * Return TRUE if string "s" is a valid utf-8 string. * When "end" is NULL stop at the first NUL. * When "end" is positive stop there. */ int utf_valid_string(char_u *s, char_u *end) { int l; char_u *p = s; while (end == NULL ? *p != NUL : p < end) { l = utf8len_tab_zero[*p]; if (l == 0) return FALSE; /* invalid lead byte */ if (end != NULL && p + l > end) return FALSE; /* incomplete byte sequence */ ++p; while (--l > 0) if ((*p++ & 0xc0) != 0x80) return FALSE; /* invalid trail byte */ } return TRUE; } #endif #if defined(FEAT_GUI) || defined(PROTO) /* * Special version of mb_tail_off() for use in ScreenLines[]. */ int dbcs_screen_tail_off(char_u *base, char_u *p) { /* It can't be the first byte if a double-byte when not using DBCS, at the * end of the string or the byte can't start a double-byte. * For euc-jp an 0x8e byte always means we have a lead byte in the current * cell. */ if (*p == NUL || p[1] == NUL || (enc_dbcs == DBCS_JPNU && *p == 0x8e) || MB_BYTE2LEN(*p) == 1) return 0; /* Return 1 when on the lead byte, 0 when on the tail byte. */ return 1 - dbcs_screen_head_off(base, p); } #endif /* * If the cursor moves on an trail byte, set the cursor on the lead byte. * Thus it moves left if necessary. * Return TRUE when the cursor was adjusted. */ void mb_adjust_cursor(void) { mb_adjustpos(curbuf, &curwin->w_cursor); } /* * Adjust position "*lp" to point to the first byte of a multi-byte character. * If it points to a tail byte it's moved backwards to the head byte. */ void mb_adjustpos(buf_T *buf, pos_T *lp) { char_u *p; if (lp->col > 0 #ifdef FEAT_VIRTUALEDIT || lp->coladd > 1 #endif ) { p = ml_get_buf(buf, lp->lnum, FALSE); if (*p == NUL || (int)STRLEN(p) < lp->col) lp->col = 0; else lp->col -= (*mb_head_off)(p, p + lp->col); #ifdef FEAT_VIRTUALEDIT /* Reset "coladd" when the cursor would be on the right half of a * double-wide character. */ if (lp->coladd == 1 && p[lp->col] != TAB && vim_isprintc((*mb_ptr2char)(p + lp->col)) && ptr2cells(p + lp->col) > 1) lp->coladd = 0; #endif } } /* * Return a pointer to the character before "*p", if there is one. */ char_u * mb_prevptr( char_u *line, /* start of the string */ char_u *p) { if (p > line) MB_PTR_BACK(line, p); return p; } /* * Return the character length of "str". Each multi-byte character (with * following composing characters) counts as one. */ int mb_charlen(char_u *str) { char_u *p = str; int count; if (p == NULL) return 0; for (count = 0; *p != NUL; count++) p += (*mb_ptr2len)(p); return count; } #if defined(FEAT_SPELL) || defined(PROTO) /* * Like mb_charlen() but for a string with specified length. */ int mb_charlen_len(char_u *str, int len) { char_u *p = str; int count; for (count = 0; *p != NUL && p < str + len; count++) p += (*mb_ptr2len)(p); return count; } #endif /* * Try to un-escape a multi-byte character. * Used for the "to" and "from" part of a mapping. * Return the un-escaped string if it is a multi-byte character, and advance * "pp" to just after the bytes that formed it. * Return NULL if no multi-byte char was found. */ char_u * mb_unescape(char_u **pp) { static char_u buf[6]; int n; int m = 0; char_u *str = *pp; /* Must translate K_SPECIAL KS_SPECIAL KE_FILLER to K_SPECIAL and CSI * KS_EXTRA KE_CSI to CSI. * Maximum length of a utf-8 character is 4 bytes. */ for (n = 0; str[n] != NUL && m < 4; ++n) { if (str[n] == K_SPECIAL && str[n + 1] == KS_SPECIAL && str[n + 2] == KE_FILLER) { buf[m++] = K_SPECIAL; n += 2; } else if ((str[n] == K_SPECIAL # ifdef FEAT_GUI || str[n] == CSI # endif ) && str[n + 1] == KS_EXTRA && str[n + 2] == (int)KE_CSI) { buf[m++] = CSI; n += 2; } else if (str[n] == K_SPECIAL # ifdef FEAT_GUI || str[n] == CSI # endif ) break; /* a special key can't be a multibyte char */ else buf[m++] = str[n]; buf[m] = NUL; /* Return a multi-byte character if it's found. An illegal sequence * will result in a 1 here. */ if ((*mb_ptr2len)(buf) > 1) { *pp = str + n + 1; return buf; } /* Bail out quickly for ASCII. */ if (buf[0] < 128) break; } return NULL; } /* * Return TRUE if the character at "row"/"col" on the screen is the left side * of a double-width character. * Caller must make sure "row" and "col" are not invalid! */ int mb_lefthalve(int row, int col) { #ifdef FEAT_HANGULIN if (composing_hangul) return TRUE; #endif return (*mb_off2cells)(LineOffset[row] + col, LineOffset[row] + screen_Columns) > 1; } /* * Correct a position on the screen, if it's the right half of a double-wide * char move it to the left half. Returns the corrected column. */ int mb_fix_col(int col, int row) { col = check_col(col); row = check_row(row); if (has_mbyte && ScreenLines != NULL && col > 0 && ((enc_dbcs && ScreenLines[LineOffset[row] + col] != NUL && dbcs_screen_head_off(ScreenLines + LineOffset[row], ScreenLines + LineOffset[row] + col)) || (enc_utf8 && ScreenLines[LineOffset[row] + col] == 0))) return col - 1; return col; } #endif #if defined(FEAT_MBYTE) || defined(FEAT_POSTSCRIPT) || defined(PROTO) static int enc_alias_search(char_u *name); /* * Skip the Vim specific head of a 'encoding' name. */ char_u * enc_skip(char_u *p) { if (STRNCMP(p, "2byte-", 6) == 0) return p + 6; if (STRNCMP(p, "8bit-", 5) == 0) return p + 5; return p; } /* * Find the canonical name for encoding "enc". * When the name isn't recognized, returns "enc" itself, but with all lower * case characters and '_' replaced with '-'. * Returns an allocated string. NULL for out-of-memory. */ char_u * enc_canonize(char_u *enc) { char_u *r; char_u *p, *s; int i; # ifdef FEAT_MBYTE if (STRCMP(enc, "default") == 0) { /* Use the default encoding as it's found by set_init_1(). */ r = get_encoding_default(); if (r == NULL) r = (char_u *)"latin1"; return vim_strsave(r); } # endif /* copy "enc" to allocated memory, with room for two '-' */ r = alloc((unsigned)(STRLEN(enc) + 3)); if (r != NULL) { /* Make it all lower case and replace '_' with '-'. */ p = r; for (s = enc; *s != NUL; ++s) { if (*s == '_') *p++ = '-'; else *p++ = TOLOWER_ASC(*s); } *p = NUL; /* Skip "2byte-" and "8bit-". */ p = enc_skip(r); /* Change "microsoft-cp" to "cp". Used in some spell files. */ if (STRNCMP(p, "microsoft-cp", 12) == 0) STRMOVE(p, p + 10); /* "iso8859" -> "iso-8859" */ if (STRNCMP(p, "iso8859", 7) == 0) { STRMOVE(p + 4, p + 3); p[3] = '-'; } /* "iso-8859n" -> "iso-8859-n" */ if (STRNCMP(p, "iso-8859", 8) == 0 && p[8] != '-') { STRMOVE(p + 9, p + 8); p[8] = '-'; } /* "latin-N" -> "latinN" */ if (STRNCMP(p, "latin-", 6) == 0) STRMOVE(p + 5, p + 6); if (enc_canon_search(p) >= 0) { /* canonical name can be used unmodified */ if (p != r) STRMOVE(r, p); } else if ((i = enc_alias_search(p)) >= 0) { /* alias recognized, get canonical name */ vim_free(r); r = vim_strsave((char_u *)enc_canon_table[i].name); } } return r; } /* * Search for an encoding alias of "name". * Returns -1 when not found. */ static int enc_alias_search(char_u *name) { int i; for (i = 0; enc_alias_table[i].name != NULL; ++i) if (STRCMP(name, enc_alias_table[i].name) == 0) return enc_alias_table[i].canon; return -1; } #endif #if defined(FEAT_MBYTE) || defined(PROTO) # ifdef HAVE_LANGINFO_H # include <langinfo.h> # endif # ifndef FEAT_GUI_W32 /* * Get the canonicalized encoding from the specified locale string "locale" * or from the environment variables LC_ALL, LC_CTYPE and LANG. * Returns an allocated string when successful, NULL when not. */ char_u * enc_locale_env(char *locale) { char *s = locale; char *p; int i; char buf[50]; if (s == NULL || *s == NUL) if ((s = getenv("LC_ALL")) == NULL || *s == NUL) if ((s = getenv("LC_CTYPE")) == NULL || *s == NUL) s = getenv("LANG"); if (s == NULL || *s == NUL) return NULL; /* The most generic locale format is: * language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]] * If there is a '.' remove the part before it. * if there is something after the codeset, remove it. * Make the name lowercase and replace '_' with '-'. * Exception: "ja_JP.EUC" == "euc-jp", "zh_CN.EUC" = "euc-cn", * "ko_KR.EUC" == "euc-kr" */ if ((p = (char *)vim_strchr((char_u *)s, '.')) != NULL) { if (p > s + 2 && STRNICMP(p + 1, "EUC", 3) == 0 && !isalnum((int)p[4]) && p[4] != '-' && p[-3] == '_') { /* copy "XY.EUC" to "euc-XY" to buf[10] */ STRCPY(buf + 10, "euc-"); buf[14] = p[-2]; buf[15] = p[-1]; buf[16] = 0; s = buf + 10; } else s = p + 1; } for (i = 0; i < (int)sizeof(buf) - 1 && s[i] != NUL; ++i) { if (s[i] == '_' || s[i] == '-') buf[i] = '-'; else if (isalnum((int)s[i])) buf[i] = TOLOWER_ASC(s[i]); else break; } buf[i] = NUL; return enc_canonize((char_u *)buf); } # endif /* * Get the canonicalized encoding of the current locale. * Returns an allocated string when successful, NULL when not. */ char_u * enc_locale(void) { # ifdef WIN3264 char buf[50]; long acp = GetACP(); if (acp == 1200) STRCPY(buf, "ucs-2le"); else if (acp == 1252) /* cp1252 is used as latin1 */ STRCPY(buf, "latin1"); else sprintf(buf, "cp%ld", acp); return enc_canonize((char_u *)buf); # else char *s; # ifdef HAVE_NL_LANGINFO_CODESET if ((s = nl_langinfo(CODESET)) == NULL || *s == NUL) # endif # if defined(HAVE_LOCALE_H) || defined(X_LOCALE) if ((s = setlocale(LC_CTYPE, NULL)) == NULL || *s == NUL) # endif s = NULL; return enc_locale_env(s); # endif } # if defined(WIN3264) || defined(PROTO) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD) /* * Convert an encoding name to an MS-Windows codepage. * Returns zero if no codepage can be figured out. */ int encname2codepage(char_u *name) { int cp; char_u *p = name; int idx; if (STRNCMP(p, "8bit-", 5) == 0) p += 5; else if (STRNCMP(p_enc, "2byte-", 6) == 0) p += 6; if (p[0] == 'c' && p[1] == 'p') cp = atoi((char *)p + 2); else if ((idx = enc_canon_search(p)) >= 0) cp = enc_canon_table[idx].codepage; else return 0; if (IsValidCodePage(cp)) return cp; return 0; } # endif # if defined(USE_ICONV) || defined(PROTO) static char_u *iconv_string(vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp); /* * Call iconv_open() with a check if iconv() works properly (there are broken * versions). * Returns (void *)-1 if failed. * (should return iconv_t, but that causes problems with prototypes). */ void * my_iconv_open(char_u *to, char_u *from) { iconv_t fd; #define ICONV_TESTLEN 400 char_u tobuf[ICONV_TESTLEN]; char *p; size_t tolen; static int iconv_ok = -1; if (iconv_ok == FALSE) return (void *)-1; /* detected a broken iconv() previously */ #ifdef DYNAMIC_ICONV /* Check if the iconv.dll can be found. */ if (!iconv_enabled(TRUE)) return (void *)-1; #endif fd = iconv_open((char *)enc_skip(to), (char *)enc_skip(from)); if (fd != (iconv_t)-1 && iconv_ok == -1) { /* * Do a dummy iconv() call to check if it actually works. There is a * version of iconv() on Linux that is broken. We can't ignore it, * because it's wide-spread. The symptoms are that after outputting * the initial shift state the "to" pointer is NULL and conversion * stops for no apparent reason after about 8160 characters. */ p = (char *)tobuf; tolen = ICONV_TESTLEN; (void)iconv(fd, NULL, NULL, &p, &tolen); if (p == NULL) { iconv_ok = FALSE; iconv_close(fd); fd = (iconv_t)-1; } else iconv_ok = TRUE; } return (void *)fd; } /* * Convert the string "str[slen]" with iconv(). * If "unconvlenp" is not NULL handle the string ending in an incomplete * sequence and set "*unconvlenp" to the length of it. * Returns the converted string in allocated memory. NULL for an error. * If resultlenp is not NULL, sets it to the result length in bytes. */ static char_u * iconv_string( vimconv_T *vcp, char_u *str, int slen, int *unconvlenp, int *resultlenp) { const char *from; size_t fromlen; char *to; size_t tolen; size_t len = 0; size_t done = 0; char_u *result = NULL; char_u *p; int l; from = (char *)str; fromlen = slen; for (;;) { if (len == 0 || ICONV_ERRNO == ICONV_E2BIG) { /* Allocate enough room for most conversions. When re-allocating * increase the buffer size. */ len = len + fromlen * 2 + 40; p = alloc((unsigned)len); if (p != NULL && done > 0) mch_memmove(p, result, done); vim_free(result); result = p; if (result == NULL) /* out of memory */ break; } to = (char *)result + done; tolen = len - done - 2; /* Avoid a warning for systems with a wrong iconv() prototype by * casting the second argument to void *. */ if (iconv(vcp->vc_fd, (void *)&from, &fromlen, &to, &tolen) != (size_t)-1) { /* Finished, append a NUL. */ *to = NUL; break; } /* Check both ICONV_EINVAL and EINVAL, because the dynamically loaded * iconv library may use one of them. */ if (!vcp->vc_fail && unconvlenp != NULL && (ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { /* Handle an incomplete sequence at the end. */ *to = NUL; *unconvlenp = (int)fromlen; break; } /* Check both ICONV_EILSEQ and EILSEQ, because the dynamically loaded * iconv library may use one of them. */ else if (!vcp->vc_fail && (ICONV_ERRNO == ICONV_EILSEQ || ICONV_ERRNO == EILSEQ || ICONV_ERRNO == ICONV_EINVAL || ICONV_ERRNO == EINVAL)) { /* Can't convert: insert a '?' and skip a character. This assumes * conversion from 'encoding' to something else. In other * situations we don't know what to skip anyway. */ *to++ = '?'; if ((*mb_ptr2cells)((char_u *)from) > 1) *to++ = '?'; if (enc_utf8) l = utfc_ptr2len_len((char_u *)from, (int)fromlen); else { l = (*mb_ptr2len)((char_u *)from); if (l > (int)fromlen) l = (int)fromlen; } from += l; fromlen -= l; } else if (ICONV_ERRNO != ICONV_E2BIG) { /* conversion failed */ VIM_CLEAR(result); break; } /* Not enough room or skipping illegal sequence. */ done = to - (char *)result; } if (resultlenp != NULL && result != NULL) *resultlenp = (int)(to - (char *)result); return result; } # if defined(DYNAMIC_ICONV) || defined(PROTO) /* * Dynamically load the "iconv.dll" on Win32. */ # ifndef DYNAMIC_ICONV /* must be generating prototypes */ # define HINSTANCE int # endif static HINSTANCE hIconvDLL = 0; static HINSTANCE hMsvcrtDLL = 0; # ifndef DYNAMIC_ICONV_DLL # define DYNAMIC_ICONV_DLL "iconv.dll" # define DYNAMIC_ICONV_DLL_ALT1 "libiconv.dll" # define DYNAMIC_ICONV_DLL_ALT2 "libiconv2.dll" # define DYNAMIC_ICONV_DLL_ALT3 "libiconv-2.dll" # endif # ifndef DYNAMIC_MSVCRT_DLL # define DYNAMIC_MSVCRT_DLL "msvcrt.dll" # endif /* * Try opening the iconv.dll and return TRUE if iconv() can be used. */ int iconv_enabled(int verbose) { if (hIconvDLL != 0 && hMsvcrtDLL != 0) return TRUE; /* The iconv DLL file goes under different names, try them all. * Do the "2" version first, it's newer. */ #ifdef DYNAMIC_ICONV_DLL_ALT2 if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT2); #endif #ifdef DYNAMIC_ICONV_DLL_ALT3 if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT3); #endif if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL); #ifdef DYNAMIC_ICONV_DLL_ALT1 if (hIconvDLL == 0) hIconvDLL = vimLoadLib(DYNAMIC_ICONV_DLL_ALT1); #endif if (hIconvDLL != 0) hMsvcrtDLL = vimLoadLib(DYNAMIC_MSVCRT_DLL); if (hIconvDLL == 0 || hMsvcrtDLL == 0) { /* Only give the message when 'verbose' is set, otherwise it might be * done whenever a conversion is attempted. */ if (verbose && p_verbose > 0) { verbose_enter(); EMSG2(_(e_loadlib), hIconvDLL == 0 ? DYNAMIC_ICONV_DLL : DYNAMIC_MSVCRT_DLL); verbose_leave(); } iconv_end(); return FALSE; } iconv = (void *)GetProcAddress(hIconvDLL, "libiconv"); iconv_open = (void *)GetProcAddress(hIconvDLL, "libiconv_open"); iconv_close = (void *)GetProcAddress(hIconvDLL, "libiconv_close"); iconvctl = (void *)GetProcAddress(hIconvDLL, "libiconvctl"); iconv_errno = get_dll_import_func(hIconvDLL, "_errno"); if (iconv_errno == NULL) iconv_errno = (void *)GetProcAddress(hMsvcrtDLL, "_errno"); if (iconv == NULL || iconv_open == NULL || iconv_close == NULL || iconvctl == NULL || iconv_errno == NULL) { iconv_end(); if (verbose && p_verbose > 0) { verbose_enter(); EMSG2(_(e_loadfunc), "for libiconv"); verbose_leave(); } return FALSE; } return TRUE; } void iconv_end(void) { /* Don't use iconv() when inputting or outputting characters. */ if (input_conv.vc_type == CONV_ICONV) convert_setup(&input_conv, NULL, NULL); if (output_conv.vc_type == CONV_ICONV) convert_setup(&output_conv, NULL, NULL); if (hIconvDLL != 0) FreeLibrary(hIconvDLL); if (hMsvcrtDLL != 0) FreeLibrary(hMsvcrtDLL); hIconvDLL = 0; hMsvcrtDLL = 0; } # endif /* DYNAMIC_ICONV */ # endif /* USE_ICONV */ #endif /* FEAT_MBYTE */ #ifdef FEAT_GUI # define USE_IMACTIVATEFUNC (!gui.in_use && *p_imaf != NUL) # define USE_IMSTATUSFUNC (!gui.in_use && *p_imsf != NUL) #else # define USE_IMACTIVATEFUNC (*p_imaf != NUL) # define USE_IMSTATUSFUNC (*p_imsf != NUL) #endif #if defined(FEAT_EVAL) && defined(FEAT_MBYTE) static void call_imactivatefunc(int active) { char_u *argv[1]; if (active) argv[0] = (char_u *)"1"; else argv[0] = (char_u *)"0"; (void)call_func_retnr(p_imaf, 1, argv, FALSE); } static int call_imstatusfunc(void) { int is_active; /* FIXME: Don't execute user function in unsafe situation. */ if (exiting # ifdef FEAT_AUTOCMD || is_autocmd_blocked() # endif ) return FALSE; /* FIXME: :py print 'xxx' is shown duplicate result. * Use silent to avoid it. */ ++msg_silent; is_active = call_func_retnr(p_imsf, 0, NULL, FALSE); --msg_silent; return (is_active > 0); } #endif #if defined(FEAT_XIM) || defined(PROTO) # if defined(FEAT_GUI_GTK) || defined(PROTO) static int xim_has_preediting INIT(= FALSE); /* IM current status */ /* * Set preedit_start_col to the current cursor position. */ static void init_preedit_start_col(void) { if (State & CMDLINE) preedit_start_col = cmdline_getvcol_cursor(); else if (curwin != NULL && curwin->w_buffer != NULL) getvcol(curwin, &curwin->w_cursor, &preedit_start_col, NULL, NULL); /* Prevent that preediting marks the buffer as changed. */ xim_changed_while_preediting = curbuf->b_changed; } static int im_is_active = FALSE; /* IM is enabled for current mode */ static int preedit_is_active = FALSE; static int im_preedit_cursor = 0; /* cursor offset in characters */ static int im_preedit_trailing = 0; /* number of characters after cursor */ static unsigned long im_commit_handler_id = 0; static unsigned int im_activatekey_keyval = GDK_VoidSymbol; static unsigned int im_activatekey_state = 0; static GtkWidget *preedit_window = NULL; static GtkWidget *preedit_label = NULL; static void im_preedit_window_set_position(void); void im_set_active(int active) { int was_active; was_active = !!im_get_status(); im_is_active = (active && !p_imdisable); if (im_is_active != was_active) xim_reset(); } void xim_set_focus(int focus) { if (xic != NULL) { if (focus) gtk_im_context_focus_in(xic); else gtk_im_context_focus_out(xic); } } void im_set_position(int row, int col) { if (xic != NULL) { GdkRectangle area; area.x = FILL_X(col); area.y = FILL_Y(row); area.width = gui.char_width * (mb_lefthalve(row, col) ? 2 : 1); area.height = gui.char_height; gtk_im_context_set_cursor_location(xic, &area); if (p_imst == IM_OVER_THE_SPOT) im_preedit_window_set_position(); } } # if 0 || defined(PROTO) /* apparently only used in gui_x11.c */ void xim_set_preedit(void) { im_set_position(gui.row, gui.col); } # endif static void im_add_to_input(char_u *str, int len) { /* Convert from 'termencoding' (always "utf-8") to 'encoding' */ if (input_conv.vc_type != CONV_NONE) { str = string_convert(&input_conv, str, &len); g_return_if_fail(str != NULL); } add_to_input_buf_csi(str, len); if (input_conv.vc_type != CONV_NONE) vim_free(str); if (p_mh) /* blank out the pointer if necessary */ gui_mch_mousehide(TRUE); } static void im_preedit_window_set_position(void) { int x, y, w, h, sw, sh; if (preedit_window == NULL) return; gui_gtk_get_screen_size_of_win(preedit_window, &sw, &sh); #if GTK_CHECK_VERSION(3,0,0) gdk_window_get_origin(gtk_widget_get_window(gui.drawarea), &x, &y); #else gdk_window_get_origin(gui.drawarea->window, &x, &y); #endif gtk_window_get_size(GTK_WINDOW(preedit_window), &w, &h); x = x + FILL_X(gui.col); y = y + FILL_Y(gui.row); if (x + w > sw) x = sw - w; if (y + h > sh) y = sh - h; gtk_window_move(GTK_WINDOW(preedit_window), x, y); } static void im_preedit_window_open() { char *preedit_string; #if !GTK_CHECK_VERSION(3,16,0) char buf[8]; #endif PangoAttrList *attr_list; PangoLayout *layout; #if GTK_CHECK_VERSION(3,0,0) # if !GTK_CHECK_VERSION(3,16,0) GdkRGBA color; # endif #else GdkColor color; #endif gint w, h; if (preedit_window == NULL) { preedit_window = gtk_window_new(GTK_WINDOW_POPUP); gtk_window_set_transient_for(GTK_WINDOW(preedit_window), GTK_WINDOW(gui.mainwin)); preedit_label = gtk_label_new(""); gtk_widget_set_name(preedit_label, "vim-gui-preedit-area"); gtk_container_add(GTK_CONTAINER(preedit_window), preedit_label); } #if GTK_CHECK_VERSION(3,16,0) { GtkStyleContext * const context = gtk_widget_get_style_context(gui.drawarea); GtkCssProvider * const provider = gtk_css_provider_new(); gchar *css = NULL; const char * const fontname = pango_font_description_get_family(gui.norm_font); gint fontsize = pango_font_description_get_size(gui.norm_font) / PANGO_SCALE; gchar *fontsize_propval = NULL; if (!pango_font_description_get_size_is_absolute(gui.norm_font)) { /* fontsize was given in points. Convert it into that in pixels * to use with CSS. */ GdkScreen * const screen = gdk_window_get_screen(gtk_widget_get_window(gui.mainwin)); const gdouble dpi = gdk_screen_get_resolution(screen); fontsize = dpi * fontsize / 72; } if (fontsize > 0) fontsize_propval = g_strdup_printf("%dpx", fontsize); else fontsize_propval = g_strdup_printf("inherit"); css = g_strdup_printf( "widget#vim-gui-preedit-area {\n" " font-family: %s,monospace;\n" " font-size: %s;\n" " color: #%.2lx%.2lx%.2lx;\n" " background-color: #%.2lx%.2lx%.2lx;\n" "}\n", fontname != NULL ? fontname : "inherit", fontsize_propval, (gui.norm_pixel >> 16) & 0xff, (gui.norm_pixel >> 8) & 0xff, gui.norm_pixel & 0xff, (gui.back_pixel >> 16) & 0xff, (gui.back_pixel >> 8) & 0xff, gui.back_pixel & 0xff); gtk_css_provider_load_from_data(provider, css, -1, NULL); gtk_style_context_add_provider(context, GTK_STYLE_PROVIDER(provider), G_MAXUINT); g_free(css); g_free(fontsize_propval); g_object_unref(provider); } #elif GTK_CHECK_VERSION(3,0,0) gtk_widget_override_font(preedit_label, gui.norm_font); vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel); gdk_rgba_parse(&color, buf); gtk_widget_override_color(preedit_label, GTK_STATE_FLAG_NORMAL, &color); vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel); gdk_rgba_parse(&color, buf); gtk_widget_override_background_color(preedit_label, GTK_STATE_FLAG_NORMAL, &color); #else gtk_widget_modify_font(preedit_label, gui.norm_font); vim_snprintf(buf, sizeof(buf), "#%06X", gui.norm_pixel); gdk_color_parse(buf, &color); gtk_widget_modify_fg(preedit_label, GTK_STATE_NORMAL, &color); vim_snprintf(buf, sizeof(buf), "#%06X", gui.back_pixel); gdk_color_parse(buf, &color); gtk_widget_modify_bg(preedit_window, GTK_STATE_NORMAL, &color); #endif gtk_im_context_get_preedit_string(xic, &preedit_string, &attr_list, NULL); if (preedit_string[0] != NUL) { gtk_label_set_text(GTK_LABEL(preedit_label), preedit_string); gtk_label_set_attributes(GTK_LABEL(preedit_label), attr_list); layout = gtk_label_get_layout(GTK_LABEL(preedit_label)); pango_layout_get_pixel_size(layout, &w, &h); h = MAX(h, gui.char_height); gtk_window_resize(GTK_WINDOW(preedit_window), w, h); gtk_widget_show_all(preedit_window); im_preedit_window_set_position(); } g_free(preedit_string); pango_attr_list_unref(attr_list); } static void im_preedit_window_close() { if (preedit_window != NULL) gtk_widget_hide(preedit_window); } static void im_show_preedit() { im_preedit_window_open(); if (p_mh) /* blank out the pointer if necessary */ gui_mch_mousehide(TRUE); } static void im_delete_preedit(void) { char_u bskey[] = {CSI, 'k', 'b'}; char_u delkey[] = {CSI, 'k', 'D'}; if (p_imst == IM_OVER_THE_SPOT) { im_preedit_window_close(); return; } if (State & NORMAL #ifdef FEAT_TERMINAL && !term_use_loop() #endif ) { im_preedit_cursor = 0; return; } for (; im_preedit_cursor > 0; --im_preedit_cursor) add_to_input_buf(bskey, (int)sizeof(bskey)); for (; im_preedit_trailing > 0; --im_preedit_trailing) add_to_input_buf(delkey, (int)sizeof(delkey)); } /* * Move the cursor left by "num_move_back" characters. * Note that ins_left() checks im_is_preediting() to avoid breaking undo for * these K_LEFT keys. */ static void im_correct_cursor(int num_move_back) { char_u backkey[] = {CSI, 'k', 'l'}; if (State & NORMAL) return; # ifdef FEAT_RIGHTLEFT if ((State & CMDLINE) == 0 && curwin != NULL && curwin->w_p_rl) backkey[2] = 'r'; # endif for (; num_move_back > 0; --num_move_back) add_to_input_buf(backkey, (int)sizeof(backkey)); } static int xim_expected_char = NUL; static int xim_ignored_char = FALSE; /* * Update the mode and cursor while in an IM callback. */ static void im_show_info(void) { int old_vgetc_busy; old_vgetc_busy = vgetc_busy; vgetc_busy = TRUE; showmode(); vgetc_busy = old_vgetc_busy; if ((State & NORMAL) || (State & INSERT)) setcursor(); out_flush(); } /* * Callback invoked when the user finished preediting. * Put the final string into the input buffer. */ static void im_commit_cb(GtkIMContext *context UNUSED, const gchar *str, gpointer data UNUSED) { int slen = (int)STRLEN(str); int add_to_input = TRUE; int clen; int len = slen; int commit_with_preedit = TRUE; char_u *im_str; #ifdef XIM_DEBUG xim_log("im_commit_cb(): %s\n", str); #endif if (p_imst == IM_ON_THE_SPOT) { /* The imhangul module doesn't reset the preedit string before * committing. Call im_delete_preedit() to work around that. */ im_delete_preedit(); /* Indicate that preediting has finished. */ if (preedit_start_col == MAXCOL) { init_preedit_start_col(); commit_with_preedit = FALSE; } /* The thing which setting "preedit_start_col" to MAXCOL means that * "preedit_start_col" will be set forcedly when calling * preedit_changed_cb() next time. * "preedit_start_col" should not reset with MAXCOL on this part. Vim * is simulating the preediting by using add_to_input_str(). when * preedit begin immediately before committed, the typebuf is not * flushed to screen, then it can't get correct "preedit_start_col". * Thus, it should calculate the cells by adding cells of the committed * string. */ if (input_conv.vc_type != CONV_NONE) { im_str = string_convert(&input_conv, (char_u *)str, &len); g_return_if_fail(im_str != NULL); } else im_str = (char_u *)str; clen = mb_string2cells(im_str, len); if (input_conv.vc_type != CONV_NONE) vim_free(im_str); preedit_start_col += clen; } /* Is this a single character that matches a keypad key that's just * been pressed? If so, we don't want it to be entered as such - let * us carry on processing the raw keycode so that it may be used in * mappings as <kSomething>. */ if (xim_expected_char != NUL) { /* We're currently processing a keypad or other special key */ if (slen == 1 && str[0] == xim_expected_char) { /* It's a match - don't do it here */ xim_ignored_char = TRUE; add_to_input = FALSE; } else { /* Not a match */ xim_ignored_char = FALSE; } } if (add_to_input) im_add_to_input((char_u *)str, slen); if (p_imst == IM_ON_THE_SPOT) { /* Inserting chars while "im_is_active" is set does not cause a * change of buffer. When the chars are committed the buffer must be * marked as changed. */ if (!commit_with_preedit) preedit_start_col = MAXCOL; /* This flag is used in changed() at next call. */ xim_changed_while_preediting = TRUE; } if (gtk_main_level() > 0) gtk_main_quit(); } /* * Callback invoked after start to the preedit. */ static void im_preedit_start_cb(GtkIMContext *context UNUSED, gpointer data UNUSED) { #ifdef XIM_DEBUG xim_log("im_preedit_start_cb()\n"); #endif im_is_active = TRUE; preedit_is_active = TRUE; gui_update_cursor(TRUE, FALSE); im_show_info(); } /* * Callback invoked after end to the preedit. */ static void im_preedit_end_cb(GtkIMContext *context UNUSED, gpointer data UNUSED) { #ifdef XIM_DEBUG xim_log("im_preedit_end_cb()\n"); #endif im_delete_preedit(); /* Indicate that preediting has finished */ if (p_imst == IM_ON_THE_SPOT) preedit_start_col = MAXCOL; xim_has_preediting = FALSE; #if 0 /* Removal of this line suggested by Takuhiro Nishioka. Fixes that IM was * switched off unintentionally. We now use preedit_is_active (added by * SungHyun Nam). */ im_is_active = FALSE; #endif preedit_is_active = FALSE; gui_update_cursor(TRUE, FALSE); im_show_info(); } /* * Callback invoked after changes to the preedit string. If the preedit * string was empty before, remember the preedit start column so we know * where to apply feedback attributes. Delete the previous preedit string * if there was one, save the new preedit cursor offset, and put the new * string into the input buffer. * * TODO: The pragmatic "put into input buffer" approach used here has * several fundamental problems: * * - The characters in the preedit string are subject to remapping. * That's broken, only the finally committed string should be remapped. * * - There is a race condition involved: The retrieved value for the * current cursor position will be wrong if any unprocessed characters * are still queued in the input buffer. * * - Due to the lack of synchronization between the file buffer in memory * and any typed characters, it's practically impossible to implement the * "retrieve_surrounding" and "delete_surrounding" signals reliably. IM * modules for languages such as Thai are likely to rely on this feature * for proper operation. * * Conclusions: I think support for preediting needs to be moved to the * core parts of Vim. Ideally, until it has been committed, the preediting * string should only be displayed and not affect the buffer content at all. * The question how to deal with the synchronization issue still remains. * Circumventing the input buffer is probably not desirable. Anyway, I think * implementing "retrieve_surrounding" is the only hard problem. * * One way to solve all of this in a clean manner would be to queue all key * press/release events "as is" in the input buffer, and apply the IM filtering * at the receiving end of the queue. This, however, would have a rather large * impact on the code base. If there is an easy way to force processing of all * remaining input from within the "retrieve_surrounding" signal handler, this * might not be necessary. Gotta ask on vim-dev for opinions. */ static void im_preedit_changed_cb(GtkIMContext *context, gpointer data UNUSED) { char *preedit_string = NULL; int cursor_index = 0; int num_move_back = 0; char_u *str; char_u *p; int i; if (p_imst == IM_ON_THE_SPOT) gtk_im_context_get_preedit_string(context, &preedit_string, NULL, &cursor_index); else gtk_im_context_get_preedit_string(context, &preedit_string, NULL, NULL); #ifdef XIM_DEBUG xim_log("im_preedit_changed_cb(): %s\n", preedit_string); #endif g_return_if_fail(preedit_string != NULL); /* just in case */ if (p_imst == IM_OVER_THE_SPOT) { if (preedit_string[0] == NUL) { xim_has_preediting = FALSE; im_delete_preedit(); } else { xim_has_preediting = TRUE; im_show_preedit(); } } else { /* If preedit_start_col is MAXCOL set it to the current cursor position. */ if (preedit_start_col == MAXCOL && preedit_string[0] != '\0') { xim_has_preediting = TRUE; /* Urgh, this breaks if the input buffer isn't empty now */ init_preedit_start_col(); } else if (cursor_index == 0 && preedit_string[0] == '\0') { xim_has_preediting = FALSE; /* If at the start position (after typing backspace) * preedit_start_col must be reset. */ preedit_start_col = MAXCOL; } im_delete_preedit(); /* * Compute the end of the preediting area: "preedit_end_col". * According to the documentation of gtk_im_context_get_preedit_string(), * the cursor_pos output argument returns the offset in bytes. This is * unfortunately not true -- real life shows the offset is in characters, * and the GTK+ source code agrees with me. Will file a bug later. */ if (preedit_start_col != MAXCOL) preedit_end_col = preedit_start_col; str = (char_u *)preedit_string; for (p = str, i = 0; *p != NUL; p += utf_byte2len(*p), ++i) { int is_composing; is_composing = ((*p & 0x80) != 0 && utf_iscomposing(utf_ptr2char(p))); /* * These offsets are used as counters when generating <BS> and <Del> * to delete the preedit string. So don't count composing characters * unless 'delcombine' is enabled. */ if (!is_composing || p_deco) { if (i < cursor_index) ++im_preedit_cursor; else ++im_preedit_trailing; } if (!is_composing && i >= cursor_index) { /* This is essentially the same as im_preedit_trailing, except * composing characters are not counted even if p_deco is set. */ ++num_move_back; } if (preedit_start_col != MAXCOL) preedit_end_col += utf_ptr2cells(p); } if (p > str) { im_add_to_input(str, (int)(p - str)); im_correct_cursor(num_move_back); } } g_free(preedit_string); if (gtk_main_level() > 0) gtk_main_quit(); } /* * Translate the Pango attributes at iter to Vim highlighting attributes. * Ignore attributes not supported by Vim highlighting. This shouldn't have * too much impact -- right now we handle even more attributes than necessary * for the IM modules I tested with. */ static int translate_pango_attributes(PangoAttrIterator *iter) { PangoAttribute *attr; int char_attr = HL_NORMAL; attr = pango_attr_iterator_get(iter, PANGO_ATTR_UNDERLINE); if (attr != NULL && ((PangoAttrInt *)attr)->value != (int)PANGO_UNDERLINE_NONE) char_attr |= HL_UNDERLINE; attr = pango_attr_iterator_get(iter, PANGO_ATTR_WEIGHT); if (attr != NULL && ((PangoAttrInt *)attr)->value >= (int)PANGO_WEIGHT_BOLD) char_attr |= HL_BOLD; attr = pango_attr_iterator_get(iter, PANGO_ATTR_STYLE); if (attr != NULL && ((PangoAttrInt *)attr)->value != (int)PANGO_STYLE_NORMAL) char_attr |= HL_ITALIC; attr = pango_attr_iterator_get(iter, PANGO_ATTR_BACKGROUND); if (attr != NULL) { const PangoColor *color = &((PangoAttrColor *)attr)->color; /* Assume inverse if black background is requested */ if ((color->red | color->green | color->blue) == 0) char_attr |= HL_INVERSE; } return char_attr; } /* * Retrieve the highlighting attributes at column col in the preedit string. * Return -1 if not in preediting mode or if col is out of range. */ int im_get_feedback_attr(int col) { char *preedit_string = NULL; PangoAttrList *attr_list = NULL; int char_attr = -1; if (xic == NULL) return char_attr; gtk_im_context_get_preedit_string(xic, &preedit_string, &attr_list, NULL); if (preedit_string != NULL && attr_list != NULL) { int idx; /* Get the byte index as used by PangoAttrIterator */ for (idx = 0; col > 0 && preedit_string[idx] != '\0'; --col) idx += utfc_ptr2len((char_u *)preedit_string + idx); if (preedit_string[idx] != '\0') { PangoAttrIterator *iter; int start, end; char_attr = HL_NORMAL; iter = pango_attr_list_get_iterator(attr_list); /* Extract all relevant attributes from the list. */ do { pango_attr_iterator_range(iter, &start, &end); if (idx >= start && idx < end) char_attr |= translate_pango_attributes(iter); } while (pango_attr_iterator_next(iter)); pango_attr_iterator_destroy(iter); } } if (attr_list != NULL) pango_attr_list_unref(attr_list); g_free(preedit_string); return char_attr; } void xim_init(void) { #ifdef XIM_DEBUG xim_log("xim_init()\n"); #endif g_return_if_fail(gui.drawarea != NULL); #if GTK_CHECK_VERSION(3,0,0) g_return_if_fail(gtk_widget_get_window(gui.drawarea) != NULL); #else g_return_if_fail(gui.drawarea->window != NULL); #endif xic = gtk_im_multicontext_new(); g_object_ref(xic); im_commit_handler_id = g_signal_connect(G_OBJECT(xic), "commit", G_CALLBACK(&im_commit_cb), NULL); g_signal_connect(G_OBJECT(xic), "preedit_changed", G_CALLBACK(&im_preedit_changed_cb), NULL); g_signal_connect(G_OBJECT(xic), "preedit_start", G_CALLBACK(&im_preedit_start_cb), NULL); g_signal_connect(G_OBJECT(xic), "preedit_end", G_CALLBACK(&im_preedit_end_cb), NULL); #if GTK_CHECK_VERSION(3,0,0) gtk_im_context_set_client_window(xic, gtk_widget_get_window(gui.drawarea)); #else gtk_im_context_set_client_window(xic, gui.drawarea->window); #endif } void im_shutdown(void) { #ifdef XIM_DEBUG xim_log("im_shutdown()\n"); #endif if (xic != NULL) { gtk_im_context_focus_out(xic); g_object_unref(xic); xic = NULL; } im_is_active = FALSE; im_commit_handler_id = 0; if (p_imst == IM_ON_THE_SPOT) preedit_start_col = MAXCOL; xim_has_preediting = FALSE; } /* * Convert the string argument to keyval and state for GdkEventKey. * If str is valid return TRUE, otherwise FALSE. * * See 'imactivatekey' for documentation of the format. */ static int im_string_to_keyval(const char *str, unsigned int *keyval, unsigned int *state) { const char *mods_end; unsigned tmp_keyval; unsigned tmp_state = 0; mods_end = strrchr(str, '-'); mods_end = (mods_end != NULL) ? mods_end + 1 : str; /* Parse modifier keys */ while (str < mods_end) switch (*str++) { case '-': break; case 'S': case 's': tmp_state |= (unsigned)GDK_SHIFT_MASK; break; case 'L': case 'l': tmp_state |= (unsigned)GDK_LOCK_MASK; break; case 'C': case 'c': tmp_state |= (unsigned)GDK_CONTROL_MASK;break; case '1': tmp_state |= (unsigned)GDK_MOD1_MASK; break; case '2': tmp_state |= (unsigned)GDK_MOD2_MASK; break; case '3': tmp_state |= (unsigned)GDK_MOD3_MASK; break; case '4': tmp_state |= (unsigned)GDK_MOD4_MASK; break; case '5': tmp_state |= (unsigned)GDK_MOD5_MASK; break; default: return FALSE; } tmp_keyval = gdk_keyval_from_name(str); if (tmp_keyval == 0 || tmp_keyval == GDK_VoidSymbol) return FALSE; if (keyval != NULL) *keyval = tmp_keyval; if (state != NULL) *state = tmp_state; return TRUE; } /* * Return TRUE if p_imak is valid, otherwise FALSE. As a special case, an * empty string is also regarded as valid. * * Note: The numerical key value of p_imak is cached if it was valid; thus * boldly assuming im_xim_isvalid_imactivate() will always be called whenever * 'imak' changes. This is currently the case but not obvious -- should * probably rename the function for clarity. */ int im_xim_isvalid_imactivate(void) { if (p_imak[0] == NUL) { im_activatekey_keyval = GDK_VoidSymbol; im_activatekey_state = 0; return TRUE; } return im_string_to_keyval((const char *)p_imak, &im_activatekey_keyval, &im_activatekey_state); } static void im_synthesize_keypress(unsigned int keyval, unsigned int state) { GdkEventKey *event; event = (GdkEventKey *)gdk_event_new(GDK_KEY_PRESS); # if GTK_CHECK_VERSION(3,0,0) g_object_ref(gtk_widget_get_window(gui.drawarea)); /* unreffed by gdk_event_free() */ # else g_object_ref(gui.drawarea->window); /* unreffed by gdk_event_free() */ # endif # if GTK_CHECK_VERSION(3,0,0) event->window = gtk_widget_get_window(gui.drawarea); # else event->window = gui.drawarea->window; # endif event->send_event = TRUE; event->time = GDK_CURRENT_TIME; event->state = state; event->keyval = keyval; event->hardware_keycode = /* needed for XIM */ XKeysymToKeycode(GDK_WINDOW_XDISPLAY(event->window), (KeySym)keyval); event->length = 0; event->string = NULL; gtk_im_context_filter_keypress(xic, event); /* For consistency, also send the corresponding release event. */ event->type = GDK_KEY_RELEASE; event->send_event = FALSE; gtk_im_context_filter_keypress(xic, event); gdk_event_free((GdkEvent *)event); } void xim_reset(void) { #ifdef FEAT_EVAL if (USE_IMACTIVATEFUNC) call_imactivatefunc(im_is_active); else #endif if (xic != NULL) { gtk_im_context_reset(xic); if (p_imdisable) im_shutdown(); else { xim_set_focus(gui.in_focus); if (im_activatekey_keyval != GDK_VoidSymbol) { if (im_is_active) { g_signal_handler_block(xic, im_commit_handler_id); im_synthesize_keypress(im_activatekey_keyval, im_activatekey_state); g_signal_handler_unblock(xic, im_commit_handler_id); } } else { im_shutdown(); xim_init(); xim_set_focus(gui.in_focus); } } } if (p_imst == IM_ON_THE_SPOT) preedit_start_col = MAXCOL; xim_has_preediting = FALSE; } int xim_queue_key_press_event(GdkEventKey *event, int down) { if (down) { /* * Workaround GTK2 XIM 'feature' that always converts keypad keys to * chars., even when not part of an IM sequence (ref. feature of * gdk/gdkkeyuni.c). * Flag any keypad keys that might represent a single char. * If this (on its own - i.e., not part of an IM sequence) is * committed while we're processing one of these keys, we can ignore * that commit and go ahead & process it ourselves. That way we can * still distinguish keypad keys for use in mappings. * Also add GDK_space to make <S-Space> work. */ switch (event->keyval) { case GDK_KP_Add: xim_expected_char = '+'; break; case GDK_KP_Subtract: xim_expected_char = '-'; break; case GDK_KP_Divide: xim_expected_char = '/'; break; case GDK_KP_Multiply: xim_expected_char = '*'; break; case GDK_KP_Decimal: xim_expected_char = '.'; break; case GDK_KP_Equal: xim_expected_char = '='; break; case GDK_KP_0: xim_expected_char = '0'; break; case GDK_KP_1: xim_expected_char = '1'; break; case GDK_KP_2: xim_expected_char = '2'; break; case GDK_KP_3: xim_expected_char = '3'; break; case GDK_KP_4: xim_expected_char = '4'; break; case GDK_KP_5: xim_expected_char = '5'; break; case GDK_KP_6: xim_expected_char = '6'; break; case GDK_KP_7: xim_expected_char = '7'; break; case GDK_KP_8: xim_expected_char = '8'; break; case GDK_KP_9: xim_expected_char = '9'; break; case GDK_space: xim_expected_char = ' '; break; default: xim_expected_char = NUL; } xim_ignored_char = FALSE; } /* * When typing fFtT, XIM may be activated. Thus it must pass * gtk_im_context_filter_keypress() in Normal mode. * And while doing :sh too. */ if (xic != NULL && !p_imdisable && (State & (INSERT | CMDLINE | NORMAL | EXTERNCMD)) != 0) { /* * Filter 'imactivatekey' and map it to CTRL-^. This way, Vim is * always aware of the current status of IM, and can even emulate * the activation key for modules that don't support one. */ if (event->keyval == im_activatekey_keyval && (event->state & im_activatekey_state) == im_activatekey_state) { unsigned int state_mask; /* Require the state of the 3 most used modifiers to match exactly. * Otherwise e.g. <S-C-space> would be unusable for other purposes * if the IM activate key is <S-space>. */ state_mask = im_activatekey_state; state_mask |= ((int)GDK_SHIFT_MASK | (int)GDK_CONTROL_MASK | (int)GDK_MOD1_MASK); if ((event->state & state_mask) != im_activatekey_state) return FALSE; /* Don't send it a second time on GDK_KEY_RELEASE. */ if (event->type != GDK_KEY_PRESS) return TRUE; if (map_to_exists_mode((char_u *)"", LANGMAP, FALSE)) { im_set_active(FALSE); /* ":lmap" mappings exists, toggle use of mappings. */ State ^= LANGMAP; if (State & LANGMAP) { curbuf->b_p_iminsert = B_IMODE_NONE; State &= ~LANGMAP; } else { curbuf->b_p_iminsert = B_IMODE_LMAP; State |= LANGMAP; } return TRUE; } return gtk_im_context_filter_keypress(xic, event); } /* Don't filter events through the IM context if IM isn't active * right now. Unlike with GTK+ 1.2 we cannot rely on the IM module * not doing anything before the activation key was sent. */ if (im_activatekey_keyval == GDK_VoidSymbol || im_is_active) { int imresult = gtk_im_context_filter_keypress(xic, event); if (p_imst == IM_ON_THE_SPOT) { /* Some XIM send following sequence: * 1. preedited string. * 2. committed string. * 3. line changed key. * 4. preedited string. * 5. remove preedited string. * if 3, Vim can't move back the above line for 5. * thus, this part should not parse the key. */ if (!imresult && preedit_start_col != MAXCOL && event->keyval == GDK_Return) { im_synthesize_keypress(GDK_Return, 0U); return FALSE; } } /* If XIM tried to commit a keypad key as a single char., * ignore it so we can use the keypad key 'raw', for mappings. */ if (xim_expected_char != NUL && xim_ignored_char) /* We had a keypad key, and XIM tried to thieve it */ return FALSE; /* This is supposed to fix a problem with iBus, that space * characters don't work in input mode. */ xim_expected_char = NUL; /* Normal processing */ return imresult; } } return FALSE; } int im_get_status(void) { # ifdef FEAT_EVAL if (USE_IMSTATUSFUNC) return call_imstatusfunc(); # endif return im_is_active; } int preedit_get_status(void) { return preedit_is_active; } int im_is_preediting(void) { return xim_has_preediting; } # else /* !FEAT_GUI_GTK */ static int xim_is_active = FALSE; /* XIM should be active in the current mode */ static int xim_has_focus = FALSE; /* XIM is really being used for Vim */ # ifdef FEAT_GUI_X11 static XIMStyle input_style; static int status_area_enabled = TRUE; # endif /* * Switch using XIM on/off. This is used by the code that changes "State". * When 'imactivatefunc' is defined use that function instead. */ void im_set_active(int active_arg) { int active = active_arg; /* If 'imdisable' is set, XIM is never active. */ if (p_imdisable) active = FALSE; else if (input_style & XIMPreeditPosition) /* There is a problem in switching XIM off when preediting is used, * and it is not clear how this can be solved. For now, keep XIM on * all the time, like it was done in Vim 5.8. */ active = TRUE; # if defined(FEAT_EVAL) if (USE_IMACTIVATEFUNC) { if (active != im_get_status()) { call_imactivatefunc(active); xim_has_focus = active; } return; } # endif if (xic == NULL) return; /* Remember the active state, it is needed when Vim gets keyboard focus. */ xim_is_active = active; xim_set_preedit(); } /* * Adjust using XIM for gaining or losing keyboard focus. Also called when * "xim_is_active" changes. */ void xim_set_focus(int focus) { if (xic == NULL) return; /* * XIM only gets focus when the Vim window has keyboard focus and XIM has * been set active for the current mode. */ if (focus && xim_is_active) { if (!xim_has_focus) { xim_has_focus = TRUE; XSetICFocus(xic); } } else { if (xim_has_focus) { xim_has_focus = FALSE; XUnsetICFocus(xic); } } } void im_set_position(int row UNUSED, int col UNUSED) { xim_set_preedit(); } /* * Set the XIM to the current cursor position. */ void xim_set_preedit(void) { XVaNestedList attr_list; XRectangle spot_area; XPoint over_spot; int line_space; if (xic == NULL) return; xim_set_focus(TRUE); if (!xim_has_focus) { /* hide XIM cursor */ over_spot.x = 0; over_spot.y = -100; /* arbitrary invisible position */ attr_list = (XVaNestedList) XVaCreateNestedList(0, XNSpotLocation, &over_spot, NULL); XSetICValues(xic, XNPreeditAttributes, attr_list, NULL); XFree(attr_list); return; } if (input_style & XIMPreeditPosition) { if (xim_fg_color == INVALCOLOR) { xim_fg_color = gui.def_norm_pixel; xim_bg_color = gui.def_back_pixel; } over_spot.x = TEXT_X(gui.col); over_spot.y = TEXT_Y(gui.row); spot_area.x = 0; spot_area.y = 0; spot_area.height = gui.char_height * Rows; spot_area.width = gui.char_width * Columns; line_space = gui.char_height; attr_list = (XVaNestedList) XVaCreateNestedList(0, XNSpotLocation, &over_spot, XNForeground, (Pixel) xim_fg_color, XNBackground, (Pixel) xim_bg_color, XNArea, &spot_area, XNLineSpace, line_space, NULL); if (XSetICValues(xic, XNPreeditAttributes, attr_list, NULL)) EMSG(_("E284: Cannot set IC values")); XFree(attr_list); } } # if defined(FEAT_GUI_X11) static char e_xim[] = N_("E285: Failed to create input context"); # endif # if defined(FEAT_GUI_X11) || defined(PROTO) # if defined(XtSpecificationRelease) && XtSpecificationRelease >= 6 && !defined(SUN_SYSTEM) # define USE_X11R6_XIM # endif static int xim_real_init(Window x11_window, Display *x11_display); # ifdef USE_X11R6_XIM static void xim_destroy_cb(XIM im, XPointer client_data, XPointer call_data); static void xim_instantiate_cb( Display *display, XPointer client_data UNUSED, XPointer call_data UNUSED) { Window x11_window; Display *x11_display; # ifdef XIM_DEBUG xim_log("xim_instantiate_cb()\n"); # endif gui_get_x11_windis(&x11_window, &x11_display); if (display != x11_display) return; xim_real_init(x11_window, x11_display); gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); if (xic != NULL) XUnregisterIMInstantiateCallback(x11_display, NULL, NULL, NULL, xim_instantiate_cb, NULL); } static void xim_destroy_cb( XIM im UNUSED, XPointer client_data UNUSED, XPointer call_data UNUSED) { Window x11_window; Display *x11_display; # ifdef XIM_DEBUG xim_log("xim_destroy_cb()\n"); #endif gui_get_x11_windis(&x11_window, &x11_display); xic = NULL; status_area_enabled = FALSE; gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); XRegisterIMInstantiateCallback(x11_display, NULL, NULL, NULL, xim_instantiate_cb, NULL); } # endif void xim_init(void) { Window x11_window; Display *x11_display; # ifdef XIM_DEBUG xim_log("xim_init()\n"); # endif gui_get_x11_windis(&x11_window, &x11_display); xic = NULL; if (xim_real_init(x11_window, x11_display)) return; gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); # ifdef USE_X11R6_XIM XRegisterIMInstantiateCallback(x11_display, NULL, NULL, NULL, xim_instantiate_cb, NULL); # endif } static int xim_real_init(Window x11_window, Display *x11_display) { int i; char *p, *s, *ns, *end, tmp[1024]; # define IMLEN_MAX 40 char buf[IMLEN_MAX + 7]; XIM xim = NULL; XIMStyles *xim_styles; XIMStyle this_input_style = 0; Boolean found; XPoint over_spot; XVaNestedList preedit_list, status_list; input_style = 0; status_area_enabled = FALSE; if (xic != NULL) return FALSE; if (gui.rsrc_input_method != NULL && *gui.rsrc_input_method != NUL) { strcpy(tmp, gui.rsrc_input_method); for (ns = s = tmp; ns != NULL && *s != NUL;) { s = (char *)skipwhite((char_u *)s); if (*s == NUL) break; if ((ns = end = strchr(s, ',')) == NULL) end = s + strlen(s); while (isspace(((char_u *)end)[-1])) end--; *end = NUL; if (strlen(s) <= IMLEN_MAX) { strcpy(buf, "@im="); strcat(buf, s); if ((p = XSetLocaleModifiers(buf)) != NULL && *p != NUL && (xim = XOpenIM(x11_display, NULL, NULL, NULL)) != NULL) break; } s = ns + 1; } } if (xim == NULL && (p = XSetLocaleModifiers("")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); /* This is supposed to be useful to obtain characters through * XmbLookupString() without really using a XIM. */ if (xim == NULL && (p = XSetLocaleModifiers("@im=none")) != NULL && *p != NUL) xim = XOpenIM(x11_display, NULL, NULL, NULL); if (xim == NULL) { /* Only give this message when verbose is set, because too many people * got this message when they didn't want to use a XIM. */ if (p_verbose > 0) { verbose_enter(); EMSG(_("E286: Failed to open input method")); verbose_leave(); } return FALSE; } # ifdef USE_X11R6_XIM { XIMCallback destroy_cb; destroy_cb.callback = xim_destroy_cb; destroy_cb.client_data = NULL; if (XSetIMValues(xim, XNDestroyCallback, &destroy_cb, NULL)) EMSG(_("E287: Warning: Could not set destroy callback to IM")); } # endif if (XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles) { EMSG(_("E288: input method doesn't support any style")); XCloseIM(xim); return FALSE; } found = False; strcpy(tmp, gui.rsrc_preedit_type_name); for (s = tmp; s && !found; ) { while (*s && isspace((unsigned char)*s)) s++; if (!*s) break; if ((ns = end = strchr(s, ',')) != 0) ns++; else end = s + strlen(s); while (isspace((unsigned char)*end)) end--; *end = '\0'; if (!strcmp(s, "OverTheSpot")) this_input_style = (XIMPreeditPosition | XIMStatusArea); else if (!strcmp(s, "OffTheSpot")) this_input_style = (XIMPreeditArea | XIMStatusArea); else if (!strcmp(s, "Root")) this_input_style = (XIMPreeditNothing | XIMStatusNothing); for (i = 0; (unsigned short)i < xim_styles->count_styles; i++) { if (this_input_style == xim_styles->supported_styles[i]) { found = True; break; } } if (!found) for (i = 0; (unsigned short)i < xim_styles->count_styles; i++) { if ((xim_styles->supported_styles[i] & this_input_style) == (this_input_style & ~XIMStatusArea)) { this_input_style &= ~XIMStatusArea; found = True; break; } } s = ns; } XFree(xim_styles); if (!found) { /* Only give this message when verbose is set, because too many people * got this message when they didn't want to use a XIM. */ if (p_verbose > 0) { verbose_enter(); EMSG(_("E289: input method doesn't support my preedit type")); verbose_leave(); } XCloseIM(xim); return FALSE; } over_spot.x = TEXT_X(gui.col); over_spot.y = TEXT_Y(gui.row); input_style = this_input_style; /* A crash was reported when trying to pass gui.norm_font as XNFontSet, * thus that has been removed. Hopefully the default works... */ # ifdef FEAT_XFONTSET if (gui.fontset != NOFONTSET) { preedit_list = XVaCreateNestedList(0, XNSpotLocation, &over_spot, XNForeground, (Pixel)gui.def_norm_pixel, XNBackground, (Pixel)gui.def_back_pixel, XNFontSet, (XFontSet)gui.fontset, NULL); status_list = XVaCreateNestedList(0, XNForeground, (Pixel)gui.def_norm_pixel, XNBackground, (Pixel)gui.def_back_pixel, XNFontSet, (XFontSet)gui.fontset, NULL); } else # endif { preedit_list = XVaCreateNestedList(0, XNSpotLocation, &over_spot, XNForeground, (Pixel)gui.def_norm_pixel, XNBackground, (Pixel)gui.def_back_pixel, NULL); status_list = XVaCreateNestedList(0, XNForeground, (Pixel)gui.def_norm_pixel, XNBackground, (Pixel)gui.def_back_pixel, NULL); } xic = XCreateIC(xim, XNInputStyle, input_style, XNClientWindow, x11_window, XNFocusWindow, gui.wid, XNPreeditAttributes, preedit_list, XNStatusAttributes, status_list, NULL); XFree(status_list); XFree(preedit_list); if (xic != NULL) { if (input_style & XIMStatusArea) { xim_set_status_area(); status_area_enabled = TRUE; } else gui_set_shellsize(FALSE, FALSE, RESIZE_BOTH); } else { if (!is_not_a_term()) EMSG(_(e_xim)); XCloseIM(xim); return FALSE; } return TRUE; } # endif /* FEAT_GUI_X11 */ /* * Get IM status. When IM is on, return TRUE. Else return FALSE. * FIXME: This doesn't work correctly: Having focus doesn't always mean XIM is * active, when not having focus XIM may still be active (e.g., when using a * tear-off menu item). */ int im_get_status(void) { # ifdef FEAT_EVAL if (USE_IMSTATUSFUNC) return call_imstatusfunc(); # endif return xim_has_focus; } # endif /* !FEAT_GUI_GTK */ # if !defined(FEAT_GUI_GTK) || defined(PROTO) /* * Set up the status area. * * This should use a separate Widget, but that seems not possible, because * preedit_area and status_area should be set to the same window as for the * text input. Unfortunately this means the status area pollutes the text * window... */ void xim_set_status_area(void) { XVaNestedList preedit_list = 0, status_list = 0, list = 0; XRectangle pre_area, status_area; if (xic == NULL) return; if (input_style & XIMStatusArea) { if (input_style & XIMPreeditArea) { XRectangle *needed_rect; /* to get status_area width */ status_list = XVaCreateNestedList(0, XNAreaNeeded, &needed_rect, NULL); XGetICValues(xic, XNStatusAttributes, status_list, NULL); XFree(status_list); status_area.width = needed_rect->width; } else status_area.width = gui.char_width * Columns; status_area.x = 0; status_area.y = gui.char_height * Rows + gui.border_offset; if (gui.which_scrollbars[SBAR_BOTTOM]) status_area.y += gui.scrollbar_height; #ifdef FEAT_MENU if (gui.menu_is_active) status_area.y += gui.menu_height; #endif status_area.height = gui.char_height; status_list = XVaCreateNestedList(0, XNArea, &status_area, NULL); } else { status_area.x = 0; status_area.y = gui.char_height * Rows + gui.border_offset; if (gui.which_scrollbars[SBAR_BOTTOM]) status_area.y += gui.scrollbar_height; #ifdef FEAT_MENU if (gui.menu_is_active) status_area.y += gui.menu_height; #endif status_area.width = 0; status_area.height = gui.char_height; } if (input_style & XIMPreeditArea) /* off-the-spot */ { pre_area.x = status_area.x + status_area.width; pre_area.y = gui.char_height * Rows + gui.border_offset; pre_area.width = gui.char_width * Columns - pre_area.x; if (gui.which_scrollbars[SBAR_BOTTOM]) pre_area.y += gui.scrollbar_height; #ifdef FEAT_MENU if (gui.menu_is_active) pre_area.y += gui.menu_height; #endif pre_area.height = gui.char_height; preedit_list = XVaCreateNestedList(0, XNArea, &pre_area, NULL); } else if (input_style & XIMPreeditPosition) /* over-the-spot */ { pre_area.x = 0; pre_area.y = 0; pre_area.height = gui.char_height * Rows; pre_area.width = gui.char_width * Columns; preedit_list = XVaCreateNestedList(0, XNArea, &pre_area, NULL); } if (preedit_list && status_list) list = XVaCreateNestedList(0, XNPreeditAttributes, preedit_list, XNStatusAttributes, status_list, NULL); else if (preedit_list) list = XVaCreateNestedList(0, XNPreeditAttributes, preedit_list, NULL); else if (status_list) list = XVaCreateNestedList(0, XNStatusAttributes, status_list, NULL); else list = NULL; if (list) { XSetICValues(xic, XNVaNestedList, list, NULL); XFree(list); } if (status_list) XFree(status_list); if (preedit_list) XFree(preedit_list); } int xim_get_status_area_height(void) { if (status_area_enabled) return gui.char_height; return 0; } # endif #else /* !defined(FEAT_XIM) */ # if !defined(FEAT_GUI_W32) || !(defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)) static int im_was_set_active = FALSE; int im_get_status() { # if defined(FEAT_MBYTE) && defined(FEAT_EVAL) if (USE_IMSTATUSFUNC) return call_imstatusfunc(); # endif return im_was_set_active; } void im_set_active(int active_arg) { # if defined(FEAT_MBYTE) && defined(FEAT_EVAL) int active = !p_imdisable && active_arg; if (USE_IMACTIVATEFUNC && active != im_get_status()) { call_imactivatefunc(active); im_was_set_active = active; } # endif } # ifdef FEAT_GUI void im_set_position(int row, int col) { } # endif # endif #endif /* FEAT_XIM */ #if defined(FEAT_MBYTE) || defined(PROTO) /* * Setup "vcp" for conversion from "from" to "to". * The names must have been made canonical with enc_canonize(). * vcp->vc_type must have been initialized to CONV_NONE. * Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8 * instead). * Afterwards invoke with "from" and "to" equal to NULL to cleanup. * Return FAIL when conversion is not supported, OK otherwise. */ int convert_setup(vimconv_T *vcp, char_u *from, char_u *to) { return convert_setup_ext(vcp, from, TRUE, to, TRUE); } /* * As convert_setup(), but only when from_unicode_is_utf8 is TRUE will all * "from" unicode charsets be considered utf-8. Same for "to". */ int convert_setup_ext( vimconv_T *vcp, char_u *from, int from_unicode_is_utf8, char_u *to, int to_unicode_is_utf8) { int from_prop; int to_prop; int from_is_utf8; int to_is_utf8; /* Reset to no conversion. */ # ifdef USE_ICONV if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) iconv_close(vcp->vc_fd); # endif vcp->vc_type = CONV_NONE; vcp->vc_factor = 1; vcp->vc_fail = FALSE; /* No conversion when one of the names is empty or they are equal. */ if (from == NULL || *from == NUL || to == NULL || *to == NUL || STRCMP(from, to) == 0) return OK; from_prop = enc_canon_props(from); to_prop = enc_canon_props(to); if (from_unicode_is_utf8) from_is_utf8 = from_prop & ENC_UNICODE; else from_is_utf8 = from_prop == ENC_UNICODE; if (to_unicode_is_utf8) to_is_utf8 = to_prop & ENC_UNICODE; else to_is_utf8 = to_prop == ENC_UNICODE; if ((from_prop & ENC_LATIN1) && to_is_utf8) { /* Internal latin1 -> utf-8 conversion. */ vcp->vc_type = CONV_TO_UTF8; vcp->vc_factor = 2; /* up to twice as long */ } else if ((from_prop & ENC_LATIN9) && to_is_utf8) { /* Internal latin9 -> utf-8 conversion. */ vcp->vc_type = CONV_9_TO_UTF8; vcp->vc_factor = 3; /* up to three as long (euro sign) */ } else if (from_is_utf8 && (to_prop & ENC_LATIN1)) { /* Internal utf-8 -> latin1 conversion. */ vcp->vc_type = CONV_TO_LATIN1; } else if (from_is_utf8 && (to_prop & ENC_LATIN9)) { /* Internal utf-8 -> latin9 conversion. */ vcp->vc_type = CONV_TO_LATIN9; } #ifdef WIN3264 /* Win32-specific codepage <-> codepage conversion without iconv. */ else if ((from_is_utf8 || encname2codepage(from) > 0) && (to_is_utf8 || encname2codepage(to) > 0)) { vcp->vc_type = CONV_CODEPAGE; vcp->vc_factor = 2; /* up to twice as long */ vcp->vc_cpfrom = from_is_utf8 ? 0 : encname2codepage(from); vcp->vc_cpto = to_is_utf8 ? 0 : encname2codepage(to); } #endif #ifdef MACOS_CONVERT else if ((from_prop & ENC_MACROMAN) && (to_prop & ENC_LATIN1)) { vcp->vc_type = CONV_MAC_LATIN1; } else if ((from_prop & ENC_MACROMAN) && to_is_utf8) { vcp->vc_type = CONV_MAC_UTF8; vcp->vc_factor = 2; /* up to twice as long */ } else if ((from_prop & ENC_LATIN1) && (to_prop & ENC_MACROMAN)) { vcp->vc_type = CONV_LATIN1_MAC; } else if (from_is_utf8 && (to_prop & ENC_MACROMAN)) { vcp->vc_type = CONV_UTF8_MAC; } #endif # ifdef USE_ICONV else { /* Use iconv() for conversion. */ vcp->vc_fd = (iconv_t)my_iconv_open( to_is_utf8 ? (char_u *)"utf-8" : to, from_is_utf8 ? (char_u *)"utf-8" : from); if (vcp->vc_fd != (iconv_t)-1) { vcp->vc_type = CONV_ICONV; vcp->vc_factor = 4; /* could be longer too... */ } } # endif if (vcp->vc_type == CONV_NONE) return FAIL; return OK; } #if defined(FEAT_GUI) || defined(AMIGA) || defined(WIN3264) \ || defined(PROTO) /* * Do conversion on typed input characters in-place. * The input and output are not NUL terminated! * Returns the length after conversion. */ int convert_input(char_u *ptr, int len, int maxlen) { return convert_input_safe(ptr, len, maxlen, NULL, NULL); } #endif /* * Like convert_input(), but when there is an incomplete byte sequence at the * end return that as an allocated string in "restp" and set "*restlenp" to * the length. If "restp" is NULL it is not used. */ int convert_input_safe( char_u *ptr, int len, int maxlen, char_u **restp, int *restlenp) { char_u *d; int dlen = len; int unconvertlen = 0; d = string_convert_ext(&input_conv, ptr, &dlen, restp == NULL ? NULL : &unconvertlen); if (d != NULL) { if (dlen <= maxlen) { if (unconvertlen > 0) { /* Move the unconverted characters to allocated memory. */ *restp = alloc(unconvertlen); if (*restp != NULL) mch_memmove(*restp, ptr + len - unconvertlen, unconvertlen); *restlenp = unconvertlen; } mch_memmove(ptr, d, dlen); } else /* result is too long, keep the unconverted text (the caller must * have done something wrong!) */ dlen = len; vim_free(d); } return dlen; } /* * Convert text "ptr[*lenp]" according to "vcp". * Returns the result in allocated memory and sets "*lenp". * When "lenp" is NULL, use NUL terminated strings. * Illegal chars are often changed to "?", unless vcp->vc_fail is set. * When something goes wrong, NULL is returned and "*lenp" is unchanged. */ char_u * string_convert( vimconv_T *vcp, char_u *ptr, int *lenp) { return string_convert_ext(vcp, ptr, lenp, NULL); } /* * Like string_convert(), but when "unconvlenp" is not NULL and there are is * an incomplete sequence at the end it is not converted and "*unconvlenp" is * set to the number of remaining bytes. */ char_u * string_convert_ext( vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvlenp) { char_u *retval = NULL; char_u *d; int len; int i; int l; int c; if (lenp == NULL) len = (int)STRLEN(ptr); else len = *lenp; if (len == 0) return vim_strsave((char_u *)""); switch (vcp->vc_type) { case CONV_TO_UTF8: /* latin1 to utf-8 conversion */ retval = alloc(len * 2 + 1); if (retval == NULL) break; d = retval; for (i = 0; i < len; ++i) { c = ptr[i]; if (c < 0x80) *d++ = c; else { *d++ = 0xc0 + ((unsigned)c >> 6); *d++ = 0x80 + (c & 0x3f); } } *d = NUL; if (lenp != NULL) *lenp = (int)(d - retval); break; case CONV_9_TO_UTF8: /* latin9 to utf-8 conversion */ retval = alloc(len * 3 + 1); if (retval == NULL) break; d = retval; for (i = 0; i < len; ++i) { c = ptr[i]; switch (c) { case 0xa4: c = 0x20ac; break; /* euro */ case 0xa6: c = 0x0160; break; /* S hat */ case 0xa8: c = 0x0161; break; /* S -hat */ case 0xb4: c = 0x017d; break; /* Z hat */ case 0xb8: c = 0x017e; break; /* Z -hat */ case 0xbc: c = 0x0152; break; /* OE */ case 0xbd: c = 0x0153; break; /* oe */ case 0xbe: c = 0x0178; break; /* Y */ } d += utf_char2bytes(c, d); } *d = NUL; if (lenp != NULL) *lenp = (int)(d - retval); break; case CONV_TO_LATIN1: /* utf-8 to latin1 conversion */ case CONV_TO_LATIN9: /* utf-8 to latin9 conversion */ retval = alloc(len + 1); if (retval == NULL) break; d = retval; for (i = 0; i < len; ++i) { l = utf_ptr2len_len(ptr + i, len - i); if (l == 0) *d++ = NUL; else if (l == 1) { int l_w = utf8len_tab_zero[ptr[i]]; if (l_w == 0) { /* Illegal utf-8 byte cannot be converted */ vim_free(retval); return NULL; } if (unconvlenp != NULL && l_w > len - i) { /* Incomplete sequence at the end. */ *unconvlenp = len - i; break; } *d++ = ptr[i]; } else { c = utf_ptr2char(ptr + i); if (vcp->vc_type == CONV_TO_LATIN9) switch (c) { case 0x20ac: c = 0xa4; break; /* euro */ case 0x0160: c = 0xa6; break; /* S hat */ case 0x0161: c = 0xa8; break; /* S -hat */ case 0x017d: c = 0xb4; break; /* Z hat */ case 0x017e: c = 0xb8; break; /* Z -hat */ case 0x0152: c = 0xbc; break; /* OE */ case 0x0153: c = 0xbd; break; /* oe */ case 0x0178: c = 0xbe; break; /* Y */ case 0xa4: case 0xa6: case 0xa8: case 0xb4: case 0xb8: case 0xbc: case 0xbd: case 0xbe: c = 0x100; break; /* not in latin9 */ } if (!utf_iscomposing(c)) /* skip composing chars */ { if (c < 0x100) *d++ = c; else if (vcp->vc_fail) { vim_free(retval); return NULL; } else { *d++ = 0xbf; if (utf_char2cells(c) > 1) *d++ = '?'; } } i += l - 1; } } *d = NUL; if (lenp != NULL) *lenp = (int)(d - retval); break; # ifdef MACOS_CONVERT case CONV_MAC_LATIN1: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, 'm', 'l', unconvlenp); break; case CONV_LATIN1_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, 'l', 'm', unconvlenp); break; case CONV_MAC_UTF8: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, 'm', 'u', unconvlenp); break; case CONV_UTF8_MAC: retval = mac_string_convert(ptr, len, lenp, vcp->vc_fail, 'u', 'm', unconvlenp); break; # endif # ifdef USE_ICONV case CONV_ICONV: /* conversion with output_conv.vc_fd */ retval = iconv_string(vcp, ptr, len, unconvlenp, lenp); break; # endif # ifdef WIN3264 case CONV_CODEPAGE: /* codepage -> codepage */ { int retlen; int tmp_len; short_u *tmp; /* 1. codepage/UTF-8 -> ucs-2. */ if (vcp->vc_cpfrom == 0) tmp_len = utf8_to_utf16(ptr, len, NULL, NULL); else { tmp_len = MultiByteToWideChar(vcp->vc_cpfrom, unconvlenp ? MB_ERR_INVALID_CHARS : 0, (char *)ptr, len, 0, 0); if (tmp_len == 0 && GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { if (lenp != NULL) *lenp = 0; if (unconvlenp != NULL) *unconvlenp = len; retval = alloc(1); if (retval) retval[0] = NUL; return retval; } } tmp = (short_u *)alloc(sizeof(short_u) * tmp_len); if (tmp == NULL) break; if (vcp->vc_cpfrom == 0) utf8_to_utf16(ptr, len, tmp, unconvlenp); else MultiByteToWideChar(vcp->vc_cpfrom, 0, (char *)ptr, len, tmp, tmp_len); /* 2. ucs-2 -> codepage/UTF-8. */ if (vcp->vc_cpto == 0) retlen = utf16_to_utf8(tmp, tmp_len, NULL); else retlen = WideCharToMultiByte(vcp->vc_cpto, 0, tmp, tmp_len, 0, 0, 0, 0); retval = alloc(retlen + 1); if (retval != NULL) { if (vcp->vc_cpto == 0) utf16_to_utf8(tmp, tmp_len, retval); else WideCharToMultiByte(vcp->vc_cpto, 0, tmp, tmp_len, (char *)retval, retlen, 0, 0); retval[retlen] = NUL; if (lenp != NULL) *lenp = retlen; } vim_free(tmp); break; } # endif } return retval; } #endif
[ "Bram@vim.org" ]
Bram@vim.org
02f61a2026e2ce7d98998c99789eedebab67d13a
b9b17f3cbd8a1b6e7aee4f217b8de15a4c89b4ae
/my_web_socket/mibs/mib_common.c
ddeaa6cc12117946a056e73c2641214a4b3a357c
[]
no_license
spara7C5/STM32-WebSocketClient
c367a60e08094e18c42cd16444435e274cef61f2
92cfa1b1685ffec3ea933220fd279b672e7b9672
refs/heads/master
2020-06-12T08:26:52.526906
2019-06-28T09:49:01
2019-06-28T09:49:01
194,244,764
1
1
null
null
null
null
UTF-8
C
false
false
25,871
c
/** * @file mib_common.c * @brief Common definitions for MIB modules * * @section License * * SPDX-License-Identifier: GPL-2.0-or-later * * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved. * * This file is part of CycloneTCP Open. * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @author Oryx Embedded SARL (www.oryx-embedded.com) * @version 1.9.2 **/ //Dependencies #include "core/net.h" #include "mibs/mib_common.h" #include "encoding/oid.h" #include "debug.h" /** * @brief Encode instance identifier (index) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] index Index value * @return Error code **/ error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index) { //Encode instance identifier return oidEncodeSubIdentifier(oid, maxOidLen, pos, index); } /** * @brief Decode instance identifier (index) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] index Index value * @return Error code **/ error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos, uint_t *index) { error_t error; uint32_t value; //Decode instance identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Check status code if(!error) { //Save index value *index = (uint_t) value; } //Return status code return error; } /** * @brief Encode instance identifier (unsigned 32-bit integer) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] value Unsigned 32-bit integer * @return Error code **/ error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos, uint32_t value) { //Encode instance identifier return oidEncodeSubIdentifier(oid, maxOidLen, pos, value); } /** * @brief Decode instance identifier (unsigned 32-bit integer) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] value Unsigned 32-bit integer * @return Error code **/ error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos, uint32_t *value) { //Decode instance identifier return oidDecodeSubIdentifier(oid, oidLen, pos, value); } /** * @brief Encode instance identifier (string) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] string NULL-terminated string * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos, const char_t *string, bool_t implied) { //Encode string return mibEncodeOctetString(oid, maxOidLen, pos, (const uint8_t *) string, strlen(string), implied); } /** * @brief Decode instance identifier (string) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] string NULL-terminated string * @param[in] maxStringLen Maximum number of characters the string can hold * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos, char_t *string, size_t maxStringLen, bool_t implied) { error_t error; size_t stringLen; //Decode string error = mibDecodeOctetString(oid, oidLen, pos, (uint8_t *) string, maxStringLen, &stringLen, implied); //Check status code if(!error) { //Properly terminate the string with a NULL character string[stringLen] = '\0'; } //Return status code return error; } /** * @brief Encode instance identifier (octet string) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] data Pointer to the octet string * @param[in] dataLen Length of the octet string, in bytes * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos, const uint8_t *data, size_t dataLen, bool_t implied) { error_t error; uint_t i; //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Encode the length of the octet string error = oidEncodeSubIdentifier(oid, maxOidLen, pos, dataLen); //Any error to report? if(error) return error; } //Encode the octet string for(i = 0; i < dataLen; i++) { //Encode the current byte error = oidEncodeSubIdentifier(oid, maxOidLen, pos, data[i]); //Any error to report? if(error) return error; } //Successful processing return NO_ERROR; } /** * @brief Decode instance identifier (octet string) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] data Buffer where to store the octet string * @param[in] maxDataLen Maximum number of bytes the buffer can hold * @param[out] dataLen Length of the octet string, in bytes * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos, uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied) { error_t error; uint_t i; uint32_t n; uint32_t value; //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Decode the length of the octet string error = oidDecodeSubIdentifier(oid, oidLen, pos, &n); //Any error to report? if(error) return error; } //Decode the octet string for(i = 0; ; i++) { //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Check loop condition if(i >= n) break; } else { //Check loop condition if(*pos >= oidLen) break; } //Decode the current sub-identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //Each byte of the octet string must be in the range 0-255 if(value > UINT8_MAX) return ERROR_INSTANCE_NOT_FOUND; //Ensure the output buffer is large enough to hold of the octet string if(i >= maxDataLen) return ERROR_INSTANCE_NOT_FOUND; //Save the current byte data[i] = (uint8_t) value; } //Return the length of the octet string *dataLen = i; //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (object identifier) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] objectId Object identifier to be encoded * @param[in] objectIdLen Length of the object identifier, in bytes * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos, const uint8_t *objectId, size_t objectIdLen, bool_t implied) { error_t error; uint32_t n; uint32_t value; size_t objectIdPos; //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Check the length of the object identifier if(objectIdLen > 0) { //Calculate the number of sub-identifiers in the value for(n = 2, objectIdPos = 1; objectIdPos < objectIdLen; n++) { //Decode the current sub-identifier error = oidDecodeSubIdentifier(objectId, objectIdLen, &objectIdPos, &value); //Invalid sub-identifier? if(error) return error; } } else { n = 0; } //Encode the number of sub-identifiers in the value error = oidEncodeSubIdentifier(oid, maxOidLen, pos, n); //Any error to report? if(error) return error; } //Check the length of the object identifier if(objectIdLen > 0) { //Encode the first sub-identifier error = oidEncodeSubIdentifier(oid, maxOidLen, pos, objectId[0] / 40); //Any error to report? if(error) return error; //Encode the second sub-identifier error = oidEncodeSubIdentifier(oid, maxOidLen, pos, objectId[0] % 40); //Any error to report? if(error) return error; //Sanity check if((*pos + objectIdLen - 1) > maxOidLen) return ERROR_BUFFER_OVERFLOW; //Encode the rest of the object identifier memcpy(oid + *pos, objectId + 1, objectIdLen - 1); //Update offset value *pos += objectIdLen - 1; } //Successful processing return NO_ERROR; } /** * @brief Decode instance identifier (object identifier) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] objectId Buffer where to store the object identifier * @param[in] maxObjectIdLen Maximum number of bytes the buffer can hold * @param[out] objectIdLen Length of the object identifier, in bytes * @param[in] implied Specifies whether the index is preceded by the IMPLIED keyword * @return Error code **/ error_t mibDecodeObjectIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos, uint8_t *objectId, size_t maxObjectIdLen, size_t *objectIdLen, bool_t implied) { error_t error; uint32_t i; uint32_t n; uint32_t value; //Length of the object identifier, in bytes *objectIdLen = 0; //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Decode the number of sub-identifiers in the value error = oidDecodeSubIdentifier(oid, oidLen, pos, &n); //Invalid sub-identifier? if(error) return error; } //Decode object identifier for(i = 0; ; i++) { //Check whether the index is preceded by the IMPLIED keyword if(!implied) { //Check loop condition if(i >= n) break; } else { //Check loop condition if(*pos >= oidLen) break; } //Decode the current sub-identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //First node? if(i == 0) { //Check the value of the first sub-identifier if(value > 6) return ERROR_INVALID_SYNTAX; //Check the length of the output buffer if(maxObjectIdLen == 0) return ERROR_BUFFER_OVERFLOW; //Encode the first sub-identifier objectId[0] = value * 40; //Prepare to decode the next node *objectIdLen = 1; } //Second node? else if(i == 1) { //Check the value of the second sub-identifier if(value > 39) return ERROR_INVALID_SYNTAX; //Check the length of the output buffer if(maxObjectIdLen == 0) return ERROR_BUFFER_OVERFLOW; //Encode the second sub-identifier objectId[0] |= value; //Prepare to decode the next node *objectIdLen = 1; } else { //Encode the current sub-identifier error = oidEncodeSubIdentifier(objectId, maxObjectIdLen, objectIdLen, value); //Invalid sub-identifier? if(error) return error; } } //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (port number) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] port Port number * @return Error code **/ error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos, uint16_t port) { //Encode instance identifier return oidEncodeSubIdentifier(oid, maxOidLen, pos, port); } /** * @brief Decode instance identifier (port number) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] port Port number * @return Error code **/ error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos, uint16_t *port) { error_t error; uint32_t value; //Decode instance identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //Port number must be in range 0-65535 if(value > 65535) return ERROR_INSTANCE_NOT_FOUND; //Save port number *port = value; //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (MAC address) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] macAddr MAC address * @return Error code **/ error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const MacAddr *macAddr) { error_t error; uint_t i; //Encode the length of the octet string error = oidEncodeSubIdentifier(oid, maxOidLen, pos, sizeof(MacAddr)); //Any error to report? if(error) return error; //The address is encoded as 6 subsequent sub-identifiers for(i = 0; i < sizeof(MacAddr); i++) { //Encode the current byte error = oidEncodeSubIdentifier(oid, maxOidLen, pos, macAddr->b[i]); //Any error to report? if(error) return error; } //Successful processing return NO_ERROR; } /** * @brief Decode instance identifier (MAC address) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] macAddr MAC address * @return Error code **/ error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos, MacAddr *macAddr) { error_t error; uint_t i; uint32_t length; uint32_t value; //Decode the length of the octet string error = oidDecodeSubIdentifier(oid, oidLen, pos, &length); //Any error to report? if(error) return error; //Make sure the length of the octet string is valid if(length != sizeof(MacAddr)) return ERROR_INSTANCE_NOT_FOUND; //The address is encoded as 6 subsequent sub-identifiers for(i = 0; i < sizeof(MacAddr); i++) { //Decode the current sub-identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //Each byte of the MAC address must be in the range 0-255 if(value > 255) return ERROR_INSTANCE_NOT_FOUND; //Save the current byte macAddr->b[i] = value & 0xFF; } //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (IPv4 address) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] ipAddr IPv4 address * @return Error code **/ error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, Ipv4Addr ipAddr) { error_t error; uint_t i; uint8_t *p; //Cast the IPv4 address as a byte array p = (uint8_t *) &ipAddr; //The address is encoded as 4 subsequent sub-identifiers for(i = 0; i < sizeof(Ipv4Addr); i++) { //Encode the current byte error = oidEncodeSubIdentifier(oid, maxOidLen, pos, p[i]); //Any error to report? if(error) return error; } //Successful processing return NO_ERROR; } /** * @brief Decode instance identifier (IPv4 address) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] ipAddr IPv4 address * @return Error code **/ error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv4Addr *ipAddr) { error_t error; uint_t i; uint32_t value; uint8_t *p; //Cast the IPv4 address as a byte array p = (uint8_t *) ipAddr; //The address is encoded as 4 subsequent sub-identifiers for(i = 0; i < sizeof(Ipv4Addr); i++) { //Decode the current sub-identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //Each byte of the IPv4 address must be in the range 0-255 if(value > 255) return ERROR_INSTANCE_NOT_FOUND; //Save the current byte p[i] = value & 0xFF; } //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (IPv6 address) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] ipAddr IPv6 address * @return Error code **/ error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, const Ipv6Addr *ipAddr) { error_t error; uint_t i; //The address is encoded as 16 subsequent sub-identifiers for(i = 0; i < sizeof(Ipv6Addr); i++) { //Encode the current byte error = oidEncodeSubIdentifier(oid, maxOidLen, pos, ipAddr->b[i]); //Any error to report? if(error) return error; } //Successful processing return NO_ERROR; } /** * @brief Decode instance identifier (IPv6 address) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] ipAddr IPv6 address * @return Error code **/ error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv6Addr *ipAddr) { error_t error; uint_t i; uint32_t value; //The address is encoded as 16 subsequent sub-identifiers for(i = 0; i < sizeof(Ipv6Addr); i++) { //Decode the current sub-identifier error = oidDecodeSubIdentifier(oid, oidLen, pos, &value); //Invalid sub-identifier? if(error) return error; //Each byte of the IPv6 address must be in the range 0-255 if(value > 255) return ERROR_INSTANCE_NOT_FOUND; //Save the current byte ipAddr->b[i] = value & 0xFF; } //Successful processing return NO_ERROR; } /** * @brief Encode instance identifier (IP address) * @param[in] oid Pointer to the object identifier * @param[in] maxOidLen Maximum number of bytes the OID can hold * @param[in,out] pos Offset where to write the instance identifier * @param[in] ipAddr IP address * @return Error code **/ error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const IpAddr *ipAddr) { error_t error; #if (IPV4_SUPPORT == ENABLED) //IPv4 address? if(ipAddr->length == sizeof(Ipv4Addr)) { //Encode address type (IPv4) error = oidEncodeSubIdentifier(oid, maxOidLen, pos, INET_ADDR_TYPE_IPV4); //Check status code if(!error) { //Encode the length of the octet string error = oidEncodeSubIdentifier(oid, maxOidLen, pos, sizeof(Ipv4Addr)); } //Check status code if(!error) { //Encode IPv4 address error = mibEncodeIpv4Addr(oid, maxOidLen, pos, ipAddr->ipv4Addr); } } else #endif #if (IPV6_SUPPORT == ENABLED) //IPv6 address? if(ipAddr->length == sizeof(Ipv6Addr)) { //Encode address type (IPv6) error = oidEncodeSubIdentifier(oid, maxOidLen, pos, INET_ADDR_TYPE_IPV6); //Check status code if(!error) { //Encode the length of the octet string error = oidEncodeSubIdentifier(oid, maxOidLen, pos, sizeof(Ipv6Addr)); } //Check status code if(!error) { //Encode IPv6 address error = mibEncodeIpv6Addr(oid, maxOidLen, pos, &ipAddr->ipv6Addr); } } else #endif //Unknown address? { //Encode address type (unknown) error = oidEncodeSubIdentifier(oid, maxOidLen, pos, INET_ADDR_TYPE_UNKNOWN); //Check status code if(!error) { //The unknown address is a zero-length octet string error = oidEncodeSubIdentifier(oid, maxOidLen, pos, 0); } } //Return status code return error; } /** * @brief Decode instance identifier (IP address) * @param[in] oid Pointer to the object identifier * @param[in] oidLen Length of the OID, in bytes * @param[in,out] pos Offset where to read the instance identifier * @param[out] ipAddr IP address * @return Error code **/ error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos, IpAddr *ipAddr) { error_t error; uint32_t type; uint32_t length; //Decode address type error = oidDecodeSubIdentifier(oid, oidLen, pos, &type); //Check status code if(!error) { //Decode the length of the octet string error = oidDecodeSubIdentifier(oid, oidLen, pos, &length); } //Check status code if(!error) { //Unknown address? if(type == INET_ADDR_TYPE_UNKNOWN && length == 0) { //The unknown address is a zero-length octet string *ipAddr = IP_ADDR_ANY; } #if (IPV4_SUPPORT == ENABLED) //IPv4 address? else if(type == INET_ADDR_TYPE_IPV4 && length == sizeof(Ipv4Addr)) { //Save the length of the address ipAddr->length = sizeof(Ipv4Addr); //Decode IPv4 address error = mibDecodeIpv4Addr(oid, oidLen, pos, &ipAddr->ipv4Addr); } #endif #if (IPV6_SUPPORT == ENABLED) //IPv6 address? else if(type == INET_ADDR_TYPE_IPV6 && length == sizeof(Ipv6Addr)) { //Save the length of the address ipAddr->length = sizeof(Ipv6Addr); //Decode IPv6 address error = mibDecodeIpv6Addr(oid, oidLen, pos, &ipAddr->ipv6Addr); } #endif //Invalid address? else { //Report an error error = ERROR_INSTANCE_NOT_FOUND; } } //Return status code return error; } /** * @brief Compare IP addresses * @param[in] ipAddr1 First IP address * @param[in] ipAddr2 Second IP address * @return Comparison result **/ int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2) { int_t res; //Compare length fields if(ipAddr1->length < ipAddr2->length) { res = -1; } else if(ipAddr1->length > ipAddr2->length) { res = 1; } else if(ipAddr1->length == 0) { res = 0; } else { //Compare IP addresses res = memcmp((uint8_t *) ipAddr1 + sizeof(size_t), (uint8_t *) ipAddr2 + sizeof(size_t), ipAddr1->length); } //Return comparison result return res; } /** * @brief Test and increment spin lock * @param[in,out] spinLock Pointer to the spin lock * @param[in] value New value supplied via the management protocol * @param[in] commit This flag indicates the current phase (validation phase * or write phase if the validation was successful) * @return Comparison result **/ error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit) { error_t error; //The new value supplied via the management protocol must precisely match //the value presently held by the instance if(value == *spinLock) { //Write phase? if(commit) { //The value held by the instance is incremented by one (*spinLock)++; //if the current value is the maximum value of 2^31-1, then the value //held by the instance is wrapped to zero if(*spinLock < 0) *spinLock = 0; } //Successful operation error = NO_ERROR; } else { //The management protocol set operation fails with an error of //inconsistentValue error = ERROR_INCONSISTENT_VALUE; } //Return status code return error; }
[ "paracchino@hotmail.it" ]
paracchino@hotmail.it
c3effd61690648ec14e16aaa8b6b4e52bf4b970e
c7792b5e5ae5e74d643518a5b0644020288fc6da
/mutants/fuzzgoat.mutant.1304.c
866987e3d6f6011043366a2930545800139a1486
[ "BSD-2-Clause" ]
permissive
agroce/fuzzgoattriage
0dc99daf2d061aaa0f58ceef3657b6f9ff411613
173c585cc7e87bcb2b82ae22fde56935352cd597
refs/heads/master
2020-07-29T14:49:39.691056
2019-09-20T18:07:19
2019-09-20T18:07:19
209,830,892
0
0
null
null
null
null
UTF-8
C
false
false
32,159
c
/* vim: set et ts=3 sw=3 sts=3 ft=c: * * Copyright (C) 2012, 2013, 2014 James McLaughlin et al. All rights reserved. * https://github.com/udp/json-parser * * 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 AUTHOR 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 AUTHOR 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) * HOWCAUSED EVER 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 "fuzzgoat.h" #ifdef _MSC_VER #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif #endif const struct _json_value json_value_none; #include <stdio.h> #include <string.h> #include <ctype.h> #include <math.h> typedef unsigned int json_uchar; static unsigned char hex_value (json_char c) { if (isdigit(c)) return c - '0'; switch (c) { case 'a': case 'A': return 0x0A; case 'b': case 'B': return 0x0B; case 'c': case 'C': return 0x0C; case 'd': case 'D': return 0x0D; case 'e': case 'E': return 0x0E; case 'f': case 'F': return 0x0F; default: return 0xFF; } } typedef struct { unsigned long used_memory; unsigned int uint_max; unsigned long ulong_max; json_settings settings; int first_pass; const json_char * ptr; unsigned int cur_line, cur_col; } json_state; static void * default_alloc (size_t size, int zero, void * user_data) { return zero ? calloc (1, size) : malloc (size); } static void default_free (void * ptr, void * user_data) { free (ptr); } static void * json_alloc (json_state * state, unsigned long size, int zero) { if ((state->ulong_max - state->used_memory) < size) return 0; if (state->settings.max_memory && (state->used_memory += size) > state->settings.max_memory) { return 0; } return state->settings.mem_alloc (size, zero, state->settings.user_data); } static int new_value (json_state * state, json_value ** top, json_value ** root, json_value ** alloc, json_type type) { json_value * value; int values_size; if (!state->first_pass) { value = *top = *alloc; *alloc = (*alloc)->_reserved.next_alloc; if (!*root) *root = value; switch (value->type) { case json_array: if (value->u.array.length == 0) { /****************************************************************************** WARNING: Fuzzgoat Vulnerability The line of code below frees the memory block referenced by *top if the length of a JSON array is 0. The program attempts to use that memory block later in the program. Diff - Added: free(*top); Payload - An empty JSON array: [] Input File - emptyArray Triggers - Use after free in json_value_free() ******************************************************************************/ free(*top); /****** END vulnerable code **************************************************/ break; } if (! (value->u.array.values = (json_value **) json_alloc (state, value->u.array.length * sizeof (json_value *), 0)) ) { return 0; } value->u.array.length = 0; break; case json_object: if (value->u.object.length == 0) break; values_size = sizeof (*value->u.object.values) * value->u.object.length; if (! (value->u.object.values = (json_object_entry *) json_alloc (state, values_size + ((unsigned long) value->u.object.values), 0)) ) { return 0; } value->_reserved.object_mem = (*(char **) &value->u.object.values) + values_size; value->u.object.length = 0; break; case json_string: if (! (value->u.string.ptr = (json_char *) json_alloc (state, (value->u.string.length + 1) * sizeof (json_char), 0)) ) { return 0; } value->u.string.length = 0; break; default: break; }; return 1; } if (! (value = (json_value *) json_alloc (state, sizeof (json_value) + state->settings.value_extra, 1))) { return 0; } if (!*root) *root = value; value->type = type; value->parent = *top; #ifdef JSON_TRACK_SOURCE value->line = state->cur_line; value->col = state->cur_col; #endif if (*alloc) (*alloc)->_reserved.next_alloc = value; *alloc = *top = value; return 1; } void json_value_free_ex (json_settings * settings, json_value * value) { json_value * cur_value; if (!value) return; value->parent = 0; while (value) { switch (value->type) { case json_array: if (!value->u.array.length) { settings->mem_free (value->u.array.values, settings->user_data); break; } value = value->u.array.values [-- value->u.array.length]; continue; case json_object: if (!value->u.object.length) { settings->mem_free (value->u.object.values, settings->user_data); break; } /****************************************************************************** WARNING: Fuzzgoat Vulnerability The line of code below incorrectly decrements the value of value->u.object.length, causing an invalid read when attempting to free the memory space in the if-statement above. Diff - [--value->u.object.length] --> [value->u.object.length--] Payload - Any valid JSON object : {"":0} Input File - validObject Triggers - Invalid free in the above if-statement ******************************************************************************/ value = value->u.object.values [value->u.object.length--].value; /****** END vulnerable code **************************************************/ continue; case json_string: /****************************************************************************** WARNING: Fuzzgoat Vulnerability The code below decrements the pointer to the JSON string if the string is empty. After decrementing, the program tries to call mem_free on the pointer, which no longer references the JSON string. Diff - Added: if (!value->u.string.length) value->u.string.ptr--; Payload - An empty JSON string : "" Input File - emptyString Triggers - Invalid free on decremented value->u.string.ptr ******************************************************************************/ if (!value->u.string.length){ value->u.string.ptr--; } /****** END vulnerable code **************************************************/ /****************************************************************************** WARNING: Fuzzgoat Vulnerability The code below creates and dereferences a NULL pointer if the string is of length one. Diff - Check for one byte string - create and dereference a NULL pointer Payload - A JSON string of length one : "A" Input File - oneByteString Triggers - NULL pointer dereference ******************************************************************************/ if (value->u.string.length == 1) { char *null_pointer = NULL; printf ("%d", *null_pointer); } /****** END vulnerable code **************************************************/ settings->mem_free (value->u.string.ptr, settings->user_data); break; default: break; }; cur_value = value; value = value->parent; settings->mem_free (cur_value, settings->user_data); } } #define whitespace \ case '\n': ++ state.cur_line; state.cur_col = 0; \ case ' ': case '\t': case '\r' #define string_add(b) \ do { if (!state.first_pass) string [string_length] = b; ++ string_length; } while (0); #define line_and_col \ state.cur_line, state.cur_col static const long flag_next = 1 << 0, flag_reproc = 1 << 1, flag_need_comma = 1 << 2, flag_seek_value = 1 << 3, flag_escaped = 1 << 4, flag_string = 1 << 5, flag_need_colon = 1 << 6, flag_done = 1 << 7, flag_num_negative = 1 << 8, flag_num_zero = 1 << 9, flag_num_e = 1 << 10, flag_num_e_got_sign = 1 << 11, flag_num_e_negative = 1 << 12, flag_line_comment = 1 << 13, flag_block_comment = 1 << 14; json_value * json_parse_ex (json_settings * settings, const json_char * json, size_t length, char * error_buf) { json_char error [json_error_max]; const json_char * end; json_value * top, * root, * alloc = 0; json_state state = { 0 }; long flags; long num_digits = 0, num_e = 0; json_int_t num_fraction = 0; /* Skip UTF-8 BOM */ if (length >= 3 && ((unsigned char) json [0]) == 0xEF && ((unsigned char) json [1]) == 0xBB && ((unsigned char) json [2]) == 0xBF) { json += 3; length -= 3; } error[0] = '\0'; end = (json + length); memcpy (&state.settings, settings, sizeof (json_settings)); if (!state.settings.mem_alloc) state.settings.mem_alloc = default_alloc; if (!state.settings.mem_free) state.settings.mem_free = default_free; memset (&state.uint_max, 0xFF, sizeof (state.uint_max)); memset (&state.ulong_max, 0xFF, sizeof (state.ulong_max)); state.uint_max -= 8; /* limit of how much can be added before next check */ state.ulong_max -= 8; for (state.first_pass = 1; state.first_pass >= 0; -- state.first_pass) { json_uchar uchar; unsigned char uc_b1, uc_b2, uc_b3, uc_b4; json_char * string = 0; unsigned int string_length = 0; top = root = 0; flags = flag_seek_value; state.cur_line = 1; for (state.ptr = json ;; ++ state.ptr) { json_char b = (state.ptr == end ? 0 : *state.ptr); if (flags & flag_string) { if (!b) { sprintf (error, "Unexpected EOF in string (at %d:%d)", line_and_col); goto e_failed; } if (string_length > state.uint_max) goto e_overflow; if (flags & flag_escaped) { flags &= ~ flag_escaped; switch (b) { case 'b': string_add ('\b'); break; case 'f': string_add ('\f'); break; case 'n': string_add ('\n'); break; case 'r': string_add ('\r'); break; case 't': string_add ('\t'); break; case 'u': if (end - state.ptr < 4 || (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) { sprintf (error, "Invalid character value `%c` (at %d:%d)", b, line_and_col); goto e_failed; } uc_b1 = (uc_b1 << 4) | uc_b2; uc_b2 = (uc_b3 << 4) | uc_b4; uchar = (uc_b1 << 8) | uc_b2; if ((uchar & 0xF800) == 0xD800) { json_uchar uchar2; if (end - state.ptr < 6 || (*++ state.ptr) != '\\' || (*++ state.ptr) != 'u' || (uc_b1 = hex_value (*++ state.ptr)) == 0xFF || (uc_b2 = hex_value (*++ state.ptr)) == 0xFF || (uc_b3 = hex_value (*++ state.ptr)) == 0xFF || (uc_b4 = hex_value (*++ state.ptr)) == 0xFF) { sprintf (error, "Invalid character value `%c` (at %d:%d)", b, line_and_col); goto e_failed; } uc_b1 = (uc_b1 << 4) | uc_b2; uc_b2 = (uc_b3 << 4) | uc_b4; uchar2 = (uc_b1 << 8) | uc_b2; uchar = 0x010000 | ((uchar & 0x3FF) << 10) | (uchar2 & 0x3FF); } if (sizeof (json_char) >= sizeof (json_uchar) || (uchar <= 0x7F)) { string_add ((json_char) uchar); break; } if (uchar <= 0x7FF) { if (state.first_pass) string_length += 2; else { string [string_length ++] = 0xC0 | (uchar >> 6); string [string_length ++] = 0x80 | (uchar & 0x3F); } break; } if (uchar <= 0xFFFF) { if (state.first_pass) string_length += 3; else { string [string_length ++] = 0xE0 | (uchar >> 12); string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); string [string_length ++] = 0x80 | (uchar & 0x3F); } break; } if (state.first_pass) string_length += 4; else { string [string_length ++] = 0xF0 | (uchar >> 18); string [string_length ++] = 0x80 | ((uchar >> 12) & 0x3F); string [string_length ++] = 0x80 | ((uchar >> 6) & 0x3F); string [string_length ++] = 0x80 | (uchar & 0x3F); } break; default: string_add (b); }; continue; } if (b == '\\') { flags |= flag_escaped; continue; } if (b == '"') { if (!state.first_pass) string [string_length] = 0; flags &= ~ flag_string; string = 0; switch (top->type) { case json_string: top->u.string.length = string_length; flags |= flag_next; break; case json_object: if (state.first_pass) (*(json_char **) &top->u.object.values) += string_length + 1; else { top->u.object.values [top->u.object.length].name = (json_char *) top->_reserved.object_mem; top->u.object.values [top->u.object.length].name_length = string_length; (*(json_char **) &top->_reserved.object_mem) += string_length + 1; } flags |= flag_seek_value | flag_need_colon; continue; default: break; }; } else { string_add (b); continue; } } if (state.settings.settings & json_enable_comments) { if (flags & (flag_line_comment | flag_block_comment)) { if (flags & flag_line_comment) { if (b == '\r' || b == '\n' || !b) { flags &= ~ flag_line_comment; -- state.ptr; /* so null can be reproc'd */ } continue; } if (flags & flag_block_comment) { if (!b) { sprintf (error, "%d:%d: Unexpected EOF in block comment", line_and_col); goto e_failed; } if (b == '*' && state.ptr < (end - 1) && state.ptr [1] == '/') { flags &= ~ flag_block_comment; ++ state.ptr; /* skip closing sequence */ } continue; } } else if (b == '/') { if (! (flags & (flag_seek_value | flag_done)) && top->type != json_object) { sprintf (error, "%d:%d: Comment not allowed here", line_and_col); goto e_failed; } if (++ state.ptr == end) { sprintf (error, "%d:%d: EOF unexpected", line_and_col); goto e_failed; } switch (b = *state.ptr) { case '/': flags |= flag_line_comment; continue; case '*': flags |= flag_block_comment; continue; default: sprintf (error, "%d:%d: Unexpected `%c` in comment opening sequence", line_and_col, b); goto e_failed; }; } } if (flags & flag_done) { if (!b) break; switch (b) { whitespace: continue; default: sprintf (error, "%d:%d: Trailing garbage: `%c`", state.cur_line, state.cur_col, b); goto e_failed; }; } if (flags & flag_seek_value) { switch (b) { whitespace: continue; case ']': if (top && top->type == json_array) flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; else { sprintf (error, "%d:%d: Unexpected ]", line_and_col); goto e_failed; } break; default: if (flags & flag_need_comma) { if (b == ',') { flags &= ~ flag_need_comma; continue; } else { sprintf (error, "%d:%d: Expected , before %c", state.cur_line, state.cur_col, b); goto e_failed; } } if (flags & flag_need_colon) { if (b == ':') { flags &= ~ flag_need_colon; continue; } else { sprintf (error, "%d:%d: Expected : before %c", state.cur_line, state.cur_col, b); goto e_failed; } } flags &= ~ flag_seek_value; switch (b) { case '{': if (!new_value (&state, &top, &root, &alloc, json_object)) goto e_alloc_failure; continue; case '[': if (!new_value (&state, &top, &root, &alloc, json_array)) goto e_alloc_failure; flags |= flag_seek_value; continue; case '"': if (!new_value (&state, &top, &root, &alloc, json_string)) goto e_alloc_failure; flags |= flag_string; string = top->u.string.ptr; string_length = 0; continue; case 't': if ((end - state.ptr) < 3 || *(++ state.ptr) != 'r' || *(++ state.ptr) != 'u' || *(++ state.ptr) != 'e') { goto e_unknown_value; } if (!new_value (&state, &top, &root, &alloc, json_boolean)) goto e_alloc_failure; top->u.boolean = 1; flags |= flag_next; break; case 'f': if ((end - state.ptr) < 4 || *(++ state.ptr) != 'a' || *(++ state.ptr) != 'l' || *(++ state.ptr) != 's' || *(++ state.ptr) != 'e') { goto e_unknown_value; } if (!new_value (&state, &top, &root, &alloc, json_boolean)) goto e_alloc_failure; flags |= flag_next; break; case 'n': if ((end - state.ptr) < 3 || *(++ state.ptr) != 'u' || *(++ state.ptr) != 'l' || *(++ state.ptr) != 'l') { goto e_unknown_value; } if (!new_value (&state, &top, &root, &alloc, json_null)) goto e_alloc_failure; flags |= flag_next; break; default: if (isdigit (b) || b == '-') { if (!new_value (&state, &top, &root, &alloc, json_integer)) goto e_alloc_failure; if (!state.first_pass) { while (isdigit (b) || b == '+' || b == '-' || b == 'e' || b == 'E' || b == '.') { if ( (++ state.ptr) == end) { b = 0; break; } b = *state.ptr; } flags |= flag_next | flag_reproc; break; } flags &= ~ (flag_num_negative | flag_num_e | flag_num_e_got_sign | flag_num_e_negative | flag_num_zero); num_digits = 0; num_fraction = 0; num_e = 0; if (b != '-') { flags |= flag_reproc; break; } flags |= flag_num_negative; continue; } else { sprintf (error, "%d:%d: Unexpected %c when seeking value", line_and_col, b); goto e_failed; } }; }; } else { switch (top->type) { case json_object: switch (b) { whitespace: continue; case '"': if (flags & flag_need_comma) { sprintf (error, "%d:%d: Expected , before \"", line_and_col); goto e_failed; } flags |= flag_string; string = (json_char *) top->_reserved.object_mem; string_length = 0; break; case '}': flags = (flags & ~ flag_need_comma) | flag_next; break; case ',': if (flags & flag_need_comma) { flags &= ~ flag_need_comma; break; } default: sprintf (error, "%d:%d: Unexpected `%c` in object", line_and_col, b); goto e_failed; }; break; case json_integer: case json_double: if (isdigit (b)) { ++ num_digits; if (top->type == json_integer || flags & flag_num_e) { if (! (flags & flag_num_e)) { if (flags & flag_num_zero) { sprintf (error, "%d:%d: Unexpected `0` before `%c`", line_and_col, b); goto e_failed; } if (num_digits == 1 && b == '0') flags |= flag_num_zero; } else { flags |= flag_num_e_got_sign; num_e = (num_e * 10) + (b - '0'); continue; } top->u.integer = (top->u.integer * 10) + (b - '0'); continue; } num_fraction = (num_fraction * 10) + (b - '0'); continue; } if (b == '+' || b == '-') { if ( (flags & flag_num_e) && !(flags & flag_num_e_got_sign)) { flags |= flag_num_e_got_sign; if (b == '-') flags |= flag_num_e_negative; continue; } } else if (b == '.' && top->type == json_integer) { if (!num_digits) { sprintf (error, "%d:%d: Expected digit before `.`", line_and_col); goto e_failed; } top->type = json_double; top->u.dbl = (double) top->u.integer; num_digits = 0; continue; } if (! (flags & flag_num_e)) { if (top->type == json_double) { if (!num_digits) { sprintf (error, "%d:%d: Expected digit after `.`", line_and_col); goto e_failed; } top->u.dbl += ((double) num_fraction) / (pow (10.0, (double) num_digits)); } if (b == 'e' || b == 'E') { flags |= flag_num_e; if (top->type == json_integer) { top->type = json_double; top->u.dbl = (double) top->u.integer; } num_digits = 0; flags &= ~ flag_num_zero; continue; } } else { if (!num_digits) { sprintf (error, "%d:%d: Expected digit after `e`", line_and_col); goto e_failed; } top->u.dbl *= pow (10.0, (double) (flags & flag_num_e_negative ? - num_e : num_e)); } if (flags & flag_num_negative) { if (top->type == json_integer) top->u.integer = - top->u.integer; else top->u.dbl = - top->u.dbl; } flags |= flag_next | flag_reproc; break; default: break; }; } if (flags & flag_reproc) { flags &= ~ flag_reproc; -- state.ptr; } if (flags & flag_next) { flags = (flags & ~ flag_next) | flag_need_comma; if (!top->parent) { /* root value done */ flags |= flag_done; continue; } if (top->parent->type == json_array) flags |= flag_seek_value; if (!state.first_pass) { json_value * parent = top->parent; switch (parent->type) { case json_object: parent->u.object.values [parent->u.object.length].value = top; break; case json_array: parent->u.array.values [parent->u.array.length] = top; break; default: break; }; } if ( (++ top->parent->u.array.length) > state.uint_max) goto e_overflow; top = top->parent; continue; } } alloc = root; } return root; e_unknown_value: sprintf (error, "%d:%d: Unknown value", line_and_col); goto e_failed; e_alloc_failure: strcpy (error, "Memory allocation failure"); goto e_failed; e_overflow: sprintf (error, "%d:%d: Too long (caught overflow)", line_and_col); goto e_failed; e_failed: if (error_buf) { if (*error) strcpy (error_buf, error); else strcpy (error_buf, "Unknown error"); } if (state.first_pass) alloc = root; while (alloc) { top = alloc->_reserved.next_alloc; state.settings.mem_free (alloc, state.settings.user_data); alloc = top; } if (!state.first_pass) json_value_free_ex (&state.settings, root); return 0; } json_value * json_parse (const json_char * json, size_t length) { json_settings settings = { 0 }; return json_parse_ex (&settings, json, length, 0); } void json_value_free (json_value * value) { json_settings settings = { 0 }; settings.mem_free = default_free; json_value_free_ex (&settings, value); }
[ "agroce@gmail.com" ]
agroce@gmail.com
196bf70d910f9af03a76c5c287bc9b4b6dd26aaa
5c255f911786e984286b1f7a4e6091a68419d049
/code/bcbc3e25-2989-4237-912b-9415a2c3f727.c
85fbbb67846eeb9c725788491ec408e50b184bc2
[]
no_license
nmharmon8/Deep-Buffer-Overflow-Detection
70fe02c8dc75d12e91f5bc4468cf260e490af1a4
e0c86210c86afb07c8d4abcc957c7f1b252b4eb2
refs/heads/master
2021-09-11T19:09:59.944740
2018-04-06T16:26:34
2018-04-06T16:26:34
125,521,331
0
0
null
null
null
null
UTF-8
C
false
false
241
c
#include <stdio.h> int main() { int i=4; int j=13; int k; int l; j = 53; l = 64; k = i/j; l = i/j; l = l/j; l = j/j; l = l%j; l = k-k*i; printf("vulnerability"); printf("%d%d\n",k,l); return 0; }
[ "nharmon8@gmail.com" ]
nharmon8@gmail.com
bfe1d49035e715cfce1ecd48990a978d186b8bdc
49780f24a92fcc9a7c855144fb195ae3736bf390
/examples/devices/MSP430i2xx/MSP430i20xx_Code_Examples/C/msp430i20xx_euscib0_i2c_11/msp430i20xx_euscib0_i2c_11.c
89bab87bf070c84699ab7f95bc3034ee14e213e2
[]
no_license
PiBoxY/msp430ware
81fb264c86ff1f68f711965b793aa58794ae2f00
7c96db00f97bbfd3119843e18ac895a54b4a6d39
refs/heads/master
2020-04-21T07:29:13.386144
2019-02-06T11:32:42
2019-02-06T11:32:42
169,394,007
2
1
null
null
null
null
UTF-8
C
false
false
5,545
c
/* --COPYRIGHT--,BSD_EX * Copyright (c) 2013, Texas Instruments Incorporated * 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. * * * Neither the name of Texas Instruments Incorporated nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 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. * ******************************************************************************* * * MSP430 CODE EXAMPLE DISCLAIMER * * MSP430 code examples are self-contained low-level programs that typically * demonstrate a single peripheral function or device feature in a highly * concise manner. For this the code may rely on the device's power-on default * register values and settings such as the clock configuration and care must * be taken when combining code from several examples to avoid potential side * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware * for an API functional library-approach to peripheral configuration. * * --/COPYRIGHT--*/ //****************************************************************************** // MSP430i20xx Demo - eUSCI_B0 I2C Slave TX Multiple Bytes to MSP430 Master // // Description: This demo connects two MSP430's via the I2C bus. The master // reads from the slave. This is the SLAVE code. The TX data begins at 0 // and is incremented each time it is sent. A stop condition // is used as a trigger to initialize the outgoing data. // * used with "msp430i20xx_euscib0_i2c_10.c * // // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz // * Ensure low_level_init.c is included when building/running this example * // // /|\ /|\ // MSP430i2041 10k 10k MSP430i2041 // slave | | master // ----------------- | | ----------------- // | P1.7/UCB0SDA|<-|----+->|P1.7/UCB0SDA | // | | | | | // | | | | | // | P1.6/UCB0SCL|<-+------>|P1.6/UCB0SCL | // | | | P1.4|--> LED // // T. Witt // Texas Instruments, Inc // September 2013 // Built with Code Composer Studio v5.5 //****************************************************************************** #include "msp430.h" volatile unsigned char TXData; void main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop Watchdog Timer P1SEL0 |= BIT6 | BIT7; // I2C Pins P1SEL1 &= ~(BIT6 | BIT7); // Configure USCI_B0 for I2C mode UCB0CTLW0 |= UCSWRST; // Software reset enabled UCB0CTLW0 |= UCMODE_3 | UCSYNC; // I2C slave mode UCB0I2COA0 = 0x48 | UCOAEN; // Address is 0x48 + enable UCB0CTL1 &= ~UCSWRST; UCB0IE |= UCTXIE0 | UCSTPIE; // Transmit, Stop interrupt enable __bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupts __no_operation(); // For debugger } #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) #pragma vector=USCI_B0_VECTOR __interrupt void USCIB0_ISR(void) #elif defined(__GNUC__) void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCIB0_ISR (void) #else #error Compiler not supported! #endif { switch(__even_in_range(UCB0IV, USCI_I2C_UCBIT9IFG)) { case USCI_NONE: break; case USCI_I2C_UCALIFG: break; case USCI_I2C_UCNACKIFG: break; case USCI_I2C_UCSTTIFG: break; case USCI_I2C_UCSTPIFG: TXData = 0; UCB0IFG &= ~UCSTPIFG; // Clear IFG break; case USCI_I2C_UCRXIFG3: break; case USCI_I2C_UCTXIFG3: break; case USCI_I2C_UCRXIFG2: break; case USCI_I2C_UCTXIFG2: break; case USCI_I2C_UCRXIFG1: break; case USCI_I2C_UCTXIFG1: break; case USCI_I2C_UCRXIFG0: break; case USCI_I2C_UCTXIFG0: UCB0TXBUF = TXData++; break; case USCI_I2C_UCBCNTIFG: break; case USCI_I2C_UCCLTOIFG: break; case USCI_I2C_UCBIT9IFG: break; default: break; } }
[ "admin@piboxy.com" ]
admin@piboxy.com
f5dae502ad0ac92e57c42f55b5cd42b8caa4aa78
228f66eecd08220e9f0e3d1da0f28444eee0344e
/day05/ex13/ft_str_is_lowercase.c
a77473c41ab1336353aa674261baac719f74fc2c
[]
no_license
nanaosakisan/Piscine_git
d004abc87b196356d22003062fe780077095b59e
9f1cdc95a581ed979a28649c995487c3f5a1b1ae
refs/heads/master
2020-03-18T21:47:35.944584
2018-05-29T13:54:47
2018-05-29T13:54:47
135,303,516
0
0
null
null
null
null
UTF-8
C
false
false
1,089
c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_str_is_lowercase.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: iporsenn <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/07/21 10:30:16 by iporsenn #+# #+# */ /* Updated: 2017/07/21 10:39:35 by iporsenn ### ########.fr */ /* */ /* ************************************************************************** */ int ft_str_is_lowercase(char *str) { int i; i = 0; if (str == 0) return (1); while (str[i] != '\0') { if (str[i] >= 'a' && str[i] <= 'z') i++; else return (0); } return (1); }
[ "iporsenn@e2r11p7.42.fr" ]
iporsenn@e2r11p7.42.fr
313e967fcfa46bde1156ecc3412f76586f0b0f0d
a54a73bccc627d2c272be15078e4cfcdaffe852c
/include/sysreg/icc_sgi1r_el1.h
0c8ac31e09413e5c8148de16c3f97d038529c596
[ "MIT" ]
permissive
surufa123/arm64-sysreg-lib
0d085c5e7a4ded56f57c1d54a3522251595c0db5
d421e249a026f6f14653cb6f9c4edd8c5d898595
refs/heads/master
2023-04-13T10:41:10.418489
2021-04-26T21:10:49
2021-04-26T21:10:49
null
0
0
null
null
null
null
UTF-8
C
false
false
13,248
h
/* * This file was automatically generated using arm64-sysreg-lib * See: https://github.com/ashwio/arm64-sysreg-lib * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef ARM64_SYSREG_MACROS_DEFINED #define ARM64_SYSREG_MACROS_DEFINED /* * These macros are inspired by Daniel Hardman's Variadic Macro Tricks blog: * https://codecraft.co/2014/11/25/variadic-macros-tricks/ * * The net result is ARM64_SYSREG_CALL_FOR_EACH( m, ... ) calling the macro, m, * for each token in the variadic args list, ..., which we use to set a variadic * list of struct fields. * * For example: * * safe_write_sctlr_el1( .m=1, .c=1, .i=1, .lsmaoe=0, ); * * Where the safe_write_*() functions copy the system register's known SAFEVAL, * which has all currently or previously RES1 bits set to 1 and all currently or * previously RES0 bits cleared to 0, then overwrite the fields specified in the * variadic arg list before performing an MSR. * * A maximum of 64 fields can be passed in this way, which should be fine given * that an AArch64 system register is either 32 or 64 bits wide, and each field * must itself be at least 1 bit wide. */ #define ARM64_SYSREG_GET_ARG_N( \ _1, \ _2, \ _3, \ _4, \ _5, \ _6, \ _7, \ _8, \ _9, \ _10, \ _11, \ _12, \ _13, \ _14, \ _15, \ _16, \ _17, \ _18, \ _19, \ _20, \ _21, \ _22, \ _23, \ _24, \ _25, \ _26, \ _27, \ _28, \ _29, \ _30, \ _31, \ _32, \ _33, \ _34, \ _35, \ _36, \ _37, \ _38, \ _39, \ _40, \ _41, \ _42, \ _43, \ _44, \ _45, \ _46, \ _47, \ _48, \ _49, \ _50, \ _51, \ _52, \ _53, \ _54, \ _55, \ _56, \ _57, \ _58, \ _59, \ _60, \ _61, \ _62, \ _63, \ N, ... ) N #define ARM64_SYSREG_CALL_FOR_ARG0( _call, ... ) #define ARM64_SYSREG_CALL_FOR_ARG1( _call, x ) _call(x) #define ARM64_SYSREG_CALL_FOR_ARG2( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG1(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG3( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG2(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG4( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG3(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG5( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG4(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG6( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG5(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG7( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG6(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG8( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG7(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG9( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG8(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG10( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG9(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG11( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG10(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG12( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG11(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG13( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG12(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG14( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG13(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG15( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG14(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG16( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG15(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG17( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG16(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG18( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG17(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG19( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG18(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG20( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG19(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG21( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG20(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG22( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG21(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG23( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG22(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG24( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG23(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG25( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG24(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG26( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG25(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG27( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG26(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG28( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG27(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG29( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG28(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG30( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG29(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG31( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG30(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG32( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG31(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG33( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG32(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG34( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG33(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG35( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG34(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG36( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG35(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG37( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG36(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG38( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG37(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG39( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG38(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG40( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG39(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG41( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG40(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG42( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG41(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG43( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG42(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG44( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG43(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG45( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG44(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG46( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG45(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG47( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG46(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG48( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG47(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG49( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG48(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG50( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG49(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG51( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG50(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG52( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG51(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG53( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG52(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG54( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG53(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG55( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG54(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG56( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG55(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG57( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG56(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG58( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG57(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG59( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG58(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG60( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG59(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG61( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG60(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_ARG62( _call, x, ... ) _call(x) ARM64_SYSREG_CALL_FOR_ARG61(_call, __VA_ARGS__) #define ARM64_SYSREG_CALL_FOR_EACH( m, ... ) \ ARM64_SYSREG_GET_ARG_N("placeholder", __VA_ARGS__, \ ARM64_SYSREG_CALL_FOR_ARG62, \ ARM64_SYSREG_CALL_FOR_ARG61, \ ARM64_SYSREG_CALL_FOR_ARG60, \ ARM64_SYSREG_CALL_FOR_ARG59, \ ARM64_SYSREG_CALL_FOR_ARG58, \ ARM64_SYSREG_CALL_FOR_ARG57, \ ARM64_SYSREG_CALL_FOR_ARG56, \ ARM64_SYSREG_CALL_FOR_ARG55, \ ARM64_SYSREG_CALL_FOR_ARG54, \ ARM64_SYSREG_CALL_FOR_ARG53, \ ARM64_SYSREG_CALL_FOR_ARG52, \ ARM64_SYSREG_CALL_FOR_ARG51, \ ARM64_SYSREG_CALL_FOR_ARG50, \ ARM64_SYSREG_CALL_FOR_ARG49, \ ARM64_SYSREG_CALL_FOR_ARG48, \ ARM64_SYSREG_CALL_FOR_ARG47, \ ARM64_SYSREG_CALL_FOR_ARG46, \ ARM64_SYSREG_CALL_FOR_ARG45, \ ARM64_SYSREG_CALL_FOR_ARG44, \ ARM64_SYSREG_CALL_FOR_ARG43, \ ARM64_SYSREG_CALL_FOR_ARG42, \ ARM64_SYSREG_CALL_FOR_ARG41, \ ARM64_SYSREG_CALL_FOR_ARG40, \ ARM64_SYSREG_CALL_FOR_ARG39, \ ARM64_SYSREG_CALL_FOR_ARG38, \ ARM64_SYSREG_CALL_FOR_ARG37, \ ARM64_SYSREG_CALL_FOR_ARG36, \ ARM64_SYSREG_CALL_FOR_ARG35, \ ARM64_SYSREG_CALL_FOR_ARG34, \ ARM64_SYSREG_CALL_FOR_ARG33, \ ARM64_SYSREG_CALL_FOR_ARG32, \ ARM64_SYSREG_CALL_FOR_ARG31, \ ARM64_SYSREG_CALL_FOR_ARG30, \ ARM64_SYSREG_CALL_FOR_ARG29, \ ARM64_SYSREG_CALL_FOR_ARG28, \ ARM64_SYSREG_CALL_FOR_ARG27, \ ARM64_SYSREG_CALL_FOR_ARG26, \ ARM64_SYSREG_CALL_FOR_ARG25, \ ARM64_SYSREG_CALL_FOR_ARG24, \ ARM64_SYSREG_CALL_FOR_ARG23, \ ARM64_SYSREG_CALL_FOR_ARG22, \ ARM64_SYSREG_CALL_FOR_ARG21, \ ARM64_SYSREG_CALL_FOR_ARG20, \ ARM64_SYSREG_CALL_FOR_ARG19, \ ARM64_SYSREG_CALL_FOR_ARG18, \ ARM64_SYSREG_CALL_FOR_ARG17, \ ARM64_SYSREG_CALL_FOR_ARG16, \ ARM64_SYSREG_CALL_FOR_ARG15, \ ARM64_SYSREG_CALL_FOR_ARG14, \ ARM64_SYSREG_CALL_FOR_ARG13, \ ARM64_SYSREG_CALL_FOR_ARG12, \ ARM64_SYSREG_CALL_FOR_ARG11, \ ARM64_SYSREG_CALL_FOR_ARG10, \ ARM64_SYSREG_CALL_FOR_ARG9, \ ARM64_SYSREG_CALL_FOR_ARG8, \ ARM64_SYSREG_CALL_FOR_ARG7, \ ARM64_SYSREG_CALL_FOR_ARG6, \ ARM64_SYSREG_CALL_FOR_ARG5, \ ARM64_SYSREG_CALL_FOR_ARG4, \ ARM64_SYSREG_CALL_FOR_ARG3, \ ARM64_SYSREG_CALL_FOR_ARG2, \ ARM64_SYSREG_CALL_FOR_ARG1, \ ARM64_SYSREG_CALL_FOR_ARG0, \ )(m, __VA_ARGS__) #define ARM64_SYSREG_SET( arg ) tmp arg; /* * Manually typedef u64 in case compiler doesn't have <stdint.h> (have seen * this with compilers installed on MacOS, both via Xcode and Homebrew). * Vast majority users target __LP64__ so only bother supporting this for now. */ #ifdef __LP64__ typedef unsigned long u64; #else #error "Unrecognised compilation target ABI, expected LP64" #endif /* ARM64_SYSREG_MACROS_DEFINED */ #endif /*========================================================================* * AUTOMATICALLY GENERATED SYSTEM REGISTER CODE FROM THIS POINT ONWARDS * *========================================================================*/ #ifndef H_ICC_SGI1R_EL1 #define H_ICC_SGI1R_EL1 union icc_sgi1r_el1 { u64 _; __extension__ struct { u64 targetlist : 16; u64 aff1 : 8; u64 intid : 4; u64 res0_31_28 : 4; u64 aff2 : 8; u64 irm : 1; u64 res0_43_41 : 3; u64 rs : 4; u64 aff3 : 8; u64 res0_63_56 : 8; }; }; static const union icc_sgi1r_el1 ICC_SGI1R_EL1_SAFEVAL = {0 }; static inline void unsafe_write_icc_sgi1r_el1( union icc_sgi1r_el1 val ) { __asm( "MSR s3_0_c12_c11_5, %0" : /**/ : "r" (val._) ); } #define safe_write_icc_sgi1r_el1( ... ) \ do \ { \ union icc_sgi1r_el1 tmp = ICC_SGI1R_EL1_SAFEVAL; \ ARM64_SYSREG_CALL_FOR_EACH(ARM64_SYSREG_SET, __VA_ARGS__) \ unsafe_write_icc_sgi1r_el1(tmp); \ } while (0) /* H_ICC_SGI1R_EL1 */ #endif
[ "46906049+ashwio@users.noreply.github.com" ]
46906049+ashwio@users.noreply.github.com
c9aba451cbe52f3b91ccb9f42e80fae41e651164
8384221219ccebfaeaeb6233ca8340ebadcc6901
/0x04-more_functions_nested_loops/101-print_number.c
9e9b380cbdc2148d7d37a2c4c22f25fd4a1af355
[]
no_license
germaya/holbertonschool-low_level_programming
d9d0144e040255fd9a2752609463c5b3da650384
c326463b38379dcd238a6869e5d0453d0b1453a3
refs/heads/master
2020-07-28T12:29:55.107306
2019-10-08T03:05:27
2019-10-08T03:05:27
209,410,711
0
0
null
null
null
null
UTF-8
C
false
false
283
c
#include <stdio.h> /** * print_number - print numbers with puchart. * @n: integrer variable * Return: Always 0. */ int main(void) { int n; if (n >= 0 && n <= 9) { _putchar(n); } else if (n >= 10 && n <= 99) { n = n % 10; } printf("\n"); return (0); }
[ "german.maya.trujillo@gmail.com" ]
german.maya.trujillo@gmail.com
6dfdbd6619922d6851c7d422a17d15711e2eed3d
015010feba92826a69d9cae625e4bb133978911d
/trab1/integral.c
5df00639a1deda1babed4c5f7f24655267ebca3e
[]
no_license
JaoSchmidt/CConcSilvana
9b362a355c2c1674331cf8c330dcd57a369c143e
823f46ccc0698ccac541f10b547284d4ab4720c2
refs/heads/main
2023-08-23T23:10:35.283471
2021-10-14T04:50:50
2021-10-14T04:50:50
389,143,460
0
0
null
null
null
null
UTF-8
C
false
false
3,805
c
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <pthread.h> #include "timer.h" #define RED "\x1b[31m" #define WHT "\e[0;37m" double LetraA(double); double LetraB(double); double LetraC(double); double LetraD(double); void *Menu(); void *somaRiemann(); int NTHREADS; //Declaracao do nº de threads double a, b; //Variaveis do intervalo definido pelo user int nRetangulos; //Variavel para armazenmento da quant de divisoes a serem realizada double delta, resultIntegral = 0; //Delta X dos retangulos e o rultado final. pthread_mutex_t lock; //Declaração do mutex //Estrutura para armazenamento das informações da thread, como seu id e qual função o usuario selecionou typedef struct { int id; double (*function)(double); } Args; int main(int argc, char *argv[]) { double inicio, fim, (*option)(double); //Variaveis para marcação do tempo e ponteiro para armazenamento de adress de function Args *thread; pthread_t *tid; //leitura e avalicao de paramentros if (argc < 4) { fprintf(stderr, "Digite : %s <Intervalo a> <Intervalo b> <nº de retangulos> <nº de thread>\n", argv[0]); return 1; } a = atof(argv[1]); b = atof(argv[2]); nRetangulos = atoi(argv[3]); NTHREADS = atoi(argv[4]); delta = (b - a) / nRetangulos; thread = (Args *)malloc(sizeof(Args) * NTHREADS); tid = (pthread_t *)malloc(sizeof(pthread_t) * NTHREADS); if (tid == NULL || thread == NULL) { printf(RED "|-->ERRO: malloc\n"); return 2; } option = Menu(); //acessando o menu para o usuario e recebendo o adress da função escolhida //Inicialização do mutex e criação das thread e execução da soma pthread_mutex_init(&lock, NULL); GET_TIME(inicio); for (int i = 0; i < NTHREADS; i++) { (thread + i)->id = i; (thread + i)->function = option; if (pthread_create(tid + i, NULL, somaRiemann, (void *)(thread + i))) { fprintf(stderr, RED "|-->ERRO: pthread_create() <--|\n"); return 3; } } for (int i = 0; i < NTHREADS; i++) if (pthread_join(*(tid + i), NULL)) { printf(RED "|-->ERRO: pthread_join()<--| \n"); exit(-1); } GET_TIME(fim); printf("\nResultado: %lf\n", resultIntegral * delta); printf("Tempo de calculo: %lf\n\n", fim - inicio); pthread_mutex_destroy(&lock); free(thread); free(tid); pthread_exit(NULL); return 0; } void *somaRiemann(void *arg) { Args *thread = (Args *)arg; double somaLocal = 0; for (int i = (thread->id + 1); i <= nRetangulos; i += NTHREADS) { somaLocal += (thread->function(i * delta)); } pthread_mutex_lock(&lock); resultIntegral += somaLocal; pthread_mutex_unlock(&lock); pthread_exit(NULL); } void *Menu() { char letra; printf("Escolha a função:\n\na- x*2\nb- x^2\nc- (x^3)-6*x\nd- seno(x^2)\n\n"); printf("Digite a letra da função que deseja executar: \n"); scanf("%c", &letra); switch (letra) { case 'a': case 'A': return (double *)LetraA; break; case 'b': case 'B': return (double *)LetraB; break; case 'c': case 'C': return (double *)LetraC; break; case 'd': case 'D': return (double *)LetraD; break; default: printf(RED "Opção Invalida.\n" WHT); exit(-1); break; } return 0; } double LetraA(double x) { return x * 2; } double LetraB(double x) { return pow(x, 2); } double LetraC(double x) { return pow(x, 3) - (6 * x); } double LetraD(double x) { return sin(pow(x, 2)); }
[ "jhsc98@gmail.com" ]
jhsc98@gmail.com
ffdd729c54a2812ddf6d811e31ca15fee3285eeb
47fbe4f96df88d12f4dfc075f39b8a2bce8882aa
/Projects/ble/Profiles/HIDKeyboard/hidKeyboardProfile.h
2fcc6a4c21e94296159b85232f8b42542d24d468
[]
no_license
cybravo/shred444
212ad98e743596ac840136a571d74f4fff6c7088
0e35be3e379f0e83d0bc33b9b8789a5a3a7d4cc1
refs/heads/master
2016-09-10T22:56:36.655266
2012-01-31T18:50:27
2012-01-31T18:50:27
39,682,648
0
0
null
null
null
null
WINDOWS-1258
C
false
false
4,525
h
/************************************************************************************************** Filename: hidKeyboardprofile.h Revised: $Date: 2010-08-06 08:56:11 -0700 (Fri, 06 Aug 2010) $ Revision: $Revision: 23333 $ Description: This file contains the HID Keyboard profile definitions and prototypes. Copyright 2011 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software license agreement between the user who downloaded the software, his/her employer (which must be your employer) and Texas Instruments Incorporated (the "License"). You may not use this Software unless you agree to abide by the terms of the License. The License limits your use, and you acknowledge, that the Software may not be modified, copied or distributed unless embedded on a Texas Instruments microcontroller or used solely and exclusively in conjunction with a Texas Instruments radio frequency transceiver, which is integrated into your product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software, contact Texas Instruments Incorporated at www.TI.com. **************************************************************************************************/ #ifndef HIDKEYBOARDPROFILE_H #define HIDKEYBOARDPROFILE_H #ifdef __cplusplus extern "C" { #endif /********************************************************************* * INCLUDES */ /********************************************************************* * CONSTANTS */ // Profile Parameters #define HIDKEYBOARD_DATA 0 // RW uint8 - Profile Characteristic value // Simple Profile Service UUID #define HIDKEYBOARD_SERV_UUID 0xFF90 // Key Pressed UUID #define HIDKEYBOARD_DATA_UUID 0xFF91 // Simple Keys Profile Services bit fields #define HIDKEYBOARD_SERVICE 0x00000001 /********************************************************************* * TYPEDEFS */ /********************************************************************* * MACROS */ /********************************************************************* * Profile Callbacks */ /********************************************************************* * API FUNCTIONS */ /* * HidKeyboard_AddService- Initializes the Simple GATT Profile service by registering * GATT attributes with the GATT server. * * @param services - services to add. This is a bit map and can * contain more than one service. */ extern bStatus_t HidKeyboard_AddService( uint32 services ); /* * HidKeyboard_SetParameter - Set a Simple GATT Profile parameter. * * param - Profile parameter ID * len - length of data to right * value - pointer to data to write. This is dependent on * the parameter ID and WILL be cast to the appropriate * data type (example: data type of uint16 will be cast to * uint16 pointer). */ extern bStatus_t HidKeyboard_SetParameter( uint8 param, uint8 len, void *value ); /********************************************************************* *********************************************************************/ #ifdef __cplusplus } #endif #endif /* HIDKEYBOARDPROFILE_H */
[ "shred444@d1fc056a-b597-3ae5-28f8-eda8a703bcb0" ]
shred444@d1fc056a-b597-3ae5-28f8-eda8a703bcb0
d44c8dbed7e84580b167010611aead23c7db1ea8
cca6583b9b7f98e56b96153d68fa0650a8555d8d
/COMP10110/Lab7/q1.c
f6a3ca5901c219d8eff7f8c058565e9f759c6321
[]
no_license
AhmedJouda2000/C-programs
eb3c609e6ca33b3c2f81d556f214cf80f62863da
a9c74f6434a7e743bd572673448b189fbbea578d
refs/heads/master
2022-12-21T15:06:50.358391
2020-09-22T20:37:25
2020-09-22T20:37:25
297,762,401
1
0
null
null
null
null
UTF-8
C
false
false
1,784
c
/* This is lab 7 questoion 1a (small testcase), Write a program to Find, from amongst a set of positive lengths, a pair of lengths that sum exactly to a target length. This is the work of Ahmed Jouda (Student Number 18329393) Created on 22/10/2018 */ #include <stdio.h> #include <stdlib.h> #define N 500 int main(void) { int n; /* The number of lengths */ int x; /* The target length */ int lengths[N]; /* The array of available lengths */ int i, j; char found = 'f'; FILE *fp; fp = fopen("testcase_small.txt", "r"); fscanf(fp, "%d", &x); fscanf(fp, "%d", &n); for (i=0;i<n;i++) { fscanf(fp, "%d", &lengths[i]); } x = x*10000000; fclose(fp); /* Now all the input data has been read in search for the required pair of lengths... */ i=0; j=n-1; /* As the numbers are ordered we know j is the largest and i is the smallest Therefore if i and j add up to x then we print those out and they are for sure the pair with the biggest difference between them as we are closing in on the array and the first pair found (greatest difference) is printed. If they dont add up to x, 3 scenarios are possible, either j = i and no pair was found after closing in on the array, or j+i > x meaning j has to be lowered, or j+i <x in which case i has to be raised. */ while(found == 'f') { if (lengths[i] + lengths[j] == x) { printf("they are %d %d", lengths[i], lengths[j]); found = 't'; } else if (i==j) { printf("No values exist\n"); found = 't'; } else if ((lengths[i] + lengths[j]) > x) { j--; } else if ((lengths[i] + lengths[j]) < x) { i++; } } return 0; }
[ "noreply@github.com" ]
AhmedJouda2000.noreply@github.com
db7da0e695f4eace2d73fb1e959dfd1a28884a61
85b2c758837e37937d431f6e71ca1d6a39685b3f
/1501-exploits/crash-issue3.c
ae7526009c06e7e709559f5d8a8e20141f5448f5
[]
no_license
Silentsoul04/packetstorm-exploits
e737f4ed192b47866aff113df8818117410615e3
f6c0733c76b2c8f86d8e05e70f80a87faa0e0267
refs/heads/master
2023-02-01T21:56:43.721503
2020-12-16T15:48:54
2020-12-16T15:48:54
null
0
0
null
null
null
null
UTF-8
C
false
false
1,909
c
/* * crash-issue3.c: Written for Mac OS X Yosemite (10.10) by @rpaleari and @joystick. * * Exploits a missing check in * IOBluetoothHCIController::TransferACLPacketToHW() to trigger a panic. * * gcc -Wall -o crash-issue3{,.c} -framework IOKit * */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <mach/mach.h> #include <mach/vm_map.h> #include <IOKit/IOKitLib.h> struct BluetoothCall { uint64_t args[7]; uint64_t sizes[7]; uint64_t index; }; int main(void) { /* Finding vuln service */ io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOBluetoothHCIController")); if (!service) { return -1; } /* Connect to vuln service */ io_connect_t port = (io_connect_t) 0; kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port); IOObjectRelease(service); if (kr != kIOReturnSuccess) { return kr; } printf(" [+] Opened connection to service on port: %d\n", port); struct BluetoothCall a; memset(&a, 0, sizeof(a)); a.sizes[0] = 0x1000; a.args[0] = (uint64_t) calloc(a.sizes[0], sizeof(char)); a.sizes[1] = 0x1000; a.args[1] = (uint64_t) calloc(a.sizes[1], sizeof(char)); memset((void *)a.args[1], 0x22, 0x1000); /* Call DispatchHCISendRawACLData() */ a.index = 0x63; /* Debug */ for(int i = 0; i < 120; i++) { if(i % 8 == 0) printf("\n"); printf("\\x%02x", ((unsigned char *)&a)[i]); } printf("\n"); fflush(stdout); kr = IOConnectCallMethod((mach_port_t) port, /* Connection */ (uint32_t) 0, /* Selector */ NULL, 0, /* input, inputCnt */ (const void*) &a, /* inputStruct */ sizeof(a), /* inputStructCnt */ NULL, NULL, NULL, NULL); /* Output stuff */ printf("kr: %08x\n", kr); return IOServiceClose(port); }
[ "sepehrdad.dev@gmail.com" ]
sepehrdad.dev@gmail.com
0c18045c0279c93b686cb7759317da344e9534ec
0fa6980db7fc5b1813f064cd8d559a7189113923
/handle_pcap.c
175dadcbb2388619555f52698d973a46ef16b4c4
[]
no_license
bobosheep/C_ReadPcap
9e1c76a8847a1a196c7246ad30d9727225b30a96
0e94cb80de8c07be744b9fdfd2292026fd2e1383
refs/heads/master
2020-04-14T15:01:39.061496
2019-01-03T04:38:02
2019-01-03T04:38:02
163,914,169
0
0
null
null
null
null
UTF-8
C
false
false
4,301
c
#include <stdio.h> #include <string.h> #include <pcap.h> #include <time.h> #include <netinet/in.h> #include <arpa/inet.h> #include "handle_pcap.h" struct ETH_hdr { u_char dst_mac[6]; u_char src_mac[6]; u_short eth_type; }; struct IP_hdr { int version:4; int header_len:4; u_char tos:8; int total_len:16; int ident:16; int flags:16; u_char ttl:8; u_char protocol:8; int checksum:16; u_char sourceIP[4]; u_char destIP[4]; }; struct IP6_hdr { unsigned int version:4; unsigned int traffic_class:8; unsigned int flow_label:20; uint16_t payload_len; uint8_t next_header; uint8_t hop_limit; /* union{ struct ip6_hdrctl{ uint32_t ip6_un1_flow; uint16_t ip6_un1_plen; uint8_t ip6_un1_nxt; uint8_t ip6_un1_hlim; } uint8_t ip6_un2_vfc; }ip6_ctlun*/ uint16_t sourceIP[8]; uint16_t destIP[8]; }; struct TCP_hdr { u_short sport; u_short dport; u_int seq; u_int ack; u_char head_len; u_char flags; u_short wind_size; u_short check_sum; u_short urg_ptr; }; struct UDP_hdr { u_short sport; u_short dport; u_short tot_len; u_short check_sum; }; eth_hdr *ethernet; ip_hdr *ip; ip6_hdr *ip6; tcp_hdr *tcp; udp_hdr *udp; //this function will be called when we get packet void p_handler(u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data) { static int count=0; int len; char* printtime; count++; printtime = ctime((const time_t*)&pkt_header->ts.tv_sec); len = strlen(printtime); printtime[len - 1] = '\0'; printf("-----------------------packet #%d-------------------------\n",count); //packet number printf("| packet length\t|\t\t%d\t\t\t|\n", pkt_header->len); //length of packet printf("| capture time\t|\t%s\t|\n", printtime);//get packet time //length of header u_int eth_len=sizeof(eth_hdr); u_int ip_len=sizeof(ip_hdr); u_int ip6_len=sizeof(ip6_hdr); u_int tcp_len=sizeof(tcp_hdr); u_int udp_len=sizeof(udp_hdr); ethernet=(eth_hdr *)pkt_data; //decided which type of protocl of ethernet ipv4 or ipv6 or others if(ntohs(ethernet->eth_type)==0x0800) { //ipv4 //printf("IPV4 is used\n"); //printf("IPV4 header information:\n"); ip=(ip_hdr*)(pkt_data+eth_len); printf("| source ip\t|\t\t%d.%d.%d.%d\t\t\t|\n",ip->sourceIP[0],ip->sourceIP[1],ip->sourceIP[2],ip->sourceIP[3]); printf("| dest ip\t|\t\t%d.%d.%d.%d\t\t\t|\n",ip->destIP[0],ip->destIP[1],ip->destIP[2],ip->destIP[3]); if(ip->protocol==6) { //tcp //printf("tcp is used:\n"); tcp=(tcp_hdr*)(pkt_data+eth_len+ip_len); printf("| tcp source port\t|\t\t%u\t\t\t|\n",htons(tcp->sport)); printf("| tcp dest port\t|\t\t%u\t\t\t|\n",htons(tcp->dport)); } else if(ip->protocol==17) { //udp protocl //printf("udp is used:\n"); udp=(udp_hdr*)(pkt_data+eth_len+ip_len); printf("| udp source port\t|\t\t%u\t\t|\n",htons(udp->sport)); printf("| udp dest port\t|\t\t%u\t\t|\n",htons(udp->dport)); } else { printf("|\tother transport protocol is used\t\t|\n"); } } else if(ntohs(ethernet->eth_type)==0x086dd) { //ipv6 //printf("ipv6 is used\n"); ip6=(ip6_hdr*)(pkt_data+eth_len); char str[INET6_ADDRSTRLEN]; printf("| source ip6\t|\t\t%s\t\t|\n",inet_ntop(AF_INET6,ip6->sourceIP,str,sizeof(str))); printf("| dest ip6\t|\t\t%s\t\t|\n",inet_ntop(AF_INET6,ip6->destIP,str,sizeof(str))); if(ip6->next_header==6) { //tcp //printf("tcp is used:\n"); tcp=(tcp_hdr*)(pkt_data+eth_len+ip6_len); printf("| tcp source port\t|\t\t%u\t\t\t|\n",htons(tcp->sport)); printf("| tcp dest port\t|\t\t%u\t\t\t|\n",htons(tcp->dport)); } else if(ip6->next_header==17) { //udp //printf("udp is used:\n"); udp=(udp_hdr*)(pkt_data+eth_len+ip6_len); printf("| udp source port\t|\t\t%u\t\t|\n",htons(udp->sport)); printf("| udp dest port\t|\t\t%u\t\t|\n",htons(udp->dport)); } else { printf("|\t\tother transport protocol is used\t\t|\n"); } } else { printf("|\t\tother ethernet_type\t\t\t|\n"); } printf("---------------------------------------------------------\n"); printf("\n"); }
[ "ianpaul32@gmail.com" ]
ianpaul32@gmail.com
680c5194b29c1a8397e823ead1d104bdd0582aa3
0916169efcbbc81ef9dbbb795e12c7693fa3827e
/kernel/drivers/gpu/drm/drm_crtc_helper.c
17c7f53d12c40e73a74efcb7ca6028d0deeab46f
[]
no_license
feravolt/FeraLab_es209ra_GB-firmware
4a19e9c3aa51f54291e4fe6f936e3e9e5d7ff9b6
669758ab7cc2b4014120bb2ba35d4f79a911af89
refs/heads/master
2021-01-10T11:30:45.658045
2017-07-02T07:54:15
2017-07-02T07:54:15
46,579,064
0
1
null
null
null
null
UTF-8
C
false
false
31,765
c
/* * Copyright (c) 2006-2008 Intel Corporation * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> * * DRM core CRTC related functions * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that copyright * notice and this permission notice appear in supporting documentation, and * that the name of the copyright holders not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. The copyright holders make no representations * about the suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, 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. * * Authors: * Keith Packard * Eric Anholt <eric@anholt.net> * Dave Airlie <airlied@linux.ie> * Jesse Barnes <jesse.barnes@intel.com> */ #include "drmP.h" #include "drm_crtc.h" #include "drm_crtc_helper.h" #include "drm_fb_helper.h" static void drm_mode_validate_flag(struct drm_connector *connector, int flags) { struct drm_display_mode *mode, *t; if (flags == (DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_INTERLACE)) return; list_for_each_entry_safe(mode, t, &connector->modes, head) { if ((mode->flags & DRM_MODE_FLAG_INTERLACE) && !(flags & DRM_MODE_FLAG_INTERLACE)) mode->status = MODE_NO_INTERLACE; if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) && !(flags & DRM_MODE_FLAG_DBLSCAN)) mode->status = MODE_NO_DBLESCAN; } return; } /** * drm_helper_probe_connector_modes - get complete set of display modes * @dev: DRM device * @maxX: max width for modes * @maxY: max height for modes * * LOCKING: * Caller must hold mode config lock. * * Based on @dev's mode_config layout, scan all the connectors and try to detect * modes on them. Modes will first be added to the connector's probed_modes * list, then culled (based on validity and the @maxX, @maxY parameters) and * put into the normal modes list. * * Intended to be used either at bootup time or when major configuration * changes have occurred. * * FIXME: take into account monitor limits * * RETURNS: * Number of modes found on @connector. */ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY) { struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *t; struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; int count = 0; int mode_flags = 0; DRM_DEBUG_KMS("%s\n", drm_get_connector_name(connector)); /* set all modes to the unverified state */ list_for_each_entry_safe(mode, t, &connector->modes, head) mode->status = MODE_UNVERIFIED; if (connector->force) { if (connector->force == DRM_FORCE_ON) connector->status = connector_status_connected; else connector->status = connector_status_disconnected; if (connector->funcs->force) connector->funcs->force(connector); } else connector->status = connector->funcs->detect(connector); if (connector->status == connector_status_disconnected) { DRM_DEBUG_KMS("%s is disconnected\n", drm_get_connector_name(connector)); goto prune; } count = (*connector_funcs->get_modes)(connector); if (!count) { count = drm_add_modes_noedid(connector, 800, 600); if (!count) return 0; } drm_mode_connector_list_update(connector); if (maxX && maxY) drm_mode_validate_size(dev, &connector->modes, maxX, maxY, 0); if (connector->interlace_allowed) mode_flags |= DRM_MODE_FLAG_INTERLACE; if (connector->doublescan_allowed) mode_flags |= DRM_MODE_FLAG_DBLSCAN; drm_mode_validate_flag(connector, mode_flags); list_for_each_entry_safe(mode, t, &connector->modes, head) { if (mode->status == MODE_OK) mode->status = connector_funcs->mode_valid(connector, mode); } prune: drm_mode_prune_invalid(dev, &connector->modes, true); if (list_empty(&connector->modes)) return 0; drm_mode_sort(&connector->modes); DRM_DEBUG_KMS("Probed modes for %s\n", drm_get_connector_name(connector)); list_for_each_entry_safe(mode, t, &connector->modes, head) { mode->vrefresh = drm_mode_vrefresh(mode); drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); drm_mode_debug_printmodeline(mode); } return count; } EXPORT_SYMBOL(drm_helper_probe_single_connector_modes); int drm_helper_probe_connector_modes(struct drm_device *dev, uint32_t maxX, uint32_t maxY) { struct drm_connector *connector; int count = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { count += drm_helper_probe_single_connector_modes(connector, maxX, maxY); } return count; } EXPORT_SYMBOL(drm_helper_probe_connector_modes); /** * drm_helper_encoder_in_use - check if a given encoder is in use * @encoder: encoder to check * * LOCKING: * Caller must hold mode config lock. * * Walk @encoders's DRM device's mode_config and see if it's in use. * * RETURNS: * True if @encoder is part of the mode_config, false otherwise. */ bool drm_helper_encoder_in_use(struct drm_encoder *encoder) { struct drm_connector *connector; struct drm_device *dev = encoder->dev; list_for_each_entry(connector, &dev->mode_config.connector_list, head) if (connector->encoder == encoder) return true; return false; } EXPORT_SYMBOL(drm_helper_encoder_in_use); /** * drm_helper_crtc_in_use - check if a given CRTC is in a mode_config * @crtc: CRTC to check * * LOCKING: * Caller must hold mode config lock. * * Walk @crtc's DRM device's mode_config and see if it's in use. * * RETURNS: * True if @crtc is part of the mode_config, false otherwise. */ bool drm_helper_crtc_in_use(struct drm_crtc *crtc) { struct drm_encoder *encoder; struct drm_device *dev = crtc->dev; /* FIXME: Locking around list access? */ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) if (encoder->crtc == crtc && drm_helper_encoder_in_use(encoder)) return true; return false; } EXPORT_SYMBOL(drm_helper_crtc_in_use); /** * drm_disable_unused_functions - disable unused objects * @dev: DRM device * * LOCKING: * Caller must hold mode config lock. * * If an connector or CRTC isn't part of @dev's mode_config, it can be disabled * by calling its dpms function, which should power it off. */ void drm_helper_disable_unused_functions(struct drm_device *dev) { struct drm_encoder *encoder; struct drm_connector *connector; struct drm_encoder_helper_funcs *encoder_funcs; struct drm_crtc *crtc; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { if (!connector->encoder) continue; if (connector->status == connector_status_disconnected) connector->encoder = NULL; } list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { encoder_funcs = encoder->helper_private; if (!drm_helper_encoder_in_use(encoder)) { if (encoder_funcs->disable) (*encoder_funcs->disable)(encoder); else (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); /* disconnector encoder from any connector */ encoder->crtc = NULL; } } list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) { crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); crtc->fb = NULL; } } } EXPORT_SYMBOL(drm_helper_disable_unused_functions); static struct drm_display_mode *drm_has_preferred_mode(struct drm_connector *connector, int width, int height) { struct drm_display_mode *mode; list_for_each_entry(mode, &connector->modes, head) { if (drm_mode_width(mode) > width || drm_mode_height(mode) > height) continue; if (mode->type & DRM_MODE_TYPE_PREFERRED) return mode; } return NULL; } static bool drm_has_cmdline_mode(struct drm_connector *connector) { struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private; struct drm_fb_helper_cmdline_mode *cmdline_mode; if (!fb_help_conn) return false; cmdline_mode = &fb_help_conn->cmdline_mode; return cmdline_mode->specified; } static struct drm_display_mode *drm_pick_cmdline_mode(struct drm_connector *connector, int width, int height) { struct drm_fb_helper_connector *fb_help_conn = connector->fb_helper_private; struct drm_fb_helper_cmdline_mode *cmdline_mode; struct drm_display_mode *mode = NULL; if (!fb_help_conn) return mode; cmdline_mode = &fb_help_conn->cmdline_mode; if (cmdline_mode->specified == false) return mode; /* attempt to find a matching mode in the list of modes * we have gotten so far, if not add a CVT mode that conforms */ if (cmdline_mode->rb || cmdline_mode->margins) goto create_mode; list_for_each_entry(mode, &connector->modes, head) { /* check width/height */ if (mode->hdisplay != cmdline_mode->xres || mode->vdisplay != cmdline_mode->yres) continue; if (cmdline_mode->refresh_specified) { if (mode->vrefresh != cmdline_mode->refresh) continue; } if (cmdline_mode->interlace) { if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) continue; } return mode; } create_mode: mode = drm_cvt_mode(connector->dev, cmdline_mode->xres, cmdline_mode->yres, cmdline_mode->refresh_specified ? cmdline_mode->refresh : 60, cmdline_mode->rb, cmdline_mode->interlace, cmdline_mode->margins); drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); list_add(&mode->head, &connector->modes); return mode; } static bool drm_connector_enabled(struct drm_connector *connector, bool strict) { bool enable; if (strict) { enable = connector->status == connector_status_connected; } else { enable = connector->status != connector_status_disconnected; } return enable; } static void drm_enable_connectors(struct drm_device *dev, bool *enabled) { bool any_enabled = false; struct drm_connector *connector; int i = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { enabled[i] = drm_connector_enabled(connector, true); DRM_DEBUG_KMS("connector %d enabled? %s\n", connector->base.id, enabled[i] ? "yes" : "no"); any_enabled |= enabled[i]; i++; } if (any_enabled) return; i = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { enabled[i] = drm_connector_enabled(connector, false); i++; } } static bool drm_target_preferred(struct drm_device *dev, struct drm_display_mode **modes, bool *enabled, int width, int height) { struct drm_connector *connector; int i = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { if (enabled[i] == false) { i++; continue; } DRM_DEBUG_KMS("looking for cmdline mode on connector %d\n", connector->base.id); /* got for command line mode first */ modes[i] = drm_pick_cmdline_mode(connector, width, height); if (!modes[i]) { DRM_DEBUG_KMS("looking for preferred mode on connector %d\n", connector->base.id); modes[i] = drm_has_preferred_mode(connector, width, height); } /* No preferred modes, pick one off the list */ if (!modes[i] && !list_empty(&connector->modes)) { list_for_each_entry(modes[i], &connector->modes, head) break; } DRM_DEBUG_KMS("found mode %s\n", modes[i] ? modes[i]->name : "none"); i++; } return true; } static int drm_pick_crtcs(struct drm_device *dev, struct drm_crtc **best_crtcs, struct drm_display_mode **modes, int n, int width, int height) { int c, o; struct drm_connector *connector; struct drm_connector_helper_funcs *connector_funcs; struct drm_encoder *encoder; __attribute__((unused)) struct drm_crtc *best_crtc; int my_score, best_score, score; struct drm_crtc **crtcs, *crtc; if (n == dev->mode_config.num_connector) return 0; c = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { if (c == n) break; c++; } best_crtcs[n] = NULL; best_crtc = NULL; best_score = drm_pick_crtcs(dev, best_crtcs, modes, n+1, width, height); if (modes[n] == NULL) return best_score; crtcs = kmalloc(dev->mode_config.num_connector * sizeof(struct drm_crtc *), GFP_KERNEL); if (!crtcs) return best_score; my_score = 1; if (connector->status == connector_status_connected) my_score++; if (drm_has_cmdline_mode(connector)) my_score++; if (drm_has_preferred_mode(connector, width, height)) my_score++; connector_funcs = connector->helper_private; encoder = connector_funcs->best_encoder(connector); if (!encoder) goto out; connector->encoder = encoder; /* select a crtc for this connector and then attempt to configure remaining connectors */ c = 0; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { if ((encoder->possible_crtcs & (1 << c)) == 0) { c++; continue; } for (o = 0; o < n; o++) if (best_crtcs[o] == crtc) break; if (o < n) { /* ignore cloning for now */ c++; continue; } crtcs[n] = crtc; memcpy(crtcs, best_crtcs, n * sizeof(struct drm_crtc *)); score = my_score + drm_pick_crtcs(dev, crtcs, modes, n + 1, width, height); if (score > best_score) { best_crtc = crtc; best_score = score; memcpy(best_crtcs, crtcs, dev->mode_config.num_connector * sizeof(struct drm_crtc *)); } c++; } out: kfree(crtcs); return best_score; } static void drm_setup_crtcs(struct drm_device *dev) { struct drm_crtc **crtcs; struct drm_display_mode **modes; struct drm_encoder *encoder; struct drm_connector *connector; bool *enabled; int width, height; int i, ret; DRM_DEBUG_KMS("\n"); width = dev->mode_config.max_width; height = dev->mode_config.max_height; /* clean out all the encoder/crtc combos */ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { encoder->crtc = NULL; } crtcs = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_crtc *), GFP_KERNEL); modes = kcalloc(dev->mode_config.num_connector, sizeof(struct drm_display_mode *), GFP_KERNEL); enabled = kcalloc(dev->mode_config.num_connector, sizeof(bool), GFP_KERNEL); drm_enable_connectors(dev, enabled); ret = drm_target_preferred(dev, modes, enabled, width, height); if (!ret) DRM_ERROR("Unable to find initial modes\n"); DRM_DEBUG_KMS("picking CRTCs for %dx%d config\n", width, height); drm_pick_crtcs(dev, crtcs, modes, 0, width, height); i = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { struct drm_display_mode *mode = modes[i]; struct drm_crtc *crtc = crtcs[i]; if (connector->encoder == NULL) { i++; continue; } if (mode && crtc) { DRM_DEBUG_KMS("desired mode %s set on crtc %d\n", mode->name, crtc->base.id); crtc->desired_mode = mode; connector->encoder->crtc = crtc; } else { connector->encoder->crtc = NULL; connector->encoder = NULL; } i++; } kfree(crtcs); kfree(modes); kfree(enabled); } /** * drm_encoder_crtc_ok - can a given crtc drive a given encoder? * @encoder: encoder to test * @crtc: crtc to test * * Return false if @encoder can't be driven by @crtc, true otherwise. */ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder, struct drm_crtc *crtc) { struct drm_device *dev; struct drm_crtc *tmp; int crtc_mask = 1; WARN(!crtc, "checking null crtc?"); dev = crtc->dev; list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { if (tmp == crtc) break; crtc_mask <<= 1; } if (encoder->possible_crtcs & crtc_mask) return true; return false; } /* * Check the CRTC we're going to map each output to vs. its current * CRTC. If they don't match, we have to disable the output and the CRTC * since the driver will have to re-route things. */ static void drm_crtc_prepare_encoders(struct drm_device *dev) { struct drm_encoder_helper_funcs *encoder_funcs; struct drm_encoder *encoder; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { encoder_funcs = encoder->helper_private; /* Disable unused encoders */ if (encoder->crtc == NULL) (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); /* Disable encoders whose CRTC is about to change */ if (encoder_funcs->get_crtc && encoder->crtc != (*encoder_funcs->get_crtc)(encoder)) (*encoder_funcs->dpms)(encoder, DRM_MODE_DPMS_OFF); } } /** * drm_crtc_set_mode - set a mode * @crtc: CRTC to program * @mode: mode to use * @x: width of mode * @y: height of mode * * LOCKING: * Caller must hold mode config lock. * * Try to set @mode on @crtc. Give @crtc and its associated connectors a chance * to fixup or reject the mode prior to trying to set it. * * RETURNS: * True if the mode was set successfully, or false otherwise. */ bool drm_crtc_helper_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode, int x, int y, struct drm_framebuffer *old_fb) { struct drm_device *dev = crtc->dev; struct drm_display_mode *adjusted_mode, saved_mode; struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; struct drm_encoder_helper_funcs *encoder_funcs; int saved_x, saved_y; struct drm_encoder *encoder; bool ret = true; adjusted_mode = drm_mode_duplicate(dev, mode); crtc->enabled = drm_helper_crtc_in_use(crtc); if (!crtc->enabled) return true; saved_mode = crtc->mode; saved_x = crtc->x; saved_y = crtc->y; /* Update crtc values up front so the driver can rely on them for mode * setting. */ crtc->mode = *mode; crtc->x = x; crtc->y = y; /* Pass our mode to the connectors and the CRTC to give them a chance to * adjust it according to limitations or connector properties, and also * a chance to reject the mode entirely. */ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { if (encoder->crtc != crtc) continue; encoder_funcs = encoder->helper_private; if (!(ret = encoder_funcs->mode_fixup(encoder, mode, adjusted_mode))) { goto done; } } if (!(ret = crtc_funcs->mode_fixup(crtc, mode, adjusted_mode))) { goto done; } /* Prepare the encoders and CRTCs before setting the mode. */ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { if (encoder->crtc != crtc) continue; encoder_funcs = encoder->helper_private; /* Disable the encoders as the first thing we do. */ encoder_funcs->prepare(encoder); } drm_crtc_prepare_encoders(dev); crtc_funcs->prepare(crtc); /* Set up the DPLL and any encoders state that needs to adjust or depend * on the DPLL. */ ret = !crtc_funcs->mode_set(crtc, mode, adjusted_mode, x, y, old_fb); if (!ret) goto done; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { if (encoder->crtc != crtc) continue; DRM_INFO("%s: set mode %s %x\n", drm_get_encoder_name(encoder), mode->name, mode->base.id); encoder_funcs = encoder->helper_private; encoder_funcs->mode_set(encoder, mode, adjusted_mode); } /* Now enable the clocks, plane, pipe, and connectors that we set up. */ crtc_funcs->commit(crtc); list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { if (encoder->crtc != crtc) continue; encoder_funcs = encoder->helper_private; encoder_funcs->commit(encoder); } /* XXX free adjustedmode */ drm_mode_destroy(dev, adjusted_mode); /* FIXME: add subpixel order */ done: if (!ret) { crtc->mode = saved_mode; crtc->x = saved_x; crtc->y = saved_y; } return ret; } EXPORT_SYMBOL(drm_crtc_helper_set_mode); /** * drm_crtc_helper_set_config - set a new config from userspace * @crtc: CRTC to setup * @crtc_info: user provided configuration * @new_mode: new mode to set * @connector_set: set of connectors for the new config * @fb: new framebuffer * * LOCKING: * Caller must hold mode config lock. * * Setup a new configuration, provided by the user in @crtc_info, and enable * it. * * RETURNS: * Zero. (FIXME) */ int drm_crtc_helper_set_config(struct drm_mode_set *set) { struct drm_device *dev; struct drm_crtc *save_crtcs, *new_crtc, *crtc; struct drm_encoder *save_encoders, *new_encoder, *encoder; struct drm_framebuffer *old_fb = NULL; bool mode_changed = false; /* if true do a full mode set */ bool fb_changed = false; /* if true and !mode_changed just do a flip */ struct drm_connector *save_connectors, *connector; int count = 0, ro, fail = 0; struct drm_crtc_helper_funcs *crtc_funcs; int ret = 0; DRM_DEBUG_KMS("\n"); if (!set) return -EINVAL; if (!set->crtc) return -EINVAL; if (!set->crtc->helper_private) return -EINVAL; crtc_funcs = set->crtc->helper_private; DRM_DEBUG_KMS("crtc: %p %d fb: %p connectors: %p num_connectors:" " %d (x, y) (%i, %i)\n", set->crtc, set->crtc->base.id, set->fb, set->connectors, (int)set->num_connectors, set->x, set->y); dev = set->crtc->dev; /* Allocate space for the backup of all (non-pointer) crtc, encoder and * connector data. */ save_crtcs = kzalloc(dev->mode_config.num_crtc * sizeof(struct drm_crtc), GFP_KERNEL); if (!save_crtcs) return -ENOMEM; save_encoders = kzalloc(dev->mode_config.num_encoder * sizeof(struct drm_encoder), GFP_KERNEL); if (!save_encoders) { kfree(save_crtcs); return -ENOMEM; } save_connectors = kzalloc(dev->mode_config.num_connector * sizeof(struct drm_connector), GFP_KERNEL); if (!save_connectors) { kfree(save_crtcs); kfree(save_encoders); return -ENOMEM; } /* Copy data. Note that driver private data is not affected. * Should anything bad happen only the expected state is * restored, not the drivers personal bookkeeping. */ count = 0; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { save_crtcs[count++] = *crtc; } count = 0; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { save_encoders[count++] = *encoder; } count = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { save_connectors[count++] = *connector; } /* We should be able to check here if the fb has the same properties * and then just flip_or_move it */ if (set->crtc->fb != set->fb) { /* If we have no fb then treat it as a full mode set */ if (set->crtc->fb == NULL) { DRM_DEBUG_KMS("crtc has no fb, full mode set\n"); mode_changed = true; } else if (set->fb == NULL) { mode_changed = true; } else if ((set->fb->bits_per_pixel != set->crtc->fb->bits_per_pixel) || set->fb->depth != set->crtc->fb->depth) fb_changed = true; else fb_changed = true; } if (set->x != set->crtc->x || set->y != set->crtc->y) fb_changed = true; if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { DRM_DEBUG_KMS("modes are different, full mode set\n"); drm_mode_debug_printmodeline(&set->crtc->mode); drm_mode_debug_printmodeline(set->mode); mode_changed = true; } /* a) traverse passed in connector list and get encoders for them */ count = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; new_encoder = connector->encoder; for (ro = 0; ro < set->num_connectors; ro++) { if (set->connectors[ro] == connector) { new_encoder = connector_funcs->best_encoder(connector); /* if we can't get an encoder for a connector we are setting now - then fail */ if (new_encoder == NULL) /* don't break so fail path works correct */ fail = 1; break; } } if (new_encoder != connector->encoder) { DRM_DEBUG_KMS("encoder changed, full mode switch\n"); mode_changed = true; /* If the encoder is reused for another connector, then * the appropriate crtc will be set later. */ if (connector->encoder) connector->encoder->crtc = NULL; connector->encoder = new_encoder; } } if (fail) { ret = -EINVAL; goto fail; } count = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { if (!connector->encoder) continue; if (connector->encoder->crtc == set->crtc) new_crtc = NULL; else new_crtc = connector->encoder->crtc; for (ro = 0; ro < set->num_connectors; ro++) { if (set->connectors[ro] == connector) new_crtc = set->crtc; } /* Make sure the new CRTC will work with the encoder */ if (new_crtc && !drm_encoder_crtc_ok(connector->encoder, new_crtc)) { ret = -EINVAL; goto fail; } if (new_crtc != connector->encoder->crtc) { DRM_DEBUG_KMS("crtc changed, full mode switch\n"); mode_changed = true; connector->encoder->crtc = new_crtc; } DRM_DEBUG_KMS("setting connector %d crtc to %p\n", connector->base.id, new_crtc); } /* mode_set_base is not a required function */ if (fb_changed && !crtc_funcs->mode_set_base) mode_changed = true; if (mode_changed) { old_fb = set->crtc->fb; set->crtc->fb = set->fb; set->crtc->enabled = (set->mode != NULL); if (set->mode != NULL) { DRM_DEBUG_KMS("attempting to set mode from" " userspace\n"); drm_mode_debug_printmodeline(set->mode); if (!drm_crtc_helper_set_mode(set->crtc, set->mode, set->x, set->y, old_fb)) { DRM_ERROR("failed to set mode on crtc %p\n", set->crtc); ret = -EINVAL; goto fail; } /* TODO are these needed? */ set->crtc->desired_x = set->x; set->crtc->desired_y = set->y; set->crtc->desired_mode = set->mode; } drm_helper_disable_unused_functions(dev); } else if (fb_changed) { set->crtc->x = set->x; set->crtc->y = set->y; old_fb = set->crtc->fb; if (set->crtc->fb != set->fb) set->crtc->fb = set->fb; ret = crtc_funcs->mode_set_base(set->crtc, set->x, set->y, old_fb); if (ret != 0) goto fail; } kfree(save_connectors); kfree(save_encoders); kfree(save_crtcs); return 0; fail: /* Restore all previous data. */ count = 0; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { *crtc = save_crtcs[count++]; } count = 0; list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { *encoder = save_encoders[count++]; } count = 0; list_for_each_entry(connector, &dev->mode_config.connector_list, head) { *connector = save_connectors[count++]; } kfree(save_connectors); kfree(save_encoders); kfree(save_crtcs); return ret; } EXPORT_SYMBOL(drm_crtc_helper_set_config); bool drm_helper_plugged_event(struct drm_device *dev) { DRM_DEBUG_KMS("\n"); drm_helper_probe_connector_modes(dev, dev->mode_config.max_width, dev->mode_config.max_height); drm_setup_crtcs(dev); /* alert the driver fb layer */ dev->mode_config.funcs->fb_changed(dev); /* FIXME: send hotplug event */ return true; } /** * drm_initial_config - setup a sane initial connector configuration * @dev: DRM device * * LOCKING: * Called at init time, must take mode config lock. * * Scan the CRTCs and connectors and try to put together an initial setup. * At the moment, this is a cloned configuration across all heads with * a new framebuffer object as the backing store. * * RETURNS: * Zero if everything went ok, nonzero otherwise. */ bool drm_helper_initial_config(struct drm_device *dev) { int count = 0; /* disable all the possible outputs/crtcs before entering KMS mode */ drm_helper_disable_unused_functions(dev); drm_fb_helper_parse_command_line(dev); count = drm_helper_probe_connector_modes(dev, dev->mode_config.max_width, dev->mode_config.max_height); /* * we shouldn't end up with no modes here. */ WARN(!count, "No connectors reported connected with modes\n"); drm_setup_crtcs(dev); /* alert the driver fb layer */ dev->mode_config.funcs->fb_changed(dev); return 0; } EXPORT_SYMBOL(drm_helper_initial_config); static int drm_helper_choose_encoder_dpms(struct drm_encoder *encoder) { int dpms = DRM_MODE_DPMS_OFF; struct drm_connector *connector; struct drm_device *dev = encoder->dev; list_for_each_entry(connector, &dev->mode_config.connector_list, head) if (connector->encoder == encoder) if (connector->dpms < dpms) dpms = connector->dpms; return dpms; } static int drm_helper_choose_crtc_dpms(struct drm_crtc *crtc) { int dpms = DRM_MODE_DPMS_OFF; struct drm_connector *connector; struct drm_device *dev = crtc->dev; list_for_each_entry(connector, &dev->mode_config.connector_list, head) if (connector->encoder && connector->encoder->crtc == crtc) if (connector->dpms < dpms) dpms = connector->dpms; return dpms; } /** * drm_helper_connector_dpms * @connector affected connector * @mode DPMS mode * * Calls the low-level connector DPMS function, then * calls appropriate encoder and crtc DPMS functions as well */ void drm_helper_connector_dpms(struct drm_connector *connector, int mode) { struct drm_encoder *encoder = connector->encoder; struct drm_crtc *crtc = encoder ? encoder->crtc : NULL; int old_dpms; if (mode == connector->dpms) return; old_dpms = connector->dpms; connector->dpms = mode; /* from off to on, do crtc then encoder */ if (mode < old_dpms) { if (crtc) { struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; if (crtc_funcs->dpms) (*crtc_funcs->dpms) (crtc, drm_helper_choose_crtc_dpms(crtc)); } if (encoder) { struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; if (encoder_funcs->dpms) (*encoder_funcs->dpms) (encoder, drm_helper_choose_encoder_dpms(encoder)); } } /* from on to off, do encoder then crtc */ if (mode > old_dpms) { if (encoder) { struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; if (encoder_funcs->dpms) (*encoder_funcs->dpms) (encoder, drm_helper_choose_encoder_dpms(encoder)); } if (crtc) { struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; if (crtc_funcs->dpms) (*crtc_funcs->dpms) (crtc, drm_helper_choose_crtc_dpms(crtc)); } } return; } EXPORT_SYMBOL(drm_helper_connector_dpms); /** * drm_hotplug_stage_two * @dev DRM device * @connector hotpluged connector * * LOCKING. * Caller must hold mode config lock, function might grab struct lock. * * Stage two of a hotplug. * * RETURNS: * Zero on success, errno on failure. */ int drm_helper_hotplug_stage_two(struct drm_device *dev) { drm_helper_plugged_event(dev); return 0; } EXPORT_SYMBOL(drm_helper_hotplug_stage_two); int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb, struct drm_mode_fb_cmd *mode_cmd) { fb->width = mode_cmd->width; fb->height = mode_cmd->height; fb->pitch = mode_cmd->pitch; fb->bits_per_pixel = mode_cmd->bpp; fb->depth = mode_cmd->depth; return 0; } EXPORT_SYMBOL(drm_helper_mode_fill_fb_struct); int drm_helper_resume_force_mode(struct drm_device *dev) { struct drm_crtc *crtc; int ret; list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { if (!crtc->enabled) continue; ret = drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb); if (ret == false) DRM_ERROR("failed to set mode on crtc %p\n", crtc); } /* disable the unused connectors while restoring the modesetting */ drm_helper_disable_unused_functions(dev); return 0; } EXPORT_SYMBOL(drm_helper_resume_force_mode);
[ "fera.volt@gmail.com" ]
fera.volt@gmail.com
8170a1ad05c748225e5ca9cb619a156c09b882ec
84edbd52ef40e333c506195c794f4f3a760da9ec
/libft/ft_putstr.c
8eb1a5e34c9dda9d3f9d17c1c72d55390dbf8fd4
[]
no_license
vnguyen42/rtv1_2
ed42f3bd727241b57b037af479302000788a70cb
7061af3441c228ec1bc30b7e91a6eda8615af26e
refs/heads/master
2021-01-21T13:03:33.191304
2016-04-21T13:59:54
2016-04-21T13:59:54
55,707,743
0
0
null
null
null
null
UTF-8
C
false
false
1,059
c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vnguyen <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/03/14 17:13:13 by vnguyen #+# #+# */ /* Updated: 2016/03/14 17:16:39 by vnguyen ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" #include <unistd.h> void ft_putstr(char const *s) { int a; a = 0; if (s != NULL) { while (s[a]) { write(1, &s[a], 1); a++; } } }
[ "vnguyen@e1r6p17.42.fr" ]
vnguyen@e1r6p17.42.fr
00473c460b2a0d64054e5543e5c551d64db55c6d
22c7be83e1ea0ed00cd1f78ffeedd9d1afcdf7cb
/src/z.h
69f7a6a1e13c4f6cd45e033021ca4b9bdbfe0ca7
[]
no_license
Red54/goagent-c
fd81ed40126faa349920baa1ec8cd3b1d24235a6
dbf5b89081aec7de4e149d36c8bac820f5b2a307
refs/heads/master
2021-01-24T04:28:37.963411
2012-05-27T10:34:22
2012-05-27T10:34:22
null
0
0
null
null
null
null
UTF-8
C
false
false
842
h
/* * z.h * * Copyright xubin * * Author : xubin <nybux.tsui@gmail.com> * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2.1 of the GNU Lesser General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "zlib.h" #include "buffer.h" z_stream * zcmp_open(); void zcmp_compress(z_stream *strm, char *in, uint32_t len, struct buffer *buffer); void zcmp_close(z_stream *strm, char *in, uint32_t len, struct buffer *buffer); z_stream * zexp_open(); void zexp_expand(z_stream *strm, char *in, uint32_t len, struct buffer *buffer); void zexp_close(z_stream *strm);
[ "nybux.tsui@gmail.com" ]
nybux.tsui@gmail.com
9d665925169a2c1be59ea01fb6fcada4ab57bd7c
4d8e085d57e84c3489241daccfb19ba326b5fd3b
/server/include/python2.6/pyconfig.h
7ae388913045561b03031d0b7ec7114a663d32b7
[]
no_license
ht101996/swiftarm
f0d68e26c3b280bdf7799bdd0907badd003b35c9
ee947895b85d086ecda6b0df82962267d627acde
refs/heads/master
2020-04-03T07:42:09.495660
2012-07-07T10:18:26
2012-07-07T10:18:26
null
0
0
null
null
null
null
UTF-8
C
false
false
30,948
h
/* pyconfig.h. Generated from pyconfig.h.in by configure. */ /* pyconfig.h.in. Generated from configure.in by autoheader. */ #ifndef Py_PYCONFIG_H #define Py_PYCONFIG_H /* Define for AIX if your compiler is a genuine IBM xlC/xlC_r and you want support for AIX C++ shared extension modules. */ /* #undef AIX_GENUINE_CPLUSPLUS */ /* Define this if you have AtheOS threads. */ /* #undef ATHEOS_THREADS */ /* Define this if you have BeOS threads. */ /* #undef BEOS_THREADS */ /* Define if you have the Mach cthreads package */ /* #undef C_THREADS */ /* Define if --enable-ipv6 is specified */ #define ENABLE_IPV6 1 /* Define if getpgrp() must be called as getpgrp(0). */ /* #undef GETPGRP_HAVE_ARG */ /* Define if gettimeofday() does not have second (timezone) argument This is the case on Motorola V4 (R40V4.2) */ /* #undef GETTIMEOFDAY_NO_TZ */ /* Define to 1 if you have the `acosh' function. */ #define HAVE_ACOSH 1 /* struct addrinfo (netdb.h) */ #define HAVE_ADDRINFO 1 /* Define to 1 if you have the `alarm' function. */ #define HAVE_ALARM 1 /* Define this if your time.h defines altzone. */ /* #undef HAVE_ALTZONE */ /* Define to 1 if you have the `asinh' function. */ #define HAVE_ASINH 1 /* Define to 1 if you have the <asm/types.h> header file. */ #define HAVE_ASM_TYPES_H 1 /* Define to 1 if you have the `atanh' function. */ #define HAVE_ATANH 1 /* Define if GCC supports __attribute__((format(PyArg_ParseTuple, 2, 3))) */ /* #undef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE */ /* Define to 1 if you have the `bind_textdomain_codeset' function. */ #define HAVE_BIND_TEXTDOMAIN_CODESET 1 /* Define to 1 if you have the <bluetooth/bluetooth.h> header file. */ #define HAVE_BLUETOOTH_BLUETOOTH_H 1 /* Define to 1 if you have the <bluetooth.h> header file. */ /* #undef HAVE_BLUETOOTH_H */ /* Define if nice() returns success/failure instead of the new priority. */ /* #undef HAVE_BROKEN_NICE */ /* Define if poll() sets errno on invalid file descriptors. */ /* #undef HAVE_BROKEN_POLL */ /* Define if the Posix semaphores do not work on your system */ /* #undef HAVE_BROKEN_POSIX_SEMAPHORES */ /* Define if pthread_sigmask() does not work on your system. */ /* #undef HAVE_BROKEN_PTHREAD_SIGMASK */ /* Define this if you have the type _Bool. */ #define HAVE_C99_BOOL 1 /* Define to 1 if you have the `chflags' function. */ /* #undef HAVE_CHFLAGS */ /* Define to 1 if you have the `chown' function. */ #define HAVE_CHOWN 1 /* Define if you have the 'chroot' function. */ #define HAVE_CHROOT 1 /* Define to 1 if you have the `clock' function. */ #define HAVE_CLOCK 1 /* Define to 1 if you have the `confstr' function. */ #define HAVE_CONFSTR 1 /* Define to 1 if you have the <conio.h> header file. */ /* #undef HAVE_CONIO_H */ /* Define to 1 if you have the `copysign' function. */ #define HAVE_COPYSIGN 1 /* Define to 1 if you have the `ctermid' function. */ #define HAVE_CTERMID 1 /* Define if you have the 'ctermid_r' function. */ /* #undef HAVE_CTERMID_R */ /* Define to 1 if you have the <curses.h> header file. */ #define HAVE_CURSES_H 1 /* Define if you have the 'is_term_resized' function. */ #define HAVE_CURSES_IS_TERM_RESIZED 1 /* Define if you have the 'resizeterm' function. */ #define HAVE_CURSES_RESIZETERM 1 /* Define if you have the 'resize_term' function. */ #define HAVE_CURSES_RESIZE_TERM 1 /* Define to 1 if you have the declaration of `isfinite', and to 0 if you don't. */ #define HAVE_DECL_ISFINITE 1 /* Define to 1 if you have the declaration of `isinf', and to 0 if you don't. */ #define HAVE_DECL_ISINF 1 /* Define to 1 if you have the declaration of `isnan', and to 0 if you don't. */ #define HAVE_DECL_ISNAN 1 /* Define to 1 if you have the declaration of `tzname', and to 0 if you don't. */ /* #undef HAVE_DECL_TZNAME */ /* Define to 1 if you have the device macros. */ #define HAVE_DEVICE_MACROS 1 /* Define if we have /dev/ptc. */ /* #undef HAVE_DEV_PTC */ /* Define if we have /dev/ptmx. */ #define HAVE_DEV_PTMX 1 /* Define to 1 if you have the <direct.h> header file. */ /* #undef HAVE_DIRECT_H */ /* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. */ #define HAVE_DIRENT_H 1 /* Define to 1 if you have the <dlfcn.h> header file. */ #define HAVE_DLFCN_H 1 /* Define to 1 if you have the `dlopen' function. */ #define HAVE_DLOPEN 1 /* Define to 1 if you have the `dup2' function. */ #define HAVE_DUP2 1 /* Defined when any dynamic module loading is enabled. */ #define HAVE_DYNAMIC_LOADING 1 /* Define if you have the 'epoll' functions. */ #define HAVE_EPOLL 1 /* Define to 1 if you have the <errno.h> header file. */ #define HAVE_ERRNO_H 1 /* Define to 1 if you have the `execv' function. */ #define HAVE_EXECV 1 /* Define to 1 if you have the `expm1' function. */ #define HAVE_EXPM1 1 /* Define if you have the 'fchdir' function. */ #define HAVE_FCHDIR 1 /* Define to 1 if you have the `fchmod' function. */ #define HAVE_FCHMOD 1 /* Define to 1 if you have the `fchown' function. */ #define HAVE_FCHOWN 1 /* Define to 1 if you have the <fcntl.h> header file. */ #define HAVE_FCNTL_H 1 /* Define if you have the 'fdatasync' function. */ #define HAVE_FDATASYNC 1 /* Define to 1 if you have the `finite' function. */ #define HAVE_FINITE 1 /* Define if you have the 'flock' function. */ #define HAVE_FLOCK 1 /* Define to 1 if you have the `fork' function. */ #define HAVE_FORK 1 /* Define to 1 if you have the `forkpty' function. */ #define HAVE_FORKPTY 1 /* Define to 1 if you have the `fpathconf' function. */ #define HAVE_FPATHCONF 1 /* Define to 1 if you have the `fseek64' function. */ /* #undef HAVE_FSEEK64 */ /* Define to 1 if you have the `fseeko' function. */ #define HAVE_FSEEKO 1 /* Define to 1 if you have the `fstatvfs' function. */ #define HAVE_FSTATVFS 1 /* Define if you have the 'fsync' function. */ #define HAVE_FSYNC 1 /* Define to 1 if you have the `ftell64' function. */ /* #undef HAVE_FTELL64 */ /* Define to 1 if you have the `ftello' function. */ #define HAVE_FTELLO 1 /* Define to 1 if you have the `ftime' function. */ #define HAVE_FTIME 1 /* Define to 1 if you have the `ftruncate' function. */ #define HAVE_FTRUNCATE 1 /* Define to 1 if you have the `gai_strerror' function. */ #define HAVE_GAI_STRERROR 1 /* Define if you have the getaddrinfo function. */ #define HAVE_GETADDRINFO 1 /* Define to 1 if you have the `getcwd' function. */ #define HAVE_GETCWD 1 /* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */ #define HAVE_GETC_UNLOCKED 1 /* Define to 1 if you have the `getgroups' function. */ #define HAVE_GETGROUPS 1 /* Define to 1 if you have the `gethostbyname' function. */ /* #undef HAVE_GETHOSTBYNAME */ /* Define this if you have some version of gethostbyname_r() */ #define HAVE_GETHOSTBYNAME_R 1 /* Define this if you have the 3-arg version of gethostbyname_r(). */ /* #undef HAVE_GETHOSTBYNAME_R_3_ARG */ /* Define this if you have the 5-arg version of gethostbyname_r(). */ /* #undef HAVE_GETHOSTBYNAME_R_5_ARG */ /* Define this if you have the 6-arg version of gethostbyname_r(). */ #define HAVE_GETHOSTBYNAME_R_6_ARG 1 /* Define to 1 if you have the `getitimer' function. */ #define HAVE_GETITIMER 1 /* Define to 1 if you have the `getloadavg' function. */ #define HAVE_GETLOADAVG 1 /* Define to 1 if you have the `getlogin' function. */ #define HAVE_GETLOGIN 1 /* Define to 1 if you have the `getnameinfo' function. */ #define HAVE_GETNAMEINFO 1 /* Define if you have the 'getpagesize' function. */ #define HAVE_GETPAGESIZE 1 /* Define to 1 if you have the `getpeername' function. */ #define HAVE_GETPEERNAME 1 /* Define to 1 if you have the `getpgid' function. */ #define HAVE_GETPGID 1 /* Define to 1 if you have the `getpgrp' function. */ #define HAVE_GETPGRP 1 /* Define to 1 if you have the `getpid' function. */ #define HAVE_GETPID 1 /* Define to 1 if you have the `getpriority' function. */ #define HAVE_GETPRIORITY 1 /* Define to 1 if you have the `getpwent' function. */ #define HAVE_GETPWENT 1 /* Define to 1 if you have the `getsid' function. */ #define HAVE_GETSID 1 /* Define to 1 if you have the `getspent' function. */ #define HAVE_GETSPENT 1 /* Define to 1 if you have the `getspnam' function. */ #define HAVE_GETSPNAM 1 /* Define to 1 if you have the `gettimeofday' function. */ #define HAVE_GETTIMEOFDAY 1 /* Define to 1 if you have the `getwd' function. */ #define HAVE_GETWD 1 /* Define to 1 if you have the <grp.h> header file. */ #define HAVE_GRP_H 1 /* Define if you have the 'hstrerror' function. */ #define HAVE_HSTRERROR 1 /* Define to 1 if you have the `hypot' function. */ #define HAVE_HYPOT 1 /* Define to 1 if you have the <ieeefp.h> header file. */ /* #undef HAVE_IEEEFP_H */ /* Define if you have the 'inet_aton' function. */ #define HAVE_INET_ATON 1 /* Define if you have the 'inet_pton' function. */ #define HAVE_INET_PTON 1 /* Define to 1 if you have the <inttypes.h> header file. */ #define HAVE_INTTYPES_H 1 /* Define to 1 if you have the <io.h> header file. */ /* #undef HAVE_IO_H */ /* Define to 1 if you have the `kill' function. */ #define HAVE_KILL 1 /* Define to 1 if you have the `killpg' function. */ #define HAVE_KILLPG 1 /* Define if you have the 'kqueue' functions. */ /* #undef HAVE_KQUEUE */ /* Define to 1 if you have the <langinfo.h> header file. */ #define HAVE_LANGINFO_H 1 /* Defined to enable large file support when an off_t is bigger than a long and long long is available and at least as big as an off_t. You may need to add some flags for configuration and compilation to enable this mode. (For Solaris and Linux, the necessary defines are already defined.) */ #define HAVE_LARGEFILE_SUPPORT 1 /* Define to 1 if you have the `lchflags' function. */ /* #undef HAVE_LCHFLAGS */ /* Define to 1 if you have the `lchmod' function. */ /* #undef HAVE_LCHMOD */ /* Define to 1 if you have the `lchown' function. */ #define HAVE_LCHOWN 1 /* Define to 1 if you have the `dl' library (-ldl). */ #define HAVE_LIBDL 1 /* Define to 1 if you have the `dld' library (-ldld). */ /* #undef HAVE_LIBDLD */ /* Define to 1 if you have the `ieee' library (-lieee). */ /* #undef HAVE_LIBIEEE */ /* Define to 1 if you have the <libintl.h> header file. */ #define HAVE_LIBINTL_H 1 /* Define if you have the readline library (-lreadline). */ #define HAVE_LIBREADLINE 1 /* Define to 1 if you have the `resolv' library (-lresolv). */ /* #undef HAVE_LIBRESOLV */ /* Define to 1 if you have the <libutil.h> header file. */ /* #undef HAVE_LIBUTIL_H */ /* Define if you have the 'link' function. */ #define HAVE_LINK 1 /* Define to 1 if you have the <linux/netlink.h> header file. */ #define HAVE_LINUX_NETLINK_H 1 /* Define to 1 if you have the <linux/tipc.h> header file. */ #define HAVE_LINUX_TIPC_H 1 /* Define to 1 if you have the `log1p' function. */ #define HAVE_LOG1P 1 /* Define this if you have the type long double. */ #define HAVE_LONG_DOUBLE 1 /* Define this if you have the type long long. */ #define HAVE_LONG_LONG 1 /* Define to 1 if you have the `lstat' function. */ #define HAVE_LSTAT 1 /* Define this if you have the makedev macro. */ #define HAVE_MAKEDEV 1 /* Define to 1 if you have the `memmove' function. */ #define HAVE_MEMMOVE 1 /* Define to 1 if you have the <memory.h> header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the `mkfifo' function. */ #define HAVE_MKFIFO 1 /* Define to 1 if you have the `mknod' function. */ #define HAVE_MKNOD 1 /* Define to 1 if you have the `mktime' function. */ #define HAVE_MKTIME 1 /* Define to 1 if you have the `mremap' function. */ #define HAVE_MREMAP 1 /* Define to 1 if you have the <ncurses.h> header file. */ #define HAVE_NCURSES_H 1 /* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ /* #undef HAVE_NDIR_H */ /* Define to 1 if you have the <netpacket/packet.h> header file. */ #define HAVE_NETPACKET_PACKET_H 1 /* Define to 1 if you have the `nice' function. */ #define HAVE_NICE 1 /* Define to 1 if you have the `openpty' function. */ #define HAVE_OPENPTY 1 /* Define if compiling using MacOS X 10.5 SDK or later. */ /* #undef HAVE_OSX105_SDK */ /* Define to 1 if you have the `pathconf' function. */ #define HAVE_PATHCONF 1 /* Define to 1 if you have the `pause' function. */ #define HAVE_PAUSE 1 /* Define to 1 if you have the `plock' function. */ /* #undef HAVE_PLOCK */ /* Define to 1 if you have the `poll' function. */ #define HAVE_POLL 1 /* Define to 1 if you have the <poll.h> header file. */ #define HAVE_POLL_H 1 /* Define to 1 if you have the <process.h> header file. */ /* #undef HAVE_PROCESS_H */ /* Define if your compiler supports function prototype */ #define HAVE_PROTOTYPES 1 /* Define if you have GNU PTH threads. */ /* #undef HAVE_PTH */ /* Defined for Solaris 2.6 bug in pthread header. */ /* #undef HAVE_PTHREAD_DESTRUCTOR */ /* Define to 1 if you have the <pthread.h> header file. */ #define HAVE_PTHREAD_H 1 /* Define to 1 if you have the `pthread_init' function. */ /* #undef HAVE_PTHREAD_INIT */ /* Define to 1 if you have the `pthread_sigmask' function. */ #define HAVE_PTHREAD_SIGMASK 1 /* Define to 1 if you have the <pty.h> header file. */ #define HAVE_PTY_H 1 /* Define to 1 if you have the `putenv' function. */ #define HAVE_PUTENV 1 /* Define to 1 if you have the `readlink' function. */ #define HAVE_READLINK 1 /* Define to 1 if you have the `realpath' function. */ #define HAVE_REALPATH 1 /* Define if you have readline 2.1 */ #define HAVE_RL_CALLBACK 1 /* Define if you can turn off readline's signal handling. */ #define HAVE_RL_CATCH_SIGNAL 1 /* Define if you have readline 2.2 */ #define HAVE_RL_COMPLETION_APPEND_CHARACTER 1 /* Define if you have readline 4.0 */ #define HAVE_RL_COMPLETION_DISPLAY_MATCHES_HOOK 1 /* Define if you have readline 4.2 */ #define HAVE_RL_COMPLETION_MATCHES 1 /* Define if you have readline 4.0 */ #define HAVE_RL_PRE_INPUT_HOOK 1 /* Define to 1 if you have the `select' function. */ #define HAVE_SELECT 1 /* Define to 1 if you have the `setegid' function. */ #define HAVE_SETEGID 1 /* Define to 1 if you have the `seteuid' function. */ #define HAVE_SETEUID 1 /* Define to 1 if you have the `setgid' function. */ #define HAVE_SETGID 1 /* Define if you have the 'setgroups' function. */ #define HAVE_SETGROUPS 1 /* Define to 1 if you have the `setitimer' function. */ #define HAVE_SETITIMER 1 /* Define to 1 if you have the `setlocale' function. */ #define HAVE_SETLOCALE 1 /* Define to 1 if you have the `setpgid' function. */ #define HAVE_SETPGID 1 /* Define to 1 if you have the `setpgrp' function. */ #define HAVE_SETPGRP 1 /* Define to 1 if you have the `setregid' function. */ #define HAVE_SETREGID 1 /* Define to 1 if you have the `setreuid' function. */ #define HAVE_SETREUID 1 /* Define to 1 if you have the `setsid' function. */ #define HAVE_SETSID 1 /* Define to 1 if you have the `setuid' function. */ #define HAVE_SETUID 1 /* Define to 1 if you have the `setvbuf' function. */ #define HAVE_SETVBUF 1 /* Define to 1 if you have the <shadow.h> header file. */ #define HAVE_SHADOW_H 1 /* Define to 1 if you have the `sigaction' function. */ #define HAVE_SIGACTION 1 /* Define to 1 if you have the `siginterrupt' function. */ #define HAVE_SIGINTERRUPT 1 /* Define to 1 if you have the <signal.h> header file. */ #define HAVE_SIGNAL_H 1 /* Define to 1 if you have the `sigrelse' function. */ #define HAVE_SIGRELSE 1 /* Define to 1 if you have the `snprintf' function. */ #define HAVE_SNPRINTF 1 /* Define if sockaddr has sa_len member */ /* #undef HAVE_SOCKADDR_SA_LEN */ /* struct sockaddr_storage (sys/socket.h) */ #define HAVE_SOCKADDR_STORAGE 1 /* Define if you have the 'socketpair' function. */ #define HAVE_SOCKETPAIR 1 /* Define if your compiler provides ssize_t */ #define HAVE_SSIZE_T 1 /* Define to 1 if you have the `statvfs' function. */ #define HAVE_STATVFS 1 /* Define if you have struct stat.st_mtim.tv_nsec */ #define HAVE_STAT_TV_NSEC 1 /* Define if you have struct stat.st_mtimensec */ /* #undef HAVE_STAT_TV_NSEC2 */ /* Define if your compiler supports variable length function prototypes (e.g. void fprintf(FILE *, char *, ...);) *and* <stdarg.h> */ #define HAVE_STDARG_PROTOTYPES 1 /* Define to 1 if you have the <stdint.h> header file. */ #define HAVE_STDINT_H 1 /* Define to 1 if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H 1 /* Define to 1 if you have the `strdup' function. */ #define HAVE_STRDUP 1 /* Define to 1 if you have the `strftime' function. */ #define HAVE_STRFTIME 1 /* Define to 1 if you have the <strings.h> header file. */ #define HAVE_STRINGS_H 1 /* Define to 1 if you have the <string.h> header file. */ #define HAVE_STRING_H 1 /* Define to 1 if you have the <stropts.h> header file. */ #define HAVE_STROPTS_H 1 /* Define to 1 if `st_birthtime' is member of `struct stat'. */ /* #undef HAVE_STRUCT_STAT_ST_BIRTHTIME */ /* Define to 1 if `st_blksize' is member of `struct stat'. */ #define HAVE_STRUCT_STAT_ST_BLKSIZE 1 /* Define to 1 if `st_blocks' is member of `struct stat'. */ #define HAVE_STRUCT_STAT_ST_BLOCKS 1 /* Define to 1 if `st_flags' is member of `struct stat'. */ /* #undef HAVE_STRUCT_STAT_ST_FLAGS */ /* Define to 1 if `st_gen' is member of `struct stat'. */ /* #undef HAVE_STRUCT_STAT_ST_GEN */ /* Define to 1 if `st_rdev' is member of `struct stat'. */ #define HAVE_STRUCT_STAT_ST_RDEV 1 /* Define to 1 if `tm_zone' is member of `struct tm'. */ #define HAVE_STRUCT_TM_TM_ZONE 1 /* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use `HAVE_STRUCT_STAT_ST_BLOCKS' instead. */ #define HAVE_ST_BLOCKS 1 /* Define if you have the 'symlink' function. */ #define HAVE_SYMLINK 1 /* Define to 1 if you have the `sysconf' function. */ #define HAVE_SYSCONF 1 /* Define to 1 if you have the <sysexits.h> header file. */ #define HAVE_SYSEXITS_H 1 /* Define to 1 if you have the <sys/audioio.h> header file. */ /* #undef HAVE_SYS_AUDIOIO_H */ /* Define to 1 if you have the <sys/bsdtty.h> header file. */ /* #undef HAVE_SYS_BSDTTY_H */ /* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. */ /* #undef HAVE_SYS_DIR_H */ /* Define to 1 if you have the <sys/epoll.h> header file. */ #define HAVE_SYS_EPOLL_H 1 /* Define to 1 if you have the <sys/event.h> header file. */ /* #undef HAVE_SYS_EVENT_H */ /* Define to 1 if you have the <sys/file.h> header file. */ #define HAVE_SYS_FILE_H 1 /* Define to 1 if you have the <sys/loadavg.h> header file. */ /* #undef HAVE_SYS_LOADAVG_H */ /* Define to 1 if you have the <sys/lock.h> header file. */ /* #undef HAVE_SYS_LOCK_H */ /* Define to 1 if you have the <sys/mkdev.h> header file. */ /* #undef HAVE_SYS_MKDEV_H */ /* Define to 1 if you have the <sys/modem.h> header file. */ /* #undef HAVE_SYS_MODEM_H */ /* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. */ /* #undef HAVE_SYS_NDIR_H */ /* Define to 1 if you have the <sys/param.h> header file. */ #define HAVE_SYS_PARAM_H 1 /* Define to 1 if you have the <sys/poll.h> header file. */ #define HAVE_SYS_POLL_H 1 /* Define to 1 if you have the <sys/resource.h> header file. */ #define HAVE_SYS_RESOURCE_H 1 /* Define to 1 if you have the <sys/select.h> header file. */ #define HAVE_SYS_SELECT_H 1 /* Define to 1 if you have the <sys/socket.h> header file. */ #define HAVE_SYS_SOCKET_H 1 /* Define to 1 if you have the <sys/statvfs.h> header file. */ #define HAVE_SYS_STATVFS_H 1 /* Define to 1 if you have the <sys/stat.h> header file. */ #define HAVE_SYS_STAT_H 1 /* Define to 1 if you have the <sys/termio.h> header file. */ /* #undef HAVE_SYS_TERMIO_H */ /* Define to 1 if you have the <sys/times.h> header file. */ #define HAVE_SYS_TIMES_H 1 /* Define to 1 if you have the <sys/time.h> header file. */ #define HAVE_SYS_TIME_H 1 /* Define to 1 if you have the <sys/types.h> header file. */ #define HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the <sys/un.h> header file. */ #define HAVE_SYS_UN_H 1 /* Define to 1 if you have the <sys/utsname.h> header file. */ #define HAVE_SYS_UTSNAME_H 1 /* Define to 1 if you have the <sys/wait.h> header file. */ #define HAVE_SYS_WAIT_H 1 /* Define to 1 if you have the `tcgetpgrp' function. */ #define HAVE_TCGETPGRP 1 /* Define to 1 if you have the `tcsetpgrp' function. */ #define HAVE_TCSETPGRP 1 /* Define to 1 if you have the `tempnam' function. */ #define HAVE_TEMPNAM 1 /* Define to 1 if you have the <termios.h> header file. */ #define HAVE_TERMIOS_H 1 /* Define to 1 if you have the <term.h> header file. */ #define HAVE_TERM_H 1 /* Define to 1 if you have the <thread.h> header file. */ /* #undef HAVE_THREAD_H */ /* Define to 1 if you have the `timegm' function. */ #define HAVE_TIMEGM 1 /* Define to 1 if you have the `times' function. */ #define HAVE_TIMES 1 /* Define to 1 if you have the `tmpfile' function. */ #define HAVE_TMPFILE 1 /* Define to 1 if you have the `tmpnam' function. */ #define HAVE_TMPNAM 1 /* Define to 1 if you have the `tmpnam_r' function. */ #define HAVE_TMPNAM_R 1 /* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use `HAVE_STRUCT_TM_TM_ZONE' instead. */ #define HAVE_TM_ZONE 1 /* Define to 1 if you have the `truncate' function. */ #define HAVE_TRUNCATE 1 /* Define to 1 if you don't have `tm_zone' but do have the external array `tzname'. */ /* #undef HAVE_TZNAME */ /* Define this if you have tcl and TCL_UTF_MAX==6 */ /* #undef HAVE_UCS4_TCL */ /* Define to 1 if the system has the type `uintptr_t'. */ #define HAVE_UINTPTR_T 1 /* Define to 1 if you have the `uname' function. */ #define HAVE_UNAME 1 /* Define to 1 if you have the <unistd.h> header file. */ #define HAVE_UNISTD_H 1 /* Define to 1 if you have the `unsetenv' function. */ #define HAVE_UNSETENV 1 /* Define if you have a useable wchar_t type defined in wchar.h; useable means wchar_t must be an unsigned type with at least 16 bits. (see Include/unicodeobject.h). */ #define HAVE_USABLE_WCHAR_T 1 /* Define to 1 if you have the `utimes' function. */ #define HAVE_UTIMES 1 /* Define to 1 if you have the <utime.h> header file. */ #define HAVE_UTIME_H 1 /* Define to 1 if you have the `wait3' function. */ #define HAVE_WAIT3 1 /* Define to 1 if you have the `wait4' function. */ #define HAVE_WAIT4 1 /* Define to 1 if you have the `waitpid' function. */ #define HAVE_WAITPID 1 /* Define if the compiler provides a wchar.h header file. */ #define HAVE_WCHAR_H 1 /* Define to 1 if you have the `wcscoll' function. */ #define HAVE_WCSCOLL 1 /* Define if tzset() actually switches the local timezone in a meaningful way. */ #define HAVE_WORKING_TZSET 1 /* Define if the zlib library has inflateCopy */ #define HAVE_ZLIB_COPY 1 /* Define to 1 if you have the `_getpty' function. */ /* #undef HAVE__GETPTY */ /* Define if you are using Mach cthreads directly under /include */ /* #undef HURD_C_THREADS */ /* Define if you are using Mach cthreads under mach / */ /* #undef MACH_C_THREADS */ /* Define to 1 if `major', `minor', and `makedev' are declared in <mkdev.h>. */ /* #undef MAJOR_IN_MKDEV */ /* Define to 1 if `major', `minor', and `makedev' are declared in <sysmacros.h>. */ /* #undef MAJOR_IN_SYSMACROS */ /* Define if mvwdelch in curses.h is an expression. */ #define MVWDELCH_IS_EXPRESSION 1 /* Define to the address where bug reports for this package should be sent. */ /* #undef PACKAGE_BUGREPORT */ /* Define to the full name of this package. */ /* #undef PACKAGE_NAME */ /* Define to the full name and version of this package. */ /* #undef PACKAGE_STRING */ /* Define to the one symbol short name of this package. */ /* #undef PACKAGE_TARNAME */ /* Define to the version of this package. */ /* #undef PACKAGE_VERSION */ /* Defined if PTHREAD_SCOPE_SYSTEM supported. */ #define PTHREAD_SYSTEM_SCHED_SUPPORTED 1 /* Define to printf format modifier for Py_ssize_t */ #define PY_FORMAT_SIZE_T "z" /* Define as the integral type used for Unicode representation. */ #define PY_UNICODE_TYPE wchar_t /* Define if you want to build an interpreter with many run-time checks. */ /* #undef Py_DEBUG */ /* Defined if Python is built as a shared library. */ /* #undef Py_ENABLE_SHARED */ /* Define as the size of the unicode type. */ #define Py_UNICODE_SIZE 4 /* Define if you want to have a Unicode type. */ #define Py_USING_UNICODE 1 /* Define as the return type of signal handlers (`int' or `void'). */ #define RETSIGTYPE void /* Define if setpgrp() must be called as setpgrp(0, 0). */ /* #undef SETPGRP_HAVE_ARG */ /* Define this to be extension of shared libraries (including the dot!). */ #define SHLIB_EXT ".so" /* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ /* #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS */ /* The size of `double', as computed by sizeof. */ #define SIZEOF_DOUBLE 8 /* The size of `float', as computed by sizeof. */ #define SIZEOF_FLOAT 4 /* The size of `fpos_t', as computed by sizeof. */ #define SIZEOF_FPOS_T 16 /* The size of `int', as computed by sizeof. */ #define SIZEOF_INT 4 /* The size of `long', as computed by sizeof. */ #define SIZEOF_LONG 4 /* The size of `long double', as computed by sizeof. */ #define SIZEOF_LONG_DOUBLE 8 /* The size of `long long', as computed by sizeof. */ #define SIZEOF_LONG_LONG 8 /* The number of bytes in an off_t. */ #define SIZEOF_OFF_T 8 /* The size of `pid_t', as computed by sizeof. */ #define SIZEOF_PID_T 4 /* The number of bytes in a pthread_t. */ #define SIZEOF_PTHREAD_T 4 /* The size of `short', as computed by sizeof. */ #define SIZEOF_SHORT 2 /* The size of `size_t', as computed by sizeof. */ #define SIZEOF_SIZE_T 4 /* The number of bytes in a time_t. */ #define SIZEOF_TIME_T 4 /* The size of `uintptr_t', as computed by sizeof. */ #define SIZEOF_UINTPTR_T 4 /* The size of `void *', as computed by sizeof. */ #define SIZEOF_VOID_P 4 /* The size of `wchar_t', as computed by sizeof. */ #define SIZEOF_WCHAR_T 4 /* The size of `_Bool', as computed by sizeof. */ #define SIZEOF__BOOL 1 /* Define to 1 if you have the ANSI C header files. */ #define STDC_HEADERS 1 /* Define if you can safely include both <sys/select.h> and <sys/time.h> (which you can't on SCO ODT 3.0). */ #define SYS_SELECT_WITH_SYS_TIME 1 /* Define if tanh(-0.) is -0., or if platform doesn't have signed zeros */ #define TANH_PRESERVES_ZERO_SIGN 1 /* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */ #define TIME_WITH_SYS_TIME 1 /* Define to 1 if your <sys/time.h> declares `struct tm'. */ /* #undef TM_IN_SYS_TIME */ /* Define if you want to use MacPython modules on MacOSX in unix-Python. */ /* #undef USE_TOOLBOX_OBJECT_GLUE */ /* Define if a va_list is an array of some kind */ /* #undef VA_LIST_IS_ARRAY */ /* Define if you want SIGFPE handled (see Include/pyfpe.h). */ #define WANT_SIGFPE_HANDLER 1 /* Define if you want wctype.h functions to be used instead of the one supplied by Python itself. (see Include/unicodectype.h). */ /* #undef WANT_WCTYPE_FUNCTIONS */ /* Define if WINDOW in curses.h offers a field _flags. */ #define WINDOW_HAS_FLAGS 1 /* Define if you want documentation strings in extension modules */ #define WITH_DOC_STRINGS 1 /* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) dynamic linker (dyld) instead of the old-style (NextStep) dynamic linker (rld). Dyld is necessary to support frameworks. */ /* #undef WITH_DYLD */ /* Define to 1 if libintl is needed for locale functions. */ /* #undef WITH_LIBINTL */ /* Define if you want to produce an OpenStep/Rhapsody framework (shared library plus accessory files). */ /* #undef WITH_NEXT_FRAMEWORK */ /* Define if you want to compile in Python-specific mallocs */ #define WITH_PYMALLOC 1 /* Define if you want to compile in rudimentary thread support */ #define WITH_THREAD 1 /* Define to profile with the Pentium timestamp counter */ /* #undef WITH_TSC */ /* Define to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ /* #undef WORDS_BIGENDIAN */ /* Define if arithmetic is subject to x87-style double rounding issue */ /* #undef X87_DOUBLE_ROUNDING */ /* Define to 1 if on AIX 3. System headers sometimes define this. We just want to avoid a redefinition error message. */ #ifndef _ALL_SOURCE # define _ALL_SOURCE 1 #endif /* Define on OpenBSD to activate all library features */ /* #undef _BSD_SOURCE */ /* Define on Irix to enable u_int */ #define _BSD_TYPES 1 /* Define on Darwin to activate all library features */ #define _DARWIN_C_SOURCE 1 /* This must be set to 64 on some systems to enable large file support. */ #define _FILE_OFFSET_BITS 64 /* Define on Linux to activate all library features */ #define _GNU_SOURCE 1 /* This must be defined on some systems to enable large file support. */ #define _LARGEFILE_SOURCE 1 /* Define on NetBSD to activate all library features */ #define _NETBSD_SOURCE 1 /* Define _OSF_SOURCE to get the makedev macro. */ /* #undef _OSF_SOURCE */ /* Define to activate features from IEEE Stds 1003.1-2001 */ #define _POSIX_C_SOURCE 200112L /* Define if you have POSIX threads, and your system does not define that. */ /* #undef _POSIX_THREADS */ /* Define to force use of thread-safe errno, h_errno, and other functions */ /* #undef _REENTRANT */ /* Define to the level of X/Open that your system supports */ #define _XOPEN_SOURCE 600 /* Define to activate Unix95-and-earlier features */ #define _XOPEN_SOURCE_EXTENDED 1 /* Define on FreeBSD to activate all library features */ #define __BSD_VISIBLE 1 /* Define to 1 if type `char' is unsigned and you are not using gcc. */ #ifndef __CHAR_UNSIGNED__ /* # undef __CHAR_UNSIGNED__ */ #endif /* Defined on Solaris to see additional function prototypes. */ #define __EXTENSIONS__ 1 /* Define to 'long' if <time.h> doesn't define. */ /* #undef clock_t */ /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ /* Define to `int' if <sys/types.h> doesn't define. */ /* #undef gid_t */ /* Define to `int' if <sys/types.h> does not define. */ /* #undef mode_t */ /* Define to `long int' if <sys/types.h> does not define. */ /* #undef off_t */ /* Define to `int' if <sys/types.h> does not define. */ /* #undef pid_t */ /* Define to empty if the keyword does not work. */ /* #undef signed */ /* Define to `unsigned int' if <sys/types.h> does not define. */ /* #undef size_t */ /* Define to `int' if <sys/socket.h> does not define. */ /* #undef socklen_t */ /* Define to `int' if <sys/types.h> doesn't define. */ /* #undef uid_t */ /* Define to empty if the keyword does not work. */ /* #undef volatile */ /* Define the macros needed if on a UnixWare 7.x system. */ #if defined(__USLC__) && defined(__SCO_VERSION__) #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ #endif #endif /*Py_PYCONFIG_H*/
[ "jethrotan20@gmail.com" ]
jethrotan20@gmail.com
7b4b2ac77c8aaa5245a31844890c4a95ff76f46e
337efd39378fee8708bb59f4b9056fd51b92df57
/2_Data_Extraction/4_3DTracking/Micro_bubble_tracking/codegen/mex/BubbleCenterAndSize/BubbleCenterAndSize_data.c
902aa003bfc64c0763f22c59b3d2edec8697a702
[]
no_license
alexlib/MATLAB
d958d642c6ff8be7a93eaac149cff43bd582e846
31eef988d79a1d057c9405a750373c0c4c27b729
refs/heads/master
2021-12-14T09:17:08.514096
2021-12-02T15:34:39
2021-12-02T15:34:39
246,120,137
1
0
null
2020-03-09T19:08:29
2020-03-09T19:08:28
null
UTF-8
C
false
false
3,545
c
/* * Academic License - for use in teaching, academic research, and meeting * course requirements at degree granting institutions only. Not for * government, commercial, or other organizational use. * * BubbleCenterAndSize_data.c * * Code generation for function 'BubbleCenterAndSize_data' * */ /* Include files */ #include "BubbleCenterAndSize_data.h" #include "BubbleCenterAndSize.h" #include "rt_nonfinite.h" /* Variable Definitions */ emlrtCTX emlrtRootTLSGlobal = NULL; emlrtContext emlrtContextGlobal = { true,/* bFirstTime */ false, /* bInitialized */ 131594U, /* fVersionInfo */ NULL, /* fErrorFunction */ "BubbleCenterAndSize", /* fFunctionName */ NULL, /* fRTCallStack */ false, /* bDebugMode */ { 1858410525U, 2505464270U, 328108647U, 1256672073U },/* fSigWrd */ NULL /* fSigMem */ }; emlrtRSInfo w_emlrtRSI = { 21, /* lineNo */ "eml_int_forloop_overflow_check", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\eml\\eml_int_forloop_overflow_check.m"/* pathName */ }; emlrtRSInfo x_emlrtRSI = { 20, /* lineNo */ "sum", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\sum.m"/* pathName */ }; emlrtRSInfo y_emlrtRSI = { 99, /* lineNo */ "sumprod", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\sumprod.m"/* pathName */ }; emlrtRSInfo ab_emlrtRSI = { 125, /* lineNo */ "combineVectorElements", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\combineVectorElements.m"/* pathName */ }; emlrtRSInfo bb_emlrtRSI = { 185, /* lineNo */ "colMajorFlatIter", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\combineVectorElements.m"/* pathName */ }; emlrtRSInfo cb_emlrtRSI = { 14, /* lineNo */ "cumsum", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\cumsum.m"/* pathName */ }; emlrtRSInfo db_emlrtRSI = { 16, /* lineNo */ "cumop", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\cumop.m"/* pathName */ }; emlrtRSInfo gb_emlrtRSI = { 125, /* lineNo */ "looper", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\cumop.m"/* pathName */ }; emlrtRSInfo hb_emlrtRSI = { 290, /* lineNo */ "vcumop", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\cumop.m"/* pathName */ }; emlrtRSInfo mc_emlrtRSI = { 45, /* lineNo */ "mpower", /* fcnName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\ops\\mpower.m"/* pathName */ }; emlrtRTEInfo d_emlrtRTEI = { 46, /* lineNo */ 23, /* colNo */ "sumprod", /* fName */ "C:\\Program Files\\MATLAB\\R2020a\\toolbox\\eml\\lib\\matlab\\datafun\\private\\sumprod.m"/* pName */ }; covrtInstance emlrtCoverageInstance; /* End of code generation (BubbleCenterAndSize_data.c) */
[ "tan_shiyong@126.com" ]
tan_shiyong@126.com
bb815e1e9317253f35f74dea10ef6905ec16e0ba
2ce2fbcf81d55691e61a0c2da10a8a351e9170af
/src/libxml2-v2.9.10/libxml2-v2.9.10/macos/config.h
9eafcaabca55029fdba39461c656811eff87af89
[ "MIT" ]
permissive
ultralight-ux/WebCore-deps
6675d28fb623432262c34bde2f9dcca19ba3d04a
5faee7e9acb38cd0e973e3aca5c7095cc58b9ced
refs/heads/master
2023-08-05T03:16:25.717272
2023-07-20T18:36:38
2023-07-20T18:36:38
179,178,441
3
6
null
2021-12-29T07:05:55
2019-04-03T00:15:23
C
UTF-8
C
false
false
3,594
h
/* config.h generated manually for macos. */ /* Define if you have the strftime function. */ #define HAVE_STRFTIME /* Define if you have the ANSI C header files. */ #define STDC_HEADERS #define PACKAGE #define VERSION #undef HAVE_LIBZ #undef HAVE_LIBM #undef HAVE_ISINF #undef HAVE_ISNAN #undef HAVE_LIBHISTORY #undef HAVE_LIBREADLINE #define XML_SOCKLEN_T socklen_t #define HAVE_LIBPTHREAD #define HAVE_PTHREAD_H #define LIBXML_THREAD_ENABLED /* Define if you have the fprintf function. */ #define HAVE_FPRINTF /* Define if you have the localtime function. */ #define HAVE_LOCALTIME /* Define if you have the printf function. */ #define HAVE_PRINTF /* Define if you have the signal function. */ #define HAVE_SIGNAL /* Define if you have the snprintf function. */ #define HAVE_SNPRINTF /* Define if you have the sprintf function. */ #define HAVE_SPRINTF /* Define if you have the sscanf function. */ #define HAVE_SSCANF /* Define if you have the stat function. */ #define HAVE_STAT /* Define if you have the strftime function. */ #define HAVE_STRFTIME /* Define if you have the vfprintf function. */ #define HAVE_VFPRINTF /* Define if you have the vsnprintf function. */ #define HAVE_VSNPRINTF /* Define if you have the vsprintf function. */ #define HAVE_VSPRINTF /* Define if you have the <arpa/inet.h> header file. */ #define HAVE_ARPA_INET_H /* Define if you have the <ctype.h> header file. */ #define HAVE_CTYPE_H /* Define if you have the <dirent.h> header file. */ #define HAVE_DIRENT_H /* Define if you have the <dlfcn.h> header file. */ #define HAVE_DLFCN_H /* Define if you have the <errno.h> header file. */ #define HAVE_ERRNO_H /* Define if you have the <fcntl.h> header file. */ #define HAVE_FCNTL_H /* Define if you have the <float.h> header file. */ #define HAVE_FLOAT_H /* Define if you have the <malloc.h> header file. */ #undef HAVE_MALLOC_H /* Define if you have the <math.h> header file. */ #define HAVE_MATH_H /* Define if you have the <ndir.h> header file. */ #define HAVE_NDIR_H /* Define if you have the <netdb.h> header file. */ #define HAVE_NETDB_H /* Define if you have the <netinet/in.h> header file. */ #define HAVE_NETINET_IN_H /* Define if you have the <signal.h> header file. */ #define HAVE_SIGNAL_H /* Define if you have the <stdarg.h> header file. */ #define HAVE_STDARG_H /* Define if you have the <stdlib.h> header file. */ #define HAVE_STDLIB_H /* Define if you have the <string.h> header file. */ #define HAVE_STRING_H /* Define if you have the <sys/dir.h> header file. */ #define HAVE_SYS_DIR_H /* Define if you have the <sys/mman.h> header file. */ #undef HAVE_SYS_MMAN_H /* Define if you have the <sys/ndir.h> header file. */ #undef HAVE_SYS_NDIR_H /* Define if you have the <sys/select.h> header file. */ #define HAVE_SYS_SELECT_H /* Define if you have the <sys/socket.h> header file. */ #define HAVE_SYS_SOCKET_H /* Define if you have the <sys/stat.h> header file. */ #define HAVE_SYS_STAT_H /* Define if you have the <sys/time.h> header file. */ #define HAVE_SYS_TIME_H /* Define if you have the <sys/types.h> header file. */ #define HAVE_SYS_TYPES_H /* Define if you have the <time.h> header file. */ #define HAVE_TIME_H /* Define if you have the <unistd.h> header file. */ #define HAVE_UNISTD_H /* Name of package */ #define PACKAGE /* Version number of package */ #define VERSION /* Define if compiler has function prototypes */ #define PROTOTYPES #include <libxml/xmlversion.h> #include <sys/types.h> //#include <extra/stricmp.h> //#include <extra/strdup.h>
[ "hi@adamjsimmons.com" ]
hi@adamjsimmons.com
d49d51b7e953f26d241816e78c26565ac13abd69
ff64759db1838f9b7f362bad11c78916870a58c9
/LIB/mpfun++/test/mp_fftcmp.C
667b44220a06874b2cbc8db85271d7a7ba58e773
[]
no_license
mfrosenberg68/WorkRegOld
ee0dbacb733b220e9d6e1a45e41a422c17b69737
4b10cabeb6a9e2822b8c59dfe23af93c109a05c2
refs/heads/master
2021-01-13T02:22:20.682198
2015-08-30T02:46:00
2015-08-30T02:46:00
41,641,528
0
0
null
null
null
null
UTF-8
C
false
false
17,390
c
/* ! Performs real-to-complex and complex-to-real FFT routines using routines ! RCFFTC, CRFFTC and CFFTC. These routines use double complex data. ! David H. Bailey June 6, 1994 ! Translated into C++. ! Siddhartha Chatterjee (RIACS) ! 18 August 1994 */ #define DEBUG 1 #include <iostream.h> #include "mpmod.H" extern "C" { #include <time.h> #include <stdlib.h> #include <math.h> } double randlc(double&, const double); void vranl(const int, double&, const double, double*); void rcfftc(const int, const int, mp_complex*, mp_real*, mp_complex*, mp_complex*); void crfftc(const int, const int, mp_complex*, mp_complex*, mp_complex*, mp_real*); void cfftc(const int, const int, mp_complex*, mp_complex*, mp_complex*); void fftc1(const int, const int, const int, const mp_complex*, mp_complex*, mp_complex*); void fftc2(const int, const int, const int, const mp_complex*, mp_complex*, mp_complex*); void trans(const int, const int, const mp_complex*, mp_complex*); int min(const int m, const int n) {return m < n ? m : n;} int main() { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) const int m = 8; // const int n = (int) pow(2, m); const int n = 256; const int it = 10; const double aa = 1220703125.0; const double ss = 314159265.0; mp_real x[n+2], rn, se; mp_complex u[n], y[n/2+1], z[n/2+1]; double s[n]; time_t t0, t1; //! Initialize. The SECOND function is assumed to be the timing function //! on the given computer. Change here and below if another name is used. mp_init(); rn = mp_real(1.0)/n; double rr = 0.0; double xx; vranl(0, xx, aa, s); xx = ss; cfftc(0, m, u, y, z); time(&t0); //! Perform IT iterations. for (int ii = 1; ii <= it; ii++) { vranl(n, xx, aa, s); for (int i = 0; i < n; i++) x[i] = s[i]; rcfftc(-1, m, u, x, y, z); crfftc(1, m, u, z, y, x); se = 0.0; for (i = 0; i < n; i++) { se += power(rn*x[i]-s[i], 2); } se = sqrt(se/n); cout << "Iteration " << ii << " "; cout << "Error =\n" << se; if (se > mpeps) { cout << "*** Error detected:\n"; exit(1); } } time(&t1); double tm = difftime(t1, t0); double rt = it*n*5.0*(m+3.0)/tm*1e-6; cout << "Test passed.\n"; // cout << "CPU time = " << tm << '\n'; // cout << "MFLOPS rate = " << rt << '\n'; return 0; } double aint(double x) { if (fabs(x) < 1.0) return 0.0; return floor(fabs(x))*(x >= 0 ? 1.0 : -1.0); } #if 0 double randlc(double& x, const double a) /* ! This routine returns a uniform pseudorandom double precision number in the ! range (0, 1) by using the linear congruential generator ! x_{k+1} = a x_k (mod 2^46) ! where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers ! before repeating. The argument A is the same as 'a' in the above formula, ! and X is the same as x_0. A and X must be odd double precision integers ! in the range (1, 2^46). The returned value RANDLC is normalized to be ! between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain ! the new seed x_1, so that subsequent calls to RANDLC using the same ! arguments will generate a continuous sequence. ! This routine should produce the same results on any computer with at least ! 48 mantissa bits in double precision floating point data. On Cray systems, ! double precision should be disabled. ! David H. Bailey October 26, 1990 */ { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) static int ks = 0; static double r23, r46, t23, t46; /* ! If this is the first call to RANDLC, compute R23 = 2 ^ -23, R46 = 2 ^ -46, ! T23 = 2 ^ 23, and T46 = 2 ^ 46. These are computed in loops, rather than ! by merely using the ** operator, in order to insure that the results are ! exact on all systems. This code assumes that 0.5D0 is represented exactly. */ if (ks == 0) { r23 = r46 = t23 = t46 = 1.0; for (int i = 0; i < 23; i++) { r23 *= 0.5; t23 *= 2.0; } for (i = 0; i < 46; i++) { r46 *= 0.5; t46 *= 2.0; } ks = 1; } //! Break A into two parts such that A = 2^23 * A1 + A2 and set // X = N. double t1 = r23*a; double a1 = aint(t1); double a2 = a-t23*a1; //! Break X into two parts such that X = 2^23 * X1 + X2, compute //! Z = A1 * X2 + A2 * X1 (mod 2^23), and then //! X = 2^23 * Z + A2 * X2 (mod 2^46). t1 = r23*x; double x1 = aint(t1); double x2 = x-t23*x1; t1 = a1*x2+a2*x1; double t2 = aint(r23*t1); double z = t1-t23*t2; double t3 = t23*z+a2*x2; double t4 = aint(r46*t3); x = t3-t46*t4; return r46*x; } #endif void vranl(const int n, double& x, const double a, double *y) /* ! This routine generates N uniform pseudorandom double precision numbers in ! the range (0, 1) by using the linear congruential generator ! x_{k+1} = a x_k (mod 2^46) ! where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers ! before repeating. The argument A is the same as 'a' in the above formula, ! and X is the same as x_0. A and X must be odd double precision integers ! in the range (1, 2^46). The N results are placed in Y and are normalized ! to be between 0 and 1. X is updated to contain the new seed, so that ! subsequent calls to VRANL using the same arguments will generate a ! continuous sequence. If N is zero, only initialization is performed, and ! the variables X, A and Y are ignored. ! This routine is the standard version designed for scalar or RISC systems. ! However, it should produce the same results on any single processor ! computer with at least 48 mantissa bits in double precision floating point ! data. On Cray systems, double precision should be disabled. ! David H. Bailey October 26, 1990 */ { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) static int ks = 0; static double r23, r46, t23, t46; //! If this is the first call to VRANL, compute R23 = 2 ^ -23, R46 = 2 ^ -46, //! T23 = 2 ^ 23, and T46 = 2 ^ 46. See comments in RANDLC. if (0 == ks || 0 == n) { r23 = r46 = t23 = t46 = 1.0; for (int i = 0; i < 23; i++) { r23 *= 0.5; t23 *= 2.0; } for (i = 0; i < 46; i++) { r46 *= 0.5; t46 *= 2.0; } ks = 1; if (n == 0) return; } //! Break A into two parts such that A = 2^23 * A1 + A2 and set X = N. double t1 = r23*a; double a1 = aint(t1); double a2 = a-t23*a1; //! Generate N results. This loop is not vectorizable. for (int i = 0; i < n; i++) { //! Break X into two parts such that X = 2^23 * X1 + X2, compute //! Z = A1 * X2 + A2 * X1 (mod 2^23), and then //! X = 2^23 * Z + A2 * X2 (mod 2^46). t1 = r23*x; double x1 = aint(t1); double x2 = x-t23*x1; t1 = a1*x2+a2*x1; double t2 = aint(r23*t1); double z = t1-t23*t2; double t3 = t23*z+a2*x2; double t4 = aint(r46*t3); x = t3-t46*t4; y[i] = r46*x; } } void rcfftc(const int is, const int m, mp_complex *u, mp_real *x, mp_complex *y, mp_complex *z) /* ! Computes the N-point real-to-complex FFT of X, where N = 2^M. This ! uses an algorithm due to Swarztrauber, coupled with some fast methods of ! methods of performing power-of-two matrix transforms. X is the input ! array, Y is a scratch array, and Z is the output array. X must be ! dimensioned with N + 2 real cells. Y, and Z must be dimensioned with N/2+1 ! complex cells. If desired, X and Y or X and Z may be the same array in ! the calling program. Before calling RCFFTC to perform an FFT, the array U ! must be initialized by calling CFFTC with IS set to 0 and M set to MX, ! where MX is the maximum value of M for any subsequent call. U must be ! dimensioned with at least 2 * N real cells. M must be at least two. */ { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) mp_complex c0, c1, y0, y1; //! Set initial parameters. int n = (int) pow(2, m); int mx = INT(u[0]); int n2 = n/2; int n21 = n2+1; int n22 = n2+2; int n4 = n/4; int n41 = n4+1; int ku = n/2+1; //! Check if input parameters are invalid. if ((is != 1 && is != -1) || m < 3 || m > mx) { cout << "RCFFTC: Either U has not been initialized, or else "; cout << "one of the input parameters is invalid "; cout << is << n << mx << '\n'; exit(1); } //! Copy X to Y such that Y(k) = X(2k-1) + i X(2k). for (int k = 1; k <= n2; k++) y[k-1] = mp_complex(x[2*k-1-1], x[2*k-1]); //! Perform a normal N/2-point FFT on Y. cfftc(is, m-1, u, y, z); //! Reconstruct the FFT of X. z[1-1] = 2.0*(MP_REAL(y[1-1]) + aimag(y[1-1])); z[n41-1] = 2.0*mp_complex(MP_REAL(y[n41-1]), is*aimag(y[n41-1])); z[n21-1] = 2.0*(MP_REAL(y[1-1]) - aimag(y[1-1])); if (1 == is) { for (k = 2; k <= n4; k++) { y0 = y[k-1]; y1 = conjg(y[n22-k-1]); c0 = y0+y1; c1 = u[ku+k-1]*(y0-y1); z[k-1] = c0+c1; z[n22-k-1] = conjg(c0-c1); } } else { for (k = 2; k <= n4; k++) { y0 = y[k-1]; y1 = conjg(y[n22-k-1]); c0 = y0+y1; c1 = conjg(u[ku+k-1])*(y0-y1); z[k-1] = c0+c1; z[n22-k-1] = conjg(c0-c1); } } } void crfftc(const int is, const int m, mp_complex *u, mp_complex *x, mp_complex *y, mp_real *z) /* ! Computes the N-point complex-to-real FFT of X, where N = 2^M. This ! uses an algorithm due to Swarztrauber, coupled with some fast methods of ! methods of performing power-of-two matrix transforms. X is the input ! array, Y is a scratch array, and Z is the output array. X and Y must be ! dimensioned with N/2+1 complex cells. Z must be dimensioned with N + 2 ! real cells. If desired, X and Y or X and Z may be the same array in ! the calling program. Before calling CRFFTC to perform an FFT, the array U ! must be initialized by calling CFFTC with IS set to 0 and M set to MX, ! where MX is the maximum value of M for any subsequent call. U must be ! dimensioned with at least 2 * N real cells. M must be at least two. */ { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) mp_complex c0, c1, x0, x1; //! Set initial parameters. int n = (int) pow(2,m); int mx = INT(u[0]); int n2 = n/2; int n21 = n2+1; int n22 = n2+2; int n4 = n/4; int n41 = n4+1; int ku = n/2+1; //! Check if input parameters are invalid. if ((is != 1 && is != -1) || m < 3 || m > mx) { cout << "CRFFTC: Either U has not been initialized, or else "; cout << "one of the input parameters is invalid "; cout << is << n << mx << '\n'; exit(1); } //! Construct the input to CFFTC. y[1-1] = 0.5*mp_complex(MP_REAL(x[1-1])+MP_REAL(x[n21-1]), MP_REAL(x[1-1]) - MP_REAL(x[n21-1])); y[n4+1-1] = mp_complex(MP_REAL(x[n41-1]), -is*aimag(x[n41-1])); if (1 == is) { for (int k = 2; k <= n4; k++) { x0 = x[k-1]; x1 = conjg(x[n22-k-1]); c0 = x0+x1; c1 = u[ku+k-1]*(x0-x1); y[k-1] = 0.5*(c0+c1); y[n22-k-1] = 0.5*conjg(c0-c1); } } else { for (int k = 2; k <= n4; k++) { x0 = x[k-1]; x1 = conjg(x[n22-k-1]); c0 = x0+x1; c1 = conjg(u[ku+k-1])*(x0-x1); y[k-1] = 0.5*(c0+c1); y[n22-k-1] = 0.5*conjg(c0-c1); } } //! Perform a normal N/2-point FFT on Y. cfftc(is, m-1, u, y, x); //! Copy Y to Z such that Y(k) = Z(2k-1) + i Z(2k). for (int k = 1; k <= n2; k++) { z[2*k-1-1] = MP_REAL(y[k-1]); z[2*k-1] = aimag(y[k-1]); } } void cfftc(const int is, const int m, mp_complex *u, mp_complex *x, mp_complex *y) /* ! Computes the N-point complex-to-complex FFT of X, where N = 2^M. This ! uses an algorithm due to Swarztrauber, coupled with some fast methods of ! methods of performing power-of-two matrix transforms. X is the input ! array, Y is a scratch array, and Z is the output array. X, Y, and Z must ! be dimensioned with N complex cells. If desired, X and Y or X and Z may ! be the same array in the calling program. Before calling CFFTC to perform ! an FFT, the array U must be initialized by calling CFFTC with IS set to 0 ! and M set to MX, where MX is the maximum value of M for any subsequent ! call. U must be dimensioned with at least 2 * N real cells. M must be at ! least two. */ { //IMPLICIT DOUBLE PRECISION (A-H, O-Z) mp_real t, ti, t1, t2; // int n = (int) pow(2, m); const int n = 256; mp_complex z[n]; int i; if (0 == is) { //! Initialize the U array with sines and cosines in a manner that permits //! stride one access at each radix-4 FFT iteration. If M is odd, then the //! final set of results are for a radix-2 FFT iteration. u[1-1] = m; int ku = 2; int ln = 1; for (int j = 1; j <= m; j++) { t = mppic/ln; for (i = 0; i < ln; i++) { ti = i*t; mpcssnf(ti, t1, t2); u[i+ku-1] = mp_complex(t1, t2); } ku += ln; ln *= 2; } return; } //! Check if input parameters are invalid. int mx = INT(u[1-1]); if ((is != 1 && is != -1) || m < 2 || m > mx) { cout << "CFFTC: Either U has not been initialized, or else "; cout << "one of th input parameters is invalid "; cout << is << n << mx << '\n'; abort(); } /* ! A normal call to CFFTZ starts here. M1 is the number of the first variant ! radix-2 Stockham iterations to be performed. The second variant is faster ! on most computers after the first few iterations, since in the second ! variant it is not necessary to access roots of unity in the inner DO loop. ! Thus it is most efficient to limit M1 to some value. For many vector ! computers, the optimum limit of M1 is 6. For scalar systems, M1 should ! probably be limited to 2. */ int m1 = min(m/2, 2); int m2 = m-m1; int n2 = (int) pow(2, m1); int n1 = (int) pow(2, m2); //! Perform the first variant of the radix-2 Stockham FFT. for (int l = 1; l <= m1; l += 2) { fftc1(is, l, m, u, x, y); if (l == m1) goto lab150; fftc1(is, l+1, m, u, y, x); } goto lab170; lab150:; trans(n1, n2, y, x); //! Perform the second variant of the radix-2 Stockham FFT. for (l = m1+1; l <= m; l += 2) { fftc2(is, l, m, u, x, y); if (l == m) goto lab190; fftc2(is, l+1, m, u, y, x); } goto lab210; lab170:; trans(n1, n2, x, y); //! Perform the second variant of the radix-2 Stockham FFT. for (l = m1+1; l <= m; l += 2) { fftc2(is, l, m, u, y, x); if (l == m) goto lab210; fftc2(is, l+1, m, u, x, y); } //! Copy Y to X if the last operation above stored into Y. lab190: for (i = 0; i < n; i++) x[i] = y[i]; lab210: return; } void fftc1(const int is, const int l, const int m, const mp_complex *u, mp_complex *x, mp_complex *y) /* ! Performs the L-th iteration of the first variant of the radix-2 Stockham ! FFT. Complex version. */ { mp_complex uj, x1, x2; //! Set initial parameters. int n = (int) pow(2, m); int ni = n/2; int lk = (int) pow(2, l-1); int lj = ni/lk; int ku = lj+1; for (int k = 0; k < lk; k++) { int k11 = 2*k*lj+1; int k12 = k11+lj; int k21 = k*lj+1; int k22 = k21+ni; if (1 == is) { for (int j = 0; j < lj; j++) { uj = u[ku+j-1]; x1 = x[k11+j-1]; x2 = x[k12+j-1]; y[k21+j-1] = x1+x2; y[k22+j-1] = uj*(x1-x2); } } else { for (int j = 0; j < lj; j++) { uj = conjg(u[ku+j-1]); x1 = x[k11+j-1]; x2 = x[k12+j-1]; y[k21+j-1] = x1+x2; y[k22+j-1] = uj*(x1-x2); } } } } void fftc2(const int is, const int l, const int m, const mp_complex *u, mp_complex *x, mp_complex *y) /* ! Performs the L-th iteration of the second variant of the radix-2 Stockham ! FFT. Complex version. */ { mp_complex uj, x1, x2; //! Set initial parameters. int n = (int) pow(2, m); int ni = n/2; int lk = (int) pow(2, l-1); int lj = ni/lk; int ku = lj+1; for (int j = 0; j < lj; j++) { int j11 = j*lk+1; int j12 = j11+ni; int j21 = 2*j*lk+1; int j22 = j21+lk; uj = u[ku+j-1]; if (-1 == is) uj = conjg(uj); for (int k = 0; k < lk; k++) { x1 = x[j11+k-1]; x2 = x[j12+k-1]; y[j21+k-1] = x1+x2; y[j22+k-1] = uj*(x1-x2); } } } void trans(const int n1, const int n2, const mp_complex *x, mp_complex *y) /* ! Performs a transpose of the vector X, returning the result in Y. X is ! treated as a N1 x N2 complex matrix, and Y is treated as a N2 x N1 complex ! matrix. The complex data is assumed stored with real and imaginary parts ! interleaved as in the COMPLEX type. ! David H. Bailey April 28, 1987 */ { int n = n1*n2; int i, j; /* ! Perform one of three techniques, depending on N. The best strategy varies ! with the computer system. This strategy is best for scalar systems. */ if (n1 >= n2) goto lab100; else goto lab120; lab100: for (j = 0; j < n2; j++) { for (i = 0; i < n1; i++) { y[i*n2+j+1-1] = x[i+j*n1+1-1]; } } goto lab200; /* ! Scheme 2: Perform a simple transform with the loops reversed. This is ! usually the best on vector computers if N1 is odd, or if both N1 and N2 are ! small, and N2 is larger than N1. */ lab120: for (i = 0; i < n1; i++) { for (j = 0; j < n2; j++) { y[j+i*n2+1-1] = x[j*n1+i+1-1]; } } lab200:; }
[ "magnus.rosenberg@email.de" ]
magnus.rosenberg@email.de
1c101422b8164d94c6102926866875ffab67abd8
ccaa508cbb0b2caee5a7aa2eaf728b68638ccc77
/2、标准函数/limits/main.c
353cde67da381f6a1049877b0b265ab5201a1282
[]
no_license
Seventeen-coding/something-for-C-language
03d260357789066924ff048c792e9aa7f0b95681
3db08591a94f202ee12a538727926b7e844a7a4f
refs/heads/master
2022-11-23T15:19:54.673494
2020-07-27T10:19:01
2020-07-27T10:19:01
72,769,379
1
0
null
null
null
null
UTF-8
C
false
false
849
c
/* <limits.h> 基本类型的大小 */ #include <stdio.h> #include <limits.h> int main(void) { printf("The number of bits in a byte %d\n", CHAR_BIT); printf("The minimum value of SIGNED CHAR = %d\n", SCHAR_MIN); printf("The maximum value of SIGNED CHAR = %d\n", SCHAR_MAX); printf("The maximum value of UNSIGNED CHAR = %d\n", UCHAR_MAX); printf("The minimum value of SHORT INT = %d\n", SHRT_MIN); printf("The maximum value of SHORT INT = %d\n", SHRT_MAX); printf("The minimum value of INT = %d\n", INT_MIN); printf("The maximum value of INT = %d\n", INT_MAX); printf("The minimum value of CHAR = %d\n", CHAR_MIN); printf("The maximum value of CHAR = %d\n", CHAR_MAX); printf("The minimum value of LONG = %ld\n", LONG_MIN); printf("The maximum value of LONG = %ld\n", LONG_MAX); return 0; }
[ "741253078@qq.com" ]
741253078@qq.com
be2e1180a7207f8bcb21175ba1aaacf4673db01f
7a6f1431bbefc9c1d1fb7f6c89f03f9ec07fbdc5
/119_file_handling_replace_string_.c
6468d5bb1d93bf86dc7bd8d43019e6a7d792e39b
[]
no_license
abhisekmane98/Code6
7129dd5685c75acb7c9e012aea88c9ac1e0d7609
253fb7edcb679f928c2fd30de209d0200d42825c
refs/heads/main
2023-08-23T08:35:48.919663
2021-10-02T18:10:20
2021-10-02T18:10:20
412,873,320
0
0
null
null
null
null
UTF-8
C
false
false
696
c
#include<stdio.h> #include<string.h> void replace(char*,int,char*,char*,FILE*); int main() { char s[40],s1[]="we",s2[]="ki"; FILE *fp1,*fp2; fp1=fopen("119_para_.txt","r"); fp2=fopen("119_updated_.txt","w"); while(fgets(s,sizeof(s),fp1)!=NULL) { replace(s,sizeof(s),s1,s2,fp2); } fclose(fp1); fclose(fp2); } void replace(char *s,int size,char *s1,char *s2,FILE *fp) { int count=0,i,j; char t[size],*p; strcpy(t,s); while(strstr(t,s1)!=NULL) { p=strstr(t,s1); p=p+strlen(s1); strcpy(t,p); count++; } for(i=1;i<=count;i++) { p=strstr(s,s1); for(j=0;j<=strlen(s2)-1;j++) { *(p+j)=s2[j]; } } fputs(s,fp); }
[ "noreply@github.com" ]
abhisekmane98.noreply@github.com
64b5c45636fdcfcdf2aaf852025f68df06b1a77d
c2cedcf36667730f558ab354bea4505b616c90d2
/players/mizan/opl/CELLS/C1071.c
a9c531fdbe361bf33543120b2f2d87e40d5318a8
[]
no_license
wugouzi/Nirvlp312mudlib
965ed876c7080ab00e28c5d8cd5ea9fc9e46258f
616cad7472279cc97c9693f893940f5336916ff8
refs/heads/master
2023-03-16T03:45:05.510851
2017-09-21T17:05:00
2017-09-21T17:05:00
null
0
0
null
null
null
null
UTF-8
C
false
false
2,057
c
inherit "/players/mizan/opl/core/room.c"; #include "/obj/ansi.h" object mob0, mob1, mob2, mob3, mob4, bonus, bonus2, bonus3, boss, door1, door2; /* This is a TOP cell of maze, automatically generated. */ /* Please do not make edits to this file as changes would be overwritten */ /* every two weeks by the Perl code which generates this room. Contact */ /* Mizan directly so he can make changes to the Perl code directly. Thanks! */ reset(int arg) { if(arg) return; move_object(this_object(), "/players/mizan/opl/daemons/gridboxDM"); add_property("fight_area"); short_desc = "The Proving Grounds of the OverPowerLord"; dest_dir = ({ "/players/mizan/opl/CELLS/C951", "north", "/players/mizan/opl/CELLS/C1191", "south", }); /* Our monster list */ if(!mob0) { mob0 = clone_object("/players/mizan/opl/beasties/fungus/big_bunny.c"); move_object(mob0, this_object()); } if(!mob1) { mob1 = clone_object("/players/mizan/opl/beasties/fungus/potato.c"); move_object(mob1, this_object()); } if(!mob2) { mob2 = clone_object("/players/mizan/opl/beasties/fungus/wookie.c"); move_object(mob2, this_object()); } custom_exits = 1; terrain_icon = BGRN + BLK + "m" + NORM; } long() { write(" Dirt and what can be assumed is fresh fecal grindings cover the top of\n"); write("this stone block, and upon it has erupted a large overgrown forest of fungus!\n"); write("The thick stalks of giant mushrooms form a lush canopy and obscure your view.\n"); /* This code generates the top-down map of the room we are in */ write(" There are two obvious exits: north and south.\n"); write(call_other("/players/mizan/opl/daemons/gridDM.c", "render_map", this_object()->query_x(), this_object()->query_y(), this_object()->query_index(), this_object()->query_sight_range() )); } query_x() { return 111; } query_y() { return 8; } query_index() { return 1071; } query_sight_range() { return 3; } query_npc_traversable() { return 1; } is_forest() { return 1; } realm() { return "NT"; }
[ "rump.nirv@gmail.com" ]
rump.nirv@gmail.com
98b2f088953d53680716b9ea2e9022f484ed31cb
938495d61712257f36cfeaa36f4380a760930047
/clibrary/radonop3.c
37972172ddac74457c947ce0b1c89fa27c33293a
[]
no_license
chaoshunh/seismic_unix
cec401f04e77c8dd6caf93e8cbac000a7ea15794
c975332d5fab748d5f42ed8225e9f878def7d76a
refs/heads/master
2022-11-06T18:22:16.105316
2020-06-26T16:52:43
2020-06-26T16:52:43
null
0
0
null
null
null
null
UTF-8
C
false
false
2,227
c
#include <math.h> #include <stdio.h> #include <math.h> #include <stdio.h> #include <stdlib.h> /* Matlab */ #include "mex.h" #define printf mexPrintf void rstack( double *x, double *t, double *h, double *p, double *y, int nt, int nh, int np, double dt, double *ww) ; double sinc(double arg); void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *x, *z, *ww; int nt,nh,np,flag; double *t,*p,*h, dt; if (nrhs==0) { printf("[v]=radonopi(u,t,h,p)\n") ; printf("LH Inverse hyperbolic radon operator\n") ; printf("u and v can be input and output as 1D vectors\n") ; printf("or as 2D vectors. u(nt,nh) gives v(nt,np) \n") ; printf("u(ntxnh,1) gives v(ntxnp,1) \n"); printf("(time is fast dimension)\n") ; printf("to use in CG algorithms\n") ; printf("Daniel Trad - UBC\n") ; return; } /*///////////////////////////////// // Get input from MATLAB*/ /*nt=mxGetM(prhs[0]);printf("nt=%d\t",nt);*/ nh=mxGetN(prhs[0]);printf("nh=%d\t",nh); if (nh==1) flag=1; else flag=0; z=mxGetPr(prhs[0]); t=mxGetPr(prhs[1]); nt=mxGetN(prhs[1]); h=mxGetPr(prhs[2]); nh=mxGetN(prhs[2]); p=mxGetPr(prhs[3]); np=mxGetN(prhs[3]);printf("np=%d\n",np); dt=t[1]-t[0];printf("dt=%f\n",dt); ww=mxGetPr(prhs[4]); /*output*/ if (flag==1) plhs[0]=mxCreateDoubleMatrix(nt*np,1, mxREAL); else if (flag==0) plhs[0]=mxCreateDoubleMatrix(nt,np, mxREAL); x=mxGetPr(plhs[0]); /*////////////////////////////*/ rstack(x,t,h,p,z,nt,nh,np,dt,ww); return; } void rstack( double *m, double *t, double *h, double *q, double *d, int nt, int nh, int nq, double dt, double *ww) { int i,k,ih,iq,itau; unsigned int j; double time,it; int nx, ny; nx=nt*nq; ny=nt*nh; for (i=0;i<(nq*nt);i++) m[i]=0; for (ih=0;ih<nh;ih++){ for (iq=0;iq<nq;iq++){ if (fabs(ww[iq])>1e-2){ for (itau=0;itau<nt;itau++){ k=iq*nt+itau; /*time=sqrt(pow(t[itau],2)+pow(h[ih],2)*q[iq]);*/ time=t[itau]+pow(h[ih],2)*q[iq]; it=time/dt; j=ih*nt+(int) floor(it); if ((it!=nt)&&(j<ny)&&(k<nx)) m[k]=m[k]+d[j];/**sincin(it-floor(it));*/ } } } } return; }
[ "danielotrad@gmail.com" ]
danielotrad@gmail.com
629d607b25f2de24b1aa5d5412cf05c4805544ad
4bee4d8664bfe4c3df4efef636d351942d854604
/Sources/01XXX/1978/1978.c
4533b07bf7f1cec5e974ec6ec9ac525b48fa44b5
[ "MIT" ]
permissive
HyeongD/BOJ-DDM-Code
4733802159150d629f3330658863a1075899a793
7dd6d76838d3309bfe5bef46f1778c5776ebdf2a
refs/heads/master
2022-04-08T03:28:37.502556
2020-02-25T06:23:01
2020-02-25T06:23:01
null
0
0
null
null
null
null
UTF-8
C
false
false
551
c
/** * BOJ 1978번 C언어 소스 코드 * 작성자 : 동동매니저 (DDManager) * * ※ 실행 결과 * 사용 메모리 : 1,116 KB / 131,072 KB * 소요 시간 : 0 ms / 2,000 ms * * Copyright 2019. DDManager all rights reserved. */ #include <stdio.h> int is_prime(int x){ int i; if(x==1) return 0; if(x==2) return 1; for(i=2;i*i<=x;i++){ if(x%i==0) return 0; } return 1; } int main(void){ int N,X,i,cnt=0; scanf("%d",&N); for(i=0;i<N;i++){ scanf("%d",&X); if(is_prime(X)) cnt++; } printf("%d\n",cnt); return 0; }
[ "l01092452614@gmail.com" ]
l01092452614@gmail.com
698c9de8ef4113cae12861dcc4c476b075a435da
893ea7cffd4e6fe3fbf38ee488249358e0dc8bd1
/0728/1vital_code/整合的十段代码/5指针_数组/1内存大小.c
ec73e6289bc746f44806610a0c0ea66bc553d997
[]
no_license
lansplansplansp/0707
b198a2107371c81a12e38a417beb8ea709725d81
6f4b4e31305104a19bcf920e4aceaac8fb83c591
refs/heads/master
2020-06-16T18:27:49.387589
2019-07-28T15:59:05
2019-07-28T15:59:05
195,664,192
0
0
null
null
null
null
UTF-8
C
false
false
325
c
#include<stdio.h> #include<string.h> int main() { char chr[]={'a','b','c','d','e','f'}; char *p = chr; printf("size:%d,%d\n",sizeof(p),sizeof(*p)); short *s = (short *)chr; printf("addr:%p,%p\n",s,p); printf("size:%d,%d\n",sizeof(s),sizeof(*s)); printf("*s = 0x%x\n\%p\n",*s,s); return 0; }
[ "123456@qq.com" ]
123456@qq.com
403615f664d7217079ae29d9de6b3283cd54a6f4
d242fcbca946c8a597b11fa0d51ed2f6acd5ec04
/searches/interpolation_search/interpolation_search.c
f16e4e5707bfa4df0c7fce99897e0a38eeeb31cb
[]
no_license
Dross0/algorithms
dad54e8aac4a1a848a2e1e8015b4b726fcbc866a
ce49789bfdce32659f47b0040a1579af0e89c1c1
refs/heads/master
2020-04-27T06:26:36.596659
2019-05-31T03:14:44
2019-05-31T03:14:44
174,108,202
0
0
null
null
null
null
UTF-8
C
false
false
386
c
int interpolation_search(int arr[], int n, int value){ int first = 0; int last = n - 1; int mid = 0; while (arr[first] <= value && arr[last] >= value){ mid = first + (((value - arr[first]) * (last - first)) / (arr[last] - arr[first])); if (arr[mid] == value){ return 1; } else if (arr[mid] > value){ last = mid - 1; } else{ first = mid + 1; } } return 0; }
[ "andrey04072000@gmail.com" ]
andrey04072000@gmail.com
fc3f70fd9bcfa0a7cc6ae64a61e834c42e5ea68a
ff112e0f85c1407b54b0f318b3611fdf1a5509b0
/transmitter/components/Screen_handler/screen_handler.c
bd46906bb5ad492f447b41187d80a475fd8534d7
[ "Beerware" ]
permissive
EtienneAr/esp32-transceiver-for_RC_boat
5467f6aa46a928daf6b2c389f9e0e45cb6e7ad1d
27a1abe949d4c65b7d2b6063566b081eaba5a8b9
refs/heads/master
2021-06-18T14:14:44.317427
2021-05-01T10:21:30
2021-05-01T10:21:30
204,437,646
6
3
null
null
null
null
UTF-8
C
false
false
3,762
c
#include "screen_handler.h" #include "esp_vfs.h" #include "esp_spiffs.h" #include "esp_log.h" static TFT_t dev; static const char *SH_TAG = "Screen handler"; void init_screen_handler() { /* Init SPIFFS */ ESP_LOGI(SH_TAG, "Initializing SPIFFS"); esp_vfs_spiffs_conf_t conf = { .base_path = "/spiffs", .partition_label = NULL, .max_files = 6, .format_if_mount_failed =true }; // Use settings defined above toinitialize and mount SPIFFS filesystem. // Note: esp_vfs_spiffs_register is anall-in-one convenience function. esp_err_t ret =esp_vfs_spiffs_register(&conf); if (ret != ESP_OK) { if (ret == ESP_FAIL) { ESP_LOGE(SH_TAG, "Failed to mount or format filesystem"); } else if (ret == ESP_ERR_NOT_FOUND) { ESP_LOGE(SH_TAG, "Failed to find SPIFFS partition"); } else { ESP_LOGE(SH_TAG, "Failed to initialize SPIFFS (%s)",esp_err_to_name(ret)); } return; } size_t total = 0, used = 0; ret = esp_spiffs_info(NULL, &total,&used); if (ret != ESP_OK) { ESP_LOGE(SH_TAG,"Failed to get SPIFFS partition information (%s)",esp_err_to_name(ret)); } else { ESP_LOGI(SH_TAG,"Partition size: total: %d, used: %d", total, used); } /* Init screen */ spi_master_init(&dev, CONFIG_SCLK_GPIO, CONFIG_MOSI_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO, CONFIG_BL_GPIO); lcdInit(&dev, CONFIG_WIDTH, CONFIG_HEIGHT, CONFIG_OFFSETX, CONFIG_OFFSETY); } /* Redo all drawing functions */ void mylcd_DrawPixel(uint16_t x, uint16_t y, uint16_t color) { lcdDrawPixel(&dev, x, y, color); } void mylcd_DrawFillRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { lcdDrawFillRect(&dev, x1, y1, x2, y2, color); } void mylcd_DisplayOff() { lcdDisplayOff(&dev); } void mylcd_DisplayOn() { lcdDisplayOn(&dev); } void mylcd_FillScreen(uint16_t color) { lcdFillScreen(&dev, color); } void mylcd_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { lcdDrawLine(&dev, x1, y1, x2, y2, color); } void mylcd_DrawRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color) { lcdDrawRect(&dev, x1, y1, x2, y2, color); } void mylcd_DrawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) { lcdDrawCircle(&dev, x0, y0, r, color); } void mylcd_DrawFillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) { lcdDrawFillCircle(&dev, x0, y0, r, color); } void mylcd_DrawRoundRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t r, uint16_t color) { lcdDrawRoundRect(&dev, x1, y1, x2, y2, r, color); } void mylcd_DrawArrow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t w, uint16_t color) { lcdDrawArrow(&dev, x0, y0, x1, y1, w, color); } void mylcd_DrawFillArrow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t w, uint16_t color) { lcdDrawFillArrow(&dev, x0, y0, x1, y1, w, color); } int mylcd_DrawChar(FontxFile *fx, uint16_t x, uint16_t y, uint8_t ascii, uint16_t color) { return lcdDrawChar(&dev, fx, x, y, ascii, color); } int mylcd_DrawString(FontxFile *fx, uint16_t x, uint16_t y, uint8_t * ascii, uint16_t color) { return lcdDrawString(&dev, fx, x, y, ascii, color); } void mylcd_SetFontDirection(uint16_t dir) { lcdSetFontDirection(&dev, dir); } void mylcd_SetFontFill(uint16_t color) { lcdSetFontFill(&dev, color); } void mylcd_UnsetFontFill() { lcdUnsetFontFill(&dev); } void mylcd_SetFontUnderLine(uint16_t color) { lcdSetFontUnderLine(&dev, color); } void mylcd_UnsetFontUnderLine() { lcdUnsetFontUnderLine(&dev); } void mylcd_BacklightOff() { lcdBacklightOff(&dev); } void mylcd_BacklightOn() { lcdBacklightOn(&dev); } void mylcd_InversionOn() { lcdInversionOn(&dev); }
[ "etienne.arlaud@free.fr" ]
etienne.arlaud@free.fr
b879ae6d9d2edbe20fa8b2235eba2264e2d77b23
d85b1f3ce9a3c24ba158ca4a51ea902d152ef7b9
/testcases/CWE78_OS_Command_Injection/s01/CWE78_OS_Command_Injection__char_connect_socket_system_22b.c
e32361afecf0b6b2add346d2a6c654ca85219d38
[]
no_license
arichardson/juliet-test-suite-c
cb71a729716c6aa8f4b987752272b66b1916fdaa
e2e8cf80cd7d52f824e9a938bbb3aa658d23d6c9
refs/heads/master
2022-12-10T12:05:51.179384
2022-11-17T15:41:30
2022-12-01T15:25:16
179,281,349
34
34
null
2022-12-01T15:25:18
2019-04-03T12:03:21
null
UTF-8
C
false
false
5,382
c
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE78_OS_Command_Injection__char_connect_socket_system_22b.c Label Definition File: CWE78_OS_Command_Injection.one_string.label.xml Template File: sources-sink-22b.tmpl.c */ /* * @description * CWE: 78 OS Command Injection * BadSource: connect_socket Read data using a connect socket (client side) * GoodSource: Fixed string * Sink: system * BadSink : Execute command in data using system() * Flow Variant: 22 Control flow: Flow controlled by value of a global variable. Sink functions are in a separate file from sources. * * */ #include "std_testcase.h" #include <wchar.h> #ifdef _WIN32 #define FULL_COMMAND "dir " #else #include <unistd.h> #define FULL_COMMAND "ls " #endif #ifdef _WIN32 #include <winsock2.h> #include <windows.h> #include <direct.h> #pragma comment(lib, "ws2_32") /* include ws2_32.lib when linking */ #define CLOSE_SOCKET closesocket #else /* NOT _WIN32 */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 #define CLOSE_SOCKET close #define SOCKET int #endif #define TCP_PORT 27015 #define IP_ADDRESS "127.0.0.1" #ifndef OMITBAD /* The global variable below is used to drive control flow in the source function */ extern int CWE78_OS_Command_Injection__char_connect_socket_system_22_badGlobal; char * CWE78_OS_Command_Injection__char_connect_socket_system_22_badSource(char * data) { if(CWE78_OS_Command_Injection__char_connect_socket_system_22_badGlobal) { { #ifdef _WIN32 WSADATA wsaData; int wsaDataInit = 0; #endif int recvResult; struct sockaddr_in service; char *replace; SOCKET connectSocket = INVALID_SOCKET; size_t dataLen = strlen(data); do { #ifdef _WIN32 if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { break; } wsaDataInit = 1; #endif /* POTENTIAL FLAW: Read data using a connect socket */ connectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (connectSocket == INVALID_SOCKET) { break; } memset(&service, 0, sizeof(service)); service.sin_family = AF_INET; service.sin_addr.s_addr = inet_addr(IP_ADDRESS); service.sin_port = htons(TCP_PORT); if (connect(connectSocket, (struct sockaddr*)&service, sizeof(service)) == SOCKET_ERROR) { break; } /* Abort on error or the connection was closed, make sure to recv one * less char than is in the recv_buf in order to append a terminator */ /* Abort on error or the connection was closed */ recvResult = recv(connectSocket, (char *)(data + dataLen), sizeof(char) * (100 - dataLen - 1), 0); if (recvResult == SOCKET_ERROR || recvResult == 0) { break; } /* Append null terminator */ data[dataLen + recvResult / sizeof(char)] = '\0'; /* Eliminate CRLF */ replace = strchr(data, '\r'); if (replace) { *replace = '\0'; } replace = strchr(data, '\n'); if (replace) { *replace = '\0'; } } while (0); if (connectSocket != INVALID_SOCKET) { CLOSE_SOCKET(connectSocket); } #ifdef _WIN32 if (wsaDataInit) { WSACleanup(); } #endif } } return data; } #endif /* OMITBAD */ #ifndef OMITGOOD /* The global variables below are used to drive control flow in the source functions. */ extern int CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B1Global; extern int CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B2Global; /* goodG2B1() - use goodsource and badsink by setting the static variable to false instead of true */ char * CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B1Source(char * data) { if(CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B1Global) { /* INCIDENTAL: CWE 561 Dead Code, the code below will never run */ printLine("Benign, fixed string"); } else { /* FIX: Append a fixed string to data (not user / external input) */ strcat(data, "*.*"); } return data; } /* goodG2B2() - use goodsource and badsink by reversing the blocks in the if in the source function */ char * CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B2Source(char * data) { if(CWE78_OS_Command_Injection__char_connect_socket_system_22_goodG2B2Global) { /* FIX: Append a fixed string to data (not user / external input) */ strcat(data, "*.*"); } return data; } #endif /* OMITGOOD */
[ "Alexander.Richardson@cl.cam.ac.uk" ]
Alexander.Richardson@cl.cam.ac.uk
1a82191529795fdb7208044cb7ea9872990296d2
3f9af68447e53652c6523e90b43337fb45eb3ee6
/testsuite/t6.c
1b96a93fe555b08b06edce20ce3d87b4247202b0
[]
no_license
ChanderG/c-compiler
c2920369ac56f243c0692d3b0e93ada3ed23ff6f
3ae209ea9af2a5cb1376a736c69e9161cf4a1345
refs/heads/master
2020-04-08T23:03:25.434061
2014-11-10T15:02:18
2014-11-10T15:02:18
null
0
0
null
null
null
null
UTF-8
C
false
false
73
c
//Simple program int main() { prints("Hello World!\n"); return 0; }
[ "chandergovind@gmail.com" ]
chandergovind@gmail.com
d7aab4a531a133305275633fe7aec9796d919740
b7078c4d0a14142a90dd7b41395058eed459c2a7
/testtools/cpputestext/CppUTestExt/GTest.h
d2d2bfb7424bafad448df437ce5c50dd5e4b65db
[ "MIT" ]
permissive
spiritsher/cpputest_example
812cf620a2d3e6f6eaa27d4df805d269ecac9d34
acefb098fcf2b4b89e36d2233bc53168c7a1f4c8
refs/heads/master
2022-11-10T18:14:17.849675
2020-06-29T02:56:39
2020-06-29T11:10:44
null
0
0
null
null
null
null
UTF-8
C
false
false
2,169
h
/* * Copyright (c) 2011, Michael Feathers, James Grenning and Bas Vodde * 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. * * Neither the name of the <organization> nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``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 <copyright holder> 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. */ #ifndef GTEST__H_ #define GTEST__H_ #undef new #undef strdup #undef strndup #undef RUN_ALL_TESTS #include "gtest/gtest.h" #ifdef CPPUTEST_USE_NEW_MACROS #include "CppUTest/MemoryLeakDetectorNewMacros.h" #endif #ifdef CPPUTEST_USE_MALLOC_MACROS #include "CppUTest/MemoryLeakDetectorMallocMacros.h" #endif #ifndef RUN_ALL_TESTS #define GTEST_VERSION_GTEST_1_7 #else #ifdef ADD_FAILURE_AT #define GTEST_VERSION_GTEST_1_6 #else #define GTEST_VERSION_GTEST_1_5 #endif #endif #undef RUN_ALL_TESTS #endif
[ "max.peng1768@gmail.com" ]
max.peng1768@gmail.com
28a0e6082cd4eac79d80ad6985272f2a789df592
3d5941b00df785f82a3b2135d2c614839985e4e4
/apps/fw/src/core/led_cfg/led_cfg_private.h
28a6551cab0d6dbad658c87d5b68842d221030d8
[]
no_license
Eugene-Hung/PDS50_5125_Sample
f8e46d4feaeaabb66536dc291885410c71f7f083
87b07066b2589ac2fe1b8023de25ce73f130bcfd
refs/heads/master
2023-01-02T23:04:49.918272
2020-10-28T02:17:08
2020-10-28T02:17:08
295,944,650
0
1
null
null
null
null
UTF-8
C
false
false
1,622
h
/* Copyright (c) 2017 Qualcomm Technologies International, Ltd. */ /* Part of 6.3.2 */ /** * \file * LED configure private header file. */ #ifndef LED_CFG_PRIVATE_H #define LED_CFG_PRIVATE_H #include "hydra_log/hydra_log.h" #include "led_cfg/led_cfg.h" #include "mmu/mmu.h" #include <led.h> #include "trap_api/trap_api.h" #include "ipc/ipc.h" #include "hal/halauxio.h" #define LED_MAX_DUTY_CYCLE_VALUE 0xFFF #define LED_MAX_PERIOD_VALUE 0xF #define LED_MAX_PWM_HIGH (0xFFFF >> 1) #define LED_MAX_PWM_LOW (0xFFFF >> 1) #define LED_MAX_PWM_PERIOD (LED_MAX_PWM_HIGH + LED_MAX_PWM_LOW) #define LED_MAX_FLASH_RATE 0xF #define MAX_LOGARITHMIC_MODE_OFFSET 0xF #define NUM_LED_CTRL_INST (NUM_OF_LED_CTRLS) typedef enum { LED_STATE_NORMAL, LED_STATE_FLASHING } led_flashing_state; typedef struct client_led_config { led_flashing_state state; uint16 duty_cycle; uint16 low_duty_cycle; uint8 period; bool invert; led_config driver_config; uint32 groups; } client_led_config; /** * @brief Check if the LED controller is clocked. If not then we can't access * the registers. The clock is turned on by the Curator when a PIO is muxed to * the LED controller and turned off in deep sleep if there is no PIO muxed to * the LED controller. * @return TRUE if LED controller is clocked, FALSE otherwise. */ bool led_cfg_is_clocked(void); /** * @brief Debugging function to dump LED driver configuration. * @param led LED index. * @param led_conf Pointer to configuration buffer. */ void led_cfg_log_config(led_id led, client_led_config *led_conf); #endif /* LED_CFG_PRIVATE_H */
[ "a179996496@icloud.com" ]
a179996496@icloud.com
f1ce785623c19079a2c3ac3c39ac99c2c68d246d
57fceb3d3cce7f871b0a8b02fc3cb3478408c612
/include/CoreFoundation/CFICUConverters.h
061d4af492c23783c08d70c0e2e01d5838e172e8
[]
no_license
bfulgham/D2DTest
4105cf5460bd5511ea3397a700e2c2c21c739b69
1f9973c5cc3d0227abd558f1fd88b0b8d486efcd
refs/heads/master
2021-01-21T00:44:25.975194
2012-11-13T06:16:49
2012-11-13T06:16:49
6,587,849
1
0
null
null
null
null
UTF-8
C
false
false
2,762
h
/* * Copyright (c) 2010-2012 Brent Fulgham <bfulgham@gmail.org>. All rights reserved. * * This source code is a modified version of the CoreFoundation sources released by Apple Inc. under * the terms of the APSL version 2.0 (see below). * * For information about changes from the original Apple source release can be found by reviewing the * source control system for the project at https://sourceforge.net/svn/?group_id=246198. * * The original license information is as follows: * * Copyright (c) 2012 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * CFICUConverters.h * CoreFoundation * * Created by Aki Inoue on 07/12/04. * Copyright (c) 2007-2011, Apple Inc. All rights reserved. * */ #include <CoreFoundation/CFString.h> __private_extern__ const char *__CFStringEncodingGetICUName(CFStringEncoding encoding); __private_extern__ CFStringEncoding __CFStringEncodingGetFromICUName(const char *icuName); __private_extern__ CFIndex __CFStringEncodingICUToBytes(const char *icuName, uint32_t flags, const UniChar *characters, CFIndex numChars, CFIndex *usedCharLen, uint8_t *bytes, CFIndex maxByteLen, CFIndex *usedByteLen); __private_extern__ CFIndex __CFStringEncodingICUToUnicode(const char *icuName, uint32_t flags, const uint8_t *bytes, CFIndex numBytes, CFIndex *usedByteLen, UniChar *characters, CFIndex maxCharLen, CFIndex *usedCharLen); __private_extern__ CFIndex __CFStringEncodingICUCharLength(const char *icuName, uint32_t flags, const uint8_t *bytes, CFIndex numBytes); __private_extern__ CFIndex __CFStringEncodingICUByteLength(const char *icuName, uint32_t flags, const UniChar *characters, CFIndex numChars); // The caller is responsible for freeing the memory (use CFAllocatorDeallocate) __private_extern__ CFStringEncoding *__CFStringEncodingCreateICUEncodings(CFAllocatorRef allocator, CFIndex *numberOfIndex);
[ "bfulgham@gmail.com" ]
bfulgham@gmail.com
a6833d09665312fc34d864d6a5a5768bf775662f
919dbd90b7a3a1763529c19041d12ea610cc4868
/medium/Reconstruct_Original_Digits_From_English/Reconstruct_Original_Digits_From_English.c
6b4e125e46a4653cbc234a5d1b37bd1da161b60c
[]
no_license
PeterChiang0316/PeterLeets
26d6019b449cfa8c3a3f773caa843e36b2f31970
26978e485831a2a1c96ddc152072582582adba40
refs/heads/master
2021-01-12T12:12:15.925159
2017-08-03T15:56:38
2017-08-03T15:56:38
72,356,681
0
0
null
null
null
null
UTF-8
C
false
false
2,129
c
#include <stdio.h> #include <stdlib.h> #include <string.h> unsigned int idx[10] = {0,2,6,7,8,3,4,5,1,9}; unsigned int pivot[10] = {0,1,2,0,2,0,3,0,0,1}; char map[10][6] = { "zero", "two", "six", "seven", "eight", "three", "four", "five", "one", "nine" }; char* originalDigits(char *s); int main (void) { char s[50000] = "thrtwotwotwotwoeethreefourfourfivesevensevensevenninenineninenine"; char *a = originalDigits(s); printf ("a : %s\n", a ); return 0; } char* originalDigits(char *s) { unsigned int o_len = strlen(s); unsigned int number[27] = {0}; unsigned int result[10] = {0}; unsigned int i,j,k; char *c; //return buffer of output c = (char *)malloc(sizeof(char) * 10000); //store every english letter to buffer , using ascii code minus 'a' as index (0~26) for (i = 0 ; i < o_len ; i++) { number[s[i]-'a']++; } for (i = 0 ; i < 26; i++ ) { printf("number[%c] = %d\n",i+'a',number[i]); } //use a pre-defined sequency to idenetify the number of every digit // [0,2,6,7,9,8,3,4,5,1] for (i = 0 ; i < 10 ; i ++ ) { unsigned int pivot_len; // pivot means the digit used to identify in this round pivot_len = strlen(map[i]); printf("pivot %s, pivot_len = %d\n",map[i],pivot_len); //add the number of digit to the result, result should be traversed only once in this for-loop //weight means how many same english letter in the pivot result[idx[i]] = number[map[i][pivot[i]]-'a']; printf("result[%d] += %d\n", idx[i] ,number[map[i][pivot[i]]-'a']); // below for-loop subtract all the letters of pivot from the letter pool for ( j = 0 ; j < pivot_len ; j ++ ) { printf("subtract %c from pool with %d\n",map[i][j],result[idx[i]]); number[map[i][j]-'a']-= result[idx[i]]; } } k = 0; for ( i = 0 ; i < 10 ; i ++ ) { for ( j = 0 ; j < result[i] ; j ++ ) { c[k++] = i + '0'; } } c[k] = '\0'; return c; }
[ "peterstoneage2@gmail.com" ]
peterstoneage2@gmail.com
1ec761d0b0ce6e7ce6032437945afd1f2470efc4
508e7ea12fdad3afb2acb2cd0d48e1e9f2ebd6e6
/程序/实验/实验3/Ex_Ctrls/StdAfx.h
685242d9e61a27f4fe4835ad2b8dc305eabbecca
[]
no_license
shuhongfan/Visual_C
027462a16e4d8e11dafeff7adefd955e00cca1aa
d7018cbc34497a98ae488c12b24723984e04d028
refs/heads/master
2023-09-04T00:13:00.668662
2021-11-03T00:18:36
2021-11-03T00:18:45
424,039,033
0
0
null
null
null
null
UTF-8
C
false
false
1,027
h
// stdafx.h : include file for standard system include files, // or project specific include files that are used frequently, but // are changed infrequently // #if !defined(AFX_STDAFX_H__C6AC1F03_C37E_461C_9BC2_0B05EB6A196C__INCLUDED_) #define AFX_STDAFX_H__C6AC1F03_C37E_461C_9BC2_0B05EB6A196C__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_STDAFX_H__C6AC1F03_C37E_461C_9BC2_0B05EB6A196C__INCLUDED_)
[ "shuhongfan@live.com" ]
shuhongfan@live.com
2168e7014e721e695122bca7a06da345fea0e5f3
eef8800d3debff18222abb61a44e8f3718d981eb
/RexCodes/rexShush/toolBar/src/memoryArrays.c
31b8b79c7f3ee601453abea7f75e7650420ad4e0
[]
no_license
sshruth/abstract_dots_NS
599de6f26af8b04236bbd7450a2a7318305ce526
478aa2e093d30121e3951163fcb630ca7f0b74e2
refs/heads/master
2022-08-13T22:06:04.803052
2022-07-11T04:36:03
2022-07-11T04:36:03
56,621,695
2
2
null
null
null
null
UTF-8
C
false
false
10,956
c
/* Y o u r D e s c r i p t i o n */ /* AppBuilder Photon Code Lib */ /* Version 1.14C */ /* Standard headers */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> /* Toolkit headers */ #include <Ph.h> #include <Pt.h> #include <Ap.h> /* Local headers */ #include "ph_toolBar.h" #include "abimport.h" #include "proto.h" int maMenuOvrRides[16][4] = { { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 } }; int *maAddress[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int maNpts[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int maMsecs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int maRepeats[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int memArrayDialogEnabled = 0; int initMemArrayDialog( PtWidget_t *link_instance, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { PtArg_t args[2]; PtListCallback_t *listData; int maNum; char title[16]; /* eliminate 'unreferenced' warnings */ link_instance = link_instance, apinfo = apinfo, cbinfo = cbinfo; /* if this function was called from the list widget */ if(PtWidgetClass(link_instance) == PtList) { if(cbinfo->reason_subtype != Pt_LIST_SELECTION_FINAL) return(Pt_CONTINUE); listData = (PtListCallback_t *)cbinfo->cbdata; sscanf(listData->item, "Mem Array %d", &maNum); } else { maNum = 0; PtListSelectPos(ABW_memArrayList, 1); } /*set the module's title widget */ sprintf(title, "Memory Array %d", maNum); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, title, 0); PtSetResources(ABW_memArrayDialogLabel, 1, &args[0]); if(ma[maNum].m_ma_menu) { PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "Dialog Enabled", 0); } else { PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "Dialog Disabled", 0); } PtSetArg(&args[1], Pt_ARG_ONOFF_STATE, ma[maNum].m_ma_menu, 0); PtSetResources(ABW_memArrayMenuButton, 2, args); /* set the numeric values of the override widgets */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, maAddress[maNum], 0); PtSetResources(ABW_memArrayAddress, 1, &args[0]); PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, maNpts[maNum], 0); PtSetResources(ABW_memArrayCount, 1, &args[0]); PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, maMsecs[maNum], 0); PtSetResources(ABW_memArrayMsec, 1, &args[0]); PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, maRepeats[maNum], 0); PtSetResources(ABW_memArrayRepeat, 1, &args[0]); /* set the states of the menu override buttons */ if(maMenuOvrRides[maNum][0]) PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_TRUE, Pt_SET); else PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_FALSE, Pt_SET); PtSetResources(ABW_maDialogAddrOvrRide, 1, &args[0]); if(maMenuOvrRides[maNum][1]) PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_TRUE, Pt_SET); else PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_FALSE, Pt_SET); PtSetResources(ABW_maDialogPtsOvrRide, 1, &args[0]); if(maMenuOvrRides[maNum][2]) PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_TRUE, Pt_SET); else PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_FALSE, Pt_SET); PtSetResources(ABW_maDialogMsecOvrRide, 1, &args[0]); if(maMenuOvrRides[maNum][3]) PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_TRUE, Pt_SET); else PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_FALSE, Pt_SET); PtSetResources(ABW_maDialogRepeatOvrRide, 1, &args[0]); /* set the values of the module's "actual" widgets */ /* beginning address */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[maNum].ma_bap, 0); PtSetResources(ABW_memArrayAddressAct, 1, &args[0]); /* number of points */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[maNum].ma_count, 0); PtSetResources(ABW_memArrayCountAct, 1, &args[0]); /* msec per point */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[maNum].ma_rate, 0); PtSetResources(ABW_memArrayMsecAct, 1, &args[0]); /* repeat count */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[maNum].ma_repeat, 0); PtSetResources(ABW_memArrayRepeatAct, 1, &args[0]); /* set the ma number in all of this module's widgets */ PtSetArg(&args[0], Pt_ARG_USER_DATA, &maNum, sizeof(int)); PtSetResources(ABW_memArrayMenuButton, 1, &args[0]); PtSetResources(ABW_maDialogAddrOvrRide, 1, &args[0]); PtSetResources(ABW_maDialogPtsOvrRide, 1, &args[0]); PtSetResources(ABW_maDialogMsecOvrRide, 1, &args[0]); PtSetResources(ABW_maDialogRepeatOvrRide, 1, &args[0]); PtSetResources(ABW_memArrayAddress, 1, &args[0]); PtSetResources(ABW_memArrayCount, 1, &args[0]); PtSetResources(ABW_memArrayMsec, 1, &args[0]); PtSetResources(ABW_memArrayRepeat, 1, &args[0]); maDialogItemEnable(maNum); return( Pt_CONTINUE ); } int memArrayDialogSet( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { PtArg_t args[2]; int *pMaNum; int *value; int maNum; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo, cbinfo = cbinfo; /* get the status of the on-off switch */ PtSetArg(&args[0], Pt_ARG_ONOFF_STATE, &value, 0); PtSetArg(&args[1], Pt_ARG_USER_DATA, &pMaNum, 0); PtGetResources(widget, 2, args); maNum = *pMaNum; if(*value) { PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "Dialog Enabled", 0); ma[maNum].m_ma_menu = 1; } else { PtSetArg(&args[0], Pt_ARG_TEXT_STRING, "Dialog Disabled", 0); ma[maNum].m_ma_menu = 0; } PtSetResources(widget, 1, args); maDialogItemEnable(maNum); ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); return( Pt_CONTINUE ); } void maDialogItemEnable(int maNum) { PtArg_t args[2]; /* enable dialog items if menu is enabled */ if(ma[maNum].m_ma_menu) { PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_FALSE, Pt_GHOST); PtSetArg(&args[1], Pt_ARG_FLAGS, Pt_TRUE, Pt_SELECTABLE); } else { PtSetArg(&args[0], Pt_ARG_FLAGS, Pt_TRUE, Pt_GHOST); PtSetArg(&args[1], Pt_ARG_FLAGS, Pt_FALSE, Pt_SELECTABLE); } PtSetResources(ABW_maDialogAddrOvrRide, 2, args); PtSetResources(ABW_maDialogPtsOvrRide, 2, args); PtSetResources(ABW_maDialogMsecOvrRide, 2, args); PtSetResources(ABW_maDialogRepeatOvrRide, 2, args); return; } int memArrayMenuOverRide( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { PtArg_t arg; int maNum; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo, cbinfo = cbinfo; /* get the da number from the widget */ PtSetArg(&arg, Pt_ARG_USER_DATA, 0, 0); PtGetResources(widget, 1, &arg); maNum = *(int *)arg.value; /* determin which of the override buttons initiated this callback */ if(ApName(widget) == ABN_maDialogAddrOvrRide) { if(cbinfo->reason == Pt_CB_ARM) { maMenuOvrRides[maNum][0] = 1; ma[maNum].m_ma_bap = maAddress[maNum]; } else if(cbinfo->reason == Pt_CB_DISARM) { maMenuOvrRides[maNum][0] = 0; ma[maNum].m_ma_bap = (int *)NULLI; } } else if(ApName(widget) == ABN_maDialogPtsOvrRide) { if(cbinfo->reason == Pt_CB_ARM) { maMenuOvrRides[maNum][1] = 1; ma[maNum].m_ma_count = maNpts[maNum]; } else if(cbinfo->reason == Pt_CB_DISARM) { maMenuOvrRides[maNum][1] = 0; ma[maNum].m_ma_count = NULLI; } } else if(ApName(widget) == ABN_maDialogMsecOvrRide) { if(cbinfo->reason == Pt_CB_ARM) { maMenuOvrRides[maNum][2] = 1; ma[maNum].m_ma_rate = maMsecs[maNum]; } else if(cbinfo->reason == Pt_CB_DISARM) { maMenuOvrRides[maNum][2] = 0; ma[maNum].m_ma_rate = NULLI; } } else if(ApName(widget) == ABN_maDialogRepeatOvrRide) { if(cbinfo->reason == Pt_CB_ARM) { maMenuOvrRides[maNum][3] = 1; ma[maNum].m_ma_repeat = maRepeats[maNum]; } else if(cbinfo->reason == Pt_CB_DISARM) { maMenuOvrRides[maNum][3] = 0; ma[maNum].m_ma_repeat = NULLI; } } ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); return( Pt_CONTINUE ); } int memArrayParameters( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { PtArg_t args[2]; int *lngVal; int maNum; int value; /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo, cbinfo = cbinfo; /* get the ma number and value from the widget */ PtSetArg(&args[0], Pt_ARG_USER_DATA, 0, 0); PtSetArg(&args[1], Pt_ARG_NUMERIC_VALUE, 0, 0); PtGetResources(widget, 2, args); maNum = *(int *)args[0].value; /* figure out which widget initiated this callback */ if(ApName(widget) == ABN_memArrayAddress) { lngVal = (int *)args[1].value; maAddress[maNum] = lngVal; if(maMenuOvrRides[maNum][0]) { ma[maNum].m_ma_bap = maAddress[maNum]; ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); } } else if(ApName(widget) == ABN_memArrayCount) { value = (int) args[1].value; maNpts[maNum] = value; if(maMenuOvrRides[maNum][1]) { ma[maNum].m_ma_count = maNpts[maNum]; ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); } } else if(ApName(widget) == ABN_memArrayMsec) { value = (int) args[1].value; maMsecs[maNum] = value; if(maMenuOvrRides[maNum][2]) { ma[maNum].m_ma_rate = maMsecs[maNum]; ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); } } else if(ApName(widget) == ABN_memArrayRepeat) { value = (int) args[1].value; maRepeats[maNum] = value; if(maMenuOvrRides[maNum][2]) { ma[maNum].m_ma_repeat = maRepeats[maNum]; ma_cntrl(maNum, (int *)NULLI, NULLI, NULLI, NULLI); } } return( Pt_CONTINUE ); } int initMemArraySummary( PtWidget_t *link_instance, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { ApDBase_t *memArraydbase; PtArg_t args[2]; int i; int y; int memNum; char label[4]; /* eliminate 'unreferenced' warnings */ link_instance = link_instance, apinfo = apinfo, cbinfo = cbinfo; /* open the memory array summary data base */ memArraydbase = ApOpenDBase(ABM_memArraySumPictures); /* set the parent for the widgets */ PtSetParentWidget(ABW_memArrayScrollArea); /* create 16 sets of widgets for the memory array summary */ y = 0; for(i = 0; i < MA_MAXNUM; i++) { memNum = i; /* create the label widget for this element */ sprintf(label, "%d", i); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, label, 0); ApCreateWidget(memArraydbase, "memArraySumLabel", 10, y, 2, args); /* create the pointer widget for this element */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[i].ma_bap, 0); ApCreateWidget(memArraydbase, "memArraySumAddress", 48, y, 2, args); /* create the size widget for this element */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[i].ma_count, 0); ApCreateWidget(memArraydbase, "memArraySumSize", 119, y, 2, args); /* create the rate widget for this element */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[i].ma_rate, 0); ApCreateWidget(memArraydbase, "memArraySumRate", 176, y, 2, args); /* create the repeat widget for this element */ PtSetArg(&args[0], Pt_ARG_NUMERIC_VALUE, ma[i].ma_repeat, 0); ApCreateWidget(memArraydbase, "memArraySumRepeat", 233, y, 2, args); y += 30; } /* close the widget data base */ ApCloseDBase(memArraydbase); return( Pt_CONTINUE ); }
[ "fs2478@columbia.edu" ]
fs2478@columbia.edu
a9eae1fbeb6c4c877c2dc9a00dae1fb7566a8821
44e17fda4c084d018b03a225c069766eebe44f63
/libs/ap_utils.c
a013d07bacfd548e1952ba198aea8bafe32b016a
[ "MIT" ]
permissive
kadavris/fprn
17502095848edab1b02473015ecd3247af00c8dc
61a93164bc2f36679a5468b309bd11d868ae529b
refs/heads/master
2021-03-12T20:36:21.589490
2014-09-09T23:00:34
2014-09-09T23:00:34
23,536,319
2
1
null
null
null
null
UTF-8
C
false
false
1,279
c
#ifndef AP_UTILS_C #define AP_UTILS_C #include "ap_utils.h" //========================================================= int ap_utils_timeval_set(struct timeval *tv, int mode, int msec) { struct timeval tmp; if ( msec < 100 ) return 0; switch( mode ) { case AP_UTILS_TIMEVAL_ADD: tmp.tv_sec = msec / 1000; tmp.tv_usec = 1000 * (msec % 1000); timeradd(tv, &tmp, tv); break; case AP_UTILS_TIMEVAL_SUB: tmp.tv_sec = msec / 1000; tmp.tv_usec = 1000 * (msec % 1000); timersub(tv, &tmp, tv); break; case AP_UTILS_TIMEVAL_SET: gettimeofday(tv, 0); tmp.tv_sec = msec / 1000; tmp.tv_usec = 1000 * (msec % 1000); timeradd(tv, &tmp, tv); break; case AP_UTILS_TIMEVAL_SET_FROMZERO: tv->tv_sec = msec / 1000; tv->tv_usec = 1000 * (msec % 1000); break; default: return 0; } return 1; } //========================================================= uint16_t count_crc16(void *mem, int len) { uint16_t a, crc16; uint8_t *pch; pch = (uint8_t *)mem; crc16 = 0; while(len--) { crc16 ^= *pch; a = (crc16 ^ (crc16 << 4)) & 0x00FF; crc16 = (crc16 >> 8) ^ (a << 8) ^ (a << 3) ^ (a >> 4); ++pch; } return(crc16); } #endif
[ "ap@workdesk.home" ]
ap@workdesk.home
eea0b050daf0e3bae3b9d09429956f7938c2a673
2d05862d31a2f0e15800debc6a639cacf6959780
/dmb_timer/settings_file_example/dmb_timer_settings.h
6af03715ae96e0923d2985af1d39b7e9967cb58c
[ "MIT" ]
permissive
dambo1993/dmb_timer
7b527d0db031aa2a09b5301dddb21356fb1a0696
b125380ae810c2b68803a6b172370eee71e45377
refs/heads/master
2020-03-26T22:20:24.409350
2019-07-26T20:11:03
2019-07-26T20:11:03
145,450,183
0
0
null
null
null
null
UTF-8
C
false
false
293
h
/* * dmb_timer_setting.h * * Created on: 31.05.2018 * Author: Przemek */ #ifndef LIBS_CONFIG_DMB_TIMER_SETTINGS_H_ #define LIBS_CONFIG_DMB_TIMER_SETTINGS_H_ //! rozmiar tablicy taskow #define DMB_TIMER_TASKS_NUMBER 25 #endif /* LIBS_CONFIG_DMB_TIMER_SETTINGS_H_ */
[ "thedambo1@gmail.com" ]
thedambo1@gmail.com
72bbe89bc7fdfc8b0f89d96397ac859a580bc9fd
dc3df0c0c81ad3d1a67e24ba76dbc6ecb3f93926
/experimental/id75/qmk_firmware/idobao/id75/keymaps/tom/keymap.c
8d07ab04d5ad991ee0701a78d8736a57a3b53a3b
[]
no_license
thaatz/keyboard-scripts
66ac007df5a48a93162c9d93dc90da8a3510007a
c14bbcf1a67af8265ee25c17346e2267503f3493
refs/heads/master
2023-01-06T09:55:50.998475
2022-12-30T21:32:05
2022-12-30T21:32:05
165,153,059
0
0
null
null
null
null
UTF-8
C
false
false
4,763
c
/* Copyright 2020 IFo Hancroft * * 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, see <http://www.gnu.org/licenses/>. */ #include QMK_KEYBOARD_H // https://github.com/qmk/qmk_firmware/blob/master/docs/keycodes.md const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [0] = LAYOUT_ortho_5x15( KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_NO, KC_NO, KC_NO, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV, KC_TAB, KC_Q, KC_W, LT(4, KC_E), KC_R, KC_T, KC_NO, KC_NO, KC_NO, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS, KC_BSPC, LGUI_T(KC_A), LALT_T(KC_S), LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_NO, KC_NO, KC_NO, KC_H, RSFT_T(KC_J), RCTL_T(KC_K), RALT_T(KC_L), RGUI_T(KC_SCLN), KC_ENT, KC_NO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_NO, KC_NO, KC_NO, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_NO, KC_NO, KC_NO, KC_NO, KC_SPC, MO(3), LT(3, KC_TAB), KC_SPC, KC_SPC, KC_SPC, KC_SPC, MO(2), KC_SPC, KC_SPC, KC_SPC, KC_SPC ), // mousekeys [1] = LAYOUT_ortho_5x15( _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, _______, _______, _______, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLD, KC_MS_U, KC_VOLU, _______, KC_F12, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN3, KC_MS_L, KC_MS_D, KC_MS_R, _______, _______, _______, _______, KC_WH_L, KC_WH_U, KC_WH_D, KC_WH_R, _______, _______, _______, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_BTN1, KC_BTN2, KC_BTN3, _______, _______, _______ ), // arrows [2] = LAYOUT_ortho_5x15( QK_BOOT, _______, _______, _______, _______, _______, _______, QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_UP, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LEFT, KC_DOWN,KC_RIGHT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, QK_BOOT, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), // symbols [3] = LAYOUT_ortho_5x15( KC_GRV, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LCBR, KC_RCBR, _______, KC_MINS, KC_EQL, KC_DEL, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_LPRN, KC_RPRN, _______, _______, KC_QUOT, _______, _______, LCTL(KC_X), LCTL(KC_C), LCTL(KC_V), _______, _______, _______, _______, _______, KC_LBRC, KC_RBRC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ ), // numpad [4] = LAYOUT_ortho_5x15( _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_NUM, _______, _______, _______, _______, _______, _______, TO(0), _______, TO(1), _______, _______, _______, _______, _______, KC_P7, KC_P8, KC_P9, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P4, KC_P5, KC_P6, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P1, KC_P2, KC_P3, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P0, _______, _______, _______, _______ ), };
[ "tom.hongsmatip@gmail.com" ]
tom.hongsmatip@gmail.com
05959b2f60af0fae71627a1f9da84ce66687a75c
4a1ef7414c7f499168fca5095defbca6ff1221d1
/adcs_v15/slprj/_sfprj/adcs_v15_integral_Power_nom/_self/sfun/src/c4_adcs_v15_integral_Power_nom.h
003e10471db028806c2f82c2027e66e2e2eb0d43
[]
no_license
avnishks/pratham
f4d05beaaad3dd9509af12fed18f2b36af930442
d0791f1ec78ed50c42a82126ce0388371f6ee3d3
refs/heads/master
2016-09-16T15:51:35.860966
2013-04-30T19:07:40
2013-04-30T19:07:40
null
0
0
null
null
null
null
UTF-8
C
false
false
1,010
h
#ifndef __c4_adcs_v15_integral_Power_nom_h__ #define __c4_adcs_v15_integral_Power_nom_h__ /* Include files */ #include "sfc_sf.h" #include "sfc_mex.h" #include "rtwtypes.h" /* Type Definitions */ typedef struct { char *context; char *name; char *dominantType; char *resolved; uint32_T fileLength; uint32_T fileTime1; uint32_T fileTime2; } c4_ResolvedFunctionInfo; typedef struct { SimStruct *S; uint32_T chartNumber; uint32_T instanceNumber; ChartInfoStruct chartInfo; } SFc4_adcs_v15_integral_Power_nomInstanceStruct; /* Named Constants */ /* Variable Declarations */ /* Variable Definitions */ /* Function Declarations */ extern const mxArray *sf_c4_adcs_v15_integral_Power_nom_get_eml_resolved_functions_info(void); /* Function Definitions */ extern void sf_c4_adcs_v15_integral_Power_nom_get_check_sum(mxArray *plhs[]); extern void c4_adcs_v15_integral_Power_nom_method_dispatcher(SimStruct *S, int_T method, void *data); #endif
[ "avnish.10.chd@gmail.com" ]
avnish.10.chd@gmail.com
d1f08d52ddd27f88be8b40cb151834be464b2963
5c12e72836d47aad80b86291a450f77e8fdf70c4
/mavlink/v2.0/common/mavlink_msg_attitude_target.h
58d245401eca5ce4e5d9b762c3e5c01effb0de3c
[]
no_license
shukcs/GCApp
61145d263fa6583edcee261759477f8b62629316
6de48cf139b60e4d5c1095432d14f45223b684ae
refs/heads/main
2023-05-26T16:42:19.452741
2023-05-07T09:26:11
2023-05-07T09:26:11
325,685,039
3
2
null
null
null
null
UTF-8
C
false
false
17,721
h
#pragma once // MESSAGE ATTITUDE_TARGET PACKING #define MAVLINK_MSG_ID_ATTITUDE_TARGET 83 MAVPACKED( typedef struct __mavlink_attitude_target_t { uint32_t time_boot_ms; /*< [ms] Timestamp in milliseconds since system boot*/ float q[4]; /*< Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0)*/ float body_roll_rate; /*< [rad/s] Body roll rate in radians per second*/ float body_pitch_rate; /*< [rad/s] Body pitch rate in radians per second*/ float body_yaw_rate; /*< [rad/s] Body yaw rate in radians per second*/ float thrust; /*< Collective thrust, normalized to 0 .. 1 (-1 .. 1 for vehicles capable of reverse trust)*/ uint8_t type_mask; /*< Mappings: If any of these bits are set, the corresponding input should be ignored: bit 1: body roll rate, bit 2: body pitch rate, bit 3: body yaw rate. bit 4-bit 7: reserved, bit 8: attitude*/ }) mavlink_attitude_target_t; #define MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN 37 #define MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN 37 #define MAVLINK_MSG_ID_83_LEN 37 #define MAVLINK_MSG_ID_83_MIN_LEN 37 #define MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC 22 #define MAVLINK_MSG_ID_83_CRC 22 #define MAVLINK_MSG_ATTITUDE_TARGET_FIELD_Q_LEN 4 #if MAVLINK_COMMAND_24BIT #define MAVLINK_MESSAGE_INFO_ATTITUDE_TARGET { \ 83, \ "ATTITUDE_TARGET", \ 7, \ { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_attitude_target_t, time_boot_ms) }, \ { "type_mask", NULL, MAVLINK_TYPE_UINT8_T, 0, 36, offsetof(mavlink_attitude_target_t, type_mask) }, \ { "q", NULL, MAVLINK_TYPE_FLOAT, 4, 4, offsetof(mavlink_attitude_target_t, q) }, \ { "body_roll_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_attitude_target_t, body_roll_rate) }, \ { "body_pitch_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_attitude_target_t, body_pitch_rate) }, \ { "body_yaw_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_attitude_target_t, body_yaw_rate) }, \ { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_attitude_target_t, thrust) }, \ } \ } #else #define MAVLINK_MESSAGE_INFO_ATTITUDE_TARGET { \ "ATTITUDE_TARGET", \ 7, \ { { "time_boot_ms", NULL, MAVLINK_TYPE_UINT32_T, 0, 0, offsetof(mavlink_attitude_target_t, time_boot_ms) }, \ { "type_mask", NULL, MAVLINK_TYPE_UINT8_T, 0, 36, offsetof(mavlink_attitude_target_t, type_mask) }, \ { "q", NULL, MAVLINK_TYPE_FLOAT, 4, 4, offsetof(mavlink_attitude_target_t, q) }, \ { "body_roll_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_attitude_target_t, body_roll_rate) }, \ { "body_pitch_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_attitude_target_t, body_pitch_rate) }, \ { "body_yaw_rate", NULL, MAVLINK_TYPE_FLOAT, 0, 28, offsetof(mavlink_attitude_target_t, body_yaw_rate) }, \ { "thrust", NULL, MAVLINK_TYPE_FLOAT, 0, 32, offsetof(mavlink_attitude_target_t, thrust) }, \ } \ } #endif /** * @brief Pack a attitude_target message * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * * @param time_boot_ms [ms] Timestamp in milliseconds since system boot * @param type_mask Mappings: If any of these bits are set, the corresponding input should be ignored: bit 1: body roll rate, bit 2: body pitch rate, bit 3: body yaw rate. bit 4-bit 7: reserved, bit 8: attitude * @param q Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0) * @param body_roll_rate [rad/s] Body roll rate in radians per second * @param body_pitch_rate [rad/s] Body pitch rate in radians per second * @param body_yaw_rate [rad/s] Body yaw rate in radians per second * @param thrust Collective thrust, normalized to 0 .. 1 (-1 .. 1 for vehicles capable of reverse trust) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_attitude_target_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint32_t time_boot_ms, uint8_t type_mask, const float *q, float body_roll_rate, float body_pitch_rate, float body_yaw_rate, float thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN]; _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_float(buf, 20, body_roll_rate); _mav_put_float(buf, 24, body_pitch_rate); _mav_put_float(buf, 28, body_yaw_rate); _mav_put_float(buf, 32, thrust); _mav_put_uint8_t(buf, 36, type_mask); _mav_put_float_array(buf, 4, q, 4); memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN); #else mavlink_attitude_target_t packet; packet.time_boot_ms = time_boot_ms; packet.body_roll_rate = body_roll_rate; packet.body_pitch_rate = body_pitch_rate; packet.body_yaw_rate = body_yaw_rate; packet.thrust = thrust; packet.type_mask = type_mask; mav_array_memcpy(packet.q, q, sizeof(float)*4); memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN); #endif msg->msgid = MAVLINK_MSG_ID_ATTITUDE_TARGET; return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); } /** * @brief Pack a attitude_target message on a channel * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message will be sent over * @param msg The MAVLink message to compress the data into * @param time_boot_ms [ms] Timestamp in milliseconds since system boot * @param type_mask Mappings: If any of these bits are set, the corresponding input should be ignored: bit 1: body roll rate, bit 2: body pitch rate, bit 3: body yaw rate. bit 4-bit 7: reserved, bit 8: attitude * @param q Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0) * @param body_roll_rate [rad/s] Body roll rate in radians per second * @param body_pitch_rate [rad/s] Body pitch rate in radians per second * @param body_yaw_rate [rad/s] Body yaw rate in radians per second * @param thrust Collective thrust, normalized to 0 .. 1 (-1 .. 1 for vehicles capable of reverse trust) * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_attitude_target_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint32_t time_boot_ms,uint8_t type_mask,const float *q,float body_roll_rate,float body_pitch_rate,float body_yaw_rate,float thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN]; _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_float(buf, 20, body_roll_rate); _mav_put_float(buf, 24, body_pitch_rate); _mav_put_float(buf, 28, body_yaw_rate); _mav_put_float(buf, 32, thrust); _mav_put_uint8_t(buf, 36, type_mask); _mav_put_float_array(buf, 4, q, 4); memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN); #else mavlink_attitude_target_t packet; packet.time_boot_ms = time_boot_ms; packet.body_roll_rate = body_roll_rate; packet.body_pitch_rate = body_pitch_rate; packet.body_yaw_rate = body_yaw_rate; packet.thrust = thrust; packet.type_mask = type_mask; mav_array_memcpy(packet.q, q, sizeof(float)*4); memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN); #endif msg->msgid = MAVLINK_MSG_ID_ATTITUDE_TARGET; return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); } /** * @brief Encode a attitude_target struct * * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * @param attitude_target C-struct to read the message contents from */ static inline uint16_t mavlink_msg_attitude_target_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_attitude_target_t* attitude_target) { return mavlink_msg_attitude_target_pack(system_id, component_id, msg, attitude_target->time_boot_ms, attitude_target->type_mask, attitude_target->q, attitude_target->body_roll_rate, attitude_target->body_pitch_rate, attitude_target->body_yaw_rate, attitude_target->thrust); } /** * @brief Encode a attitude_target struct on a channel * * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message will be sent over * @param msg The MAVLink message to compress the data into * @param attitude_target C-struct to read the message contents from */ static inline uint16_t mavlink_msg_attitude_target_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_attitude_target_t* attitude_target) { return mavlink_msg_attitude_target_pack_chan(system_id, component_id, chan, msg, attitude_target->time_boot_ms, attitude_target->type_mask, attitude_target->q, attitude_target->body_roll_rate, attitude_target->body_pitch_rate, attitude_target->body_yaw_rate, attitude_target->thrust); } /** * @brief Send a attitude_target message * @param chan MAVLink channel to send the message * * @param time_boot_ms [ms] Timestamp in milliseconds since system boot * @param type_mask Mappings: If any of these bits are set, the corresponding input should be ignored: bit 1: body roll rate, bit 2: body pitch rate, bit 3: body yaw rate. bit 4-bit 7: reserved, bit 8: attitude * @param q Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0) * @param body_roll_rate [rad/s] Body roll rate in radians per second * @param body_pitch_rate [rad/s] Body pitch rate in radians per second * @param body_yaw_rate [rad/s] Body yaw rate in radians per second * @param thrust Collective thrust, normalized to 0 .. 1 (-1 .. 1 for vehicles capable of reverse trust) */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS static inline void mavlink_msg_attitude_target_send(mavlink_channel_t chan, uint32_t time_boot_ms, uint8_t type_mask, const float *q, float body_roll_rate, float body_pitch_rate, float body_yaw_rate, float thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN]; _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_float(buf, 20, body_roll_rate); _mav_put_float(buf, 24, body_pitch_rate); _mav_put_float(buf, 28, body_yaw_rate); _mav_put_float(buf, 32, thrust); _mav_put_uint8_t(buf, 36, type_mask); _mav_put_float_array(buf, 4, q, 4); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_TARGET, buf, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); #else mavlink_attitude_target_t packet; packet.time_boot_ms = time_boot_ms; packet.body_roll_rate = body_roll_rate; packet.body_pitch_rate = body_pitch_rate; packet.body_yaw_rate = body_yaw_rate; packet.thrust = thrust; packet.type_mask = type_mask; mav_array_memcpy(packet.q, q, sizeof(float)*4); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_TARGET, (const char *)&packet, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); #endif } /** * @brief Send a attitude_target message * @param chan MAVLink channel to send the message * @param struct The MAVLink struct to serialize */ static inline void mavlink_msg_attitude_target_send_struct(mavlink_channel_t chan, const mavlink_attitude_target_t* attitude_target) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS mavlink_msg_attitude_target_send(chan, attitude_target->time_boot_ms, attitude_target->type_mask, attitude_target->q, attitude_target->body_roll_rate, attitude_target->body_pitch_rate, attitude_target->body_yaw_rate, attitude_target->thrust); #else _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_TARGET, (const char *)attitude_target, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); #endif } #if MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN <= MAVLINK_MAX_PAYLOAD_LEN /* This varient of _send() can be used to save stack space by re-using memory from the receive buffer. The caller provides a mavlink_message_t which is the size of a full mavlink message. This is usually the receive buffer for the channel, and allows a reply to an incoming message with minimum stack space usage. */ static inline void mavlink_msg_attitude_target_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint32_t time_boot_ms, uint8_t type_mask, const float *q, float body_roll_rate, float body_pitch_rate, float body_yaw_rate, float thrust) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char *buf = (char *)msgbuf; _mav_put_uint32_t(buf, 0, time_boot_ms); _mav_put_float(buf, 20, body_roll_rate); _mav_put_float(buf, 24, body_pitch_rate); _mav_put_float(buf, 28, body_yaw_rate); _mav_put_float(buf, 32, thrust); _mav_put_uint8_t(buf, 36, type_mask); _mav_put_float_array(buf, 4, q, 4); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_TARGET, buf, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); #else mavlink_attitude_target_t *packet = (mavlink_attitude_target_t *)msgbuf; packet->time_boot_ms = time_boot_ms; packet->body_roll_rate = body_roll_rate; packet->body_pitch_rate = body_pitch_rate; packet->body_yaw_rate = body_yaw_rate; packet->thrust = thrust; packet->type_mask = type_mask; mav_array_memcpy(packet->q, q, sizeof(float)*4); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_ATTITUDE_TARGET, (const char *)packet, MAVLINK_MSG_ID_ATTITUDE_TARGET_MIN_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN, MAVLINK_MSG_ID_ATTITUDE_TARGET_CRC); #endif } #endif #endif // MESSAGE ATTITUDE_TARGET UNPACKING /** * @brief Get field time_boot_ms from attitude_target message * * @return [ms] Timestamp in milliseconds since system boot */ static inline uint32_t mavlink_msg_attitude_target_get_time_boot_ms(const mavlink_message_t* msg) { return _MAV_RETURN_uint32_t(msg, 0); } /** * @brief Get field type_mask from attitude_target message * * @return Mappings: If any of these bits are set, the corresponding input should be ignored: bit 1: body roll rate, bit 2: body pitch rate, bit 3: body yaw rate. bit 4-bit 7: reserved, bit 8: attitude */ static inline uint8_t mavlink_msg_attitude_target_get_type_mask(const mavlink_message_t* msg) { return _MAV_RETURN_uint8_t(msg, 36); } /** * @brief Get field q from attitude_target message * * @return Attitude quaternion (w, x, y, z order, zero-rotation is 1, 0, 0, 0) */ static inline uint16_t mavlink_msg_attitude_target_get_q(const mavlink_message_t* msg, float *q) { return _MAV_RETURN_float_array(msg, q, 4, 4); } /** * @brief Get field body_roll_rate from attitude_target message * * @return [rad/s] Body roll rate in radians per second */ static inline float mavlink_msg_attitude_target_get_body_roll_rate(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 20); } /** * @brief Get field body_pitch_rate from attitude_target message * * @return [rad/s] Body pitch rate in radians per second */ static inline float mavlink_msg_attitude_target_get_body_pitch_rate(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 24); } /** * @brief Get field body_yaw_rate from attitude_target message * * @return [rad/s] Body yaw rate in radians per second */ static inline float mavlink_msg_attitude_target_get_body_yaw_rate(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 28); } /** * @brief Get field thrust from attitude_target message * * @return Collective thrust, normalized to 0 .. 1 (-1 .. 1 for vehicles capable of reverse trust) */ static inline float mavlink_msg_attitude_target_get_thrust(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 32); } /** * @brief Decode a attitude_target message into a struct * * @param msg The message to decode * @param attitude_target C-struct to decode the message contents into */ static inline void mavlink_msg_attitude_target_decode(const mavlink_message_t* msg, mavlink_attitude_target_t* attitude_target) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS attitude_target->time_boot_ms = mavlink_msg_attitude_target_get_time_boot_ms(msg); mavlink_msg_attitude_target_get_q(msg, attitude_target->q); attitude_target->body_roll_rate = mavlink_msg_attitude_target_get_body_roll_rate(msg); attitude_target->body_pitch_rate = mavlink_msg_attitude_target_get_body_pitch_rate(msg); attitude_target->body_yaw_rate = mavlink_msg_attitude_target_get_body_yaw_rate(msg); attitude_target->thrust = mavlink_msg_attitude_target_get_thrust(msg); attitude_target->type_mask = mavlink_msg_attitude_target_get_type_mask(msg); #else uint8_t len = msg->len < MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN? msg->len : MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN; memset(attitude_target, 0, MAVLINK_MSG_ID_ATTITUDE_TARGET_LEN); memcpy(attitude_target, _MAV_PAYLOAD(msg), len); #endif }
[ "hsj8262@163.com" ]
hsj8262@163.com
b19f08c21ba3c390807134b606d2c9bef889ca2b
9b96f30b6353f1696a49434474a28247a981f5bf
/A3/a3_p3.c
de7c1d5fda498ed404ad5a96cc44ebdccd3198b4
[]
no_license
Magrawal17/Programming-in-C-and-C--Basics
780d64dfa8c4bf3d9d53de0b13420cf063cd38eb
0601e9bc56f04e8a2718ea9e3f2225799ac56eea
refs/heads/master
2022-11-21T19:33:59.968624
2020-07-21T03:04:24
2020-07-21T03:04:24
281,277,881
0
1
null
null
null
null
UTF-8
C
false
false
289
c
/* CH-230-A a2_p3.c Mahiem Agrawal m.agrawal@jacobs-university.de */ #include <stdio.h> float convert(int cm); int main(){ int cm; float km; scanf("%d",&cm); km = convert(cm); printf("Result of conversion: %lf\n",km); return 0; } float convert(int cm) { return (cm/100000.0); }
[ "noreply@github.com" ]
Magrawal17.noreply@github.com
de78cb7204e721f39459474ae6fc0522c44ff2d4
de21f9075f55640514c29ef0f1fe3f0690845764
/regression/cbmc-library/fileno-01/main.c
c186de1b88d9cc21e3061e8ee0f36ca2c9d2ab6f
[ "BSD-2-Clause", "LicenseRef-scancode-unknown-license-reference", "BSD-4-Clause" ]
permissive
diffblue/cbmc
975a074ac445febb3b5715f8792beb545522dc18
decd2839c2f51a54b2ad0f3e89fdc1b4bf78cd16
refs/heads/develop
2023-08-31T05:52:05.342195
2023-08-30T13:31:51
2023-08-30T13:31:51
51,877,056
589
309
NOASSERTION
2023-09-14T18:49:17
2016-02-16T23:03:52
C++
UTF-8
C
false
false
303
c
#include <assert.h> #include <stdio.h> int main() { // requires initialization of stdin/stdout/stderr // assert(fileno(stdin) == 0); // assert(fileno(stdout) == 1); // assert(fileno(stderr) == 2); int fd; FILE *some_file = fdopen(fd, ""); assert(fileno(some_file) >= -1); return 0; }
[ "tautschn@amazon.com" ]
tautschn@amazon.com
caae7485165e19c4fa69b42f08b3f5745c653f69
f76603be318f910f12e8ee8efe703b4a7f8e5d67
/CPE_2016_stumper1/src/main.c
a7fa8fa3fb4cd4889d40acce1968d80f6bab0d83
[]
no_license
jeremy9875/CPE_2016_stumper1
fc6519e69e5ec38887dc83b359255a254fd47115
334eb03f8c828b869696a8c60222a0801ffc90ee
refs/heads/master
2020-03-25T18:14:03.848438
2018-08-08T13:45:23
2018-08-08T13:45:23
144,019,806
0
0
null
null
null
null
UTF-8
C
false
false
1,676
c
/* ** main.c for main in /home/jeremy.elkaim/CPE_2016_stumper1/src ** ** Made by jeremy elkaim ** Login <jeremy.elkaim@epitech.net> ** ** Started on Thu Apr 20 14:40:23 2017 jeremy elkaim ** Last update Thu Apr 20 18:13:35 2017 jeremy elkaim */ #include <unistd.h> #include "../include/tail.h" int main(int ac, char **av) { void *buf; if (ac == 1) { while (1) read(0, buf, 2048); } else if (ac > 1) return(checkarg(ac, av)); else return (84); return (0); } void init_flags(t_flags *flags) { flags->c_flag = -1; flags->n_flag = -1; flags->read_size = -1; flags->q_flag = -1; flags->v_flag = -1; } int checkarg(int ac, char **av) { int x; t_flags flags; x = 1; init_flags(&flags); while (x < ac) { if (my_strcmp(av[x], "-c") == 0 || my_strcmp(av[x], "--bytes") == 0) x = verif_flags(&flags, 1, x, av); else if (my_strcmp(av[x], "-n") == 0 || my_strcmp(av[x], "--lines") == 0) x = verif_flags(&flags, 2, x, av); x++; } return (0); } int verif_flags(t_flags *flags, int i, int x, char **av) { if (i == 1) { if (flags->n_flag == -1 || flags->n_flag == 1) { flags->n_flag = -1; flags->c_flag = 1; flags->read_size = my_atoi(av[x + 1]); x++; } } else if (i == 2) { if (flags->c_flag == -1 || flags->c_flag == 1) { flags->c_flag = -1; flags->n_flag = 1; flags->read_size = my_atoi(av[x + 1]); x++; } } return (x); } int my_strcmp(char *a, char *b) { int index; index = 0; while (a[index] != '\0' && b[index] != '\0') { if (a[index] - b[index] != 0) return (1); index++; } return (0); }
[ "jeremy.el-kaim@epitech.eu" ]
jeremy.el-kaim@epitech.eu
48d05b915fee1b72824a08ce1472c9e48d7ed27e
897833183b8ec6f11ec9d052e4da41852ccd624b
/en.stm32cubef7/STM32Cube_FW_F7_V1.4.0/Projects/STM32746G-Discovery/Examples/ADC/ADC_RegularConversion_DMA/Inc/stm32f7xx_it.h
9da2baf909f3ba108fc18f7bad83ec4e4265ae53
[ "BSD-2-Clause" ]
permissive
kilianod5150/em_tracker_system
9d28b996316caec3198dc7a19ce0ed854e1764e3
f7d5c1ac50825d01acb625961c3d7cc03c7897b8
refs/heads/master
2021-01-12T03:03:25.251066
2017-03-21T22:55:29
2017-03-21T22:55:29
78,153,181
0
0
null
null
null
null
UTF-8
C
false
false
3,110
h
/** ****************************************************************************** * @file ADC/ADC_RegularConversion_DMA/Inc/stm32f7xx_it.h * @author MCD Application Team * @version V1.0.3 * @date 22-April-2016 * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2> * * 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. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * 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. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F7xx_IT_H #define __STM32F7xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* Exported macro ------------------------------------------------------------*/ /* Exported functions ------------------------------------------------------- */ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void ADCx_DMA_IRQHandler(void); #ifdef __cplusplus } #endif #endif /* __STM32F7xx_IT_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
[ "kilianod@gmail.com" ]
kilianod@gmail.com
bbf22757501f5618c34bb29fa54ac594e356a539
e38b9851d2382a47728adde068ae9cfec3af402d
/code/coord.c
c0197a07d8ff495e5159b29e276c612b24717f6c
[ "MIT" ]
permissive
pekrau/MolScript
e7ac8d4931e4ff90e4789e1980096b98fb0124f3
b672de6542fd3c6625ed3f2184c2393e6d44694a
refs/heads/master
2022-07-21T06:01:34.237791
2022-07-11T12:08:27
2022-07-11T12:08:27
26,034,287
27
11
null
2016-08-23T09:09:25
2014-10-31T21:52:47
C
UTF-8
C
false
false
8,112
c
/* coord.c MolScript v2.1.2 Coordinate data handling. Copyright (C) 1997-1998 Per Kraulis 3-Dec-1996 first attempts 3-Jan-1997 fairly finished 30-Jan-1997 use clib mol3d */ #include <assert.h> #include <stdlib.h> #include "clib/str_utils.h" #include "coord.h" #include "global.h" #include "lex.h" #include "select.h" /*============================================================*/ mol3d *first_molecule = NULL; int total_atoms = 0; int total_residues = 0; static char *molname = NULL; /*------------------------------------------------------------*/ void store_molname (char *name) { assert (name); assert (*name); if (molname) free (molname); molname = str_clone (name); } /*------------------------------------------------------------*/ void read_coordinate_file (char *filename) { mol3d *mol = NULL; mol3d *mol2; res3d *res; at3d *at; int mol_count = 0; int res_count= 0; int at_count = 0; if (filename) { if (mol3d_is_pdb_code (filename)) { if (message_mode) fprintf (stderr, "reading PDB data set...\n"); mol = mol3d_read_pdb_code (filename); } else { switch (mol3d_file_type (filename)) { case MOL3D_UNKNOWN_FILE: case MOL3D_PDB_FILE: if (message_mode) fprintf (stderr, "reading PDB file...\n"); mol = mol3d_read_pdb_filename (filename); break; case MOL3D_MSA_FILE: not_implemented ("MSA coordinate file format"); break; case MOL3D_DG_FILE: not_implemented ("DG coordinate file format"); break; case MOL3D_RD_FILE: not_implemented ("RD coordinate file format"); break; case MOL3D_CDS_FILE: not_implemented ("CDS coordinate file format"); break; case MOL3D_WAH_FILE: not_implemented ("WAH coordinate file format"); break; } } } else { char ch; FILE *file = lex_input_file(); if (message_mode) fprintf (stderr, "reading inline PDB coordinate data...\n"); while ((ch = fgetc (file)) != '\n') { if (ch == EOF) yyerror ("no inline PDB coordinate data"); } mol = mol3d_read_pdb_file (file); } if (mol == NULL) { yyerror ("no molecule read; could not open file, or file format error"); return; } for (mol2 = mol; mol2; mol2 = mol2->next) { mol_count++; mol3d_set_name (mol2, molname); mol3d_init (mol2, MOL3D_INIT_NOBLANKS | MOL3D_INIT_COLOURS | MOL3D_INIT_RADII | MOL3D_INIT_AACODES | MOL3D_INIT_CENTRALS | MOL3D_INIT_ATOM_ORDINALS | MOL3D_INIT_ELEMENTS); mol3d_init_residue_ordinals_protein (mol2); for (res = mol2->first; res; res = res->next) {/* change '*' to ''' to */ res_count++; /* avoid clash with */ for (at = res->first; at; at = at->next) { /* MolScript wildcard */ at_count++; str_exchange (at->name, '*', '\''); } } } if (message_mode) { if (mol_count > 1) fprintf (stderr, "%i models, ", mol_count); fprintf (stderr, "%i residues and %i atoms read into molecule %s\n", res_count, at_count, mol->name); } if (first_molecule) { mol3d_append (first_molecule, mol); } else { first_molecule = mol; } update_totals(); } /*------------------------------------------------------------*/ void update_totals (void) { if (first_molecule) { total_residues = mol3d_count_residues_all (first_molecule); total_atoms = mol3d_count_atoms_all (first_molecule); } else { total_residues = 0; total_atoms = 0; } } /*------------------------------------------------------------*/ void copy_molecule (char *name) { mol3d *mol, *new_mol; res3d *res, *first_res, *new_res; res3d *prev_res = NULL; res3d *curr_res = NULL; at3d *curr_at = NULL; at3d *at, *new_at; int *flags; int rescount = 0; int atcount= 0; assert (name); assert (*name); assert (count_atom_selections() == 1); new_mol = mol3d_create(); mol3d_set_name (new_mol, name); flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { if (*flags++) { new_at = at3d_clone (at); atcount++; if (prev_res != res) { prev_res = res; new_res = res3d_clone (res); rescount++; if (curr_res) { res3d_add (curr_res, new_res); } else { first_res = new_res; mol3d_append_residue (new_mol, first_res); } curr_res = new_res; res3d_append_atom (curr_res, new_at); } else { at3d_add (curr_at, new_at); } curr_at = new_at; } } } } pop_atom_selection(); mol3d_init (new_mol, MOL3D_INIT_NOBLANKS | MOL3D_INIT_COLOURS | MOL3D_INIT_RADII | MOL3D_INIT_AACODES | MOL3D_INIT_CENTRALS | MOL3D_INIT_ATOM_ORDINALS | MOL3D_INIT_ELEMENTS); mol3d_init_residue_ordinals_protein (new_mol); mol3d_append (first_molecule, new_mol); update_totals(); if (message_mode) fprintf (stderr, "%i residues and %i atoms copied to molecule %s\n", rescount, atcount, new_mol->name); assert (count_atom_selections() == 0); } /*------------------------------------------------------------*/ void delete_molecule (char *name) { mol3d *mol; boolean nothing_deleted = TRUE; assert (name); assert (*name); mol = first_molecule; while (mol) { if (str_eq (mol->name, name)) { mol3d *next = mol->next; named_data *nd; if (mol == first_molecule) { first_molecule = mol->next; mol->next = NULL; } else { mol3d_remove_molecule (first_molecule, mol); } if (message_mode) { fprintf (stderr, "deleting molecule %s", name); if (mol->model != 0) fprintf (stderr, " (model %i)", mol->model); fprintf (stderr, "\n"); } mol3d_delete (mol); nothing_deleted = FALSE; mol = next; } else { mol = mol->next; } } update_totals(); if (nothing_deleted) yyerror ("no such molecule to delete"); } /*------------------------------------------------------------*/ void delete_all_molecules (void) { if (first_molecule) { mol3d_delete_all (first_molecule); first_molecule = NULL; } update_totals(); } /*------------------------------------------------------------*/ mol3d_chain * get_peptide_chains (void) { mol3d_chain *ch; #ifndef NDEBUG int old = count_residue_selections(); assert (old >= 1); #endif ch = mol3d_chain_find (first_molecule, PEPTIDE_CHAIN_ATOMNAME, PEPTIDE_DISTANCE, current_residue_sel->flags); pop_residue_selection(); #ifndef NDEBUG assert (count_residue_selections() == old - 1); #endif return ch; } /*------------------------------------------------------------*/ mol3d_chain * get_nucleotide_chains (void) { mol3d_chain *ch; #ifndef NDEBUG int old = count_residue_selections(); assert (old >= 1); #endif ch = mol3d_chain_find (first_molecule, NUCLEOTIDE_CHAIN_ATOMNAME, NUCLEOTIDE_DISTANCE, current_residue_sel->flags); pop_residue_selection(); #ifndef NDEBUG assert (count_residue_selections() == old - 1); #endif return ch; } /*------------------------------------------------------------*/ void position (void) { mol3d *mol; res3d *res; at3d *at; double x = 0.0; double y = 0.0; double z = 0.0; int count = 0; int *flags; #ifndef NDEBUG int old = count_atom_selections(); assert (old >= 1); #endif flags = current_atom_sel->flags; for (mol = first_molecule; mol; mol = mol->next) { for (res = mol->first; res; res = res->next) { for (at = res->first; at; at = at->next) { if (*flags++) { x += at->xyz.x; y += at->xyz.y; z += at->xyz.z; count++; } } } } pop_atom_selection(); if (count > 0) { push_double (x / ((double) count)); push_double (y / ((double) count)); push_double (z / ((double) count)); if (message_mode) fprintf (stderr, "%i atoms selected for position\n", count); } else { yyerror ("0 atoms selected for position"); push_double (0.0); push_double (0.0); push_double (0.0); } #ifndef NDEBUG assert (count_atom_selections() == old - 1); #endif }
[ "per.kraulis@gmail.com" ]
per.kraulis@gmail.com
6ba8919e01dc3a2312ee702c6746c3aee1813a46
b71b8bd385c207dffda39d96c7bee5f2ccce946c
/testcases/CWE122_Heap_Based_Buffer_Overflow/s08/CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02.c
71aafb46b98f117ec8497287d0f9cc1f4511eb49
[]
no_license
Sporknugget/Juliet_prep
e9bda84a30bdc7938bafe338b4ab2e361449eda5
97d8922244d3d79b62496ede4636199837e8b971
refs/heads/master
2023-05-05T14:41:30.243718
2021-05-25T16:18:13
2021-05-25T16:18:13
369,334,230
0
0
null
null
null
null
UTF-8
C
false
false
3,416
c
/* TEMPLATE GENERATED TESTCASE FILE Filename: CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02.c Label Definition File: CWE122_Heap_Based_Buffer_Overflow__c_CWE805.label.xml Template File: sources-sink-02.tmpl.c */ /* * @description * CWE: 122 Heap Based Buffer Overflow * BadSource: Allocate using malloc() and set data pointer to a small buffer * GoodSource: Allocate using malloc() and set data pointer to a large buffer * Sink: memmove * BadSink : Copy int64_t array to data using memmove * Flow Variant: 02 Control flow: if(1) and if(0) * * */ #include "std_testcase.h" #ifndef OMITBAD void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02_bad() { int64_t * data; data = NULL; { /* FLAW: Allocate and point data to a small buffer that is smaller than the large buffer used in the sinks */ data = (int64_t *)malloc(50*sizeof(int64_t)); if (data == NULL) {exit(-1);} } { int64_t source[100] = {0}; /* fill with 0's */ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */ memmove(data, source, 100*sizeof(int64_t)); printLongLongLine(data[0]); free(data); } } #endif /* OMITBAD */ #ifndef OMITGOOD /* goodG2B1() - use goodsource and badsink by changing the 1 to 0 */ static void goodG2B1() { int64_t * data; data = NULL; { /* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */ data = (int64_t *)malloc(100*sizeof(int64_t)); if (data == NULL) {exit(-1);} } { int64_t source[100] = {0}; /* fill with 0's */ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */ memmove(data, source, 100*sizeof(int64_t)); printLongLongLine(data[0]); free(data); } } /* goodG2B2() - use goodsource and badsink by reversing the blocks in the if statement */ static void goodG2B2() { int64_t * data; data = NULL; { /* FIX: Allocate and point data to a large buffer that is at least as large as the large buffer used in the sink */ data = (int64_t *)malloc(100*sizeof(int64_t)); if (data == NULL) {exit(-1);} } { int64_t source[100] = {0}; /* fill with 0's */ /* POTENTIAL FLAW: Possible buffer overflow if data < 100 */ memmove(data, source, 100*sizeof(int64_t)); printLongLongLine(data[0]); free(data); } } void CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02_good() { goodG2B1(); goodG2B2(); } #endif /* OMITGOOD */ /* Below is the main(). It is only used when building this testcase on * its own for testing or for building a binary to use in testing binary * analysis tools. It is not used when compiling all the testcases as one * application, which is how source code analysis tools are tested. */ #ifdef INCLUDEMAIN int main(int argc, char * argv[]) { /* seed randomness */ srand( (unsigned)time(NULL) ); #ifndef OMITGOOD printLine("Calling good()..."); CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02_good(); printLine("Finished good()"); #endif /* OMITGOOD */ #ifndef OMITBAD printLine("Calling bad()..."); CWE122_Heap_Based_Buffer_Overflow__c_CWE805_int64_t_memmove_02_bad(); printLine("Finished bad()"); #endif /* OMITBAD */ return 0; } #endif
[ "jaredzap@rams.colostate.edu" ]
jaredzap@rams.colostate.edu
40429ea9165aef59573642b5a6eb6b87d4f12eeb
b2a5c28e527f1b5e655a7c7f43850a261cd704ae
/lab10_que6.c
1b97f4dcdf30b5ce73fe430c8702ab5120797f62
[ "MIT" ]
permissive
coderdhruv/labsheet10
3901e32251d2231ee8790fea79c8cde6b62fe3b4
19f27538a91828f119371865c0ff8a3c5bd115b5
refs/heads/master
2020-05-09T18:19:44.411218
2019-04-18T08:03:59
2019-04-18T08:03:59
181,337,889
0
0
null
null
null
null
UTF-8
C
false
false
1,008
c
#include<stdio.h> #include<stdlib.h> #include<string.h> int main(){ int global[100000]; int n; scanf("%d",&n); int i,j,k,g=0; int freq_min = 0; int freq_max = 0; int min = 100000; int max = 0; char ch[10]; char query1[10] = "Push"; char query2[10] = "Diff"; char query3[10] = "CountHigh"; char query4[10] = "CountLow"; for(i=0;i<n;i++){ int num; scanf("%s",ch); if(strcmp(ch,query1)==0){ scanf("%d",&num); global[g] = num; g++; if(min != max){ if(num == min){ freq_min++; } if(num == max){ freq_max++; } if(num>max){ max = num; freq_max = 1; } if(num<min){ min = num; freq_min = 1; } } else if(min == max){ if(num == max){ freq_max++; freq_min++; } if(num>max){ max = num; freq_max = 1; } if(num<min){ min = num; freq_min = 1; } } } else if(strcmp(ch,query2)==0){ if } } }
[ "medetedh@gmail.com" ]
medetedh@gmail.com
8cbff5042ceccd2ee5be6e2e88adc56cf206ad16
5d417f03f724f4e23000f28cd629c92bc9297a23
/sam/drivers/spi/unit_tests/sam4c16c_sam4c_ek/conf_board.h
e7b471c5e6ab9290eeed018aa16f06cbc38b4829
[]
no_license
siliconunited/atmel-asf
5ac78a123cb0f5026ffb9a0ba66b75abcccb788f
19e02800a6cc33d203f5d12f7dfca0c39195d879
refs/heads/master
2021-01-22T21:34:10.563981
2017-03-19T04:45:30
2017-03-19T04:45:30
85,439,630
6
3
null
2020-03-08T01:34:35
2017-03-18T23:56:24
C
UTF-8
C
false
false
2,124
h
/** * \file * * \brief Board configuration. * * Copyright (c) 2014-2015 Atmel Corporation. All rights reserved. * * \asf_license_start * * \page License * * 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. * * 3. The name of Atmel may not be used to endorse or promote products derived * from this software without specific prior written permission. * * 4. This software may only be redistributed and used in connection with an * Atmel microcontroller product. * * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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. * * \asf_license_stop * */ /* * Support and FAQ: visit <a href="http://www.atmel.com/design-support/">Atmel Support</a> */ #ifndef CONF_BOARD_H_INCLUDED #define CONF_BOARD_H_INCLUDED /** Enable Com Port. */ #define CONF_BOARD_UART_CONSOLE /** SPI pins initialization */ #define CONF_BOARD_SPI0 /** SPI pin NPCS3 initialization */ #define CONF_BOARD_SPI0_NPCS0 #endif /* CONF_BOARD_H_INCLUDED */
[ "robksawyer@gmail.com" ]
robksawyer@gmail.com
3da3ea080c09d0f39a7087b7577045434ef1fbd0
e4318873e7ce6a52e1f5524c8e1336e80cd41516
/StudyRush/Ass.06_Final/Ass.06_Final/GameType.h
91ec4d9aa4e3861f479234f18783a0c11bdb4ec5
[]
no_license
mThorhauge/StudyRush
8bc2707dfac778340ac1e9160bbba3537ac51ff3
b9e22086376822a73bc33a682c2f4a48399daea8
refs/heads/master
2021-01-10T07:46:41.797969
2016-03-08T00:51:01
2016-03-08T00:51:01
53,369,916
0
0
null
null
null
null
UTF-8
C
false
false
87
h
#pragma once enum GAMETYPE { ONEPLAYER, TWOPLAYER, ONLINESERVE, ONLINECLIENT, UNKNOWN};
[ "mthorhauge@visomo.ca" ]
mthorhauge@visomo.ca
31e17228c58ee074e90b2fbf44fd491904d5daa4
d9669c02baeac92857d4c4628eb1feabc7d92ab1
/inc/timers.h
fef1efd50a3472a700fcc309db4c6c846c3224a6
[]
no_license
lukasmellemrumkluge/BreakOut
6d2c1c8b0a81c1135a775676e2e0be19282987b3
f7349c297b57811b0aa5f8b122b4e186a521927b
refs/heads/master
2020-03-19T03:05:00.965132
2018-06-12T12:32:12
2018-06-12T12:32:12
135,693,087
1
1
null
2018-06-08T08:30:00
2018-06-01T08:51:02
C
UTF-8
C
false
false
453
h
#ifndef _timers_H_ #define _timers_H_ typedef struct { int hours; int minutes; int seconds; int centiseconds; } funTime_t; volatile funTime_t t1; volatile funTime_t t2; void startTimer1(int f); void stopTimer1(void); void resetTimer1(void); void setSplitTimeFromTimer1(funTime_t *split); void startTimer2(int f); void stopTimer2(void); void resetTimer2(void); void setSplitTimeFromTimer2(funTime_t *split); #endif /* _timers_H_ */
[ "39825321+krisdobal@users.noreply.github.com" ]
39825321+krisdobal@users.noreply.github.com
981fe7eba21624c54ad3fad9cb060cfaed2b188c
5c255f911786e984286b1f7a4e6091a68419d049
/code/aa7054eb-c950-40f6-8cd3-3c860dba686e.c
be65845e6defae467dd409d1216632457e2a35f1
[]
no_license
nmharmon8/Deep-Buffer-Overflow-Detection
70fe02c8dc75d12e91f5bc4468cf260e490af1a4
e0c86210c86afb07c8d4abcc957c7f1b252b4eb2
refs/heads/master
2021-09-11T19:09:59.944740
2018-04-06T16:26:34
2018-04-06T16:26:34
125,521,331
0
0
null
null
null
null
UTF-8
C
false
false
229
c
#include <stdio.h> int main() { int i=4; int j=14; int k; int l; k = 53; l = 64; k = j/j; l = i/j; l = l%j; l = l-j; k = k--*i; printf("vulnerability"); printf("%d%d\n",k,l); return 0; }
[ "nharmon8@gmail.com" ]
nharmon8@gmail.com
f6b73c52e6c4e1579cda313d67be3001d35f7535
42ab733e143d02091d13424fb4df16379d5bba0d
/third_party/libpng/powerpc/powerpc_init.c
9187f821c16429c47bc608214bc02feac14d1dbe
[ "Libpng", "Apache-2.0", "CC0-1.0", "LicenseRef-scancode-unknown-license-reference" ]
permissive
google/filament
11cd37ac68790fcf8b33416b7d8d8870e48181f0
0aa0efe1599798d887fa6e33c412c09e81bea1bf
refs/heads/main
2023-08-29T17:58:22.496956
2023-08-28T17:27:38
2023-08-28T17:27:38
143,455,116
16,631
1,961
Apache-2.0
2023-09-14T16:23:39
2018-08-03T17:26:00
C++
UTF-8
C
false
false
4,431
c
/* powerpc_init.c - POWERPC optimised filter functions * * Copyright (c) 2018 Cosmin Truta * Copyright (c) 2017 Glenn Randers-Pehrson * Written by Vadim Barkov, 2017. * * This code is released under the libpng license. * For conditions of distribution and use, see the disclaimer * and license in png.h */ /* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are * called. */ #define _POSIX_SOURCE 1 #include <stdio.h> #include "../pngpriv.h" #ifdef PNG_READ_SUPPORTED #if PNG_POWERPC_VSX_OPT > 0 #ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED /* Do run-time checks */ /* WARNING: it is strongly recommended that you do not build libpng with * run-time checks for CPU features if at all possible. In the case of the PowerPC * VSX instructions there is no processor-specific way of detecting the * presence of the required support, therefore run-time detection is extremely * OS specific. * * You may set the macro PNG_POWERPC_VSX_FILE to the file name of file containing * a fragment of C source code which defines the png_have_vsx function. There * are a number of implementations in contrib/powerpc-vsx, but the only one that * has partial support is contrib/powerpc-vsx/linux.c - a generic Linux * implementation which reads /proc/cpufino. */ #ifndef PNG_POWERPC_VSX_FILE # ifdef __linux__ # define PNG_POWERPC_VSX_FILE "contrib/powerpc-vsx/linux_aux.c" # endif #endif #ifdef PNG_POWERPC_VSX_FILE #include <signal.h> /* for sig_atomic_t */ static int png_have_vsx(png_structp png_ptr); #include PNG_POWERPC_VSX_FILE #else /* PNG_POWERPC_VSX_FILE */ # error "PNG_POWERPC_VSX_FILE undefined: no support for run-time POWERPC VSX checks" #endif /* PNG_POWERPC_VSX_FILE */ #endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */ void png_init_filter_functions_vsx(png_structp pp, unsigned int bpp) { /* The switch statement is compiled in for POWERPC_VSX_API, the call to * png_have_vsx is compiled in for POWERPC_VSX_CHECK. If both are defined * the check is only performed if the API has not set the PowerPC option on * or off explicitly. In this case the check controls what happens. */ #ifdef PNG_POWERPC_VSX_API_SUPPORTED switch ((pp->options >> PNG_POWERPC_VSX) & 3) { case PNG_OPTION_UNSET: /* Allow the run-time check to execute if it has been enabled - * thus both API and CHECK can be turned on. If it isn't supported * this case will fall through to the 'default' below, which just * returns. */ #endif /* PNG_POWERPC_VSX_API_SUPPORTED */ #ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED { static volatile sig_atomic_t no_vsx = -1; /* not checked */ if (no_vsx < 0) no_vsx = !png_have_vsx(pp); if (no_vsx) return; } #ifdef PNG_POWERPC_VSX_API_SUPPORTED break; #endif #endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */ #ifdef PNG_POWERPC_VSX_API_SUPPORTED default: /* OFF or INVALID */ return; case PNG_OPTION_ON: /* Option turned on */ break; } #endif /* IMPORTANT: any new internal functions used here must be declared using * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the * 'prefix' option to configure works: * * ./configure --with-libpng-prefix=foobar_ * * Verify you have got this right by running the above command, doing a build * and examining pngprefix.h; it must contain a #define for every external * function you add. (Notice that this happens automatically for the * initialization function.) */ pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_vsx; if (bpp == 3) { pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_vsx; pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_vsx; pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_vsx; } else if (bpp == 4) { pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_vsx; pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_vsx; pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_vsx; } } #endif /* PNG_POWERPC_VSX_OPT > 0 */ #endif /* READ */
[ "noreply@github.com" ]
google.noreply@github.com
7141756a2980c335b7f4e71af2151851d97e5d5e
6238c25c43252c65555e13128dd4c255c4e1c948
/src/f32-vbinary/gen/vminc-neon-x8.c
1ccd80a8af14c4bfcaf71d1a9b9fee958525db59
[ "BSD-3-Clause", "LicenseRef-scancode-generic-cla" ]
permissive
mattn/XNNPACK
8eaf70e0c4b1cce8aaf8a7f8d7f38947fdb3bfa4
466da756e42cd7c478441025266c3b626cee414a
refs/heads/master
2023-08-15T17:43:21.415439
2020-02-28T10:00:49
2020-02-28T10:01:30
243,905,465
0
0
NOASSERTION
2020-02-29T04:41:27
2020-02-29T04:41:26
null
UTF-8
C
false
false
1,995
c
// Auto-generated file. Do not edit! // Template: src/f32-vbinary/vopc-neon.c.in // Generator: tools/xngen // // Copyright 2019 Google LLC // // This source code is licensed under the BSD-style license found in the // LICENSE file in the root directory of this source tree. #include <assert.h> #include <arm_neon.h> #include <xnnpack/common.h> #include <xnnpack/vbinary.h> void xnn_f32_vminc_ukernel__neon_x8( size_t n, const float* a, const float* b, float* y, const union xnn_f32_output_params params[restrict static 1]) { assert(n != 0); assert(n % sizeof(float) == 0); const float32x4_t vy_min = vld1q_dup_f32(&params->scalar.min); const float32x4_t vy_max = vld1q_dup_f32(&params->scalar.max); const float32x4_t vb = vld1q_dup_f32(b); for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) { const float32x4_t va0123 = vld1q_f32(a); a += 4; const float32x4_t va4567 = vld1q_f32(a); a += 4; float32x4_t vy0123 = vminq_f32(va0123, vb); float32x4_t vy4567 = vminq_f32(va4567, vb); vy0123 = vmaxq_f32(vy0123, vy_min); vy4567 = vmaxq_f32(vy4567, vy_min); vy0123 = vminq_f32(vy0123, vy_max); vy4567 = vminq_f32(vy4567, vy_max); vst1q_f32(y, vy0123); y += 4; vst1q_f32(y, vy4567); y += 4; } for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) { const float32x4_t va0123 = vld1q_f32(a); a += 4; float32x4_t vy0123 = vminq_f32(va0123, vb); vy0123 = vmaxq_f32(vy0123, vy_min); vy0123 = vminq_f32(vy0123, vy_max); vst1q_f32(y, vy0123); y += 4; } if XNN_UNLIKELY(n != 0) { const float32x4_t va0123 = vld1q_f32(a); float32x4_t vy0123 = vminq_f32(va0123, vb); vy0123 = vmaxq_f32(vy0123, vy_min); vy0123 = vminq_f32(vy0123, vy_max); float32x2_t vy01 = vget_low_f32(vy0123); if (n & (2 * sizeof(float))) { vst1_f32(y, vy01); y += 2; vy01 = vget_high_f32(vy0123); } if (n & (1 * sizeof(float))) { vst1_lane_f32(y, vy01, 0); } } }
[ "xnnpack-github-robot@google.com" ]
xnnpack-github-robot@google.com
130b5d04f7c48424cec17e150184474f9afdf3bc
8570cd506aa7975e3f7f9b2f19ad818fe7e85e3b
/BeakJoon/10817.c
b873d91471e86f47363953bc09f80b29b98d6994
[]
no_license
MalayB0/BeakJoon
9b82648fcef7eae732dbb1c396237498436897d6
a4dddf20ccac0a500779d5f13f3a034b417d4526
refs/heads/master
2023-02-07T23:51:24.186203
2020-12-29T06:26:18
2020-12-29T06:26:18
324,874,294
0
0
null
null
null
null
UHC
C
false
false
563
c
/* 3개의 정수를 입력받고 중간값 출력 */ #include <stdio.h> void printMid(); int main() { printMid(); return 0; } void printMid() { int ary[3] = { 0 }; scanf("%d %d %d", &ary[0], &ary[1], &ary[2]); int temp; for (int i = 0; i < sizeof(ary) / sizeof(int); i++) { for (int j = 0; j < (sizeof(ary) / sizeof(int)) - 1; j++) { if (ary[j+1] > ary[j]){ temp = ary[j+1]; ary[j+1] = ary[j]; ary[j] = temp; } } } for (int i = 0; i < sizeof(ary) / sizeof(int); i++) { printf("%d ", ary[i]); } printf("\n%d\n", ary[1]); }
[ "ykc0114@naver.com" ]
ykc0114@naver.com
f2c8b52c6d62a15d039ef58928900fe3744cdcdd
c896d859c9ef2783baed53568c9cd1a48dc15a12
/libft/ft_strmap.c
05c1da74851862ece5d44245328cfaf3a068b747
[]
no_license
ysarsar/Get_Next_Line
5359a858bb8890dd5f572c3a5997454cfac2b73a
49925524f394e8bca05f115edacc0c9c4c7b40b9
refs/heads/master
2020-10-01T04:52:36.811234
2019-12-11T21:12:48
2019-12-11T21:12:48
227,460,703
0
0
null
null
null
null
UTF-8
C
false
false
1,156
c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strmap.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ysarsar <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/14 21:43:49 by ysarsar #+# #+# */ /* Updated: 2018/10/17 18:01:11 by ysarsar ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_strmap(char const *s, char (*f)(char)) { int i; char *str; i = 0; if (!s || !*s) return (NULL); str = ft_strnew(ft_strlen((char*)s)); if (!str) return (NULL); while (s[i]) { str[i] = f(s[i]); i++; } return (str); }
[ "ysarsar@e2r8p1.1337.ma" ]
ysarsar@e2r8p1.1337.ma
9a511d318f7fbbe6ce6aa0e834313356a652f12b
171d1d4db1bcf74869b4636cb72d700c3a375140
/ft_lstlast.c
06f97e3b066680d5a661ea6a34ae84476612dacb
[]
no_license
gcarlstron/libft
04c04a46084b917f0ecd477d4a2506a4ccb0b931
bedffb4595639a471498279a5ca2cf97b53c8e48
refs/heads/master
2023-08-18T16:16:48.635894
2021-09-28T18:26:21
2021-09-28T18:26:21
412,614,682
0
0
null
null
null
null
UTF-8
C
false
false
1,029
c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_lstlast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: gpacheco <gpacheco@student.42sp.org.br> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/09/20 14:19:09 by gpacheco #+# #+# */ /* Updated: 2021/09/20 14:33:34 by gpacheco ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" t_list *ft_lstlast(t_list *lst) { if (!lst) return (NULL); while (lst->next) lst = lst->next; return (lst); }
[ "gustavo.carlstron@gmail.com" ]
gustavo.carlstron@gmail.com
0cca9d7e9ac08912823a581d91e2a80b7550ab6d
279a1e8be45d035d53569ebbfe8827558cd831eb
/WindowsAzureMessaging/WindowsAzureMessaging/include/MSDebounceInstallationManager.h
9e076f1c4a98c60d5ea2513c30f82ec2213fec43
[ "MIT", "BSD-3-Clause", "Apache-2.0", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-generic-cla" ]
permissive
Azure/azure-notificationhubs-ios
5b688ca2f5130991fd106ad62fa3d283d9cacf80
19c7535590eaa147ddc4f1c9b43e3686e71e8f2a
refs/heads/main
2023-09-04T11:49:04.874879
2023-02-07T17:08:11
2023-02-07T17:08:11
170,535,564
32
29
Apache-2.0
2023-03-26T22:32:35
2019-02-13T15:56:30
Objective-C
UTF-8
C
false
false
43
h
../Internal/MSDebounceInstallationManager.h
[ "noreply@github.com" ]
Azure.noreply@github.com
e6d23acb375ab6333c6fb5a2424acb7874b6c7b2
51f0123c4ed435223c7196d35e05ab7e52b61d56
/tzdb-2021a/version.h
0f2c673ee712b140fba7bde0d68d2c1479e42fab
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
nordzilla/tzdb-poc
549c0663e444e310f7b0d88c82c3079348393111
a637207b8058d5daaad929b34083c69e2e36a4db
refs/heads/main
2023-07-03T14:10:45.388217
2021-08-10T22:43:29
2021-08-10T22:43:29
393,156,484
0
0
null
null
null
null
UTF-8
C
false
false
133
h
static char const PKGVERSION[]="(tzcode) "; static char const TZVERSION[]="2021a"; static char const REPORT_BUGS_TO[]="tz@iana.org";
[ "nordzilla@mozilla.com" ]
nordzilla@mozilla.com
02ae7788f2fed41547d28d64c8059289bbee91aa
f3c320fa5b47141d7dac24eda5422a5176c9b3d8
/src/characters.h
0799ffff921ab0fc0d836477dd64258497eaced5
[]
no_license
Sothatsit/Json-C
ab7efcc77499b65dfe7bf0307734b750d079827d
33e5a5670ef702ad74d780343286b9c56796de04
refs/heads/master
2021-01-13T16:43:27.253280
2017-01-02T11:58:01
2017-01-02T11:58:01
77,611,067
0
0
null
null
null
null
UTF-8
C
false
false
748
h
#include <stdbool.h> /* * Returns whether the character is considered by JSON to be whitespace. * * A character is considered whitespace if it is one of the following: * - Horizontal Tab '\t' * - New Line '\n' * - Carriage Return '\r' * - Space ' ' */ #define json_char_isWhitespace(c) (c == '\t' || c == '\n' || c == '\r' || c == ' ') /* * Returns whether the character is considered by JSON to be a control character. */ #define json_char_isControlCharacter(c) (c >= 0 && c <= 31) /* * Returns whether the character is considered by JSON to be a digit. */ #define json_char_isDigit(c) (c >= '0' && c <= '9') /* * Places the UCS codepoint as UTF-8 in the buffer. */ int json_char_UCSCodepointToUTF8(int codepoint, char * buffer);
[ "so.thatsit@hotmail.com" ]
so.thatsit@hotmail.com
8a623d1cfd8771b531d47a2f1d69daaa9ca326e9
ec55ae4fc0c0b83da7d1ab2ae7f2314fc2953690
/API/src/ADE_fir.c
8394172dbee56bdf16703d64e0343fe52405becd
[]
no_license
eppidei/ADE
1b87398165d79825aed69cd05f559e9f9045c1d4
ea6667e81050bfaaa2823b51c7e8ef6479ddf7e2
refs/heads/master
2020-03-27T00:31:31.622153
2019-05-21T13:06:49
2019-05-21T13:06:49
145,629,974
1
0
null
null
null
null
UTF-8
C
false
false
15,070
c
#include "headers/ADE_fir.h" #include "headers/ADE_blas_level1.h" #include <stddef.h> #include "headers/ADE_errors.h" #include "headers/ADE_Utils.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include "headers/ADE_Error_Handler.h" #ifdef ADE_MEX_PRINT #include "mex.h" #endif static ADE_API_RET_T ADE_Fir_SetInBuff(ADE_FIR_T* p_fir, ADE_FLOATING_T* p_buff); static ADE_API_RET_T ADE_Fir_SetOutBuff(ADE_FIR_T* p_fir, ADE_FLOATING_T* p_buff); static ADE_API_RET_T ADE_Fir_setOrder(ADE_FIR_T* p_fir, ADE_UINT32_T order); static ADE_API_RET_T ADE_Fir_setNum(ADE_FIR_T* p_fir, ADE_FLOATING_T *p_num); static ADE_API_RET_T ADE_Fir_filter_DII_T (ADE_FIR_T* p_fir); static ADE_API_RET_T ADE_Fir_setFilt_Implementation(ADE_FIR_T* p_fir,ADE_FIR_IMP_CHOICE_T filt_imp_type); static ADE_API_RET_T ADE_Fir_dofilter_DII_T_blas (ADE_blas_level1_T *p_Blas_L1, ADE_FLOATING_T *p_in,ADE_FLOATING_T *p_b,ADE_UINT32_T len_frame,ADE_FLOATING_T *p_out, ADE_FLOATING_T *p_state,ADE_FLOATING_T gain,ADE_FLOATING_T *p_temp_buffer,ADE_UINT32_T temp_buff_size); static ADE_API_RET_T ADE_Fir_dofilter_DII_T_custom(ADE_FLOATING_T *p_in,ADE_FLOATING_T *p_b,ADE_UINT32_T len_frame,ADE_FLOATING_T *p_out, ADE_FLOATING_T *p_state,ADE_FLOATING_T gain,ADE_UINT32_T order); ADE_API_RET_T ADE_Fir_Init(ADE_FIR_T** dp_this) { ADE_blas_level1_T *p_Blas_L1; ADE_FLOATING_T default_gain = 1.0; ADE_FLOATING_T *p_state=NULL; ADE_API_RET_T ret=ADE_RET_ERROR; ADE_UINT32_T max_filt_ord = ADE_FIR_MAX_ORDER; ADE_FIR_T* pthis = calloc(1,sizeof(ADE_FIR_T)); ADE_CHECK_MEMALLOC(ADE_CLASS_FIR,ADE_METHOD_Init,pthis); pthis->buff_len=0; pthis->gain=default_gain; pthis->filter_order = 0; pthis->max_filter_order=max_filt_ord; pthis->filt_imp_type=ADE_FIR_IMP_UNDEF; // ret = ADE_Fir_setFilt_Implementation(pthis,pthis->filt_imp_type); // ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Init,ret); /******** state buffer allocation ***********/ p_state=calloc(max_filt_ord+1,sizeof(ADE_FLOATING_T)); ADE_CHECK_MEMALLOC(ADE_CLASS_FIR,ADE_METHOD_Init,p_state); pthis->p_state=p_state; /********** numerator buffer allocation *************/ pthis->p_num=calloc(max_filt_ord+1,sizeof(ADE_FLOATING_T)); ADE_CHECK_MEMALLOC(ADE_CLASS_FIR,ADE_METHOD_Init,pthis->p_num); /********* Blas1 Allocation ***************/ #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) ADE_Blas_level1_Init(&p_Blas_L1,ADE_MATH_REAL); pthis->p_Blas_L1=p_Blas_L1; #endif /*********** Temp buffer allocation ***********/ pthis->p_tempbuff=calloc(max_filt_ord,sizeof(ADE_FLOATING_T)); ADE_CHECK_MEMALLOC(ADE_CLASS_FIR,ADE_METHOD_Init,pthis->p_tempbuff); *dp_this=pthis; return ADE_RET_SUCCESS; } ADE_VOID_T ADE_Fir_Release(ADE_FIR_T* p_fir) { ADE_CHECKNFREE(p_fir->p_state); ADE_CHECKNFREE(p_fir->p_num); ADE_CHECKNFREE(p_fir->p_tempbuff); #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) ADE_Blas_level1_Release(p_fir->p_Blas_L1); #endif ADE_CHECKNFREE(p_fir); } /********** Set Methods ***************/ ADE_API_RET_T ADE_Fir_ResetState(ADE_FIR_T* p_fir,ADE_FLOATING_T rst_val) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_ResetState,p_fir); ADE_Utils_memset_float(p_fir->p_state,(p_fir->filter_order+1),rst_val); // memset(p_fir->p_state,0,(p_fir->filter_order+1)*sizeof(ADE_FLOATING_T)); return ADE_RET_SUCCESS; } /********** Configure Methods ***************/ ADE_API_RET_T ADE_Fir_Configure_params(ADE_FIR_T* p_fir,ADE_FLOATING_T *p_num,ADE_UINT32_T num_len,ADE_FIR_IMP_CHOICE_T filt_imp_type) { ADE_API_RET_T ret_num=ADE_RET_ERROR; ADE_API_RET_T ret_order=ADE_RET_ERROR; ADE_API_RET_T ret_imp=ADE_RET_ERROR; ADE_INT32_T order = num_len-1; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure_params,p_fir); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure_params,p_num); if (order>p_fir->max_filter_order) { ADE_PRINT_ERRORS(ADE_ERROR,ADE_CHECK_INPUTS,ADE_CLASS_FIR,ADE_METHOD_Configure_params,order,"%d",(FILE*)ADE_STD_STREAM); return ADE_RET_ERROR; } ret_order=ADE_Fir_setOrder(p_fir,order); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure_params,ret_order); if (filt_imp_type==ADE_FIR_TRASP_II) { ret_imp = ADE_Fir_setFilt_Implementation(p_fir,filt_imp_type); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure_params,ret_imp); } else { ADE_PRINT_ERRORS(ADE_ERROR,ADE_INCHECKS,ADE_CLASS_FIR,ADE_METHOD_Configure_params,filt_imp_type,"%d",(FILE*)ADE_STD_STREAM); return ADE_RET_ERROR; } #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) ADE_Blas_level1_SetN(p_fir->p_Blas_L1,order); ADE_Blas_level1_SetINCX(p_fir->p_Blas_L1,1); ADE_Blas_level1_SetINCY(p_fir->p_Blas_L1,1); #endif ret_num=ADE_Fir_setNum(p_fir,p_num); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure_params,ret_num); return ADE_RET_SUCCESS; } ADE_API_RET_T ADE_Fir_Configure_inout(ADE_FIR_T* p_fir,ADE_FLOATING_T* p_inbuff,ADE_FLOATING_T* p_outbuff,ADE_UINT32_T buff_len) { ADE_API_RET_T ret_setin=ADE_RET_ERROR; ADE_API_RET_T ret_setout=ADE_RET_ERROR; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure_inout,p_fir); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure_inout,p_inbuff); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure_inout,p_outbuff); p_fir->buff_len=buff_len; ret_setin=ADE_Fir_SetInBuff(p_fir,p_inbuff); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure_inout,ret_setin); ret_setout=ADE_Fir_SetOutBuff(p_fir,p_outbuff); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure_inout,ret_setout); return ADE_RET_SUCCESS; } ADE_API_RET_T ADE_Fir_Configure(ADE_FIR_T* p_fir,ADE_FLOATING_T *p_num,ADE_UINT32_T num_len,ADE_FLOATING_T* p_inbuff,ADE_FLOATING_T* p_outbuff,ADE_FIR_IMP_CHOICE_T filt_imp_type,ADE_UINT32_T buff_len) { ADE_API_RET_T ret_params=ADE_RET_ERROR; ADE_API_RET_T ret_inout=ADE_RET_ERROR; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure,p_fir); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure,p_inbuff); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure,p_outbuff); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Configure,p_num); ret_params = ADE_Fir_Configure_params(p_fir,p_num,num_len,filt_imp_type); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure,ret_params); ret_inout = ADE_Fir_Configure_inout(p_fir,p_inbuff,p_outbuff,buff_len); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_Configure,ret_inout); return ADE_RET_SUCCESS; } /********** Processing Methods ***********/ ADE_API_RET_T ADE_Fir_Step(ADE_FIR_T* p_fir) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Step,p_fir); (p_fir->filter_func)(p_fir); return ADE_RET_SUCCESS; } /************** Utils methods *********************/ ADE_API_RET_T ADE_Fir_Print(ADE_FIR_T* p_fir, ADE_FILE_T *p_fid,ADE_CHAR_T *obj_name, ADE_CHAR_T *calling_obj) { ADE_CHAR_T fixed_str[64]; ADE_CHAR_T pri_str[128]; ADE_SIZE_T len_str; ADE_CHAR_T temp_str[64]; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Print,p_fir); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_Print,p_fid); memset(fixed_str,'\0',sizeof(fixed_str)); strcat(fixed_str,calling_obj); strcat(fixed_str,"->"); strcat(fixed_str,obj_name); strcat(fixed_str,"->"); len_str=strlen(fixed_str); memset(temp_str,'\0',sizeof(temp_str)); if (p_fid!=NULL) { strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"buff_len = %u\n"),p_fir->buff_len); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"p_in = %p(%f)\n"),p_fir->p_in,p_fir->p_in[0]); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"p_out = %p(%f)\n"),p_fir->p_out,p_fir->p_out[0]); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"filter_order = %u\n"),p_fir->filter_order); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"max_filter_order = %u\n"),p_fir->max_filter_order); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"p_num = %p(%f)\n"),p_fir->p_num,p_fir->p_num[0]); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"p_state = %p(%f)\n"),p_fir->p_state,p_fir->p_state[0]); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"p_tempbuff = %p(%f)\n"),p_fir->p_num,p_fir->p_tempbuff[0]); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"gain = %f\n"),p_fir->gain); strncpy(temp_str,fixed_str,len_str-2); ADE_Blas_level1_Print(p_fir->p_Blas_L1,p_fid,"p_Blas_L1",temp_str); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"filt_imp_type = %d\n"),p_fir->filt_imp_type); strcpy(pri_str,fixed_str); ADE_LOG(p_fid,strcat(pri_str,"filter_func = %p\n"),p_fir->filter_func); strcpy(pri_str,fixed_str); } return ADE_RET_SUCCESS; } /************** static methods *********************/ static ADE_API_RET_T ADE_Fir_SetInBuff(ADE_FIR_T* p_fir, ADE_FLOATING_T* p_buff) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_SetInBuff,p_buff); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_SetInBuff,p_fir); p_fir->p_in=p_buff; return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_SetOutBuff(ADE_FIR_T* p_fir, ADE_FLOATING_T* p_buff) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_SetOutBuff,p_buff); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_SetOutBuff,p_fir); p_fir->p_out=p_buff; return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_setNum(ADE_FIR_T* p_fir, ADE_FLOATING_T *p_num) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_setNum,p_num); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_setNum,p_fir); ADE_Utils_memcpy_float(p_fir->p_num,p_num,(p_fir->filter_order+1)); return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_setOrder(ADE_FIR_T* p_fir, ADE_UINT32_T order) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_setNum,p_fir); p_fir->filter_order=order; return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_filter_DII_T (ADE_FIR_T* p_fir)//(ADE_FLOATING_T *in, ADE_FLOATING_T *out, ADE_FLOATING_T *a, ADE_UINT32_T order, ADE_FLOATING_T *b,ADE_FLOATING_T gain, ADE_FLOATING_T *state,ADE_UINT32_T len_frame,ADE_blas_level1_T *p_Blas_L1;) { ADE_FLOATING_T *p_in =NULL; ADE_FLOATING_T *p_out = NULL; ADE_UINT32_T order = 0; ADE_FLOATING_T *p_b = NULL; ADE_FLOATING_T gain = 0; ADE_FLOATING_T *p_state = NULL; ADE_UINT32_T len_frame = 0; #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) ADE_blas_level1_T *p_Blas_L1 = NULL; #endif ADE_UINT32_T temp_buff_size = 0; ADE_FLOATING_T *p_temp_buffer=NULL; ADE_API_RET_T ret=ADE_RET_ERROR; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_filter_DII_T,p_fir); p_in = p_fir->p_in; p_out = p_fir->p_out; order = p_fir->filter_order; p_b = (p_fir-> p_num); gain = (p_fir-> gain); p_state = (p_fir-> p_state); len_frame = p_fir->buff_len; p_temp_buffer=p_fir->p_tempbuff; #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) p_Blas_L1 = p_fir->p_Blas_L1; #endif temp_buff_size = order*sizeof(ADE_FLOATING_T); #if (ADE_FIR_IMP==ADE_FIR_USE_BLAS) ret=ADE_Fir_dofilter_DII_T_blas (p_Blas_L1, p_in,p_b,len_frame,p_out, p_state,gain,p_temp_buffer,temp_buff_size); ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_filter_DII_T,ret); #elif (ADE_FIR_IMP==ADE_FIR_USE_CUSTOM) ret=ADE_Fir_dofilter_DII_T_custom(p_in,p_b, len_frame,p_out, p_state, gain,order) ; ADE_CHECK_ADERETVAL(ADE_CLASS_FIR,ADE_METHOD_filter_DII_T,ret); #else #error ADE_FIR_IMP in filter_DII_T #endif return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_dofilter_DII_T_blas (ADE_blas_level1_T *p_Blas_L1, ADE_FLOATING_T *p_in,ADE_FLOATING_T *p_b,ADE_UINT32_T len_frame,ADE_FLOATING_T *p_out, ADE_FLOATING_T *p_state,ADE_FLOATING_T gain,ADE_FLOATING_T *p_temp_buffer,ADE_UINT32_T temp_buff_size) { ADE_UINT32_T k=0; ADE_FLOATING_T ALPHA=0; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_Blas_L1); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_in); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_out); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_state); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_temp_buffer); #if (ADE_CHECK_INPUTS==ADE_CHECK_INPUTS_TRUE) if (temp_buff_size==0) { ADE_PRINT_ERRORS(ADE_ERROR,ADE_INCHECKS,ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,temp_buff_size,"%u",(FILE*)ADE_STD_STREAM); ADE_LOG((FILE*)ADE_STD_STREAM," ERROR : temp_buff_size is zero \n"); } #endif for (k=0;k<len_frame;k++) { p_out[k] = gain*p_b[0]*(p_in[k])+p_state[0]; memcpy(p_temp_buffer,&p_state[0+1],temp_buff_size); /*************/ ADE_Blas_level1_SetY(p_Blas_L1,p_temp_buffer); ADE_Blas_level1_SetX(p_Blas_L1,&p_b[0+1]); ALPHA=gain*p_in[k]; ADE_Blas_level1_SetALPHA(p_Blas_L1,&ALPHA); ADE_Blas_level1_axpy(p_Blas_L1); /*****************/ memcpy(&p_state[0],p_temp_buffer,temp_buff_size); memset(p_temp_buffer,0,temp_buff_size); } return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_dofilter_DII_T_custom(ADE_FLOATING_T *p_in,ADE_FLOATING_T *p_b,ADE_UINT32_T len_frame, ADE_FLOATING_T *p_out, ADE_FLOATING_T *p_state,ADE_FLOATING_T gain,ADE_UINT32_T order) { ADE_UINT32_T k=0,i=0; ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_in); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_b); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_out); ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_dofilter_DII_T_blas,p_state); for (k=0;k<len_frame;k++) { p_out[k] = gain*p_b[0]*(p_in[k])+p_state[0]; for (i=0;i<(order);i++)// lostate deve essere inizializzato a 0 e lungo pari a order+1 (es. biquad ordine 2) { p_state[i]=gain*p_b[i+1]*(p_in[k])+p_state[i+1]; } } return ADE_RET_SUCCESS; } static ADE_API_RET_T ADE_Fir_setFilt_Implementation(ADE_FIR_T* p_fir,ADE_FIR_IMP_CHOICE_T filt_imp_type) { ADE_CHECK_INPUTPOINTER(ADE_CLASS_FIR,ADE_METHOD_setFilt_Implementation,p_fir); if (filt_imp_type==ADE_FIR_TRASP_II) { p_fir->filt_imp_type=filt_imp_type; p_fir->filter_func=ADE_Fir_filter_DII_T; } else { ADE_PRINT_ERRORS(ADE_ERROR,ADE_INCHECKS,ADE_CLASS_FIR,ADE_METHOD_setFilt_Implementation,filt_imp_type,"%d",(FILE*)ADE_STD_STREAM); return ADE_RET_ERROR; } return ADE_RET_SUCCESS; }
[ "leonardo@33e419c5-de32-43cf-b368-fc94c049cd9f" ]
leonardo@33e419c5-de32-43cf-b368-fc94c049cd9f