file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/499772.c
|
int sum (int x, int y)
{
return (x + y);
}
float average (float x, float y, float z)
{
return (x + y + z) / 3;
}
|
the_stack_data/18612.c
|
/*Exercise 3 - Repetition
Write a C program to calculate the sum of the numbers from 1 to n.
Where n is a keyboard input.
e.g.
n -> 100
sum = 1+2+3+....+ 99+100 = 5050
n -> 1-
sum = 1+2+3+...+10 = 55 */
#include <stdio.h>
int main() {
int i,n,sum =0 ;
printf("Enter the value of the n : ");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
sum=sum+i;
}
printf("Total is : %d \n",sum);
return 0;
}
|
the_stack_data/90916.c
|
// Faça um programa que leia os valores correspondentes aos três lados a, b e c de um triângulo. O programa deve então calcular a área A do triângulo utilizando a fórmula de Heron:
// onde
// A = s(s − a)(s − b))(s − c)
// s = a + b + c. 2
#include <stdio.h>
#include <math.h>
int main(void) {
float s, a, b, c;
int area;
printf("Intruduza o valor de A: ");
scanf("%f", &a);
printf("Intruduza o valor de B: ");
scanf("%f", &b);
printf("Intruduza o valor de C: ");
scanf("%f", &c);
s = (a + b + c) / 2;
area = sqrt(s *(s - a)*(s - b)*(s - c));
printf("Aarea do tringulo A é: %d", area);
return 0;
}
|
the_stack_data/470785.c
|
int foo();
int bar();
int main() {
return foo() + bar();
}
|
the_stack_data/923275.c
|
/* HAL raised several warnings, ignore them */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#ifdef STM32F0xx
#include "stm32f0xx_hal_uart_ex.c"
#elif STM32F3xx
#include "stm32f3xx_hal_uart_ex.c"
#elif STM32F7xx
#include "stm32f7xx_hal_uart_ex.c"
#elif STM32G0xx
#include "stm32g0xx_hal_uart_ex.c"
#elif STM32G4xx
#include "stm32g4xx_hal_uart_ex.c"
#elif STM32H7xx
#include "stm32h7xx_hal_uart_ex.c"
#elif STM32L0xx
#include "stm32l0xx_hal_uart_ex.c"
#elif STM32L4xx
#include "stm32l4xx_hal_uart_ex.c"
#elif STM32L5xx
#include "stm32l5xx_hal_uart_ex.c"
#elif STM32MP1xx
#include "stm32mp1xx_hal_uart_ex.c"
#elif STM32WBxx
#include "stm32wbxx_hal_uart_ex.c"
#endif
#pragma GCC diagnostic pop
|
the_stack_data/617291.c
|
/* PR middle-end/41837 */
/* { dg-do compile } */
/* { dg-options "-fipa-struct-reorg -O -fwhole-program -fprofile-generate" } */
typedef struct { int a, b; } T1;
typedef struct S1 *T2;
typedef struct S2 *T3;
typedef struct S3 *T4;
typedef struct S4 *T5;
struct S4 { union { int c; } d; };
struct S2 { int e; T2 f; int g; };
typedef struct { T3 h; } T6;
typedef struct { int i; } *T7;
struct S3 { T6 j; T7 k; };
void f5 (T4);
void f6 (void (*)(T4));
void f7 (void (*)(T5, T1 *));
void
f1 (T4 x)
{
if (!x->j.h->e)
f5 (x);
}
void
f2 (void)
{
f6 (f1);
}
void
f3 (T5 x, T1 *y)
{
}
void
f4 (void)
{
f7 (f3);
}
|
the_stack_data/97012420.c
|
#define GREETING "Hello, suckers!"
#include <stdio.h>
void print_greeting(int n) {
for (int i = 0; i < n; ++i)
puts(GREETING);
}
int main() {
int f, w;
puts("5 times via for loop");
for (f = 0; f < 5; ++f)
print_greeting(1);
puts("5 times via while loop");
w = 0;
while (w < 5) {
print_greeting(1);
++w;
}
puts("5 times via function invocation");
print_greeting(5);
return 0;
}
|
the_stack_data/119612.c
|
/*
insertion sort
good:
simple to program
efficient for small arrays
in-place, doesn't require more than a constant amount of memory
we can sort as the data comes in (adaptive sort)
stable sort
bad:
very inefficient for large arrays
void qsort( void * ptr, size_t els, size_t bytesPerEl,
int (*comp)( const void * p0, const void * p1));
if p0 must come before p1: comp returns < 0
if p0 must come after p1: comp returns > 0
if either p0 or p1 can come first: comp returns 0
*/
#include <stdio.h>
#include <stdlib.h> // sort, rand, exit
int compare0( const void * p0, const void * p1 ); // increasing
int compare1( const void * p0, const void * p1 ); // decreasing
int die( const char * msg );
void show( const unsigned arr[], unsigned els );
void sort( unsigned arr[], unsigned els );
void exchange( unsigned * a, unsigned * b );
int main(){
unsigned i = 0;
unsigned * a = malloc( 10 * sizeof(*a));
if( a == NULL) die( "allocation failure" );
for( i; i < 10; i++ )
a[i] = rand(); // [0, 32768)
show( a, 10 );
qsort( a, 10, sizeof(*a), a[0]%2 ? compare1 : compare0);
//sort( a, 10 );
show( a, 10 );
} // main
int compare0( const void * p0, const void * p1 ){ // increasing
unsigned u0 = *(const unsigned *)p0;
unsigned u1 = *(const unsigned *)p1;
int ret = 0;
if( u0 < u1 ) ret = -1;
if( u0 > u1 ) ret = 1;
static unsigned comparisons;
comparisons++;
//printf( "%u: comparing %u and %u, returning %i\n", comparisons,
// u0, u1, ret
//);
return ret;
}
int compare1( const void * p0, const void * p1 ){ // decreasing
unsigned u0 = *(const unsigned *)p0;
unsigned u1 = *(const unsigned *)p1;
int ret = 0;
if( u0 < u1 ) ret = 1;
if( u0 > u1 ) ret = -1;
static unsigned comparisons;
comparisons++;
//printf( "%u: comparing %u and %u, returning %i\n", comparisons,
// u0, u1, ret
//);
return ret;
}
int die( const char * msg ){
printf( "Fatal error: %s\n", msg );
exit( EXIT_FAILURE );
} // die
void show( const unsigned arr[], unsigned els ){
if( els > 0 ){
printf( " %u", arr[0] );
show( arr+1, els-1);
}else{
printf( "\n" );
}
}
void sort( unsigned arr[], unsigned els ){
unsigned j = 1;
for( j; j < els; j++ ){
unsigned i = j;
for( i; i > 0 && arr[i-1] > arr[i]; i-- )
exchange( arr+(i-1), arr+i );
}
}
void exchange( unsigned * a, unsigned * b ){
unsigned t = *a;
*a = *b;
*b = t;
}
|
the_stack_data/616119.c
|
//TODO ignore file would be better
extern const int HASHLENGTH;
#ifdef SERVER
#include <string.h>
#include "storage.h"
struct data data_array[MAX_CLIENTS];
void init_array(void){
for(int i = 0; i < MAX_CLIENTS; i++){
data_array[i].in_use = 0;
data_array[i].index = 0;
data_array[i].depth = 0;
data_array[i].max_width = 0;
data_array[i].max_height = 0;
data_array[i].factor_of_secret_derivation = 0;
for(int j = 0; j < HASHLENGTH; j++){
data_array[i].root_secret[j] = '\0';
data_array[i].derived[j] = '\0';
if(j < 22)
data_array[i].one_time_pad[j] = '\0';
}
}
}
int get_index(char *key){
for(int i = 0; i < MAX_CLIENTS; i++){
if(data_array[i].in_use != 0 && !strcmp(key, data_array[i].key)) {
return i;
}
}
return -1;
}
int get_next_free_slot(void){
for(int i = 0; i < MAX_CLIENTS; i++){
if(data_array[i].in_use == 0) {
return i;
}
}
return -1;
}
struct data search_future_keys(char *key){
//go trough all stored clients
for(int i = 0; i < MAX_CLIENTS; i++){
//if there is a client stored
if(data_array[i].in_use == 1){
//temporally store current state of the client
char init_key[ONETIMEPASSWORDLENGTH*2+1];
memcpy(init_key, data_array[i].key, ONETIMEPASSWORDLENGTH*2+1);
char init_secret[HASHLENGTH];
memcpy(init_secret, data_array[i].root_secret, HASHLENGTH);
char init_derived[HASHLENGTH];
memcpy(init_derived, data_array[i].derived, HASHLENGTH);
char init_otp[HASHLENGTH-ONETIMEPASSWORDLENGTH];
memcpy(init_otp, data_array[i].one_time_pad, HASHLENGTH-ONETIMEPASSWORDLENGTH);
int init_index = data_array[i].index;
int init_depth = data_array[i].depth;
//calculate the next FUTUREKEYS states for that client
for(int j = 0; j < FUTUREKEYS; j++){
move_to_expect_next_message(&data_array[i]);
int index = get_index(key);
//if key found -> keep that state
if(index != -1)
return data_array[index];
}
//no key found in the future states -> reset data to init state
data_array[i].index = init_index;
data_array[i].depth = init_depth;
memcpy(data_array[i].key, init_key, ONETIMEPASSWORDLENGTH*2+1);
memcpy(data_array[i].root_secret, init_secret, HASHLENGTH);
memcpy(data_array[i].derived, init_derived, HASHLENGTH);
memcpy(data_array[i].one_time_pad, init_otp, HASHLENGTH-ONETIMEPASSWORDLENGTH);
}
}
//no key found in the future states of any stored client
struct data null;
null.in_use = 0;
return null;
}
struct data read_data_from_key(char *key){
int index = get_index(key);
if(index != -1)
return data_array[index];
else{
//check if key is found in the FUTUREKEYS next states
return search_future_keys(key);
/*
struct data null;
null.in_use = 0;
return null;
*/
}
}
int store_object(struct data *d){
int index = get_index(d->key);
if(index == -1){
index = get_next_free_slot();
if(index == -1){
return 0;
}
}
memmove(data_array[index].key, d->key, strlen(d->key)+1);
data_array[index].id = d->id;
data_array[index].index = d->index;
data_array[index].depth = d->depth;
data_array[index].max_width = d->max_width;
data_array[index].max_height = d->max_height;
data_array[index].factor_of_secret_derivation = d->factor_of_secret_derivation;
memmove(data_array[index].root_secret, d->root_secret, HASHLENGTH);
memmove(data_array[index].derived, d->derived, HASHLENGTH);
memmove(data_array[index].one_time_pad, d->one_time_pad, HASHLENGTH-ONETIMEPASSWORDLENGTH);
data_array[index].in_use = 1;
return 1;
}
int delete_object_from_key(char *key){
int index = get_index(key);
if(index != -1){
data_array[index].in_use = 0;
return 1;
}
else {
return 0;
}
}
//for debugging
void print_storage(void){
for(int i = 0; i < MAX_CLIENTS; i++){
if(data_array[i].in_use == 1){
char key_hex[HASHLENGTH*2+1];
from_binary_to_hex(data_array[i].root_secret, HASHLENGTH, key_hex);
key_hex[HASHLENGTH*2] = '\0';
char otp_hex[(HASHLENGTH-ONETIMEPASSWORDLENGTH)*2+1];
from_binary_to_hex(data_array[i].one_time_pad, HASHLENGTH-ONETIMEPASSWORDLENGTH, otp_hex);
otp_hex[(HASHLENGTH-ONETIMEPASSWORDLENGTH)*2] = '\0';
printf("%d %s %d %d %d %d %d %s %s\n", data_array[i].in_use, data_array[i].key, data_array[i].index, data_array[i].depth, data_array[i].max_width, data_array[i].max_height, data_array[i].factor_of_secret_derivation, key_hex, otp_hex);
}
else
printf("empty\n");
}
}
#endif
|
the_stack_data/3263938.c
|
/*
*******************************************************************************
* Copyright (c) 2020-2021, STMicroelectronics
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
*******************************************************************************
*/
/*
* Automatically generated from STM32H742I(G-I)Kx.xml, STM32H742I(G-I)Tx.xml
* STM32H743IGKx.xml, STM32H743IGTx.xml
* STM32H743IIKx.xml, STM32H743IITx.xml
* STM32H747BGTx.xml, STM32H747BITx.xml
* STM32H750IBKx.xml, STM32H750IBTx.xml
* STM32H753IIKx.xml, STM32H753IITx.xml
* STM32H757BITx.xml
* CubeMX DB release 6.0.30
*/
#ifdef ARDUINO_DAISY_PATCH_SM
#include "Arduino.h"
#include "PeripheralPins.h"
/* =====
* Notes:
* - The pins mentioned Px_y_ALTz are alternative possibilities which use other
* HW peripheral instances. You can use them the same way as any other "normal"
* pin (i.e. analogWrite(PA7_ALT1, 128);).
*
* - Commented lines are alternative possibilities which are not used per default.
* If you change them, you will have to know what you do
* =====
*/
//*** ADC ***
#ifdef HAL_ADC_MODULE_ENABLED
WEAK const PinMap PinMap_ADC[] = {
{PA_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC1_INP16
{PA_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 17, 0)}, // ADC1_INP17
{PA_2, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC1_INP14
{PA_2_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC2_INP14
{PA_3, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC1_INP15
{PA_3_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC2_INP15
{PA_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // ADC1_INP18
{PA_4_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 18, 0)}, // ADC2_INP18
{PA_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 19, 0)}, // ADC1_INP19
{PA_5_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 19, 0)}, // ADC2_INP19
{PA_6, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC1_INP3
{PA_6_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC2_INP3
{PA_7, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC1_INP7
{PA_7_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC2_INP7
// {PB_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC1_INP9
// {PB_0_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC2_INP9
{PB_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC1_INP5
{PB_1_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC2_INP5
{PC_0, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC1_INP10
{PC_0_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC2_INP10
{PC_0_ALT2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 10, 0)}, // ADC3_INP10
{PC_1, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC1_INP11
{PC_1_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC2_INP11
{PC_1_ALT2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 11, 0)}, // ADC3_INP11
{PC_2_C, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 0, 0)}, // ADC3_INP0
{PC_3_C, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // ADC3_INP1
{PC_4, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC1_INP4
{PC_4_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC2_INP4
// {PC_5, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC1_INP8
// {PC_5_ALT1, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC2_INP8
// {PF_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 5, 0)}, // ADC3_INP5
// {PF_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 9, 0)}, // ADC3_INP9
// {PF_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 4, 0)}, // ADC3_INP4
// {PF_6, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 8, 0)}, // ADC3_INP8
// {PF_7, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 3, 0)}, // ADC3_INP3
// {PF_8, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 7, 0)}, // ADC3_INP7
// {PF_9, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC3_INP2
// {PF_10, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC3_INP6
// {PF_11, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC1_INP2
// {PF_12, ADC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC1_INP6
// {PF_13, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // ADC2_INP2
// {PF_14, ADC2, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 6, 0)}, // ADC2_INP6
// {PH_2, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 13, 0)}, // ADC3_INP13
// {PH_3, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 14, 0)}, // ADC3_INP14
// {PH_4, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 15, 0)}, // ADC3_INP15
// {PH_5, ADC3, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 16, 0)}, // ADC3_INP16
{NC, NP, 0}
};
#endif
//*** DAC ***
#ifdef HAL_DAC_MODULE_ENABLED
WEAK const PinMap PinMap_DAC[] = {
{PA_4, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 1, 0)}, // DAC1_OUT1
{PA_5, DAC1, STM_PIN_DATA_EXT(STM_MODE_ANALOG, GPIO_NOPULL, 0, 2, 0)}, // DAC1_OUT2
{NC, NP, 0}
};
#endif
//*** I2C ***
#ifdef HAL_I2C_MODULE_ENABLED
WEAK const PinMap PinMap_I2C_SDA[] = {
// {PB_7, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
// {PB_7_ALT1, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF6_I2C4)},
{PB_9, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
{PB_9_ALT1, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF6_I2C4)},
// {PB_11, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
{PC_9, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
// {PD_13, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
{PF_0, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
{PF_15, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
{PH_5, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
{PH_8, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
{PH_12, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
{NC, NP, 0}
};
#endif
#ifdef HAL_I2C_MODULE_ENABLED
WEAK const PinMap PinMap_I2C_SCL[] = {
// {PA_8, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
// {PB_6, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
// {PB_6_ALT1, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF6_I2C4)},
{PB_8, I2C1, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C1)},
{PB_8_ALT1, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF6_I2C4)},
{PB_10, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
// {PD_12, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
{PF_1, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
{PF_14, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
// {PH_4, I2C2, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C2)},
// {PH_7, I2C3, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C3)},
{PH_11, I2C4, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_NOPULL, GPIO_AF4_I2C4)},
{NC, NP, 0}
};
#endif
//*** TIM ***
#ifdef HAL_TIM_MODULE_ENABLED
WEAK const PinMap PinMap_TIM[] = {
{PA_0, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1
{PA_0_ALT1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
{PA_1, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
{PA_1_ALT1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2
{PA_1_ALT2, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 1, 1)}, // TIM15_CH1N
{PA_2, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
{PA_2_ALT1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3
{PA_2_ALT2, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 1, 0)}, // TIM15_CH1
{PA_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
{PA_3_ALT1, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4
{PA_3_ALT2, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 2, 0)}, // TIM15_CH2
{PA_5, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1
{PA_5_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N
{PA_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
{PA_6_ALT1, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1
{PA_7, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N
{PA_7_ALT1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
{PA_7_ALT2, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N
{PA_7_ALT3, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1
// {PA_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1
{PA_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2
{PA_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3
{PA_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4
{PA_15, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 1, 0)}, // TIM2_CH1
// {PB_0, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N
// {PB_0_ALT1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
// {PB_0_ALT2, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N
{PB_1, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N
{PB_1_ALT1, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
{PB_1_ALT2, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N
{PB_3, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 2, 0)}, // TIM2_CH2
{PB_4, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
// {PB_5, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
// {PB_6, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1
// {PB_6_ALT1, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM16, 1, 1)}, // TIM16_CH1N
// {PB_7, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2
// {PB_7_ALT1, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM17, 1, 1)}, // TIM17_CH1N
{PB_8, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
{PB_8_ALT1, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM16, 1, 0)}, // TIM16_CH1
{PB_9, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
{PB_9_ALT1, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM17, 1, 0)}, // TIM17_CH1
{PB_10, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 3, 0)}, // TIM2_CH3
// {PB_11, TIM2, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM2, 4, 0)}, // TIM2_CH4
// {PB_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N
{PB_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N
{PB_14_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N
{PB_14_ALT2, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM12, 1, 0)}, // TIM12_CH1
{PB_15, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N
{PB_15_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N
{PB_15_ALT2, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM12, 2, 0)}, // TIM12_CH2
// {PC_6, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 1, 0)}, // TIM3_CH1
// {PC_6_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1
{PC_7, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 2, 0)}, // TIM3_CH2
{PC_7_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2
{PC_8, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 3, 0)}, // TIM3_CH3
{PC_8_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3
{PC_9, TIM3, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM3, 4, 0)}, // TIM3_CH4
{PC_9_ALT1, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4
// {PD_12, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 1, 0)}, // TIM4_CH1
// {PD_13, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 2, 0)}, // TIM4_CH2
{PD_14, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 3, 0)}, // TIM4_CH3
{PD_15, TIM4, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM4, 4, 0)}, // TIM4_CH4
{PE_4, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 1, 1)}, // TIM15_CH1N
{PE_5, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 1, 0)}, // TIM15_CH1
{PE_6, TIM15, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_TIM15, 2, 0)}, // TIM15_CH2
{PE_8, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 1)}, // TIM1_CH1N
{PE_9, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 1, 0)}, // TIM1_CH1
{PE_10, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 1)}, // TIM1_CH2N
{PE_11, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 2, 0)}, // TIM1_CH2
{PE_12, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 1)}, // TIM1_CH3N
{PE_13, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 3, 0)}, // TIM1_CH3
{PE_14, TIM1, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM1, 4, 0)}, // TIM1_CH4
{PF_6, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM16, 1, 0)}, // TIM16_CH1
{PF_7, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM17, 1, 0)}, // TIM17_CH1
{PF_8, TIM13, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM13, 1, 0)}, // TIM13_CH1
{PF_8_ALT1, TIM16, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM16, 1, 1)}, // TIM16_CH1N
{PF_9, TIM14, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_TIM14, 1, 0)}, // TIM14_CH1
{PF_9_ALT1, TIM17, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF1_TIM17, 1, 1)}, // TIM17_CH1N
// {PH_6, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM12, 1, 0)}, // TIM12_CH1
{PH_9, TIM12, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM12, 2, 0)}, // TIM12_CH2
{PH_10, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 1, 0)}, // TIM5_CH1
{PH_11, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 2, 0)}, // TIM5_CH2
{PH_12, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 3, 0)}, // TIM5_CH3
{PH_13, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 1)}, // TIM8_CH1N
{PH_14, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 1)}, // TIM8_CH2N
{PH_15, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 1)}, // TIM8_CH3N
{PI_0, TIM5, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF2_TIM5, 4, 0)}, // TIM5_CH4
{PI_2, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 4, 0)}, // TIM8_CH4
{PI_5, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 1, 0)}, // TIM8_CH1
{PI_6, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 2, 0)}, // TIM8_CH2
{PI_7, TIM8, STM_PIN_DATA_EXT(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_TIM8, 3, 0)}, // TIM8_CH3
{NC, NP, 0}
};
#endif
//*** UART ***
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_TX[] = {
{PA_0, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PA_2, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_9, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_LPUART)},
{PA_9_ALT1, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PA_12, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_UART4)},
{PA_15, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_UART7)},
{PB_4, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_UART7)},
// {PB_6, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART)},
// {PB_6_ALT1, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_UART5)},
// {PB_6_ALT2, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_9, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PB_10, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PB_13, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_UART5)},
{PB_14, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART1)},
// {PC_6, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{PC_10, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PC_10_ALT1, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PC_12, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
{PD_1, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
// {PD_5, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PD_8, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PE_1, UART8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)},
{PE_8, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PF_7, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PG_14, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{PH_13, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RX[] = {
{PA_1, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PA_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
// {PA_8, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_UART7)},
{PA_10, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_LPUART)},
{PA_10_ALT1, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PA_11, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_UART4)},
{PB_3, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_UART7)},
// {PB_5, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_UART5)},
// {PB_7, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_LPUART)},
// {PB_7_ALT1, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PB_8, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
// {PB_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
// {PB_12, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF14_UART5)},
{PB_15, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF4_USART1)},
{PC_7, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{PC_11, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PC_11_ALT1, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PD_0, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PD_2, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
// {PD_6, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PD_9, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PE_0, UART8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)},
{PE_7, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PF_6, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
// {PG_9, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{PH_14, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PI_9, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_RTS[] = {
{PA_1, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_12, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_LPUART)},
{PA_12_ALT1, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
{PA_15, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PB_14, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PB_14_ALT1, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PC_8, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
// {PD_4, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
// {PD_12, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PD_15, UART8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)},
{PE_9, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PF_8, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PG_8, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
// {PG_12, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{NC, NP, 0}
};
#endif
#ifdef HAL_UART_MODULE_ENABLED
WEAK const PinMap PinMap_UART_CTS[] = {
{PA_0, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
{PA_11, LPUART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF3_LPUART)},
{PA_11_ALT1, USART1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART1)},
// {PB_0, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
// {PB_13, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PB_15, UART4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART4)},
{PC_9, UART5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART5)},
{PD_3, USART2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART2)},
// {PD_11, USART3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART3)},
{PD_14, UART8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_UART8)},
{PE_10, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PF_9, UART7, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_UART7)},
{PG_13, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{PG_15, USART6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_USART6)},
{NC, NP, 0}
};
#endif
//*** SPI ***
#ifdef HAL_SPI_MODULE_ENABLED
WEAK const PinMap PinMap_SPI_MOSI[] = {
{PA_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PA_7_ALT1, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
// {PB_2, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_SPI3)},
// {PB_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
// {PB_5_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_SPI3)},
// {PB_5_ALT2, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PB_15, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_1, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_3_C, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_12, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
// {PD_6, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI3)},
// {PD_7, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PE_6, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PE_14, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PF_9, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PF_11, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PG_14, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI6)},
{PI_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{NC, NP, 0}
};
#endif
#ifdef HAL_SPI_MODULE_ENABLED
WEAK const PinMap PinMap_SPI_MISO[] = {
{PA_6, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PA_6_ALT1, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PB_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PB_4_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PB_4_ALT2, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PB_14, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_2_C, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_11, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PE_5, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PE_13, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PF_8, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
// {PG_9, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
// {PG_12, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI6)},
// {PH_7, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PI_2, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{NC, NP, 0}
};
#endif
#ifdef HAL_SPI_MODULE_ENABLED
WEAK const PinMap PinMap_SPI_SCLK[] = {
{PA_5, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PA_5_ALT1, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PA_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PA_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PB_3, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PB_3_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PB_3_ALT2, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PB_10, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
// {PB_13, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PC_10, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PD_3, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PE_2, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PE_12, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PF_7, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
// {PG_11, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PG_13, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI6)},
// {PH_6, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PI_1, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{NC, NP, 0}
};
#endif
#ifdef HAL_SPI_MODULE_ENABLED
WEAK const PinMap PinMap_SPI_SSEL[] = {
{PA_4, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PA_4_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PA_4_ALT2, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF8_SPI6)},
{PA_11, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PA_15, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PA_15_ALT1, SPI3, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF6_SPI3)},
{PA_15_ALT2, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_SPI6)},
{PB_4, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF7_SPI2)},
{PB_9, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
// {PB_12, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{PE_4, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PE_11, SPI4, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI4)},
{PF_6, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PG_8, SPI6, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI6)},
// {PG_10, SPI1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI1)},
{PH_5, SPI5, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI5)},
{PI_0, SPI2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF5_SPI2)},
{NC, NP, 0}
};
#endif
//*** FDCAN ***
#ifdef HAL_FDCAN_MODULE_ENABLED
WEAK const PinMap PinMap_CAN_RD[] = {
{PA_11, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
// {PB_5, FDCAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN2)},
{PB_8, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
// {PB_12, FDCAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN2)},
{PD_0, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
{PH_14, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
{PI_9, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
{NC, NP, 0}
};
#endif
#ifdef HAL_FDCAN_MODULE_ENABLED
WEAK const PinMap PinMap_CAN_TD[] = {
{PA_12, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
// {PB_6, FDCAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN2)},
{PB_9, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
// {PB_13, FDCAN2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN2)},
{PD_1, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
{PH_13, FDCAN1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_FDCAN1)},
{NC, NP, 0}
};
#endif
//*** ETHERNET ***
#ifdef HAL_ETH_MODULE_ENABLED
WEAK const PinMap PinMap_Ethernet[] = {
{PA_0, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS
{PA_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_REF_CLK
{PA_1_ALT1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RX_CLK
{PA_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_MDIO
{PA_3, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_COL
{PA_7, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS_DV
{PA_7_ALT1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RX_DV
// {PB_0, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD2
{PB_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD3
// {PB_5, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_PPS_OUT
{PB_8, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD3
{PB_10, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RX_ER
// {PB_11, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_EN
// {PB_12, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD0
// {PB_13, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD1
{PC_1, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_MDC
{PC_2_C, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD2
{PC_3_C, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_CLK
{PC_4, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD0
// {PC_5, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD1
{PE_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD3
{PG_8, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_PPS_OUT
// {PG_11, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TX_EN
// {PG_12, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD1
{PG_13, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD0
{PG_14, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_TXD1
{PH_2, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_CRS
{PH_3, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_COL
// {PH_6, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD2
// {PH_7, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RXD3
{PI_10, ETH, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF11_ETH)}, // ETH_RX_ER
{NC, NP, 0}
};
#endif
//*** QUADSPI ***
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_DATA0[] = {
{PC_9, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO0
// {PD_11, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO0
{PE_7, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK2_IO0
{PF_8, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO0
{PH_2, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK2_IO0
{NC, NP, 0}
};
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_DATA1[] = {
{PC_10, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO1
// {PD_12, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO1
{PE_8, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK2_IO1
{PF_9, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_IO1
{PH_3, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK2_IO1
{NC, NP, 0}
};
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_DATA2[] = {
{PE_2, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO2
{PE_9, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK2_IO2
{PF_7, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO2
// {PG_9, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK2_IO2
{NC, NP, 0}
};
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_DATA3[] = {
{PA_1, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO3
// {PD_13, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO3
{PE_10, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK2_IO3
{PF_6, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_IO3
{PG_14, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK2_IO3
{NC, NP, 0}
};
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_SCLK[] = {
// {PB_2, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_CLK
{PF_10, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_CLK
{NC, NP, 0}
};
#endif
#ifdef HAL_QSPI_MODULE_ENABLED
WEAK const PinMap PinMap_QUADSPI_SSEL[] = {
// {PB_6, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_NCS
{PB_10, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK1_NCS
{PC_11, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_QUADSPI)}, // QUADSPI_BK2_NCS
{PG_6, QUADSPI, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_QUADSPI)}, // QUADSPI_BK1_NCS
{NC, NP, 0}
};
#endif
//*** USB ***
#if defined(HAL_PCD_MODULE_ENABLED) || defined(HAL_HCD_MODULE_ENABLED)
WEAK const PinMap PinMap_USB_OTG_FS[] = {
// {PA_8, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG1_FS)}, // USB_OTG_FS_SOF
{PA_9, USB_OTG_FS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_FS_VBUS
{PA_10, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG1_FS)}, // USB_OTG_FS_ID
{PA_11, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG1_FS)}, // USB_OTG_FS_DM
{PA_12, USB_OTG_FS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG1_FS)}, // USB_OTG_FS_DP
{NC, NP, 0}
};
#endif
#if defined(HAL_PCD_MODULE_ENABLED) || defined(HAL_HCD_MODULE_ENABLED)
WEAK const PinMap PinMap_USB_OTG_HS[] = {
#ifdef USE_USB_HS_IN_FS
{PA_4, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG2_FS)}, // USB_OTG_HS_SOF
// {PB_12, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF12_OTG2_FS)}, // USB_OTG_HS_ID
// {PB_13, USB_OTG_HS, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, GPIO_AF_NONE)}, // USB_OTG_HS_VBUS
{PB_14, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG2_FS)}, // USB_OTG_HS_DM
{PB_15, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_OTG2_FS)}, // USB_OTG_HS_DP
#else
{PA_3, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D0
{PA_5, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_CK
// {PB_0, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D1
{PB_1, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D2
// {PB_5, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D7
{PB_10, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D3
// {PB_11, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D4
{PB_12, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D5
// {PB_13, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_D6
{PC_0, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_STP
{PC_2_C, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_DIR
{PC_3_C, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_NXT
// {PH_4, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_NXT
// {PI_11, USB_OTG_HS, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_OTG2_HS)}, // USB_OTG_HS_ULPI_DIR
#endif /* USE_USB_HS_IN_FS */
{NC, NP, 0}
};
#endif
//*** SD ***
#ifdef HAL_SD_MODULE_ENABLED
WEAK const PinMap PinMap_SD[] = {
{PA_0, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_SDIO2)}, // SDMMC2_CMD
{PB_3, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_SDIO2)}, // SDMMC2_D2
{PB_4, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_SDIO2)}, // SDMMC2_D3
{PB_8, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF7_SDIO1)}, // SDMMC1_CKIN
{PB_8_ALT1, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D4
{PB_8_ALT2, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_SDIO2)}, // SDMMC2_D4
{PB_9, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF7_SDIO1)}, // SDMMC1_CDIR
{PB_9_ALT1, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D5
{PB_9_ALT2, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_SDIO2)}, // SDMMC2_D5
{PB_14, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_SDIO2)}, // SDMMC2_D0
{PB_15, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF9_SDIO2)}, // SDMMC2_D1
{PC_1, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF9_SDIO2)}, // SDMMC2_CK
// {PC_6, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF8_SDIO1)}, // SDMMC1_D0DIR
// {PC_6_ALT1, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D6
// {PC_6_ALT2, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_SDIO2)}, // SDMMC2_D6
{PC_7, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF8_SDIO1)}, // SDMMC1_D123DIR
{PC_7_ALT1, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D7
{PC_7_ALT2, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_SDIO2)}, // SDMMC2_D7
{PC_8, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D0
{PC_9, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D1
{PC_10, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D2
{PC_11, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF12_SDIO1)}, // SDMMC1_D3
{PC_12, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO1)}, // SDMMC1_CK
{PD_2, SDMMC1, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF12_SDIO1)}, // SDMMC1_CMD
// {PD_6, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF11_SDIO2)}, // SDMMC2_CK
// {PD_7, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF11_SDIO2)}, // SDMMC2_CMD
// {PG_11, SDMMC2, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_PULLUP, GPIO_AF10_SDIO2)}, // SDMMC2_D2
{NC, NP, 0}
};
#endif
#endif /* ARDUINO_DAISY_PATCH_SM */
|
the_stack_data/277373.c
|
//Debug vers.
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define SIZE 10
/*
Week 4 Question 1
Description
Please finish the three sorting function in template, bubble sort, selection sort and insertion sort.
You will get 80 point if you finish one of three, 90 point if two and 100 point for all three.
*/
void bubbleSort(int *array, int n)
{
int i, j, k, temp;
for( i = 0 ; i < n-1 ; i++)
{
/*��ƨ�����A�p���b�e*/
int flag = 0;
for( j = 0 ; j < n-i-1 ; j++)
{
/*��j��j+1����Ƥ���A��j����� > j+1 �ɡB���*/
if(array[j] > array[j+1])
{
flag = 1;
temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
/*Dedugging--------------
printf("#%d pass: \n", i+1);
printf("\t#%d compare: ", j+1);
for( k = 0 ; k < n-i ; k++)
{
//�C��compare�x��ƶq�|�H��i++�ӻ���A�G�j��H��-i�������I
if(temp == array[k])
printf("--%d-- ", array[k]);
else
printf("%d ",array[k]);
}
printf("\n");
*/
}
/*Dedugging--------------
printf("#final array: ");
for( k = 0 ; k < n ; k++)
{
printf("%d ",array[k]);
}
printf("\n-------------------------------------------------------------------------\n\n");
*/
// printf("=================================================================================================\n");
if(flag == 0)
break;
}
}
void insertionSort(int *array, int n)
{
int insert_i, insert_n, cp_i, i;
for( insert_i = 1 ; insert_i < n ; insert_i++)
{
int insert_n = array[insert_i];///target number & target index
//printf("insert_n = %d \n", insert_n);
for( cp_i = insert_i-1 ; cp_i>=0 && array[cp_i] >= insert_n; cp_i--)
///compare_index is the index from insert_i to 0 step by step, in order to find where to insert in
///stopping condition when (compare_index<0) or (the place insert in
{
array[cp_i+1] = array[cp_i];///�C�ӼƦr���Ჾ
}
array[cp_i+1] = insert_n;
printf("#%d insertion: ", insert_i);
for( i = 0 ; i < n ; i++)
{
if( array[i] == array[cp_i+1])
printf("--%d-- ", array[i]);
else
printf("%d ", array[i]);
}
printf("\n");
}
}
void selectionSort(int *array, int n)
{
int base, min_index, i;
for(base = 0 ; base < n-1 ; base++)
{
min_index = base;
printf("base : %d ----->", base);
for( i = base+1 ; i < n ; i++)
{
if(array[min_index] > array[i])
min_index = i;
printf("%d ", array[i]);
}
int temp = array[min_index];
array[min_index] = array[base];
array[base] = temp;
printf("\n array[min_index]---%d--- ", array[min_index]);
printf("\n array[base]---%d--- ", array[base]);
printf("\n\n");
}
for( i = 0 ; i < n ; i++)
printf("%d ", array[i]);
printf("\n");
}
int main()
{
int array[SIZE];
int j, k;
srand(time(NULL));
for(j = 0; j < SIZE; j ++)
array[j] = rand();
printf("------------------------------Pre------------------------------------\n");
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n");
printf("BUBBLE SORT\n");
bubbleSort(array, SIZE);
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n===============================================================================\n");
for(j = 0; j < SIZE; j ++)
array[j] = rand();
printf("------------------------------Pre------------------------------------\n");
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n");
printf("INSERTION SORT\n");
insertionSort(array, SIZE);
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n==============================================================================\n");
for(j = 0; j < SIZE; j ++)
array[j] = rand();
printf("-------------------------------Pre------------------------------------\n");
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n");
printf("SELECTION SORT\n");
selectionSort(array, SIZE);
for(j = 0; j < SIZE; j ++)
printf("%d ", array[j]);
printf("\n");
}
|
the_stack_data/154828935.c
|
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdint.h>
/*
let result = 0;
let shift = 0;
while (true) {
const byte = input.shift();
result |= (byte & 0x7f) << shift;
shift += 7;
if ((0x80 & byte) === 0) {
if (shift < 32 && (byte & 0x40) !== 0) {
return result | (~0 << shift);
}
return result;
}
}*/
enum {
LEB_ZERO = 0,
LEB_PARTIAL = 1,
LEB_FINISHED = 2,
};
struct Parser {
uint32_t result;
int shift;
int state;
};
int put_char(struct Parser* parser, char c, int32_t* res) {
if (parser->state == LEB_FINISHED) {
parser->state = LEB_ZERO;
parser->shift = 0;
parser->result = 0;
}
parser->state = LEB_PARTIAL;
parser->result |= ((uint32_t)(c & 0x7f)) << parser->shift;
parser->shift += 7;
if ((0x80 & c) == 0) {
if (parser->shift < 32 && (c & 0x40) != 0) {
parser->result = parser->result | (~0 << parser->shift);
}
*res = (int32_t)parser->result;
parser->state = LEB_FINISHED;
return 0;
}
return -2;
}
int main(int argc, char** argv) {
if (argc != 2) {
return -1;
}
struct stat s;
int fd;
int res = (
stat(argv[1], &s) != -1
&& (fd = open(argv[1], O_RDONLY)) != -1
);
int page_size = getpagesize();
printf("Page size: %d\n", page_size);
size_t block_size = 0;
while (block_size < s.st_size) {
size_t next_block_size = block_size + (size_t)page_size;
if (next_block_size > s.st_size) {
next_block_size = s.st_size;
}
char* tmp = mmap(
NULL,
next_block_size,
PROT_READ,
MAP_SHARED,
fd,
0
);
if (tmp == MAP_FAILED) {
break;
} else {
munmap(tmp, next_block_size);
block_size = next_block_size;
}
}
struct Parser parser = {};
int32_t value;
for (size_t sz = 0; sz < s.st_size; sz += block_size) {
size_t limit = s.st_size - sz;
if (limit < block_size) {
block_size = limit;
}
char* mem = mmap(
NULL,
block_size,
PROT_READ,
MAP_SHARED,
fd,
sz
);
for (size_t i = 0; i < s.st_size; i++) {
if (!put_char(&parser, mem[i], &value)) {
printf("%d\n", value);
}
}
munmap(mem, block_size);
}
return 0;
}
|
the_stack_data/28621.c
|
#include <stdio.h>
#define LOWER 0
#define UPPER 300
#define STEP 20
int main() {
int fahr;
for (fahr = LOWER; fahr <= UPPER; fahr += STEP) {
printf("%d\t%6.1f\n", fahr, (5.0 / 9.0) * (fahr - 32));
}
}
|
the_stack_data/95449398.c
|
typedef struct {
int value;
} HeapNode;
typedef HeapNode* HeapNodePtr;
typedef struct {
HeapNodePtr array;
int size;
int capacity;
} Heap;
typedef Heap * HeapPtr;
HeapPtr buildHeap(HeapNodePtr elements, int size);
void destroyHeap(HeapPtr heap);
void pushHeap(HeapPtr heap, HeapNode newElement);
HeapNode popHeap(HeapPtr heap);
void percolateUp(HeapPtr heap, int index);
void percolateDown(HeapPtr heap, int index);
HeapPtr buildHeap(HeapNodePtr elements, int size) {
HeapPtr result = (HeapPtr)malloc(sizeof(Heap));
result->size = size;
result->array = (HeapNodePtr)malloc(sizeof(HeapNode) * (size + 1));
result->capacity = size + 1;
for (int i = 0; i < size; i ++) {
result->array[i + 1] = elements[i];
}
for (int i = size / 2; i > 0; i --) {
percolateDown(result, i);
}
return result;
}
void destroyHeap(HeapPtr heap) {
free(heap->array);
free(heap);
}
void pushHeap(HeapPtr heap, HeapNode newElement) {
if (heap->size >= heap->capacity - 1) {
heap->array = realloc(heap->array, sizeof(HeapNode) * heap->capacity * 2);
heap->capacity *= 2;
}
heap->array[++ heap->size] = newElement;
percolateUp(heap, heap->size);
}
HeapNode popHeap(HeapPtr heap) {
HeapNode result = heap->array[1];
heap->array[1] = heap->array[heap->size --];
percolateDown(heap, 1);
return result;
}
void percolateUp(HeapPtr heap, int index) {
HeapNode targetNode = heap->array[index];
int i = 0;
for (i = index; i / 2 >= 1 && heap->array[i / 2].value > targetNode.value; i /= 2) {
heap->array[i] = heap->array[i / 2];
}
heap->array[i] = targetNode;
}
void percolateDown(HeapPtr heap, int index) {
HeapNode targetNode = heap->array[index];
int i = index, childIndex = index;
for (i = index; i * 2 <= heap->size; i = childIndex) {
childIndex = i * 2;
if (childIndex < heap->size && heap->array[childIndex + 1].value < heap->array[childIndex].value) {
childIndex += 1;
}
if (targetNode.value > heap->array[childIndex].value) {
heap->array[i] = heap->array[childIndex];
} else {
break;
}
}
heap->array[i] = targetNode;
}
|
the_stack_data/120390.c
|
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
typedef struct node node;
void list(node *first)
{
node *c;
printf("\n");
for(c=first;c!=NULL;c=c->next)
{
printf("%5d",c->data);
}
}
node* ins_after(node *f)
{
int m;
node *c,*cur;
cur=(node*)malloc(sizeof(node));
printf("\n Data ::");
scanf("%d",&cur->data);
cur->next=NULL;
if(f==NULL)
{
f=cur;
return f;
}
printf("\n After Which No.?");
scanf("%d",&m);
for(c=f;c!=NULL;c=c->next)
{
if(c->data==m)
{
cur->next=c->next;
c->next=cur;
break;
}
}
return f;
}
node *ins_before(node *f)
{
int m;
node *c,*cur,*p;
cur=(node*)malloc(sizeof(node));
printf("\n Data ::");
scanf("%d",&cur->data);
cur->next=NULL;
if(f==NULL)
{
f=cur;
return f;
}
printf("\n Before Which No. ?");
scanf("%d",&m);
c=f;
p=NULL;
while(c!=NULL)
{
if(c->data==m)
{
cur->next=c;
if(p!=NULL)
p->next=cur;
else
f=cur;
break;
}
p=c;
c=c->next;
}
return f;
}
main()
{
int a,n,i;
node *f=NULL;
do
{
printf("\n1.Insert After");
printf("\n2.Insert Before");
printf("\n3.List");
printf("\n4.Exit");
printf("\nEnter Your Choice ::");
scanf("%d",&n);
switch(n)
{
case 1:
f=ins_after(f);
list(f);
break;
case 2:
f=ins_before(f);
list(f);
break;
case 3:
list(f);
break;
}
}
while(n!=4);
}
|
the_stack_data/165764980.c
|
/*
* Copyright (C) 2018-2020 Alibaba Group Holding Limited
*/
#if defined(CONFIG_DECODER_IPC) && CONFIG_DECODER_IPC
#include "avutil/common.h"
#include "avcodec/ad_cls.h"
#include "icore/ad_icore_internal.h"
#include "ad_icore.h"
#define TAG "ad_ipc"
struct ad_ipc_priv {
ad_icore_t *hdl;
};
static int _ad_ipc_open(ad_cls_t *o)
{
int rc;
struct ad_ipc_priv *priv = NULL;
ad_icore_t *hdl;
adi_conf_t adi_cnf;
priv = aos_zalloc(sizeof(struct ad_ipc_priv));
CHECK_RET_TAG_WITH_RET(priv, -1);
rc = ad_icore_init();
CHECK_RET_TAG_WITH_GOTO(rc == 0, err);
rc = ad_icore_conf_init(&adi_cnf);
CHECK_RET_TAG_WITH_GOTO(rc == 0, err);
adi_cnf.sf = o->ash.sf;
adi_cnf.block_align = o->ash.block_align;
adi_cnf.bps = o->ash.bps;
adi_cnf.extradata = o->ash.extradata;
adi_cnf.extradata_size = o->ash.extradata_size;
hdl = ad_icore_open(o->ash.id, &adi_cnf);
CHECK_RET_TAG_WITH_GOTO(hdl, err);
ad_icore_get_sf(hdl, &o->ash.sf);
priv->hdl = hdl;
o->priv = priv;
return 0;
err:
aos_free(priv);
return -1;
}
static int _ad_ipc_decode(ad_cls_t *o, avframe_t *frame, int *got_frame, const avpacket_t *pkt)
{
int ret = -1;
struct ad_ipc_priv *priv = o->priv;
ret = ad_icore_decode(priv->hdl, frame, got_frame, pkt);
if (*got_frame) {
o->ash.sf = frame->sf;
}
return ret;
}
static int _ad_ipc_control(ad_cls_t *o, int cmd, void *arg, size_t *arg_size)
{
//TODO
return 0;
}
static int _ad_ipc_reset(ad_cls_t *o)
{
int rc;
struct ad_ipc_priv *priv = o->priv;
rc = ad_icore_reset(priv->hdl);
return rc;
}
static int _ad_ipc_close(ad_cls_t *o)
{
struct ad_ipc_priv *priv = o->priv;
ad_icore_close(priv->hdl);
aos_free(priv);
o->priv = NULL;
return 0;
}
const struct ad_ops ad_ops_ipc = {
.name = "ipc",
.id = AVCODEC_ID_AAC | AVCODEC_ID_MP3,
.open = _ad_ipc_open,
.decode = _ad_ipc_decode,
.control = _ad_ipc_control,
.reset = _ad_ipc_reset,
.close = _ad_ipc_close,
};
#endif
|
the_stack_data/32949663.c
|
#include <stdio.h>
int main() {
int N;
scanf("%d", &N);
int count_odds = 0;
for (int i = 0; i < N; i++) {
int A;
scanf("%d", &A);
if (A % 2 == 1) {
count_odds++;
}
}
printf("%s\n", count_odds % 2 == 0 ? "YES" : "NO");
return 0;
}
|
the_stack_data/184518424.c
|
/*********************************************************
* Your Name: Colby Morrison
* Partner Name: Noah Ari
*********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int parse(char *in)
{
char run = in[0];
int count = 0;
for (int i = 0; i < strlen(in); i++)
{
char cur = in[i];
if (cur == run)
count++;
else
{
fwrite(&count, sizeof(count), 1, stdout);
fwrite(&run, sizeof(char), 1, stdout);
run = cur;
count = 1;
}
}
fwrite(&count, sizeof(count), 1, stdout);
fwrite(&run, sizeof(char), 1, stdout);
return 0;
}
int main(int argc, char *argv[])
{
FILE *fp = fopen(argv[1], "r");
if(!fp){
fclose(fp);
return 1;
}
// How long is the file?
fseek(fp, 0, SEEK_END);
long length = ftell(fp);
fseek(fp, 0, SEEK_SET);
// Allocate memory for contents of file (what if it's bigger than memory??)
char *contents = malloc(length + 1);
if(!contents){
fclose(fp);
return 1;
}
// Read whole file
int done = fread(contents, length, 1, fp);
if(!done){
fclose(fp);
return 1;
}
fclose(fp);
// Parse file
parse(contents);
// Free memory
free(contents);
return 0;
}
|
the_stack_data/121018.c
|
#include <stdlib.h>
#include <math.h>
float* data;
float pi = 3.14159265358979323846;
float pi2 = 6.28318530717958647692;
#define REAL 0
#define IMAG 1
//data[point][real or imag]
//returns answer in data[]
void cmult(float* data, float* data2, float* output){
output[REAL] = (data[REAL] * data2[REAL]) - (data[IMAG] * data2[IMAG]);
output[IMAG] = (data[REAL] * data2[IMAG]) + (data[IMAG] * data2[REAL]);
}
void DTFT(float** x, float** X, int N){
for(int k = 0; k < N; k++){
X[k][REAL] = 0;
X[k][IMAG] = 0;
for(int n = 0; n < N; n++){
float val[3][2];
val[0][REAL] = x[n][0];
val[0][IMAG] = x[n][1];
val[1][REAL] = cosf(pi2*k*n/N);
val[1][IMAG] = -1*sinf(pi2*k*n/N);
cmult(val[0], val[1], val[2]);
X[k][REAL]= X[k][REAL] + val[2][REAL];
X[k][IMAG]= X[k][IMAG] + val[2][IMAG];
}
}
}
void cooley_tukey(float** xData, float** X, int N, int columns, int rows){
/* Reshape */
float*** x2 = (float***)malloc(sizeof(float**) * rows);
float*** x2_0 = (float***)malloc(sizeof(float**) * rows);
for(int x = 0; x < rows; x++){
x2[x] = (float**)malloc(sizeof(float*) * columns);
x2_0[x] = (float**)malloc(sizeof(float*) * columns);
for(int y = 0; y < columns; y++){
x2[x][y] = (float*)malloc(sizeof(float) * 2);
x2_0[x][y] = (float*)malloc(sizeof(float) * 2);
x2[x][y][REAL] = xData[rows*y+x][REAL];
x2[x][y][IMAG] = xData[rows*y+x][IMAG];
}
}
float*** x2_1 = (float***)malloc(sizeof(float**) * columns);
float*** x2_2 = (float***)malloc(sizeof(float**) * columns);
for(int y = 0; y < columns; y++){
x2_1[y] = (float**)malloc(sizeof(float*) * rows);
x2_2[y] = (float**)malloc(sizeof(float*) * rows);
for(int x = 0; x < rows; x++){
x2_1[y][x] = (float*)malloc(sizeof(float) * 2);
x2_2[y][x] = (float*)malloc(sizeof(float) * 2);
}
}
/* DTFT rows */
for(int x = 0; x < rows; x++){
DTFT(x2[x], x2_0[x], columns);
}
/* Twiddle Factors and rearrange for DTFT by row*/
for(int x = 0; x < rows; x++){
for(int y = 0; y < columns; y++){
float val[2];
val[0] = cosf(pi2*x*y/N);
val[1] = -1*sinf(pi2*x*y/N);
cmult(x2_0[x][y], val, x2_1[y][x]);
}
}
/* DTFT columns */
for(int y = 0; y < columns; y++){
DTFT(x2_1[y], x2_2[y], rows);
}
/* Reshape into 1 dimensional array */
for(int pos = 0; pos < N; pos++){
int x = pos%columns;
int y = (pos-x)/columns;
X[pos][REAL] = x2_2[x][y][REAL];
X[pos][IMAG] = x2_2[x][y][IMAG];
}
/* Free Memory */
for(int x = 0; x < rows; x++){
for(int y = 0; y < columns; y++){
free(x2[x][y]);
free(x2_0[x][y]);
}
free(x2[x]);
free(x2_0[x]);
}
for(int y = 0; y < columns; y++){
for(int x = 0; x < rows; x++){
free(x2_1[y][x]);
free(x2_2[y][x]);
}
free(x2_1[y]);
free(x2_2[y]);
}
free(x2_1);
free(x2_2);
free(x2);
free(x2_0);
}
void absolute(float** data, float* absoluteData, int N){
for(int i = 0; i < N; i++){
absoluteData[i] = sqrtf(powf(data[i][0],2)+powf(data[i][1],2));
}
}
void real2complex(float* real, float** complex, int N){
for(int i = 0; i < N; i++){
complex[i][0] = real[i];
complex[i][1] = 0.0;
}
}
int main(int argc, char** argv){
int N = 35; // number of points
float Fs = 1000; // sampling frequency
int Fsignal = 90; // signalnal frequency
float** X_FFT = (float**)malloc(sizeof(float*) * N);
float** sig = (float**)malloc(sizeof(float*) * N);
float* X = (float*)malloc(sizeof(float) * N);
for(int i = 0; i < N; i++){
X_FFT[i] = (float*)malloc(sizeof(float) * 2);
sig[i] = (float*)malloc(sizeof(float) * 2);
}
for(int i = 0; i < N; i++){
sig[i][0] = sinf(2*pi*(float)Fsignal*i/(float)Fs);
sig[i][1] = 0.0;
}
cooley_tukey(sig, X_FFT, N, 7, 5);
absolute(X_FFT, X, N);
for(int i = 0; i < N; i++){
free(X_FFT[i]);
free(sig[i]);
}
free(X_FFT);
free(sig);
free(X);
return 0;
}
|
the_stack_data/48576605.c
|
#include<stdio.h>
/* retorna a soma dos divisores de n */
int soma_divisores(int n);
/* Nao modifique o main!! */
int main() {
int n;
scanf("%d", &n);
if(soma_divisores(n) == n) {
printf("SIM\n");
} else {
printf("NAO\n");
}
return 0;
}
int soma_divisores(int n){
int i,num=0;
for(i=1;i<n+1;i++){
if(n%i==0){
num+=i;
//printf("%d\n",i);
}
}
return num-n;
}
|
the_stack_data/90766506.c
|
/*
* float.c -- Some simple test to see if the float libs are
* working correctly. Calculations are done with
* software functions.
*
*
*
*
*/
volatile float e = 0.0f;
volatile float fac = 1.0f;
int main(void)
{
int i;
for (i = 1; i<20; i++)
{
e = e + 1.0f/fac;
fac = fac * i;
}
return 0;
}
|
the_stack_data/31388753.c
|
#include <stdio.h>
int fib(int x, int y)
{
if ((x == 0) || ((x >= y) && (y >= 1)))
return 1;
return fib(x-y, y) + fib(x - 1, y - 1);
}
int main ()
{
int m = 10, n = 9;
printf("%d", fib(m, n));
getchar();
return 0;
}
|
the_stack_data/57949290.c
|
/*! \file gene_bruit_rayleigh_scalaire.c
\brief sous-programme generant un scalaire suivant une loi de rayleigh
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
void gene_bruit_rayleigh_scalaire(float param_loi, float *scalaire_rayleigh_real,float *scalaire_rayleigh_imag)
{
unsigned int g_seed;
static int compteur_appel=-1;
time_t temps;
float var_uni1,var_uni2;
compteur_appel=compteur_appel+1;
if (compteur_appel==0)
{
temps=time(0);
temps=temps-(3666*24*365*(2005-1970));
temps=(time_t)fmod((double)temps,100000.); /* 100000 valeurs possibles pour le germe */
g_seed=(unsigned int)temps;
srand(g_seed);
/* fprintf(stderr,"initialisation du germe (g_seed=%d)\n",g_seed); */
}
if (compteur_appel>1000000) compteur_appel=-1; /* tous les 1000000 d appels a la fonction on change le germe */
do{
var_uni1=((float)rand())/((float)RAND_MAX);
}while(var_uni1 == 0.);
/* variable uniforme entre 0 et 1 */
var_uni2=((float)rand())/((float)RAND_MAX);
/* variable gaussienne */
*(scalaire_rayleigh_real)=param_loi* (float)(sqrt( (-2. * log((double) (var_uni1 + 1.e-20)) )) * cos((double)(2.*M_PI*var_uni2)) );
*(scalaire_rayleigh_imag)=param_loi* (float)(sqrt( (-2. * log((double) (var_uni1 + 1.e-20)) )) * sin((double)(2.*M_PI*var_uni2)) );
return;
}
|
the_stack_data/85330.c
|
#include <stdio.h>
#include <string.h>
#ifndef __CC65__
#include <sys/time.h>
#endif
#define PSIZE 1000
unsigned primes[PSIZE];
int
main(void)
{
#ifndef __CC65__
struct timeval tv1, tv2;
#endif
unsigned num_primes;
unsigned num;
#ifndef __CC65__
gettimeofday(&tv1, NULL);
#endif
num_primes = 0;
num = 2;
while (num_primes < PSIZE) {
unsigned i;
for (i = 0; i < num_primes; ++i) {
if (num % primes[i] == 0) {
break;
}
}
if (i >= num_primes) {
printf("%u\r\n", num);
primes[num_primes++] = num;
}
++num;
}
#ifndef __CC65__
gettimeofday(&tv2, NULL);
#endif
printf("primes[%u]=%u\r\n", PSIZE-1, primes[PSIZE-1]);
#ifndef __CC65__
printf("%lu seconds\r\n", (unsigned long)(tv2.tv_sec - tv1.tv_sec));
#endif
return 0;
}
|
the_stack_data/105985.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jnawrock <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/28 11:20:02 by jnawrock #+# #+# */
/* Updated: 2019/10/28 12:20:03 by jnawrock ### ########.fr */
/* */
/* ************************************************************************** */
int ft_putchar(char c);
int ft_putnbr(int nb)
{
if (nb < 0)
{
ft_putchar('-');
if (nb == -2147483648)
{
ft_putchar('2');
nb = 147483648;
}
else
nb = nb * -1;
}
if (nb >= 10)
{
ft_putnbr(nb / 10);
}
return (ft_putchar((nb % 10) + '0'));
}
|
the_stack_data/70449797.c
|
#include <stdio.h>
void quickSort(int data[], int left, int right){
int mid, tmp, i, j;
i = left;
j = right;
mid = data[(left + right) / 2];
do {
while(data[i] < mid){
i++;
}
while(data[j] > mid){
j--;
}
if(i <= j){
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
i++;
j--;
}
} while( i <= j );
if(left < j){
quickSort(data, left, j);
}
if(i < right){
quickSort(data, i, right);
}
}
void printAll(int data[], int length)
{
int i;
for (i = 0; i < length; i++)
printf("Data[%d] = %d \n", i + 1, data[i]);
}
int main()
{
int data[] = { 1, 13, 5, 3, 7, 2, 15 , 23, 1, 34, 3, 32, 45, 9};
int length = sizeof(data) / sizeof(data[0]);
quickSort(data, 0, length - 1);
printAll(data, length);
return 0;
}
|
the_stack_data/565867.c
|
//Maximum Difference problem
#include<stdio.h>
void main()
{
int n,i,j,k,arr[100],f=0,max,min;
printf("Please Enter the number of elements : \n");
scanf("%d",&n);
for(i=0;i<=n-1;i++)
{
printf("Enter an element : ");
scanf("%d",&arr[i]);
}
max = arr[0];
//Finding the rightmost-largest number
for(i=0;i<=n-1;i++)
{
if(max < arr[i])
{
max = arr[i];
j = i;
}
}
min = arr[0];
//Finding the leftmost-smallest number
for(i=0;i<=j;i++)
{
if(min > arr[i])
{
min = arr[i];
}
}
printf("Maximum Difference = %d\n",max-min);
}
|
the_stack_data/65676.c
|
/* $OpenBSD: strcmp.c,v 1.7 2003/06/02 23:28:08 millert Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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 University 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)strcmp.c 5.5 (Berkeley) 1/26/91";*/
static char *rcsid = "$OpenBSD: strcmp.c,v 1.7 2003/06/02 23:28:08 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif
/*
* Compare strings.
*/
int
strcmp(s1, s2)
register const char *s1, *s2;
{
while (*s1 == *s2++)
if (*s1++ == 0)
return (0);
return (*(const u_char *)s1 - *(const u_char *)--s2);
}
|
the_stack_data/42130.c
|
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ARR_LEN(a) (size_t)(sizeof((a)) / sizeof((a)[0]))
typedef struct {
char *str;
bool expect;
} test_t;
bool isNumber(char *s)
{
int i = 0;
bool e = 0;
bool dot = 0;
for (; (' ' == s[i]); ++i);
if ( ('-' == s[i]) || ('+' == s[i]) )
{
++i;
}
for (; '\0' != s[i]; ++i)
{
if ( ('e' == s[i]) && (! e) )
{
if ('-'== s[i+1])
{
++i;
}
e = true;
}
else if ( ('.' == s[i]) && (! e) && (! dot) )
{
dot = true;
}
else if ( (' ' != s[i]) && (('0' > s[i]) || ('9' < s[i])) )
{
return false;
}
}
return true;
}
int main(void)
{
test_t tests[] = {
{" 0.1 ", true},
{"abc" , false},
{"1 a" , false},
{"2e10", true},
{" 1e", false},
{"e3", false},
{" 6e-1", true},
{" --6 ", false},
{"-+3", false},
{" -90e3 ", true},
{" 99e2.5 ", false},
{"53.5e93", true},
{"95a54e53", false},
};
for (size_t i = 0; i < ARR_LEN(tests); ++i)
{
bool ret = isNumber(tests[i].str);
printf("%-15s--> %d", tests[i].str, ret);
if (ret != tests[i].expect)
{
printf(" FAILED");
}
printf("\n");
}
return 0;
}
|
the_stack_data/9511784.c
|
#include<stdio.h>
int main(){
float a, b, c, max;
scanf("%f", &a);
scanf("%f", &b);
scanf("%f", &c);
max=a;
if(max<b)max=b;
if(max<c)max=c;
printf("\n%.1f", max);
return 0;
}
|
the_stack_data/107954349.c
|
#include <stdbool.h>
#include <stdio.h>
struct ListNode {
int val;
struct ListNode *next;
};
bool hasCycle1(struct ListNode *head) {
if (head==NULL)return false;
struct ListNode *fast = head;//一次走两步
struct ListNode *slow = head;//一次走一步
while (fast!=NULL && slow!=NULL && fast->next!=NULL){
fast = fast->next->next;
slow = slow->next;
if (fast==slow)
return true;
}
return false;
}
//堆大小足够的话,操作系统malloc一般是向上生长的,如果链表有环的话,那么next的地址一般比当前地址小
bool hasCycle(struct ListNode *head) {
struct ListNode *p = head;
while (p!=NULL && p->next!=NULL){
if (p->next <= p)//1、指向前面的结点 2、自己指向自己
return true;
p = p->next;
}
return false;
}
|
the_stack_data/90764855.c
|
// SKIP PARAM: --set solver td3 --enable ana.int.interval --enable exp.partition-arrays.enabled --set ana.activated "['base','threadid','threadflag','expRelation','apron','mallocWrapper']" --set exp.privatization none
// These examples were cases were we saw issues of not reaching a fixpoint during development of the octagon domain. Since those issues might
// resurface, these tests without asserts are included
typedef int wchar_t;
typedef unsigned long size_t;
char *trim2(char const *s, int how)
{
char *d;
char *tmp___4;
unsigned int state;
int tmp___9;
if (tmp___9 == 0) {
tmp___9 = 1;
}
size_t tmp___18;
d = tmp___4;
if (tmp___18 > 1UL)
{
if (how != 1)
{
state = 0U;
while (1)
{
if (!tmp___9){
}
else {
break;
}
state = 1U;
}
}
}
return (d);
}
int main(int argc, char const *argv[])
{
char *s;
trim2(s, 4);
return 0;
}
|
the_stack_data/68887778.c
|
//
// Created by hengxin on 7/14/21.
//
#include <stdio.h>
int main() {
/**
* int: %d
*/
// int d;
// scanf("%d", &d);
// printf("d = %d\n", d);
// int d1;
// int d2;
// scanf("%d%d", &d1, &d2);
// printf("d1 = %d \t d2 = %d\n", d1, d2);
/**
* string: %s
*/
char str[10];
scanf("%9s", str);
printf("str = %s\n", str);
scanf("%s", str);
printf("str = %s\n", str);
/**
* input: 302abc302
*/
int e;
char s[10];
scanf("%d%s", &e, s);
printf("e = %d \t s = %s", e, s);
return 0;
}
|
the_stack_data/632884.c
|
#include <stdio.h>
int main(void)
{
int x = 5;
int y = 2;
// typecasting float
float z = (float)x / y;
printf("\nO resultado é %.1f\n", z);
return 0;
} // end main
|
the_stack_data/154645.c
|
#include <stdio.h>
#define SIZE 3000000
int n, a[SIZE], t[SIZE / 2], i, ti, f;
long long c;
void count(int *l, int *r) {
if (r - l <= 1)
return;
int *m = l + (r - l) / 2;
count(l, m);
count(m, r);
int i, j = 0, ls = m - l, rs = r - m;
for (i = 0; i != ls; ++i)
*(t + i) = *(l + i);
for (i = 0; i != ls && j != rs; l++) {
if (*(t + i) <= *(m + j)) {
*l = *(t + i);
i++;
c += j;
} else {
*l = *(m + j);
j++;
}
}
for (; i != ls; i++, l++) {
*l = *(t + i);
c += j;
}
}
int main() {
scanf("%d", &n);
for (i = 0; i != n; ++i)
scanf("%d", a + i);
count(a, a + n);
printf("%lld", c);
return 0;
}
|
the_stack_data/840511.c
|
int a;
int b;
int * p;
int * q;
int ** pp;
int ** pq;
// Case 1
void storeAddress()
{
p = &a;
}
|
the_stack_data/949564.c
|
/*-
* Copyright (c) 2003, Steven G. Kargl
* 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 unmodified, 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 ``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.
*/
#include <sys/cdefs.h>
#if defined(LIBM_SCCS) && !defined(lint)
__RCSID("$NetBSD: s_round.c,v 1.2 2007/08/21 20:10:27 drochner Exp $");
#if 0
__FBSDID("$FreeBSD: src/lib/msun/src/s_round.c,v 1.1 2004/06/07 08:05:36 das Exp $");
#endif
#endif
#include <math.h>
double
round(double x)
{
double t;
int i;
i = fpclassify(x);
if (i == FP_INFINITE || i == FP_NAN)
return (x);
if (x >= 0.0) {
t = floor(x);
if (x - t >= 0.5)
t += 1.0;
return (t);
} else {
x = -x;
t = floor(x);
if (x - t >= 0.5)
t += 1.0;
return (-t);
}
}
|
the_stack_data/43888755.c
|
#include <stdio.h>
int main()
{
int i,j,c;
do{
printf("************\n");
printf("enter the value of c\n");
scanf("%d",&c);
printf("************\n");
for (j=0;j<13;j++)
{
i=j+c;
switch(i)
{
case 1: printf("the value of i is %d\n",i); break;
case 2: printf("the value of i is %d\n",i); break;
case 3: printf("the value of i is %d\n",i); break;
case 4: printf("the value of i is %d\n",i); break;
case 5: printf("the value of i is %d\n",i); break;
case 6: printf("the value of i is %d\n",i); break;
case 7: printf("the value of i is %d\n",i); break;
case 8: printf("the value of i is %d\n",i); break;
case 9: printf("the value of i is %d\n",i); break;
case 10: printf("the value of i is %d\n",i); break;
default: printf("the value of i is exceed 10\n");
}
}
}while(i<=30);
return 0;
}
|
the_stack_data/40761968.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ourgot <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/06 05:30:53 by ourgot #+# #+# */
/* Updated: 2019/09/10 11:33:58 by ourgot ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
return (c >= '0' && c <= '9');
}
|
the_stack_data/43887743.c
|
/**
******************************************************************************
* @file stm32f1xx_ll_gpio.c
* @author MCD Application Team
* @brief GPIO LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© Copyright (c) 2016 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_ll_gpio.h"
#include "stm32f1xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32F1xx_LL_Driver
* @{
*/
#if defined(GPIOA) || defined(GPIOB) || defined(GPIOC) || defined(GPIOD) || defined(GPIOE) || defined(GPIOF) || defined(GPIOG)
/** @addtogroup GPIO_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup GPIO_LL_Private_Macros
* @{
*/
#define IS_LL_GPIO_PIN(__VALUE__) ((((__VALUE__)&LL_GPIO_PIN_ALL) != 0u) && (((__VALUE__) & (~LL_GPIO_PIN_ALL)) == 0u))
#define IS_LL_GPIO_MODE(__VALUE__) \
(((__VALUE__) == LL_GPIO_MODE_ANALOG) || ((__VALUE__) == LL_GPIO_MODE_FLOATING) || ((__VALUE__) == LL_GPIO_MODE_INPUT) || \
((__VALUE__) == LL_GPIO_MODE_OUTPUT) || ((__VALUE__) == LL_GPIO_MODE_ALTERNATE))
#define IS_LL_GPIO_SPEED(__VALUE__) \
(((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) || ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) || ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) || ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
#define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_DOWN) || ((__VALUE__) == LL_GPIO_PULL_UP))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup GPIO_LL_Exported_Functions
* @{
*/
/** @addtogroup GPIO_LL_EF_Init
* @{
*/
/**
* @brief De-initialize GPIO registers (Registers restored to their default values).
* @param GPIOx GPIO Port
* @retval An ErrorStatus enumeration value:
* - SUCCESS: GPIO registers are de-initialized
* - ERROR: Wrong GPIO Port
*/
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
/* Force and Release reset on clock of GPIOx Port */
if (GPIOx == GPIOA) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOA);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOA);
} else if (GPIOx == GPIOB) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOB);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOB);
} else if (GPIOx == GPIOC) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOC);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOC);
} else if (GPIOx == GPIOD) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOD);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOD);
}
#if defined(GPIOE)
else if (GPIOx == GPIOE) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOE);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOE);
}
#endif
#if defined(GPIOF)
else if (GPIOx == GPIOF) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOF);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOF);
}
#endif
#if defined(GPIOG)
else if (GPIOx == GPIOG) {
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOG);
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOG);
}
#endif
else {
status = ERROR;
}
return (status);
}
/**
* @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
* @param GPIOx GPIO Port
* @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
* that contains the configuration information for the specified GPIO peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
* - ERROR: Not applicable
*/
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
{
uint32_t pinmask;
uint32_t pinpos;
uint32_t currentpin;
/* Check the parameters */
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
/* ------------------------- Configure the port pins ---------------- */
/* Initialize pinpos on first pin set */
pinmask = ((GPIO_InitStruct->Pin) << GPIO_PIN_MASK_POS) >> GPIO_PIN_NB;
pinpos = POSITION_VAL(pinmask);
/* Configure the port pins */
while ((pinmask >> pinpos) != 0u) {
/* skip if bit is not set */
if ((pinmask & (1u << pinpos)) != 0u) {
/* Get current io position */
if (pinpos < GPIO_PIN_MASK_POS) {
currentpin = (0x00000101uL << pinpos);
} else {
currentpin = ((0x00010001u << (pinpos - GPIO_PIN_MASK_POS)) | 0x04000000u);
}
/* Check Pin Mode and Pin Pull parameters */
assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
/* Pin Mode configuration */
LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
/* Pull-up Pull-down resistor configuration*/
LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) {
/* Check speed and Output mode parameters */
assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
/* Speed mode configuration */
LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
/* Output mode configuration*/
LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
}
}
pinpos++;
}
return (SUCCESS);
}
/**
* @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
* @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
{
/* Reset GPIO init structure parameters values */
GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
GPIO_InitStruct->Mode = LL_GPIO_MODE_FLOATING;
GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct->Pull = LL_GPIO_PULL_DOWN;
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined \
(GPIOF) || defined (GPIOG) */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/946572.c
|
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MDATA_MAX_SIZE 1000
#define MOVINGAVERAGING_WINDOW_SIZE 10
#define NO_ERROR 0
#define OUT_OF_MEMORY_ERROR 1
#define FILE_ERROR 2
#define ECGDATA_SAMPLE_RATE 360
void genSinusWithNoise(double f[], int length, double length_period, double amplitude, double offset, double amplitude_noise)
{
for (int i = 0; i < length; ++i)
{
f[i] = amplitude * sin(2*M_PI/length_period * i);
f[i] += offset;
f[i] += (rand() % 100) * amplitude_noise/100;
}
}
int readDataFromFile(char *filepath, double *mdata, int max_length, int *length)
{
int idummy = 0;
double ddummy = 0;
FILE* f = fopen(filepath, "r");
if (f==NULL)
return FILE_ERROR;
*length = 0;
while (!feof(f) && (*length < max_length)) // Solange Dateiende NICHT erreicht ist
{
char s[100];
if (fgets(s,100,f) == NULL) // Nächste Zeile einlesen
break;
if (sscanf(s,"%d;%lf;%lf", &idummy, &mdata[*length], &ddummy) == 3)
(*length)++;
}
fclose(f);
return NO_ERROR;
}
int writeData2File(char *filepath, double data[], int length)
{
FILE* f = fopen(filepath, "w");
if (f == NULL)
return FILE_ERROR;
for (int i=0;i<length;i++)
fprintf(f,
"%.3f\n", data[i]
);
fclose(f);
return NO_ERROR;
}
double removeOffset(double f[], int length)
{
double sum = 0;
double offset = 0;
for(int i = 0; i < length; ++i)
{
sum += f[i];
}
offset = sum/length;
for(int i = 0; i < length; ++i) {
f[i] -= offset;
}
return offset;
}
void calcMovingAveraging(double f[], int length) {
double sum=0;
double avg=0;
for(int i = 0; i < MOVINGAVERAGING_WINDOW_SIZE; i++)
{
sum += f[i];
}
for(int i = 0; i < (length - MOVINGAVERAGING_WINDOW_SIZE); i++)
{
avg = sum / MOVINGAVERAGING_WINDOW_SIZE;
sum += f[i + 10];
sum = sum - f[i];
f[i] = avg;
}
}
void diffSignal (double f[], int lenght) {
for (int i = 0; i < (lenght - 1); i++) {
f[i] = f[i + 1] - f[i];
}
}
double normalizeSignal(double f[], int lenght){
double max = 0;
double runden;
for(int i = 0; i < lenght; i++) {
if(abs(f[i]) > max ) {
max = abs(f[i]);
}
}
for(int i = 0; i < lenght; i++) {
f[i] = f[i] / max;
runden = round(f[i]);
f[i] = runden;
}
return 0;
}
double getMaxValue(double f[], int length, int *x) {
double groessterWert = 0;
for (int i = 0; i < length; i++) {
if (abs(f[i]) > groessterWert) {
groessterWert = abs(f[i]);
*x = i;
}
}
return 0;
}
int findRPeak(double f_2diff[], double f_orig[], int length, double rpeak[], int rpeak_length) {
int nz_legnth = 0;
int qrs_complex_start = -1, qrs_complex_end = -1;
int rpeak_i = 0;
int x = 0;
//Abtastrate: ECGDATA_SAMPLE_RATE = 360 Hz
//Abtastdauer: 1/360 s
//Wieviele Feldelemente sind in 0.6 s enthalten?
//0.6/(1/360) = 0.6 s * Abtastfrequenz
const int nsep = 0.6 * ECGDATA_SAMPLE_RATE;
//1.) Wir suchen den Startpunkt des ersten QRS-Komplexe -> Q-Wert
for( int i = 0; i < length; ++i) {
if (f_2diff[i] != 0) {
qrs_complex_start = i;
qrs_complex_end = i;
break;
}
}
//2.) Suche die Start und Endwerte aller restlichen QRS-suchen und zwischen den Start-
// und Endpunkten wird das Maximum und somit die R-Zacke bestimmt!
for( int i = qrs_complex_start + 1; i < length; ++i) {
if (f_2diff[i] != 0) { //Start oder Ende eines QRS-Komplex detektiert?
if ( (i - qrs_complex_end) >= nsep ) { //neuen QRS-Komplex gefunden!
if (rpeak_i < rpeak_length) {
getMaxValue(&f_orig[qrs_complex_start], qrs_complex_end - qrs_complex_start, &x);
rpeak[rpeak_i] = x + qrs_complex_start;
//printf("%d.): qrs-start: %d, qrs-length: %d, r-peak: %1.f\n", rpeak_i, qrs_complex_start, qrs_complex_end - qrs_complex_start, rpeak[rpeak_i]);
++rpeak_i;
qrs_complex_start = i;
}
else {
break;
}
}
qrs_complex_end = i;
}
}
/*
* continue;
if (letztes Feldelement - qrs_complex_start > 2*letzterDetektierterHerzschlag)
; //-> Stromschlag
*/
if (qrs_complex_end > qrs_complex_start) {
getMaxValue(&f_orig[qrs_complex_start], qrs_complex_end - qrs_complex_start, &x);
rpeak[rpeak_i] = x + qrs_complex_start;
//printf("%d.): qrs-start: %d, qrs-length: %d, r-peak: %1.f\n", rpeak_i, qrs_complex_start, qrs_complex_end - qrs_complex_start, rpeak[rpeak_i]);
++rpeak_i;
}
return rpeak_i;
}
void printHeartRate(double rpeak[], int length) {
int anzahl;
double rpm;
for(int i = 0; i < (length - 1); i++) {
anzahl = rpeak[i + 1] - rpeak[i];
rpm = (ECGDATA_SAMPLE_RATE * 60) / anzahl;
printf("%lf", rpm);
}
}
int changeFeld(double f[], double f_orgin[], int length) {
for (int i = 0; i < length; i++) {
f_orgin[i] = f[i];
}
return 0;
}
int main () {
double f[999];
double f_orig[999];
double rpeak[10];
int rpeak_length = 10;
int length = 999;
//double rvgenSinusWithNoise = genSinusWithNoise(f, length, 100, 2, 1, 0.2);
readDataFromFile("mdata.csv", f, length, &length);
writeData2File("EKG1.csv", f, length);
double offset = removeOffset(f, length);
calcMovingAveraging(f, length);
changeFeld(f, f_orig, length);
writeData2File("EKG_gefiltert.csv", f, length);
diffSignal(f, length);
normalizeSignal(f, length);
diffSignal(f, length);
writeData2File("EKG3.csv", f, length);
double rpeak_i = findRPeak(f, f_orig, length, rpeak, rpeak_length);
printHeartRate(rpeak, rpeak_i);
system("python3 plotdata.py EKG3.csv");
return 0;
}
/*
double mdata[MDATA_MAX_SIZE];
measurement data
int mdata_length = 0;
readDataFromFile("mdata.csv", mdata, MDATA_MAX_SIZE, &mdata_length);
genSinusWithNoise(mdata, sizeof(mdata)/sizeof(double), 100, 2, 1, 0.2);
genSinusWithNoise(mdata, sizeof(mdata)/sizeof(double), 100, 2, 1, 0.0);
writeData2File("sinus.csv", mdata, sizeof(mdata)/sizeof(double));
return (EXIT_SUCCESS);
*/
|
the_stack_data/218894538.c
|
/* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern void signal(int sig , void *func ) ;
extern float strtof(char const *str , char const *endptr ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
void RandomFunc(unsigned int input[1] , unsigned int output[1] )
{
unsigned int state[1] ;
unsigned short copy13 ;
{
state[0UL] = input[0UL] + 4284877637U;
if ((state[0UL] >> 4U) & 1U) {
if ((state[0UL] >> 4U) & 1U) {
state[0UL] *= state[0UL];
} else {
state[0UL] += state[0UL];
state[0UL] *= state[0UL];
}
} else
if ((state[0UL] >> 3U) & 1U) {
copy13 = *((unsigned short *)(& state[0UL]) + 0);
*((unsigned short *)(& state[0UL]) + 0) = *((unsigned short *)(& state[0UL]) + 1);
*((unsigned short *)(& state[0UL]) + 1) = copy13;
} else {
state[0UL] += state[0UL];
}
output[0UL] = (state[0UL] - 504895825UL) + 234084018U;
}
}
int main(int argc , char *argv[] )
{
unsigned int input[1] ;
unsigned int output[1] ;
int randomFuns_i5 ;
unsigned int randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 4242424242U) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
|
the_stack_data/179831669.c
|
#include <stdlib.h>
/**
* string_nconcat - concatenates two strings, up to n bytes of s2
*
* @s1: string 1 to concatenate with string 2
* @s2: string 2 to concatenate with string 1
* @n: number of bytes to concatenate of s2
*
* Return: pointer to new string, or NULL on failure
*/
char *string_nconcat(char *s1, char *s2, unsigned int n)
{
unsigned int s1Size = 0, s2Size = 0, i = 0;
char *conc, *concStart;
if (s1 == NULL)
s1 = "";
if (s2 == NULL)
s2 = "";
while (*(s1 + s1Size))
s1Size++;
while (*(s2 + s2Size))
s2Size++;
if (n > s2Size)
n = s2Size;
conc = malloc(sizeof(char) * (s1Size + n) + 1);
if (conc == NULL)
return (NULL);
concStart = conc;
while (*s1)
*conc++ = *s1++;
while (i < n)
{
*conc++ = *s2++;
i++;
}
*conc = '\0';
return (concStart);
}
|
the_stack_data/59512849.c
|
/*Exercise 3 - Repetition
Write a C program to calculate the sum of the numbers from 1 to n.
Where n is a keyboard input.
e.g.
n -> 100
sum = 1+2+3+....+ 99+100 = 5050
n -> 1-
sum = 1+2+3+...+10 = 55 */
#include <stdio.h>
int main()
{
int number, n, sum;
sum = 0;
printf("Enter a number: ");
scanf("%d",&number);
for(n = 1; n <= number; n++)
{
sum += n;
}
printf("The sum is:%d",sum);
return 0;
}
|
the_stack_data/156392060.c
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int l, i, ljb;
double a,b,c;
scanf("%d", &l);
for (i = 0; i < l; i++)
{
//获取三条边
scanf("%lf %lf %lf", &a, &b, &c);
//计算部分
//初始化变量
ljb = 1;
//任意两边之和大于第三边
if (!(a + b > c && a + c > b && b + c > a))
{
ljb = 0;
}
//输出
if (ljb == 0)
{
printf("NO\n");
} else {
printf("YES\n");
}
}
return 0;
}
|
the_stack_data/161080628.c
|
/* compress.c -- compress a memory buffer
* Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#define ZLIB_INTERNAL
#include "zlib.h"
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}
/* ===========================================================================
If the default memLevel or windowBits for deflateInit() is changed, then
this function needs to be updated.
*/
uLong ZEXPORT compressBound (sourceLen)
uLong sourceLen;
{
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
}
|
the_stack_data/981772.c
|
//original file: EBStack.java
//amino-cbbs\trunk\amino\java\src\main\java\org\amino\ds\lockfree
//push only
#include <pthread.h>
#define assume(e) __VERIFIER_assume(e)
#define assert(e) { if(!(e)) { ERROR: goto ERROR; (void)0; } }
void __VERIFIER_atomic_CAS(
int *v,
int e,
int u,
int *r)
{
if(*v == e)
{
*v = u, *r = 1;
}
else
{
*r = 0;
}
}
#define MEMSIZE (2*32+1) //0 for "NULL"
int memory[MEMSIZE];
#define INDIR(cell,idx) memory[cell+idx]
int next_alloc_idx = 1;
int top = 0;
void __VERIFIER_atomic_index_malloc(int *curr_alloc_idx)
{
if(next_alloc_idx+2-1 > MEMSIZE) *curr_alloc_idx = 0;
else *curr_alloc_idx = next_alloc_idx, next_alloc_idx += 2;
}
#define isEmpty() (top == 0)
#define exit(r) assume(0);
inline void push(int d) {
int oldTop, newTop,ret;
__VERIFIER_atomic_index_malloc(&newTop);
if(newTop == 0)
exit(-1);
INDIR(newTop,0) = d;
while (1) {
oldTop = top;
INDIR(newTop,1) = oldTop;
__VERIFIER_atomic_CAS(&top,oldTop,newTop,&ret);
if(ret) return;
}
}
void* thr1(void* arg){
while(1){push(10); assert(top != 0);}
return 0;
}
int main()
{
pthread_t t;
while(1) { pthread_create(&t, 0, thr1, 0); }
}
|
the_stack_data/67325373.c
|
#include <stdio.h>
#define MAXTITL 64
#define MAXAUTH 64
#define MAXBOKS 64
struct book{
char title[MAXTITL];
char auth[MAXAUTH];
float value;
};
int main(int argc, char *argv[])
{
struct book library[MAXBOKS];
int count = 0, idx;
printf("Enter the book title : \n");
printf("Press [ENTER] at the start of line to stop.\n");
while (count < MAXBOKS && gets(library[count].title) != NULL && library[count].title[0])
{
printf("Now enter the auhtor :");
gets(library[count].auth);
printf("Now enter the price :");
scanf("%f", &library[count++].value);
while (getchar() != 10) {}
if (count < MAXBOKS)
printf("Enter the next line :");
}
if (count > 0)
{
printf("Here is the list of your books :\n");
for (idx = 0; idx < count ; idx ++)
{
printf("\e[3;33m%s\e[0m by \e[0;31m%s \e[0m: \e[0;30m$%.2f[0m\n",library[idx].title, library[idx].auth , library[idx].value);
}
}
else {
printf("No books , so bad\n");
}
return 0;
}
|
the_stack_data/178264941.c
|
// C Compiler flag: -fopenmp
#include <stdio.h>
#include <omp.h>
#include <stdlib.h>
#define N 20
int main(int argc, char *argv[])
{
int threadsCount = omp_get_max_threads();
printf("Threads count: %d\n", threadsCount);
int length = 12;
int a[length];
int b[length];
int c[length];
;
//printf("before first section: a: %d ; b: %d\n",a, b);
#pragma omp parallel for schedule(static, 4) num_threads(3)
for (int i = 0; i < length; i++)
{
a[i] = i * 10;
b[i] = i * 20;
printf("working %d of %d threads\n", omp_get_thread_num(), omp_get_num_threads());
}
for (int i = 0; i < length; i++)
{
printf("%d ", a[i]);
}
printf("\n");
for (int i = 0; i < length; i++)
{
printf("%d ", b[i]);
}
printf("\n");
#pragma omp parallel for schedule(dynamic, 2) num_threads(4)
for (int i = 0; i < length; i++)
{
c[i] = a[i] + b[i];
printf("working %d of %d threads\n", omp_get_thread_num(), omp_get_num_threads());
}
for (int i = 0; i < length; i++)
{
printf("%d ", c[i]);
}
printf("\n");
return 0;
}
|
the_stack_data/145497.c
|
#ifdef COMPILE_FOR_TEST
#include <assert.h>
#define assume(cond) assert(cond)
#endif
void main(int argc, char* argv[]) {
int x_0_0;//sh_buf.outcnt
int x_0_1;//sh_buf.outcnt
int x_0_2;//sh_buf.outcnt
int x_0_3;//sh_buf.outcnt
int x_0_4;//sh_buf.outcnt
int x_0_5;//sh_buf.outcnt
int x_1_0;//sh_buf.outbuf[0]
int x_1_1;//sh_buf.outbuf[0]
int x_2_0;//sh_buf.outbuf[1]
int x_2_1;//sh_buf.outbuf[1]
int x_3_0;//sh_buf.outbuf[2]
int x_3_1;//sh_buf.outbuf[2]
int x_4_0;//sh_buf.outbuf[3]
int x_4_1;//sh_buf.outbuf[3]
int x_5_0;//sh_buf.outbuf[4]
int x_5_1;//sh_buf.outbuf[4]
int x_6_0;//sh_buf.outbuf[5]
int x_7_0;//sh_buf.outbuf[6]
int x_8_0;//sh_buf.outbuf[7]
int x_9_0;//sh_buf.outbuf[8]
int x_10_0;//sh_buf.outbuf[9]
int x_11_0;//LOG_BUFSIZE
int x_11_1;//LOG_BUFSIZE
int x_12_0;//CREST_scheduler::lock_0
int x_13_0;//t3 T0
int x_14_0;//t2 T0
int x_15_0;//arg T0
int x_16_0;//functioncall::param T0
int x_16_1;//functioncall::param T0
int x_17_0;//buffered T0
int x_18_0;//functioncall::param T0
int x_18_1;//functioncall::param T0
int x_19_0;//functioncall::param T0
int x_19_1;//functioncall::param T0
int x_20_0;//functioncall::param T0
int x_20_1;//functioncall::param T0
int x_21_0;//functioncall::param T0
int x_21_1;//functioncall::param T0
int x_22_0;//direction T0
int x_23_0;//functioncall::param T0
int x_23_1;//functioncall::param T0
int x_24_0;//functioncall::param T0
int x_24_1;//functioncall::param T0
int x_25_0;//functioncall::param T0
int x_25_1;//functioncall::param T0
int x_26_0;//functioncall::param T0
int x_26_1;//functioncall::param T0
int x_27_0;//functioncall::param T0
int x_27_1;//functioncall::param T0
int x_28_0;//functioncall::param T0
int x_28_1;//functioncall::param T0
int x_29_0;//functioncall::param T0
int x_29_1;//functioncall::param T0
int x_30_0;//functioncall::param T0
int x_30_1;//functioncall::param T0
int x_31_0;//functioncall::param T0
int x_31_1;//functioncall::param T0
int x_32_0;//functioncall::param T0
int x_32_1;//functioncall::param T0
int x_33_0;//functioncall::param T0
int x_33_1;//functioncall::param T0
int x_34_0;//functioncall::param T0
int x_34_1;//functioncall::param T0
int x_35_0;//functioncall::param T1
int x_35_1;//functioncall::param T1
int x_36_0;//functioncall::param T1
int x_36_1;//functioncall::param T1
int x_37_0;//i T1
int x_37_1;//i T1
int x_37_2;//i T1
int x_38_0;//rv T1
int x_39_0;//rv T1
int x_39_1;//rv T1
int x_40_0;//functioncall::param T1
int x_40_1;//functioncall::param T1
int x_41_0;//functioncall::param T1
int x_41_1;//functioncall::param T1
int x_42_0;//functioncall::param T1
int x_42_1;//functioncall::param T1
int x_43_0;//functioncall::param T1
int x_43_1;//functioncall::param T1
int x_44_0;//functioncall::param T1
int x_44_1;//functioncall::param T1
int x_45_0;//functioncall::param T1
int x_45_1;//functioncall::param T1
int x_46_0;//functioncall::param T1
int x_46_1;//functioncall::param T1
int x_47_0;//functioncall::param T1
int x_47_1;//functioncall::param T1
int x_48_0;//functioncall::param T1
int x_48_1;//functioncall::param T1
int x_49_0;//functioncall::param T2
int x_49_1;//functioncall::param T2
int x_50_0;//functioncall::param T2
int x_50_1;//functioncall::param T2
int x_51_0;//i T2
int x_51_1;//i T2
int x_51_2;//i T2
int x_51_3;//i T2
int x_52_0;//rv T2
int x_53_0;//functioncall::param T2
int x_53_1;//functioncall::param T2
int x_54_0;//functioncall::param T2
int x_54_1;//functioncall::param T2
int x_55_0;//functioncall::param T2
int x_55_1;//functioncall::param T2
int x_55_2;//functioncall::param T2
int x_56_0;//functioncall::param T2
int x_56_1;//functioncall::param T2
T_0_0_0: x_0_0 = 0;
T_0_1_0: x_1_0 = 0;
T_0_2_0: x_2_0 = 0;
T_0_3_0: x_3_0 = 0;
T_0_4_0: x_4_0 = 0;
T_0_5_0: x_5_0 = 0;
T_0_6_0: x_6_0 = 0;
T_0_7_0: x_7_0 = 0;
T_0_8_0: x_8_0 = 0;
T_0_9_0: x_9_0 = 0;
T_0_10_0: x_10_0 = 0;
T_0_11_0: x_11_0 = 0;
T_0_12_0: x_13_0 = 2207465696;
T_0_13_0: x_14_0 = 652563040;
T_0_14_0: x_15_0 = 0;
T_0_15_0: x_16_0 = 1629818292;
T_0_16_0: x_16_1 = -1;
T_0_17_0: x_17_0 = 0;
T_0_18_0: x_18_0 = 186374628;
T_0_19_0: x_18_1 = x_17_0;
T_0_20_0: x_19_0 = 121281417;
T_0_21_0: x_19_1 = 97;
T_0_22_0: x_20_0 = 423504060;
T_0_23_0: x_20_1 = 0;
T_0_24_0: x_21_0 = 2110638670;
T_0_25_0: x_21_1 = 0;
T_0_26_0: x_22_0 = 652558400;
T_0_27_0: x_23_0 = 1012126001;
T_0_28_0: x_23_1 = x_22_0;
T_0_29_0: x_24_0 = 1398782568;
T_0_30_0: x_24_1 = 0;
T_0_31_0: x_12_0 = -1;
T_0_32_0: x_0_1 = 5;
T_0_33_0: x_1_1 = 72;
T_0_34_0: x_2_1 = 69;
T_0_35_0: x_3_1 = 76;
T_0_36_0: x_4_1 = 76;
T_0_37_0: x_5_1 = 79;
T_0_38_0: x_25_0 = 205823360;
T_0_39_0: x_25_1 = 83;
T_0_40_0: x_26_0 = 1927757954;
T_0_41_0: x_26_1 = 1;
T_0_42_0: x_27_0 = 137460458;
T_0_43_0: x_27_1 = 1;
T_0_44_0: x_28_0 = 2079608722;
T_0_45_0: x_28_1 = 1;
T_0_46_0: x_29_0 = 505851798;
T_0_47_0: x_29_1 = 82;
T_0_48_0: x_30_0 = 858577036;
T_0_49_0: x_30_1 = 90;
T_0_50_0: x_31_0 = 18606374;
T_0_51_0: x_31_1 = 1;
T_0_52_0: x_32_0 = 14098913;
T_0_53_0: x_32_1 = 1;
T_0_54_0: x_33_0 = 863163108;
T_0_55_0: x_33_1 = 2;
T_0_56_0: x_34_0 = 1099126220;
T_0_57_0: x_34_1 = 2;
T_0_58_0: x_11_1 = 3;
T_1_59_1: x_35_0 = 486398993;
T_1_60_1: x_35_1 = x_27_1;
T_1_61_1: x_36_0 = 1019567072;
T_1_62_1: x_36_1 = x_28_1;
T_1_63_1: x_37_0 = 0;
T_1_64_1: x_38_0 = -701119999;
T_1_65_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_39_0 = 659625904;
T_1_66_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_40_0 = 677875750;
T_1_67_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_40_1 = -1;
T_1_68_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_39_1 = x_40_1;
T_1_69_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_39_1 + 1 == 0) x_0_2 = 0;
T_1_70_1: x_49_0 = 1930682230;
T_1_71_1: x_49_1 = x_33_1;
T_2_72_2: x_50_0 = 1673004486;
T_2_73_2: x_50_1 = x_34_1;
T_2_74_2: x_51_0 = 0;
T_2_75_2: x_52_0 = -703221247;
T_2_76_2: if (x_50_1 < x_11_1) x_53_0 = 1079352320;
T_2_77_2: if (x_50_1 < x_11_1) x_53_1 = 47649070405376;
T_2_78_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_41_0 = 624807112;
T_2_79_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_41_1 = 9;
T_1_80_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_42_0 = 1731805325;
T_1_81_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_42_1 = x_41_1;
T_1_82_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_0_3 = 0;
T_1_83_1: if (x_36_1 < x_11_1) x_43_0 = 956941541;
T_1_84_1: if (x_36_1 < x_11_1) x_43_1 = 47649068304128;
T_1_85_1: if (x_36_1 < x_11_1) x_44_0 = 919240087;
T_1_86_1: if (x_36_1 < x_11_1) x_44_1 = x_0_3 + x_36_1;
T_1_87_1: if (x_36_1 < x_11_1) x_37_1 = 0;
T_1_88_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_45_0 = 1442639402;
T_1_89_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_45_1 = 47649068304128;
T_1_90_1: if (x_36_1 < x_11_1) x_37_2 = 1 + x_37_1;
T_1_91_1: if (x_36_1 < x_11_1) x_46_0 = 1829814318;
T_1_92_1: if (x_36_1 < x_11_1) x_46_1 = 47649068304128;
T_1_93_1: if (x_36_1 < x_11_1) x_0_4 = x_0_3 + x_36_1;
T_1_94_1: if (x_36_1 < x_11_1) x_47_0 = 1998090619;
T_1_95_1: if (x_36_1 < x_11_1) x_47_1 = 47649068304128;
T_1_96_1: if (x_50_1 < x_11_1) x_54_0 = 1102654503;
T_1_97_1: if (x_50_1 < x_11_1) x_54_1 = x_0_2 + x_50_1;
T_2_98_2: if (x_50_1 < x_11_1) x_51_1 = 0;
T_2_99_2: if (x_50_1 < x_11_1 && x_51_1 < x_49_1) x_55_0 = 1312148962;
T_2_100_2: if (x_50_1 < x_11_1 && x_51_1 < x_49_1) x_55_1 = 47649070405376;
T_2_101_2: if (x_50_1 < x_11_1) x_51_2 = 1 + x_51_1;
T_2_102_2: if (x_50_1 < x_11_1 && x_51_2 < x_49_1) x_55_2 = 47649070405376;
T_2_103_2: if (x_50_1 < x_11_1) x_51_3 = 1 + x_51_2;
T_2_104_2: if (x_50_1 < x_11_1) x_56_0 = 36981599;
T_2_105_2: if (x_50_1 < x_11_1) x_56_1 = 47649070405376;
T_2_106_2: if (x_50_1 < x_11_1) x_0_5 = x_0_4 + x_50_1;
T_2_107_2: if (x_36_1 < x_11_1) x_48_0 = 1223935920;
T_2_108_2: if (x_36_1 < x_11_1) x_48_1 = 47649068304128;
T_1_109_1: if (x_36_1 < x_11_1) assert(x_0_5 == x_44_1);
}
|
the_stack_data/26700481.c
|
#define intval(p) (((int)(p))>>2)
#define makeint(v) ((((int)v)<<2)+2)
main()
{
int x,y,z;
x=0xe2345678;
y=makeint(x);
z=intval(y);
printf("%x %x %x\n", x,y,z);
}
|
the_stack_data/1176711.c
|
#include <stdio.h>
void main() {
printf("Hello World!");
}
|
the_stack_data/25136525.c
|
#include<stdio.h>
#include<math.h>
int stringToNumber(char arr[]) {
int number = 0;
for( int i = 0; arr[i] != '\0'; i++) {
number = number * 10 + (arr[i] - '0');
}
return number;
}
int dayofweek(int d, int m, int y) {
int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
if(m < 3) {
y--;
}
return ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
int main() {
int size = 20;
char dateString[size];
char date[size];
char month[size];
char year[size];
int i, j;
printf("\n\nEnter the date in a single line: ( DD-MM-YYYY / DD.MM.YYYY / DD_MM_YYYY ) \n\n");
scanf("%[^\n]s",dateString);
printf("\nThe entered date is : \n");
printf("\n%s\n",dateString);
j = 0;
for(i=0; i<2; i++) {
date[i] = dateString[j];
j++;
}
date[i] = '\0';
j = 3;
for(i=0; i<2; i++) {
month[i] = dateString[j];
j++;
}
month[i] = '\0';
j = 6;
for(i=0; i<4; i++) {
year[i] = dateString[j];
j++;
}
year[i] = '\0';
int d = stringToNumber(date);
int m = stringToNumber(month);
int y = stringToNumber(year);
int ind = dayofweek(d,m,y);
printf("\nDate : %d\n",d);
printf("\nMonth : %d\n",m);
printf("\nYear: %d\n",y);
char array[7][10] = { "Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday" } ;
printf("\nResult:\n\n\nIt was %s on %s\n\n",array[ind],dateString);
}
|
the_stack_data/461557.c
|
#include <stdio.h>
#include <math.h>
void main(){
FILE *infa;
FILE *outf;
double f;
long long int i;
long long unsigned int a;
infa = fopen("stim/double_ceil_a", "r");
outf = fopen("stim/double_ceil_z_expected", "w");
while(1){
if(fscanf(infa, "%llu", &a) == EOF) break;
f = *(double*)&a;
f = ceil(f);
i = *(long long int*)&f;
fprintf(outf, "%llu\n", i);
}
fclose(infa);
fclose(outf);
}
|
the_stack_data/178266412.c
|
//@ #include "nat.gh"
/*@
lemma void induction(nat n1, nat n2)
requires true;
ensures true;
{
switch(n1)
{
case succ(n10):
switch(n2)
{
case succ(n20):
induction(zero, n10); //~
case zero:
}
case zero:
switch(n2)
{
case succ(n20):
case zero:
}
}
}
@*/
|
the_stack_data/31387745.c
|
#include <stdio.h>
int main() {
int i, j, k = 1, x, y, n_linhas;
scanf("%d %d", &x, &y);
n_linhas = y / x;
for (i = 1; i <= n_linhas; i++) {
for (j = 1; j <= x - 1; j++) {
printf("%d ", k);
k++;
}
printf("%d\n", k);
k++;
}
return 0;
}
|
the_stack_data/109748.c
|
int main()
{
int i, ii;
int data=0;
char *p=(char *)&data;
i=ii;
__CPROVER_assume(i>=0 && i<4);
p[i]++;
if(i==0)
assert(data==1);
else if(i==1)
assert(data==0x100);
else if(i==2)
assert(data==0x10000);
else
assert(data==0x1000000);
}
|
the_stack_data/184517432.c
|
/////////////////////////////
// The superstring problem //
/////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Constants */
#define MAXSTRINGLENGTH 100
#define INF 100000
/* Help functions */
unsigned int max(unsigned int a, unsigned int b) { /* Basic maximum finding (unsigned ints) */
if (a > b) return a;
else return b;
}
int maxint(int a, int b) { /* Basic maximum finding (ints) */
if (a > b) return a;
else return b;
}
unsigned int power(unsigned int a, unsigned int n) { /* Fast powering */
if (!n) return 1;
return (n % 2) ? a * power(a, n - 1) : power(a * a, n / 2);
}
unsigned char bit(unsigned int i, unsigned long mask) { /* i bit of mask */
return (mask >> i) % 2;
}
unsigned int count(unsigned long mask) { /* the number of 1-bits of mask */
return (mask == 0) ? 0 : (mask % 2) + count(mask >> 1);
}
/* Main algorithms */
unsigned int *p_function(char *s) { /* The prefix-function finding */
unsigned int i, j, n = strlen(s);
unsigned int *res = malloc(n * sizeof(unsigned int));
res[0] = 0;
for(i = 1; i < n; i++) {
j = res[i - 1];
while ((j > 0) && (s[i] != s[j]))
j = res[j - 1];
res[i] = j;
if (s[i] == s[j]) res[i]++;
}
return res;
}
unsigned int cmp(char *s1, char *s2, unsigned int *f) { /* The Knuth-Morris-Pratt's algorithm. It differs a bit from p_function */
unsigned int i, k = 0;
for(i = 0; i < strlen(s2); i++) {
while ((k > 0) && (s1[k] != s2[i]))
k = f[k - 1];
if (s1[k] == s2[i]) k++;
}
return k;
}
int **hamilton(unsigned int **d, unsigned int n) { /* Finding hamiltonian path by the dynamics in the profile */
int **dp = (int **)malloc(power(2, n) * sizeof(unsigned long *));
unsigned int mask, i, j;
for(i = 0; i < power(2, n); i++) {
dp[i] = calloc(n, sizeof(int));
for(j = 0; j < n; j++)
dp[i][j] = ((count(i) == 1) && (bit(j, i))) ? 0 : -INF;
}
for(mask = 0; mask < power(2, n); mask++)
for(i = 0; i < n; i++)
if ((count(mask) - 1) && !(bit(i, mask) - 1))
for(j = 0; j < n; j++)
dp[mask][i] = maxint(dp[mask][i], dp[mask ^ power(2, i)][j] + d[j][i]);
return dp;
}
/* Core */
int main(int argc, char **argv) {
unsigned int n, i, j, total_length = 0;
//------------input and preprocessing------------
scanf("%u\n", &n);
char **s = (char **)malloc(n * sizeof(unsigned long*));
char tmp_str[MAXSTRINGLENGTH];
unsigned int *p_array[n]; /* array of p-functions for all strings. Needed for preprocessing of p_matrix */
unsigned int **p_matrix = (unsigned int **)malloc(n * sizeof(unsigned long*)); /* The first part of the problem's solution, */
/* contains prefix-functions for all ordered pairs of strings */
for(i = 0; i < n; i++) {
p_matrix[i] = malloc(n * sizeof(int));
gets(tmp_str);
total_length += strlen(tmp_str);
s[i] = malloc((strlen(tmp_str) + 1) * sizeof(unsigned char));
for(j = 0; j < strlen(tmp_str); j++) {
s[i][j] = tmp_str[j];
}
s[i][strlen(tmp_str)] = '\0';
p_array[i] = p_function(s[i]);
}
//------------Fill the prefix-matrix-------------
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
if (i == j) p_matrix[i][j] = 0;
else p_matrix[i][j] = (int)cmp(s[i], s[j], p_array[i]);
for(i = 0; i < n; i++) {
free(s[i]);
free(p_array[i]);
}
free(s);
//-----------Finding answer and output-----------
int **dp = hamilton(p_matrix, n);
unsigned int ans = 0;
for(i = 0; i < n; i++) {
if (dp[power(2, n) - 1][i] < 0) continue;
ans = max(ans, dp[power(2, n) - 1][i]);
free(p_matrix[i]);
}
free(p_matrix);
for(i = 0; i < power(2, n); i++)
free(dp[i]);
free(dp);
printf("%u", total_length - ans);
return 0;
}
|
the_stack_data/1218270.c
|
/* trans2genom.c
Junfeng Liu, 2016
This is an program to convert the position of transcriptome to the position of genome according to the file generated by bismark_methylation_extractor and out_trans.
gcc -o trans2genom-bismark trans2genom-bismark.c -lm
trans2genom-bismark <pe.txt generated by bismark_methylation_extractor > <out_trans>
*/
#include<stdio.h>
#include<string.h>
#include<errno.h>
#include<stdlib.h>
#include<math.h>
/*The function is used to convert the position of transcriptome to the position of genome according to the file pe.txt and out_trans*/
int convert (char *summary_complex, char *out_trans);
/*The function is used to compute the position in genome according the assigned transcriptom position*/
int pos_ge (char *trans_name, char *pos, char *out_trans);
/*The function is used to test transname*/
int pos_test (char *trans_name, char *ls);
/*Global variable for genome postion*/
char pos_genom[1000];
int main (int argc, char* argv[])
{
int l;
char out_trans[1000], summary_complex[1000];
if(argc>2) {
strcpy(summary_complex, argv[1]);
strcpy(out_trans, argv[2]);
} else {
return -1;
}
l=convert(summary_complex,out_trans);
return (l);
}
int convert (char *summary_complex, char *out_trans)
{
/* j for chracter loop about each row of the methylation_summary-complex file;
read for column loop about each row;
k for character loop about each column;
l for 'for loop';
*/
int k, j, l, read;
/* j1 for chracter loop about the fourth column of the methylation_summary-complex file;
read1 for segment loop about the fourth column of the methylation_summary-complex file;
k1 for character loop about each segment;
*/
int k1, j1, read1;
/*ls[] for each row of the methylation_summary-complex file;
temp[] for each column of the row;
ls1[] for each row of the out_trans file;
*/
char ls[5000], ls1[5000], temp[1000];
/*trans_name[] is for the transcript name;
pre_trans_name[] is for the previous transcript name;
*/
char trans_name[1000], pre_trans_name[1000];
FILE *fcomplex, *fout, *foutls, *ftrans;
if((fcomplex=fopen(summary_complex, "r"))==NULL) {
return -1;
}
if((fout=fopen("methylation_genom", "w"))==NULL) {
return -1;
}
if((ftrans=fopen(out_trans, "r"))==NULL) {
return -1;
}
/*pre_trans_name[] initial value*/
strcpy(pre_trans_name,"pretransname");
/*read each row of the methylation_summary-complex file*/
while(fgets(ls,5000,fcomplex) != NULL) {
k=0;
j=0;
read=0;
memset(temp,0,sizeof(temp));
memset(trans_name,0,sizeof(trans_name));
while(read<5) {
temp[k]=ls[j];
if(ls[j]==' '||ls[j]=='\t'||ls[j]=='\n') {
if(read==0) {
fprintf(fout,"%s",temp);
}
if(read==1) {
fprintf(fout,"%s",temp);
}
if(read==2) {
for(l=0;l<k;l++) {
trans_name[l]=temp[l];
}
fprintf(fout,"%s\t",trans_name);
if(strncmp(temp,pre_trans_name,k)!=0) {
if(strcmp(pre_trans_name,"pretransname")==0) {
for(l=0;l<2;l++) {
if(fgets(ls1,5000,ftrans) == NULL) {
rewind(ftrans);
break;
}
l=pos_test(trans_name,ls1);
}
if((foutls=fopen("out_trans_temp", "w"))==NULL) {
return -1;
}
fprintf(foutls,"%s",ls1);
fclose(foutls);
memset(pre_trans_name,0,sizeof(pre_trans_name));
for(l=0;l<k;l++) {
pre_trans_name[l]=temp[l];
}
} else {
for(l=0;l<2;l++) {
if(fgets(ls1,5000,ftrans) == NULL) {
rewind(ftrans);
break;
}
l=pos_test(trans_name,ls1);
}
if((foutls=fopen("out_trans_temp", "w"))==NULL) {
return -1;
}
fprintf(foutls,"%s",ls1);
fclose(foutls);
memset(pre_trans_name,0,sizeof(pre_trans_name));
for(l=0;l<k;l++) {
pre_trans_name[l]=temp[l];
}
}
}
}
if(read==3) {
memset(pos_genom,0,sizeof(pos_genom));
pos_ge(trans_name,temp,"out_trans_temp");
fprintf(fout,"%s\t",pos_genom);
}
if(read==4) {
fprintf(fout,"%s",temp);
}
memset(temp,0,sizeof(temp));
read=read+1;
k=0;
} else {
k=k+1;
}
j=j+1;
}
}
fclose(fcomplex);
fclose(fout);
fclose(ftrans);
return 0;
}
int pos_ge(char *trans_name, char *pos, char *out_trans) {
/* j for chracter loop about each row of the hits file;
read for column loop about each row;
k for character loop about each column;
l for 'for loop';
*/
int k, j, l, read;
long n1, n2, n3, n4;
/*ls[] for each row of the hits file;
temp[] for each column of the row;
*/
char ls[5000], temp[1000], temp2[1000], temp3[1000], pos_ls[1000];
FILE *fout_trans;
if((fout_trans=fopen(out_trans, "r"))==NULL) {
return -1;
}
memset(pos_ls,0,sizeof(pos_ls));
for(l=0;l<strlen(pos)-1;l++) {
pos_ls[l]=pos[l];
}
n4=0;
while(fgets(ls,5000,fout_trans) != NULL) {
k=0;
j=0;
read=0;
n1=0;
n2=0;
n3=0;
memset(temp,0,sizeof(temp));
memset(temp2,0,sizeof(temp2));
memset(temp3,0,sizeof(temp3));
while(read<1000) {
temp[k]=ls[j];
if(ls[j]==' '||ls[j]=='\t'||ls[j]=='\n') {
if(read==0) {
for(l=0;l<k;l++) {
temp2[l]=temp[l];
}
}
if(read==1) {
if(strncmp(temp,trans_name,strlen(trans_name))!=0) {
break;
}
}
if((read>=2)&&(fmod(read,2)==0)) {
n1=atol(temp);
}
if((read>=2)&&(fmod(read,2)==1)) {
n2=atol(temp);
}
if((n2>=n1)&&(n1>0)) {
n3=n3+(n2-n1)+1;
if(atol(pos_ls)<=n3) {
n4=n2-(n3-atol(pos_ls));
sprintf(temp3,"%ld",n4);
strcat(pos_genom,temp2);
strcat(pos_genom,"-");
strcat(pos_genom,temp3);
break;
}
}
memset(temp,0,sizeof(temp));
read=read+1;
k=0;
} else {
k=k+1;
}
j=j+1;
}
if(n4>0) {
break;
}
}
fclose(fout_trans);
return 0;
}
int pos_test(char *trans_name, char *ls) {
/* j for chracter loop about each row of the hits file;
read for column loop about each row;
k for character loop about each column;
l for 'for loop';
*/
int k, j, l, read;
int n;
/*
temp[] for each column of the row;
*/
char temp[1000];
k=0;
j=0;
read=0;
memset(temp,0,sizeof(temp));
while(read<2) {
temp[k]=ls[j];
if(ls[j]==' '||ls[j]=='\t'||ls[j]=='\n') {
if(read==1) {
if(strncmp(temp,trans_name,strlen(trans_name))==0) {
n=2;
} else {
n=0;
}
}
memset(temp,0,sizeof(temp));
read=read+1;
k=0;
} else {
k=k+1;
}
j=j+1;
}
return n;
}
|
the_stack_data/894890.c
|
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<getopt.h>
#include<sys/stat.h>
void parse_args(int argc, const char **argv);
int exist_file(char *path);
int main(int argc, char **argv){
if (argc != 2){
fprintf(stderr, "usage: cfile [filename]\n");
exit(1);
}
parse_args(argc,argv);
if (exist_file(argv[1])) {
fprintf(stderr, "file exsist!!!\n");
exit(1);
}
FILE *fp;
fp = fopen (argv[1], "a");
fprintf(fp, "#include<stdio.h>\n");
fprintf(fp, "#include<stdlib.h>\n");
fprintf(fp, "#include<string.h>\n\n");
fprintf(fp, "int main(int argc, char **argv){\n\n");
fprintf(fp, "}\n");
fclose(fp);
return 0;
}
void parse_args(int argc, const char **argv){
int o;
struct option s_longopts[] = {
{"help", no_argument, NULL, 'h'},
{0,0,0,0},
};
while ((o = getopt_long(argc, (char * const *)argv, "h", s_longopts, NULL)) != EOF){
switch (o) {
case 'h':
fprintf(stdout, "usage: cfile [filename]\n");
break;
default:
break;
}
}
}
int exist_file(char *path){
struct stat st;
if (stat(path, &st) != 0){
return 0;
}
//return (st.st_mode & S_IFMT) == S_IFREG;
return S_ISREG(st.st_mode);
}
|
the_stack_data/852918.c
|
/* Boxes through a Tunnel */
#include <stdio.h>
#include <stdlib.h>
#define MAX_HEIGHT 41
#define TRUE 1
#define FALSE 0
struct box
{
int length;
int width;
int height;
};
typedef struct box box;
int get_volume(box b) {
int box_volume=(b.length)*(b.width)*(b.height);
return box_volume;
}
int is_lower_than_max_height(box b) {
if(b.height<MAX_HEIGHT)
{
return TRUE;
}
else
{
return FALSE;
}
}
int main()
{
int n;
scanf("%d", &n);
box *boxes = malloc(n * sizeof(box));
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &boxes[i].length, &boxes[i].width, &boxes[i].height);
}
for (int i = 0; i < n; i++) {
if (is_lower_than_max_height(boxes[i])) {
printf("%d\n", get_volume(boxes[i]));
}
}
return 0;
}
|
the_stack_data/27637.c
|
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* The state must be seeded so that it is not everywhere zero. */
uint64_t s[ 2 ];
uint64_t xorshift128plus(void) {
uint64_t s1 = s[ 0 ];
const uint64_t s0 = s[ 1 ];
s[ 0 ] = s0;
s1 ^= s1 << 23;
return ( s[ 1 ] = ( s1 ^ s0 ^ ( s1 >> 17 ) ^ ( s0 >> 26 ) ) ) + s0;
}
int main(int argc, char *argv[]) {
s[0] = 1L;
s[1] = 2L;
uint64_t length = 10;
if (argc > 1) {
length = atoi(argv[1]);
}
if(argc > 3) {
s[0] = atol(argv[2]);
s[1] = atol(argv[3]);
}
printf("[\n");
for (int i = 0; i < length; i++) {
printf(" \"%016llX\"", xorshift128plus());
if (i < length - 1) {
printf(",\n");
}
}
printf("\n]\n");
}
|
the_stack_data/1270832.c
|
#include <stdio.h>
main()
{
printf("hello");
printf("world");
printf("\n");
}
|
the_stack_data/588064.c
|
/*
Code Description :
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations.
It consists of nodes.
A Node has 2 parts ->
i) Data part contains value of the node.
ii) Address part contains the address of the next or the successor node.
Through this C program, Nodes of a linked list are arranged such that the odd and the even nodes are segregated.
Here,all even nodes appear before all the odd nodes in the modified linked list,
keeping the order of even and odd numbers same.
*/
#include <stdio.h>
#include <malloc.h>
/* Defining the structure of a Node */
struct node{
int data; //holds value of temp->data
struct node *next; //holds address of next node after temp
};
/* Header to point to the first node and Last to point to the Last one */
struct node *header, *last;
/* Function for Creation of a Linked List */
void create(){
struct node *temp = (struct node*) malloc(sizeof(struct node));
printf("Enter value of Node: ");
scanf("%d", &temp->data); //assigning value to temp->a
temp->next= NULL;
/* if header is NULL */
if (header == NULL){
header = temp;
last = temp;
return;
}
/* if header is not NULL */
else {
last->next = temp;
last = temp;
return;
}
}
/* Function to Display Nodes of a Linked List */
void show()
{
struct node *temp = header;
while (temp != NULL){
printf("-->%d", temp->data);
temp = temp->next;
}
printf("-->NULL");
}
void segregateEvenOdd()
{
struct node *end_node = last, *prev = NULL, *curr = header;
/* Consider all odd nodes before the first even node and move then after end */
while (curr->data %2 != 0 && curr != end_node)
{
last->next = curr;
curr = curr->next;
last->next->next = NULL;
last = last->next;
}
/* If current node is even */
if (curr->data%2 == 0)
{
/* Change the header to first even node */
header = curr;
while (curr != end_node){
/* if current node is EVEN make prev point to it and update curr node with curr's next */
if ( (curr->data)%2 == 0 ){
prev = curr;
curr = curr->next;
}
/* if current is ODD node */
else{
/* make prev next's point to curr's next */
prev->next = curr->next;
/* Move curr to end of list */
last->next = curr;
/* Make next of curr as NULL */
curr->next = NULL;
/* make curr as last of list */
last = curr;
/* Update current pointer to next of prev (next of node that has been moved to end of last) */
curr = prev->next;
}
}
}
/* If end of original list is odd then set it as last node of modified list*/
if (last!=end_node && (end_node->data)%2 != 0)
{
prev->next = end_node->next;
end_node->next = NULL;
last->next = end_node;
last=end_node;
}
return;
}
/* Driver Function */
void main(){
int i, num;
printf("Enter the number of nodes : "); //ask for user input
scanf("%d", &num);
for (i = 1; i <= num; i++)
create(); //calling create function
printf("\nLinked List is : \n");
show(); //calling show function
segregateEvenOdd(); //calling function to Segregate
printf("\nLinked List after calling SegregateOddEven() : \n");
show(); //calling how function
}
/*
COMPLEXITY:
Space Complexity : O(n)
Time Complexity : O(n)
OUTPUT:
Enter the number of nodes : 7
Enter value of Node: 2
Enter value of Node: 6
Enter value of Node: 3
Enter value of Node: 7
Enter value of Node: 4
Enter value of Node: 9
Enter value of Node: 8
Linked List is :
-->2-->6-->3-->7-->4-->9-->8-->NULL
Linked List after calling SegregateOddEven() :
-->2-->6-->4-->8-->3-->7-->9-->NULL
*/
|
the_stack_data/248580148.c
|
int data[] = { 4, 5, 6 };
int deaddata[] = { 7, 8, 9 };
int func() { return 0; }
int deadfunc() { return 0; }
__attribute__((visibility("default")))
int* foo()
{
return data;
}
__attribute__((visibility("default")))
void* foo2()
{
return func;
}
|
the_stack_data/371310.c
|
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
int compare(const void * x1, const void * x2){
return ( *(int*)x1 - *(int*)x2 );
}
int Intersection(char *a, char *b){
//printf("Intersection!\n");
int i,j,lengtha,lengthb,len=0,len1=0,len3=0;
lengtha=strlen(a);
lengthb=strlen(b);
//printf("%s %s\n",a ,b);
//printf(" %d %d \n",lengtha,lengthb);
if(strcmp(a,b)==0) return 0;
else{
i=lengtha-1;
int k=0;
int z=lengtha-1;
for(j=0;j<lengtha;j++){
if((a[i]==b[k])&&(i<=lengtha-1)){
while((a[i]==b[k])&&(i<=lengtha-1)){
len++;
k++;
i++;
}
}
if((i==lengtha)&&(len>len1)) len1=len;
len=0;
k=0;
z--;
i=z;
}
//printf("len=%d\n",len1);
return len1;
}
}
int main(){
int n,i,j,k;
scanf("%d\n",&n);
char array[n][50];
int Matrix[n][n];
for(i=0;i<n;i++) gets(array[i]);
/*for(i=0;i<n;i++) for(j=0;j<n;j++) Matrix[i][j]=Intersection(array[i],array[j]);
for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ",Matrix[i][j]);
}
printf("\n");
}*/
printf("\n");
for(i=0;i<n;i++) for(j=0;j<n;j++) Matrix[i][j]=Intersection(array[j],array[i]);
/*for(i=0;i<n;i++){
for(j=0;j<n;j++){
printf("%d ",Matrix[i][j]);
}
printf("\n");
}*/
int FullLength=0;
for(i=0;i<n;i++) FullLength+=strlen(array[i]);
//printf("FullLength=%d\n",FullLength);
int Maximums[n];
for(i=0;i<n;i++){
//printf("maxarray!\n");
int MEMi,MEMj,k;
int d,s;
int max=Matrix[0][0];
//printf("max0=%d\n",max);
for (d=0;d<n;d++) for (s=0;s<n;s++) if (Matrix[d][s] > max){
max = Matrix[d][s];
MEMi=d;
MEMj=s;
}
for(k=0;k<n;k++) Matrix[k][MEMj]=0;
for(k=0;k<n;k++) Matrix[MEMi][k]=0;
if(i!=n-1){ FullLength-=max; }
max=0;
}
//qsort(Maximums,n,sizeof(int),compare);
int Minus=0;
for(i=n-1;i>0;i--) Minus+=Maximums[i];
printf("%d\n",FullLength-Minus);
return 0;
}
|
the_stack_data/116604.c
|
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Simple cpu eater busy loop. Runs as a daemon. prints the child PID to
* std so you can easily kill it later.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char *argv[])
{
pid_t pid;
int life_universe_and_everything;
int fd;
switch(fork()) {
case -1:
perror(argv[0]);
exit(1);
break;
case 0: /* child */
chdir("/");
umask(0);
setpgrp();
setsid();
/* fork again to fully detach from controlling terminal. */
switch(pid = fork()) {
case -1:
break;
case 0: /* second child */
/* redirect to /dev/null */
close(0);
open("/dev/null", 0);
close(1);
if(open("/dev/null", O_WRONLY) < 0) {
perror("/dev/null");
exit(1);
}
fflush(stdout);
close(2);
dup(1);
for (fd = 3; fd < 256; fd++) {
close(fd);
}
/* busy looper */
while (1) {
life_universe_and_everything = 42 * 2;
}
default:
/* so caller can easily kill it later. */
printf("%d\n", pid);
exit(0);
break;
}
break;
default:
exit(0);
break;
}
return 0;
}
/* vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab */
|
the_stack_data/131142.c
|
#include <stdio.h>
int main(int argc, char *argv[]) {
int a = sizeof(char),
b = sizeof(int),
c = sizeof(double),
d = sizeof(float);
printf ("Tamanho do char: %i\n", a);
printf ("Tamanho do int: %i\n", b);
printf ("Tamanho do double: %i\n", c);
printf ("Tamanho do float: %i\n", d);
return 0;
}
|
the_stack_data/1188093.c
|
/*This file is written by Meltem Çetiner*/
#include <stdio.h>
#include <stdio.h>
#include <string.h>
typedef enum {Ali, Ayse, Fatma, Mehmet}employee;
typedef enum {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday}day;
#define NUM_EMPLOYEES 4
#define NUM_DAYS 7
#define ENERGIES "Energies.txt"
#define REPORT "report.txt"
void read_matrix(const char* file_name, int m[NUM_EMPLOYEES][NUM_DAYS]);
void create_work_plan(int job_schedule[NUM_EMPLOYEES][NUM_DAYS], int m[NUM_EMPLOYEES][NUM_DAYS]);
int index_sort(const int m[],const int n,int ordinal);
void sort(int* mat1,int* mat2,const int size );
employee find_the_employer_of_the_day(int work_schedule[NUM_EMPLOYEES][NUM_DAYS], day day_name);
employee find_the_employer_of_the_week(int work_schedule[NUM_EMPLOYEES][NUM_DAYS]);
void report(const char* file_name, int job_scheduling[NUM_EMPLOYEES][NUM_DAYS]);
int main()
{
printf("..starting.\n");
int job_energies[NUM_EMPLOYEES][NUM_DAYS], schedule[NUM_EMPLOYEES][NUM_DAYS];
read_matrix(ENERGIES, job_energies);
create_work_plan(schedule, job_energies);
report(REPORT, schedule);
printf("..finishing.\n");
}
void read_matrix(const char* file_name, int m[NUM_EMPLOYEES][NUM_DAYS])
{
day c_day;
employee c_employee; //counters
FILE *inp;
inp = fopen(file_name,"r");
if( inp == NULL)
printf( " The file [ %s ] couldnt be found ..\n", file_name);
else
{
for(c_day=Monday; c_day < NUM_DAYS; c_day++)
{
for( c_employee=Ali; c_employee < NUM_EMPLOYEES; c_employee++)
{
if( fscanf( inp, "%d", &m[c_employee][c_day]) == EOF)
m[c_employee][c_day] = 0;
}
}
}
fclose(inp);
}
void create_work_plan(int job_schedule[NUM_EMPLOYEES][NUM_DAYS], int m[NUM_EMPLOYEES][NUM_DAYS])
{
day c_day;
employee c_employee;
int c_job, counter=0;
int total_energies[NUM_EMPLOYEES]={0,0,0,0};
int daily_works[]={0,0,0,0};
/*initializing*/
for ( c_employee=Ali ; c_employee<NUM_EMPLOYEES ; c_employee++)
{
for( c_day=Monday; c_day<NUM_DAYS; c_day++)
job_schedule[ c_employee ][ c_day ] = 0 ;
daily_works[c_employee] = 0 ;
}
/*filling the job_schedule matrix*/
for( c_day=Monday; c_day<NUM_DAYS; c_day++)
{
for ( c_employee=Ali; c_employee<NUM_EMPLOYEES ; c_employee++)
daily_works[c_employee]=m[c_employee][c_day];
int ordinality[]={ 0 , 1 , 2 , 3};
sort(daily_works,ordinality, NUM_EMPLOYEES);
for ( c_job=0 ; c_job<NUM_EMPLOYEES ; c_job++)
{
int index_employee = index_sort(total_energies,NUM_EMPLOYEES,c_job);
//printf("index %d : \t",index_employee);
job_schedule[ index_employee ][ c_day ] =daily_works[NUM_EMPLOYEES-(c_job+1)];
//printf("job_schedule[ %d ][ %d ] =%d :\n", index_employee , c_day , daily_works[ c_job ] );
}
for ( c_job=0 ; c_job<NUM_EMPLOYEES ; c_job++)
total_energies[ c_job ] += job_schedule[ c_job ][ c_day ] ;
}
}
employee find_the_employer_of_the_day(int work_schedule[NUM_EMPLOYEES][NUM_DAYS], day day_name)
{
int i, max = work_schedule[0][(int)day_name];
employee employee = 0;
for(i=1; i < NUM_EMPLOYEES; i++)
{
if(max < work_schedule[i][(int)day_name])
{
max = work_schedule[i][(int)day_name];
employee = i;
}
}
return employee;
}
employee find_the_employer_of_the_week(int work_schedule[][NUM_DAYS])
{
int i, j, sum, max = -1;
employee employee = 0;
for(i=Ali; i < NUM_EMPLOYEES; i++)
{
sum = 0;
/* find total energy of the employee */
for(j=0; j < NUM_DAYS; j++)
{
sum += work_schedule[i][j];
}
/* compare it to maximum sum value */
if(max < sum)
{
max = sum;
employee = i;
}
}
return employee;
}
void report(const char* file_name, int job_scheduling[][NUM_DAYS])
{
/* I've created strings same order in enumerated types for ease printing. */
char employees[NUM_EMPLOYEES][20] = {"Ali", "Ayse", "Fatma", "Mehmet"};
char days[NUM_DAYS][10] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int i, j, employee;
FILE *output;
output = fopen(file_name, "w");
fprintf(output, "\nReport:\n\n");
fprintf(output, " ");
/* print days to file */
for(i=Monday; i < NUM_DAYS; i++)
{
fprintf(output, " %s", &days[i][0]);
}
fprintf(output, "\n\n");
for(i=Ali; i < NUM_EMPLOYEES; i++)
{
/* print i. employee's name to file */
fprintf(output, "%s", &employees[i][0]);
/* print i. employee's job schedule to file */
for(j=0; j < NUM_DAYS; j++)
{
fprintf(output, " %d", job_scheduling[i][j]);
}
fprintf(output, "\n\n");
}
/* find the most worked employee for each day and print to file */
for(i=Monday; i < NUM_DAYS; i++)
{
employee = find_the_employer_of_the_day(job_scheduling, (day)i);
fprintf(output, "The best employer of %s: %s\n\n", &days[i][0], &employees[(int)employee][0]);
}
/* find the employer of week and print to file */
employee = find_the_employer_of_the_week(job_scheduling);
fprintf(output, "The best employer of week is %s ... Congratulations %s\n\n", &employees[(int)employee][0], &employees[(int)employee][0]);
fclose(output);
}
/* params: this function takes an array m with size n and */
/* an ordinal number */
/* aim : it finds the index of m matrix on ordinal number */
/* returns its index */
/* */
/* for example; we have m[4]={100,60,70,50} */
/* if we call (m,4,2) */
/* it finds 2.biggest number 70 and returns 2 */
/* for another example; */
/* lets say there are some equal numbers and we have */
/* m[4]={100,60,60,50} */
/* if we call (m,4,2) */
/* it finds 2.biggest number 60 and returns 1 */
/* it will returns first finding index */
int index_sort(const int m[],const int n,const int ordinal)
{
int counter;
int sorted_m[n],sorted_index[n];
for( counter=0; counter<n; counter++ )
{
sorted_m[counter] = m[counter];
sorted_index[counter] = counter;
}
sort(sorted_m,sorted_index,n);
return sorted_index[ordinal];
}
/*this function takes two paralel matrices with their size */
/*and sorts both of them from biggest to smallest in sync */
/* */
/*For example; mat1[4]={100,40,60,50} mat2[4]={0,1,2,3} */
/*------------------after sorting-------------------------------*/
/* mat1[4]={100,60,50,40} mat2[4]={0,2,3,1} */
void sort(int* mat1,int* mat2,const int size )
{
int c_a,c_b, temp;
for( c_a=0; c_a<size ; c_a++)
{
for( c_b=(c_a+1) ; c_b<size ; c_b++)
{
if( mat1[c_a] < mat1[c_b])
{
temp = mat1[c_a];
mat1[c_a] = mat1[c_b];
mat1[c_b] = temp;
temp = mat2[c_a];
mat2[c_a] = mat2[c_b];
mat2[c_b] = temp;
}
}
}
}
|
the_stack_data/59511692.c
|
#include <stdio.h>
void main()
{
int num1;
printf("Por favor insira um numero: ");
scanf("%d", &num1);
for (int i = 1; i <= num1; i++)
{
for (int j = 1; j <= i; j++)
{
printf("%d", i);
}
printf("\n");
}
}
|
the_stack_data/154827923.c
|
/* To investigate Example 5.4 on Page 13 of INRIA TR 7560
*
* I designed this example to kill the simple computation of di and
* dj.
*
* Ideally, I could add it to Vivien's ALICe database and compare
* results obtained by the different tools...
*/
int main()
{
int i, j, k, n;
if(i+j==5) {
while(k>0) {
i+=n, j-=n;
k--;
}
}
return 0;
}
|
the_stack_data/150143251.c
|
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[ ])
{
if (symlink(argv[1], argv[2]) == -1) { // 심볼릭 링크 만들기
exit(1);
}
exit(0);
}
|
the_stack_data/212643256.c
|
/*
* Copyright 2016 The Emscripten Authors. All rights reserved.
* Emscripten is available under two separate licenses, the MIT license and the
* University of Illinois/NCSA Open Source License. Both these licenses can be
* found in the LICENSE file.
*/
#include <stdio.h>
#include <stdlib.h>
extern int __cxa_thread_atexit(void (*dtor)(void *), void *obj, void *dso_symbol);
extern int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj, void *dso_symbol);
static void cleanA() { printf("A\n"); }
static void cleanB() { printf("B\n"); }
static void cleanCarg(void* x) { printf("C %d\n", (int)x); }
int main() {
atexit(cleanA);
atexit(cleanB);
__cxa_thread_atexit(cleanCarg, (void*)100, NULL);
__cxa_thread_atexit_impl(cleanCarg, (void*)234, NULL);
return 0;
}
|
the_stack_data/170452954.c
|
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#ifndef CS
#define CS 4098
#endif
#define CacheSZ CS*1024/sizeof(double)
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>
double GetWallTime(void)
{
struct timeval tp;
static long start=0, startu;
if (!start)
{
gettimeofday(&tp, NULL);
start = tp.tv_sec;
startu = tp.tv_usec;
return(0.0);
}
gettimeofday(&tp, NULL);
return( ((double) (tp.tv_sec - start)) + (tp.tv_usec-startu)/1000000.0 );
}
/* Collect multiple timing samples */
#ifndef MT
#define MT 10
#endif
#ifndef RANDSEED
#define RANDSEED 1
#endif
/* Measure the collective performance of multiple invocations */
#ifndef NREP
#define NREP 500
#endif
/* routine to measure performance of*/
void dgemvT(const int M,const int N,const double alpha,const double* A,const int lda,const double* X,const int incX,const double beta,double* Y,const int incY)
;
/* macro for the value of routien parameter */
#ifndef MS
#define MS 72
#endif
/* macro for the value of routien parameter */
#ifndef NS
#define NS 72
#endif
int main(int argc, char **argv)
{
/* arrays for storing results of multiple timings */
double __timer_diff[MT];
/* induction variable for Multiple timing */
int __pt_MT_ivar;
double __timer_min,__timer_avg,__timer_max;
/* induction variable for multiple invocations in a single timing */
int __pt_NREP_ivar;
/* variables to support cache flushing */
double* __pt_flush_buffer;
double __pt_flush_bufferVal;
/* variable for computing MFLOPS */
double __pt_flops;
/* induction variables */
int __pt_i0, __pt_i1, __pt_i2;
/*variables to store starting and ending of timing */
double __timer_begin, __timer_end;
/* Declaring parameters of the routine */
int M;
int N;
double alpha;
double* A;
int lda;
double* X;
int incX;
double beta;
double* Y;
int incY;
double* A_buf;
int A_size, A_rep;
double* X_buf;
int X_size, X_rep;
double* Y_buf;
int Y_size, Y_rep;
/* parameter initializations */
srand(RANDSEED);
M = MS;
N = NS;
alpha = 1;
A_size=M*N;
A_rep=CacheSZ / A_size + 1;
A_buf = calloc(A_size*A_rep, sizeof(double));
lda = MS;
X_size=N;
X_rep=CacheSZ / X_size + 1;
X_buf = calloc(X_size*X_rep, sizeof(double));
incX = 1;
beta = 1;
Y_size=M;
Y_rep=CacheSZ / Y_size + 1;
Y_buf = calloc(Y_size*Y_rep, sizeof(double));
incY = 1;
/* Multiple Timings */
for (__pt_MT_ivar=0; __pt_MT_ivar<MT; ++__pt_MT_ivar) {
srand(RANDSEED);
for (__pt_i0=0; __pt_i0<A_size *A_rep; ++__pt_i0)
{
A_buf[__pt_i0] = rand();;
}
A = A_buf;
for (__pt_i0=0; __pt_i0<X_size *X_rep; ++__pt_i0)
{
X_buf[__pt_i0] = rand();;
}
X = X_buf;
for (__pt_i0=0; __pt_i0<Y_size *Y_rep; ++__pt_i0)
{
Y_buf[__pt_i0] = 1;
}
Y = Y_buf;
/* Timer start */
__timer_begin = GetWallTime();
/* Timing loop */
for (__pt_NREP_ivar=0; __pt_NREP_ivar<NREP; ++__pt_NREP_ivar) {
dgemvT (M,N,alpha,A,lda,X,incX,beta,Y,incY);
if (__pt_i0 < A_rep-1)
A += A_size;
else A = A_buf;
if (__pt_i0 < X_rep-1)
X += X_size;
else X = X_buf;
if (__pt_i0 < Y_rep-1)
Y += Y_size;
else Y = Y_buf;
}
/* Timer end */
__timer_end = GetWallTime();
/* result of a single timing */
__timer_diff[__pt_MT_ivar] = (__timer_end-__timer_begin)/NREP;
}
/* flops of computation */
__pt_flops = 2*M*N+M*N;
/* Compute minimum of multiple timings */
__timer_min=__timer_diff[0];
__timer_max=__timer_diff[0];
__timer_avg=__timer_diff[0];
for (__pt_MT_ivar=1; __pt_MT_ivar<MT; ++__pt_MT_ivar)
{
if (__timer_min > __timer_diff[__pt_MT_ivar])
__timer_min = __timer_diff[__pt_MT_ivar];
if (__timer_max < __timer_diff[__pt_MT_ivar])
__timer_max = __timer_diff[__pt_MT_ivar];
__timer_avg += __timer_diff[__pt_MT_ivar];
}
__timer_avg /= MT;
/* output timing results */
for (__pt_MT_ivar=0; __pt_MT_ivar < MT; ++__pt_MT_ivar)
{
printf("time in seconds [%d]: %.15f\n", __pt_MT_ivar, __timer_diff[__pt_MT_ivar]);
}
printf("Minimum time in seconds: %.15f\n", __timer_min);
printf("Maximum time in seconds: %.15f\n", __timer_max);
printf("Average time in seconds: %.15f\n", __timer_avg);
printf("Maximum MFLOPS: %.15f\n", __pt_flops/__timer_min/1000000);
printf("Minimum MFLOPS: %.15f\n", __pt_flops/__timer_max/1000000);
printf("Average MFLOPS: %.15f\n", __pt_flops/__timer_avg/1000000);
printf("Configuration\n"
"-------------\n");
printf("CPU MHZ: 2160\n");
printf("Cache Size: %d\n", CS);
#ifdef DO_FLUSH
printf("Cache Flush Method: generic\n");
#else
printf("Cache Flush Method: none\n");
#endif
printf("ARCH: generic\n");
printf("nrep: %d\n", NREP);
printf("mt: %d\n", MT);
printf("Random Seed: %d\n", RANDSEED);
return(0);
}
|
the_stack_data/7949386.c
|
int main() {
int a[1000];
int i;
for (i = 0; i < 1000; i++) {
a[i] = i;
}
return a[123];
}
|
the_stack_data/370098.c
|
/*
** EPITECH PROJECT, 2019
** quadtree
** File description:
** calloc
*/
#include <stdlib.h>
#include <string.h>
void *my_calloc(int capacity, int size)
{
void *alloc = malloc(capacity * size);
if (!alloc)
return (NULL);
memset(alloc, -1, capacity * size);
return (alloc);
}
|
the_stack_data/23574371.c
|
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main() {
double mas[100];
double a, x, d, xmin, xmax, maxv, minv;
int c, s, i, counter=0;
char s_s[10], xmin_s[10], xmax_s[10], st[200]={0}, l[100], tmp[100], *key;
do {
printf("Для выхода из программы, введите 0\n");
printf("Формула 1: Рассчет G, введите 1\n");
printf("Формула 2: Рассчет F, введите 2\n");
printf("Формула 3: Рассчет Y, введите 3\n");
scanf("%d", &c);
if (c == 0) {
printf("До свидания!");
break;
}
if ((c < 0) || (c > 3)) {
printf("Неверно введено значение, введите его заново!\n");
scanf("%d", &c);
} else
printf("Введите минимальное значение х: ");
scanf("%s", &xmin_s);
printf("Введите максимальное значение x: ");
scanf("%s", &xmax_s);
fflush(stdin);
xmin = atof(xmin_s);
xmax = atof(xmax_s);
printf("Введите а: ");
scanf("%lf", &a);
if (xmin_s >= xmax_s) {
printf("Максимальное значение х должно быть больше минимального\n");
printf("Введите еще раз х: ");
scanf("%s", &xmax_s);
fflush(stdin);
xmax = atof(xmax_s);
}
printf("Введите колличество шагов: ");
scanf("%s", &s_s);
fflush(stdin);
s = atoi(s_s);
if (s <= 0) {
printf("Число шагов не может быть меньше или равно 0\n");
printf("Введите число шагов еще раз: ");
scanf("%s", &s_s);
fflush(stdin);
}
if (s > 100) {
printf("Допустимое кол-во шагов не должно превышать 100! Введите другое значение.");
break;
}
switch (c) {
case 1: {
for (x = xmin, i = 0;
x <= xmax & i <= s; x += (xmax - xmin) / (s - 1), i++) {
d = (10 * pow(a, 2) + 11 * a * x + 3 * pow(x, 2));
if (d == (10e-6)) {
printf("Введите другие значения \n");
break;
}
mas[i] = (5 * (-2 * pow(a, 2) + a * x + 3 * pow(x, 2))/d);
printf("x = %lf\t", x);
printf("G=%lf\n", mas[i]);
}
break;
case 2: {
for (x = xmin, i = 0; x <= xmax; x += (xmax - xmin) / (s - 1), i++) {
mas[i] = sin(10 * pow(a, 2) - 7 * a * x + pow(x ,2));
printf("x = %0.18lf\t", x);
printf("F= %0.18lf\n", mas[i]);
}
break;
case 3: {
for (x = xmin, i = 0; x <= xmax; x += (xmax - xmin) / (s - 1), i++) {
mas[i] = atan(45 * pow(a, 2) + 79 * a * x + 30 * pow(x, 2));
printf("x = %lf\t", x);
printf("Y= %lf\n", mas[i]);
}
break;
}
}
}
}
for(i = 0;i <= s;i++) {
sprintf(l, "%lf", mas[i]);
strcat(st, l);
}
printf("Result = %s\n", st);
for (i = 0, minv = mas[0], maxv = mas[0]; i < s; i++) {
if (mas[i] > maxv)
maxv = mas[i];
if (mas[i] < minv)
minv = mas[i];
}
printf("Макс. значение: %0.18lf\n", maxv);
printf("Мин. значение: %0.18lf\n", minv);
printf("Введите шаблон: \n");
scanf("%s", &tmp);
key = strstr(st, tmp);
while(key) {
sprintf(st, key +1);
counter++;
key = strstr(st, tmp);
}
printf("%d\n", counter);
} while (c != 0);
return 0;
}
|
the_stack_data/43886580.c
|
#include <stdio.h>
void scilab_rt_bar_d0i0d0_(double scalarin0,
int scalarin1,
double scalarin2)
{
printf("%f", scalarin0);
printf("%d", scalarin1);
printf("%f", scalarin2);
}
|
the_stack_data/220455500.c
|
// Regression test. Previously Clang just returned the library name instead
// of the full path.
// RUN: %clang -print-file-name=libclang_rt.osx.a --target=x86_64-apple-darwin20.3.0 \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
// RUN: %clang -print-file-name=libclang_rt.osx.a --target=x86_64-apple-macosx11.0.0 \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR %s
// PRINT-RUNTIME-DIR: lib{{/|\\}}darwin{{/|\\}}libclang_rt.osx.a
// RUN: %clang -print-file-name=libclang_rt.ios.a --target=arm64-apple-ios14.0.0 \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-IOS %s
// PRINT-RUNTIME-DIR-IOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.ios.a
// RUN: %clang -print-file-name=libclang_rt.tvos.a --target=arm64-apple-tvos14.0.0 \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-TVOS %s
// PRINT-RUNTIME-DIR-TVOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.tvos.a
// RUN: %clang -print-file-name=libclang_rt.watchos.a --target=arm64-apple-watchos5.0.0 \
// RUN: -resource-dir=%S/Inputs/resource_dir \
// RUN: | FileCheck --check-prefix=PRINT-RUNTIME-DIR-WATCHOS %s
// PRINT-RUNTIME-DIR-WATCHOS: lib{{/|\\}}darwin{{/|\\}}libclang_rt.watchos.a
|
the_stack_data/161080763.c
|
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Strip Android-specific records out of hprof data, back-converting from
* 1.0.3 to 1.0.2. This removes some useful information, but allows
* Android hprof data to be handled by widely-available tools (like "jhat").
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include <assert.h>
//#define VERBOSE_DEBUG
#ifdef VERBOSE_DEBUG
# define DBUG(...) fprintf(stderr, __VA_ARGS__)
#else
# define DBUG(...)
#endif
#ifndef FALSE
# define FALSE 0
# define TRUE (!FALSE)
#endif
typedef enum HprofBasicType {
HPROF_BASIC_OBJECT = 2,
HPROF_BASIC_BOOLEAN = 4,
HPROF_BASIC_CHAR = 5,
HPROF_BASIC_FLOAT = 6,
HPROF_BASIC_DOUBLE = 7,
HPROF_BASIC_BYTE = 8,
HPROF_BASIC_SHORT = 9,
HPROF_BASIC_INT = 10,
HPROF_BASIC_LONG = 11,
} HprofBasicType;
typedef enum HprofTag {
/* tags we must handle specially */
HPROF_TAG_HEAP_DUMP = 0x0c,
HPROF_TAG_HEAP_DUMP_SEGMENT = 0x1c,
} HprofTag;
typedef enum HprofHeapTag {
/* 1.0.2 tags */
HPROF_ROOT_UNKNOWN = 0xff,
HPROF_ROOT_JNI_GLOBAL = 0x01,
HPROF_ROOT_JNI_LOCAL = 0x02,
HPROF_ROOT_JAVA_FRAME = 0x03,
HPROF_ROOT_NATIVE_STACK = 0x04,
HPROF_ROOT_STICKY_CLASS = 0x05,
HPROF_ROOT_THREAD_BLOCK = 0x06,
HPROF_ROOT_MONITOR_USED = 0x07,
HPROF_ROOT_THREAD_OBJECT = 0x08,
HPROF_CLASS_DUMP = 0x20,
HPROF_INSTANCE_DUMP = 0x21,
HPROF_OBJECT_ARRAY_DUMP = 0x22,
HPROF_PRIMITIVE_ARRAY_DUMP = 0x23,
/* Android 1.0.3 tags */
HPROF_HEAP_DUMP_INFO = 0xfe,
HPROF_ROOT_INTERNED_STRING = 0x89,
HPROF_ROOT_FINALIZING = 0x8a,
HPROF_ROOT_DEBUGGER = 0x8b,
HPROF_ROOT_REFERENCE_CLEANUP = 0x8c,
HPROF_ROOT_VM_INTERNAL = 0x8d,
HPROF_ROOT_JNI_MONITOR = 0x8e,
HPROF_UNREACHABLE = 0x90, /* deprecated */
HPROF_PRIMITIVE_ARRAY_NODATA_DUMP = 0xc3,
} HprofHeapTag;
#define kIdentSize 4
#define kRecHdrLen 9
/*
* ===========================================================================
* Expanding buffer
* ===========================================================================
*/
/* simple struct */
typedef struct {
unsigned char* storage;
size_t curLen;
size_t maxLen;
} ExpandBuf;
/*
* Create an ExpandBuf.
*/
static ExpandBuf* ebAlloc(void)
{
static const int kInitialSize = 64;
ExpandBuf* newBuf = (ExpandBuf*) malloc(sizeof(ExpandBuf));
if (newBuf == NULL)
return NULL;
newBuf->storage = (unsigned char*) malloc(kInitialSize);
newBuf->curLen = 0;
newBuf->maxLen = kInitialSize;
return newBuf;
}
/*
* Release the storage associated with an ExpandBuf.
*/
static void ebFree(ExpandBuf* pBuf)
{
if (pBuf != NULL) {
free(pBuf->storage);
free(pBuf);
}
}
/*
* Return a pointer to the data buffer.
*
* The pointer may change as data is added to the buffer, so this value
* should not be cached.
*/
static inline unsigned char* ebGetBuffer(ExpandBuf* pBuf)
{
return pBuf->storage;
}
/*
* Get the amount of data currently in the buffer.
*/
static inline size_t ebGetLength(ExpandBuf* pBuf)
{
return pBuf->curLen;
}
/*
* Empty the buffer.
*/
static void ebClear(ExpandBuf* pBuf)
{
pBuf->curLen = 0;
}
/*
* Ensure that the buffer can hold at least "size" additional bytes.
*/
static int ebEnsureCapacity(ExpandBuf* pBuf, int size)
{
assert(size > 0);
if (pBuf->curLen + size > pBuf->maxLen) {
int newSize = pBuf->curLen + size + 128; /* oversize slightly */
unsigned char* newStorage = realloc(pBuf->storage, newSize);
if (newStorage == NULL) {
fprintf(stderr, "ERROR: realloc failed on size=%d\n", newSize);
return -1;
}
pBuf->storage = newStorage;
pBuf->maxLen = newSize;
}
assert(pBuf->curLen + size <= pBuf->maxLen);
return 0;
}
/*
* Add data to the buffer after ensuring it can hold it.
*/
static int ebAddData(ExpandBuf* pBuf, const void* data, size_t count)
{
ebEnsureCapacity(pBuf, count);
memcpy(pBuf->storage + pBuf->curLen, data, count);
pBuf->curLen += count;
return 0;
}
/*
* Read a NULL-terminated string from the input.
*/
static int ebReadString(ExpandBuf* pBuf, FILE* in)
{
int ic;
do {
ebEnsureCapacity(pBuf, 1);
ic = getc(in);
if (feof(in) || ferror(in)) {
fprintf(stderr, "ERROR: failed reading input\n");
return -1;
}
pBuf->storage[pBuf->curLen++] = (unsigned char) ic;
} while (ic != 0);
return 0;
}
/*
* Read some data, adding it to the expanding buffer.
*
* This will ensure that the buffer has enough space to hold the new data
* (plus the previous contents).
*/
static int ebReadData(ExpandBuf* pBuf, FILE* in, size_t count, int eofExpected)
{
size_t actual;
assert(count > 0);
ebEnsureCapacity(pBuf, count);
actual = fread(pBuf->storage + pBuf->curLen, 1, count, in);
if (actual != count) {
if (eofExpected && feof(in) && !ferror(in)) {
/* return without reporting an error */
} else {
fprintf(stderr, "ERROR: read %d of %d bytes\n", actual, count);
return -1;
}
}
pBuf->curLen += count;
assert(pBuf->curLen <= pBuf->maxLen);
return 0;
}
/*
* Write the data from the buffer. Resets the data count to zero.
*/
static int ebWriteData(ExpandBuf* pBuf, FILE* out)
{
size_t actual;
assert(pBuf->curLen > 0);
assert(pBuf->curLen <= pBuf->maxLen);
actual = fwrite(pBuf->storage, 1, pBuf->curLen, out);
if (actual != pBuf->curLen) {
fprintf(stderr, "ERROR: write %d of %d bytes\n", actual, pBuf->curLen);
return -1;
}
pBuf->curLen = 0;
return 0;
}
/*
* ===========================================================================
* Hprof stuff
* ===========================================================================
*/
/*
* Get a 2-byte value, in big-endian order, from memory.
*/
static uint16_t get2BE(const unsigned char* buf)
{
uint16_t val;
val = (buf[0] << 8) | buf[1];
return val;
}
/*
* Get a 4-byte value, in big-endian order, from memory.
*/
static uint32_t get4BE(const unsigned char* buf)
{
uint32_t val;
val = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
return val;
}
/*
* Set a 4-byte value, in big-endian order.
*/
static void set4BE(unsigned char* buf, uint32_t val)
{
buf[0] = val >> 24;
buf[1] = val >> 16;
buf[2] = val >> 8;
buf[3] = val;
}
/*
* Get the size, in bytes, of one of the "basic types".
*/
static int computeBasicLen(HprofBasicType basicType)
{
static const int sizes[] = { -1, -1, 4, -1, 1, 2, 4, 8, 1, 2, 4, 8 };
static const size_t maxSize = sizeof(sizes) / sizeof(sizes[0]);
assert(basicType >= 0);
if (basicType >= maxSize)
return -1;
return sizes[basicType];
}
/*
* Compute the length of a HPROF_CLASS_DUMP block.
*/
static int computeClassDumpLen(const unsigned char* origBuf, int len)
{
const unsigned char* buf = origBuf;
int blockLen = 0;
int i, count;
blockLen += kIdentSize * 7 + 8;
buf += blockLen;
len -= blockLen;
if (len < 0)
return -1;
count = get2BE(buf);
buf += 2;
len -= 2;
DBUG("CDL: 1st count is %d\n", count);
for (i = 0; i < count; i++) {
HprofBasicType basicType;
int basicLen;
basicType = buf[2];
basicLen = computeBasicLen(basicType);
if (basicLen < 0) {
DBUG("ERROR: invalid basicType %d\n", basicType);
return -1;
}
buf += 2 + 1 + basicLen;
len -= 2 + 1 + basicLen;
if (len < 0)
return -1;
}
count = get2BE(buf);
buf += 2;
len -= 2;
DBUG("CDL: 2nd count is %d\n", count);
for (i = 0; i < count; i++) {
HprofBasicType basicType;
int basicLen;
basicType = buf[kIdentSize];
basicLen = computeBasicLen(basicType);
if (basicLen < 0) {
fprintf(stderr, "ERROR: invalid basicType %d\n", basicType);
return -1;
}
buf += kIdentSize + 1 + basicLen;
len -= kIdentSize + 1 + basicLen;
if (len < 0)
return -1;
}
count = get2BE(buf);
buf += 2;
len -= 2;
DBUG("CDL: 3rd count is %d\n", count);
for (i = 0; i < count; i++) {
buf += kIdentSize + 1;
len -= kIdentSize + 1;
if (len < 0)
return -1;
}
DBUG("Total class dump len: %d\n", buf - origBuf);
return buf - origBuf;
}
/*
* Compute the length of a HPROF_INSTANCE_DUMP block.
*/
static int computeInstanceDumpLen(const unsigned char* origBuf, int len)
{
int extraCount = get4BE(origBuf + kIdentSize * 2 + 4);
return kIdentSize * 2 + 8 + extraCount;
}
/*
* Compute the length of a HPROF_OBJECT_ARRAY_DUMP block.
*/
static int computeObjectArrayDumpLen(const unsigned char* origBuf, int len)
{
int arrayCount = get4BE(origBuf + kIdentSize + 4);
return kIdentSize * 2 + 8 + arrayCount * kIdentSize;
}
/*
* Compute the length of a HPROF_PRIMITIVE_ARRAY_DUMP block.
*/
static int computePrimitiveArrayDumpLen(const unsigned char* origBuf, int len)
{
int arrayCount = get4BE(origBuf + kIdentSize + 4);
HprofBasicType basicType = origBuf[kIdentSize + 8];
int basicLen = computeBasicLen(basicType);
return kIdentSize + 9 + arrayCount * basicLen;
}
/*
* Crunch through a heap dump record, writing the original or converted
* data to "out".
*/
static int processHeapDump(ExpandBuf* pBuf, FILE* out)
{
ExpandBuf* pOutBuf = ebAlloc();
unsigned char* origBuf = ebGetBuffer(pBuf);
unsigned char* buf = origBuf;
int len = ebGetLength(pBuf);
int result = -1;
pBuf = NULL; /* we just use the raw pointer from here forward */
/* copy the original header to the output buffer */
if (ebAddData(pOutBuf, buf, kRecHdrLen) != 0)
goto bail;
buf += kRecHdrLen; /* skip past record header */
len -= kRecHdrLen;
while (len > 0) {
unsigned char subType = buf[0];
int justCopy = TRUE;
int subLen;
DBUG("--- 0x%02x ", subType);
switch (subType) {
/* 1.0.2 types */
case HPROF_ROOT_UNKNOWN:
subLen = kIdentSize;
break;
case HPROF_ROOT_JNI_GLOBAL:
subLen = kIdentSize * 2;
break;
case HPROF_ROOT_JNI_LOCAL:
subLen = kIdentSize + 8;
break;
case HPROF_ROOT_JAVA_FRAME:
subLen = kIdentSize + 8;
break;
case HPROF_ROOT_NATIVE_STACK:
subLen = kIdentSize + 4;
break;
case HPROF_ROOT_STICKY_CLASS:
subLen = kIdentSize;
break;
case HPROF_ROOT_THREAD_BLOCK:
subLen = kIdentSize + 4;
break;
case HPROF_ROOT_MONITOR_USED:
subLen = kIdentSize;
break;
case HPROF_ROOT_THREAD_OBJECT:
subLen = kIdentSize + 8;
break;
case HPROF_CLASS_DUMP:
subLen = computeClassDumpLen(buf+1, len-1);
break;
case HPROF_INSTANCE_DUMP:
subLen = computeInstanceDumpLen(buf+1, len-1);
break;
case HPROF_OBJECT_ARRAY_DUMP:
subLen = computeObjectArrayDumpLen(buf+1, len-1);
break;
case HPROF_PRIMITIVE_ARRAY_DUMP:
subLen = computePrimitiveArrayDumpLen(buf+1, len-1);
break;
/* these were added for Android in 1.0.3 */
case HPROF_HEAP_DUMP_INFO:
justCopy = FALSE;
subLen = kIdentSize + 4;
// no 1.0.2 equivalent for this
break;
case HPROF_ROOT_INTERNED_STRING:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_ROOT_FINALIZING:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_ROOT_DEBUGGER:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_ROOT_REFERENCE_CLEANUP:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_ROOT_VM_INTERNAL:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_ROOT_JNI_MONITOR:
/* keep the ident, drop the next 8 bytes */
buf[0] = HPROF_ROOT_UNKNOWN;
justCopy = FALSE;
ebAddData(pOutBuf, buf, 1 + kIdentSize);
subLen = kIdentSize + 8;
break;
case HPROF_UNREACHABLE:
buf[0] = HPROF_ROOT_UNKNOWN;
subLen = kIdentSize;
break;
case HPROF_PRIMITIVE_ARRAY_NODATA_DUMP:
buf[0] = HPROF_PRIMITIVE_ARRAY_DUMP;
buf[5] = buf[6] = buf[7] = buf[8] = 0; /* set array len to 0 */
subLen = kIdentSize + 9;
break;
/* shouldn't get here */
default:
fprintf(stderr, "ERROR: unexpected subtype 0x%02x at offset %d\n",
subType, buf - origBuf);
goto bail;
}
if (justCopy) {
/* copy source data */
DBUG("(%d)\n", 1 + subLen);
ebAddData(pOutBuf, buf, 1 + subLen);
} else {
/* other data has been written, or the sub-record omitted */
DBUG("(adv %d)\n", 1 + subLen);
}
/* advance to next entry */
buf += 1 + subLen;
len -= 1 + subLen;
}
/*
* Update the record length.
*/
set4BE(ebGetBuffer(pOutBuf) + 5, ebGetLength(pOutBuf) - kRecHdrLen);
if (ebWriteData(pOutBuf, out) != 0)
goto bail;
result = 0;
bail:
ebFree(pOutBuf);
return result;
}
/*
* Filter an hprof data file.
*/
static int filterData(FILE* in, FILE* out)
{
const char *magicString;
ExpandBuf* pBuf;
int result = -1;
pBuf = ebAlloc();
if (pBuf == NULL)
goto bail;
/*
* Start with the header.
*/
if (ebReadString(pBuf, in) != 0)
goto bail;
magicString = (const char*)ebGetBuffer(pBuf);
if (strcmp(magicString, "JAVA PROFILE 1.0.3") != 0) {
if (strcmp(magicString, "JAVA PROFILE 1.0.2") == 0) {
fprintf(stderr, "ERROR: HPROF file already in 1.0.2 format.\n");
} else {
fprintf(stderr, "ERROR: expecting HPROF file format 1.0.3\n");
}
goto bail;
}
/* downgrade to 1.0.2 */
(ebGetBuffer(pBuf))[17] = '2';
if (ebWriteData(pBuf, out) != 0)
goto bail;
/*
* Copy:
* (4b) identifier size, always 4
* (8b) file creation date
*/
if (ebReadData(pBuf, in, 12, FALSE) != 0)
goto bail;
if (ebWriteData(pBuf, out) != 0)
goto bail;
/*
* Read records until we hit EOF. Each record begins with:
* (1b) type
* (4b) timestamp
* (4b) length of data that follows
*/
while (1) {
assert(ebGetLength(pBuf) == 0);
/* read type char */
if (ebReadData(pBuf, in, 1, TRUE) != 0)
goto bail;
if (feof(in))
break;
/* read the rest of the header */
if (ebReadData(pBuf, in, kRecHdrLen-1, FALSE) != 0)
goto bail;
unsigned char* buf = ebGetBuffer(pBuf);
unsigned char type;
unsigned int timestamp, length;
type = buf[0];
timestamp = get4BE(buf + 1);
length = get4BE(buf + 5);
buf = NULL; /* ptr invalid after next read op */
/* read the record data */
if (length != 0) {
if (ebReadData(pBuf, in, length, FALSE) != 0)
goto bail;
}
if (type == HPROF_TAG_HEAP_DUMP ||
type == HPROF_TAG_HEAP_DUMP_SEGMENT)
{
DBUG("Processing heap dump 0x%02x (%d bytes)\n",
type, length);
if (processHeapDump(pBuf, out) != 0)
goto bail;
ebClear(pBuf);
} else {
/* keep */
DBUG("Keeping 0x%02x (%d bytes)\n", type, length);
if (ebWriteData(pBuf, out) != 0)
goto bail;
}
}
result = 0;
bail:
ebFree(pBuf);
return result;
}
/*
* Get args.
*/
int main(int argc, char** argv)
{
FILE* in = stdin;
FILE* out = stdout;
int cc;
if (argc != 3) {
fprintf(stderr, "Usage: hprof-conf infile outfile\n\n");
fprintf(stderr,
"Specify '-' for either or both to use stdin/stdout.\n\n");
fprintf(stderr,
"Copyright (C) 2009 The Android Open Source Project\n\n"
"This software is built from source code licensed under the "
"Apache License,\n"
"Version 2.0 (the \"License\"). You may obtain a copy of the "
"License at\n\n"
" http://www.apache.org/licenses/LICENSE-2.0\n\n"
"See the associated NOTICE file for this software for further "
"details.\n");
return 2;
}
if (strcmp(argv[1], "-") != 0) {
in = fopen(argv[1], "rb");
if (in == NULL) {
fprintf(stderr, "ERROR: failed to open input '%s': %s\n",
argv[1], strerror(errno));
return 1;
}
}
if (strcmp(argv[2], "-") != 0) {
out = fopen(argv[2], "wb");
if (out == NULL) {
fprintf(stderr, "ERROR: failed to open output '%s': %s\n",
argv[2], strerror(errno));
if (in != stdin)
fclose(in);
return 1;
}
}
cc = filterData(in, out);
if (in != stdin)
fclose(in);
if (out != stdout)
fclose(out);
return (cc != 0);
}
|
the_stack_data/654013.c
|
/*
* http-dump: permite inspecionar comandos http enviados a um servidor web por um navegador qualquer
*
* Profs. Eleri Cardozo e Marco A. A. Henriques
*
*/
/*
* Arquivos a incluir com cabeçalhos e definições
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
/*
* Programa principal
*/
main(arg_cont, arg_valor)
int arg_cont;
char **arg_valor;
{
unsigned short porta; /* porta a se conectar no servidor */
char area[1024]; /* area para envio e recebimento de dados */
struct sockaddr_in cliente; /* estrutura de informações sobre os clientes */
struct sockaddr_in servidor; /* estrutura de informações sobre o servidor */
int soquete; /* soquete para aceitação de pedidos de conexão */
int novo_soquete; /* soquete de conexão aos clientes */
int nome_compr; /* comprimento do nome de um cliente */
int mensagem_compr; /* comprimento da mensagem recebida */
int i;
/*
* Verifique os argumentos. Deve haver apenas um: o número da porta a se conectar.
*/
if (arg_cont != 2)
{
fprintf(stderr, "Uso: %s número_da_porta\n", arg_valor[0]);
exit(1);
}
/*
* Primeiro argumento deve ser o número da porta.
*/
porta = (unsigned short) atoi(arg_valor[1]);
/*
* Crie um soquete para aceitar pedidos de conexão.
*/
if ((soquete = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
perror("Erro em socket()");
exit(2);
}
/*
* Ligue o soquete ao endereço do servidor.
*/
servidor.sin_family = AF_INET;
servidor.sin_port = htons(porta);
servidor.sin_addr.s_addr = INADDR_ANY;
if (bind(soquete, (struct sockaddr *)&servidor, sizeof(servidor)) < 0)
{
perror("Erro em bind().\n");
exit(3);
}
/*
* Aguarde por pedidos de conexão com um fila de até 5 pedidos.
*/
if (listen(soquete, 5) != 0)
{
perror("Erro em listen().\n");
exit(4);
}
/*
* Entre em laço infinito
*/
printf("\n%s já está aceitando conexões de clientes HTTP.\n", arg_valor[0]);
fflush(stdout);
while (1) {
/*
* Aceite um pedido de conexão.
*/
nome_compr = sizeof(cliente);
if ((novo_soquete = accept(soquete, (struct sockaddr *)&cliente, &nome_compr)) == -1)
{
perror("Erro em accept().\n");
break;
}
/*
* Receba a mensagem no novo soquete.
*/
if ((mensagem_compr = recv(novo_soquete, area, sizeof(area), 0)) == -1)
{
perror("Erro em recv().\n");
break;
}
/*
* Imprima o que recebeu e feche a conexão.
*/
printf("\nMensagem recebida:\n");
for(i = 0; i < mensagem_compr; i++) printf("%c", area[i]);
fflush(stdout);
close(novo_soquete);
} /* Laço termina aqui */
close(soquete);
printf("O servidor terminou com erro.\n");
exit(5);
}
|
the_stack_data/115994.c
|
void XtAddActions() {} ;
void XtAddCallback() {} ;
void XtAddCallbacks() {} ;
void XtAddConverter() {} ;
void XtAddEventHandler() {} ;
void XtAddExposureToRegion() {} ;
void XtAddGrab() {} ;
void XtAddInput() {} ;
void XtAddRawEventHandler() {} ;
void XtAddSignal() {} ;
void XtAddTimeOut() {} ;
void XtAddWorkProc() {} ;
void XtAllocateGC() {} ;
void XtAppAddActionHook() {} ;
void XtAppAddActions() {} ;
void XtAppAddBlockHook() {} ;
void XtAppAddConverter() {} ;
void XtAppAddInput() {} ;
void XtAppAddSignal() {} ;
void XtAppAddTimeOut() {} ;
void XtAppAddWorkProc() {} ;
void XtAppCreateShell() {} ;
void XtAppError() {} ;
void XtAppErrorMsg() {} ;
void XtAppGetErrorDatabase() {} ;
void XtAppGetErrorDatabaseText() {} ;
void XtAppGetExitFlag() {} ;
void XtAppGetSelectionTimeout() {} ;
void XtAppInitialize() {} ;
void XtAppLock() {} ;
void XtAppMainLoop() {} ;
void XtAppNextEvent() {} ;
void XtAppPeekEvent() {} ;
void XtAppPending() {} ;
void XtAppProcessEvent() {} ;
void XtAppReleaseCacheRefs() {} ;
void XtAppSetErrorHandler() {} ;
void XtAppSetErrorMsgHandler() {} ;
void XtAppSetExitFlag() {} ;
void XtAppSetFallbackResources() {} ;
void XtAppSetSelectionTimeout() {} ;
void XtAppSetTypeConverter() {} ;
void XtAppSetWarningHandler() {} ;
void XtAppSetWarningMsgHandler() {} ;
void XtAppUnlock() {} ;
void XtAppWarning() {} ;
void XtAppWarningMsg() {} ;
void XtAugmentTranslations() {} ;
void XtBuildEventMask() {} ;
void XtCallAcceptFocus() {} ;
void XtCallActionProc() {} ;
void XtCallCallbackList() {} ;
void XtCallCallbacks() {} ;
void XtCallConverter() {} ;
void XtCallbackExclusive() {} ;
void XtCallbackNone() {} ;
void XtCallbackNonexclusive() {} ;
void XtCallbackPopdown() {} ;
void XtCallbackReleaseCacheRef() {} ;
void XtCallbackReleaseCacheRefList() {} ;
void XtCalloc() {} ;
void XtCancelSelectionRequest() {} ;
void XtChangeManagedSet() {} ;
void XtClass() {} ;
void XtCloseDisplay() {} ;
void XtConfigureWidget() {} ;
void XtConvert() {} ;
void XtConvertAndStore() {} ;
void XtConvertCase() {} ;
void XtCreateApplicationContext() {} ;
void XtCreateApplicationShell() {} ;
void XtCreateManagedWidget() {} ;
void XtCreatePopupShell() {} ;
void XtCreateSelectionRequest() {} ;
void XtCreateWidget() {} ;
void XtCreateWindow() {} ;
void XtCvtColorToPixel() {} ;
void XtCvtIntToBool() {} ;
void XtCvtIntToBoolean() {} ;
void XtCvtIntToColor() {} ;
void XtCvtIntToFloat() {} ;
void XtCvtIntToFont() {} ;
void XtCvtIntToPixel() {} ;
void XtCvtIntToPixmap() {} ;
void XtCvtIntToShort() {} ;
void XtCvtIntToUnsignedChar() {} ;
void XtCvtStringToAcceleratorTable() {} ;
void XtCvtStringToAtom() {} ;
void XtCvtStringToBool() {} ;
void XtCvtStringToBoolean() {} ;
void XtCvtStringToCommandArgArray() {} ;
void XtCvtStringToCursor() {} ;
void XtCvtStringToDimension() {} ;
void XtCvtStringToDirectoryString() {} ;
void XtCvtStringToDisplay() {} ;
void XtCvtStringToFile() {} ;
void XtCvtStringToFloat() {} ;
void XtCvtStringToFont() {} ;
void XtCvtStringToFontSet() {} ;
void XtCvtStringToFontStruct() {} ;
void XtCvtStringToGravity() {} ;
void XtCvtStringToInitialState() {} ;
void XtCvtStringToInt() {} ;
void XtCvtStringToPixel() {} ;
void XtCvtStringToRestartStyle() {} ;
void XtCvtStringToShort() {} ;
void XtCvtStringToTranslationTable() {} ;
void XtCvtStringToUnsignedChar() {} ;
void XtCvtStringToVisual() {} ;
void XtDatabase() {} ;
void XtDestroyApplicationContext() {} ;
void XtDestroyGC() {} ;
void XtDestroyWidget() {} ;
void XtDirectConvert() {} ;
void XtDisownSelection() {} ;
void XtDispatchEvent() {} ;
void XtDispatchEventToWidget() {} ;
void XtDisplay() {} ;
void XtDisplayInitialize() {} ;
void XtDisplayOfObject() {} ;
void XtDisplayStringConversionWarning() {} ;
void XtDisplayToApplicationContext() {} ;
void XtError() {} ;
void XtErrorMsg() {} ;
void XtFindFile() {} ;
void XtFree() {} ;
void XtGetActionKeysym() {} ;
void XtGetActionList() {} ;
void XtGetApplicationNameAndClass() {} ;
void XtGetApplicationResources() {} ;
void XtGetClassExtension() {} ;
void XtGetConstraintResourceList() {} ;
void XtGetDisplays() {} ;
void XtGetErrorDatabase() {} ;
void XtGetErrorDatabaseText() {} ;
void XtGetGC() {} ;
void XtGetKeyboardFocusWidget() {} ;
void XtGetKeysymTable() {} ;
void XtGetMultiClickTime() {} ;
void XtGetResourceList() {} ;
void XtGetSelectionParameters() {} ;
void XtGetSelectionRequest() {} ;
void XtGetSelectionTimeout() {} ;
void XtGetSelectionValue() {} ;
void XtGetSelectionValueIncremental() {} ;
void XtGetSelectionValues() {} ;
void XtGetSelectionValuesIncremental() {} ;
void XtGetSubresources() {} ;
void XtGetSubvalues() {} ;
void XtGetValues() {} ;
void XtGrabButton() {} ;
void XtGrabKey() {} ;
void XtGrabKeyboard() {} ;
void XtGrabPointer() {} ;
void XtHasCallbacks() {} ;
void XtHooksOfDisplay() {} ;
void XtInitialize() {} ;
void XtInitializeWidgetClass() {} ;
void XtInsertEventHandler() {} ;
void XtInsertEventTypeHandler() {} ;
void XtInsertRawEventHandler() {} ;
void XtInstallAccelerators() {} ;
void XtInstallAllAccelerators() {} ;
void XtIsApplicationShell() {} ;
void XtIsComposite() {} ;
void XtIsConstraint() {} ;
void XtIsManaged() {} ;
void XtIsObject() {} ;
void XtIsOverrideShell() {} ;
void XtIsRealized() {} ;
void XtIsRectObj() {} ;
void XtIsSensitive() {} ;
void XtIsSessionShell() {} ;
void XtIsShell() {} ;
void XtIsSubclass() {} ;
void XtIsTopLevelShell() {} ;
void XtIsTransientShell() {} ;
void XtIsVendorShell() {} ;
void XtIsWMShell() {} ;
void XtIsWidget() {} ;
void XtKeysymToKeycodeList() {} ;
void XtLastEventProcessed() {} ;
void XtLastTimestampProcessed() {} ;
void XtMainLoop() {} ;
void XtMakeGeometryRequest() {} ;
void XtMakeResizeRequest() {} ;
void XtMalloc() {} ;
void XtManageChild() {} ;
void XtManageChildren() {} ;
void XtMapWidget() {} ;
void XtMenuPopupAction() {} ;
void XtMergeArgLists() {} ;
void XtMoveWidget() {} ;
void XtName() {} ;
void XtNameToWidget() {} ;
void XtNewString() {} ;
void XtNextEvent() {} ;
void XtNoticeSignal() {} ;
void XtOpenApplication() {} ;
void XtOpenDisplay() {} ;
void XtOverrideTranslations() {} ;
void XtOwnSelection() {} ;
void XtOwnSelectionIncremental() {} ;
void XtParent() {} ;
void XtParseAcceleratorTable() {} ;
void XtParseTranslationTable() {} ;
void XtPeekEvent() {} ;
void XtPending() {} ;
void XtPopdown() {} ;
void XtPopup() {} ;
void XtPopupSpringLoaded() {} ;
void XtProcessEvent() {} ;
void XtProcessLock() {} ;
void XtProcessUnlock() {} ;
void XtQueryGeometry() {} ;
void XtRealizeWidget() {} ;
void XtRealloc() {} ;
void XtRegisterCaseConverter() {} ;
void XtRegisterDrawable() {} ;
void XtRegisterExtensionSelector() {} ;
void XtRegisterGrabAction() {} ;
void XtReleaseGC() {} ;
void XtReleasePropertyAtom() {} ;
void XtRemoveActionHook() {} ;
void XtRemoveAllCallbacks() {} ;
void XtRemoveBlockHook() {} ;
void XtRemoveCallback() {} ;
void XtRemoveCallbacks() {} ;
void XtRemoveEventHandler() {} ;
void XtRemoveEventTypeHandler() {} ;
void XtRemoveGrab() {} ;
void XtRemoveInput() {} ;
void XtRemoveRawEventHandler() {} ;
void XtRemoveSignal() {} ;
void XtRemoveTimeOut() {} ;
void XtRemoveWorkProc() {} ;
void XtReservePropertyAtom() {} ;
void XtResizeWidget() {} ;
void XtResizeWindow() {} ;
void XtResolvePathname() {} ;
void XtScreen() {} ;
void XtScreenDatabase() {} ;
void XtScreenOfObject() {} ;
void XtSendSelectionRequest() {} ;
void XtSessionGetToken() {} ;
void XtSessionReturnToken() {} ;
void XtSetErrorHandler() {} ;
void XtSetErrorMsgHandler() {} ;
void XtSetEventDispatcher() {} ;
void XtSetKeyTranslator() {} ;
void XtSetKeyboardFocus() {} ;
void XtSetLanguageProc() {} ;
void XtSetMappedWhenManaged() {} ;
void XtSetMultiClickTime() {} ;
void XtSetSelectionParameters() {} ;
void XtSetSelectionTimeout() {} ;
void XtSetSensitive() {} ;
void XtSetSubvalues() {} ;
void XtSetTypeConverter() {} ;
void XtSetValues() {} ;
void XtSetWMColormapWindows() {} ;
void XtSetWarningHandler() {} ;
void XtSetWarningMsgHandler() {} ;
void XtStringConversionWarning() {} ;
void XtSuperclass() {} ;
void XtToolkitInitialize() {} ;
void XtToolkitThreadInitialize() {} ;
void XtTranslateCoords() {} ;
void XtTranslateKey() {} ;
void XtTranslateKeycode() {} ;
void XtUngrabButton() {} ;
void XtUngrabKey() {} ;
void XtUngrabKeyboard() {} ;
void XtUngrabPointer() {} ;
void XtUninstallTranslations() {} ;
void XtUnmanageChild() {} ;
void XtUnmanageChildren() {} ;
void XtUnmapWidget() {} ;
void XtUnrealizeWidget() {} ;
void XtUnregisterDrawable() {} ;
void XtVaAppCreateShell() {} ;
void XtVaAppInitialize() {} ;
void XtVaCreateArgsList() {} ;
void XtVaCreateManagedWidget() {} ;
void XtVaCreatePopupShell() {} ;
void XtVaCreateWidget() {} ;
void XtVaGetApplicationResources() {} ;
void XtVaGetSubresources() {} ;
void XtVaGetSubvalues() {} ;
void XtVaGetValues() {} ;
void XtVaOpenApplication() {} ;
void XtVaSetSubvalues() {} ;
void XtVaSetValues() {} ;
void XtWarning() {} ;
void XtWarningMsg() {} ;
void XtWidgetToApplicationContext() {} ;
void XtWindow() {} ;
void XtWindowOfObject() {} ;
void XtWindowToWidget() {} ;
void _XtCheckSubclassFlag() {} ;
void _XtCopyFromArg() {} ;
void _XtInherit() {} ;
void _XtIsSubclassOf() {} ;
__asm__(".globl XtCXtToolkitError; .pushsection .data; .type XtCXtToolkitError,@object; .size XtCXtToolkitError, 4; XtCXtToolkitError: .long 0; .popsection");
__asm__(".globl XtShellStrings; .pushsection .data; .type XtShellStrings,@object; .size XtShellStrings, 1289; XtShellStrings: .long 0; .popsection");
__asm__(".globl XtStrings; .pushsection .data; .type XtStrings,@object; .size XtStrings, 2649; XtStrings: .long 0; .popsection");
__asm__(".globl _XtInheritTranslations; .pushsection .data; .type _XtInheritTranslations,@object; .size _XtInheritTranslations, 4; _XtInheritTranslations: .long 0; .popsection");
__asm__(".globl applicationShellClassRec; .pushsection .data; .type applicationShellClassRec,@object; .size applicationShellClassRec, 156; applicationShellClassRec: .long 0; .popsection");
__asm__(".globl applicationShellWidgetClass; .pushsection .data; .type applicationShellWidgetClass,@object; .size applicationShellWidgetClass, 4; applicationShellWidgetClass: .long 0; .popsection");
__asm__(".globl colorConvertArgs; .pushsection .data; .type colorConvertArgs,@object; .size colorConvertArgs, 24; colorConvertArgs: .long 0; .popsection");
__asm__(".globl compositeClassRec; .pushsection .data; .type compositeClassRec,@object; .size compositeClassRec, 136; compositeClassRec: .long 0; .popsection");
__asm__(".globl compositeWidgetClass; .pushsection .data; .type compositeWidgetClass,@object; .size compositeWidgetClass, 4; compositeWidgetClass: .long 0; .popsection");
__asm__(".globl constraintClassRec; .pushsection .data; .type constraintClassRec,@object; .size constraintClassRec, 164; constraintClassRec: .long 0; .popsection");
__asm__(".globl constraintWidgetClass; .pushsection .data; .type constraintWidgetClass,@object; .size constraintWidgetClass, 4; constraintWidgetClass: .long 0; .popsection");
__asm__(".globl coreWidgetClass; .pushsection .data; .type coreWidgetClass,@object; .size coreWidgetClass, 4; coreWidgetClass: .long 0; .popsection");
__asm__(".globl objectClass; .pushsection .data; .type objectClass,@object; .size objectClass, 4; objectClass: .long 0; .popsection");
__asm__(".globl objectClassRec; .pushsection .data; .type objectClassRec,@object; .size objectClassRec, 116; objectClassRec: .long 0; .popsection");
__asm__(".globl overrideShellClassRec; .pushsection .data; .type overrideShellClassRec,@object; .size overrideShellClassRec, 144; overrideShellClassRec: .long 0; .popsection");
__asm__(".globl overrideShellWidgetClass; .pushsection .data; .type overrideShellWidgetClass,@object; .size overrideShellWidgetClass, 4; overrideShellWidgetClass: .long 0; .popsection");
__asm__(".globl rectObjClass; .pushsection .data; .type rectObjClass,@object; .size rectObjClass, 4; rectObjClass: .long 0; .popsection");
__asm__(".globl rectObjClassRec; .pushsection .data; .type rectObjClassRec,@object; .size rectObjClassRec, 116; rectObjClassRec: .long 0; .popsection");
__asm__(".globl sessionShellClassRec; .pushsection .data; .type sessionShellClassRec,@object; .size sessionShellClassRec, 160; sessionShellClassRec: .long 0; .popsection");
__asm__(".globl sessionShellWidgetClass; .pushsection .data; .type sessionShellWidgetClass,@object; .size sessionShellWidgetClass, 4; sessionShellWidgetClass: .long 0; .popsection");
__asm__(".globl shellClassRec; .pushsection .data; .type shellClassRec,@object; .size shellClassRec, 140; shellClassRec: .long 0; .popsection");
__asm__(".globl shellWidgetClass; .pushsection .data; .type shellWidgetClass,@object; .size shellWidgetClass, 4; shellWidgetClass: .long 0; .popsection");
__asm__(".globl topLevelShellClassRec; .pushsection .data; .type topLevelShellClassRec,@object; .size topLevelShellClassRec, 152; topLevelShellClassRec: .long 0; .popsection");
__asm__(".globl topLevelShellWidgetClass; .pushsection .data; .type topLevelShellWidgetClass,@object; .size topLevelShellWidgetClass, 4; topLevelShellWidgetClass: .long 0; .popsection");
__asm__(".globl transientShellClassRec; .pushsection .data; .type transientShellClassRec,@object; .size transientShellClassRec, 152; transientShellClassRec: .long 0; .popsection");
__asm__(".globl transientShellWidgetClass; .pushsection .data; .type transientShellWidgetClass,@object; .size transientShellWidgetClass, 4; transientShellWidgetClass: .long 0; .popsection");
__asm__(".globl widgetClass; .pushsection .data; .type widgetClass,@object; .size widgetClass, 4; widgetClass: .long 0; .popsection");
__asm__(".globl widgetClassRec; .pushsection .data; .type widgetClassRec,@object; .size widgetClassRec, 116; widgetClassRec: .long 0; .popsection");
__asm__(".globl wmShellClassRec; .pushsection .data; .type wmShellClassRec,@object; .size wmShellClassRec, 144; wmShellClassRec: .long 0; .popsection");
__asm__(".globl wmShellWidgetClass; .pushsection .data; .type wmShellWidgetClass,@object; .size wmShellWidgetClass, 4; wmShellWidgetClass: .long 0; .popsection");
|
the_stack_data/95321.c
|
/* xmalloc.c -- malloc with out of memory checking
Copyright (C) 1990, 1991, 1993 Free Software Foundation, Inc.
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, 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., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if __STDC__
#define VOID void
#else
#define VOID char
#endif
#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#else
VOID *malloc ();
VOID *realloc ();
void free ();
#endif
#if __STDC__ && defined (HAVE_VPRINTF)
void error (int, int, char const *, ...);
#else
void error ();
#endif
/* Allocate N bytes of memory dynamically, with error checking. */
VOID *
xmalloc (n)
size_t n;
{
VOID *p;
p = malloc (n);
if (p == 0)
/* Must exit with 2 for `cmp'. */
error (2, 0, "memory exhausted");
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
with error checking.
If P is NULL, run xmalloc.
If N is 0, run free and return NULL. */
VOID *
xrealloc (p, n)
VOID *p;
size_t n;
{
if (p == 0)
return xmalloc (n);
if (n == 0)
{
free (p);
return 0;
}
p = realloc (p, n);
if (p == 0)
/* Must exit with 2 for `cmp'. */
error (2, 0, "memory exhausted");
return p;
}
|
the_stack_data/59512902.c
|
#include <stdio.h>
int power(int x, int y) {
if (y == 0) // TERMINAL CONDITION
return 1;
return x * power(x, y - 1);
}
int main() {
int x = 5;
int y = 3;
int result = power(x, y);
printf("%d to the power of %d is = %d\n", x, y, result);
return 0;
}
|
the_stack_data/68888625.c
|
/* Write a program that calculates statistics on word length for a sentence. The sentence is terminated by a ’.’ For each found length of a word the number of words of that length is printed. Only those lengths that are found in the input are printed. Only letters from a-z or A-Z are allowed to form words. Words are separated by a space. No punctuation characters other than ’.’ are allowed. If any other input character is recognized or the input is longer than 80 characters the program displays ”NOT VALID”. Note, that in the case that no word is present in the input, nothing is printed.
% u6_stats
Enter a sentence: Bolt was expected to use the super bark.
Length 2: 1
Length 3: 3
Length 4: 2
Length 5: 1
Length 8: 1
% u6_stats
Enter a sentence: Something wasn’t right.
NOT VALID
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
/* Allow up to 82 chars so "NOT VALID" can be triggered on inputs with more than 81 chars (= 80 allowed characters + 1 null terminator). */
int maxchars = 82;
char userinput[82] = {'\0'};
// max. 11 diff. possible word lengths in 80 chars (w/ spaces inbetween)
int wordlengths[2][11] = {};
int countchars = 0;
int thislength = 0;
int validletter = 0;
int placeholder_0;
int placeholder_1;
int i=0, j=0, k=0;
printf("Enter a sentence: \n");
/* fgets reads full userinputs from standard input including spaces, special chars and - if input is less than the allowed no. of character (= if there's space left in the array) - also new line characters (Enter key). */
fgets(userinput, maxchars, stdin);
/* As newline characters are also counted with strlen(), a potential '\n' character needs to be replaced with the null terminator. */
for (i=0;i<maxchars;i++) {
if(userinput[i] == '\n') {
userinput[i] = '\0';
break;
}
}
countchars = strlen(userinput); // all printable chars + spaces
// input is at least one character and not more than 80
if(countchars > 0 && countchars <= 80) {
// go through all characters of userinput
for(i=0;i<countchars;i++) {
// check if userinput[i] is a lowercase character a-z
for(char ch='a';ch<='z';ch++) {
if(userinput[i] == ch) {
thislength++;
validletter = 1;
}
}
// if userinput[i] isn't lowercase, check if it's uppercase A-Z
if (validletter != 1) {
for(char ch='A';ch<='Z';ch++) {
if(userinput[i] == ch) {
thislength++;
validletter = 1;
}
}
}
// userinput[i] is no character at all; check for spaces and '.'
if(validletter != 1) {
if(userinput[i] == ' ' || userinput[i] == '.') {
if (thislength > 0) {
// check if word length already in array
for (j=0;j<11;j++) {
if (wordlengths[0][j] == thislength) { // yes
wordlengths[1][j] += 1;
thislength = 0;
break;
}
}
if (thislength != 0) {
for (j=0;j<11;j++) { // no; add to array
if (wordlengths[0][j] == 0) {
wordlengths[0][j] = thislength;
wordlengths[1][j] += 1;
thislength = 0;
break;
}
}
}
}
} else { // userinput[i] is no valid character -> exit
printf("NOT VALID\n");
exit(0);
}
}
validletter = 0;
}
// sort array by word length ascending (bubble sort)
for(j=1;j<11;j++) {
for(k=1;k<11;k++) {
if(wordlengths[0][k] < wordlengths[0][k-1]) {
placeholder_0 = wordlengths[0][k-1];
placeholder_1 = wordlengths[1][k-1];
wordlengths[0][k-1] = wordlengths[0][k];
wordlengths[1][k-1] = wordlengths[1][k];
wordlengths[0][k] = placeholder_0;
wordlengths[1][k] = placeholder_1;
}
}
}
for(k=0;k<11;k++) {
if (wordlengths[0][k] != 0) { // ignore empty columns
printf("Length %d: %d\n", wordlengths[0][k], wordlengths[1][k]);
}
}
} else if (countchars > 80) { // more than allowed characters entered
printf("NOT VALID\n");
} else { // no characters entered - do nothing
}
return 0;
}
|
the_stack_data/218894473.c
|
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <time.h>
// cria filhos
int cria_filhos(int n){
pid_t pid;
int i;
for(i=0;i<n;i++){
pid=fork();
if(pid<0){
return -1;
}else if(pid==0){
return i+1;
}
}
return 0;
}
int main(void) {
const int QTD_FILHOS = 10;
int i;
int id = 0;
id = cria_filhos(QTD_FILHOS);
if(id==-1){
perror("fork failled!!!");
exit(EXIT_FAILURE);
}
// código do filho
if(id>0){
for(i=((id-1)*100+1);i<id*100;i++){
printf("Filho %d : nº %d\n", id, i);
}
exit(id);
}
// código do pai
if(id==0){
int status;
pid_t p;
for(i=0;i<QTD_FILHOS;i++){
wait(&status);
if(p==-1){
perror("Waited failled!!");
exit(EXIT_FAILURE);
}else if(WIFEXITED(status)){
printf("Filho: %d\n", WEXITSTATUS(status));
}
}
}
return 0;
}
|
the_stack_data/179831722.c
|
#include<stdio.h>
#include<signal.h>
#include<stdlib.h>
static void sig_quit(int);
int main(int argc, char *argv[]) {
sigset_t newmask, oldmask, pendmask;
if (signal(SIGQUIT, sig_quit) == SIG_ERR) {
perror("signal");
exit(EXIT_FAILURE);
}
printf("install sig_quit\n");
// Block SIGQUIT and save current signal mask.
sigemptyset(&newmask);
sigaddset(&newmask, SIGQUIT);
if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
perror("signal");
exit(EXIT_FAILURE);
}
printf("Block SIGQUIT,wait 15 second\n");
sleep(15); /* SIGQUIT here will remain pending */
if (sigpending(&pendmask) < 0) {
perror("signal");
exit(EXIT_FAILURE);
}
if (sigismember(&pendmask, SIGQUIT)) {
printf("\nSIGQUIT pending\n");
}
if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
perror("signal");
exit(EXIT_FAILURE);
}
printf("SIGQUIT unblocked\n");
sleep(15); /* SIGQUIT here will terminate with core file */
return 0;
}
static void sig_quit(int signo) {
printf("caught SIGQUIT,the process will quit\n");
if (signal(SIGQUIT, SIG_DFL) == SIG_ERR) {
perror("signal");
exit(EXIT_FAILURE);
}
}
|
the_stack_data/75667.c
|
struct info_t {};
int main ();
int main (ac, av)
int ac;
{}
|
the_stack_data/220454688.c
|
// Exercício 10 - Suponha um vetor N com 10 elementos e outro vetor M com 10 elementos.
// Faça um programa em C que calcule o produto escalar P de A por B. (Isto é,
// P = A[1] * B[1] + A[2] * B[2] + ... A[N] + B[N]).
# include <stdio.h>
int linha(void) {
char x = '-';
printf("\n\033[33m");
for (int count = 0; count < 30; count ++) {
printf("%c", x);
}
printf("\033[m\n\n");
return 0;
}
int main(void) {
int qtd = 0;
linha();
printf("\033[32m## PRODUTO ESCALAR.\033[m\n");
linha();
printf("Quantidade de números a serem digitados nos vetores: ");
scanf("%i", &qtd);
int vetorN[qtd], vetorM[qtd];
linha();
printf(" \033[31mVetor N\033[m\n");
for (int count = 0; count < qtd; count ++) {
printf("Digite %i números [%i/%i]: ",qtd, count + 1, qtd);
scanf("%i", &vetorN[count]);
}
linha();
printf(" \033[31mVetor M\033[m\n");
for (int count = 0; count < qtd; count ++) {
printf("Digite %i números [%i/%i]: ",qtd, count + 1, qtd);
scanf("%i", &vetorM[count]);
}
linha();
int produto = 0;
for (int count = 0; count < qtd; count ++) {
produto += vetorN[count] * vetorM[count];
}
printf("Produto Escalar de N por M: %i\n", produto);
linha();
return 0;
}
|
the_stack_data/52121.c
|
/*
Copyright (c) 2014-2018, Alexey Frunze
2-clause BSD license.
*/
#ifdef _WINDOWS
asm(
"section .kernel32_hints\n"
"dd _hint_TzSpecificLocalTimeToSystemTime"
);
asm(
"section .kernel32_iat\n"
"__imp__TzSpecificLocalTimeToSystemTime: dd _hint_TzSpecificLocalTimeToSystemTime"
);
static char hint_TzSpecificLocalTimeToSystemTime[] = "\0\0TzSpecificLocalTimeToSystemTime";
extern char _kernel32_dll__[];
static char* pdll = _kernel32_dll__; // pull trailers for sections .kernel32_hints and .kernel32_iat
struct _TIME_ZONE_INFORMATION;
struct _SYSTEMTIME;
int __TzSpecificLocalTimeToSystemTime(struct _TIME_ZONE_INFORMATION* lpTimeZoneInformation,
struct _SYSTEMTIME* lpLocalTime,
struct _SYSTEMTIME* lpUniversalTime)
{
asm(
"push dword [ebp+16]\n"
"push dword [ebp+12]\n"
"push dword [ebp+8]\n"
"call dword [__imp__TzSpecificLocalTimeToSystemTime]"
);
}
#endif // _WINDOWS
|
the_stack_data/43887608.c
|
#include <string.h>
#include <stdio.h>
/*
Attributes: FUNC VLA2
*/
void func(void)
{
int sz, i;
scanf("%d", &sz);
for (i = 0 ; i < sz ; ++i)
{
char buf[sz];
gets(buf);
printf(buf);
}
}
int main()
{
func();
return 0;
}
|
the_stack_data/40761823.c
|
//===-- bswapsi2_test.c - Test __bswapsi2 ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file tests __bswapsi2 for the compiler_rt library.
//
//===----------------------------------------------------------------------===//
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
extern uint32_t __bswapsi2(uint32_t);
#if __arm__
int test__bswapsi2(uint32_t a, uint32_t expected)
{
uint32_t actual = __bswapsi2(a);
if (actual != expected)
printf("error in test__bswapsi2(0x%0X) = 0x%0X, expected 0x%0X\n",
a, actual, expected);
return actual != expected;
}
#endif
int main()
{
#if __arm__
if (test__bswapsi2(0x12345678, 0x78563412))
return 1;
if (test__bswapsi2(0x00000001, 0x01000000))
return 1;
#else
printf("skipped\n");
#endif
return 0;
}
|
the_stack_data/1175881.c
|
/*
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
*
* For licensing, see LICENSE.SPECS
*/
#ifdef _WIN32
#include <windows.h>
#define sleep(x) Sleep((x)*1000)
#endif
#ifndef _WIN32
#include <unistd.h>
#include <pthread.h>
#endif
int testAdd(int a, int b)
{
return a + b;
};
int testFunctionAdd(int a, int b, int (*f)(int, int))
{
return f(a, b);
};
void testBlocking(int seconds) {
sleep(seconds);
};
struct async_data {
void (*fn)(int);
int value;
};
static void* asyncThreadCall(void *data)
{
struct async_data* d = (struct async_data *) data;
if (d != NULL && d->fn != NULL) {
(*d->fn)(d->value);
}
return NULL;
}
void testAsyncCallback(void (*fn)(int), int value)
{
#ifndef _WIN32
pthread_t t;
struct async_data d;
d.fn = fn;
d.value = value;
pthread_create(&t, NULL, asyncThreadCall, &d);
pthread_join(t, NULL);
#else
(*fn)(value);
#endif
}
#if defined(_WIN32) && !defined(_WIN64)
struct StructUCDP {
unsigned char a1;
double a2;
void *a3;
};
void __stdcall testStdcallManyParams(long *a1, char a2, short int a3, int a4, __int64 a5,
struct StructUCDP a6, struct StructUCDP *a7, float a8, double a9) {
}
#endif
|
the_stack_data/144654.c
|
/**************************************************************************
* Copyright (c) 2001 by Punch Telematix. 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. Neither the name of Punch Telematix nor the names of *
* other contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission.*
* *
* THIS SOFTWARE IS PROVIDED ``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 PUNCH TELEMATIX OR OTHER CONTRIBUTORS BE LIABLE *
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, *
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE *
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN *
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
**************************************************************************/
#include <stdio.h>
static int d = 0; // Should be no problem
//int e = 0; // Should complain about 'multiply defined'
extern int e; // Defined in module_1.c
extern int c;
extern int parameter;
extern int get_int(int a); // in module_1
extern int is_an_exported_function(int a); // in kernel
int defined_in_2 = 100;
int second_add(int a, int b) {
int result;
printf("2 doing the adding\n");
result = d + e;
printf("2 result is now %d\n", result);
result += c;
printf("2 result is now %d\n", result);
result += a;
printf("2 result is now %d\n", result);
result += b;
printf("2 result is now %d\n", result);
result += get_int(256);
printf("2 result is now %d\n", result);
result = is_an_exported_function(result);
printf("2 result is now %d\n", result);
return result;
}
void init_module(void) {
printf("module 2: initializing, parameter = %d\n", parameter);
}
void clean_module(void) {
printf("module 2: cleaning, parameter = %d\n", parameter);
}
|
the_stack_data/183454.c
|
#include <math.h>
long double
ldexpl(long double x, int n)
{
return scalbnl(x, n);
}
|
the_stack_data/26701642.c
|
/* mbed Microcontroller Library
*******************************************************************************
* Copyright (c) 2018, STMicroelectronics
* 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. 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.
*******************************************************************************
*/
#if DEVICE_LPTICKER
/***********************************************************************/
/* lpticker_lptim config is 1 in json config file */
/* LPTICKER is based on LPTIM feature from ST drivers. RTC is not used */
#if MBED_CONF_TARGET_LPTICKER_LPTIM
#include "lp_ticker_api.h"
#include "mbed_error.h"
#if !defined(LPTICKER_DELAY_TICKS) || (LPTICKER_DELAY_TICKS < 3)
#warning "lpticker_delay_ticks value should be set to 3"
#endif
LPTIM_HandleTypeDef LptimHandle;
const ticker_info_t *lp_ticker_get_info()
{
static const ticker_info_t info = {
#if MBED_CONF_TARGET_LSE_AVAILABLE
LSE_VALUE / MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK,
#else
LSI_VALUE / MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK,
#endif
16
};
return &info;
}
volatile uint8_t lp_Fired = 0;
static void LPTIM1_IRQHandler(void);
static void (*irq_handler)(void);
void lp_ticker_init(void)
{
/* Check if LPTIM is already configured */
if (__HAL_RCC_LPTIM1_IS_CLK_ENABLED()) {
lp_ticker_disable_interrupt();
return;
}
RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct = {0};
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
#if MBED_CONF_TARGET_LSE_AVAILABLE
/* Enable LSE clock */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
/* Select the LSE clock as LPTIM peripheral clock */
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
#if (TARGET_STM32L0)
RCC_PeriphCLKInitStruct.LptimClockSelection = RCC_LPTIM1CLKSOURCE_LSE;
#else
RCC_PeriphCLKInitStruct.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSE;
#endif
#else /* MBED_CONF_TARGET_LSE_AVAILABLE */
/* Enable LSI clock */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
/* Select the LSI clock as LPTIM peripheral clock */
RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_LPTIM1;
#if (TARGET_STM32L0)
RCC_PeriphCLKInitStruct.LptimClockSelection = RCC_LPTIM1CLKSOURCE_LSI;
#else
RCC_PeriphCLKInitStruct.Lptim1ClockSelection = RCC_LPTIM1CLKSOURCE_LSI;
#endif
#endif /* MBED_CONF_TARGET_LSE_AVAILABLE */
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
error("HAL_RCC_OscConfig ERROR\n");
return;
}
if (HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct) != HAL_OK) {
error("HAL_RCCEx_PeriphCLKConfig ERROR\n");
return;
}
__HAL_RCC_LPTIM1_CLK_ENABLE();
__HAL_RCC_LPTIM1_FORCE_RESET();
__HAL_RCC_LPTIM1_RELEASE_RESET();
/* Initialize the LPTIM peripheral */
LptimHandle.Instance = LPTIM1;
LptimHandle.State = HAL_LPTIM_STATE_RESET;
LptimHandle.Init.Clock.Source = LPTIM_CLOCKSOURCE_APBCLOCK_LPOSC;
#if defined(MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK)
#if (MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK == 4)
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV4;
#elif (MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK == 2)
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV2;
#else
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
#endif
#else
LptimHandle.Init.Clock.Prescaler = LPTIM_PRESCALER_DIV1;
#endif /* MBED_CONF_TARGET_LPTICKER_LPTIM_CLOCK */
LptimHandle.Init.Trigger.Source = LPTIM_TRIGSOURCE_SOFTWARE;
LptimHandle.Init.OutputPolarity = LPTIM_OUTPUTPOLARITY_HIGH;
LptimHandle.Init.UpdateMode = LPTIM_UPDATE_IMMEDIATE;
LptimHandle.Init.CounterSource = LPTIM_COUNTERSOURCE_INTERNAL;
#if defined (LPTIM_INPUT1SOURCE_GPIO) /* STM32L4 */
LptimHandle.Init.Input1Source = LPTIM_INPUT1SOURCE_GPIO;
LptimHandle.Init.Input2Source = LPTIM_INPUT2SOURCE_GPIO;
#endif /* LPTIM_INPUT1SOURCE_GPIO */
if (HAL_LPTIM_Init(&LptimHandle) != HAL_OK) {
error("HAL_LPTIM_Init ERROR\n");
return;
}
NVIC_SetVector(LPTIM1_IRQn, (uint32_t)LPTIM1_IRQHandler);
#if defined (__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT)
/* EXTI lines are not configured by default */
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_IT();
__HAL_LPTIM_WAKEUPTIMER_EXTI_ENABLE_RISING_EDGE();
#endif
__HAL_LPTIM_ENABLE_IT(&LptimHandle, LPTIM_IT_CMPM);
HAL_LPTIM_Counter_Start(&LptimHandle, 0xFFFF);
/* Need to write a compare value in order to get LPTIM_FLAG_CMPOK in set_interrupt */
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, 0);
while (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == RESET) {
}
}
static void LPTIM1_IRQHandler(void)
{
LptimHandle.Instance = LPTIM1;
if (lp_Fired) {
lp_Fired = 0;
if (irq_handler) {
irq_handler();
}
}
/* Compare match interrupt */
if (__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPM) != RESET) {
if (__HAL_LPTIM_GET_IT_SOURCE(&LptimHandle, LPTIM_IT_CMPM) != RESET) {
/* Clear Compare match flag */
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
if (irq_handler) {
irq_handler();
}
}
}
#if defined (__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG)
/* EXTI lines are not configured by default */
__HAL_LPTIM_WAKEUPTIMER_EXTI_CLEAR_FLAG();
#endif
}
uint32_t lp_ticker_read(void)
{
uint32_t lp_time = LPTIM1->CNT;
/* Reading the LPTIM_CNT register may return unreliable values.
It is necessary to perform two consecutive read accesses and verify that the two returned values are identical */
while (lp_time != LPTIM1->CNT) {
lp_time = LPTIM1->CNT;
}
return lp_time;
}
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
LptimHandle.Instance = LPTIM1;
irq_handler = (void (*)(void))lp_ticker_irq_handler;
/* CMPOK is set by hardware to inform application that the APB bus write operation to the LPTIM_CMP register has been successfully completed */
/* Any successive write before the CMPOK flag be set, will lead to unpredictable results */
/* LPTICKER_DELAY_TICKS value prevents OS to call this set interrupt function before CMPOK */
MBED_ASSERT(__HAL_LPTIM_GET_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK) == SET);
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPOK);
__HAL_LPTIM_COMPARE_SET(&LptimHandle, timestamp);
lp_ticker_clear_interrupt();
NVIC_EnableIRQ(LPTIM1_IRQn);
}
void lp_ticker_fire_interrupt(void)
{
lp_Fired = 1;
irq_handler = (void (*)(void))lp_ticker_irq_handler;
NVIC_SetPendingIRQ(LPTIM1_IRQn);
NVIC_EnableIRQ(LPTIM1_IRQn);
}
void lp_ticker_disable_interrupt(void)
{
NVIC_DisableIRQ(LPTIM1_IRQn);
LptimHandle.Instance = LPTIM1;
}
void lp_ticker_clear_interrupt(void)
{
LptimHandle.Instance = LPTIM1;
__HAL_LPTIM_CLEAR_FLAG(&LptimHandle, LPTIM_FLAG_CMPM);
NVIC_ClearPendingIRQ(LPTIM1_IRQn);
}
void lp_ticker_free(void)
{
lp_ticker_disable_interrupt();
}
/*****************************************************************/
/* lpticker_lptim config is 0 or not defined in json config file */
/* LPTICKER is based on RTC wake up feature from ST drivers */
#else /* MBED_CONF_TARGET_LPTICKER_LPTIM */
#include "rtc_api_hal.h"
const ticker_info_t *lp_ticker_get_info()
{
static const ticker_info_t info = {
RTC_CLOCK / 4, // RTC_WAKEUPCLOCK_RTCCLK_DIV4
32
};
return &info;
}
void lp_ticker_init(void)
{
rtc_init();
lp_ticker_disable_interrupt();
}
uint32_t lp_ticker_read(void)
{
return rtc_read_lp();
}
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
rtc_set_wake_up_timer(timestamp);
}
void lp_ticker_fire_interrupt(void)
{
rtc_fire_interrupt();
}
void lp_ticker_disable_interrupt(void)
{
rtc_deactivate_wake_up_timer();
}
void lp_ticker_clear_interrupt(void)
{
lp_ticker_disable_interrupt();
}
void lp_ticker_free(void)
{
lp_ticker_disable_interrupt();
}
#endif /* MBED_CONF_TARGET_LPTICKER_LPTIM */
#endif /* DEVICE_LPTICKER */
|
the_stack_data/165768606.c
|
/* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */
/*
* kill - send signal to process
*/
#include <signal.h>
main(argc, argv)
char **argv;
{
register signo, pid, res;
int errlev;
extern char *sys_errlist[];
extern errno;
errlev = 0;
if (argc <= 1) {
usage:
printf("usage: kill [ -signo ] pid ...\n");
exit(2);
}
if (*argv[1] == '-') {
signo = atoi(argv[1]+1);
argc--;
argv++;
} else
signo = SIGTERM;
argv++;
while (argc > 1) {
if (**argv<'0' || **argv>'9')
goto usage;
res = kill(pid = atoi(*argv), signo);
if (res<0) {
printf("%u: %s\n", pid, sys_errlist[errno]);
errlev = 1;
}
argc--;
argv++;
}
return(errlev);
}
|
the_stack_data/117328331.c
|
#include <stdio.h>
#include <stdlib.h>
struct array{int wert[3];};
struct array init_array(void)
{
struct array z;
for(int i=0;i< sizeof(struct array)/sizeof(int);i++)
{
printf("Wert %d eingeben:", i);
scanf("%d", &z.wert[i]);
}
return z;
}
void output_array(struct array z)
{
for(int i=0;i<sizeof(struct array)/sizeof(int);i++)
{
printf("%d\t",z.wert[i]);
}
}
int main(void) {
setbuf(stdout, NULL); //Ausgabebuffer ausschalten
struct array new_array;
//Array als Rückgabewert in einer Struktur verschachtelt
new_array=init_array();
//Call-by-value
output_array(new_array);
return EXIT_SUCCESS;
}
|
the_stack_data/67325238.c
|
//{{BLOCK(PongBallR)
//======================================================================
//
// PongBallR, 24x24@2,
// + regular map (flat), not compressed, 3x3
// External tile file: (null).
// Total size: 20 = 20
//
// Exported by Cearn's GBA Image Transmogrifier, v0.8.6
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================
const unsigned short PongBallRMap[10] __attribute__((aligned(4)))=
{
0x0007,0x0008,0x0009,0x000A,0x000B,0x000C,0x1007,0x1008,
0x1009,0x0000,
};
//}}BLOCK(PongBallR)
|
the_stack_data/153269574.c
|
long
filtd(wi, y1)
long wi, y1;
{
long dif, difs, difsx, yut;
dif = ((wi << 5) + 131072 - y1) & 131071;
difs = dif >> 16;
difsx = difs ? (dif >> 5) + 4096 : dif >> 5;
yut = (y1 + difsx) & 8191;
return(yut);
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.