file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/97012934.c | /*
dtostrf - Emulation for dtostrf function from avr-libc
Copyright (c) 2013 Arduino. All rights reserved.
Written by Cristian Maglie <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *dtostrf(double val, signed char width, unsigned char prec, char *sout)
{
//Commented code is the original version
/*char fmt[20];
sprintf(fmt, "%%%d.%df", width, prec);
sprintf(sout, fmt, val);
return sout;*/
// Handle negative numbers
unsigned int negative = 0;
if (val < 0.0) {
negative = 1;
val = -val;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (int i = 0; i < prec; ++i) {
rounding /= 10.0;
}
val += rounding;
// Extract the integer part of the number
unsigned long int_part = (unsigned long)val;
double remainder = val - (double)int_part;
if (negative) {
int_part = -int_part;
}
// Extract digits from the remainder
unsigned long dec_part = 0;
double decade = 1.0;
for (int i = 0; i < prec; i++) {
decade *= 10.0;
}
remainder *= decade;
dec_part = (int)remainder;
sprintf(sout, "%ld.%0*ld", int_part, prec, dec_part);
// Handle minimum field width of the output string
// width is signed value, negative for left adjustment.
// Range -128,127
char fmt[129] = "";
unsigned int w = width;
if (width < 0) {
negative = 1;
w = -width;
} else {
negative = 0;
}
if (strlen(sout) < w) {
memset(fmt, ' ', 128);
fmt[w - strlen(sout)] = '\0';
if (negative == 0) {
char *tmp = strdup(sout);
strcpy(sout, fmt);
strcat(sout, tmp);
free(tmp);
} else {
// left adjustment
strcat(sout, fmt);
}
}
return sout;
}
|
the_stack_data/154828421.c | #include <stdio.h>
#include <string.h>
void test2(char* x){
char dest[4096];
strcpy(dest,x);
}
int test1(int y) {
printf("test1 function %i\n", y+20);
char xy[] = "abcdefg";
test2(xy);
return y+20;
}
int test(int x) {
char y[] = "test function";
printf("%s\n", y);
test1(x);
return x+(x*2)+20;
}
int main (int argc, char** argv) {
printf("main function\n");
test(20);
return 0;
}
|
the_stack_data/62638740.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_printable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jsanfeli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/11 18:11:48 by jsanfeli #+# #+# */
/* Updated: 2021/08/15 13:47:24 by jsanfeli ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
int ft_str_is_printable(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] < 32 || str[i] > 126)
{
return (0);
}
i++;
}
return (1);
}
|
the_stack_data/154827437.c | #include <stdio.h>
#include <stdlib.h>
int main(void) {
char *sieve;
size_t i;
unsigned count = 0;
size_t n = 1000000;
const unsigned target = 10001;
sieve = calloc(n, sizeof *sieve);
for (i = 2; i < n; i++) {
if (!sieve[i]) {
size_t j;
count++;
if (count == target) {
printf("%lu\n", i);
break;
}
for (j = i * 2; j < n; j += i) {
sieve[j] = 1;
}
}
}
free(sieve);
return 0;
}
|
the_stack_data/220456784.c | //number conversion
#include <stdio.h>
#include <math.h>
int bin2dec(long);
long dec2bin(int);
long oct2dec(int);
int dec2oct(int);
int main()
{
int c,d,o,d1;
long b;
do
{
printf("1.Binary To Decimal\n2.Decimal To Binary\n3.Octal To Decimal\n4.Decimal To Octal\n5.Exit\n");
printf("enter your choice\n");
scanf("%d",&c);
switch(c)
{
case 1:
printf("enter binary no.\n");
scanf("%ld",&b);
printf("Decimal no.=%d\n",bin2dec(b));
break;
case 2:
printf("enter decimal no.\n");
scanf("%d",&d);
printf("Binary no.=%d\n",dec2bin(d));
break;
case 3:
printf("enter octal no.\n");
scanf("%d",&o);
printf("Decimal no.=%d\n",oct2dec(o));
break;
case 4:
printf("enter decimal no.\n");
scanf("%d",&d1);
printf("Octal no.=%d\n",dec2oct(d1));
break;
default:
printf("THANK YOU\n");
}
}while(c!=5);
return 0;
}
int bin2dec(long n)
{
int d=0,i=0,r;
while(n!=0)
{
r=n%10;
n=n/10;
d+=r*pow(2,i);
++i;
}
return d;
}
long dec2bin(int n)
{
long b=0;
int r,i=1,step=1;
while(n!=0)
{
r=n%2;
printf("step %d : %d/2,remainder=%d,quotient=%d\n",step++,n,r,n/2);
n/=2;
b+=r*i;
i*=10;
}
return b;
}
long oct2dec(int n)
{
int d=0,i=0;
while(n!=0)
{
d+=(n%10)*pow(8,i);
++i;
n=n/10;
}
i=1;
return d;
}
int dec2oct(int n)
{
int o=0,i=1;
while(n!=0)
{
o+=(n%8)*i;
n/=8;
i*=10;
}
return o;
}
|
the_stack_data/62637756.c | /*
basic 1
*/
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
int fd;
int ret = 0;
int read_pin;
int write_ret;
int write_on ;
int main(int argc, char *argv[])
{
unsigned int i;
char read_pin_buf;
fd = open("/dev/io_control",O_RDWR);
if(fd < 0)
{
perror("error to open /dev/io_control_dev");
exit(1);
}
int number ;
while(1)
{
ret = read(fd, &read_pin,4);
if(ret < 0)
{
perror("error to read\n");
exit(1);
}
read_pin_buf=read_pin;
switch(read_pin_buf)
{
case 4:
case 5:
case 6:
number = read_pin_buf +1 ;
write_on = number +7 ;
write_ret = write(fd , &write_on , 4) ;
if(write_ret < 0)
{
printf("open led error!\n");
exit(1) ;
}
break;
case 7:
case 8:
case 9:
case 10:
case 11:
number = read_pin_buf -7 ;
write_on = number + 7 ;
write_ret = write(fd , &write_on , 4);
if(write_ret < 0)
{
printf("open led error!\n ");
exit(1) ;
}
break;
default:
write_on = 15 ;
write_ret = write(fd , &write_on , 4);
if(write_ret < 0)
{
printf("led error!\n");
exit(1);
}
break;
}
/*
for(i=4;i<10;i++)
{
if(read_pin_buf==i && (i>6))
printf("read the PIN: PI%d-(key%d)\n",i,i-7);
if(read_pin_buf==i && (i<=6))
printf("read the PIN: PI%d-(key%d)\n",i,i+1);
}
if(read_pin_buf==10)
printf("read the PIN: PG9-(key3)\n");
if(read_pin_buf==11)
printf("read the PIN: PG11-(key4)\n");
*/
}
close(fd);
return 0;
}
|
the_stack_data/1100283.c | #include <resolv.h>
int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen)
{
int nsend, nrecv;
int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen, &nsend, &nrecv);
return r<0 || !anslen ? -1 : anslen;
}
weak_alias(__res_send, res_send);
|
the_stack_data/430783.c | /*
***************************************************************************
* Ralink Tech Inc.
* 4F, No. 2 Technology 5th Rd.
* Science-based Industrial Park
* Hsin-chu, Taiwan, R.O.C.
*
* (c) Copyright 2002-2007, Ralink Technology, Inc.
*
* All rights reserved. Ralink's source code is an unpublished work and the
* use of a copyright notice does not imply otherwise. This source code
* contains confidential trade secret material of Ralink Tech. Any attemp
* or participation in deciphering, decoding, reverse engineering or in any
* way altering the source code is stricitly prohibited, unless the prior
* written consent of Ralink Technology, Inc. is obtained.
***************************************************************************
Module Name:
cmm_mat.c
Abstract:
Support Mac Address Translation function.
Note:
MAC Address Translation(MAT) engine subroutines, we should just take care
packet to bridge.
Revision History:
Who When What
-------------- ---------- ----------------------------------------------
Shiang 02-26-2007 Init version
*/
#ifdef MAT_SUPPORT
#include "rt_config.h"
extern MATProtoOps MATProtoIPHandle;
extern MATProtoOps MATProtoARPHandle;
extern MATProtoOps MATProtoPPPoEDisHandle;
extern MATProtoOps MATProtoPPPoESesHandle;
extern MATProtoOps MATProtoIPv6Handle;
extern UCHAR SNAP_802_1H[];
extern UCHAR SNAP_BRIDGE_TUNNEL[];
#define MAX_MAT_NODE_ENTRY_NUM 128 /* We support maximum 128 node entry for our system */
#define MAT_NODE_ENTRY_SIZE 40 /*28 // bytes //change to 40 for IPv6Mac Table */
typedef struct _MATNodeEntry
{
UCHAR data[MAT_NODE_ENTRY_SIZE];
struct _MATNodeEntry *next;
}MATNodeEntry, *PMATNodeEntry;
#ifdef KMALLOC_BATCH
/*static MATNodeEntry *MATNodeEntryPoll = NULL; */
#endif
static MATProtoTable MATProtoTb[]=
{
{ETH_P_IP, &MATProtoIPHandle}, /* IP handler */
{ETH_P_ARP, &MATProtoARPHandle}, /* ARP handler */
{ETH_P_PPP_DISC, &MATProtoPPPoEDisHandle}, /* PPPoE discovery stage handler */
{ETH_P_PPP_SES, &MATProtoPPPoESesHandle}, /* PPPoE session stage handler */
{ETH_P_IPV6, &MATProtoIPv6Handle}, /* IPv6 handler */
};
#define MAX_MAT_SUPPORT_PROTO_NUM (sizeof(MATProtoTb)/sizeof(MATProtoTable))
/* --------------------------------- Public Function-------------------------------- */
NDIS_STATUS MATDBEntryFree(
IN MAT_STRUCT *pMatStruct,
IN PUCHAR NodeEntry)
{
#ifdef KMALLOC_BATCH
MATNodeEntry *pPtr, *pMATNodeEntryPoll;
pMATNodeEntryPoll = (MATNodeEntry *)pAd->MatCfg.MATNodeEntryPoll;
pPtr = (MATNodeEntry *)NodeEntry;
NdisZeroMemory(pPtr, sizeof(MATNodeEntry));
if (pMATNodeEntryPoll->next)
{
pPtr->next = pMATNodeEntryPoll->next;
pMATNodeEntryPoll->next = pPtr;
} else {
pMATNodeEntryPoll->next = pPtr;
}
#else
os_free_mem(NULL, NodeEntry);
NodeEntry = NULL;
#endif
return TRUE;
}
PUCHAR MATDBEntryAlloc(IN MAT_STRUCT *pMatStruct, IN UINT32 size)
{
#ifdef KMALLOC_BATCH
MATNodeEntry *pPtr = NULL, *pMATNodeEntryPoll;
pMATNodeEntryPoll = (MATNodeEntry *)pMatStruct->pMATNodeEntryPoll;
if (pMATNodeEntryPoll->next)
{
pPtr = pMATNodeEntryPoll->next;
pMATNodeEntryPoll->next = pPtr->next;
}
#else
UCHAR *pPtr = NULL;
os_alloc_mem(NULL, (PUCHAR *)&pPtr, size);
/*pPtr = kmalloc(size, MEM_ALLOC_FLAG); */
#endif
return (PUCHAR)pPtr;
}
VOID dumpPkt(PUCHAR pHeader, int len)
{
int i;
PSTRING tmp;
tmp = (PSTRING)pHeader;
DBGPRINT(RT_DEBUG_OFF, ("--StartDump\n"));
for(i=0;i<len; i++)
{
if ( (i%16==0) && (i!=0))
DBGPRINT(RT_DEBUG_OFF, ("\n"));
DBGPRINT(RT_DEBUG_OFF, ("%02x ", tmp[i]& 0xff));
}
DBGPRINT(RT_DEBUG_OFF, ("\n--EndDump\n"));
return;
}
/*
========================================================================
Routine Description:
For each out-going packet, check the upper layer protocol type if need
to handled by our APCLI convert engine. If yes, call corresponding handler
to handle it.
Arguments:
pAd =>Pointer to our adapter
pPkt =>pointer to the 802.11 header of outgoing packet
ifIdx =>Interface Index want to dispatch to.
Return Value:
Success =>
TRUE
Mapped mac address if found, else return specific default mac address
depends on the upper layer protocol type.
Error =>
FALSE.
Note:
1.the pPktHdr must be a 802.3 packet.
2.Maybe we need a TxD arguments?
3.We check every packet here including group mac address becasue we need to
handle DHCP packet.
========================================================================
*/
PUCHAR MATEngineTxHandle(
IN PRTMP_ADAPTER pAd,
IN PNDIS_PACKET pPkt,
IN UINT ifIdx,
IN UCHAR OpMode)
{
PUCHAR pLayerHdr = NULL, pPktHdr = NULL, pMacAddr = NULL;
UINT16 protoType, protoType_ori;
INT i;
struct _MATProtoOps *pHandle = NULL;
PUCHAR retSkb = NULL;
BOOLEAN bVLANPkt = FALSE;
if(pAd->MatCfg.status != MAT_ENGINE_STAT_INITED)
return NULL;
pPktHdr = GET_OS_PKT_DATAPTR(pPkt);
if (!pPktHdr)
return NULL;
protoType_ori = get_unaligned((PUINT16)(pPktHdr + 12));
/* Get the upper layer protocol type of this 802.3 pkt. */
protoType = OS_NTOHS(protoType_ori);
/* handle 802.1q enabled packet. Skip the VLAN tag field to get the protocol type. */
if (protoType == 0x8100)
{
protoType_ori = get_unaligned((PUINT16)(pPktHdr + 12 + 4));
protoType = OS_NTOHS(protoType_ori);
bVLANPkt = TRUE;
}
/* For differnet protocol, dispatch to specific handler */
for (i=0; i < MAX_MAT_SUPPORT_PROTO_NUM; i++)
{
if (protoType == MATProtoTb[i].protocol)
{
pHandle = MATProtoTb[i].pHandle; /* the pHandle must not be null! */
pLayerHdr = bVLANPkt ? (pPktHdr + MAT_VLAN_ETH_HDR_LEN) : (pPktHdr + MAT_ETHER_HDR_LEN);
#ifdef CONFIG_AP_SUPPORT
#ifdef APCLI_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_AP(pAd)
{
#ifdef MAC_REPEATER_SUPPORT
UCHAR tempIdx = ifIdx;
UCHAR CliIdx = 0xFF;
if (tempIdx >= 64)
{
CliIdx = ((tempIdx - 64) % 16);
tempIdx = ((tempIdx - 64) / 16);
pMacAddr = &pAd->ApCfg.ApCliTab[tempIdx].RepeaterCli[CliIdx].CurrentAddress[0];
}
else
#endif /* MAC_REPEATER_SUPPORT */
pMacAddr = &pAd->ApCfg.ApCliTab[ifIdx].wdev.if_addr[0];
}
#endif /* APCLI_SUPPORT */
#endif /* CONFIG_AP_SUPPORT */
#ifdef CONFIG_STA_SUPPORT
#ifdef ETH_CONVERT_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
pMacAddr = &pAd->CurrentAddress[0];
#endif /* ETH_CONVERT_SUPPORT */
#endif /* CONFIG_STA_SUPPORT */
if (pHandle->tx!=NULL)
retSkb = pHandle->tx((PVOID)&pAd->MatCfg, RTPKT_TO_OSPKT(pPkt), pLayerHdr, pMacAddr);
return retSkb;
}
}
return retSkb;
}
/*
========================================================================
Routine Description:
Depends on the Received packet, check the upper layer protocol type
and search for specific mapping table to find out the real destination
MAC address.
Arguments:
pAd =>Pointer to our adapter
pPkt =>pointer to the 802.11 header of receviced packet
infIdx =>Interface Index want to dispatch to.
Return Value:
Success =>
Mapped mac address if found, else return specific default mac address
depends on the upper layer protocol type.
Error =>
NULL
Note:
========================================================================
*/
PUCHAR MATEngineRxHandle(
IN PRTMP_ADAPTER pAd,
IN PNDIS_PACKET pPkt,
IN UINT infIdx)
{
PUCHAR pMacAddr = NULL;
PUCHAR pLayerHdr = NULL, pPktHdr = NULL;
UINT16 protoType;
INT i =0;
struct _MATProtoOps *pHandle = NULL;
if(pAd->MatCfg.status != MAT_ENGINE_STAT_INITED)
return NULL;
pPktHdr = GET_OS_PKT_DATAPTR(pPkt);
if (!pPktHdr)
return NULL;
/* If it's a multicast/broadcast packet, we do nothing. */
if (IS_GROUP_MAC(pPktHdr))
return NULL;
/* Get the upper layer protocol type of this 802.3 pkt and dispatch to specific handler */
protoType = OS_NTOHS(get_unaligned((PUINT16)(pPktHdr + 12)));
for (i=0; i<MAX_MAT_SUPPORT_PROTO_NUM; i++)
{
if (protoType == MATProtoTb[i].protocol)
{
pHandle = MATProtoTb[i].pHandle; /* the pHandle must not be null! */
pLayerHdr = (pPktHdr + MAT_ETHER_HDR_LEN);
/* RTMP_SEM_LOCK(&MATDBLock); */
if(pHandle->rx!=NULL)
pMacAddr = pHandle->rx((PVOID)&pAd->MatCfg, RTPKT_TO_OSPKT(pPkt), pLayerHdr, NULL);
/* RTMP_SEM_UNLOCK(&MATDBLock); */
break;
}
}
if (pMacAddr)
NdisMoveMemory(pPktHdr, pMacAddr, MAC_ADDR_LEN);
return NULL;
}
BOOLEAN MATPktRxNeedConvert(
IN PRTMP_ADAPTER pAd,
IN PNET_DEV net_dev)
{
#ifdef CONFIG_AP_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_AP(pAd)
{
#ifdef APCLI_SUPPORT
int i = 0;
/* Check if the packet will be send to apcli interface. */
while(i<MAX_APCLI_NUM)
{
/*BSSID match the ApCliBssid ?(from a valid AP) */
if ((pAd->ApCfg.ApCliTab[i].Valid == TRUE)
&& (net_dev == pAd->ApCfg.ApCliTab[i].wdev.if_dev)
#ifdef MWDS
&& (pAd->ApCfg.ApCliTab[i].bEnableMWDS == FALSE)
#endif /* MWDS */
)
return TRUE;
i++;
}
#endif /* APCLI_SUPPORT */
}
#endif /* CONFIG_AP_SUPPORT */
#ifdef CONFIG_STA_SUPPORT
#ifdef ETH_CONVERT_SUPPORT
IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
{
if (pAd->EthConvert.ECMode & ETH_CONVERT_MODE_DONGLE)
return TRUE;
}
#endif /* ETH_CONVERT_SUPPORT */
#endif /* CONFIG_STA_SUPPORT */
return FALSE;
}
NDIS_STATUS MATEngineExit(
IN RTMP_ADAPTER *pAd)
{
struct _MATProtoOps *pHandle = NULL;
int i;
if(pAd->MatCfg.status == MAT_ENGINE_STAT_EXITED)
return TRUE;
pAd->MatCfg.status = MAT_ENGINE_STAT_EXITED;
/* For each registered protocol, we call it's exit handler. */
for (i=0; i<MAX_MAT_SUPPORT_PROTO_NUM; i++)
{
pHandle = MATProtoTb[i].pHandle;
if (pHandle->exit!=NULL)
pHandle->exit(&pAd->MatCfg);
}
#ifdef KMALLOC_BATCH
/* Free the memory used to store node entries. */
if (pAd->MatCfg.pMATNodeEntryPoll)
{
os_free_mem(pAd, pAd->MatCfg.pMATNodeEntryPoll);
pAd->MatCfg.pMATNodeEntryPoll = NULL;
}
#endif
return TRUE;
}
NDIS_STATUS MATEngineInit(
IN RTMP_ADAPTER *pAd)
{
MATProtoOps *pHandle = NULL;
int i, status;
if(pAd->MatCfg.status == MAT_ENGINE_STAT_INITED)
return TRUE;
#ifdef KMALLOC_BATCH
/* Allocate memory for node entry, we totally allocate 128 entries and link them together. */
/* pAd->MatCfg.pMATNodeEntryPoll = kmalloc(sizeof(MATNodeEntry) * MAX_MAT_NODE_ENTRY_NUM, GFP_KERNEL); */
os_alloc_mem_suspend(NULL, (UCHAR **)&(pAd->MatCfg.pMATNodeEntryPoll), sizeof(MATNodeEntry) * MAX_MAT_NODE_ENTRY_NUM);
if (pAd->MatCfg.pMATNodeEntryPoll != NULL)
{
MATNodeEntry *pPtr=NULL;
NdisZeroMemory(pAd->MatCfg.pMATNodeEntryPoll, sizeof(MATNodeEntry) * MAX_MAT_NODE_ENTRY_NUM);
pPtr = pAd->MatCfg.pMATNodeEntryPoll;
for (i = 0; i < (MAX_MAT_NODE_ENTRY_NUM -1); i++)
{
pPtr->next = (MATNodeEntry *)(pPtr+1);
pPtr = pPtr->next;
}
pPtr->next = NULL;
} else {
return FALSE;
}
#endif
/* For each specific protocol, call it's init function. */
for (i = 0; i < MAX_MAT_SUPPORT_PROTO_NUM; i++)
{
pHandle = MATProtoTb[i].pHandle;
ASSERT(pHandle);
if (pHandle->init != NULL)
{
status = pHandle->init(&pAd->MatCfg);
if (status == FALSE)
{
DBGPRINT(RT_DEBUG_ERROR, ("MATEngine Init Protocol (0x%x) failed, Stop the MAT Funciton initialization failed!\n", MATProtoTb[i].protocol));
goto init_failed;
}
DBGPRINT(RT_DEBUG_TRACE, ("MATEngine Init Protocol (0x%04x) success!\n", MATProtoTb[i].protocol));
}
}
NdisAllocateSpinLock(pAd, &pAd->MatCfg.MATDBLock);
#ifdef MAC_REPEATER_SUPPORT
pAd->MatCfg.bMACRepeaterEn = FALSE;
#endif /* MAC_REPEATER_SUPPORT */
pAd->MatCfg.pPriv = (VOID *)pAd;
pAd->MatCfg.status = MAT_ENGINE_STAT_INITED;
return TRUE;
init_failed:
/* For each specific protocol, call it's exit function. */
for (i = 0; i < MAX_MAT_SUPPORT_PROTO_NUM; i++)
{
if ((pHandle = MATProtoTb[i].pHandle) != NULL)
{
if (pHandle->exit != NULL)
{
status = pHandle->exit(&pAd->MatCfg);
if (status == FALSE)
goto init_failed;
}
}
}
#ifdef KMALLOC_BATCH
if (pAd->MatCfg.pMATNodeEntryPoll)
os_free_mem(pAd, pAd->MatCfg.pMATNodeEntryPoll);
pAd->MatCfg.status = MAT_ENGINE_STAT_EXITED;
#endif /* KMALLOC_BATCH */
return FALSE;
}
#endif /* MAT_SUPPORT */
|
the_stack_data/117898.c | #include <sys/types.h>
#include <sys/timeb.h>
static struct timeb gorp = {
0L,
0,
5*60,
1
};
ftime(gorpp)
struct timeb *gorpp;
{
*gorpp = gorp;
return(0);
}
|
the_stack_data/170452440.c | #include <stdio.h>
int add_int(int, int);
float add_float(float, float);
int add_int(int num1, int num2)
{
return num1 + num2;
}
float add_float(float num1, float num2)
{
return num1 + num2;
}
// Ubuntu下执行:gcc -shared -Wl,-soname,adder -o adder.so -fPIC add.c |
the_stack_data/568836.c | /*
** 2010 May 05
**
** The author disclaims copyright to this source code. In place of
** a legal notice, here is a blessing:
**
** May you do good and not evil.
** May you find forgiveness for yourself and forgive others.
** May you share freely, never taking more than you give.
**
******************************************************************************
**
** This file contains the implementation of the Tcl [testvfs] command,
** used to create SQLite VFS implementations with various properties and
** instrumentation to support testing SQLite.
**
** testvfs VFSNAME ?OPTIONS?
**
** Available options are:
**
** -noshm BOOLEAN (True to omit shm methods. Default false)
** -default BOOLEAN (True to make the vfs default. Default false)
** -szosfile INTEGER (Value for sqlite3_vfs.szOsFile)
** -mxpathname INTEGER (Value for sqlite3_vfs.mxPathname)
** -iversion INTEGER (Value for sqlite3_vfs.iVersion)
*/
#if SQLITE_TEST /* This file is used for testing only */
#include "sqlite3.h"
#include "sqliteInt.h"
#if defined(INCLUDE_SQLITE_TCL_H)
# include "sqlite_tcl.h"
#else
# include "tcl.h"
#endif
typedef struct Testvfs Testvfs;
typedef struct TestvfsShm TestvfsShm;
typedef struct TestvfsBuffer TestvfsBuffer;
typedef struct TestvfsFile TestvfsFile;
typedef struct TestvfsFd TestvfsFd;
/*
** An open file handle.
*/
struct TestvfsFile {
sqlite3_file base; /* Base class. Must be first */
TestvfsFd *pFd; /* File data */
};
#define tvfsGetFd(pFile) (((TestvfsFile *)pFile)->pFd)
struct TestvfsFd {
sqlite3_vfs *pVfs; /* The VFS */
const char *zFilename; /* Filename as passed to xOpen() */
sqlite3_file *pReal; /* The real, underlying file descriptor */
Tcl_Obj *pShmId; /* Shared memory id for Tcl callbacks */
TestvfsBuffer *pShm; /* Shared memory buffer */
u32 excllock; /* Mask of exclusive locks */
u32 sharedlock; /* Mask of shared locks */
TestvfsFd *pNext; /* Next handle opened on the same file */
};
#define FAULT_INJECT_NONE 0
#define FAULT_INJECT_TRANSIENT 1
#define FAULT_INJECT_PERSISTENT 2
typedef struct TestFaultInject TestFaultInject;
struct TestFaultInject {
int iCnt; /* Remaining calls before fault injection */
int eFault; /* A FAULT_INJECT_* value */
int nFail; /* Number of faults injected */
};
/*
** An instance of this structure is allocated for each VFS created. The
** sqlite3_vfs.pAppData field of the VFS structure registered with SQLite
** is set to point to it.
*/
struct Testvfs {
char *zName; /* Name of this VFS */
sqlite3_vfs *pParent; /* The VFS to use for file IO */
sqlite3_vfs *pVfs; /* The testvfs registered with SQLite */
Tcl_Interp *interp; /* Interpreter to run script in */
Tcl_Obj *pScript; /* Script to execute */
TestvfsBuffer *pBuffer; /* List of shared buffers */
int isNoshm;
int isFullshm;
int mask; /* Mask controlling [script] and [ioerr] */
TestFaultInject ioerr_err;
TestFaultInject full_err;
TestFaultInject cantopen_err;
#if 0
int iIoerrCnt;
int ioerr;
int nIoerrFail;
int iFullCnt;
int fullerr;
int nFullFail;
#endif
int iDevchar;
int iSectorsize;
};
/*
** The Testvfs.mask variable is set to a combination of the following.
** If a bit is clear in Testvfs.mask, then calls made by SQLite to the
** corresponding VFS method is ignored for purposes of:
**
** + Simulating IO errors, and
** + Invoking the Tcl callback script.
*/
#define TESTVFS_SHMOPEN_MASK 0x00000001
#define TESTVFS_SHMLOCK_MASK 0x00000010
#define TESTVFS_SHMMAP_MASK 0x00000020
#define TESTVFS_SHMBARRIER_MASK 0x00000040
#define TESTVFS_SHMCLOSE_MASK 0x00000080
#define TESTVFS_OPEN_MASK 0x00000100
#define TESTVFS_SYNC_MASK 0x00000200
#define TESTVFS_DELETE_MASK 0x00000400
#define TESTVFS_CLOSE_MASK 0x00000800
#define TESTVFS_WRITE_MASK 0x00001000
#define TESTVFS_TRUNCATE_MASK 0x00002000
#define TESTVFS_ACCESS_MASK 0x00004000
#define TESTVFS_FULLPATHNAME_MASK 0x00008000
#define TESTVFS_READ_MASK 0x00010000
#define TESTVFS_UNLOCK_MASK 0x00020000
#define TESTVFS_LOCK_MASK 0x00040000
#define TESTVFS_CKLOCK_MASK 0x00080000
#define TESTVFS_FCNTL_MASK 0x00100000
#define TESTVFS_ALL_MASK 0x001FFFFF
#define TESTVFS_MAX_PAGES 1024
/*
** A shared-memory buffer. There is one of these objects for each shared
** memory region opened by clients. If two clients open the same file,
** there are two TestvfsFile structures but only one TestvfsBuffer structure.
*/
struct TestvfsBuffer {
char *zFile; /* Associated file name */
int pgsz; /* Page size */
u8 *aPage[TESTVFS_MAX_PAGES]; /* Array of ckalloc'd pages */
TestvfsFd *pFile; /* List of open handles */
TestvfsBuffer *pNext; /* Next in linked list of all buffers */
};
#define PARENTVFS(x) (((Testvfs *)((x)->pAppData))->pParent)
#define TESTVFS_MAX_ARGS 12
/*
** Method declarations for TestvfsFile.
*/
static int tvfsClose(sqlite3_file*);
static int tvfsRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
static int tvfsWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
static int tvfsTruncate(sqlite3_file*, sqlite3_int64 size);
static int tvfsSync(sqlite3_file*, int flags);
static int tvfsFileSize(sqlite3_file*, sqlite3_int64 *pSize);
static int tvfsLock(sqlite3_file*, int);
static int tvfsUnlock(sqlite3_file*, int);
static int tvfsCheckReservedLock(sqlite3_file*, int *);
static int tvfsFileControl(sqlite3_file*, int op, void *pArg);
static int tvfsSectorSize(sqlite3_file*);
static int tvfsDeviceCharacteristics(sqlite3_file*);
/*
** Method declarations for tvfs_vfs.
*/
static int tvfsOpen(sqlite3_vfs*, const char *, sqlite3_file*, int , int *);
static int tvfsDelete(sqlite3_vfs*, const char *zName, int syncDir);
static int tvfsAccess(sqlite3_vfs*, const char *zName, int flags, int *);
static int tvfsFullPathname(sqlite3_vfs*, const char *zName, int, char *zOut);
#ifndef SQLITE_OMIT_LOAD_EXTENSION
static void *tvfsDlOpen(sqlite3_vfs*, const char *zFilename);
static void tvfsDlError(sqlite3_vfs*, int nByte, char *zErrMsg);
static void (*tvfsDlSym(sqlite3_vfs*,void*, const char *zSymbol))(void);
static void tvfsDlClose(sqlite3_vfs*, void*);
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
static int tvfsRandomness(sqlite3_vfs*, int nByte, char *zOut);
static int tvfsSleep(sqlite3_vfs*, int microseconds);
static int tvfsCurrentTime(sqlite3_vfs*, double*);
static int tvfsShmOpen(sqlite3_file*);
static int tvfsShmLock(sqlite3_file*, int , int, int);
static int tvfsShmMap(sqlite3_file*,int,int,int, void volatile **);
static void tvfsShmBarrier(sqlite3_file*);
static int tvfsShmUnmap(sqlite3_file*, int);
static int tvfsFetch(sqlite3_file*, sqlite3_int64, int, void**);
static int tvfsUnfetch(sqlite3_file*, sqlite3_int64, void*);
static sqlite3_io_methods tvfs_io_methods = {
3, /* iVersion */
tvfsClose, /* xClose */
tvfsRead, /* xRead */
tvfsWrite, /* xWrite */
tvfsTruncate, /* xTruncate */
tvfsSync, /* xSync */
tvfsFileSize, /* xFileSize */
tvfsLock, /* xLock */
tvfsUnlock, /* xUnlock */
tvfsCheckReservedLock, /* xCheckReservedLock */
tvfsFileControl, /* xFileControl */
tvfsSectorSize, /* xSectorSize */
tvfsDeviceCharacteristics, /* xDeviceCharacteristics */
tvfsShmMap, /* xShmMap */
tvfsShmLock, /* xShmLock */
tvfsShmBarrier, /* xShmBarrier */
tvfsShmUnmap, /* xShmUnmap */
tvfsFetch,
tvfsUnfetch
};
static int tvfsResultCode(Testvfs *p, int *pRc){
struct errcode {
int eCode;
const char *zCode;
} aCode[] = {
{ SQLITE_OK, "SQLITE_OK" },
{ SQLITE_ERROR, "SQLITE_ERROR" },
{ SQLITE_IOERR, "SQLITE_IOERR" },
{ SQLITE_LOCKED, "SQLITE_LOCKED" },
{ SQLITE_BUSY, "SQLITE_BUSY" },
{ SQLITE_READONLY, "SQLITE_READONLY" },
{ SQLITE_READONLY_CANTINIT, "SQLITE_READONLY_CANTINIT" },
{ -1, "SQLITE_OMIT" },
};
const char *z;
int i;
z = Tcl_GetStringResult(p->interp);
for(i=0; i<ArraySize(aCode); i++){
if( 0==strcmp(z, aCode[i].zCode) ){
*pRc = aCode[i].eCode;
return 1;
}
}
return 0;
}
static int tvfsInjectFault(TestFaultInject *p){
int ret = 0;
if( p->eFault ){
p->iCnt--;
if( p->iCnt==0 || (p->iCnt<0 && p->eFault==FAULT_INJECT_PERSISTENT ) ){
ret = 1;
p->nFail++;
}
}
return ret;
}
static int tvfsInjectIoerr(Testvfs *p){
return tvfsInjectFault(&p->ioerr_err);
}
static int tvfsInjectFullerr(Testvfs *p){
return tvfsInjectFault(&p->full_err);
}
static int tvfsInjectCantopenerr(Testvfs *p){
return tvfsInjectFault(&p->cantopen_err);
}
static void tvfsExecTcl(
Testvfs *p,
const char *zMethod,
Tcl_Obj *arg1,
Tcl_Obj *arg2,
Tcl_Obj *arg3,
Tcl_Obj *arg4
){
int rc; /* Return code from Tcl_EvalObj() */
Tcl_Obj *pEval;
assert( p->pScript );
assert( zMethod );
assert( p );
assert( arg2==0 || arg1!=0 );
assert( arg3==0 || arg2!=0 );
pEval = Tcl_DuplicateObj(p->pScript);
Tcl_IncrRefCount(p->pScript);
Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zMethod, -1));
if( arg1 ) Tcl_ListObjAppendElement(p->interp, pEval, arg1);
if( arg2 ) Tcl_ListObjAppendElement(p->interp, pEval, arg2);
if( arg3 ) Tcl_ListObjAppendElement(p->interp, pEval, arg3);
if( arg4 ) Tcl_ListObjAppendElement(p->interp, pEval, arg4);
rc = Tcl_EvalObjEx(p->interp, pEval, TCL_EVAL_GLOBAL);
if( rc!=TCL_OK ){
Tcl_BackgroundError(p->interp);
Tcl_ResetResult(p->interp);
}
}
/*
** Close an tvfs-file.
*/
static int tvfsClose(sqlite3_file *pFile){
TestvfsFile *pTestfile = (TestvfsFile *)pFile;
TestvfsFd *pFd = pTestfile->pFd;
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_CLOSE_MASK ){
tvfsExecTcl(p, "xClose",
Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId, 0, 0
);
}
if( pFd->pShmId ){
Tcl_DecrRefCount(pFd->pShmId);
pFd->pShmId = 0;
}
if( pFile->pMethods ){
ckfree((char *)pFile->pMethods);
}
sqlite3OsClose(pFd->pReal);
ckfree((char *)pFd);
pTestfile->pFd = 0;
return SQLITE_OK;
}
/*
** Read data from an tvfs-file.
*/
static int tvfsRead(
sqlite3_file *pFile,
void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_READ_MASK ){
tvfsExecTcl(p, "xRead",
Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId, 0, 0
);
tvfsResultCode(p, &rc);
}
if( rc==SQLITE_OK && p->mask&TESTVFS_READ_MASK && tvfsInjectIoerr(p) ){
rc = SQLITE_IOERR;
}
if( rc==SQLITE_OK ){
rc = sqlite3OsRead(pFd->pReal, zBuf, iAmt, iOfst);
}
return rc;
}
/*
** Write data to an tvfs-file.
*/
static int tvfsWrite(
sqlite3_file *pFile,
const void *zBuf,
int iAmt,
sqlite_int64 iOfst
){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_WRITE_MASK ){
tvfsExecTcl(p, "xWrite",
Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId,
Tcl_NewWideIntObj(iOfst), Tcl_NewIntObj(iAmt)
);
tvfsResultCode(p, &rc);
if( rc<0 ) return SQLITE_OK;
}
if( rc==SQLITE_OK && tvfsInjectFullerr(p) ){
rc = SQLITE_FULL;
}
if( rc==SQLITE_OK && p->mask&TESTVFS_WRITE_MASK && tvfsInjectIoerr(p) ){
rc = SQLITE_IOERR;
}
if( rc==SQLITE_OK ){
rc = sqlite3OsWrite(pFd->pReal, zBuf, iAmt, iOfst);
}
return rc;
}
/*
** Truncate an tvfs-file.
*/
static int tvfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_TRUNCATE_MASK ){
tvfsExecTcl(p, "xTruncate",
Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId, 0, 0
);
tvfsResultCode(p, &rc);
}
if( rc==SQLITE_OK ){
rc = sqlite3OsTruncate(pFd->pReal, size);
}
return rc;
}
/*
** Sync an tvfs-file.
*/
static int tvfsSync(sqlite3_file *pFile, int flags){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_SYNC_MASK ){
char *zFlags = 0;
switch( flags ){
case SQLITE_SYNC_NORMAL:
zFlags = "normal";
break;
case SQLITE_SYNC_FULL:
zFlags = "full";
break;
case SQLITE_SYNC_NORMAL|SQLITE_SYNC_DATAONLY:
zFlags = "normal|dataonly";
break;
case SQLITE_SYNC_FULL|SQLITE_SYNC_DATAONLY:
zFlags = "full|dataonly";
break;
default:
assert(0);
}
tvfsExecTcl(p, "xSync",
Tcl_NewStringObj(pFd->zFilename, -1), pFd->pShmId,
Tcl_NewStringObj(zFlags, -1), 0
);
tvfsResultCode(p, &rc);
}
if( rc==SQLITE_OK && tvfsInjectFullerr(p) ) rc = SQLITE_FULL;
if( rc==SQLITE_OK ){
rc = sqlite3OsSync(pFd->pReal, flags);
}
return rc;
}
/*
** Return the current file-size of an tvfs-file.
*/
static int tvfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
TestvfsFd *p = tvfsGetFd(pFile);
return sqlite3OsFileSize(p->pReal, pSize);
}
/*
** Lock an tvfs-file.
*/
static int tvfsLock(sqlite3_file *pFile, int eLock){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_LOCK_MASK ){
char zLock[30];
sqlite3_snprintf(sizeof(zLock),zLock,"%d",eLock);
tvfsExecTcl(p, "xLock", Tcl_NewStringObj(pFd->zFilename, -1),
Tcl_NewStringObj(zLock, -1), 0, 0);
}
return sqlite3OsLock(pFd->pReal, eLock);
}
/*
** Unlock an tvfs-file.
*/
static int tvfsUnlock(sqlite3_file *pFile, int eLock){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_UNLOCK_MASK ){
char zLock[30];
sqlite3_snprintf(sizeof(zLock),zLock,"%d",eLock);
tvfsExecTcl(p, "xUnlock", Tcl_NewStringObj(pFd->zFilename, -1),
Tcl_NewStringObj(zLock, -1), 0, 0);
}
if( p->mask&TESTVFS_WRITE_MASK && tvfsInjectIoerr(p) ){
return SQLITE_IOERR_UNLOCK;
}
return sqlite3OsUnlock(pFd->pReal, eLock);
}
/*
** Check if another file-handle holds a RESERVED lock on an tvfs-file.
*/
static int tvfsCheckReservedLock(sqlite3_file *pFile, int *pResOut){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_CKLOCK_MASK ){
tvfsExecTcl(p, "xCheckReservedLock", Tcl_NewStringObj(pFd->zFilename, -1),
0, 0, 0);
}
return sqlite3OsCheckReservedLock(pFd->pReal, pResOut);
}
/*
** File control method. For custom operations on an tvfs-file.
*/
static int tvfsFileControl(sqlite3_file *pFile, int op, void *pArg){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( op==SQLITE_FCNTL_PRAGMA ){
char **argv = (char**)pArg;
if( sqlite3_stricmp(argv[1],"error")==0 ){
int rc = SQLITE_ERROR;
if( argv[2] ){
const char *z = argv[2];
int x = atoi(z);
if( x ){
rc = x;
while( sqlite3Isdigit(z[0]) ){ z++; }
while( sqlite3Isspace(z[0]) ){ z++; }
}
if( z[0] ) argv[0] = sqlite3_mprintf("%s", z);
}
return rc;
}
if( sqlite3_stricmp(argv[1], "filename")==0 ){
argv[0] = sqlite3_mprintf("%s", pFd->zFilename);
return SQLITE_OK;
}
}
if( p->pScript && (p->mask&TESTVFS_FCNTL_MASK) ){
struct Fcntl {
int iFnctl;
const char *zFnctl;
} aF[] = {
{ SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, "BEGIN_ATOMIC_WRITE" },
{ SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, "COMMIT_ATOMIC_WRITE" },
};
int i;
for(i=0; i<sizeof(aF)/sizeof(aF[0]); i++){
if( op==aF[i].iFnctl ) break;
}
if( i<sizeof(aF)/sizeof(aF[0]) ){
int rc = 0;
tvfsExecTcl(p, "xFileControl",
Tcl_NewStringObj(pFd->zFilename, -1),
Tcl_NewStringObj(aF[i].zFnctl, -1),
0, 0
);
tvfsResultCode(p, &rc);
if( rc ) return rc;
}
}
return sqlite3OsFileControl(pFd->pReal, op, pArg);
}
/*
** Return the sector-size in bytes for an tvfs-file.
*/
static int tvfsSectorSize(sqlite3_file *pFile){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->iSectorsize>=0 ){
return p->iSectorsize;
}
return sqlite3OsSectorSize(pFd->pReal);
}
/*
** Return the device characteristic flags supported by an tvfs-file.
*/
static int tvfsDeviceCharacteristics(sqlite3_file *pFile){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)pFd->pVfs->pAppData;
if( p->iDevchar>=0 ){
return p->iDevchar;
}
return sqlite3OsDeviceCharacteristics(pFd->pReal);
}
/*
** Open an tvfs file handle.
*/
static int tvfsOpen(
sqlite3_vfs *pVfs,
const char *zName,
sqlite3_file *pFile,
int flags,
int *pOutFlags
){
int rc;
TestvfsFile *pTestfile = (TestvfsFile *)pFile;
TestvfsFd *pFd;
Tcl_Obj *pId = 0;
Testvfs *p = (Testvfs *)pVfs->pAppData;
pFd = (TestvfsFd *)ckalloc(sizeof(TestvfsFd) + PARENTVFS(pVfs)->szOsFile);
memset(pFd, 0, sizeof(TestvfsFd) + PARENTVFS(pVfs)->szOsFile);
pFd->pShm = 0;
pFd->pShmId = 0;
pFd->zFilename = zName;
pFd->pVfs = pVfs;
pFd->pReal = (sqlite3_file *)&pFd[1];
memset(pTestfile, 0, sizeof(TestvfsFile));
pTestfile->pFd = pFd;
/* Evaluate the Tcl script:
**
** SCRIPT xOpen FILENAME KEY-VALUE-ARGS
**
** If the script returns an SQLite error code other than SQLITE_OK, an
** error is returned to the caller. If it returns SQLITE_OK, the new
** connection is named "anon". Otherwise, the value returned by the
** script is used as the connection name.
*/
Tcl_ResetResult(p->interp);
if( p->pScript && p->mask&TESTVFS_OPEN_MASK ){
Tcl_Obj *pArg = Tcl_NewObj();
Tcl_IncrRefCount(pArg);
if( flags&SQLITE_OPEN_MAIN_DB ){
const char *z = &zName[strlen(zName)+1];
while( *z ){
Tcl_ListObjAppendElement(0, pArg, Tcl_NewStringObj(z, -1));
z += strlen(z) + 1;
Tcl_ListObjAppendElement(0, pArg, Tcl_NewStringObj(z, -1));
z += strlen(z) + 1;
}
}
tvfsExecTcl(p, "xOpen", Tcl_NewStringObj(pFd->zFilename, -1), pArg, 0, 0);
Tcl_DecrRefCount(pArg);
if( tvfsResultCode(p, &rc) ){
if( rc!=SQLITE_OK ) return rc;
}else{
pId = Tcl_GetObjResult(p->interp);
}
}
if( (p->mask&TESTVFS_OPEN_MASK) && tvfsInjectIoerr(p) ) return SQLITE_IOERR;
if( tvfsInjectCantopenerr(p) ) return SQLITE_CANTOPEN;
if( tvfsInjectFullerr(p) ) return SQLITE_FULL;
if( !pId ){
pId = Tcl_NewStringObj("anon", -1);
}
Tcl_IncrRefCount(pId);
pFd->pShmId = pId;
Tcl_ResetResult(p->interp);
rc = sqlite3OsOpen(PARENTVFS(pVfs), zName, pFd->pReal, flags, pOutFlags);
if( pFd->pReal->pMethods ){
sqlite3_io_methods *pMethods;
int nByte;
if( pVfs->iVersion>1 ){
nByte = sizeof(sqlite3_io_methods);
}else{
nByte = offsetof(sqlite3_io_methods, xShmMap);
}
pMethods = (sqlite3_io_methods *)ckalloc(nByte);
memcpy(pMethods, &tvfs_io_methods, nByte);
pMethods->iVersion = pFd->pReal->pMethods->iVersion;
if( pMethods->iVersion>pVfs->iVersion ){
pMethods->iVersion = pVfs->iVersion;
}
if( pVfs->iVersion>1 && ((Testvfs *)pVfs->pAppData)->isNoshm ){
pMethods->xShmUnmap = 0;
pMethods->xShmLock = 0;
pMethods->xShmBarrier = 0;
pMethods->xShmMap = 0;
}
pFile->pMethods = pMethods;
}
return rc;
}
/*
** Delete the file located at zPath. If the dirSync argument is true,
** ensure the file-system modifications are synced to disk before
** returning.
*/
static int tvfsDelete(sqlite3_vfs *pVfs, const char *zPath, int dirSync){
int rc = SQLITE_OK;
Testvfs *p = (Testvfs *)pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_DELETE_MASK ){
tvfsExecTcl(p, "xDelete",
Tcl_NewStringObj(zPath, -1), Tcl_NewIntObj(dirSync), 0, 0
);
tvfsResultCode(p, &rc);
}
if( rc==SQLITE_OK ){
rc = sqlite3OsDelete(PARENTVFS(pVfs), zPath, dirSync);
}
return rc;
}
/*
** Test for access permissions. Return true if the requested permission
** is available, or false otherwise.
*/
static int tvfsAccess(
sqlite3_vfs *pVfs,
const char *zPath,
int flags,
int *pResOut
){
Testvfs *p = (Testvfs *)pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_ACCESS_MASK ){
int rc;
char *zArg = 0;
if( flags==SQLITE_ACCESS_EXISTS ) zArg = "SQLITE_ACCESS_EXISTS";
if( flags==SQLITE_ACCESS_READWRITE ) zArg = "SQLITE_ACCESS_READWRITE";
if( flags==SQLITE_ACCESS_READ ) zArg = "SQLITE_ACCESS_READ";
tvfsExecTcl(p, "xAccess",
Tcl_NewStringObj(zPath, -1), Tcl_NewStringObj(zArg, -1), 0, 0
);
if( tvfsResultCode(p, &rc) ){
if( rc!=SQLITE_OK ) return rc;
}else{
Tcl_Interp *interp = p->interp;
if( TCL_OK==Tcl_GetBooleanFromObj(0, Tcl_GetObjResult(interp), pResOut) ){
return SQLITE_OK;
}
}
}
return sqlite3OsAccess(PARENTVFS(pVfs), zPath, flags, pResOut);
}
/*
** Populate buffer zOut with the full canonical pathname corresponding
** to the pathname in zPath. zOut is guaranteed to point to a buffer
** of at least (DEVSYM_MAX_PATHNAME+1) bytes.
*/
static int tvfsFullPathname(
sqlite3_vfs *pVfs,
const char *zPath,
int nOut,
char *zOut
){
Testvfs *p = (Testvfs *)pVfs->pAppData;
if( p->pScript && p->mask&TESTVFS_FULLPATHNAME_MASK ){
int rc;
tvfsExecTcl(p, "xFullPathname", Tcl_NewStringObj(zPath, -1), 0, 0, 0);
if( tvfsResultCode(p, &rc) ){
if( rc!=SQLITE_OK ) return rc;
}
}
return sqlite3OsFullPathname(PARENTVFS(pVfs), zPath, nOut, zOut);
}
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/*
** Open the dynamic library located at zPath and return a handle.
*/
static void *tvfsDlOpen(sqlite3_vfs *pVfs, const char *zPath){
return sqlite3OsDlOpen(PARENTVFS(pVfs), zPath);
}
/*
** Populate the buffer zErrMsg (size nByte bytes) with a human readable
** utf-8 string describing the most recent error encountered associated
** with dynamic libraries.
*/
static void tvfsDlError(sqlite3_vfs *pVfs, int nByte, char *zErrMsg){
sqlite3OsDlError(PARENTVFS(pVfs), nByte, zErrMsg);
}
/*
** Return a pointer to the symbol zSymbol in the dynamic library pHandle.
*/
static void (*tvfsDlSym(sqlite3_vfs *pVfs, void *p, const char *zSym))(void){
return sqlite3OsDlSym(PARENTVFS(pVfs), p, zSym);
}
/*
** Close the dynamic library handle pHandle.
*/
static void tvfsDlClose(sqlite3_vfs *pVfs, void *pHandle){
sqlite3OsDlClose(PARENTVFS(pVfs), pHandle);
}
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
/*
** Populate the buffer pointed to by zBufOut with nByte bytes of
** random data.
*/
static int tvfsRandomness(sqlite3_vfs *pVfs, int nByte, char *zBufOut){
return sqlite3OsRandomness(PARENTVFS(pVfs), nByte, zBufOut);
}
/*
** Sleep for nMicro microseconds. Return the number of microseconds
** actually slept.
*/
static int tvfsSleep(sqlite3_vfs *pVfs, int nMicro){
return sqlite3OsSleep(PARENTVFS(pVfs), nMicro);
}
/*
** Return the current time as a Julian Day number in *pTimeOut.
*/
static int tvfsCurrentTime(sqlite3_vfs *pVfs, double *pTimeOut){
return PARENTVFS(pVfs)->xCurrentTime(PARENTVFS(pVfs), pTimeOut);
}
static int tvfsShmOpen(sqlite3_file *pFile){
Testvfs *p;
int rc = SQLITE_OK; /* Return code */
TestvfsBuffer *pBuffer; /* Buffer to open connection to */
TestvfsFd *pFd; /* The testvfs file structure */
pFd = tvfsGetFd(pFile);
p = (Testvfs *)pFd->pVfs->pAppData;
assert( 0==p->isFullshm );
assert( pFd->pShmId && pFd->pShm==0 && pFd->pNext==0 );
/* Evaluate the Tcl script:
**
** SCRIPT xShmOpen FILENAME
*/
Tcl_ResetResult(p->interp);
if( p->pScript && p->mask&TESTVFS_SHMOPEN_MASK ){
tvfsExecTcl(p, "xShmOpen", Tcl_NewStringObj(pFd->zFilename, -1), 0, 0, 0);
if( tvfsResultCode(p, &rc) ){
if( rc!=SQLITE_OK ) return rc;
}
}
assert( rc==SQLITE_OK );
if( p->mask&TESTVFS_SHMOPEN_MASK && tvfsInjectIoerr(p) ){
return SQLITE_IOERR;
}
/* Search for a TestvfsBuffer. Create a new one if required. */
for(pBuffer=p->pBuffer; pBuffer; pBuffer=pBuffer->pNext){
if( 0==strcmp(pFd->zFilename, pBuffer->zFile) ) break;
}
if( !pBuffer ){
int szName = (int)strlen(pFd->zFilename);
int nByte = sizeof(TestvfsBuffer) + szName + 1;
pBuffer = (TestvfsBuffer *)ckalloc(nByte);
memset(pBuffer, 0, nByte);
pBuffer->zFile = (char *)&pBuffer[1];
memcpy(pBuffer->zFile, pFd->zFilename, szName+1);
pBuffer->pNext = p->pBuffer;
p->pBuffer = pBuffer;
}
/* Connect the TestvfsBuffer to the new TestvfsShm handle and return. */
pFd->pNext = pBuffer->pFile;
pBuffer->pFile = pFd;
pFd->pShm = pBuffer;
return rc;
}
static void tvfsAllocPage(TestvfsBuffer *p, int iPage, int pgsz){
assert( iPage<TESTVFS_MAX_PAGES );
if( p->aPage[iPage]==0 ){
p->aPage[iPage] = (u8 *)ckalloc(pgsz);
memset(p->aPage[iPage], 0, pgsz);
p->pgsz = pgsz;
}
}
static int tvfsShmMap(
sqlite3_file *pFile, /* Handle open on database file */
int iPage, /* Page to retrieve */
int pgsz, /* Size of pages */
int isWrite, /* True to extend file if necessary */
void volatile **pp /* OUT: Mapped memory */
){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData);
if( p->isFullshm ){
return sqlite3OsShmMap(pFd->pReal, iPage, pgsz, isWrite, pp);
}
if( 0==pFd->pShm ){
rc = tvfsShmOpen(pFile);
if( rc!=SQLITE_OK ){
return rc;
}
}
if( p->pScript && p->mask&TESTVFS_SHMMAP_MASK ){
Tcl_Obj *pArg = Tcl_NewObj();
Tcl_IncrRefCount(pArg);
Tcl_ListObjAppendElement(p->interp, pArg, Tcl_NewIntObj(iPage));
Tcl_ListObjAppendElement(p->interp, pArg, Tcl_NewIntObj(pgsz));
Tcl_ListObjAppendElement(p->interp, pArg, Tcl_NewIntObj(isWrite));
tvfsExecTcl(p, "xShmMap",
Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, pArg, 0
);
tvfsResultCode(p, &rc);
Tcl_DecrRefCount(pArg);
}
if( rc==SQLITE_OK && p->mask&TESTVFS_SHMMAP_MASK && tvfsInjectIoerr(p) ){
rc = SQLITE_IOERR;
}
if( rc==SQLITE_OK && isWrite && !pFd->pShm->aPage[iPage] ){
tvfsAllocPage(pFd->pShm, iPage, pgsz);
}
if( rc==SQLITE_OK || rc==SQLITE_READONLY ){
*pp = (void volatile *)pFd->pShm->aPage[iPage];
}
return rc;
}
static int tvfsShmLock(
sqlite3_file *pFile,
int ofst,
int n,
int flags
){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData);
int nLock;
char zLock[80];
if( p->isFullshm ){
return sqlite3OsShmLock(pFd->pReal, ofst, n, flags);
}
if( p->pScript && p->mask&TESTVFS_SHMLOCK_MASK ){
sqlite3_snprintf(sizeof(zLock), zLock, "%d %d", ofst, n);
nLock = (int)strlen(zLock);
if( flags & SQLITE_SHM_LOCK ){
strcpy(&zLock[nLock], " lock");
}else{
strcpy(&zLock[nLock], " unlock");
}
nLock += (int)strlen(&zLock[nLock]);
if( flags & SQLITE_SHM_SHARED ){
strcpy(&zLock[nLock], " shared");
}else{
strcpy(&zLock[nLock], " exclusive");
}
tvfsExecTcl(p, "xShmLock",
Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId,
Tcl_NewStringObj(zLock, -1), 0
);
tvfsResultCode(p, &rc);
}
if( rc==SQLITE_OK && p->mask&TESTVFS_SHMLOCK_MASK && tvfsInjectIoerr(p) ){
rc = SQLITE_IOERR;
}
if( rc==SQLITE_OK ){
int isLock = (flags & SQLITE_SHM_LOCK);
int isExcl = (flags & SQLITE_SHM_EXCLUSIVE);
u32 mask = (((1<<n)-1) << ofst);
if( isLock ){
TestvfsFd *p2;
for(p2=pFd->pShm->pFile; p2; p2=p2->pNext){
if( p2==pFd ) continue;
if( (p2->excllock&mask) || (isExcl && p2->sharedlock&mask) ){
rc = SQLITE_BUSY;
break;
}
}
if( rc==SQLITE_OK ){
if( isExcl ) pFd->excllock |= mask;
if( !isExcl ) pFd->sharedlock |= mask;
}
}else{
if( isExcl ) pFd->excllock &= (~mask);
if( !isExcl ) pFd->sharedlock &= (~mask);
}
}
return rc;
}
static void tvfsShmBarrier(sqlite3_file *pFile){
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData);
if( p->pScript && p->mask&TESTVFS_SHMBARRIER_MASK ){
const char *z = pFd->pShm ? pFd->pShm->zFile : "";
tvfsExecTcl(p, "xShmBarrier", Tcl_NewStringObj(z, -1), pFd->pShmId, 0, 0);
}
if( p->isFullshm ){
sqlite3OsShmBarrier(pFd->pReal);
return;
}
}
static int tvfsShmUnmap(
sqlite3_file *pFile,
int deleteFlag
){
int rc = SQLITE_OK;
TestvfsFd *pFd = tvfsGetFd(pFile);
Testvfs *p = (Testvfs *)(pFd->pVfs->pAppData);
TestvfsBuffer *pBuffer = pFd->pShm;
TestvfsFd **ppFd;
if( p->isFullshm ){
return sqlite3OsShmUnmap(pFd->pReal, deleteFlag);
}
if( !pBuffer ) return SQLITE_OK;
assert( pFd->pShmId && pFd->pShm );
if( p->pScript && p->mask&TESTVFS_SHMCLOSE_MASK ){
tvfsExecTcl(p, "xShmUnmap",
Tcl_NewStringObj(pFd->pShm->zFile, -1), pFd->pShmId, 0, 0
);
tvfsResultCode(p, &rc);
}
for(ppFd=&pBuffer->pFile; *ppFd!=pFd; ppFd=&((*ppFd)->pNext));
assert( (*ppFd)==pFd );
*ppFd = pFd->pNext;
pFd->pNext = 0;
if( pBuffer->pFile==0 ){
int i;
TestvfsBuffer **pp;
for(pp=&p->pBuffer; *pp!=pBuffer; pp=&((*pp)->pNext));
*pp = (*pp)->pNext;
for(i=0; pBuffer->aPage[i]; i++){
ckfree((char *)pBuffer->aPage[i]);
}
ckfree((char *)pBuffer);
}
pFd->pShm = 0;
return rc;
}
static int tvfsFetch(
sqlite3_file *pFile,
sqlite3_int64 iOfst,
int iAmt,
void **pp
){
TestvfsFd *pFd = tvfsGetFd(pFile);
return sqlite3OsFetch(pFd->pReal, iOfst, iAmt, pp);
}
static int tvfsUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *p){
TestvfsFd *pFd = tvfsGetFd(pFile);
return sqlite3OsUnfetch(pFd->pReal, iOfst, p);
}
static int SQLITE_TCLAPI testvfs_obj_cmd(
ClientData cd,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
Testvfs *p = (Testvfs *)cd;
enum DB_enum {
CMD_SHM, CMD_DELETE, CMD_FILTER, CMD_IOERR, CMD_SCRIPT,
CMD_DEVCHAR, CMD_SECTORSIZE, CMD_FULLERR, CMD_CANTOPENERR
};
struct TestvfsSubcmd {
char *zName;
enum DB_enum eCmd;
} aSubcmd[] = {
{ "shm", CMD_SHM },
{ "delete", CMD_DELETE },
{ "filter", CMD_FILTER },
{ "ioerr", CMD_IOERR },
{ "fullerr", CMD_FULLERR },
{ "cantopenerr", CMD_CANTOPENERR },
{ "script", CMD_SCRIPT },
{ "devchar", CMD_DEVCHAR },
{ "sectorsize", CMD_SECTORSIZE },
{ 0, 0 }
};
int i;
if( objc<2 ){
Tcl_WrongNumArgs(interp, 1, objv, "SUBCOMMAND ...");
return TCL_ERROR;
}
if( Tcl_GetIndexFromObjStruct(
interp, objv[1], aSubcmd, sizeof(aSubcmd[0]), "subcommand", 0, &i)
){
return TCL_ERROR;
}
Tcl_ResetResult(interp);
switch( aSubcmd[i].eCmd ){
case CMD_SHM: {
Tcl_Obj *pObj;
int rc;
TestvfsBuffer *pBuffer;
char *zName;
if( objc!=3 && objc!=4 ){
Tcl_WrongNumArgs(interp, 2, objv, "FILE ?VALUE?");
return TCL_ERROR;
}
zName = ckalloc(p->pParent->mxPathname);
rc = p->pParent->xFullPathname(
p->pParent, Tcl_GetString(objv[2]),
p->pParent->mxPathname, zName
);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, "failed to get full path: ",
Tcl_GetString(objv[2]), 0);
ckfree(zName);
return TCL_ERROR;
}
for(pBuffer=p->pBuffer; pBuffer; pBuffer=pBuffer->pNext){
if( 0==strcmp(pBuffer->zFile, zName) ) break;
}
ckfree(zName);
if( !pBuffer ){
Tcl_AppendResult(interp, "no such file: ", Tcl_GetString(objv[2]), 0);
return TCL_ERROR;
}
if( objc==4 ){
int n;
u8 *a = Tcl_GetByteArrayFromObj(objv[3], &n);
int pgsz = pBuffer->pgsz;
if( pgsz==0 ) pgsz = 65536;
for(i=0; i*pgsz<n; i++){
int nByte = pgsz;
tvfsAllocPage(pBuffer, i, pgsz);
if( n-i*pgsz<pgsz ){
nByte = n;
}
memcpy(pBuffer->aPage[i], &a[i*pgsz], nByte);
}
}
pObj = Tcl_NewObj();
for(i=0; pBuffer->aPage[i]; i++){
int pgsz = pBuffer->pgsz;
if( pgsz==0 ) pgsz = 65536;
Tcl_AppendObjToObj(pObj, Tcl_NewByteArrayObj(pBuffer->aPage[i], pgsz));
}
Tcl_SetObjResult(interp, pObj);
break;
}
/* TESTVFS filter METHOD-LIST
**
** Activate special processing for those methods contained in the list
*/
case CMD_FILTER: {
static struct VfsMethod {
char *zName;
int mask;
} vfsmethod [] = {
{ "xShmOpen", TESTVFS_SHMOPEN_MASK },
{ "xShmLock", TESTVFS_SHMLOCK_MASK },
{ "xShmBarrier", TESTVFS_SHMBARRIER_MASK },
{ "xShmUnmap", TESTVFS_SHMCLOSE_MASK },
{ "xShmMap", TESTVFS_SHMMAP_MASK },
{ "xSync", TESTVFS_SYNC_MASK },
{ "xDelete", TESTVFS_DELETE_MASK },
{ "xWrite", TESTVFS_WRITE_MASK },
{ "xRead", TESTVFS_READ_MASK },
{ "xTruncate", TESTVFS_TRUNCATE_MASK },
{ "xOpen", TESTVFS_OPEN_MASK },
{ "xClose", TESTVFS_CLOSE_MASK },
{ "xAccess", TESTVFS_ACCESS_MASK },
{ "xFullPathname", TESTVFS_FULLPATHNAME_MASK },
{ "xUnlock", TESTVFS_UNLOCK_MASK },
{ "xLock", TESTVFS_LOCK_MASK },
{ "xCheckReservedLock", TESTVFS_CKLOCK_MASK },
{ "xFileControl", TESTVFS_FCNTL_MASK },
};
Tcl_Obj **apElem = 0;
int nElem = 0;
int mask = 0;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "LIST");
return TCL_ERROR;
}
if( Tcl_ListObjGetElements(interp, objv[2], &nElem, &apElem) ){
return TCL_ERROR;
}
Tcl_ResetResult(interp);
for(i=0; i<nElem; i++){
int iMethod;
char *zElem = Tcl_GetString(apElem[i]);
for(iMethod=0; iMethod<ArraySize(vfsmethod); iMethod++){
if( strcmp(zElem, vfsmethod[iMethod].zName)==0 ){
mask |= vfsmethod[iMethod].mask;
break;
}
}
if( iMethod==ArraySize(vfsmethod) ){
Tcl_AppendResult(interp, "unknown method: ", zElem, 0);
return TCL_ERROR;
}
}
p->mask = mask;
break;
}
/*
** TESTVFS script ?SCRIPT?
**
** Query or set the script to be run when filtered VFS events
** occur.
*/
case CMD_SCRIPT: {
if( objc==3 ){
int nByte;
if( p->pScript ){
Tcl_DecrRefCount(p->pScript);
p->pScript = 0;
}
Tcl_GetStringFromObj(objv[2], &nByte);
if( nByte>0 ){
p->pScript = Tcl_DuplicateObj(objv[2]);
Tcl_IncrRefCount(p->pScript);
}
}else if( objc!=2 ){
Tcl_WrongNumArgs(interp, 2, objv, "?SCRIPT?");
return TCL_ERROR;
}
Tcl_ResetResult(interp);
if( p->pScript ) Tcl_SetObjResult(interp, p->pScript);
break;
}
/*
** TESTVFS ioerr ?IFAIL PERSIST?
**
** Where IFAIL is an integer and PERSIST is boolean.
*/
case CMD_CANTOPENERR:
case CMD_IOERR:
case CMD_FULLERR: {
TestFaultInject *pTest = 0;
int iRet;
switch( aSubcmd[i].eCmd ){
case CMD_IOERR: pTest = &p->ioerr_err; break;
case CMD_FULLERR: pTest = &p->full_err; break;
case CMD_CANTOPENERR: pTest = &p->cantopen_err; break;
default: assert(0);
}
iRet = pTest->nFail;
pTest->nFail = 0;
pTest->eFault = 0;
pTest->iCnt = 0;
if( objc==4 ){
int iCnt, iPersist;
if( TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &iCnt)
|| TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &iPersist)
){
return TCL_ERROR;
}
pTest->eFault = iPersist?FAULT_INJECT_PERSISTENT:FAULT_INJECT_TRANSIENT;
pTest->iCnt = iCnt;
}else if( objc!=2 ){
Tcl_WrongNumArgs(interp, 2, objv, "?CNT PERSIST?");
return TCL_ERROR;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(iRet));
break;
}
case CMD_DELETE: {
Tcl_DeleteCommand(interp, Tcl_GetString(objv[0]));
break;
}
case CMD_DEVCHAR: {
struct DeviceFlag {
char *zName;
int iValue;
} aFlag[] = {
{ "default", -1 },
{ "atomic", SQLITE_IOCAP_ATOMIC },
{ "atomic512", SQLITE_IOCAP_ATOMIC512 },
{ "atomic1k", SQLITE_IOCAP_ATOMIC1K },
{ "atomic2k", SQLITE_IOCAP_ATOMIC2K },
{ "atomic4k", SQLITE_IOCAP_ATOMIC4K },
{ "atomic8k", SQLITE_IOCAP_ATOMIC8K },
{ "atomic16k", SQLITE_IOCAP_ATOMIC16K },
{ "atomic32k", SQLITE_IOCAP_ATOMIC32K },
{ "atomic64k", SQLITE_IOCAP_ATOMIC64K },
{ "sequential", SQLITE_IOCAP_SEQUENTIAL },
{ "safe_append", SQLITE_IOCAP_SAFE_APPEND },
{ "undeletable_when_open", SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN },
{ "powersafe_overwrite", SQLITE_IOCAP_POWERSAFE_OVERWRITE },
{ "immutable", SQLITE_IOCAP_IMMUTABLE },
{ 0, 0 }
};
Tcl_Obj *pRet;
int iFlag;
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?ATTR-LIST?");
return TCL_ERROR;
}
if( objc==3 ){
int j;
int iNew = 0;
Tcl_Obj **flags = 0;
int nFlags = 0;
if( Tcl_ListObjGetElements(interp, objv[2], &nFlags, &flags) ){
return TCL_ERROR;
}
for(j=0; j<nFlags; j++){
int idx = 0;
if( Tcl_GetIndexFromObjStruct(interp, flags[j], aFlag,
sizeof(aFlag[0]), "flag", 0, &idx)
){
return TCL_ERROR;
}
if( aFlag[idx].iValue<0 && nFlags>1 ){
Tcl_AppendResult(interp, "bad flags: ", Tcl_GetString(objv[2]), 0);
return TCL_ERROR;
}
iNew |= aFlag[idx].iValue;
}
p->iDevchar = iNew| 0x10000000;
}
pRet = Tcl_NewObj();
for(iFlag=0; iFlag<sizeof(aFlag)/sizeof(aFlag[0]); iFlag++){
if( p->iDevchar & aFlag[iFlag].iValue ){
Tcl_ListObjAppendElement(
interp, pRet, Tcl_NewStringObj(aFlag[iFlag].zName, -1)
);
}
}
Tcl_SetObjResult(interp, pRet);
break;
}
case CMD_SECTORSIZE: {
if( objc>3 ){
Tcl_WrongNumArgs(interp, 2, objv, "?VALUE?");
return TCL_ERROR;
}
if( objc==3 ){
int iNew = 0;
if( Tcl_GetIntFromObj(interp, objv[2], &iNew) ){
return TCL_ERROR;
}
p->iSectorsize = iNew;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(p->iSectorsize));
break;
}
}
return TCL_OK;
}
static void SQLITE_TCLAPI testvfs_obj_del(ClientData cd){
Testvfs *p = (Testvfs *)cd;
if( p->pScript ) Tcl_DecrRefCount(p->pScript);
sqlite3_vfs_unregister(p->pVfs);
ckfree((char *)p->pVfs);
ckfree((char *)p);
}
/*
** Usage: testvfs VFSNAME ?SWITCHES?
**
** Switches are:
**
** -noshm BOOLEAN (True to omit shm methods. Default false)
** -default BOOLEAN (True to make the vfs default. Default false)
**
** This command creates two things when it is invoked: an SQLite VFS, and
** a Tcl command. Both are named VFSNAME. The VFS is installed. It is not
** installed as the default VFS.
**
** The VFS passes all file I/O calls through to the underlying VFS.
**
** Whenever the xShmMap method of the VFS
** is invoked, the SCRIPT is executed as follows:
**
** SCRIPT xShmMap FILENAME ID
**
** The value returned by the invocation of SCRIPT above is interpreted as
** an SQLite error code and returned to SQLite. Either a symbolic
** "SQLITE_OK" or numeric "0" value may be returned.
**
** The contents of the shared-memory buffer associated with a given file
** may be read and set using the following command:
**
** VFSNAME shm FILENAME ?NEWVALUE?
**
** When the xShmLock method is invoked by SQLite, the following script is
** run:
**
** SCRIPT xShmLock FILENAME ID LOCK
**
** where LOCK is of the form "OFFSET NBYTE lock/unlock shared/exclusive"
*/
static int SQLITE_TCLAPI testvfs_cmd(
ClientData cd,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
static sqlite3_vfs tvfs_vfs = {
3, /* iVersion */
0, /* szOsFile */
0, /* mxPathname */
0, /* pNext */
0, /* zName */
0, /* pAppData */
tvfsOpen, /* xOpen */
tvfsDelete, /* xDelete */
tvfsAccess, /* xAccess */
tvfsFullPathname, /* xFullPathname */
#ifndef SQLITE_OMIT_LOAD_EXTENSION
tvfsDlOpen, /* xDlOpen */
tvfsDlError, /* xDlError */
tvfsDlSym, /* xDlSym */
tvfsDlClose, /* xDlClose */
#else
0, /* xDlOpen */
0, /* xDlError */
0, /* xDlSym */
0, /* xDlClose */
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
tvfsRandomness, /* xRandomness */
tvfsSleep, /* xSleep */
tvfsCurrentTime, /* xCurrentTime */
0, /* xGetLastError */
0, /* xCurrentTimeInt64 */
0, /* xSetSystemCall */
0, /* xGetSystemCall */
0, /* xNextSystemCall */
};
Testvfs *p; /* New object */
sqlite3_vfs *pVfs; /* New VFS */
char *zVfs;
int nByte; /* Bytes of space to allocate at p */
int i;
int isNoshm = 0; /* True if -noshm is passed */
int isFullshm = 0; /* True if -fullshm is passed */
int isDefault = 0; /* True if -default is passed */
int szOsFile = 0; /* Value passed to -szosfile */
int mxPathname = -1; /* Value passed to -mxpathname */
int iVersion = 3; /* Value passed to -iversion */
if( objc<2 || 0!=(objc%2) ) goto bad_args;
for(i=2; i<objc; i += 2){
int nSwitch;
char *zSwitch;
zSwitch = Tcl_GetStringFromObj(objv[i], &nSwitch);
if( nSwitch>2 && 0==strncmp("-noshm", zSwitch, nSwitch) ){
if( Tcl_GetBooleanFromObj(interp, objv[i+1], &isNoshm) ){
return TCL_ERROR;
}
if( isNoshm ) isFullshm = 0;
}
else if( nSwitch>2 && 0==strncmp("-default", zSwitch, nSwitch) ){
if( Tcl_GetBooleanFromObj(interp, objv[i+1], &isDefault) ){
return TCL_ERROR;
}
}
else if( nSwitch>2 && 0==strncmp("-szosfile", zSwitch, nSwitch) ){
if( Tcl_GetIntFromObj(interp, objv[i+1], &szOsFile) ){
return TCL_ERROR;
}
}
else if( nSwitch>2 && 0==strncmp("-mxpathname", zSwitch, nSwitch) ){
if( Tcl_GetIntFromObj(interp, objv[i+1], &mxPathname) ){
return TCL_ERROR;
}
}
else if( nSwitch>2 && 0==strncmp("-iversion", zSwitch, nSwitch) ){
if( Tcl_GetIntFromObj(interp, objv[i+1], &iVersion) ){
return TCL_ERROR;
}
}
else if( nSwitch>2 && 0==strncmp("-fullshm", zSwitch, nSwitch) ){
if( Tcl_GetBooleanFromObj(interp, objv[i+1], &isFullshm) ){
return TCL_ERROR;
}
if( isFullshm ) isNoshm = 0;
}
else{
goto bad_args;
}
}
if( szOsFile<sizeof(TestvfsFile) ){
szOsFile = sizeof(TestvfsFile);
}
zVfs = Tcl_GetString(objv[1]);
nByte = sizeof(Testvfs) + (int)strlen(zVfs)+1;
p = (Testvfs *)ckalloc(nByte);
memset(p, 0, nByte);
p->iDevchar = -1;
p->iSectorsize = -1;
/* Create the new object command before querying SQLite for a default VFS
** to use for 'real' IO operations. This is because creating the new VFS
** may delete an existing [testvfs] VFS of the same name. If such a VFS
** is currently the default, the new [testvfs] may end up calling the
** methods of a deleted object.
*/
Tcl_CreateObjCommand(interp, zVfs, testvfs_obj_cmd, p, testvfs_obj_del);
p->pParent = sqlite3_vfs_find(0);
p->interp = interp;
p->zName = (char *)&p[1];
memcpy(p->zName, zVfs, strlen(zVfs)+1);
pVfs = (sqlite3_vfs *)ckalloc(sizeof(sqlite3_vfs));
memcpy(pVfs, &tvfs_vfs, sizeof(sqlite3_vfs));
pVfs->pAppData = (void *)p;
pVfs->iVersion = iVersion;
pVfs->zName = p->zName;
pVfs->mxPathname = p->pParent->mxPathname;
if( mxPathname>=0 && mxPathname<pVfs->mxPathname ){
pVfs->mxPathname = mxPathname;
}
pVfs->szOsFile = szOsFile;
p->pVfs = pVfs;
p->isNoshm = isNoshm;
p->isFullshm = isFullshm;
p->mask = TESTVFS_ALL_MASK;
sqlite3_vfs_register(pVfs, isDefault);
return TCL_OK;
bad_args:
Tcl_WrongNumArgs(interp, 1, objv, "VFSNAME ?-noshm BOOL? ?-fullshm BOOL? ?-default BOOL? ?-mxpathname INT? ?-szosfile INT? ?-iversion INT?");
return TCL_ERROR;
}
extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
extern const char *sqlite3ErrName(int);
/*
** tclcmd: vfs_shmlock DB DBNAME (shared|exclusive) (lock|unlock) OFFSET N
*/
static int SQLITE_TCLAPI test_vfs_shmlock(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
const char *azArg1[] = {"shared", "exclusive", 0};
const char *azArg2[] = {"lock", "unlock", 0};
sqlite3 *db = 0;
int rc = SQLITE_OK;
const char *zDbname = 0;
int iArg1 = 0;
int iArg2 = 0;
int iOffset = 0;
int n = 0;
sqlite3_file *pFd;
if( objc!=7 ){
Tcl_WrongNumArgs(interp, 1, objv,
"DB DBNAME (shared|exclusive) (lock|unlock) OFFSET N"
);
return TCL_ERROR;
}
zDbname = Tcl_GetString(objv[2]);
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|| Tcl_GetIndexFromObj(interp, objv[3], azArg1, "ARG", 0, &iArg1)
|| Tcl_GetIndexFromObj(interp, objv[4], azArg2, "ARG", 0, &iArg2)
|| Tcl_GetIntFromObj(interp, objv[5], &iOffset)
|| Tcl_GetIntFromObj(interp, objv[6], &n)
){
return TCL_ERROR;
}
sqlite3_file_control(db, zDbname, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd);
if( pFd==0 ){
return TCL_ERROR;
}
rc = pFd->pMethods->xShmLock(pFd, iOffset, n,
(iArg1==0 ? SQLITE_SHM_SHARED : SQLITE_SHM_EXCLUSIVE)
| (iArg2==0 ? SQLITE_SHM_LOCK : SQLITE_SHM_UNLOCK)
);
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
return TCL_OK;
}
static int SQLITE_TCLAPI test_vfs_set_readmark(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
sqlite3 *db = 0;
int rc = SQLITE_OK;
const char *zDbname = 0;
int iSlot = 0;
int iVal = -1;
sqlite3_file *pFd;
void volatile *pShm = 0;
u32 *aShm;
int iOff;
if( objc!=4 && objc!=5 ){
Tcl_WrongNumArgs(interp, 1, objv, "DB DBNAME SLOT ?VALUE?");
return TCL_ERROR;
}
zDbname = Tcl_GetString(objv[2]);
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db)
|| Tcl_GetIntFromObj(interp, objv[3], &iSlot)
|| (objc==5 && Tcl_GetIntFromObj(interp, objv[4], &iVal))
){
return TCL_ERROR;
}
sqlite3_file_control(db, zDbname, SQLITE_FCNTL_FILE_POINTER, (void*)&pFd);
if( pFd==0 ){
return TCL_ERROR;
}
rc = pFd->pMethods->xShmMap(pFd, 0, 32*1024, 0, &pShm);
if( rc!=SQLITE_OK ){
Tcl_SetObjResult(interp, Tcl_NewStringObj(sqlite3ErrName(rc), -1));
return TCL_ERROR;
}
if( pShm==0 ){
Tcl_AppendResult(interp, "*-shm is not yet mapped", 0);
return TCL_ERROR;
}
aShm = (u32*)pShm;
iOff = 12*2+1+iSlot;
if( objc==5 ){
aShm[iOff] = iVal;
}
Tcl_SetObjResult(interp, Tcl_NewIntObj(aShm[iOff]));
return TCL_OK;
}
int Sqlitetestvfs_Init(Tcl_Interp *interp){
Tcl_CreateObjCommand(interp, "testvfs", testvfs_cmd, 0, 0);
Tcl_CreateObjCommand(interp, "vfs_shmlock", test_vfs_shmlock, 0, 0);
Tcl_CreateObjCommand(interp, "vfs_set_readmark", test_vfs_set_readmark, 0, 0);
return TCL_OK;
}
#endif
|
the_stack_data/25136831.c | /* Copyright (C) 1989, Digital Equipment Corporation */
/* All rights reserved. */
/* See the file COPYRIGHT for a full description. */
/* */
/* Last modified on Mon Jan 9 10:18:15 PST 1995 by kalsow */
/* modified on Tue Oct 13 17:17:05 PDT 1992 by muller */
#ifdef __cplusplus
extern "C" {
#endif
extern char etext;
extern char edata;
extern char end;
#ifdef __alpha
extern char __ldr_data;
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/file.h>
#include <fcntl.h>
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>
/* We do not include marker.h here; indeed, we do not want this piece
of code to be covered !! For the same reason, the marker is broken
into pieces. */
const char marker2[] = "Coverage 1.0";
sigset_t signals;
sigjmp_buf mark;
long volatile *saved;
void catcher( int );
void p( long start, long end, int direction );
void recover( void );
void report_coverage (void);
void exit (int n) {
report_coverage ();
_exit (n);
}
//Try and determine the bounds of the data segment between etext and edata
int MapSeg(long p0, long p1, int direction) {
int result;
/*
* Block the SIGSEGV signals. This set of
* signals will be saved as part of the environment
* by the sigsetjmp() function.
*/
saved = 0;
sigemptyset( &signals );
sigaddset( &signals, SIGSEGV );
sigprocmask( SIG_SETMASK, &signals, NULL );
if( sigsetjmp( mark, 1 ) != 0 ) {
recover();
result = 0;
}
else {
p(p0,p1,direction);
sigprocmask( SIG_SETMASK, NULL, &signals );
result = -1;
}
return( result );
}
void p( long p0, long p1, int direction ) {
long ptmp;
long volatile *wd;
long volatile maybesegv;
struct sigaction sigact;
/* Send signal handler in case error condition is detected */
sigemptyset( &sigact.sa_mask );
sigact.sa_flags = 0;
sigact.sa_handler = catcher;
sigaction( SIGSEGV, &sigact, NULL );
sigdelset( &signals, SIGSEGV );
sigprocmask( SIG_SETMASK, &signals, NULL );
if (direction == 0) {
ptmp = p1;
for (wd = (long volatile *)p0; wd < (long volatile *)ptmp; wd++) {
p1 = (long)wd;
saved = wd;
maybesegv = *wd; //possibly generate fault
}
} else {
ptmp = p0;
for (wd = (long volatile *)p1; wd > (long volatile *)ptmp; wd--) {
p0 = (long)wd;
saved = wd;
maybesegv = *wd; //possibly generate fault
}
}
}
void recover( void ) {
sigprocmask( SIG_SETMASK, NULL, &signals );
}
void catcher( int signo ) {
siglongjmp( mark, -1 );
}
void CheckSegment(int output_file, long begin, long end) {
char *c;
char *start;
int state;
long marker2_len = sizeof (marker2) - 1;
state = 0;
for (c = (char *) begin; c < (char *) end; c++) {
if ( (*c == '<') && (*(c+1) == '<') && (*(c+2) == '<') && (*(c+3) == '<')
&& (strncmp ((const char *)c+4, marker2, marker2_len) == 0)) {
//Found a start marker
c += marker2_len + 4;
state = 1;
start = c;
}
if ( (*c == '>') && (*(c+1) == '>') && (*(c+2) == '>') && (*(c+3) == '>')
&& (strncmp ((const char *)c-marker2_len, marker2, marker2_len) == 0)) {
//Found an end marker
if (state == 1) {
/* write the segment */
unsigned long segLen = (c - marker2_len) - start;
write (output_file, &segLen, sizeof (long));
write (output_file, start, segLen);
}
state = 0;
c++;
}
}
}
void report_coverage (void)
{
const char *output_file_name;
int output_file;
unsigned long first_global, last_global, end_global;
long s,e;
/* open the output file */
output_file_name = getenv ("COVERAGE_DATABASE");
if (output_file_name == NULL) output_file_name = "coverage.out";
output_file = open (output_file_name, O_WRONLY | O_APPEND | O_CREAT, 0644);
if (output_file == -1) {
fprintf (stderr, "coverage: cannot report coverage to %s\n",
output_file_name);
exit (1); }
/* get an aligned pointer to the data segment */
#ifdef mips
first_global = 0x10000000;
last_global = (long) &edata;
#else
#ifdef __alpha
first_global = (long) &__ldr_data /* 0x140000000 */;
last_global = (long) &end;
#else
first_global = (long) &etext;
last_global = (long) &edata;
end_global = (long) &end;
#endif
#endif
//printf("etext %p edata %p end %p \n",first_global,last_global,end_global);
/*
//the segment from the end of the text to somewhere into the data segment
has tags but they are not the ones we want.
s = first_global;
e = last_global;
printf("range start %p end %p \n",s,e);
s /= sizeof (long); s *= sizeof (long);
e /= sizeof (long); e *= sizeof (long);
printf("range start %p end %p \n",s,e);
MapSeg(s,e,0);
if (saved != 0) e = (long)saved;
printf("range start %p end %p \n",s,e);
CheckSegment(output_file,s,e);
*/
s = first_global;
e = last_global;
s /= sizeof (long); s *= sizeof (long);
e /= sizeof (long); e *= sizeof (long);
//printf("range start %p end %p \n",s,e);
MapSeg(s,e,1);
if (saved != 0) s = (long)saved + 8;
//printf("range start %p end %p \n",s,e);
CheckSegment(output_file,s,e);
close (output_file);
}
|
the_stack_data/461843.c | #include "math.h"
double expm1(double n) {
return 0.0;
}
|
the_stack_data/68627.c | #include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define TOKENS "><+-.,[]"
#define CODE_SEGMENT_SIZE 30000
#define STACK_SEGMENT_SIZE 1000
#define DATA_SEGMENT_SIZE 30000
typedef void (*Callback)(void);
struct
{
char cs[CODE_SEGMENT_SIZE]; /* Code Segment */
long ip; /* Instruction Pointer */
char ss[STACK_SEGMENT_SIZE]; /* Stack Segment */
long sp; /* Stack Pointer */
char ds[DATA_SEGMENT_SIZE]; /* Data Segment */
long bp; /* Base Pointer */
Callback fn[128];
} vm;
void vm_forward()
{
vm.bp = (vm.bp + 1) % DATA_SEGMENT_SIZE;
}
void vm_backward()
{
vm.bp = (vm.bp + DATA_SEGMENT_SIZE - 1) % DATA_SEGMENT_SIZE;
}
void vm_increment()
{
vm.ds[vm.bp]++;
}
void vm_decrement()
{
vm.ds[vm.bp]--;
}
void vm_input()
{
vm.ds[vm.bp] = getchar();
}
void vm_output()
{
putchar(vm.ds[vm.bp]);
}
void vm_while_entry()
{
if (vm.ds[vm.bp])
{
vm.ss[vm.sp] = vm.ip - 1;
vm.sp++;
}
else
{
int c = 1;
for (vm.ip++; vm.cs[vm.ip] && c; vm.ip++)
{
if (vm.cs[vm.ip] == '[')
{
c++;
}
else if (vm.cs[vm.ip] == ']')
{
c--;
}
}
}
}
void vm_while_exit()
{
if (vm.ds[vm.bp])
{
vm.sp--;
vm.ip = vm.ss[vm.sp];
}
}
void setup()
{
int c;
int i;
memset(&vm, 0, sizeof(vm));
vm.fn['>'] = vm_forward;
vm.fn['<'] = vm_backward;
vm.fn['+'] = vm_increment;
vm.fn['-'] = vm_decrement;
vm.fn['.'] = vm_output;
vm.fn[','] = vm_input;
vm.fn['['] = vm_while_entry;
vm.fn[']'] = vm_while_exit;
for (i = 0; (c = getchar()) != EOF;)
{
if (strchr(TOKENS, c))
{
vm.cs[i] = c;
i++;
}
}
}
void run()
{
while (vm.cs[vm.ip])
{
vm.fn[vm.cs[vm.ip]]();
vm.ip++;
}
}
int main(int argc, char *argv[])
{
if (argc > 1)
{
freopen(argv[1], "r", stdin);
}
setup();
run();
return 0;
}
|
the_stack_data/184517926.c | #include <stdio.h>
typedef long long int64;
int64 n = 5;
int64 main() {
int64 f = 1;
while(n > 1) {
f = f * n;
n -= 1;
}
printf("%lld\n", f);
return 0;
}
|
the_stack_data/175142022.c | #include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <signal.h>
#define ERR(source) (fprintf(stderr,"%s:%d\n",__FILE__,__LINE__),\
perror(source),kill(0,SIGKILL),\
exit(EXIT_FAILURE))
volatile sig_atomic_t sig_count = 0;
void sethandler( void (*f)(int), int sigNo) {
struct sigaction act;
memset(&act, 0, sizeof(struct sigaction));
act.sa_handler = f;
if (-1==sigaction(sigNo, &act, NULL)) ERR("sigaction");
}
void sigchld_handler(int sig) {
pid_t pid;
for(;;){
pid=waitpid(0, NULL, WNOHANG);
if(pid==0) return;
if(pid<=0) {
if(errno==ECHILD) return;
ERR("waitpid");
}
}
}
void sig_handler(int sig) {
sig_count++;;
}
void child_work(int m) {
struct timespec t = {0, m*10000};
sethandler(SIG_DFL,SIGUSR1);
while(1){
nanosleep(&t,NULL);
if(kill(getppid(),SIGUSR1))ERR("kill");
}
}
void parent_work(int b, int s, char *name) {
int i,in,out;
ssize_t count;
char *buf=malloc(s);
if(!buf) ERR("malloc");
if((out=open(name,O_WRONLY|O_CREAT|O_TRUNC|O_APPEND,0777))<0)ERR("open");
if((in=open("/dev/urandom",O_RDONLY))<0)ERR("open");
for(i=0; i<b;i++){
if((count=read(in,buf,s))<0) ERR("read");
if((count=write(out,buf,count))<0) ERR("read");
if(fprintf(stderr,"Block of %ld bytes transfered. Signals RX:%d\n",count,sig_count)<0)ERR("fprintf");;
}
if(close(in))ERR("close");
if(close(out))ERR("close");
free(buf);
if(kill(0,SIGUSR1))ERR("kill");
}
void usage(char *name){
fprintf(stderr,"USAGE: %s m p\n",name);
fprintf(stderr,"m - number of 1/1000 milliseconds between signals [1,999], i.e. one milisecond maximum\n");
fprintf(stderr,"p - after p SIGUSR1 send one SIGUSER2 [1,999]\n");
exit(EXIT_FAILURE);
}
int main(int argc, char** argv) {
int m,b,s;
char *name;
if(argc!=5) usage(argv[0]);
m = atoi(argv[1]); b = atoi(argv[2]); s = atoi(argv[3]); name=argv[4];
if (m<=0||m>999||b<=0||b>999||s<=0||s>999)usage(argv[0]);
sethandler(sig_handler,SIGUSR1);
pid_t pid;
if((pid=fork())<0) ERR("fork");
if(0==pid) child_work(m);
else {
parent_work(b,s*1024*1024,name);
while(wait(NULL)>0);
}
return EXIT_SUCCESS;
}
|
the_stack_data/237642025.c | extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
float x_14, _x_x_14;
bool _J1307, _x__J1307;
bool _J1301, _x__J1301;
float x_8, _x_x_8;
bool _J1295, _x__J1295;
float x_17, _x_x_17;
bool _EL_X_1277, _x__EL_X_1277;
float x_3, _x_x_3;
float x_0, _x_x_0;
float x_5, _x_x_5;
float x_9, _x_x_9;
float x_6, _x_x_6;
float x_1, _x_x_1;
float x_7, _x_x_7;
float x_10, _x_x_10;
float x_11, _x_x_11;
float x_13, _x_x_13;
float x_15, _x_x_15;
float x_19, _x_x_19;
float x_18, _x_x_18;
bool _EL_U_1272, _x__EL_U_1272;
float x_2, _x_x_2;
bool _EL_U_1274, _x__EL_U_1274;
bool _EL_U_1276, _x__EL_U_1276;
float x_4, _x_x_4;
float x_16, _x_x_16;
float x_12, _x_x_12;
int __steps_to_fair = __VERIFIER_nondet_int();
x_14 = __VERIFIER_nondet_float();
_J1307 = __VERIFIER_nondet_bool();
_J1301 = __VERIFIER_nondet_bool();
x_8 = __VERIFIER_nondet_float();
_J1295 = __VERIFIER_nondet_bool();
x_17 = __VERIFIER_nondet_float();
_EL_X_1277 = __VERIFIER_nondet_bool();
x_3 = __VERIFIER_nondet_float();
x_0 = __VERIFIER_nondet_float();
x_5 = __VERIFIER_nondet_float();
x_9 = __VERIFIER_nondet_float();
x_6 = __VERIFIER_nondet_float();
x_1 = __VERIFIER_nondet_float();
x_7 = __VERIFIER_nondet_float();
x_10 = __VERIFIER_nondet_float();
x_11 = __VERIFIER_nondet_float();
x_13 = __VERIFIER_nondet_float();
x_15 = __VERIFIER_nondet_float();
x_19 = __VERIFIER_nondet_float();
x_18 = __VERIFIER_nondet_float();
_EL_U_1272 = __VERIFIER_nondet_bool();
x_2 = __VERIFIER_nondet_float();
_EL_U_1274 = __VERIFIER_nondet_bool();
_EL_U_1276 = __VERIFIER_nondet_bool();
x_4 = __VERIFIER_nondet_float();
x_16 = __VERIFIER_nondet_float();
x_12 = __VERIFIER_nondet_float();
bool __ok = (1 && (((( !_EL_X_1277) && ( !_J1295)) && ( !_J1301)) && ( !_J1307)));
while (__steps_to_fair >= 0 && __ok) {
if (((_J1295 && _J1301) && _J1307)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x_x_14 = __VERIFIER_nondet_float();
_x__J1307 = __VERIFIER_nondet_bool();
_x__J1301 = __VERIFIER_nondet_bool();
_x_x_8 = __VERIFIER_nondet_float();
_x__J1295 = __VERIFIER_nondet_bool();
_x_x_17 = __VERIFIER_nondet_float();
_x__EL_X_1277 = __VERIFIER_nondet_bool();
_x_x_3 = __VERIFIER_nondet_float();
_x_x_0 = __VERIFIER_nondet_float();
_x_x_5 = __VERIFIER_nondet_float();
_x_x_9 = __VERIFIER_nondet_float();
_x_x_6 = __VERIFIER_nondet_float();
_x_x_1 = __VERIFIER_nondet_float();
_x_x_7 = __VERIFIER_nondet_float();
_x_x_10 = __VERIFIER_nondet_float();
_x_x_11 = __VERIFIER_nondet_float();
_x_x_13 = __VERIFIER_nondet_float();
_x_x_15 = __VERIFIER_nondet_float();
_x_x_19 = __VERIFIER_nondet_float();
_x_x_18 = __VERIFIER_nondet_float();
_x__EL_U_1272 = __VERIFIER_nondet_bool();
_x_x_2 = __VERIFIER_nondet_float();
_x__EL_U_1274 = __VERIFIER_nondet_bool();
_x__EL_U_1276 = __VERIFIER_nondet_bool();
_x_x_4 = __VERIFIER_nondet_float();
_x_x_16 = __VERIFIER_nondet_float();
_x_x_12 = __VERIFIER_nondet_float();
__ok = ((((((((((((((((((((((((x_17 + (-1.0 * _x_x_0)) <= -3.0) && (((x_14 + (-1.0 * _x_x_0)) <= -9.0) && (((x_13 + (-1.0 * _x_x_0)) <= -6.0) && (((x_12 + (-1.0 * _x_x_0)) <= -3.0) && (((x_10 + (-1.0 * _x_x_0)) <= -13.0) && (((x_8 + (-1.0 * _x_x_0)) <= -16.0) && (((x_6 + (-1.0 * _x_x_0)) <= -3.0) && (((x_5 + (-1.0 * _x_x_0)) <= -20.0) && (((x_0 + (-1.0 * _x_x_0)) <= -20.0) && ((x_2 + (-1.0 * _x_x_0)) <= -11.0)))))))))) && (((x_17 + (-1.0 * _x_x_0)) == -3.0) || (((x_14 + (-1.0 * _x_x_0)) == -9.0) || (((x_13 + (-1.0 * _x_x_0)) == -6.0) || (((x_12 + (-1.0 * _x_x_0)) == -3.0) || (((x_10 + (-1.0 * _x_x_0)) == -13.0) || (((x_8 + (-1.0 * _x_x_0)) == -16.0) || (((x_6 + (-1.0 * _x_x_0)) == -3.0) || (((x_5 + (-1.0 * _x_x_0)) == -20.0) || (((x_0 + (-1.0 * _x_x_0)) == -20.0) || ((x_2 + (-1.0 * _x_x_0)) == -11.0))))))))))) && ((((x_18 + (-1.0 * _x_x_1)) <= -13.0) && (((x_17 + (-1.0 * _x_x_1)) <= -6.0) && (((x_15 + (-1.0 * _x_x_1)) <= -18.0) && (((x_14 + (-1.0 * _x_x_1)) <= -1.0) && (((x_13 + (-1.0 * _x_x_1)) <= -8.0) && (((x_12 + (-1.0 * _x_x_1)) <= -18.0) && (((x_10 + (-1.0 * _x_x_1)) <= -7.0) && (((x_7 + (-1.0 * _x_x_1)) <= -2.0) && (((x_2 + (-1.0 * _x_x_1)) <= -14.0) && ((x_6 + (-1.0 * _x_x_1)) <= -8.0)))))))))) && (((x_18 + (-1.0 * _x_x_1)) == -13.0) || (((x_17 + (-1.0 * _x_x_1)) == -6.0) || (((x_15 + (-1.0 * _x_x_1)) == -18.0) || (((x_14 + (-1.0 * _x_x_1)) == -1.0) || (((x_13 + (-1.0 * _x_x_1)) == -8.0) || (((x_12 + (-1.0 * _x_x_1)) == -18.0) || (((x_10 + (-1.0 * _x_x_1)) == -7.0) || (((x_7 + (-1.0 * _x_x_1)) == -2.0) || (((x_2 + (-1.0 * _x_x_1)) == -14.0) || ((x_6 + (-1.0 * _x_x_1)) == -8.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_2)) <= -19.0) && (((x_17 + (-1.0 * _x_x_2)) <= -9.0) && (((x_14 + (-1.0 * _x_x_2)) <= -15.0) && (((x_11 + (-1.0 * _x_x_2)) <= -9.0) && (((x_10 + (-1.0 * _x_x_2)) <= -9.0) && (((x_8 + (-1.0 * _x_x_2)) <= -7.0) && (((x_5 + (-1.0 * _x_x_2)) <= -13.0) && (((x_4 + (-1.0 * _x_x_2)) <= -13.0) && (((x_0 + (-1.0 * _x_x_2)) <= -1.0) && ((x_1 + (-1.0 * _x_x_2)) <= -17.0)))))))))) && (((x_18 + (-1.0 * _x_x_2)) == -19.0) || (((x_17 + (-1.0 * _x_x_2)) == -9.0) || (((x_14 + (-1.0 * _x_x_2)) == -15.0) || (((x_11 + (-1.0 * _x_x_2)) == -9.0) || (((x_10 + (-1.0 * _x_x_2)) == -9.0) || (((x_8 + (-1.0 * _x_x_2)) == -7.0) || (((x_5 + (-1.0 * _x_x_2)) == -13.0) || (((x_4 + (-1.0 * _x_x_2)) == -13.0) || (((x_0 + (-1.0 * _x_x_2)) == -1.0) || ((x_1 + (-1.0 * _x_x_2)) == -17.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_3)) <= -15.0) && (((x_18 + (-1.0 * _x_x_3)) <= -13.0) && (((x_17 + (-1.0 * _x_x_3)) <= -18.0) && (((x_10 + (-1.0 * _x_x_3)) <= -2.0) && (((x_8 + (-1.0 * _x_x_3)) <= -19.0) && (((x_7 + (-1.0 * _x_x_3)) <= -4.0) && (((x_4 + (-1.0 * _x_x_3)) <= -5.0) && (((x_2 + (-1.0 * _x_x_3)) <= -4.0) && (((x_0 + (-1.0 * _x_x_3)) <= -1.0) && ((x_1 + (-1.0 * _x_x_3)) <= -15.0)))))))))) && (((x_19 + (-1.0 * _x_x_3)) == -15.0) || (((x_18 + (-1.0 * _x_x_3)) == -13.0) || (((x_17 + (-1.0 * _x_x_3)) == -18.0) || (((x_10 + (-1.0 * _x_x_3)) == -2.0) || (((x_8 + (-1.0 * _x_x_3)) == -19.0) || (((x_7 + (-1.0 * _x_x_3)) == -4.0) || (((x_4 + (-1.0 * _x_x_3)) == -5.0) || (((x_2 + (-1.0 * _x_x_3)) == -4.0) || (((x_0 + (-1.0 * _x_x_3)) == -1.0) || ((x_1 + (-1.0 * _x_x_3)) == -15.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_4)) <= -6.0) && (((x_18 + (-1.0 * _x_x_4)) <= -2.0) && (((x_16 + (-1.0 * _x_x_4)) <= -15.0) && (((x_15 + (-1.0 * _x_x_4)) <= -6.0) && (((x_14 + (-1.0 * _x_x_4)) <= -10.0) && (((x_13 + (-1.0 * _x_x_4)) <= -5.0) && (((x_10 + (-1.0 * _x_x_4)) <= -18.0) && (((x_7 + (-1.0 * _x_x_4)) <= -15.0) && (((x_1 + (-1.0 * _x_x_4)) <= -18.0) && ((x_5 + (-1.0 * _x_x_4)) <= -2.0)))))))))) && (((x_19 + (-1.0 * _x_x_4)) == -6.0) || (((x_18 + (-1.0 * _x_x_4)) == -2.0) || (((x_16 + (-1.0 * _x_x_4)) == -15.0) || (((x_15 + (-1.0 * _x_x_4)) == -6.0) || (((x_14 + (-1.0 * _x_x_4)) == -10.0) || (((x_13 + (-1.0 * _x_x_4)) == -5.0) || (((x_10 + (-1.0 * _x_x_4)) == -18.0) || (((x_7 + (-1.0 * _x_x_4)) == -15.0) || (((x_1 + (-1.0 * _x_x_4)) == -18.0) || ((x_5 + (-1.0 * _x_x_4)) == -2.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_5)) <= -5.0) && (((x_15 + (-1.0 * _x_x_5)) <= -6.0) && (((x_14 + (-1.0 * _x_x_5)) <= -16.0) && (((x_12 + (-1.0 * _x_x_5)) <= -2.0) && (((x_11 + (-1.0 * _x_x_5)) <= -11.0) && (((x_10 + (-1.0 * _x_x_5)) <= -13.0) && (((x_9 + (-1.0 * _x_x_5)) <= -6.0) && (((x_7 + (-1.0 * _x_x_5)) <= -13.0) && (((x_2 + (-1.0 * _x_x_5)) <= -20.0) && ((x_3 + (-1.0 * _x_x_5)) <= -20.0)))))))))) && (((x_18 + (-1.0 * _x_x_5)) == -5.0) || (((x_15 + (-1.0 * _x_x_5)) == -6.0) || (((x_14 + (-1.0 * _x_x_5)) == -16.0) || (((x_12 + (-1.0 * _x_x_5)) == -2.0) || (((x_11 + (-1.0 * _x_x_5)) == -11.0) || (((x_10 + (-1.0 * _x_x_5)) == -13.0) || (((x_9 + (-1.0 * _x_x_5)) == -6.0) || (((x_7 + (-1.0 * _x_x_5)) == -13.0) || (((x_2 + (-1.0 * _x_x_5)) == -20.0) || ((x_3 + (-1.0 * _x_x_5)) == -20.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_6)) <= -9.0) && (((x_18 + (-1.0 * _x_x_6)) <= -6.0) && (((x_16 + (-1.0 * _x_x_6)) <= -15.0) && (((x_15 + (-1.0 * _x_x_6)) <= -15.0) && (((x_14 + (-1.0 * _x_x_6)) <= -12.0) && (((x_10 + (-1.0 * _x_x_6)) <= -11.0) && (((x_9 + (-1.0 * _x_x_6)) <= -17.0) && (((x_7 + (-1.0 * _x_x_6)) <= -9.0) && (((x_4 + (-1.0 * _x_x_6)) <= -15.0) && ((x_5 + (-1.0 * _x_x_6)) <= -7.0)))))))))) && (((x_19 + (-1.0 * _x_x_6)) == -9.0) || (((x_18 + (-1.0 * _x_x_6)) == -6.0) || (((x_16 + (-1.0 * _x_x_6)) == -15.0) || (((x_15 + (-1.0 * _x_x_6)) == -15.0) || (((x_14 + (-1.0 * _x_x_6)) == -12.0) || (((x_10 + (-1.0 * _x_x_6)) == -11.0) || (((x_9 + (-1.0 * _x_x_6)) == -17.0) || (((x_7 + (-1.0 * _x_x_6)) == -9.0) || (((x_4 + (-1.0 * _x_x_6)) == -15.0) || ((x_5 + (-1.0 * _x_x_6)) == -7.0)))))))))))) && ((((x_17 + (-1.0 * _x_x_7)) <= -13.0) && (((x_16 + (-1.0 * _x_x_7)) <= -20.0) && (((x_14 + (-1.0 * _x_x_7)) <= -11.0) && (((x_13 + (-1.0 * _x_x_7)) <= -12.0) && (((x_12 + (-1.0 * _x_x_7)) <= -9.0) && (((x_9 + (-1.0 * _x_x_7)) <= -16.0) && (((x_8 + (-1.0 * _x_x_7)) <= -8.0) && (((x_7 + (-1.0 * _x_x_7)) <= -6.0) && (((x_5 + (-1.0 * _x_x_7)) <= -14.0) && ((x_6 + (-1.0 * _x_x_7)) <= -19.0)))))))))) && (((x_17 + (-1.0 * _x_x_7)) == -13.0) || (((x_16 + (-1.0 * _x_x_7)) == -20.0) || (((x_14 + (-1.0 * _x_x_7)) == -11.0) || (((x_13 + (-1.0 * _x_x_7)) == -12.0) || (((x_12 + (-1.0 * _x_x_7)) == -9.0) || (((x_9 + (-1.0 * _x_x_7)) == -16.0) || (((x_8 + (-1.0 * _x_x_7)) == -8.0) || (((x_7 + (-1.0 * _x_x_7)) == -6.0) || (((x_5 + (-1.0 * _x_x_7)) == -14.0) || ((x_6 + (-1.0 * _x_x_7)) == -19.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_8)) <= -6.0) && (((x_12 + (-1.0 * _x_x_8)) <= -4.0) && (((x_11 + (-1.0 * _x_x_8)) <= -1.0) && (((x_8 + (-1.0 * _x_x_8)) <= -11.0) && (((x_7 + (-1.0 * _x_x_8)) <= -14.0) && (((x_6 + (-1.0 * _x_x_8)) <= -3.0) && (((x_4 + (-1.0 * _x_x_8)) <= -8.0) && (((x_2 + (-1.0 * _x_x_8)) <= -14.0) && (((x_0 + (-1.0 * _x_x_8)) <= -4.0) && ((x_1 + (-1.0 * _x_x_8)) <= -1.0)))))))))) && (((x_18 + (-1.0 * _x_x_8)) == -6.0) || (((x_12 + (-1.0 * _x_x_8)) == -4.0) || (((x_11 + (-1.0 * _x_x_8)) == -1.0) || (((x_8 + (-1.0 * _x_x_8)) == -11.0) || (((x_7 + (-1.0 * _x_x_8)) == -14.0) || (((x_6 + (-1.0 * _x_x_8)) == -3.0) || (((x_4 + (-1.0 * _x_x_8)) == -8.0) || (((x_2 + (-1.0 * _x_x_8)) == -14.0) || (((x_0 + (-1.0 * _x_x_8)) == -4.0) || ((x_1 + (-1.0 * _x_x_8)) == -1.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_9)) <= -4.0) && (((x_18 + (-1.0 * _x_x_9)) <= -7.0) && (((x_16 + (-1.0 * _x_x_9)) <= -16.0) && (((x_15 + (-1.0 * _x_x_9)) <= -9.0) && (((x_13 + (-1.0 * _x_x_9)) <= -19.0) && (((x_10 + (-1.0 * _x_x_9)) <= -20.0) && (((x_7 + (-1.0 * _x_x_9)) <= -17.0) && (((x_4 + (-1.0 * _x_x_9)) <= -14.0) && (((x_0 + (-1.0 * _x_x_9)) <= -16.0) && ((x_3 + (-1.0 * _x_x_9)) <= -17.0)))))))))) && (((x_19 + (-1.0 * _x_x_9)) == -4.0) || (((x_18 + (-1.0 * _x_x_9)) == -7.0) || (((x_16 + (-1.0 * _x_x_9)) == -16.0) || (((x_15 + (-1.0 * _x_x_9)) == -9.0) || (((x_13 + (-1.0 * _x_x_9)) == -19.0) || (((x_10 + (-1.0 * _x_x_9)) == -20.0) || (((x_7 + (-1.0 * _x_x_9)) == -17.0) || (((x_4 + (-1.0 * _x_x_9)) == -14.0) || (((x_0 + (-1.0 * _x_x_9)) == -16.0) || ((x_3 + (-1.0 * _x_x_9)) == -17.0)))))))))))) && ((((x_17 + (-1.0 * _x_x_10)) <= -12.0) && (((x_16 + (-1.0 * _x_x_10)) <= -20.0) && (((x_13 + (-1.0 * _x_x_10)) <= -6.0) && (((x_10 + (-1.0 * _x_x_10)) <= -4.0) && (((x_9 + (-1.0 * _x_x_10)) <= -10.0) && (((x_7 + (-1.0 * _x_x_10)) <= -9.0) && (((x_6 + (-1.0 * _x_x_10)) <= -16.0) && (((x_5 + (-1.0 * _x_x_10)) <= -7.0) && (((x_1 + (-1.0 * _x_x_10)) <= -10.0) && ((x_2 + (-1.0 * _x_x_10)) <= -6.0)))))))))) && (((x_17 + (-1.0 * _x_x_10)) == -12.0) || (((x_16 + (-1.0 * _x_x_10)) == -20.0) || (((x_13 + (-1.0 * _x_x_10)) == -6.0) || (((x_10 + (-1.0 * _x_x_10)) == -4.0) || (((x_9 + (-1.0 * _x_x_10)) == -10.0) || (((x_7 + (-1.0 * _x_x_10)) == -9.0) || (((x_6 + (-1.0 * _x_x_10)) == -16.0) || (((x_5 + (-1.0 * _x_x_10)) == -7.0) || (((x_1 + (-1.0 * _x_x_10)) == -10.0) || ((x_2 + (-1.0 * _x_x_10)) == -6.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_11)) <= -7.0) && (((x_18 + (-1.0 * _x_x_11)) <= -5.0) && (((x_15 + (-1.0 * _x_x_11)) <= -15.0) && (((x_12 + (-1.0 * _x_x_11)) <= -20.0) && (((x_8 + (-1.0 * _x_x_11)) <= -5.0) && (((x_7 + (-1.0 * _x_x_11)) <= -20.0) && (((x_6 + (-1.0 * _x_x_11)) <= -15.0) && (((x_4 + (-1.0 * _x_x_11)) <= -15.0) && (((x_2 + (-1.0 * _x_x_11)) <= -15.0) && ((x_3 + (-1.0 * _x_x_11)) <= -7.0)))))))))) && (((x_19 + (-1.0 * _x_x_11)) == -7.0) || (((x_18 + (-1.0 * _x_x_11)) == -5.0) || (((x_15 + (-1.0 * _x_x_11)) == -15.0) || (((x_12 + (-1.0 * _x_x_11)) == -20.0) || (((x_8 + (-1.0 * _x_x_11)) == -5.0) || (((x_7 + (-1.0 * _x_x_11)) == -20.0) || (((x_6 + (-1.0 * _x_x_11)) == -15.0) || (((x_4 + (-1.0 * _x_x_11)) == -15.0) || (((x_2 + (-1.0 * _x_x_11)) == -15.0) || ((x_3 + (-1.0 * _x_x_11)) == -7.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_12)) <= -9.0) && (((x_15 + (-1.0 * _x_x_12)) <= -16.0) && (((x_14 + (-1.0 * _x_x_12)) <= -5.0) && (((x_13 + (-1.0 * _x_x_12)) <= -15.0) && (((x_12 + (-1.0 * _x_x_12)) <= -16.0) && (((x_8 + (-1.0 * _x_x_12)) <= -14.0) && (((x_6 + (-1.0 * _x_x_12)) <= -8.0) && (((x_4 + (-1.0 * _x_x_12)) <= -13.0) && (((x_0 + (-1.0 * _x_x_12)) <= -20.0) && ((x_2 + (-1.0 * _x_x_12)) <= -12.0)))))))))) && (((x_18 + (-1.0 * _x_x_12)) == -9.0) || (((x_15 + (-1.0 * _x_x_12)) == -16.0) || (((x_14 + (-1.0 * _x_x_12)) == -5.0) || (((x_13 + (-1.0 * _x_x_12)) == -15.0) || (((x_12 + (-1.0 * _x_x_12)) == -16.0) || (((x_8 + (-1.0 * _x_x_12)) == -14.0) || (((x_6 + (-1.0 * _x_x_12)) == -8.0) || (((x_4 + (-1.0 * _x_x_12)) == -13.0) || (((x_0 + (-1.0 * _x_x_12)) == -20.0) || ((x_2 + (-1.0 * _x_x_12)) == -12.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_13)) <= -12.0) && (((x_18 + (-1.0 * _x_x_13)) <= -6.0) && (((x_16 + (-1.0 * _x_x_13)) <= -15.0) && (((x_14 + (-1.0 * _x_x_13)) <= -18.0) && (((x_10 + (-1.0 * _x_x_13)) <= -18.0) && (((x_9 + (-1.0 * _x_x_13)) <= -16.0) && (((x_8 + (-1.0 * _x_x_13)) <= -1.0) && (((x_4 + (-1.0 * _x_x_13)) <= -16.0) && (((x_0 + (-1.0 * _x_x_13)) <= -11.0) && ((x_1 + (-1.0 * _x_x_13)) <= -3.0)))))))))) && (((x_19 + (-1.0 * _x_x_13)) == -12.0) || (((x_18 + (-1.0 * _x_x_13)) == -6.0) || (((x_16 + (-1.0 * _x_x_13)) == -15.0) || (((x_14 + (-1.0 * _x_x_13)) == -18.0) || (((x_10 + (-1.0 * _x_x_13)) == -18.0) || (((x_9 + (-1.0 * _x_x_13)) == -16.0) || (((x_8 + (-1.0 * _x_x_13)) == -1.0) || (((x_4 + (-1.0 * _x_x_13)) == -16.0) || (((x_0 + (-1.0 * _x_x_13)) == -11.0) || ((x_1 + (-1.0 * _x_x_13)) == -3.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_14)) <= -6.0) && (((x_18 + (-1.0 * _x_x_14)) <= -5.0) && (((x_14 + (-1.0 * _x_x_14)) <= -18.0) && (((x_12 + (-1.0 * _x_x_14)) <= -20.0) && (((x_10 + (-1.0 * _x_x_14)) <= -2.0) && (((x_9 + (-1.0 * _x_x_14)) <= -3.0) && (((x_5 + (-1.0 * _x_x_14)) <= -18.0) && (((x_2 + (-1.0 * _x_x_14)) <= -3.0) && (((x_0 + (-1.0 * _x_x_14)) <= -3.0) && ((x_1 + (-1.0 * _x_x_14)) <= -9.0)))))))))) && (((x_19 + (-1.0 * _x_x_14)) == -6.0) || (((x_18 + (-1.0 * _x_x_14)) == -5.0) || (((x_14 + (-1.0 * _x_x_14)) == -18.0) || (((x_12 + (-1.0 * _x_x_14)) == -20.0) || (((x_10 + (-1.0 * _x_x_14)) == -2.0) || (((x_9 + (-1.0 * _x_x_14)) == -3.0) || (((x_5 + (-1.0 * _x_x_14)) == -18.0) || (((x_2 + (-1.0 * _x_x_14)) == -3.0) || (((x_0 + (-1.0 * _x_x_14)) == -3.0) || ((x_1 + (-1.0 * _x_x_14)) == -9.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_15)) <= -1.0) && (((x_17 + (-1.0 * _x_x_15)) <= -9.0) && (((x_16 + (-1.0 * _x_x_15)) <= -5.0) && (((x_15 + (-1.0 * _x_x_15)) <= -17.0) && (((x_11 + (-1.0 * _x_x_15)) <= -9.0) && (((x_9 + (-1.0 * _x_x_15)) <= -20.0) && (((x_7 + (-1.0 * _x_x_15)) <= -8.0) && (((x_4 + (-1.0 * _x_x_15)) <= -2.0) && (((x_0 + (-1.0 * _x_x_15)) <= -16.0) && ((x_1 + (-1.0 * _x_x_15)) <= -3.0)))))))))) && (((x_19 + (-1.0 * _x_x_15)) == -1.0) || (((x_17 + (-1.0 * _x_x_15)) == -9.0) || (((x_16 + (-1.0 * _x_x_15)) == -5.0) || (((x_15 + (-1.0 * _x_x_15)) == -17.0) || (((x_11 + (-1.0 * _x_x_15)) == -9.0) || (((x_9 + (-1.0 * _x_x_15)) == -20.0) || (((x_7 + (-1.0 * _x_x_15)) == -8.0) || (((x_4 + (-1.0 * _x_x_15)) == -2.0) || (((x_0 + (-1.0 * _x_x_15)) == -16.0) || ((x_1 + (-1.0 * _x_x_15)) == -3.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_16)) <= -10.0) && (((x_17 + (-1.0 * _x_x_16)) <= -4.0) && (((x_16 + (-1.0 * _x_x_16)) <= -15.0) && (((x_15 + (-1.0 * _x_x_16)) <= -19.0) && (((x_13 + (-1.0 * _x_x_16)) <= -15.0) && (((x_12 + (-1.0 * _x_x_16)) <= -13.0) && (((x_7 + (-1.0 * _x_x_16)) <= -6.0) && (((x_6 + (-1.0 * _x_x_16)) <= -16.0) && (((x_1 + (-1.0 * _x_x_16)) <= -2.0) && ((x_2 + (-1.0 * _x_x_16)) <= -19.0)))))))))) && (((x_19 + (-1.0 * _x_x_16)) == -10.0) || (((x_17 + (-1.0 * _x_x_16)) == -4.0) || (((x_16 + (-1.0 * _x_x_16)) == -15.0) || (((x_15 + (-1.0 * _x_x_16)) == -19.0) || (((x_13 + (-1.0 * _x_x_16)) == -15.0) || (((x_12 + (-1.0 * _x_x_16)) == -13.0) || (((x_7 + (-1.0 * _x_x_16)) == -6.0) || (((x_6 + (-1.0 * _x_x_16)) == -16.0) || (((x_1 + (-1.0 * _x_x_16)) == -2.0) || ((x_2 + (-1.0 * _x_x_16)) == -19.0)))))))))))) && ((((x_19 + (-1.0 * _x_x_17)) <= -12.0) && (((x_17 + (-1.0 * _x_x_17)) <= -6.0) && (((x_15 + (-1.0 * _x_x_17)) <= -15.0) && (((x_13 + (-1.0 * _x_x_17)) <= -4.0) && (((x_11 + (-1.0 * _x_x_17)) <= -10.0) && (((x_7 + (-1.0 * _x_x_17)) <= -7.0) && (((x_6 + (-1.0 * _x_x_17)) <= -1.0) && (((x_5 + (-1.0 * _x_x_17)) <= -15.0) && (((x_1 + (-1.0 * _x_x_17)) <= -16.0) && ((x_4 + (-1.0 * _x_x_17)) <= -5.0)))))))))) && (((x_19 + (-1.0 * _x_x_17)) == -12.0) || (((x_17 + (-1.0 * _x_x_17)) == -6.0) || (((x_15 + (-1.0 * _x_x_17)) == -15.0) || (((x_13 + (-1.0 * _x_x_17)) == -4.0) || (((x_11 + (-1.0 * _x_x_17)) == -10.0) || (((x_7 + (-1.0 * _x_x_17)) == -7.0) || (((x_6 + (-1.0 * _x_x_17)) == -1.0) || (((x_5 + (-1.0 * _x_x_17)) == -15.0) || (((x_1 + (-1.0 * _x_x_17)) == -16.0) || ((x_4 + (-1.0 * _x_x_17)) == -5.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_18)) <= -20.0) && (((x_17 + (-1.0 * _x_x_18)) <= -14.0) && (((x_14 + (-1.0 * _x_x_18)) <= -14.0) && (((x_13 + (-1.0 * _x_x_18)) <= -4.0) && (((x_12 + (-1.0 * _x_x_18)) <= -15.0) && (((x_10 + (-1.0 * _x_x_18)) <= -19.0) && (((x_4 + (-1.0 * _x_x_18)) <= -12.0) && (((x_3 + (-1.0 * _x_x_18)) <= -1.0) && (((x_0 + (-1.0 * _x_x_18)) <= -9.0) && ((x_2 + (-1.0 * _x_x_18)) <= -5.0)))))))))) && (((x_18 + (-1.0 * _x_x_18)) == -20.0) || (((x_17 + (-1.0 * _x_x_18)) == -14.0) || (((x_14 + (-1.0 * _x_x_18)) == -14.0) || (((x_13 + (-1.0 * _x_x_18)) == -4.0) || (((x_12 + (-1.0 * _x_x_18)) == -15.0) || (((x_10 + (-1.0 * _x_x_18)) == -19.0) || (((x_4 + (-1.0 * _x_x_18)) == -12.0) || (((x_3 + (-1.0 * _x_x_18)) == -1.0) || (((x_0 + (-1.0 * _x_x_18)) == -9.0) || ((x_2 + (-1.0 * _x_x_18)) == -5.0)))))))))))) && ((((x_18 + (-1.0 * _x_x_19)) <= -5.0) && (((x_15 + (-1.0 * _x_x_19)) <= -13.0) && (((x_13 + (-1.0 * _x_x_19)) <= -5.0) && (((x_11 + (-1.0 * _x_x_19)) <= -8.0) && (((x_10 + (-1.0 * _x_x_19)) <= -17.0) && (((x_7 + (-1.0 * _x_x_19)) <= -10.0) && (((x_6 + (-1.0 * _x_x_19)) <= -20.0) && (((x_5 + (-1.0 * _x_x_19)) <= -17.0) && (((x_0 + (-1.0 * _x_x_19)) <= -3.0) && ((x_3 + (-1.0 * _x_x_19)) <= -11.0)))))))))) && (((x_18 + (-1.0 * _x_x_19)) == -5.0) || (((x_15 + (-1.0 * _x_x_19)) == -13.0) || (((x_13 + (-1.0 * _x_x_19)) == -5.0) || (((x_11 + (-1.0 * _x_x_19)) == -8.0) || (((x_10 + (-1.0 * _x_x_19)) == -17.0) || (((x_7 + (-1.0 * _x_x_19)) == -10.0) || (((x_6 + (-1.0 * _x_x_19)) == -20.0) || (((x_5 + (-1.0 * _x_x_19)) == -17.0) || (((x_0 + (-1.0 * _x_x_19)) == -3.0) || ((x_3 + (-1.0 * _x_x_19)) == -11.0)))))))))))) && (((((_EL_X_1277 == (_x__EL_U_1276 || ( !(_x__EL_U_1274 || ( !(_x__EL_U_1272 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_13))))))))) && ((_EL_U_1276 == (_x__EL_U_1276 || ( !(_x__EL_U_1274 || ( !(_x__EL_U_1272 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_13))))))))) && ((_EL_U_1272 == (_x__EL_U_1272 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_13))))) && (_EL_U_1274 == (_x__EL_U_1274 || ( !(_x__EL_U_1272 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_13)))))))))) && (_x__J1295 == (( !((_J1295 && _J1301) && _J1307)) && (((_J1295 && _J1301) && _J1307) || (((20.0 <= (x_10 + (-1.0 * x_13))) || ( !((20.0 <= (x_10 + (-1.0 * x_13))) || _EL_U_1272))) || _J1295))))) && (_x__J1301 == (( !((_J1295 && _J1301) && _J1307)) && (((_J1295 && _J1301) && _J1307) || ((( !((20.0 <= (x_10 + (-1.0 * x_13))) || _EL_U_1272)) || ( !(_EL_U_1274 || ( !((20.0 <= (x_10 + (-1.0 * x_13))) || _EL_U_1272))))) || _J1301))))) && (_x__J1307 == (( !((_J1295 && _J1301) && _J1307)) && (((_J1295 && _J1301) && _J1307) || ((( !(_EL_U_1274 || ( !((20.0 <= (x_10 + (-1.0 * x_13))) || _EL_U_1272)))) || ( !(_EL_U_1276 || ( !(_EL_U_1274 || ( !((20.0 <= (x_10 + (-1.0 * x_13))) || _EL_U_1272))))))) || _J1307))))));
x_14 = _x_x_14;
_J1307 = _x__J1307;
_J1301 = _x__J1301;
x_8 = _x_x_8;
_J1295 = _x__J1295;
x_17 = _x_x_17;
_EL_X_1277 = _x__EL_X_1277;
x_3 = _x_x_3;
x_0 = _x_x_0;
x_5 = _x_x_5;
x_9 = _x_x_9;
x_6 = _x_x_6;
x_1 = _x_x_1;
x_7 = _x_x_7;
x_10 = _x_x_10;
x_11 = _x_x_11;
x_13 = _x_x_13;
x_15 = _x_x_15;
x_19 = _x_x_19;
x_18 = _x_x_18;
_EL_U_1272 = _x__EL_U_1272;
x_2 = _x_x_2;
_EL_U_1274 = _x__EL_U_1274;
_EL_U_1276 = _x__EL_U_1276;
x_4 = _x_x_4;
x_16 = _x_x_16;
x_12 = _x_x_12;
}
}
|
the_stack_data/88361.c | int main() {
return ~4;
} |
the_stack_data/61075327.c | /*
************************************************
username : smmehrab
fullname : s.m.mehrabul islam
email : [email protected]
institute : university of dhaka, bangladesh
session : 2017-2018
************************************************
*/
#include<stdio.h>
#include<math.h>
int main()
{
long long int t,cs=0,a,b,i,j,k,l,x,y,as,bs;
scanf("%lld",&t);
while(t--){
scanf("%lld %lld",&a,&b);
i=2*((a-1)/3);
if((a-1)%3==2) i++;
j=2*(b/3);
if(b%3==2) j++;
printf("Case %lld: %lld\n",++cs,j-i);
}
return 0;
}
|
the_stack_data/146758.c | /*
* init_space.c
*
* Created on: Jun 19, 2015
* Author: alan
*/
void init_space(int dim,int* perm){
/* dim: the dimensions of the space
* perm: the permutation to start with
*
*/
/* calculate the edges of the space
* need to know the coordinate of perm
*/
for(int i=0;i<dim;i++){
/* check offset of current permutation */
/* calcuate the soluions in this column*/
/* move to the next column */
}
}
|
the_stack_data/444256.c | #include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
int hashing(int chave, int table_size)
{
return chave % table_size;
}
int sondagem_linear(int chave, int i, int table_size)
{
return hashing(chave + i, table_size);
}
int sondagem_quadatica(int chave, int i, int table_size)
{
return hashing(chave + 3 * i + 7 * i * i, table_size);
}
int hashing_aux(int chave)
{
return 1 + (chave % 13);
}
int duplo_hash(int chave, int i, int table_size)
{
return (hashing(chave, table_size) + i * hashing_aux(chave)) % table_size;
}
void imprime_enderecamento_aberto(int chaves[], int table_size, int (*hashing)(int chave, int i, int table_size))
{
for (int i = 0; i < 10; i++)
{
printf("\n%d ->", chaves[i]);
for (int j = 0; j < table_size; j++)
{
printf(" %d", hashing(chaves[i], j, table_size));
}
}
}
void main()
{
int m = 17;
int chaves[] = {2, 32, 43, 16, 77, 51, 1, 17, 42, 111};
printf("\nSondagem linear:");
imprime_enderecamento_aberto(chaves, m, sondagem_linear);
printf("\n");
printf("\nSondagem quadrática:");
imprime_enderecamento_aberto(chaves, m, sondagem_quadatica);
printf("\n");
printf("\nHash duplo:");
imprime_enderecamento_aberto(chaves, m, duplo_hash);
printf("\n");
} |
the_stack_data/178264455.c | #ifdef GNU_VARIADIC
# define FOO(args...) do { foo(args); } while (0)
#else
# define FOO(...) do { foo(__VA_ARGS__); } while (0)
#endif
#define BAR(x) FOO("x"); FOO(")");
void
foo(char *a)
{
BAR();
}
|
the_stack_data/145983.c | /*
* FILE: vo_postprocess/double-framerate.c
* AUTHORS: Martin Benes <[email protected]>
* Lukas Hejtmanek <[email protected]>
* Petr Holub <[email protected]>
* Milos Liska <[email protected]>
* Jiri Matela <[email protected]>
* Dalibor Matura <[email protected]>
* Ian Wesley-Smith <[email protected]>
*
* Copyright (c) 2005-2011 CESNET z.s.p.o.
*
* Redistribution and use in source and binary forms, with or without
* modification, is 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*
* This product includes software developed by CESNET z.s.p.o.
*
* 4. Neither the name of the CESNET 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 AUTHORS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESSED 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 AUTHORS 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 HAVE_CONFIG_H
#include "config.h"
#include "config_unix.h"
#endif
#ifdef HAVE_LINUX
#include "debug.h"
#include "video_codec.h"
#include <pthread.h>
#include <stdlib.h>
#include "vo_postprocess/scale.h"
#include "video_display.h"
#include <GL/glew.h>
#include "gl_context.h"
struct state_scale {
struct video_frame *in;
struct gl_context context;
int scaled_width, scaled_height;
GLuint tex_input;
GLuint tex_output;
GLuint fbo;
};
void scale_get_supported_codecs(codec_t ** supported_codecs, int *count)
{
codec_t supported[] = {UYVY, RGBA};
*supported_codecs = supported;
*count = sizeof(supported) / sizeof(codec_t);
}
static void usage()
{
printf("Scale postprocessor settings:\n");
printf("\t-p scale:width:height\n");
}
void * scale_init(char *config) {
struct state_scale *s;
char *save_ptr = NULL;
char *ptr;
if(!config) {
fprintf(stderr, "Scale postprocessor incorrect usage.\n");
}
if(!config || strcmp(config, "help") == 0) {
usage();
return NULL;
}
s = (struct state_scale *)
malloc(sizeof(struct state_scale));
ptr = strtok_r(config, ":", &save_ptr);
assert(ptr != NULL);
s->scaled_width = atoi(ptr);
assert(ptr != NULL);
ptr = strtok_r(NULL, ":", &save_ptr);
s->scaled_height = atoi(ptr);
assert(s != NULL);
s->in = NULL;
init_gl_context(&s->context, GL_CONTEXT_LEGACY);
gl_context_make_current(&s->context);
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &s->tex_input);
glBindTexture(GL_TEXTURE_2D, s->tex_input);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenTextures(1, &s->tex_output);
glBindTexture(GL_TEXTURE_2D, s->tex_input);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenFramebuffers(1, &s->fbo);
return s;
}
int scale_reconfigure(void *state, struct video_desc desc)
{
struct state_scale *s = (struct state_scale *) state;
struct tile *in_tile;
int i;
int width, height;
if(s->in) {
int i;
for(i = 0; i < (int) s->in->tile_count; ++i) {
free(s->in->tiles[0].data);
}
vf_free(s->in);
}
s->in = vf_alloc(desc.tile_count);
s->in->color_spec = desc.color_spec;
s->in->fps = desc.fps;
s->in->interlacing = desc.interlacing;
for(i = 0; i < (int) desc.tile_count; ++i) {
in_tile = vf_get_tile(s->in, i);
in_tile->width = desc.width;
in_tile->height = desc.height;
in_tile->linesize = vc_get_linesize(desc.width, desc.color_spec);
in_tile->data_len = in_tile->linesize * desc.height;
in_tile->data = malloc(in_tile->data_len);
}
gl_context_make_current(&s->context);
glBindTexture(GL_TEXTURE_2D, s->tex_input);
width = in_tile->width;
height = in_tile->height;
if(s->in->color_spec == UYVY) {
width /= 2;
}
if(s->in->interlacing == INTERLACED_MERGED) {
width *= 2;
height /= 2;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, s->tex_output);
width = s->scaled_width;
height = s->scaled_height;
if(s->in->color_spec == UYVY) {
width /= 2;
}
if(s->in->interlacing == INTERLACED_MERGED) {
width *= 2;
height /= 2;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
return TRUE;
}
struct video_frame * scale_getf(void *state)
{
struct state_scale *s = (struct state_scale *) state;
return s->in;
}
void scale_postprocess(void *state, struct video_frame *in, struct video_frame *out, int req_pitch)
{
struct state_scale *s = (struct state_scale *) state;
int i;
int width, height;
int src_linesize = vc_get_linesize(out->tiles[0].width, out->color_spec);
char *tmp_data = NULL;
if(req_pitch != src_linesize) {
tmp_data = malloc(src_linesize *
out->tiles[0].height);
}
gl_context_make_current(&s->context);
for(i = 0; i < (int) in->tile_count; ++i) {
struct tile *in_tile = vf_get_tile(s->in, i);
glBindTexture(GL_TEXTURE_2D, s->tex_input);
width = in_tile->width;
height = in_tile->height;
if(s->in->color_spec == UYVY) {
width /= 2;
}
if(s->in->interlacing == INTERLACED_MERGED) {
width *= 2;
height /= 2;
}
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
GL_RGBA, GL_UNSIGNED_BYTE, in_tile->data);
glBindFramebuffer(GL_FRAMEBUFFER, s->fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, s->tex_output, 0);
width = s->scaled_width;
height = s->scaled_height;
if(s->in->color_spec == UYVY) {
width /= 2;
}
if(s->in->interlacing == INTERLACED_MERGED) {
width *= 2;
height /= 2;
}
glViewport(0, 0, width, height);
glBindTexture(GL_TEXTURE_2D, s->tex_input);
glClearColor(1,0,0,1);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0);
glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0);
glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0);
glEnd();
glBindTexture(GL_TEXTURE_2D, s->tex_output);
if(tmp_data) { /* we need to change pitch */
int y;
glReadPixels(0, 0, width , height, GL_RGBA, GL_UNSIGNED_BYTE, tmp_data);
char *src = tmp_data;
char *dst = out->tiles[i].data;
for (y = 0; y < (int) out->tiles[i].height; y += 1) {
memcpy(dst, src, src_linesize);
dst += req_pitch;
src += src_linesize;
}
} else {
glReadPixels(0, 0, width , height, GL_RGBA, GL_UNSIGNED_BYTE, out->tiles[i].data);
}
}
free(tmp_data);
}
void scale_done(void *state)
{
struct state_scale *s = (struct state_scale *) state;
glDeleteTextures(1, &s->tex_input);
glDeleteTextures(1, &s->tex_output);
glDeleteFramebuffers(1, &s->fbo);
free(s->in->tiles[0].data);
vf_free(s->in);
destroy_gl_context(&s->context);
free(state);
}
void scale_get_out_desc(void *state, struct video_desc *out, int *in_display_mode, int *out_frames)
{
struct state_scale *s = (struct state_scale *) state;
out->width = s->scaled_width;
out->height = s->scaled_height;
out->color_spec = s->in->color_spec;
out->interlacing = s->in->interlacing;
out->fps = s->in->fps;
out->tile_count = 1;
*in_display_mode = DISPLAY_PROPERTY_VIDEO_MERGED;
*out_frames = 1;
}
#endif /* HAVE_LINUX */
|
the_stack_data/45450026.c | /* mbed Microcontroller Library
* Copyright (c) 2018-2019 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if DEVICE_LPTICKER
#include "ti/devices/cc32xx/inc/hw_types.h"
#include "ti/devices/cc32xx/driverlib/prcm.h"
/*******************************************************************************
* lp_ticker implementation on this target is mapped on top of the sleep clock counter
* that is running in the lowest energy modes. The sleep clock counter is 48b running
* at 32.768KHz. This gives 0.03ms resolution for the low power timer which requires
* millisecond accuracy.
*
******************************************************************************/
#include "lp_ticker_api.h"
#include "mbed_critical.h"
// There's actually 48b but Mbed OS supports 32b only.
#define RTC_BITS 32u
#define RTC_FREQ 32768u
static bool rtc_inited = false;
const ticker_info_t *lp_ticker_get_info()
{
static const ticker_info_t info = {
RTC_FREQ, // 32KHz
RTC_BITS // 32 bit counter
};
return &info;
}
void lp_ticker_init()
{
if (PRCMRTCInUseGet() == true)
// When RTC is in use, slow clock counter can't be accessed
{
return;
}
if (!rtc_inited) {
NVIC_SetVector(INT_PRCM_IRQn, (uint32_t)lp_ticker_irq_handler);
NVIC_ClearPendingIRQ(INT_PRCM_IRQn);
NVIC_EnableIRQ(INT_PRCM_IRQn);
PRCMIntStatus(); // Read clears pending interrupts
rtc_inited = true;
} else {
PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
}
}
void lp_ticker_free()
{
/* Disable the RTC if it was inited and is no longer in use by anyone. */
if (rtc_inited) {
NVIC_DisableIRQ(INT_PRCM_IRQn);
rtc_inited = false;
}
}
void lp_ticker_set_interrupt(timestamp_t timestamp)
{
// timestamp is defined as 32b.
core_util_critical_section_enter();
// Clear pending interrupt
PRCMIntStatus();
PRCMSlowClkCtrMatchSet(timestamp);
PRCMIntEnable(PRCM_INT_SLOW_CLK_CTR);
core_util_critical_section_exit();
}
void lp_ticker_fire_interrupt(void)
{
core_util_critical_section_enter();
NVIC_SetPendingIRQ(INT_PRCM_IRQn);
core_util_critical_section_exit();
}
void lp_ticker_disable_interrupt()
{
PRCMIntDisable(PRCM_INT_SLOW_CLK_CTR);
}
void lp_ticker_clear_interrupt()
{
PRCMIntStatus(); // Read clears pending interrupts
}
timestamp_t lp_ticker_read()
{
// Read forever until reaching two of the same
volatile unsigned long long read_previous, read_current;
do {
read_previous = PRCMSlowClkCtrFastGet();
read_current = PRCMSlowClkCtrFastGet();
} while (read_previous != read_current);
return read_current;
}
#endif /* DEVICE_LPTICKER */
|
the_stack_data/26700995.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
C语言 结构 函数
*/
// 单向链表
struct Node {
int id;
struct Node * next;
};
// 创建节点
struct Node * NodeAlloc();
// 删除节点并且删除全部子节点
void NodeDealloc(struct Node * node);
// 在 curr 前面插入节点 node
void NodeBefore(struct Node * curr,struct Node * node);
// 在 curr 后面插入节点 node
void NodeAfter(struct Node * curr,struct Node * node);
int main() {
return 0;
}
|
the_stack_data/25670.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <time.h>
size_t g = 0;
void *m_Fun(void *argv)
{
int *m_id = (int *)argv;
static size_t s = 0;
++s;
++g;
printf("ID: %d, Static: %lu, Global: %lu\n", *m_id, ++s, ++g);
}
int main()
{
pthread_t id;
for (size_t i = 0; i < 3; i++)
{
pthread_create(&id, NULL, m_Fun, (void *)&id);
}
sleep(5);
printf("\n\tTerminando.\n\n");
pthread_exit(NULL);
return 0;
}
|
the_stack_data/114643.c | /*
* loancalc.c - Loan Calculator
*
* Brett Lee <[email protected]>
*/
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
main( int argc, char *argv[] ) {
char answer, filename;
FILE *cfptr, *fstdout;
/*
printf("\nARGC: %d \n", argc);
printf("ARGV0: %s \n", argv[0]);
printf("ARGV1: %s \n", argv[1]);
printf("ARGV2: %s \n", argv[2]);
*/
if (( argc != 1 ) && ( argc != 3 ))
{
printf("\nUsage: %s [ -f <filename> ]\n", argv[0]);
return 0;
}
if ( argv[1] == NULL )
{
fstdout = stdout;
}
else if ( strcmp (argv[1], "-f" ))
{
printf("\nUsage: %s [ -f <filename> ]\n", argv[0]);
return 0;
} else {
if (( cfptr = fopen( argv[2], "w" )) == NULL )
{
printf("\nCould not open file: %s \n", argv[2]);
return 0;
}
fstdout = cfptr;
}
system ("tput clear");
printf(" \n\
\n\
Amortization Schedules \n\
------------------------------------------- \n\
\n\
Which of the following loans would you like to consider? \n\
\n\
(N) Non-Amortized :: Pay Interest Only - Big Balloon Due at Term \n\
(P) Partially Amortized :: Pay Some of the Principle - Balloon Due at Term \n\
(A) Fully Amortized :: Pay All of the Principle and Interest \n\
(E) Fully Amortized + :: Make Extra Payments Toward the Principle \n\
\n\
(Q) Quit \n\
\n\
Please make your selection: ");
scanf("%c", &answer);
switch ( answer ) {
case 'N': case 'n':
system ("tput clear");
do_nonamort( fstdout );
break;
case 'P': case 'p':
system ("tput clear");
do_partialamort( fstdout );
break;
case 'A': case 'a':
system ("tput clear");
do_amort( fstdout );
break;
case 'E': case 'e':
system ("tput clear");
do_amort_extra( fstdout );
break;
default:
break;
}
} /* End of Main */
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */
/* -------------------------------------------------------------- */
double round (double dollars)
{
double pennies;
pennies = floor (dollars * 100 + .5);
return pennies / 100.;
}
int do_amort( FILE *fstdout )
{
int n, years;
double loanamt, intyr;
double npmts, intmo, pmt, bal, intpmt, prinpmt;
double principlepaid, interestpaid, totalpaid;
double pow (double, double);
printf("\nYou will need to enter the following:\n \n\
Principal \n\
Interest Rate \n\
Term of the Loan\n\n");
printf("Enter principal (e.g. 119000) : ");
scanf("%lf", &loanamt);
printf("Enter annual interest rate (e.g. 8.375) : ");
scanf("%lf", &intyr);
printf("Enter number of years (e.g. 30): ");
scanf("%d", &years);
fprintf(fstdout, "principal = %7.2f interest = %6.4f%% years = %d \n",
loanamt, intyr, years);
fprintf(fstdout, " \n\
Payment Total Interest Principal Balance \n\
Number Payment Portion Portion \n\
------------------------------------------------------\n");
fprintf(fstdout, " %55.2f\n", loanamt);
npmts = years * 12.0;
intmo = intyr / 12.0 / 100;
pmt = loanamt * intmo / (1 - (pow (1 + intmo, -1 * npmts)));
pmt = round (pmt);
bal = loanamt;
principlepaid = 0;
interestpaid = 0;
totalpaid = 0;
for (n = 1; n <= npmts; n++) {
intpmt = round (bal * intmo);
if (n < npmts)
prinpmt = pmt - intpmt;
else
prinpmt = bal;
bal -= prinpmt;
fprintf(fstdout, "%8d %11.2f %10.2f %10.2f %13.2f\n",
n, intpmt + prinpmt, intpmt, prinpmt, bal);
principlepaid += prinpmt;
interestpaid += intpmt;
totalpaid += (prinpmt + intpmt);
}
fprintf(fstdout, " \n\
Payment Total Interest Principal Balance \n\
Number Payment Portion Portion \n\
-----------------------------------------------------\n\n");
fprintf(fstdout, "Terms of the Loan:\n");
fprintf(fstdout, "------------------\n");
fprintf(fstdout,
"\tPrincipal: %10.2f \n\tInterest: %10.3f%% \n\tYears: %14d \n\n",
loanamt, intyr, years);
fprintf(fstdout, "Truth in Lending:\n");
fprintf(fstdout, "-----------------\n");
fprintf(fstdout,
"\tPrinciple: %10.2f \n\tInterest: %10.2f \n\tTotal: %10.2f \n",
principlepaid, interestpaid, totalpaid);
return 1;
}
int do_amort_extra( FILE *fstdout )
{
int n, years;
double loanamt, intyr, extrapmt;
double npmts, intmo, pmt, bal, intpmt, prinpmt;
double principlepaid, interestpaid, totalpaid;
double pow (double, double);
printf("\nYou will need to enter the following: \n\n\
Principal \n\
Interest Rate \n\
Term of the Loan \n\
Any extra payments \n\n");
printf("Enter principal (e.g. 119000) : ");
scanf("%lf", &loanamt);
printf("Enter annual interest rate (e.g. 8.375) : ");
scanf("%lf", &intyr);
printf("Enter number of years (e.g. 30): ");
scanf("%d", &years);
printf("Extra payment each month: (e.g. 200): ");
scanf("%lf", &extrapmt);
fprintf(fstdout, "principal = %7.2f interest = %6.4f%% years = %d \n",
loanamt, intyr, years);
fprintf(fstdout, " \n\
-----------------------------------------------------------------------------\n\
Payment Required Extra Total Interest Principal Balance \n\
Number Payment Payment Payment Portion Portion \n\
-----------------------------------------------------------------------------\n\n");
fprintf(fstdout, " %75.2f\n", loanamt);
npmts = years * 12.0;
intmo = intyr / 12.0 / 100;
pmt = loanamt * intmo / (1 - (pow (1 + intmo, -1 * npmts)));
pmt = round (pmt);
bal = loanamt;
n = 1;
principlepaid = 0;
interestpaid = 0;
totalpaid = 0;
while ( bal > 0 ) {
intpmt = round (bal * intmo);
if (pmt > (bal + intpmt)) {
pmt = (bal + intpmt);
extrapmt = 0;
prinpmt = bal;
}
else if ((pmt + extrapmt) > (bal + intpmt)) {
extrapmt = (bal + intpmt - pmt);
prinpmt = bal;
}
else
prinpmt = (pmt + extrapmt - intpmt);
bal -= prinpmt;
fprintf(fstdout, "%4d %12.2f %9.2f %10.2f %11.2f %12.2f %12.2f\n",
n, pmt, extrapmt, pmt + extrapmt, intpmt, prinpmt, bal);
principlepaid += (prinpmt);
interestpaid += intpmt;
totalpaid += (prinpmt + intpmt);
n++;
}
fprintf(fstdout, " \n\
-----------------------------------------------------------------------------\n\
Payment Required Extra Total Interest Principal Balance \n\
Number Payment Payment Payment Portion Portion \n\
-----------------------------------------------------------------------------\n\n");
fprintf(fstdout, "Terms of the Loan:\n");
fprintf(fstdout, "------------------\n");
fprintf(fstdout,
"\tPrincipal: %10.2f \n\tInterest: %10.3f%% \n\tYears: %14d \n\n",
loanamt, intyr, years);
fprintf(fstdout, "Truth in Lending:\n");
fprintf(fstdout, "-----------------\n");
fprintf(fstdout,
"\tPrinciple: %10.2f \n\tInterest: %10.2f \n\tTotal: %10.2f \n",
principlepaid, interestpaid, totalpaid);
return 1;
}
int do_nonamort( FILE *fstdout )
{
int n, years;
double loanamt, intyr;
double npmts, intmo, pmt, bal, intpmt, prinpmt;
double principlepaid, interestpaid, totalpaid;
double pow (double, double);
printf("\nYou will need to enter the following:\n \n\
Principal \n\
Interest Rate\n\n");
printf("Enter principal (e.g. 119000) : ");
scanf("%lf", &loanamt);
printf("Enter annual interest rate (e.g. 8.375) : ");
scanf("%lf", &intyr);
fprintf(fstdout, "principal = %7.2f interest = %6.4f%%\n",
loanamt, intyr);
fprintf(fstdout, " \n\
\n\
Non-Amoritized Calculations \n\
------------------------------------------------------\n");
intmo = intyr / 12.0 / 100;
pmt = loanamt * intmo;
pmt = round (pmt);
bal = loanamt;
intpmt = round (bal * intmo);
prinpmt = pmt - intpmt;
bal -= prinpmt;
fprintf(fstdout, " \n\
Loan Amount: %35.2f\n \n\
Monthly Payments: %35.2f\n \n\
Principal Paid: %35.2f\n \n\
Balance Due: %35.2f\n\n", loanamt, intpmt, prinpmt, bal);
return 1;
}
int do_partialamort( FILE *fstdout )
{
int n, years;
double loanamt, intyr;
double npmts, intmo, pmt, bal, intpmt, prinpmt;
double principlepaid, interestpaid, totalpaid;
double pow (double, double);
printf("\nYou will need to enter the following:\n \n\
Principal \n\
Interest Rate \n\
Term of the Loan \n\
Payment Amount\n\n");
printf("Enter the loan amount (e.g. 119000) : ");
scanf("%lf", &loanamt);
printf("Enter the annual interest rate as a percentage (e.g. 5.375) : ");
scanf("%lf", &intyr);
printf("Enter the term of the loan - in years (e.g. 30): ");
scanf("%d", &years);
printf("Enter the payment amount - per month (e.g. 1500): ");
scanf("%lf", &pmt);
fprintf(fstdout,
"principal = %7.2f interest = %6.4f%% years = %d payment = %7.2f\n",
loanamt, intyr, years, pmt);
fprintf(fstdout, " \n\
Payment Total Interest Principal Balance \n\
Number Payment Portion Portion \n\
------------------------------------------------------\n");
fprintf(fstdout, " %55.2f\n", loanamt);
npmts = years * 12.0;
intmo = intyr / 12.0 / 100;
bal = loanamt;
principlepaid = 0;
interestpaid = 0;
totalpaid = 0;
for (n = 1; n <= npmts; n++) {
intpmt = round (bal * intmo);
if (n < npmts)
prinpmt = pmt - intpmt;
else
prinpmt = bal;
bal -= prinpmt;
fprintf(fstdout, "%8d %11.2f %10.2f %10.2f %13.2f\n",
n, intpmt + prinpmt, intpmt, prinpmt, bal);
principlepaid += prinpmt;
interestpaid += intpmt;
totalpaid += (prinpmt + intpmt);
}
fprintf(fstdout, " \n\
Payment Total Interest Principal Balance \n\
Number Payment Portion Portion \n\
-----------------------------------------------------\n\n");
fprintf(fstdout, "Terms of the Loan:\n");
fprintf(fstdout, "------------------\n");
fprintf(fstdout,
"\tPrincipal: %10.2f \n\tInterest: %10.3f%% \n\tYears: %14d \n\n",
loanamt, intyr, years);
fprintf(fstdout, "Truth in Lending:\n");
fprintf(fstdout, "-----------------\n");
fprintf(fstdout,
"\tPrinciple: %10.2f \n\tInterest: %10.2f \n\tTotal: %10.2f \n",
principlepaid, interestpaid, totalpaid);
return 1;
}
|
the_stack_data/133105.c | #include <stdbool.h> /* C99 only */
#include <stdio.h>
#include <stdlib.h>
#define NUM_RANKS 13
#define NUM_SUITS 4
#define NUM_CARDS 5
/* external variables */
int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUITS];
bool straight, flush, four, three, ace_low;
int pairs;
/* prototypes */
void read_cards(void);
void analyze_hand(void);
void print_result(void);
/***************************************************************
* main: Calls read_cards, analyze_hand and print_result *
* repeatedly. *
***************************************************************/
int main(void)
{
for (;;)
{
read_cards();
analyze_hand();
print_result();
}
}
/***************************************************************
* read_cards: Reads the cards into external variables; *
* checks for bad cards and duplicate cards. *
***************************************************************/
void read_cards(void)
{
bool card_exists[NUM_RANKS][NUM_SUITS];
char ch, rank_ch, suit_ch;
int rank, suit;
bool bad_card;
int cards_read = 0;
for (rank = 0; rank < NUM_RANKS; rank++)
{
num_in_rank[rank] = 0;
for (suit = 0; suit < NUM_SUITS; suit++)
card_exists[rank][suit] = false;
}
for (suit = 0; suit < NUM_SUITS; suit++)
num_in_suit[suit] = 0;
while (cards_read < NUM_CARDS)
{
bad_card = false;
printf("Enter a card: ");
rank_ch = getchar();
switch (rank_ch)
{
case '0':
exit(EXIT_SUCCESS);
case '2':
rank = 0;
break;
case '3':
rank = 1;
break;
case '4':
rank = 2;
break;
case '5':
rank = 3;
break;
case '6':
rank = 4;
break;
case '7':
rank = 5;
break;
case '8':
rank = 6;
break;
case '9':
rank = 7;
break;
case 't':
case 'T':
rank = 8;
break;
case 'j':
case 'J':
rank = 9;
break;
case 'q':
case 'Q':
rank = 10;
break;
case 'k':
case 'K':
rank = 11;
break;
case 'a':
case 'A':
rank = 12;
break;
default:
bad_card = true;
}
suit_ch = getchar();
switch (suit_ch)
{
case 'c':
case 'C':
suit = 0;
break;
case 'd':
case 'D':
suit = 1;
break;
case 'h':
case 'H':
suit = 2;
break;
case 's':
case 'S':
suit = 3;
break;
default:
bad_card = true;
}
while ((ch = getchar()) != '\n')
{
if (ch != ' ')
bad_card = true;
}
if (bad_card)
printf("Bad card; ignored.\n");
else if (card_exists[rank][suit])
printf("Duplicate card; ignored.\n");
else
{
num_in_rank[rank]++;
num_in_suit[suit]++;
card_exists[rank][suit] = true;
cards_read++;
}
}
}
/***************************************************************
* analyze_hand: Determines whether the hand contains a *
* straight, a flush, four-of-a-kind, and/or *
* three-of-a-kind; determines the number of *
* pairs; stores the result into external *
* variables *
***************************************************************/
void analyze_hand(void)
{
int num_consec = 0;
int rank, suit;
straight = false;
flush = false;
four = false;
three = false;
ace_low = false;
pairs = 0;
/* check for flush */
for (suit = 0; suit < NUM_SUITS; suit++)
{
if (num_in_suit[suit] == NUM_CARDS)
flush = true;
}
/* check for straight / ace-low */
rank = 0;
while (num_in_rank[rank] == 0)
rank++;
for (; rank < NUM_RANKS && num_in_rank[rank] > 0; rank++)
num_consec++;
if (num_consec == 4 && rank == 4 && num_in_rank[12] == 1)
{
ace_low = true;
return;
}
if (num_consec == NUM_CARDS)
{
straight = true;
return;
}
/* check for 4-of-a-kind, 3-of-a-kind and pairs */
for (rank = 0; rank < NUM_RANKS; rank++)
{
if (num_in_rank[rank] == 4)
four = true;
if (num_in_rank[rank] == 3)
three = true;
if (num_in_rank[rank] == 2)
pairs++;
}
}
/***************************************************************
* print_result: Notifies the user of the result, using *
* the external variables set by analyze_hand. *
***************************************************************/
void print_result(void)
{
if (straight && flush)
printf("Straight flush");
else if (four)
printf("Four of a kind");
else if (three && pairs == 1)
printf("Full house");
else if (ace_low)
printf("Ace-Low");
else if (flush)
printf("Flush");
else if (straight)
printf("Straight");
else if (pairs == 2)
printf("Two pairs");
else if (pairs == 1)
printf("Pair");
else
printf("High card");
printf("\n\n");
} |
the_stack_data/87637359.c | /* rng.c
This file contains the code for a high-quality random number
generator written by Don Knuth. The auxilliary routine
ran_arr_cycle() has been modified slightly, and ran_init() is new.
To use it:
0. #include "rng.h" (or "naututil.h" if you are using nauty)
1. Call ran_init(seed), where seed is any long integer.
This step is optional, but if you don't use it you
will always get the same sequence of random numbers.
2. For each random number, use the NEXTRAN macro. It will
give a random value in the range 0..2^30-1. Alternatively,
KRAN(k) will have a random value in the range 0..k-1.
KRAN(k) actually gives you NEXTRAN mod k, so it is not
totally uniform if k is very large. In that case, you
can use the slightly slower GETKRAN(k,var) to set the
variable var to a better random number from 0..k-1.
Brendan McKay, July 2002. Fixed Nov 2002 on advice of DEK.
*/
/* This program by D E Knuth is in the public domain and freely copyable
* AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES!
* It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6
* (or in the errata to the 2nd edition --- see
* http://www-cs-faculty.stanford.edu/~knuth/taocp.html
* in the changes to Volume 2 on pages 171 and following). */
/* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are
included here; there's no backwards compatibility with the original. */
/* If you find any bugs, please report them immediately to
* [email protected]
* (and you will be rewarded if the bug is genuine). Thanks! */
/************ see the book for explanations and caveats! *******************/
/************ in particular, you need two's complement arithmetic **********/
#define KK 100 /* the long lag */
#define LL 37 /* the short lag */
#define MM (1L<<30) /* the modulus */
#define mod_diff(x,y) (((x)-(y))&(MM-1)) /* subtraction mod MM */
long ran_x[KK]; /* the generator state */
#ifdef __STDC__
void ran_array(long aa[],int n)
#else
void ran_array(aa,n) /* put n new random numbers in aa */
long *aa; /* destination */
int n; /* array length (must be at least KK) */
#endif
{
int i,j;
for (j=0;j<KK;j++) aa[j]=ran_x[j];
for (;j<n;j++) aa[j]=mod_diff(aa[j-KK],aa[j-LL]);
for (i=0;i<LL;i++,j++) ran_x[i]=mod_diff(aa[j-KK],aa[j-LL]);
for (;i<KK;i++,j++) ran_x[i]=mod_diff(aa[j-KK],ran_x[i-LL]);
}
/* the following routines are from exercise 3.6--15 */
/* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */
#define QUALITY 1009 /* recommended quality level for high-res use */
static long ran_arr_buf[QUALITY];
static long ran_arr_dummy=-1, ran_arr_started=-1;
long *ran_arr_ptr=&ran_arr_dummy; /* the next random number, or -1 */
#define TT 70 /* guaranteed separation between streams */
#define is_odd(x) ((x)&1) /* units bit of x */
#ifdef __STDC__
void ran_start(long seed)
#else
void ran_start(seed) /* do this before using ran_array */
long seed; /* selector for different streams */
#endif
{
int t,j;
long x[KK+KK-1]; /* the preparation buffer */
long ss=(seed+2)&(MM-2);
for (j=0;j<KK;j++) {
x[j]=ss; /* bootstrap the buffer */
ss<<=1; if (ss>=MM) ss-=MM-2; /* cyclic shift 29 bits */
}
x[1]++; /* make x[1] (and only x[1]) odd */
for (ss=seed&(MM-1),t=TT-1; t; ) {
for (j=KK-1;j>0;j--) x[j+j]=x[j], x[j+j-1]=0; /* "square" */
for (j=KK+KK-2;j>=KK;j--)
x[j-(KK-LL)]=mod_diff(x[j-(KK-LL)],x[j]),
x[j-KK]=mod_diff(x[j-KK],x[j]);
if (is_odd(ss)) { /* "multiply by z" */
for (j=KK;j>0;j--) x[j]=x[j-1];
x[0]=x[KK]; /* shift the buffer cyclically */
x[LL]=mod_diff(x[LL],x[KK]);
}
if (ss) ss>>=1; else t--;
}
for (j=0;j<LL;j++) ran_x[j+KK-LL]=x[j];
for (;j<KK;j++) ran_x[j-LL]=x[j];
for (j=0;j<10;j++) ran_array(x,KK+KK-1); /* warm things up */
ran_arr_ptr=&ran_arr_started;
}
void
ran_init(long seed) /* Added by BDM: use instead of ran_start. */
/* But this is less important with this version */
{
ran_start((unsigned long)seed % (MM-2));
}
#define ran_arr_next() (*ran_arr_ptr>=0? *ran_arr_ptr++: ran_arr_cycle())
long
ran_arr_cycle(void)
/* Modified by BDM to automatically initialise
if no explicit initialisation has been done */
{
if (ran_arr_ptr==&ran_arr_dummy)
ran_start(314159L); /* the user forgot to initialize */
ran_array(ran_arr_buf,QUALITY);
ran_arr_buf[KK]=-1;
ran_arr_ptr=ran_arr_buf+1;
return ran_arr_buf[0];
}
|
the_stack_data/6388129.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int arr[] = {1,2,3,4,5,6,7,8}, l;
// Finding the number of element if they are not set in definition. Size of all array / size of 1 element.
l = sizeof(arr)/sizeof(arr[0]);
printf("%d\n", l);
while (l--)
{
printf("arr[%d] -> %d\n", l, arr[l]);
}
return 0;
}
|
the_stack_data/150141216.c | void ft_escape_convert(char *dest, const char *src)
{
char *dest_pt;
const char *src_pt;
char c;
src_pt = src;
dest_pt = dest;
while (*src_pt)
switch (c = *src_pt++) {
case '\t':
*dest_pt++ = '\\';
*dest_pt++ = 't';
break;
case '\n':
*dest_pt++ = '\\';
*dest_pt++ = 'n';
break;
default:
*dest_pt++ = c;
break;
}
*dest_pt = '\0';
}
#include <stdio.h>
int main(void)
{
char dest[200];
const char *src = "\\norigin is not \n this\0";
ft_escape_convert(dest, src);
printf("%s", dest);
return (0);
}
|
the_stack_data/23576336.c | #include <stdio.h>
#define FALSE 0
#define TRUE 1
#define OUT 0
#define IN 1
/* balanced-parens: checks that all opened parenthesis in a file are followed by a closing parenthesis.
note: this includes parens anywhere in the file, including inside quoted strings and in comments.
TODO: Create an array of "Errors" to output instead of just true|false
TODO: Improve the analyzer to look for anything outside of braces, function and variable declarations, etc...
*/
int main(void)
{
int ch, openparens, openbrackets, openbraces;
char prev, singlequotestate, doublequotestate, commentstate, linecommentstate;
prev = '\0';
singlequotestate = doublequotestate = commentstate = linecommentstate = OUT;
openparens = openbrackets = openbraces = 0;
while ((ch = getchar()) != EOF) {
if (prev == '/') {
if (ch == '*')
commentstate = IN;
else if (ch == '/')
linecommentstate = IN;
prev = ch;
continue;
}
if (commentstate == IN) {
if (prev == '*' && ch == '/')
commentstate = OUT;
prev = ch;
continue;
}
if (linecommentstate == IN) {
if (ch == '\n')
linecommentstate = OUT;
prev = ch;
continue;
}
if (singlequotestate == IN) {
if (ch == '\'')
singlequotestate = OUT;
prev = ch;
continue;
}
if (doublequotestate == IN) {
if (ch == '\"')
doublequotestate = OUT;
prev = ch;
continue;
}
switch(ch) {
case '(':
openparens++;
break;
case '[':
openbrackets++;
break;
case '{':
openbraces++;
break;
case ')':
if (openparens <= 0)
return FALSE;
openparens--;
break;
case ']':
if (openbrackets <= 0)
return FALSE;
openbrackets--;
break;
case '}':
if (openbraces <= 0)
return FALSE;
openbraces--;
break;
}
prev = ch;
}
if (singlequotestate || doublequotestate || commentstate || linecommentstate ||
openparens || openbrackets || openbraces) {
printf("FALSE");
return FALSE;
}
else {
printf("TRUE");
return TRUE;
}
}
|
the_stack_data/212960.c | /* Copyright © 2000 ACME, Inc., All Rights Reserved */ |
the_stack_data/1101040.c | #include <string.h>
#include <panel.h>
#define NLINES 10
#define NCOLS 40
void init_wins(WINDOW **wins, int n);
void win_show(WINDOW *win, char *label, int label_color);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
int main()
{ WINDOW *my_wins[3];
PANEL *my_panels[3];
PANEL *top;
int ch;
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
/* Initialize all the colors */
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_wins(my_wins, 3);
/* Attach a panel to each window */ /* Order is bottom up */
my_panels[0] = new_panel(my_wins[0]); /* Push 0, order: stdscr-0 */
my_panels[1] = new_panel(my_wins[1]); /* Push 1, order: stdscr-0-1 */
my_panels[2] = new_panel(my_wins[2]); /* Push 2, order: stdscr-0-1-2 */
/* Set up the user pointers to the next panel */
set_panel_userptr(my_panels[0], my_panels[1]);
set_panel_userptr(my_panels[1], my_panels[2]);
set_panel_userptr(my_panels[2], my_panels[0]);
/* Update the stacking order. 2nd panel will be on top */
update_panels();
/* Show it on the screen */
attron(COLOR_PAIR(4));
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F1 to Exit)");
attroff(COLOR_PAIR(4));
doupdate();
top = my_panels[2];
while((ch = getch()) != KEY_F(1))
{ switch(ch)
{ case 9:
top = (PANEL *)panel_userptr(top);
top_panel(top);
break;
}
update_panels();
doupdate();
}
endwin();
return 0;
}
/* Put all the windows */
void init_wins(WINDOW **wins, int n)
{ int x, y, i;
char label[80];
y = 2;
x = 10;
for(i = 0; i < n; ++i)
{ wins[i] = newwin(NLINES, NCOLS, y, x);
sprintf(label, "Window Number %d", i + 1);
win_show(wins[i], label, i + 1);
y += 3;
x += 7;
}
}
/* Show the window with a border and a label */
void win_show(WINDOW *win, char *label, int label_color)
{ int startx, starty, height, width;
getbegyx(win, starty, startx);
getmaxyx(win, height, width);
box(win, 0, 0);
mvwaddch(win, 2, 0, ACS_LTEE);
mvwhline(win, 2, 1, ACS_HLINE, width - 2);
mvwaddch(win, 2, width - 1, ACS_RTEE);
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color));
}
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color)
{ int length, x, y;
float temp;
if(win == NULL)
win = stdscr;
getyx(win, y, x);
if(startx != 0)
x = startx;
if(starty != 0)
y = starty;
if(width == 0)
width = 80;
length = strlen(string);
temp = (width - length)/ 2;
x = startx + (int)temp;
wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}
|
the_stack_data/97366.c | /* libFLAC - Free Lossless Audio Codec library
* Copyright (C) 2001-2009 Josh Coalson
* Copyright (C) 2011-2013 Xiph.Org Foundation
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of the Xiph.org Foundation 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 FOUNDATION 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 HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef FLAC_METADATA_INTERFACES
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/stat.h> /* for stat(), maybe chmod() */
#include "private/metadata.h"
#include "FLAC/assert.h"
#include "FLAC/stream_decoder.h"
#include "share/alloc.h"
#include "share/compat.h"
#include "share/macros.h"
#include "share/safe_str.h"
#include "private/macros.h"
#include "private/memory.h"
/* Alias the first (in share/alloc.h) to the second (in src/libFLAC/memory.c). */
#define safe_malloc_mul_2op_ safe_malloc_mul_2op_p
/****************************************************************************
*
* Local function declarations
*
***************************************************************************/
static void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
static void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes);
static void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, unsigned bytes);
static FLAC__uint32 unpack_uint32_(FLAC__byte *b, unsigned bytes);
static FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, unsigned bytes);
static FLAC__uint64 unpack_uint64_(FLAC__byte *b, unsigned bytes);
static FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator);
static FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block);
static FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, unsigned *length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, unsigned block_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, unsigned block_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, unsigned block_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, unsigned max_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, unsigned block_length);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block);
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, unsigned block_length);
static FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block);
static FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, unsigned block_length);
static FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, unsigned block_length);
static FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block);
static FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block);
static FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block);
static FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block);
static FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, unsigned block_length);
static FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block);
static FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, unsigned padding_length, FLAC__bool padding_is_last);
static FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append);
static void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator);
static FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator);
static unsigned seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb);
static unsigned seek_to_first_metadata_block_(FILE *f);
static FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append);
static FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup);
static FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
static FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status);
static FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status);
static FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status);
static FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status);
static FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status);
static void cleanup_tempfile_(FILE **tempfile, char **tempfilename);
static FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats);
static void set_file_stats_(const char *filename, struct flac_stat_s *stats);
static int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence);
static FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle);
static FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status);
#ifdef FLAC__VALGRIND_TESTING
static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret = fwrite(ptr, size, nmemb, stream);
if(!ferror(stream))
fflush(stream);
return ret;
}
#else
#define local__fwrite fwrite
#endif
/****************************************************************************
*
* Level 0 implementation
*
***************************************************************************/
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
static void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
typedef struct {
FLAC__bool got_error;
FLAC__StreamMetadata *object;
} level0_client_data;
static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC__MetadataType type)
{
level0_client_data cd;
FLAC__StreamDecoder *decoder;
FLAC__ASSERT(0 != filename);
cd.got_error = false;
cd.object = 0;
decoder = FLAC__stream_decoder_new();
if(0 == decoder)
return 0;
FLAC__stream_decoder_set_md5_checking(decoder, false);
FLAC__stream_decoder_set_metadata_ignore_all(decoder);
FLAC__stream_decoder_set_metadata_respond(decoder, type);
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) {
(void)FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
return 0;
}
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder) || cd.got_error) {
(void)FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
if(0 != cd.object)
FLAC__metadata_object_delete(cd.object);
return 0;
}
(void)FLAC__stream_decoder_finish(decoder);
FLAC__stream_decoder_delete(decoder);
return cd.object;
}
FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo)
{
FLAC__StreamMetadata *object;
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != streaminfo);
object = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_STREAMINFO);
if (object) {
/* can just copy the contents since STREAMINFO has no internal structure */
*streaminfo = *object;
FLAC__metadata_object_delete(object);
return true;
}
else {
return false;
}
}
FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != tags);
*tags = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_VORBIS_COMMENT);
return 0 != *tags;
}
FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != cuesheet);
*cuesheet = get_one_metadata_block_(filename, FLAC__METADATA_TYPE_CUESHEET);
return 0 != *cuesheet;
}
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
(void)decoder, (void)frame, (void)buffer, (void)client_data;
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
level0_client_data *cd = (level0_client_data *)client_data;
(void)decoder;
/*
* we assume we only get here when the one metadata block we were
* looking for was passed to us
*/
if(!cd->got_error && 0 == cd->object) {
if(0 == (cd->object = FLAC__metadata_object_clone(metadata)))
cd->got_error = true;
}
}
void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
level0_client_data *cd = (level0_client_data *)client_data;
(void)decoder;
if(status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC)
cd->got_error = true;
}
FLAC_API FLAC__bool FLAC__metadata_get_picture(const char *filename, FLAC__StreamMetadata **picture, FLAC__StreamMetadata_Picture_Type type, const char *mime_type, const FLAC__byte *description, unsigned max_width, unsigned max_height, unsigned max_depth, unsigned max_colors)
{
FLAC__Metadata_SimpleIterator *it;
FLAC__uint64 max_area_seen = 0;
FLAC__uint64 max_depth_seen = 0;
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != picture);
*picture = 0;
it = FLAC__metadata_simple_iterator_new();
if(0 == it)
return false;
if(!FLAC__metadata_simple_iterator_init(it, filename, /*read_only=*/true, /*preserve_file_stats=*/true)) {
FLAC__metadata_simple_iterator_delete(it);
return false;
}
do {
if(FLAC__metadata_simple_iterator_get_block_type(it) == FLAC__METADATA_TYPE_PICTURE) {
FLAC__StreamMetadata *obj = FLAC__metadata_simple_iterator_get_block(it);
FLAC__uint64 area = (FLAC__uint64)obj->data.picture.width * (FLAC__uint64)obj->data.picture.height;
/* check constraints */
if(
(type == (FLAC__StreamMetadata_Picture_Type)(-1) || type == obj->data.picture.type) &&
(mime_type == 0 || !strcmp(mime_type, obj->data.picture.mime_type)) &&
(description == 0 || !strcmp((const char *)description, (const char *)obj->data.picture.description)) &&
obj->data.picture.width <= max_width &&
obj->data.picture.height <= max_height &&
obj->data.picture.depth <= max_depth &&
obj->data.picture.colors <= max_colors &&
(area > max_area_seen || (area == max_area_seen && obj->data.picture.depth > max_depth_seen))
) {
if(*picture)
FLAC__metadata_object_delete(*picture);
*picture = obj;
max_area_seen = area;
max_depth_seen = obj->data.picture.depth;
}
else {
FLAC__metadata_object_delete(obj);
}
}
} while(FLAC__metadata_simple_iterator_next(it));
FLAC__metadata_simple_iterator_delete(it);
return (0 != *picture);
}
/****************************************************************************
*
* Level 1 implementation
*
***************************************************************************/
#define SIMPLE_ITERATOR_MAX_PUSH_DEPTH (1+4)
/* 1 for initial offset, +4 for our own personal use */
struct FLAC__Metadata_SimpleIterator {
FILE *file;
char *filename, *tempfile_path_prefix;
struct flac_stat_s stats;
FLAC__bool has_stats;
FLAC__bool is_writable;
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__off_t offset[SIMPLE_ITERATOR_MAX_PUSH_DEPTH];
FLAC__off_t first_offset; /* this is the offset to the STREAMINFO block */
unsigned depth;
/* this is the metadata block header of the current block we are pointing to: */
FLAC__bool is_last;
FLAC__MetadataType type;
unsigned length;
};
FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[] = {
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR",
"FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR"
};
FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void)
{
FLAC__Metadata_SimpleIterator *iterator = calloc(1, sizeof(FLAC__Metadata_SimpleIterator));
if(0 != iterator) {
iterator->file = 0;
iterator->filename = 0;
iterator->tempfile_path_prefix = 0;
iterator->has_stats = false;
iterator->is_writable = false;
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
iterator->first_offset = iterator->offset[0] = -1;
iterator->depth = 0;
}
return iterator;
}
static void simple_iterator_free_guts_(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
if(0 != iterator->file) {
fclose(iterator->file);
iterator->file = 0;
if(iterator->has_stats)
set_file_stats_(iterator->filename, &iterator->stats);
}
if(0 != iterator->filename) {
free(iterator->filename);
iterator->filename = 0;
}
if(0 != iterator->tempfile_path_prefix) {
free(iterator->tempfile_path_prefix);
iterator->tempfile_path_prefix = 0;
}
}
FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
simple_iterator_free_guts_(iterator);
free(iterator);
}
FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__ASSERT(0 != iterator);
status = iterator->status;
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
return status;
}
static FLAC__bool simple_iterator_prime_input_(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool read_only)
{
unsigned ret;
FLAC__ASSERT(0 != iterator);
if(read_only || 0 == (iterator->file = flac_fopen(iterator->filename, "r+b"))) {
iterator->is_writable = false;
if(read_only || errno == EACCES) {
if(0 == (iterator->file = flac_fopen(iterator->filename, "rb"))) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE;
return false;
}
}
else {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE;
return false;
}
}
else {
iterator->is_writable = true;
}
ret = seek_to_first_metadata_block_(iterator->file);
switch(ret) {
case 0:
iterator->depth = 0;
iterator->first_offset = iterator->offset[iterator->depth] = ftello(iterator->file);
return read_metadata_block_header_(iterator);
case 1:
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
case 2:
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
case 3:
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE;
return false;
default:
FLAC__ASSERT(0);
return false;
}
}
#if 0
@@@ If we decide to finish implementing this, put this comment back in metadata.h
/*
* The 'tempfile_path_prefix' allows you to specify a directory where
* tempfiles should go. Remember that if your metadata edits cause the
* FLAC file to grow, the entire file will have to be rewritten. If
* 'tempfile_path_prefix' is NULL, the temp file will be written in the
* same directory as the original FLAC file. This makes replacing the
* original with the tempfile fast but requires extra space in the same
* partition for the tempfile. If space is a problem, you can pass a
* directory name belonging to a different partition in
* 'tempfile_path_prefix'. Note that you should use the forward slash
* '/' as the directory separator. A trailing slash is not needed; it
* will be added automatically.
*/
FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool preserve_file_stats, const char *tempfile_path_prefix);
#endif
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_init(FLAC__Metadata_SimpleIterator *iterator, const char *filename, FLAC__bool read_only, FLAC__bool preserve_file_stats)
{
const char *tempfile_path_prefix = 0; /*@@@ search for comments near 'flac_rename(...)' for what it will take to finish implementing this */
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != filename);
simple_iterator_free_guts_(iterator);
if(!read_only && preserve_file_stats)
iterator->has_stats = get_file_stats_(filename, &iterator->stats);
if(0 == (iterator->filename = strdup(filename))) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
if(0 != tempfile_path_prefix && 0 == (iterator->tempfile_path_prefix = strdup(tempfile_path_prefix))) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
return simple_iterator_prime_input_(iterator, read_only);
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
return iterator->is_writable;
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
if(iterator->is_last)
return false;
if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
iterator->offset[iterator->depth] = ftello(iterator->file);
return read_metadata_block_header_(iterator);
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__off_t this_offset;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
if(iterator->offset[iterator->depth] == iterator->first_offset)
return false;
if(0 != fseeko(iterator->file, iterator->first_offset, SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
this_offset = iterator->first_offset;
if(!read_metadata_block_header_(iterator))
return false;
/* we ignore any error from ftello() and catch it in fseeko() */
while(ftello(iterator->file) + (FLAC__off_t)iterator->length < iterator->offset[iterator->depth]) {
if(0 != fseeko(iterator->file, iterator->length, SEEK_CUR)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
this_offset = ftello(iterator->file);
if(!read_metadata_block_header_(iterator))
return false;
}
iterator->offset[iterator->depth] = this_offset;
return true;
}
/*@@@@add to tests*/
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
return iterator->is_last;
}
/*@@@@add to tests*/
FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
return iterator->offset[iterator->depth];
}
FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
return iterator->type;
}
/*@@@@add to tests*/
FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
return iterator->length;
}
/*@@@@add to tests*/
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id)
{
const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
FLAC__ASSERT(0 != id);
if(iterator->type != FLAC__METADATA_TYPE_APPLICATION) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT;
return false;
}
if(fread(id, 1, id_bytes, iterator->file) != id_bytes) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
/* back up */
if(0 != fseeko(iterator->file, -((int)id_bytes), SEEK_CUR)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
return true;
}
FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__StreamMetadata *block = FLAC__metadata_object_new(iterator->type);
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
if(0 != block) {
block->is_last = iterator->is_last;
block->length = iterator->length;
if(!read_metadata_block_data_(iterator, block)) {
FLAC__metadata_object_delete(block);
return 0;
}
/* back up to the beginning of the block data to stay consistent */
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH, SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
FLAC__metadata_object_delete(block);
return 0;
}
}
else
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return block;
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding)
{
FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];)
FLAC__bool ret;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
FLAC__ASSERT(0 != block);
if(!iterator->is_writable) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE;
return false;
}
if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO || block->type == FLAC__METADATA_TYPE_STREAMINFO) {
if(iterator->type != block->type) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT;
return false;
}
}
block->is_last = iterator->is_last;
if(iterator->length == block->length)
return write_metadata_block_stationary_(iterator, block);
else if(iterator->length > block->length) {
if(use_padding && iterator->length >= FLAC__STREAM_METADATA_HEADER_LENGTH + block->length) {
ret = write_metadata_block_stationary_with_padding_(iterator, block, iterator->length - FLAC__STREAM_METADATA_HEADER_LENGTH - block->length, block->is_last);
FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
else {
ret = rewrite_whole_file_(iterator, block, /*append=*/false);
FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
}
else /* iterator->length < block->length */ {
unsigned padding_leftover = 0;
FLAC__bool padding_is_last = false;
if(use_padding) {
/* first see if we can even use padding */
if(iterator->is_last) {
use_padding = false;
}
else {
const unsigned extra_padding_bytes_required = block->length - iterator->length;
simple_iterator_push_(iterator);
if(!FLAC__metadata_simple_iterator_next(iterator)) {
(void)simple_iterator_pop_(iterator);
return false;
}
if(iterator->type != FLAC__METADATA_TYPE_PADDING) {
use_padding = false;
}
else {
if(FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length == extra_padding_bytes_required) {
padding_leftover = 0;
block->is_last = iterator->is_last;
}
else if(iterator->length < extra_padding_bytes_required)
use_padding = false;
else {
padding_leftover = FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length - extra_padding_bytes_required;
padding_is_last = iterator->is_last;
block->is_last = false;
}
}
if(!simple_iterator_pop_(iterator))
return false;
}
}
if(use_padding) {
if(padding_leftover == 0) {
ret = write_metadata_block_stationary_(iterator, block);
FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
else {
FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH);
ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last);
FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
}
else {
ret = rewrite_whole_file_(iterator, block, /*append=*/false);
FLAC__ASSERT(!ret || iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(!ret || ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
}
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding)
{
unsigned padding_leftover = 0;
FLAC__bool padding_is_last = false;
FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth] + FLAC__STREAM_METADATA_HEADER_LENGTH + iterator->length;)
FLAC__bool ret;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
FLAC__ASSERT(0 != block);
if(!iterator->is_writable) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE;
return false;
}
if(block->type == FLAC__METADATA_TYPE_STREAMINFO) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT;
return false;
}
block->is_last = iterator->is_last;
if(use_padding) {
/* first see if we can even use padding */
if(iterator->is_last) {
use_padding = false;
}
else {
simple_iterator_push_(iterator);
if(!FLAC__metadata_simple_iterator_next(iterator)) {
(void)simple_iterator_pop_(iterator);
return false;
}
if(iterator->type != FLAC__METADATA_TYPE_PADDING) {
use_padding = false;
}
else {
if(iterator->length == block->length) {
padding_leftover = 0;
block->is_last = iterator->is_last;
}
else if(iterator->length < FLAC__STREAM_METADATA_HEADER_LENGTH + block->length)
use_padding = false;
else {
padding_leftover = iterator->length - block->length;
padding_is_last = iterator->is_last;
block->is_last = false;
}
}
if(!simple_iterator_pop_(iterator))
return false;
}
}
if(use_padding) {
/* move to the next block, which is suitable padding */
if(!FLAC__metadata_simple_iterator_next(iterator))
return false;
if(padding_leftover == 0) {
ret = write_metadata_block_stationary_(iterator, block);
FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
else {
FLAC__ASSERT(padding_leftover >= FLAC__STREAM_METADATA_HEADER_LENGTH);
ret = write_metadata_block_stationary_with_padding_(iterator, block, padding_leftover - FLAC__STREAM_METADATA_HEADER_LENGTH, padding_is_last);
FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
}
else {
ret = rewrite_whole_file_(iterator, block, /*append=*/true);
FLAC__ASSERT(iterator->offset[iterator->depth] == debug_target_offset);
FLAC__ASSERT(ftello(iterator->file) == debug_target_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
return ret;
}
}
FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding)
{
FLAC__ASSERT_DECLARATION(FLAC__off_t debug_target_offset = iterator->offset[iterator->depth];)
FLAC__bool ret;
if(!iterator->is_writable) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE;
return false;
}
if(iterator->type == FLAC__METADATA_TYPE_STREAMINFO) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT;
return false;
}
if(use_padding) {
FLAC__StreamMetadata *padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING);
if(0 == padding) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
padding->length = iterator->length;
if(!FLAC__metadata_simple_iterator_set_block(iterator, padding, false)) {
FLAC__metadata_object_delete(padding);
return false;
}
FLAC__metadata_object_delete(padding);
if(!FLAC__metadata_simple_iterator_prev(iterator))
return false;
FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset);
FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset);
return true;
}
else {
ret = rewrite_whole_file_(iterator, 0, /*append=*/false);
FLAC__ASSERT(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length == debug_target_offset);
FLAC__ASSERT(ftello(iterator->file) + (FLAC__off_t)iterator->length == debug_target_offset);
return ret;
}
}
/****************************************************************************
*
* Level 2 implementation
*
***************************************************************************/
typedef struct FLAC__Metadata_Node {
FLAC__StreamMetadata *data;
struct FLAC__Metadata_Node *prev, *next;
} FLAC__Metadata_Node;
struct FLAC__Metadata_Chain {
char *filename; /* will be NULL if using callbacks */
FLAC__bool is_ogg;
FLAC__Metadata_Node *head;
FLAC__Metadata_Node *tail;
unsigned nodes;
FLAC__Metadata_ChainStatus status;
FLAC__off_t first_offset, last_offset;
/*
* This is the length of the chain initially read from the FLAC file.
* it is used to compare against the current length to decide whether
* or not the whole file has to be rewritten.
*/
FLAC__off_t initial_length;
/* @@@ hacky, these are currently only needed by ogg reader */
FLAC__IOHandle handle;
FLAC__IOCallback_Read read_cb;
};
struct FLAC__Metadata_Iterator {
FLAC__Metadata_Chain *chain;
FLAC__Metadata_Node *current;
};
FLAC_API const char * const FLAC__Metadata_ChainStatusString[] = {
"FLAC__METADATA_CHAIN_STATUS_OK",
"FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT",
"FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE",
"FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE",
"FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE",
"FLAC__METADATA_CHAIN_STATUS_BAD_METADATA",
"FLAC__METADATA_CHAIN_STATUS_READ_ERROR",
"FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR",
"FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR",
"FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR",
"FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR",
"FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR",
"FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR",
"FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS",
"FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH",
"FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL"
};
static FLAC__Metadata_Node *node_new_(void)
{
return calloc(1, sizeof(FLAC__Metadata_Node));
}
static void node_delete_(FLAC__Metadata_Node *node)
{
FLAC__ASSERT(0 != node);
if(0 != node->data)
FLAC__metadata_object_delete(node->data);
free(node);
}
static void chain_init_(FLAC__Metadata_Chain *chain)
{
FLAC__ASSERT(0 != chain);
chain->filename = 0;
chain->is_ogg = false;
chain->head = chain->tail = 0;
chain->nodes = 0;
chain->status = FLAC__METADATA_CHAIN_STATUS_OK;
chain->initial_length = 0;
chain->read_cb = 0;
}
static void chain_clear_(FLAC__Metadata_Chain *chain)
{
FLAC__Metadata_Node *node, *next;
FLAC__ASSERT(0 != chain);
for(node = chain->head; node; ) {
next = node->next;
node_delete_(node);
node = next;
}
if(0 != chain->filename)
free(chain->filename);
chain_init_(chain);
}
static void chain_append_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node)
{
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != node);
FLAC__ASSERT(0 != node->data);
node->next = node->prev = 0;
node->data->is_last = true;
if(0 != chain->tail)
chain->tail->data->is_last = false;
if(0 == chain->head)
chain->head = node;
else {
FLAC__ASSERT(0 != chain->tail);
chain->tail->next = node;
node->prev = chain->tail;
}
chain->tail = node;
chain->nodes++;
}
static void chain_remove_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node)
{
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != node);
if(node == chain->head)
chain->head = node->next;
else
node->prev->next = node->next;
if(node == chain->tail)
chain->tail = node->prev;
else
node->next->prev = node->prev;
if(0 != chain->tail)
chain->tail->data->is_last = true;
chain->nodes--;
}
static void chain_delete_node_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node)
{
chain_remove_node_(chain, node);
node_delete_(node);
}
static FLAC__off_t chain_calculate_length_(FLAC__Metadata_Chain *chain)
{
const FLAC__Metadata_Node *node;
FLAC__off_t length = 0;
for(node = chain->head; node; node = node->next)
length += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length);
return length;
}
static void iterator_insert_node_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node)
{
FLAC__ASSERT(0 != node);
FLAC__ASSERT(0 != node->data);
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
FLAC__ASSERT(0 != iterator->chain);
FLAC__ASSERT(0 != iterator->chain->head);
FLAC__ASSERT(0 != iterator->chain->tail);
node->data->is_last = false;
node->prev = iterator->current->prev;
node->next = iterator->current;
if(0 == node->prev)
iterator->chain->head = node;
else
node->prev->next = node;
iterator->current->prev = node;
iterator->chain->nodes++;
}
static void iterator_insert_node_after_(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Node *node)
{
FLAC__ASSERT(0 != node);
FLAC__ASSERT(0 != node->data);
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
FLAC__ASSERT(0 != iterator->chain);
FLAC__ASSERT(0 != iterator->chain->head);
FLAC__ASSERT(0 != iterator->chain->tail);
iterator->current->data->is_last = false;
node->prev = iterator->current;
node->next = iterator->current->next;
if(0 == node->next)
iterator->chain->tail = node;
else
node->next->prev = node;
node->prev->next = node;
iterator->chain->tail->data->is_last = true;
iterator->chain->nodes++;
}
/* return true iff node and node->next are both padding */
static FLAC__bool chain_merge_adjacent_padding_(FLAC__Metadata_Chain *chain, FLAC__Metadata_Node *node)
{
if(node->data->type == FLAC__METADATA_TYPE_PADDING && 0 != node->next && node->next->data->type == FLAC__METADATA_TYPE_PADDING) {
const unsigned growth = FLAC__STREAM_METADATA_HEADER_LENGTH + node->next->data->length;
node->data->length += growth; /* new block size can be greater than max metadata block size, but it'll be fixed later in chain_prepare_for_write_() */
chain_delete_node_(chain, node->next);
return true;
}
else
return false;
}
/* Returns the new length of the chain, or 0 if there was an error. */
/* WATCHOUT: This can get called multiple times before a write, so
* it should still work when this happens.
*/
/* WATCHOUT: Make sure to also update the logic in
* FLAC__metadata_chain_check_if_tempfile_needed() if the logic here changes.
*/
static FLAC__off_t chain_prepare_for_write_(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
{
FLAC__off_t current_length = chain_calculate_length_(chain);
if(use_padding) {
/* if the metadata shrank and the last block is padding, we just extend the last padding block */
if(current_length < chain->initial_length && chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
const FLAC__off_t delta = chain->initial_length - current_length;
chain->tail->data->length += delta;
current_length += delta;
FLAC__ASSERT(current_length == chain->initial_length);
}
/* if the metadata shrank more than 4 bytes then there's room to add another padding block */
else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) {
FLAC__StreamMetadata *padding;
FLAC__Metadata_Node *node;
if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return 0;
}
padding->length = chain->initial_length - (FLAC__STREAM_METADATA_HEADER_LENGTH + current_length);
if(0 == (node = node_new_())) {
FLAC__metadata_object_delete(padding);
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return 0;
}
node->data = padding;
chain_append_node_(chain, node);
current_length = chain_calculate_length_(chain);
FLAC__ASSERT(current_length == chain->initial_length);
}
/* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */
else if(current_length > chain->initial_length) {
const FLAC__off_t delta = current_length - chain->initial_length;
if(chain->tail->data->type == FLAC__METADATA_TYPE_PADDING) {
/* if the delta is exactly the size of the last padding block, remove the padding block */
if((FLAC__off_t)chain->tail->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) {
chain_delete_node_(chain, chain->tail);
current_length = chain_calculate_length_(chain);
FLAC__ASSERT(current_length == chain->initial_length);
}
/* if there is at least 'delta' bytes of padding, trim the padding down */
else if((FLAC__off_t)chain->tail->data->length >= delta) {
chain->tail->data->length -= delta;
current_length -= delta;
FLAC__ASSERT(current_length == chain->initial_length);
}
}
}
}
/* check sizes of all metadata blocks; reduce padding size if necessary */
{
FLAC__Metadata_Node *node;
for (node = chain->head; node; node = node->next) {
if(node->data->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) {
if(node->data->type == FLAC__METADATA_TYPE_PADDING) {
node->data->length = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
current_length = chain_calculate_length_(chain);
} else {
chain->status = FLAC__METADATA_CHAIN_STATUS_BAD_METADATA;
return 0;
}
}
}
}
return current_length;
}
static FLAC__bool chain_read_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Tell tell_cb)
{
FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != chain);
/* we assume we're already at the beginning of the file */
switch(seek_to_first_metadata_block_cb_(handle, read_cb, seek_cb)) {
case 0:
break;
case 1:
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
return false;
case 2:
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
case 3:
chain->status = FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE;
return false;
default:
FLAC__ASSERT(0);
return false;
}
{
FLAC__int64 pos = tell_cb(handle);
if(pos < 0) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
return false;
}
chain->first_offset = (FLAC__off_t)pos;
}
{
FLAC__bool is_last;
FLAC__MetadataType type;
unsigned length;
do {
node = node_new_();
if(0 == node) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
if(!read_metadata_block_header_cb_(handle, read_cb, &is_last, &type, &length)) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
return false;
}
node->data = FLAC__metadata_object_new(type);
if(0 == node->data) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
node->data->is_last = is_last;
node->data->length = length;
chain->status = get_equivalent_status_(read_metadata_block_data_cb_(handle, read_cb, seek_cb, node->data));
if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) {
node_delete_(node);
return false;
}
chain_append_node_(chain, node);
} while(!is_last);
}
{
FLAC__int64 pos = tell_cb(handle);
if(pos < 0) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
return false;
}
chain->last_offset = (FLAC__off_t)pos;
}
chain->initial_length = chain_calculate_length_(chain);
return true;
}
static FLAC__StreamDecoderReadStatus chain_read_ogg_read_cb_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder;
if(*bytes > 0 && chain->status == FLAC__METADATA_CHAIN_STATUS_OK) {
*bytes = chain->read_cb(buffer, sizeof(FLAC__byte), *bytes, chain->handle);
if(*bytes == 0)
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
else
return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
else
return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
}
static FLAC__StreamDecoderWriteStatus chain_read_ogg_write_cb_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
{
(void)decoder, (void)frame, (void)buffer, (void)client_data;
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
static void chain_read_ogg_metadata_cb_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
FLAC__Metadata_Node *node;
(void)decoder;
node = node_new_();
if(0 == node) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
node->data = FLAC__metadata_object_clone(metadata);
if(0 == node->data) {
node_delete_(node);
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return;
}
chain_append_node_(chain, node);
}
static void chain_read_ogg_error_cb_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
{
FLAC__Metadata_Chain *chain = (FLAC__Metadata_Chain*)client_data;
(void)decoder, (void)status;
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
}
static FLAC__bool chain_read_ogg_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb)
{
FLAC__StreamDecoder *decoder;
FLAC__ASSERT(0 != chain);
/* we assume we're already at the beginning of the file */
chain->handle = handle;
chain->read_cb = read_cb;
if(0 == (decoder = FLAC__stream_decoder_new())) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
FLAC__stream_decoder_set_metadata_respond_all(decoder);
if(FLAC__stream_decoder_init_ogg_stream(decoder, chain_read_ogg_read_cb_, /*seek_callback=*/0, /*tell_callback=*/0, /*length_callback=*/0, /*eof_callback=*/0, chain_read_ogg_write_cb_, chain_read_ogg_metadata_cb_, chain_read_ogg_error_cb_, chain) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
return false;
}
chain->first_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR; /*@@@ maybe needs better error code */
if(chain->status != FLAC__METADATA_CHAIN_STATUS_OK) {
FLAC__stream_decoder_delete(decoder);
return false;
}
FLAC__stream_decoder_delete(decoder);
chain->last_offset = 0; /*@@@ wrong; will need to be set correctly to implement metadata writing for Ogg FLAC */
chain->initial_length = chain_calculate_length_(chain);
return true;
}
static FLAC__bool chain_rewrite_metadata_in_place_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, FLAC__IOCallback_Seek seek_cb)
{
FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != chain->head);
if(0 != seek_cb(handle, chain->first_offset, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
for(node = chain->head; node; node = node->next) {
if(!write_metadata_block_header_cb_(handle, write_cb, node->data)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR;
return false;
}
if(!write_metadata_block_data_cb_(handle, write_cb, node->data)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR;
return false;
}
}
/*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/
chain->status = FLAC__METADATA_CHAIN_STATUS_OK;
return true;
}
static FLAC__bool chain_rewrite_metadata_in_place_(FLAC__Metadata_Chain *chain)
{
FILE *file;
FLAC__bool ret;
FLAC__ASSERT(0 != chain->filename);
if(0 == (file = flac_fopen(chain->filename, "r+b"))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
return false;
}
/* chain_rewrite_metadata_in_place_cb_() sets chain->status for us */
ret = chain_rewrite_metadata_in_place_cb_(chain, (FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, fseek_wrapper_);
fclose(file);
return ret;
}
static FLAC__bool chain_rewrite_file_(FLAC__Metadata_Chain *chain, const char *tempfile_path_prefix)
{
FILE *f, *tempfile = NULL;
char *tempfilename;
FLAC__Metadata_SimpleIteratorStatus status;
const FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != chain->filename);
FLAC__ASSERT(0 != chain->head);
/* copy the file prefix (data up to first metadata block */
if(0 == (f = flac_fopen(chain->filename, "rb"))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
return false;
}
if(!open_tempfile_(chain->filename, tempfile_path_prefix, &tempfile, &tempfilename, &status)) {
chain->status = get_equivalent_status_(status);
goto err;
}
if(!copy_n_bytes_from_file_(f, tempfile, chain->first_offset, &status)) {
chain->status = get_equivalent_status_(status);
goto err;
}
/* write the metadata */
for(node = chain->head; node; node = node->next) {
if(!write_metadata_block_header_(tempfile, &status, node->data)) {
chain->status = get_equivalent_status_(status);
goto err;
}
if(!write_metadata_block_data_(tempfile, &status, node->data)) {
chain->status = get_equivalent_status_(status);
goto err;
}
}
/*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/
/* copy the file postfix (everything after the metadata) */
if(0 != fseeko(f, chain->last_offset, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
goto err;
}
if(!copy_remaining_bytes_from_file_(f, tempfile, &status)) {
chain->status = get_equivalent_status_(status);
goto err;
}
/* move the tempfile on top of the original */
(void)fclose(f);
if(!transport_tempfile_(chain->filename, &tempfile, &tempfilename, &status))
return false;
return true;
err:
(void)fclose(f);
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
}
/* assumes 'handle' is already at beginning of file */
static FLAC__bool chain_rewrite_file_cb_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb)
{
FLAC__Metadata_SimpleIteratorStatus status;
const FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 == chain->filename);
FLAC__ASSERT(0 != chain->head);
/* copy the file prefix (data up to first metadata block */
if(!copy_n_bytes_from_file_cb_(handle, read_cb, temp_handle, temp_write_cb, chain->first_offset, &status)) {
chain->status = get_equivalent_status_(status);
return false;
}
/* write the metadata */
for(node = chain->head; node; node = node->next) {
if(!write_metadata_block_header_cb_(temp_handle, temp_write_cb, node->data)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR;
return false;
}
if(!write_metadata_block_data_cb_(temp_handle, temp_write_cb, node->data)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR;
return false;
}
}
/*FLAC__ASSERT(fflush(), ftello() == chain->last_offset);*/
/* copy the file postfix (everything after the metadata) */
if(0 != seek_cb(handle, chain->last_offset, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
if(!copy_remaining_bytes_from_file_cb_(handle, read_cb, eof_cb, temp_handle, temp_write_cb, &status)) {
chain->status = get_equivalent_status_(status);
return false;
}
return true;
}
FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void)
{
FLAC__Metadata_Chain *chain = calloc(1, sizeof(FLAC__Metadata_Chain));
if(0 != chain)
chain_init_(chain);
return chain;
}
FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain)
{
FLAC__ASSERT(0 != chain);
chain_clear_(chain);
free(chain);
}
FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain)
{
FLAC__Metadata_ChainStatus status;
FLAC__ASSERT(0 != chain);
status = chain->status;
chain->status = FLAC__METADATA_CHAIN_STATUS_OK;
return status;
}
static FLAC__bool chain_read_(FLAC__Metadata_Chain *chain, const char *filename, FLAC__bool is_ogg)
{
FILE *file;
FLAC__bool ret;
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != filename);
chain_clear_(chain);
if(0 == (chain->filename = strdup(filename))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
chain->is_ogg = is_ogg;
if(0 == (file = flac_fopen(filename, "rb"))) {
chain->status = FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
return false;
}
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, file, (FLAC__IOCallback_Read)fread) :
chain_read_cb_(chain, file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, ftell_wrapper_)
;
fclose(file);
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/false);
}
/*@@@@add to tests*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename)
{
return chain_read_(chain, filename, /*is_ogg=*/true);
}
static FLAC__bool chain_read_with_callbacks_(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__bool is_ogg)
{
FLAC__bool ret;
FLAC__ASSERT(0 != chain);
chain_clear_(chain);
if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.tell) {
chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS;
return false;
}
chain->is_ogg = is_ogg;
/* rewind */
if(0 != callbacks.seek(handle, 0, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
/* the function also sets chain->status for us */
ret = is_ogg?
chain_read_ogg_cb_(chain, handle, callbacks.read) :
chain_read_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.tell)
;
return ret;
}
FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/false);
}
/*@@@@add to tests*/
FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
return chain_read_with_callbacks_(chain, handle, callbacks, /*is_ogg=*/true);
}
typedef enum {
LBS_NONE = 0,
LBS_SIZE_CHANGED,
LBS_BLOCK_ADDED,
LBS_BLOCK_REMOVED
} LastBlockState;
FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding)
{
/* This does all the same checks that are in chain_prepare_for_write_()
* but doesn't actually alter the chain. Make sure to update the logic
* here if chain_prepare_for_write_() changes.
*/
FLAC__off_t current_length;
LastBlockState lbs_state = LBS_NONE;
unsigned lbs_size = 0;
FLAC__ASSERT(0 != chain);
current_length = chain_calculate_length_(chain);
if(use_padding) {
const FLAC__Metadata_Node * const node = chain->tail;
/* if the metadata shrank and the last block is padding, we just extend the last padding block */
if(current_length < chain->initial_length && node->data->type == FLAC__METADATA_TYPE_PADDING) {
lbs_state = LBS_SIZE_CHANGED;
lbs_size = node->data->length + (chain->initial_length - current_length);
}
/* if the metadata shrank more than 4 bytes then there's room to add another padding block */
else if(current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH <= chain->initial_length) {
lbs_state = LBS_BLOCK_ADDED;
lbs_size = chain->initial_length - (current_length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH);
}
/* if the metadata grew but the last block is padding, try cutting the padding to restore the original length so we don't have to rewrite the whole file */
else if(current_length > chain->initial_length) {
const FLAC__off_t delta = current_length - chain->initial_length;
if(node->data->type == FLAC__METADATA_TYPE_PADDING) {
/* if the delta is exactly the size of the last padding block, remove the padding block */
if((FLAC__off_t)node->data->length + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH == delta) {
lbs_state = LBS_BLOCK_REMOVED;
lbs_size = 0;
}
/* if there is at least 'delta' bytes of padding, trim the padding down */
else if((FLAC__off_t)node->data->length >= delta) {
lbs_state = LBS_SIZE_CHANGED;
lbs_size = node->data->length - delta;
}
}
}
}
current_length = 0;
/* check sizes of all metadata blocks; reduce padding size if necessary */
{
const FLAC__Metadata_Node *node;
for(node = chain->head; node; node = node->next) {
unsigned block_len = node->data->length;
if(node == chain->tail) {
if(lbs_state == LBS_BLOCK_REMOVED)
continue;
else if(lbs_state == LBS_SIZE_CHANGED)
block_len = lbs_size;
}
if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN)) {
if(node->data->type == FLAC__METADATA_TYPE_PADDING)
block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
else
return false /* the return value doesn't matter */;
}
current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len);
}
if(lbs_state == LBS_BLOCK_ADDED) {
/* test added padding block */
unsigned block_len = lbs_size;
if(block_len >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
block_len = (1u << FLAC__STREAM_METADATA_LENGTH_LEN) - 1;
current_length += (FLAC__STREAM_METADATA_HEADER_LENGTH + block_len);
}
}
return (current_length != chain->initial_length);
}
FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats)
{
struct flac_stat_s stats;
const char *tempfile_path_prefix = 0;
FLAC__off_t current_length;
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 == chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
}
current_length = chain_prepare_for_write_(chain, use_padding);
/* a return value of 0 means there was an error; chain->status is already set */
if (0 == current_length)
return false;
if(preserve_file_stats)
get_file_stats_(chain->filename, &stats);
if(current_length == chain->initial_length) {
if(!chain_rewrite_metadata_in_place_(chain))
return false;
}
else {
if(!chain_rewrite_file_(chain, tempfile_path_prefix))
return false;
/* recompute lengths and offsets */
{
const FLAC__Metadata_Node *node;
chain->initial_length = current_length;
chain->last_offset = chain->first_offset;
for(node = chain->head; node; node = node->next)
chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length);
}
}
if(preserve_file_stats)
set_file_stats_(chain->filename, &stats);
return true;
}
FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks)
{
FLAC__off_t current_length;
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
}
if (0 == callbacks.write || 0 == callbacks.seek) {
chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS;
return false;
}
if (FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL;
return false;
}
current_length = chain_prepare_for_write_(chain, use_padding);
/* a return value of 0 means there was an error; chain->status is already set */
if (0 == current_length)
return false;
FLAC__ASSERT(current_length == chain->initial_length);
return chain_rewrite_metadata_in_place_cb_(chain, handle, callbacks.write, callbacks.seek);
}
FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks_and_tempfile(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks, FLAC__IOHandle temp_handle, FLAC__IOCallbacks temp_callbacks)
{
FLAC__off_t current_length;
FLAC__ASSERT(0 != chain);
if (chain->is_ogg) { /* cannot write back to Ogg FLAC yet */
chain->status = FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
return false;
}
if (0 != chain->filename) {
chain->status = FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH;
return false;
}
if (0 == callbacks.read || 0 == callbacks.seek || 0 == callbacks.eof) {
chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS;
return false;
}
if (0 == temp_callbacks.write) {
chain->status = FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS;
return false;
}
if (!FLAC__metadata_chain_check_if_tempfile_needed(chain, use_padding)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL;
return false;
}
current_length = chain_prepare_for_write_(chain, use_padding);
/* a return value of 0 means there was an error; chain->status is already set */
if (0 == current_length)
return false;
FLAC__ASSERT(current_length != chain->initial_length);
/* rewind */
if(0 != callbacks.seek(handle, 0, SEEK_SET)) {
chain->status = FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
return false;
}
if(!chain_rewrite_file_cb_(chain, handle, callbacks.read, callbacks.seek, callbacks.eof, temp_handle, temp_callbacks.write))
return false;
/* recompute lengths and offsets */
{
const FLAC__Metadata_Node *node;
chain->initial_length = current_length;
chain->last_offset = chain->first_offset;
for(node = chain->head; node; node = node->next)
chain->last_offset += (FLAC__STREAM_METADATA_HEADER_LENGTH + node->data->length);
}
return true;
}
FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain)
{
FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != chain);
for(node = chain->head; node; ) {
if(!chain_merge_adjacent_padding_(chain, node))
node = node->next;
}
}
FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain)
{
FLAC__Metadata_Node *node, *save;
unsigned i;
FLAC__ASSERT(0 != chain);
/*
* Don't try and be too smart... this simple algo is good enough for
* the small number of nodes that we deal with.
*/
for(i = 0, node = chain->head; i < chain->nodes; i++) {
if(node->data->type == FLAC__METADATA_TYPE_PADDING) {
save = node->next;
chain_remove_node_(chain, node);
chain_append_node_(chain, node);
node = save;
}
else {
node = node->next;
}
}
FLAC__metadata_chain_merge_padding(chain);
}
FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void)
{
FLAC__Metadata_Iterator *iterator = calloc(1, sizeof(FLAC__Metadata_Iterator));
/* calloc() implies:
iterator->current = 0;
iterator->chain = 0;
*/
return iterator;
}
FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator)
{
FLAC__ASSERT(0 != iterator);
free(iterator);
}
FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != chain);
FLAC__ASSERT(0 != chain->head);
iterator->chain = chain;
iterator->current = chain->head;
}
FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator)
{
FLAC__ASSERT(0 != iterator);
if(0 == iterator->current || 0 == iterator->current->next)
return false;
iterator->current = iterator->current->next;
return true;
}
FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator)
{
FLAC__ASSERT(0 != iterator);
if(0 == iterator->current || 0 == iterator->current->prev)
return false;
iterator->current = iterator->current->prev;
return true;
}
FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
FLAC__ASSERT(0 != iterator->current->data);
return iterator->current->data->type;
}
FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
return iterator->current->data;
}
FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != block);
return FLAC__metadata_iterator_delete_block(iterator, false) && FLAC__metadata_iterator_insert_block_after(iterator, block);
}
FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding)
{
FLAC__Metadata_Node *save;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
if(0 == iterator->current->prev) {
FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO);
return false;
}
save = iterator->current->prev;
if(replace_with_padding) {
FLAC__metadata_object_delete_data(iterator->current->data);
iterator->current->data->type = FLAC__METADATA_TYPE_PADDING;
}
else {
chain_delete_node_(iterator->chain, iterator->current);
}
iterator->current = save;
return true;
}
FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block)
{
FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
FLAC__ASSERT(0 != block);
if(block->type == FLAC__METADATA_TYPE_STREAMINFO)
return false;
if(0 == iterator->current->prev) {
FLAC__ASSERT(iterator->current->data->type == FLAC__METADATA_TYPE_STREAMINFO);
return false;
}
if(0 == (node = node_new_()))
return false;
node->data = block;
iterator_insert_node_(iterator, node);
iterator->current = node;
return true;
}
FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block)
{
FLAC__Metadata_Node *node;
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->current);
FLAC__ASSERT(0 != block);
if(block->type == FLAC__METADATA_TYPE_STREAMINFO)
return false;
if(0 == (node = node_new_()))
return false;
node->data = block;
iterator_insert_node_after_(iterator, node);
iterator->current = node;
return true;
}
/****************************************************************************
*
* Local function definitions
*
***************************************************************************/
void pack_uint32_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes)
{
unsigned i;
b += bytes;
for(i = 0; i < bytes; i++) {
*(--b) = (FLAC__byte)(val & 0xff);
val >>= 8;
}
}
void pack_uint32_little_endian_(FLAC__uint32 val, FLAC__byte *b, unsigned bytes)
{
unsigned i;
for(i = 0; i < bytes; i++) {
*(b++) = (FLAC__byte)(val & 0xff);
val >>= 8;
}
}
void pack_uint64_(FLAC__uint64 val, FLAC__byte *b, unsigned bytes)
{
unsigned i;
b += bytes;
for(i = 0; i < bytes; i++) {
*(--b) = (FLAC__byte)(val & 0xff);
val >>= 8;
}
}
FLAC__uint32 unpack_uint32_(FLAC__byte *b, unsigned bytes)
{
FLAC__uint32 ret = 0;
unsigned i;
for(i = 0; i < bytes; i++)
ret = (ret << 8) | (FLAC__uint32)(*b++);
return ret;
}
FLAC__uint32 unpack_uint32_little_endian_(FLAC__byte *b, unsigned bytes)
{
FLAC__uint32 ret = 0;
unsigned i;
b += bytes;
for(i = 0; i < bytes; i++)
ret = (ret << 8) | (FLAC__uint32)(*--b);
return ret;
}
FLAC__uint64 unpack_uint64_(FLAC__byte *b, unsigned bytes)
{
FLAC__uint64 ret = 0;
unsigned i;
for(i = 0; i < bytes; i++)
ret = (ret << 8) | (FLAC__uint64)(*b++);
return ret;
}
FLAC__bool read_metadata_block_header_(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
if(!read_metadata_block_header_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, &iterator->is_last, &iterator->type, &iterator->length)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
return true;
}
FLAC__bool read_metadata_block_data_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block)
{
FLAC__ASSERT(0 != iterator);
FLAC__ASSERT(0 != iterator->file);
iterator->status = read_metadata_block_data_cb_((FLAC__IOHandle)iterator->file, (FLAC__IOCallback_Read)fread, fseek_wrapper_, block);
return (iterator->status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK);
}
FLAC__bool read_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__bool *is_last, FLAC__MetadataType *type, unsigned *length)
{
FLAC__byte raw_header[FLAC__STREAM_METADATA_HEADER_LENGTH];
if(read_cb(raw_header, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH)
return false;
*is_last = raw_header[0] & 0x80? true : false;
*type = (FLAC__MetadataType)(raw_header[0] & 0x7f);
*length = unpack_uint32_(raw_header + 1, 3);
/* Note that we don't check:
* if(iterator->type >= FLAC__METADATA_TYPE_UNDEFINED)
* we just will read in an opaque block
*/
return true;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata *block)
{
switch(block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
return read_metadata_block_data_streaminfo_cb_(handle, read_cb, &block->data.stream_info);
case FLAC__METADATA_TYPE_PADDING:
return read_metadata_block_data_padding_cb_(handle, seek_cb, &block->data.padding, block->length);
case FLAC__METADATA_TYPE_APPLICATION:
return read_metadata_block_data_application_cb_(handle, read_cb, &block->data.application, block->length);
case FLAC__METADATA_TYPE_SEEKTABLE:
return read_metadata_block_data_seektable_cb_(handle, read_cb, &block->data.seek_table, block->length);
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
return read_metadata_block_data_vorbis_comment_cb_(handle, read_cb, seek_cb, &block->data.vorbis_comment, block->length);
case FLAC__METADATA_TYPE_CUESHEET:
return read_metadata_block_data_cuesheet_cb_(handle, read_cb, &block->data.cue_sheet);
case FLAC__METADATA_TYPE_PICTURE:
return read_metadata_block_data_picture_cb_(handle, read_cb, &block->data.picture);
default:
return read_metadata_block_data_unknown_cb_(handle, read_cb, &block->data.unknown, block->length);
}
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_StreamInfo *block)
{
FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH], *b;
if(read_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
b = buffer;
/* we are using hardcoded numbers for simplicity but we should
* probably eventually write a bit-level unpacker and use the
* _STREAMINFO_ constants.
*/
block->min_blocksize = unpack_uint32_(b, 2); b += 2;
block->max_blocksize = unpack_uint32_(b, 2); b += 2;
block->min_framesize = unpack_uint32_(b, 3); b += 3;
block->max_framesize = unpack_uint32_(b, 3); b += 3;
block->sample_rate = (unpack_uint32_(b, 2) << 4) | ((unsigned)(b[2] & 0xf0) >> 4);
block->channels = (unsigned)((b[2] & 0x0e) >> 1) + 1;
block->bits_per_sample = ((((unsigned)(b[2] & 0x01)) << 4) | (((unsigned)(b[3] & 0xf0)) >> 4)) + 1;
block->total_samples = (((FLAC__uint64)(b[3] & 0x0f)) << 32) | unpack_uint64_(b+4, 4);
memcpy(block->md5sum, b+8, 16);
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_Padding *block, unsigned block_length)
{
(void)block; /* nothing to do; we don't care about reading the padding bytes */
if(0 != seek_cb(handle, block_length, SEEK_CUR))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Application *block, unsigned block_length)
{
const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
if(read_cb(block->id, 1, id_bytes, handle) != id_bytes)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
if(block_length < id_bytes)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block_length -= id_bytes;
if(block_length == 0) {
block->data = 0;
}
else {
if(0 == (block->data = malloc(block_length)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
if(read_cb(block->data, 1, block_length, handle) != block_length)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_SeekTable *block, unsigned block_length)
{
unsigned i;
FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH];
FLAC__ASSERT(block_length % FLAC__STREAM_METADATA_SEEKPOINT_LENGTH == 0);
block->num_points = block_length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
if(block->num_points == 0)
block->points = 0;
else if(0 == (block->points = safe_malloc_mul_2op_p(block->num_points, /*times*/sizeof(FLAC__StreamMetadata_SeekPoint))))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
for(i = 0; i < block->num_points; i++) {
if(read_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
/* some MAGIC NUMBERs here */
block->points[i].sample_number = unpack_uint64_(buffer, 8);
block->points[i].stream_offset = unpack_uint64_(buffer+8, 8);
block->points[i].frame_samples = unpack_uint32_(buffer+16, 2);
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_entry_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_VorbisComment_Entry *entry, unsigned max_length)
{
const unsigned entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8 == sizeof(buffer));
if(max_length < entry_length_len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
max_length -= entry_length_len;
if(read_cb(buffer, 1, entry_length_len, handle) != entry_length_len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
entry->length = unpack_uint32_little_endian_(buffer, entry_length_len);
if(max_length < entry->length) {
entry->length = 0;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA;
} else max_length -= entry->length;
if(0 != entry->entry)
free(entry->entry);
if(entry->length == 0) {
entry->entry = 0;
}
else {
if(0 == (entry->entry = safe_malloc_add_2op_(entry->length, /*+*/1)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
if(read_cb(entry->entry, 1, entry->length, handle) != entry->length)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
entry->entry[entry->length] = '\0';
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb, FLAC__StreamMetadata_VorbisComment *block, unsigned block_length)
{
unsigned i;
FLAC__Metadata_SimpleIteratorStatus status;
const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8 == sizeof(buffer));
status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, &(block->vendor_string), block_length);
if(block_length >= 4)
block_length -= 4;
if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA)
goto skip;
else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK)
return status;
block_length -= block->vendor_string.length;
if(block_length < num_comments_len) goto skip; else block_length -= num_comments_len;
if(read_cb(buffer, 1, num_comments_len, handle) != num_comments_len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->num_comments = unpack_uint32_little_endian_(buffer, num_comments_len);
if(block->num_comments == 0) {
block->comments = 0;
}
else if(0 == (block->comments = calloc(block->num_comments, sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
block->num_comments = 0;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
}
for(i = 0; i < block->num_comments; i++) {
status = read_metadata_block_data_vorbis_comment_entry_cb_(handle, read_cb, block->comments + i, block_length);
if(block_length >= 4) block_length -= 4;
if(status == FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA) {
block->num_comments = i;
goto skip;
}
else if(status != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK) return status;
block_length -= block->comments[i].length;
}
skip:
if(block_length > 0) {
/* bad metadata */
if(0 != seek_cb(handle, block_length, SEEK_CUR))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_track_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet_Track *track)
{
unsigned i, len;
FLAC__byte buffer[32]; /* asserted below that this is big enough */
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
track->offset = unpack_uint64_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
track->number = (FLAC__byte)unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8;
if(read_cb(track->isrc, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0);
len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN == 1);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN == 1);
track->type = buffer[0] >> 7;
track->pre_emphasis = (buffer[0] >> 6) & 1;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
track->num_indices = (FLAC__byte)unpack_uint32_(buffer, len);
if(track->num_indices == 0) {
track->indices = 0;
}
else if(0 == (track->indices = calloc(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index))))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
for(i = 0; i < track->num_indices; i++) {
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
track->indices[i].offset = unpack_uint64_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
track->indices[i].number = (FLAC__byte)unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_CueSheet *block)
{
unsigned i, len;
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__byte buffer[1024]; /* MSVC needs a constant expression so we put a magic number and assert */
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN)/8 <= sizeof(buffer));
FLAC__ASSERT(sizeof(FLAC__uint64) <= sizeof(buffer));
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8;
if(read_cb(block->media_catalog_number, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->lead_in = unpack_uint64_(buffer, len);
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0);
len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->is_cd = buffer[0]&0x80? true : false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->num_tracks = unpack_uint32_(buffer, len);
if(block->num_tracks == 0) {
block->tracks = 0;
}
else if(0 == (block->tracks = calloc(block->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track))))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
for(i = 0; i < block->num_tracks; i++) {
if(FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK != (status = read_metadata_block_data_cuesheet_track_cb_(handle, read_cb, block->tracks + i)))
return status;
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
static FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cstring_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__byte **data, FLAC__uint32 *length, FLAC__uint32 length_len)
{
FLAC__byte buffer[sizeof(FLAC__uint32)];
FLAC__ASSERT(0 != data);
FLAC__ASSERT(length_len%8 == 0);
length_len /= 8; /* convert to bytes */
FLAC__ASSERT(sizeof(buffer) >= length_len);
if(read_cb(buffer, 1, length_len, handle) != length_len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
*length = unpack_uint32_(buffer, length_len);
if(0 != *data)
free(*data);
if(0 == (*data = safe_malloc_add_2op_(*length, /*+*/1)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
if(*length > 0) {
if(read_cb(*data, 1, *length, handle) != *length)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
}
(*data)[*length] = '\0';
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Picture *block)
{
FLAC__Metadata_SimpleIteratorStatus status;
FLAC__byte buffer[4]; /* asserted below that this is big enough */
FLAC__uint32 len;
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_TYPE_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->type = (FLAC__StreamMetadata_Picture_Type)unpack_uint32_(buffer, len);
if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, (FLAC__byte**)(&(block->mime_type)), &len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK)
return status;
if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->description), &len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK)
return status;
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->width = unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->height = unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->depth = unpack_uint32_(buffer, len);
FLAC__ASSERT(FLAC__STREAM_METADATA_PICTURE_COLORS_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN / 8;
if(read_cb(buffer, 1, len, handle) != len)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
block->colors = unpack_uint32_(buffer, len);
/* for convenience we use read_metadata_block_data_picture_cstring_cb_() even though it adds an extra terminating NUL we don't use */
if((status = read_metadata_block_data_picture_cstring_cb_(handle, read_cb, &(block->data), &(block->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN)) != FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK)
return status;
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__Metadata_SimpleIteratorStatus read_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__StreamMetadata_Unknown *block, unsigned block_length)
{
if(block_length == 0) {
block->data = 0;
}
else {
if(0 == (block->data = malloc(block_length)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
if(read_cb(block->data, 1, block_length, handle) != block_length)
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
}
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
}
FLAC__bool write_metadata_block_header_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block)
{
FLAC__ASSERT(0 != file);
FLAC__ASSERT(0 != status);
if(!write_metadata_block_header_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
return true;
}
FLAC__bool write_metadata_block_data_(FILE *file, FLAC__Metadata_SimpleIteratorStatus *status, const FLAC__StreamMetadata *block)
{
FLAC__ASSERT(0 != file);
FLAC__ASSERT(0 != status);
if (write_metadata_block_data_cb_((FLAC__IOHandle)file, (FLAC__IOCallback_Write)fwrite, block)) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK;
return true;
}
else {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
}
FLAC__bool write_metadata_block_header_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block)
{
FLAC__byte buffer[FLAC__STREAM_METADATA_HEADER_LENGTH];
FLAC__ASSERT(block->length < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
/* double protection */
if(block->length >= (1u << FLAC__STREAM_METADATA_LENGTH_LEN))
return false;
buffer[0] = (block->is_last? 0x80 : 0) | (FLAC__byte)block->type;
pack_uint32_(block->length, buffer + 1, 3);
if(write_cb(buffer, 1, FLAC__STREAM_METADATA_HEADER_LENGTH, handle) != FLAC__STREAM_METADATA_HEADER_LENGTH)
return false;
return true;
}
FLAC__bool write_metadata_block_data_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata *block)
{
FLAC__ASSERT(0 != block);
switch(block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
return write_metadata_block_data_streaminfo_cb_(handle, write_cb, &block->data.stream_info);
case FLAC__METADATA_TYPE_PADDING:
return write_metadata_block_data_padding_cb_(handle, write_cb, &block->data.padding, block->length);
case FLAC__METADATA_TYPE_APPLICATION:
return write_metadata_block_data_application_cb_(handle, write_cb, &block->data.application, block->length);
case FLAC__METADATA_TYPE_SEEKTABLE:
return write_metadata_block_data_seektable_cb_(handle, write_cb, &block->data.seek_table);
case FLAC__METADATA_TYPE_VORBIS_COMMENT:
return write_metadata_block_data_vorbis_comment_cb_(handle, write_cb, &block->data.vorbis_comment);
case FLAC__METADATA_TYPE_CUESHEET:
return write_metadata_block_data_cuesheet_cb_(handle, write_cb, &block->data.cue_sheet);
case FLAC__METADATA_TYPE_PICTURE:
return write_metadata_block_data_picture_cb_(handle, write_cb, &block->data.picture);
default:
return write_metadata_block_data_unknown_cb_(handle, write_cb, &block->data.unknown, block->length);
}
}
FLAC__bool write_metadata_block_data_streaminfo_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_StreamInfo *block)
{
FLAC__byte buffer[FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
const unsigned channels1 = block->channels - 1;
const unsigned bps1 = block->bits_per_sample - 1;
/* we are using hardcoded numbers for simplicity but we should
* probably eventually write a bit-level packer and use the
* _STREAMINFO_ constants.
*/
pack_uint32_(block->min_blocksize, buffer, 2);
pack_uint32_(block->max_blocksize, buffer+2, 2);
pack_uint32_(block->min_framesize, buffer+4, 3);
pack_uint32_(block->max_framesize, buffer+7, 3);
buffer[10] = (block->sample_rate >> 12) & 0xff;
buffer[11] = (block->sample_rate >> 4) & 0xff;
buffer[12] = ((block->sample_rate & 0x0f) << 4) | (channels1 << 1) | (bps1 >> 4);
buffer[13] = (FLAC__byte)(((bps1 & 0x0f) << 4) | ((block->total_samples >> 32) & 0x0f));
pack_uint32_((FLAC__uint32)block->total_samples, buffer+14, 4);
memcpy(buffer+18, block->md5sum, 16);
if(write_cb(buffer, 1, FLAC__STREAM_METADATA_STREAMINFO_LENGTH, handle) != FLAC__STREAM_METADATA_STREAMINFO_LENGTH)
return false;
return true;
}
FLAC__bool write_metadata_block_data_padding_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Padding *block, unsigned block_length)
{
unsigned i, n = block_length;
FLAC__byte buffer[1024];
(void)block;
memset(buffer, 0, 1024);
for(i = 0; i < n/1024; i++)
if(write_cb(buffer, 1, 1024, handle) != 1024)
return false;
n %= 1024;
if(write_cb(buffer, 1, n, handle) != n)
return false;
return true;
}
FLAC__bool write_metadata_block_data_application_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Application *block, unsigned block_length)
{
const unsigned id_bytes = FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8;
if(write_cb(block->id, 1, id_bytes, handle) != id_bytes)
return false;
block_length -= id_bytes;
if(write_cb(block->data, 1, block_length, handle) != block_length)
return false;
return true;
}
FLAC__bool write_metadata_block_data_seektable_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_SeekTable *block)
{
unsigned i;
FLAC__byte buffer[FLAC__STREAM_METADATA_SEEKPOINT_LENGTH];
for(i = 0; i < block->num_points; i++) {
/* some MAGIC NUMBERs here */
pack_uint64_(block->points[i].sample_number, buffer, 8);
pack_uint64_(block->points[i].stream_offset, buffer+8, 8);
pack_uint32_(block->points[i].frame_samples, buffer+16, 2);
if(write_cb(buffer, 1, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH, handle) != FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)
return false;
}
return true;
}
FLAC__bool write_metadata_block_data_vorbis_comment_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_VorbisComment *block)
{
unsigned i;
const unsigned entry_length_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN / 8;
const unsigned num_comments_len = FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN / 8;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(flac_max(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN, FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN) / 8 == sizeof(buffer));
pack_uint32_little_endian_(block->vendor_string.length, buffer, entry_length_len);
if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len)
return false;
if(write_cb(block->vendor_string.entry, 1, block->vendor_string.length, handle) != block->vendor_string.length)
return false;
pack_uint32_little_endian_(block->num_comments, buffer, num_comments_len);
if(write_cb(buffer, 1, num_comments_len, handle) != num_comments_len)
return false;
for(i = 0; i < block->num_comments; i++) {
pack_uint32_little_endian_(block->comments[i].length, buffer, entry_length_len);
if(write_cb(buffer, 1, entry_length_len, handle) != entry_length_len)
return false;
if(write_cb(block->comments[i].entry, 1, block->comments[i].length, handle) != block->comments[i].length)
return false;
}
return true;
}
FLAC__bool write_metadata_block_data_cuesheet_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_CueSheet *block)
{
unsigned i, j, len;
FLAC__byte buffer[1024]; /* asserted below that this is big enough */
FLAC__ASSERT(sizeof(buffer) >= sizeof(FLAC__uint64));
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN)/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN/8);
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN / 8;
if(write_cb(block->media_catalog_number, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN / 8;
pack_uint64_(block->lead_in, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) % 8 == 0);
len = (FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN + FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN) / 8;
memset(buffer, 0, len);
if(block->is_cd)
buffer[0] |= 0x80;
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN / 8;
pack_uint32_(block->num_tracks, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
for(i = 0; i < block->num_tracks; i++) {
FLAC__StreamMetadata_CueSheet_Track *track = block->tracks + i;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN / 8;
pack_uint64_(track->offset, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN / 8;
pack_uint32_(track->number, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN / 8;
if(write_cb(track->isrc, 1, len, handle) != len)
return false;
FLAC__ASSERT((FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) % 8 == 0);
len = (FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN + FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN) / 8;
memset(buffer, 0, len);
buffer[0] = (track->type << 7) | (track->pre_emphasis << 6);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN / 8;
pack_uint32_(track->num_indices, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
for(j = 0; j < track->num_indices; j++) {
FLAC__StreamMetadata_CueSheet_Index *indx = track->indices + j;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN / 8;
pack_uint64_(indx->offset, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN / 8;
pack_uint32_(indx->number, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN % 8 == 0);
len = FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN / 8;
memset(buffer, 0, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
}
}
return true;
}
FLAC__bool write_metadata_block_data_picture_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Picture *block)
{
unsigned len;
size_t slen;
FLAC__byte buffer[4]; /* magic number is asserted below */
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_TYPE_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_COLORS_LEN%8);
FLAC__ASSERT(0 == FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN%8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8);
FLAC__ASSERT(sizeof(buffer) >= FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8);
len = FLAC__STREAM_METADATA_PICTURE_TYPE_LEN/8;
pack_uint32_(block->type, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN/8;
slen = strlen(block->mime_type);
pack_uint32_(slen, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
if(write_cb(block->mime_type, 1, slen, handle) != slen)
return false;
len = FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN/8;
slen = strlen((const char *)block->description);
pack_uint32_(slen, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
if(write_cb(block->description, 1, slen, handle) != slen)
return false;
len = FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN/8;
pack_uint32_(block->width, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN/8;
pack_uint32_(block->height, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN/8;
pack_uint32_(block->depth, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_COLORS_LEN/8;
pack_uint32_(block->colors, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
len = FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN/8;
pack_uint32_(block->data_length, buffer, len);
if(write_cb(buffer, 1, len, handle) != len)
return false;
if(write_cb(block->data, 1, block->data_length, handle) != block->data_length)
return false;
return true;
}
FLAC__bool write_metadata_block_data_unknown_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Write write_cb, const FLAC__StreamMetadata_Unknown *block, unsigned block_length)
{
if(write_cb(block->data, 1, block_length, handle) != block_length)
return false;
return true;
}
FLAC__bool write_metadata_block_stationary_(FLAC__Metadata_SimpleIterator *iterator, const FLAC__StreamMetadata *block)
{
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
if(!write_metadata_block_header_(iterator->file, &iterator->status, block))
return false;
if(!write_metadata_block_data_(iterator->file, &iterator->status, block))
return false;
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
return read_metadata_block_header_(iterator);
}
FLAC__bool write_metadata_block_stationary_with_padding_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, unsigned padding_length, FLAC__bool padding_is_last)
{
FLAC__StreamMetadata *padding;
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
block->is_last = false;
if(!write_metadata_block_header_(iterator->file, &iterator->status, block))
return false;
if(!write_metadata_block_data_(iterator->file, &iterator->status, block))
return false;
if(0 == (padding = FLAC__metadata_object_new(FLAC__METADATA_TYPE_PADDING)))
return FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
padding->is_last = padding_is_last;
padding->length = padding_length;
if(!write_metadata_block_header_(iterator->file, &iterator->status, padding)) {
FLAC__metadata_object_delete(padding);
return false;
}
if(!write_metadata_block_data_(iterator->file, &iterator->status, padding)) {
FLAC__metadata_object_delete(padding);
return false;
}
FLAC__metadata_object_delete(padding);
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
return read_metadata_block_header_(iterator);
}
FLAC__bool rewrite_whole_file_(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool append)
{
FILE *tempfile = NULL;
char *tempfilename = NULL;
int fixup_is_last_code = 0; /* 0 => no need to change any is_last flags */
FLAC__off_t fixup_is_last_flag_offset = -1;
FLAC__ASSERT(0 != block || append == false);
if(iterator->is_last) {
if(append) {
fixup_is_last_code = 1; /* 1 => clear the is_last flag at the following offset */
fixup_is_last_flag_offset = iterator->offset[iterator->depth];
}
else if(0 == block) {
simple_iterator_push_(iterator);
if(!FLAC__metadata_simple_iterator_prev(iterator)) {
(void)simple_iterator_pop_(iterator);
return false;
}
fixup_is_last_code = -1; /* -1 => set the is_last the flag at the following offset */
fixup_is_last_flag_offset = iterator->offset[iterator->depth];
if(!simple_iterator_pop_(iterator))
return false;
}
}
if(!simple_iterator_copy_file_prefix_(iterator, &tempfile, &tempfilename, append))
return false;
if(0 != block) {
if(!write_metadata_block_header_(tempfile, &iterator->status, block)) {
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
}
if(!write_metadata_block_data_(tempfile, &iterator->status, block)) {
cleanup_tempfile_(&tempfile, &tempfilename);
return false;
}
}
if(!simple_iterator_copy_file_postfix_(iterator, &tempfile, &tempfilename, fixup_is_last_code, fixup_is_last_flag_offset, block==0))
return false;
if(append)
return FLAC__metadata_simple_iterator_next(iterator);
return true;
}
void simple_iterator_push_(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(iterator->depth+1 < SIMPLE_ITERATOR_MAX_PUSH_DEPTH);
iterator->offset[iterator->depth+1] = iterator->offset[iterator->depth];
iterator->depth++;
}
FLAC__bool simple_iterator_pop_(FLAC__Metadata_SimpleIterator *iterator)
{
FLAC__ASSERT(iterator->depth > 0);
iterator->depth--;
if(0 != fseeko(iterator->file, iterator->offset[iterator->depth], SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
return read_metadata_block_header_(iterator);
}
/* return meanings:
* 0: ok
* 1: read error
* 2: seek error
* 3: not a FLAC file
*/
unsigned seek_to_first_metadata_block_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Seek seek_cb)
{
FLAC__byte buffer[4];
size_t n;
unsigned i;
FLAC__ASSERT(FLAC__STREAM_SYNC_LENGTH == sizeof(buffer));
/* skip any id3v2 tag */
errno = 0;
n = read_cb(buffer, 1, 4, handle);
if(errno)
return 1;
else if(n != 4)
return 3;
else if(0 == memcmp(buffer, "ID3", 3)) {
unsigned tag_length = 0;
/* skip to the tag length */
if(seek_cb(handle, 2, SEEK_CUR) < 0)
return 2;
/* read the length */
for(i = 0; i < 4; i++) {
if(read_cb(buffer, 1, 1, handle) < 1 || buffer[0] & 0x80)
return 1;
tag_length <<= 7;
tag_length |= (buffer[0] & 0x7f);
}
/* skip the rest of the tag */
if(seek_cb(handle, tag_length, SEEK_CUR) < 0)
return 2;
/* read the stream sync code */
errno = 0;
n = read_cb(buffer, 1, 4, handle);
if(errno)
return 1;
else if(n != 4)
return 3;
}
/* check for the fLaC signature */
if(0 == memcmp(FLAC__STREAM_SYNC_STRING, buffer, FLAC__STREAM_SYNC_LENGTH))
return 0;
else
return 3;
}
unsigned seek_to_first_metadata_block_(FILE *f)
{
return seek_to_first_metadata_block_cb_((FLAC__IOHandle)f, (FLAC__IOCallback_Read)fread, fseek_wrapper_);
}
FLAC__bool simple_iterator_copy_file_prefix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, FLAC__bool append)
{
const FLAC__off_t offset_end = append? iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length : iterator->offset[iterator->depth];
if(0 != fseeko(iterator->file, 0, SEEK_SET)) {
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
if(!open_tempfile_(iterator->filename, iterator->tempfile_path_prefix, tempfile, tempfilename, &iterator->status)) {
cleanup_tempfile_(tempfile, tempfilename);
return false;
}
if(!copy_n_bytes_from_file_(iterator->file, *tempfile, offset_end, &iterator->status)) {
cleanup_tempfile_(tempfile, tempfilename);
return false;
}
return true;
}
FLAC__bool simple_iterator_copy_file_postfix_(FLAC__Metadata_SimpleIterator *iterator, FILE **tempfile, char **tempfilename, int fixup_is_last_code, FLAC__off_t fixup_is_last_flag_offset, FLAC__bool backup)
{
FLAC__off_t save_offset = iterator->offset[iterator->depth];
FLAC__ASSERT(0 != *tempfile);
if(0 != fseeko(iterator->file, save_offset + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length, SEEK_SET)) {
cleanup_tempfile_(tempfile, tempfilename);
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
if(!copy_remaining_bytes_from_file_(iterator->file, *tempfile, &iterator->status)) {
cleanup_tempfile_(tempfile, tempfilename);
return false;
}
if(fixup_is_last_code != 0) {
/*
* if code == 1, it means a block was appended to the end so
* we have to clear the is_last flag of the previous block
* if code == -1, it means the last block was deleted so
* we have to set the is_last flag of the previous block
*/
/* MAGIC NUMBERs here; we know the is_last flag is the high bit of the byte at this location */
FLAC__byte x;
if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) {
cleanup_tempfile_(tempfile, tempfilename);
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
if(fread(&x, 1, 1, *tempfile) != 1) {
cleanup_tempfile_(tempfile, tempfilename);
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
if(fixup_is_last_code > 0) {
FLAC__ASSERT(x & 0x80);
x &= 0x7f;
}
else {
FLAC__ASSERT(!(x & 0x80));
x |= 0x80;
}
if(0 != fseeko(*tempfile, fixup_is_last_flag_offset, SEEK_SET)) {
cleanup_tempfile_(tempfile, tempfilename);
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR;
return false;
}
if(local__fwrite(&x, 1, 1, *tempfile) != 1) {
cleanup_tempfile_(tempfile, tempfilename);
iterator->status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
}
(void)fclose(iterator->file);
if(!transport_tempfile_(iterator->filename, tempfile, tempfilename, &iterator->status))
return false;
if(iterator->has_stats)
set_file_stats_(iterator->filename, &iterator->stats);
if(!simple_iterator_prime_input_(iterator, !iterator->is_writable))
return false;
if(backup) {
while(iterator->offset[iterator->depth] + (FLAC__off_t)FLAC__STREAM_METADATA_HEADER_LENGTH + (FLAC__off_t)iterator->length < save_offset)
if(!FLAC__metadata_simple_iterator_next(iterator))
return false;
return true;
}
else {
/* move the iterator to it's original block faster by faking a push, then doing a pop_ */
FLAC__ASSERT(iterator->depth == 0);
iterator->offset[0] = save_offset;
iterator->depth++;
return simple_iterator_pop_(iterator);
}
}
FLAC__bool copy_n_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
{
FLAC__byte buffer[8192];
size_t n;
FLAC__ASSERT(bytes >= 0);
while(bytes > 0) {
n = flac_min(sizeof(buffer), (size_t)bytes);
if(fread(buffer, 1, n, file) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
if(local__fwrite(buffer, 1, n, tempfile) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
bytes -= n;
}
return true;
}
FLAC__bool copy_n_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__off_t bytes, FLAC__Metadata_SimpleIteratorStatus *status)
{
FLAC__byte buffer[8192];
size_t n;
FLAC__ASSERT(bytes >= 0);
while(bytes > 0) {
n = flac_min(sizeof(buffer), (size_t)bytes);
if(read_cb(buffer, 1, n, handle) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
if(temp_write_cb(buffer, 1, n, temp_handle) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
bytes -= n;
}
return true;
}
FLAC__bool copy_remaining_bytes_from_file_(FILE *file, FILE *tempfile, FLAC__Metadata_SimpleIteratorStatus *status)
{
FLAC__byte buffer[8192];
size_t n;
while(!feof(file)) {
n = fread(buffer, 1, sizeof(buffer), file);
if(n == 0 && !feof(file)) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
if(n > 0 && local__fwrite(buffer, 1, n, tempfile) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
}
return true;
}
FLAC__bool copy_remaining_bytes_from_file_cb_(FLAC__IOHandle handle, FLAC__IOCallback_Read read_cb, FLAC__IOCallback_Eof eof_cb, FLAC__IOHandle temp_handle, FLAC__IOCallback_Write temp_write_cb, FLAC__Metadata_SimpleIteratorStatus *status)
{
FLAC__byte buffer[8192];
size_t n;
while(!eof_cb(handle)) {
n = read_cb(buffer, 1, sizeof(buffer), handle);
if(n == 0 && !eof_cb(handle)) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR;
return false;
}
if(n > 0 && temp_write_cb(buffer, 1, n, temp_handle) != n) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR;
return false;
}
}
return true;
}
static int
local_snprintf(char *str, size_t size, const char *fmt, ...)
{
va_list va;
int rc;
va_start (va, fmt);
#if defined(_WIN32)||defined(__WATCOM__)
rc = _vsnprintf (str, size, fmt, va);
if (size != 0) {
if (rc < 0) rc = (int)size;
if ((size_t)rc >= size) str[size - 1] = '\0';
}
#else
rc = vsnprintf (str, size, fmt, va);
#endif
va_end (va);
return rc;
}
FLAC__bool open_tempfile_(const char *filename, const char *tempfile_path_prefix, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status)
{
static const char *tempfile_suffix = ".metadata_edit";
if(0 == tempfile_path_prefix) {
size_t dest_len = strlen(filename) + strlen(tempfile_suffix) + 1;
if(0 == (*tempfilename = safe_malloc_(dest_len))) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
local_snprintf(*tempfilename, dest_len, "%s%s", filename, tempfile_suffix);
}
else {
const char *p = strrchr(filename, '/');
size_t dest_len;
if(0 == p)
p = filename;
else
p++;
dest_len = strlen(tempfile_path_prefix) + strlen(p) + strlen(tempfile_suffix) + 2;
if(0 == (*tempfilename = safe_malloc_(dest_len))) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR;
return false;
}
local_snprintf(*tempfilename, dest_len, "%s/%s%s", tempfile_path_prefix, p, tempfile_suffix);
}
if(0 == (*tempfile = flac_fopen(*tempfilename, "w+b"))) {
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE;
return false;
}
return true;
}
FLAC__bool transport_tempfile_(const char *filename, FILE **tempfile, char **tempfilename, FLAC__Metadata_SimpleIteratorStatus *status)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != tempfile);
FLAC__ASSERT(0 != *tempfile);
FLAC__ASSERT(0 != tempfilename);
FLAC__ASSERT(0 != *tempfilename);
FLAC__ASSERT(0 != status);
(void)fclose(*tempfile);
*tempfile = 0;
#if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__ || defined __EMX__ || defined __OS2__ || defined __NT__
/* on some flavors of windows, flac_rename() will fail if the destination already exists */
if(flac_unlink(filename) < 0) {
cleanup_tempfile_(tempfile, tempfilename);
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR;
return false;
}
#endif
/*@@@ to fully support the tempfile_path_prefix we need to update this piece to actually copy across filesystems instead of just flac_rename(): */
if(0 != flac_rename(*tempfilename, filename)) {
cleanup_tempfile_(tempfile, tempfilename);
*status = FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR;
return false;
}
cleanup_tempfile_(tempfile, tempfilename);
return true;
}
void cleanup_tempfile_(FILE **tempfile, char **tempfilename)
{
if(0 != *tempfile) {
(void)fclose(*tempfile);
*tempfile = 0;
}
if(0 != *tempfilename) {
(void)flac_unlink(*tempfilename);
free(*tempfilename);
*tempfilename = 0;
}
}
FLAC__bool get_file_stats_(const char *filename, struct flac_stat_s *stats)
{
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != stats);
return (0 == flac_stat(filename, stats));
}
void set_file_stats_(const char *filename, struct flac_stat_s *stats)
{
struct utimbuf srctime;
FLAC__ASSERT(0 != filename);
FLAC__ASSERT(0 != stats);
srctime.actime = stats->st_atime;
srctime.modtime = stats->st_mtime;
(void)flac_chmod(filename, stats->st_mode);
(void)flac_utime(filename, &srctime);
#if !defined _MSC_VER && !defined __BORLANDC__ && !defined __MINGW32__ && !defined __OS2__ && !defined __NT__ && !defined __DJGPP__
FLAC_CHECK_RETURN(chown(filename, stats->st_uid, -1));
FLAC_CHECK_RETURN(chown(filename, -1, stats->st_gid));
#endif
}
int fseek_wrapper_(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
{
return fseeko((FILE*)handle, (FLAC__off_t)offset, whence);
}
FLAC__int64 ftell_wrapper_(FLAC__IOHandle handle)
{
return ftello((FILE*)handle);
}
FLAC__Metadata_ChainStatus get_equivalent_status_(FLAC__Metadata_SimpleIteratorStatus status)
{
switch(status) {
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK:
return FLAC__METADATA_CHAIN_STATUS_OK;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT:
return FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE:
return FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE:
return FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE:
return FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA:
return FLAC__METADATA_CHAIN_STATUS_BAD_METADATA;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR:
return FLAC__METADATA_CHAIN_STATUS_READ_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR:
return FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR:
return FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR:
return FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR:
return FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR:
return FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR;
case FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR:
default:
return FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR;
}
}
#endif /* FLAC_METADATA_INTERFACES */
|
the_stack_data/431540.c | #include <stdio.h>
#include <stdlib.h>
typedef struct _Node_
{
int minTurn;
char chDir;
} Node;
Node *pMinTurn = NULL;
int nRows = 0, nCols = 0;
void CalculateMinTurn(int curRow, int curCol)
{
if (pMinTurn[curRow*nCols + curCol].chDir == 'X')
return -1;
int minTurn = nRows*nCols;
if (curRow > 0 && curRow < nRows && pMinTurn[(curRow - 1)*nCols + curCol].chDir != '\0' && pMinTurn[(curRow - 1)*nCols + curCol].chDir != 'X') // from top (to down)
{
if (pMinTurn[(curRow - 1)*nCols + curCol].chDir == 'D' && pMinTurn[(curRow - 1)*nCols + curCol].minTurn < minTurn)
minTurn = pMinTurn[(curRow - 1)*nCols + curCol].minTurn, pMinTurn[curRow*nCols + curCol].chDir = 'D';
else if (pMinTurn[(curRow - 1)*nCols + curCol].chDir != 'D' && pMinTurn[(curRow - 1)*nCols + curCol].minTurn + 1 <minTurn)
minTurn = pMinTurn[(curRow - 1)*nCols + curCol].minTurn + 1, pMinTurn[curRow*nCols + curCol].chDir = 'D';
}
if (curCol > 0 && curCol < nCols && pMinTurn[curRow * nCols + curCol - 1].chDir != '\0' && pMinTurn[curRow * nCols + curCol - 1].chDir != 'X') // from left (to right)
{
if (pMinTurn[curRow * nCols + curCol - 1].chDir == 'R' && pMinTurn[curRow * nCols + curCol - 1].minTurn < minTurn)
minTurn = pMinTurn[curRow * nCols + curCol - 1].minTurn, pMinTurn[curRow*nCols + curCol].chDir = 'R';
else if(pMinTurn[curRow * nCols + curCol - 1].chDir != 'R' && pMinTurn[curRow * nCols + curCol - 1].minTurn + 1 < minTurn)
minTurn = pMinTurn[curRow * nCols + curCol - 1].minTurn + 1, pMinTurn[curRow*nCols + curCol].chDir = 'R';
}
if (curCol >= 0 && curCol < nCols - 1 && pMinTurn[curRow * nCols + curCol + 1].chDir != '\0' && pMinTurn[curRow * nCols + curCol + 1].chDir != 'X') // from right (to left)
{
if (pMinTurn[curRow * nCols + curCol + 1].chDir == 'L' && pMinTurn[curRow * nCols + curCol + 1].minTurn < minTurn)
minTurn = pMinTurn[curRow * nCols + curCol + 1].minTurn, pMinTurn[curRow*nCols + curCol].chDir = 'L';
else if (pMinTurn[curRow * nCols + curCol + 1].chDir != 'L' && pMinTurn[curRow * nCols + curCol + 1].minTurn + 1 < minTurn)
minTurn = pMinTurn[curRow * nCols + curCol + 1].minTurn + 1, pMinTurn[curRow*nCols + curCol].chDir = 'L';
}
if (minTurn < nRows*nCols)
pMinTurn[curRow*nCols + curCol].minTurn = minTurn;
else
pMinTurn[curRow*nCols + curCol].minTurn = -1;
}
void main()
{
while (scanf("%d %d", &nRows, &nCols) != EOF)
{
pMinTurn = (Node *)calloc(nRows*nCols, sizeof(Node));
// Read start and end point
int stPoint, endPoint;
scanf("%d %d", &stPoint, &endPoint);
pMinTurn[stPoint].minTurn = 0;
pMinTurn[stPoint].chDir = 'D';
// Read the positions of obstacles
int nObstacle = 0;
scanf("%d", &nObstacle);
for (int k = 0; k < nObstacle; k++)
{
int xRow = 0, yCol = 0;
scanf("%d %d", &xRow, &yCol);
pMinTurn[xRow*nCols + yCol].minTurn = -1;
pMinTurn[xRow*nCols + yCol].chDir = 'X';
}
for (int r = 0; r < nRows; r++)
{
for (int c = 0; c < nCols; c++)
{
if (r == 0 && c == stPoint)
continue;
CalculateMinTurn(r, c);
}
for (int c = nCols-1; c >=0; c--)
{
if (r == 0 && c == stPoint)
continue;
CalculateMinTurn(r, c);
}
}
printf("%d\n", pMinTurn[(nRows - 1)*nCols + endPoint]);
free(pMinTurn);
}
}
|
the_stack_data/62636595.c | #include <stdio.h>
#define TABINC 8 /* number of spaces for one TAB hit */
#define MAXLINE 1000 /* maximum number of characters in an array */
void detab(char characters[], int characters_count);
int main()
{
int i, c;
int pos;
char line[MAXLINE];
pos = 1;
while ((c = getc(stdin)) != '\n') {
if(c != '\t') {
line[i] = c;
++pos;
}
else if(c == '\t')
detab(line, pos);
}
line[pos] = '\0';
printf("%s", line);
return 0;
}
void detab(char add_tab[], int incpos)
{
int nb;
nb = TABINC - ((incpos-1) % TABINC);
while(nb >= 1) {
add_tab[incpos] = '#';
++incpos;
}
}
|
the_stack_data/167330271.c | /*
Copyright (c) 2010-2019, Mark Final
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of BuildAMation 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.
*/
char *PlatformName()
{
return "Windows";
}
|
the_stack_data/1248267.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 51
struct bigint {
size_t size;
char *s;
};
/* add two bigints, return the result with n1 */
void add(struct bigint *n1, struct bigint *n2)
{
int i, j;
int carry = 0;
char d1, d2;
if ( n1 -> size < n2 -> size ) {
char *s = malloc( (n1 -> size + 1) * sizeof(char));
size_t size;
strcpy(s, n1 -> s);
n1 -> s = realloc(n1 -> s, n2 -> size + 1);
strcpy(n1 -> s, n2 -> s);
strcpy(n2 -> s, s);
n2 -> s = realloc(n2 -> s, n1 -> size + 1);
size = n1 -> size;
n1 -> size = n2 -> size;
n2 -> size = size;
free(s);
}
for ( i = n1 -> size - 1, j = n2 -> size - 1; i >= 0 && j >= 0; i--, j-- ) {
d1 = n1 -> s[i] - '0';
d2 = n2 -> s[j] - '0';
if ( (carry += d1 + d2) > 9 ) {
n1 -> s[i] = carry - 10 + '0';
carry = 1;
} else {
n1 -> s[i] = carry + '0';
carry = 0;
}
}
if ( carry != 0 ) {
if ( i == 0 ) {
d1 = n1 -> s[i] - '0';
carry += d1;
if ( carry > 9 ) {
n1 -> s[i] = carry - 10 + '0';
carry = 1;
} else {
n1 -> s[i] = carry + '0';
carry = 0;
}
} else if ( i < 0 ) {
char *s, *t;
n1 -> size = n1 -> size + 1;
s = malloc((n1 -> size + 1) * sizeof(char));
strcpy(s + 1, n1 -> s);
s[0] = carry + '0';
t = n1 -> s;
n1 -> s = s;
free(t);
carry = 0;
} else {
for ( ; i >= 0; i-- ) {
d1 = n1 -> s[i] - '0';
carry += d1;
if ( carry > 9 ) {
n1 -> s[i] = carry - 10 + '0';
carry = 1;
} else {
n1 -> s[i] = carry + '0';
carry = 0;
break;
}
}
}
if ( carry != 0 ) {
char *s, *t;
n1 -> size = n1 -> size + 1;
s = malloc((n1 -> size + 1) * sizeof(char));
strcpy(s + 1, n1 -> s);
s[0] = carry + '0';
t = n1 -> s;
n1 -> s = s;
free(t);
carry = 0;
}
}
}
int main()
{
struct bigint n1, n2;
n1.size = SIZE - 1;
n2.size = SIZE - 1;
n1.s = malloc(SIZE * sizeof(char));
n2.s = malloc(SIZE * sizeof(char));
for ( fgets(n1.s, SIZE, stdin), getchar(); fgets(n2.s, SIZE, stdin) != NULL; getchar() ) {
add(&n1, &n2);
}
puts(n1.s);
free(n1.s);
free(n2.s);
return 0;
}
|
the_stack_data/176701690.c | #include <stdio.h>
/* Enunciado:
*
* Elabore um programa que exiba "Ola, mundo!" na tela e pula uma linha
*
*/
int main (int argc, char *argv[])
{
// Coloque seu codigo a partir daqui
printf("Ola, mundo!\n");
return 0;
}
|
the_stack_data/170453683.c | /* Generated by re2c 1.0.3 */
#line 1 "../gpr.re2c"
// generated parser support file. -*- mode: C -*-
// command line: wisitoken-bnf-generate.exe --generate LR1 Ada_Emacs re2c PROCESS gpr.wy
//
// Copyright (C) 2013 - 2019 Free Software Foundation, Inc.
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 3, or (at
// your option) any later version.
//
// This software 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct wisi_lexer
{
unsigned char* buffer; // input text, in utf-8 encoding
unsigned char* buffer_last; // last byte in buffer
unsigned char* cursor; // current byte
unsigned char* byte_token_start; // byte position at start of current token
size_t char_pos; // character position of current character
size_t char_token_start; // character position at start of current token
int line; // 1 indexed
int line_token_start; // line at start of current token
unsigned char* marker; // saved cursor
size_t marker_pos; // saved character position
size_t marker_line; // saved line
unsigned char* context; // saved cursor
size_t context_pos; // saved character position
int context_line; // saved line
int verbosity;
} wisi_lexer;
#define YYCTYPE unsigned char
#define NO_ERROR 0
#define ERROR_unrecognized_character 1
wisi_lexer* gpr_new_lexer
(unsigned char* input, size_t length, int verbosity)
{
wisi_lexer* result = malloc (sizeof (wisi_lexer));
result->buffer = input;
result->buffer_last = input + length - 1;
result->cursor = input;
result->byte_token_start = input;
result->char_pos = 1; /* match WisiToken.Buffer_Region */
result->char_token_start = 1;
result->line = (*result->cursor == 0x0A) ? 2 : 1;
result->line_token_start = result->line;
result->verbosity = verbosity;
return result;
}
void
gpr_free_lexer(wisi_lexer** lexer)
{
free(*lexer);
*lexer = 0;
}
void
gpr_reset_lexer(wisi_lexer* lexer)
{
lexer->cursor = lexer->buffer;
lexer->char_pos = 1;
lexer->line = (*lexer->cursor == 0x0A) ? 2 : 1;
}
static void debug(wisi_lexer* lexer, int state, unsigned char ch)
{
if (lexer->verbosity > 0)
{
if (ch < ' ')
printf ("lexer: %d, 0x%x\n", state, ch);
else
printf ("lexer: %d, '%c' 0x%x\n", state, ch, ch);
}
}
#define YYDEBUG(state, ch) debug(lexer, state, ch)
#define YYCURSOR lexer->cursor
#define YYPEEK() (lexer->cursor <= lexer->buffer_last) ? *lexer->cursor : 4
static void skip(wisi_lexer* lexer)
{
if (lexer->cursor <= lexer->buffer_last)
++lexer->cursor;
if (lexer->cursor <= lexer->buffer_last)
{
/* UFT-8 encoding: https://en.wikipedia.org/wiki/UTF-8#Description */
if (*lexer->cursor == 0x0A && lexer->cursor > lexer->buffer && *(lexer->cursor - 1) == 0x0D)
{/* second byte of DOS line ending */
}
else if ((*lexer->cursor & 0x80) == 0x80 && (*lexer->cursor & 0xC0) != 0xC0)
{/* byte 2, 3 or 4 of multi-byte UTF-8 char */
}
else
++lexer->char_pos;
if (*lexer->cursor == 0x0A) ++lexer->line;
}
}
#define YYSKIP() skip(lexer)
#define YYBACKUP() lexer->marker = lexer->cursor; lexer->marker_pos = lexer->char_pos;lexer->marker_line = lexer->line
#define YYRESTORE() lexer->cursor = lexer->marker; lexer->char_pos = lexer->marker_pos;lexer->line = lexer->marker_line
#define YYBACKUPCTX() lexer->context = lexer->cursor; lexer->context_pos = lexer->char_pos;lexer->context_line = lexer->line
#define YYRESTORECTX() lexer->cursor = lexer->context; lexer->char_pos = lexer->context_pos;lexer->line = lexer->context_line
int gpr_next_token
(wisi_lexer* lexer,
int* id,
size_t* byte_position,
size_t* byte_length,
size_t* char_position,
size_t* char_length,
int* line_start)
{
int status = NO_ERROR;
*id = -1;
if (lexer->cursor > lexer->buffer_last)
{
*id = 39;
*byte_position = lexer->buffer_last - lexer->buffer + 1;
*byte_length = 0;
*char_position = lexer->char_token_start;
*char_length = 0;
*line_start = lexer->line;
return status;
}
lexer->byte_token_start = lexer->cursor;
lexer->char_token_start = lexer->char_pos;
if (*lexer->cursor == 0x0A)
lexer->line_token_start = lexer->line-1;
else
lexer->line_token_start = lexer->line;
while (*id == -1 && status == 0)
{
#line 153 "../gpr_re2c.c"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
YYDEBUG(0, *YYCURSOR);
yych = YYPEEK ();
switch (yych) {
case 0x04: goto yy4;
case '\t':
case ' ': goto yy6;
case '\n': goto yy8;
case '\r': goto yy10;
case '"': goto yy11;
case '&': goto yy12;
case '\'': goto yy14;
case '(': goto yy16;
case ')': goto yy18;
case ',': goto yy20;
case '-': goto yy22;
case '.': goto yy23;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': goto yy25;
case ':': goto yy28;
case ';': goto yy30;
case '=': goto yy32;
case 'A':
case 'a': goto yy33;
case 'B':
case 'D':
case 'G':
case 'H':
case 'J':
case 'K':
case 'M':
case 'Q':
case 'V':
case 'X':
case 'Y':
case 'Z':
case 'b':
case 'd':
case 'g':
case 'h':
case 'j':
case 'k':
case 'm':
case 'q':
case 'v':
case 'x':
case 'y':
case 'z': goto yy35;
case 'C':
case 'c': goto yy37;
case 'E':
case 'e': goto yy38;
case 'F':
case 'f': goto yy39;
case 'I':
case 'i': goto yy40;
case 'L':
case 'l': goto yy41;
case 'N':
case 'n': goto yy42;
case 'O':
case 'o': goto yy43;
case 'P':
case 'p': goto yy44;
case 'R':
case 'r': goto yy45;
case 'S':
case 's': goto yy46;
case 'T':
case 't': goto yy47;
case 'U':
case 'u': goto yy48;
case 'W':
case 'w': goto yy49;
case '|': goto yy50;
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF: goto yy52;
case 0xE0: goto yy53;
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF: goto yy54;
case 0xF0: goto yy55;
case 0xF1:
case 0xF2:
case 0xF3: goto yy56;
case 0xF4: goto yy57;
default: goto yy2;
}
yy2:
YYDEBUG(2, YYPEEK ());
YYSKIP ();
yy3:
YYDEBUG(3, YYPEEK ());
#line 241 "../gpr.re2c"
{status = ERROR_unrecognized_character; continue;}
#line 299 "../gpr_re2c.c"
yy4:
YYDEBUG(4, YYPEEK ());
YYSKIP ();
YYDEBUG(5, YYPEEK ());
#line 239 "../gpr.re2c"
{*id = 39; continue;}
#line 306 "../gpr_re2c.c"
yy6:
YYDEBUG(6, YYPEEK ());
YYSKIP ();
YYDEBUG(7, YYPEEK ());
#line 194 "../gpr.re2c"
{ lexer->byte_token_start = lexer->cursor;
lexer->char_token_start = lexer->char_pos;
if (*lexer->cursor == 0x0A)
lexer->line_token_start = lexer->line-1;
else
lexer->line_token_start = lexer->line;
continue; }
#line 319 "../gpr_re2c.c"
yy8:
YYDEBUG(8, YYPEEK ());
YYSKIP ();
YYDEBUG(9, YYPEEK ());
#line 201 "../gpr.re2c"
{*id = 1; continue;}
#line 326 "../gpr_re2c.c"
yy10:
YYDEBUG(10, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case '\n': goto yy8;
default: goto yy3;
}
yy11:
YYDEBUG(11, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case ' ':
case '!':
case '"':
case '#':
case '$':
case '%':
case '&':
case '\'':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case '{':
case '|':
case '}':
case '~':
case 0x7F:
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy59;
default: goto yy3;
}
yy12:
YYDEBUG(12, YYPEEK ());
YYSKIP ();
YYDEBUG(13, YYPEEK ());
#line 227 "../gpr.re2c"
{*id = 27; continue;}
#line 497 "../gpr_re2c.c"
yy14:
YYDEBUG(14, YYPEEK ());
YYSKIP ();
YYDEBUG(15, YYPEEK ());
#line 233 "../gpr.re2c"
{*id = 33; continue;}
#line 504 "../gpr_re2c.c"
yy16:
YYDEBUG(16, YYPEEK ());
YYSKIP ();
YYDEBUG(17, YYPEEK ());
#line 214 "../gpr.re2c"
{*id = 14; continue;}
#line 511 "../gpr_re2c.c"
yy18:
YYDEBUG(18, YYPEEK ());
YYSKIP ();
YYDEBUG(19, YYPEEK ());
#line 221 "../gpr.re2c"
{*id = 21; continue;}
#line 518 "../gpr_re2c.c"
yy20:
YYDEBUG(20, YYPEEK ());
YYSKIP ();
YYDEBUG(21, YYPEEK ());
#line 230 "../gpr.re2c"
{*id = 30; continue;}
#line 525 "../gpr_re2c.c"
yy22:
YYDEBUG(22, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case '-': goto yy69;
default: goto yy3;
}
yy23:
YYDEBUG(23, YYPEEK ());
YYSKIP ();
YYDEBUG(24, YYPEEK ());
#line 231 "../gpr.re2c"
{*id = 31; continue;}
#line 540 "../gpr_re2c.c"
yy25:
YYDEBUG(25, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
YYDEBUG(26, YYPEEK ());
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': goto yy25;
default: goto yy27;
}
yy27:
YYDEBUG(27, YYPEEK ());
#line 236 "../gpr.re2c"
{*id = 36; continue;}
#line 563 "../gpr_re2c.c"
yy28:
YYDEBUG(28, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case '=': goto yy72;
default: goto yy29;
}
yy29:
YYDEBUG(29, YYPEEK ());
#line 228 "../gpr.re2c"
{*id = 28; continue;}
#line 576 "../gpr_re2c.c"
yy30:
YYDEBUG(30, YYPEEK ());
YYSKIP ();
YYDEBUG(31, YYPEEK ());
#line 234 "../gpr.re2c"
{*id = 34; continue;}
#line 583 "../gpr_re2c.c"
yy32:
YYDEBUG(32, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case '>': goto yy74;
default: goto yy3;
}
yy33:
YYDEBUG(33, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'B':
case 'b': goto yy76;
case 'G':
case 'g': goto yy77;
case 'T':
case 't': goto yy78;
default: goto yy36;
}
yy34:
YYDEBUG(34, YYPEEK ());
#line 237 "../gpr.re2c"
{*id = 37; continue;}
#line 611 "../gpr_re2c.c"
yy35:
YYDEBUG(35, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
yy36:
YYDEBUG(36, YYPEEK ());
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z': goto yy35;
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF: goto yy80;
case 0xE0: goto yy81;
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF: goto yy82;
case 0xF0: goto yy83;
case 0xF1:
case 0xF2:
case 0xF3: goto yy84;
case 0xF4: goto yy85;
default: goto yy34;
}
yy37:
YYDEBUG(37, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy86;
case 'O':
case 'o': goto yy87;
default: goto yy36;
}
yy38:
YYDEBUG(38, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy88;
case 'X':
case 'x': goto yy89;
default: goto yy36;
}
yy39:
YYDEBUG(39, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'O':
case 'o': goto yy90;
default: goto yy36;
}
yy40:
YYDEBUG(40, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy91;
default: goto yy36;
}
yy41:
YYDEBUG(41, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'I':
case 'i': goto yy93;
default: goto yy36;
}
yy42:
YYDEBUG(42, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'U':
case 'u': goto yy94;
default: goto yy36;
}
yy43:
YYDEBUG(43, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy95;
default: goto yy36;
}
yy44:
YYDEBUG(44, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy96;
case 'R':
case 'r': goto yy97;
default: goto yy36;
}
yy45:
YYDEBUG(45, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy98;
default: goto yy36;
}
yy46:
YYDEBUG(46, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy99;
default: goto yy36;
}
yy47:
YYDEBUG(47, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'Y':
case 'y': goto yy100;
default: goto yy36;
}
yy48:
YYDEBUG(48, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy101;
default: goto yy36;
}
yy49:
YYDEBUG(49, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'H':
case 'h': goto yy102;
case 'I':
case 'i': goto yy103;
default: goto yy36;
}
yy50:
YYDEBUG(50, YYPEEK ());
YYSKIP ();
YYDEBUG(51, YYPEEK ());
#line 235 "../gpr.re2c"
{*id = 35; continue;}
#line 894 "../gpr_re2c.c"
yy52:
YYDEBUG(52, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy35;
default: goto yy3;
}
yy53:
YYDEBUG(53, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy80;
default: goto yy3;
}
yy54:
YYDEBUG(54, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy80;
default: goto yy3;
}
yy55:
YYDEBUG(55, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy82;
default: goto yy3;
}
yy56:
YYDEBUG(56, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy82;
default: goto yy3;
}
yy57:
YYDEBUG(57, YYPEEK ());
yyaccept = 0;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F: goto yy82;
default: goto yy3;
}
yy58:
YYDEBUG(58, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
yy59:
YYDEBUG(59, YYPEEK ());
switch (yych) {
case ' ':
case '!':
case '#':
case '$':
case '%':
case '&':
case '\'':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case '{':
case '|':
case '}':
case '~':
case 0x7F: goto yy58;
case '"': goto yy61;
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF: goto yy63;
case 0xE0: goto yy64;
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF: goto yy65;
case 0xF0: goto yy66;
case 0xF1:
case 0xF2:
case 0xF3: goto yy67;
case 0xF4: goto yy68;
default: goto yy60;
}
yy60:
YYDEBUG(60, YYPEEK ());
YYRESTORE ();
switch (yyaccept) {
case 0: goto yy3;
case 1: goto yy34;
case 2: goto yy62;
case 3: goto yy71;
case 4: goto yy79;
case 5: goto yy92;
case 6: goto yy115;
case 7: goto yy118;
case 8: goto yy128;
case 9: goto yy134;
case 10: goto yy139;
case 11: goto yy146;
case 12: goto yy148;
case 13: goto yy150;
case 14: goto yy169;
case 15: goto yy178;
case 16: goto yy181;
case 17: goto yy183;
case 18: goto yy185;
case 19: goto yy187;
case 20: goto yy190;
case 21: goto yy194;
case 22: goto yy196;
case 23: goto yy198;
case 24: goto yy208;
default: goto yy213;
}
yy61:
YYDEBUG(61, YYPEEK ());
yyaccept = 2;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '"': goto yy58;
default: goto yy62;
}
yy62:
YYDEBUG(62, YYPEEK ());
#line 238 "../gpr.re2c"
{*id = 38; continue;}
#line 1436 "../gpr_re2c.c"
yy63:
YYDEBUG(63, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy58;
default: goto yy60;
}
yy64:
YYDEBUG(64, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy63;
default: goto yy60;
}
yy65:
YYDEBUG(65, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy63;
default: goto yy60;
}
yy66:
YYDEBUG(66, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy65;
default: goto yy60;
}
yy67:
YYDEBUG(67, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy65;
default: goto yy60;
}
yy68:
YYDEBUG(68, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F: goto yy65;
default: goto yy60;
}
yy69:
YYDEBUG(69, YYPEEK ());
yyaccept = 3;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
YYDEBUG(70, YYPEEK ());
switch (yych) {
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07:
case 0x08:
case '\t':
case '\v':
case '\f':
case '\r':
case 0x0E:
case 0x0F:
case 0x10:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x15:
case 0x16:
case 0x17:
case 0x18:
case 0x19:
case 0x1A:
case 0x1B:
case 0x1C:
case 0x1D:
case 0x1E:
case 0x1F:
case ' ':
case '!':
case '"':
case '#':
case '$':
case '%':
case '&':
case '\'':
case '(':
case ')':
case '*':
case '+':
case ',':
case '-':
case '.':
case '/':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ':':
case ';':
case '<':
case '=':
case '>':
case '?':
case '@':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '[':
case '\\':
case ']':
case '^':
case '_':
case '`':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case '{':
case '|':
case '}':
case '~':
case 0x7F: goto yy69;
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF: goto yy104;
case 0xE0: goto yy105;
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF: goto yy106;
case 0xF0: goto yy107;
case 0xF1:
case 0xF2:
case 0xF3: goto yy108;
case 0xF4: goto yy109;
default: goto yy71;
}
yy71:
YYDEBUG(71, YYPEEK ());
#line 202 "../gpr.re2c"
{*id = 2; continue;}
#line 1959 "../gpr_re2c.c"
yy72:
YYDEBUG(72, YYPEEK ());
YYSKIP ();
YYDEBUG(73, YYPEEK ());
#line 229 "../gpr.re2c"
{*id = 29; continue;}
#line 1966 "../gpr_re2c.c"
yy74:
YYDEBUG(74, YYPEEK ());
YYSKIP ();
YYDEBUG(75, YYPEEK ());
#line 232 "../gpr.re2c"
{*id = 32; continue;}
#line 1973 "../gpr_re2c.c"
yy76:
YYDEBUG(76, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy110;
default: goto yy36;
}
yy77:
YYDEBUG(77, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'G':
case 'g': goto yy111;
default: goto yy36;
}
yy78:
YYDEBUG(78, YYPEEK ());
yyaccept = 4;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy79;
}
yy79:
YYDEBUG(79, YYPEEK ());
#line 204 "../gpr.re2c"
{*id = 4; continue;}
#line 2123 "../gpr_re2c.c"
yy80:
YYDEBUG(80, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy35;
default: goto yy60;
}
yy81:
YYDEBUG(81, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy80;
default: goto yy60;
}
yy82:
YYDEBUG(82, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy80;
default: goto yy60;
}
yy83:
YYDEBUG(83, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy82;
default: goto yy60;
}
yy84:
YYDEBUG(84, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy82;
default: goto yy60;
}
yy85:
YYDEBUG(85, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F: goto yy82;
default: goto yy60;
}
yy86:
YYDEBUG(86, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy112;
default: goto yy36;
}
yy87:
YYDEBUG(87, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy113;
default: goto yy36;
}
yy88:
YYDEBUG(88, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'D':
case 'd': goto yy114;
default: goto yy36;
}
yy89:
YYDEBUG(89, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy116;
default: goto yy36;
}
yy90:
YYDEBUG(90, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy117;
default: goto yy36;
}
yy91:
YYDEBUG(91, YYPEEK ());
yyaccept = 5;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy92;
}
yy92:
YYDEBUG(92, YYPEEK ());
#line 213 "../gpr.re2c"
{*id = 13; continue;}
#line 2636 "../gpr_re2c.c"
yy93:
YYDEBUG(93, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'B':
case 'b': goto yy119;
default: goto yy36;
}
yy94:
YYDEBUG(94, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'L':
case 'l': goto yy120;
default: goto yy36;
}
yy95:
YYDEBUG(95, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'H':
case 'h': goto yy121;
default: goto yy36;
}
yy96:
YYDEBUG(96, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'C':
case 'c': goto yy122;
default: goto yy36;
}
yy97:
YYDEBUG(97, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'O':
case 'o': goto yy123;
default: goto yy36;
}
yy98:
YYDEBUG(98, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy124;
default: goto yy36;
}
yy99:
YYDEBUG(99, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy125;
default: goto yy36;
}
yy100:
YYDEBUG(100, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'P':
case 'p': goto yy126;
default: goto yy36;
}
yy101:
YYDEBUG(101, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy127;
default: goto yy36;
}
yy102:
YYDEBUG(102, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy129;
default: goto yy36;
}
yy103:
YYDEBUG(103, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy130;
default: goto yy36;
}
yy104:
YYDEBUG(104, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy69;
default: goto yy60;
}
yy105:
YYDEBUG(105, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy104;
default: goto yy60;
}
yy106:
YYDEBUG(106, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy104;
default: goto yy60;
}
yy107:
YYDEBUG(107, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy106;
default: goto yy60;
}
yy108:
YYDEBUG(108, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F:
case 0x90:
case 0x91:
case 0x92:
case 0x93:
case 0x94:
case 0x95:
case 0x96:
case 0x97:
case 0x98:
case 0x99:
case 0x9A:
case 0x9B:
case 0x9C:
case 0x9D:
case 0x9E:
case 0x9F:
case 0xA0:
case 0xA1:
case 0xA2:
case 0xA3:
case 0xA4:
case 0xA5:
case 0xA6:
case 0xA7:
case 0xA8:
case 0xA9:
case 0xAA:
case 0xAB:
case 0xAC:
case 0xAD:
case 0xAE:
case 0xAF:
case 0xB0:
case 0xB1:
case 0xB2:
case 0xB3:
case 0xB4:
case 0xB5:
case 0xB6:
case 0xB7:
case 0xB8:
case 0xB9:
case 0xBA:
case 0xBB:
case 0xBC:
case 0xBD:
case 0xBE:
case 0xBF: goto yy106;
default: goto yy60;
}
yy109:
YYDEBUG(109, YYPEEK ());
YYSKIP ();
yych = YYPEEK ();
switch (yych) {
case 0x80:
case 0x81:
case 0x82:
case 0x83:
case 0x84:
case 0x85:
case 0x86:
case 0x87:
case 0x88:
case 0x89:
case 0x8A:
case 0x8B:
case 0x8C:
case 0x8D:
case 0x8E:
case 0x8F: goto yy106;
default: goto yy60;
}
yy110:
YYDEBUG(110, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy131;
default: goto yy36;
}
yy111:
YYDEBUG(111, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy132;
default: goto yy36;
}
yy112:
YYDEBUG(112, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy133;
default: goto yy36;
}
yy113:
YYDEBUG(113, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'F':
case 'f': goto yy135;
default: goto yy36;
}
yy114:
YYDEBUG(114, YYPEEK ());
yyaccept = 6;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy115;
}
yy115:
YYDEBUG(115, YYPEEK ());
#line 208 "../gpr.re2c"
{*id = 8; continue;}
#line 3259 "../gpr_re2c.c"
yy116:
YYDEBUG(116, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy136;
default: goto yy36;
}
yy117:
YYDEBUG(117, YYPEEK ());
yyaccept = 7;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy118;
}
yy118:
YYDEBUG(118, YYPEEK ());
#line 212 "../gpr.re2c"
{*id = 12; continue;}
#line 3398 "../gpr_re2c.c"
yy119:
YYDEBUG(119, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy137;
default: goto yy36;
}
yy120:
YYDEBUG(120, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'L':
case 'l': goto yy138;
default: goto yy36;
}
yy121:
YYDEBUG(121, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy140;
default: goto yy36;
}
yy122:
YYDEBUG(122, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'K':
case 'k': goto yy141;
default: goto yy36;
}
yy123:
YYDEBUG(123, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'J':
case 'j': goto yy142;
default: goto yy36;
}
yy124:
YYDEBUG(124, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy143;
default: goto yy36;
}
yy125:
YYDEBUG(125, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy144;
default: goto yy36;
}
yy126:
YYDEBUG(126, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy145;
default: goto yy36;
}
yy127:
YYDEBUG(127, YYPEEK ());
yyaccept = 8;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy128;
}
yy128:
YYDEBUG(128, YYPEEK ());
#line 224 "../gpr.re2c"
{*id = 24; continue;}
#line 3614 "../gpr_re2c.c"
yy129:
YYDEBUG(129, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy147;
default: goto yy36;
}
yy130:
YYDEBUG(130, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'H':
case 'h': goto yy149;
default: goto yy36;
}
yy131:
YYDEBUG(131, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy151;
default: goto yy36;
}
yy132:
YYDEBUG(132, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy152;
default: goto yy36;
}
yy133:
YYDEBUG(133, YYPEEK ());
yyaccept = 9;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy134;
}
yy134:
YYDEBUG(134, YYPEEK ());
#line 206 "../gpr.re2c"
{*id = 6; continue;}
#line 3786 "../gpr_re2c.c"
yy135:
YYDEBUG(135, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'I':
case 'i': goto yy153;
default: goto yy36;
}
yy136:
YYDEBUG(136, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy154;
case 'R':
case 'r': goto yy155;
default: goto yy36;
}
yy137:
YYDEBUG(137, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy156;
default: goto yy36;
}
yy138:
YYDEBUG(138, YYPEEK ());
yyaccept = 10;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy139;
}
yy139:
YYDEBUG(139, YYPEEK ());
#line 216 "../gpr.re2c"
{*id = 16; continue;}
#line 3949 "../gpr_re2c.c"
yy140:
YYDEBUG(140, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy157;
default: goto yy36;
}
yy141:
YYDEBUG(141, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy158;
default: goto yy36;
}
yy142:
YYDEBUG(142, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy159;
default: goto yy36;
}
yy143:
YYDEBUG(143, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'M':
case 'm': goto yy160;
default: goto yy36;
}
yy144:
YYDEBUG(144, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'D':
case 'd': goto yy161;
default: goto yy36;
}
yy145:
YYDEBUG(145, YYPEEK ());
yyaccept = 11;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy146;
}
yy146:
YYDEBUG(146, YYPEEK ());
#line 223 "../gpr.re2c"
{*id = 23; continue;}
#line 4132 "../gpr_re2c.c"
yy147:
YYDEBUG(147, YYPEEK ());
yyaccept = 12;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy148;
}
yy148:
YYDEBUG(148, YYPEEK ());
#line 225 "../gpr.re2c"
{*id = 25; continue;}
#line 4260 "../gpr_re2c.c"
yy149:
YYDEBUG(149, YYPEEK ());
yyaccept = 13;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy150;
}
yy150:
YYDEBUG(150, YYPEEK ());
#line 226 "../gpr.re2c"
{*id = 26; continue;}
#line 4388 "../gpr_re2c.c"
yy151:
YYDEBUG(151, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy162;
default: goto yy36;
}
yy152:
YYDEBUG(152, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'G':
case 'g': goto yy163;
default: goto yy36;
}
yy153:
YYDEBUG(153, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'G':
case 'g': goto yy164;
default: goto yy36;
}
yy154:
YYDEBUG(154, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'D':
case 'd': goto yy165;
default: goto yy36;
}
yy155:
YYDEBUG(155, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy166;
default: goto yy36;
}
yy156:
YYDEBUG(156, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy167;
default: goto yy36;
}
yy157:
YYDEBUG(157, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy168;
default: goto yy36;
}
yy158:
YYDEBUG(158, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'G':
case 'g': goto yy170;
default: goto yy36;
}
yy159:
YYDEBUG(159, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'C':
case 'c': goto yy171;
default: goto yy36;
}
yy160:
YYDEBUG(160, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy172;
default: goto yy36;
}
yy161:
YYDEBUG(161, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy173;
default: goto yy36;
}
yy162:
YYDEBUG(162, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'C':
case 'c': goto yy174;
default: goto yy36;
}
yy163:
YYDEBUG(163, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy175;
default: goto yy36;
}
yy164:
YYDEBUG(164, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'U':
case 'u': goto yy176;
default: goto yy36;
}
yy165:
YYDEBUG(165, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy177;
default: goto yy36;
}
yy166:
YYDEBUG(166, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy179;
default: goto yy36;
}
yy167:
YYDEBUG(167, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'Y':
case 'y': goto yy180;
default: goto yy36;
}
yy168:
YYDEBUG(168, YYPEEK ());
yyaccept = 14;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy169;
}
yy169:
YYDEBUG(169, YYPEEK ());
#line 217 "../gpr.re2c"
{*id = 17; continue;}
#line 4703 "../gpr_re2c.c"
yy170:
YYDEBUG(170, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy182;
default: goto yy36;
}
yy171:
YYDEBUG(171, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy184;
default: goto yy36;
}
yy172:
YYDEBUG(172, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy186;
default: goto yy36;
}
yy173:
YYDEBUG(173, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy188;
default: goto yy36;
}
yy174:
YYDEBUG(174, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy189;
default: goto yy36;
}
yy175:
YYDEBUG(175, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy191;
default: goto yy36;
}
yy176:
YYDEBUG(176, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'R':
case 'r': goto yy192;
default: goto yy36;
}
yy177:
YYDEBUG(177, YYPEEK ());
yyaccept = 15;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy178;
}
yy178:
YYDEBUG(178, YYPEEK ());
#line 209 "../gpr.re2c"
{*id = 9; continue;}
#line 4908 "../gpr_re2c.c"
yy179:
YYDEBUG(179, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'L':
case 'l': goto yy193;
default: goto yy36;
}
yy180:
YYDEBUG(180, YYPEEK ());
yyaccept = 16;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy181;
}
yy181:
YYDEBUG(181, YYPEEK ());
#line 215 "../gpr.re2c"
{*id = 15; continue;}
#line 5047 "../gpr_re2c.c"
yy182:
YYDEBUG(182, YYPEEK ());
yyaccept = 17;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy183;
}
yy183:
YYDEBUG(183, YYPEEK ());
#line 218 "../gpr.re2c"
{*id = 18; continue;}
#line 5175 "../gpr_re2c.c"
yy184:
YYDEBUG(184, YYPEEK ());
yyaccept = 18;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy185;
}
yy185:
YYDEBUG(185, YYPEEK ());
#line 219 "../gpr.re2c"
{*id = 19; continue;}
#line 5303 "../gpr_re2c.c"
yy186:
YYDEBUG(186, YYPEEK ());
yyaccept = 19;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy187;
}
yy187:
YYDEBUG(187, YYPEEK ());
#line 220 "../gpr.re2c"
{*id = 20; continue;}
#line 5431 "../gpr_re2c.c"
yy188:
YYDEBUG(188, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'D':
case 'd': goto yy195;
default: goto yy36;
}
yy189:
YYDEBUG(189, YYPEEK ());
yyaccept = 20;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy190;
}
yy190:
YYDEBUG(190, YYPEEK ());
#line 203 "../gpr.re2c"
{*id = 3; continue;}
#line 5570 "../gpr_re2c.c"
yy191:
YYDEBUG(191, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'E':
case 'e': goto yy197;
default: goto yy36;
}
yy192:
YYDEBUG(192, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy199;
default: goto yy36;
}
yy193:
YYDEBUG(193, YYPEEK ());
yyaccept = 21;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
case '_': goto yy200;
default: goto yy194;
}
yy194:
YYDEBUG(194, YYPEEK ());
#line 210 "../gpr.re2c"
{*id = 10; continue;}
#line 5720 "../gpr_re2c.c"
yy195:
YYDEBUG(195, YYPEEK ());
yyaccept = 22;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy196;
}
yy196:
YYDEBUG(196, YYPEEK ());
#line 222 "../gpr.re2c"
{*id = 22; continue;}
#line 5848 "../gpr_re2c.c"
yy197:
YYDEBUG(197, YYPEEK ());
yyaccept = 23;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy198;
}
yy198:
YYDEBUG(198, YYPEEK ());
#line 205 "../gpr.re2c"
{*id = 5; continue;}
#line 5976 "../gpr_re2c.c"
yy199:
YYDEBUG(199, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy201;
default: goto yy36;
}
yy200:
YYDEBUG(200, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'A':
case 'a': goto yy202;
default: goto yy36;
}
yy201:
YYDEBUG(201, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'I':
case 'i': goto yy203;
default: goto yy36;
}
yy202:
YYDEBUG(202, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy204;
default: goto yy36;
}
yy203:
YYDEBUG(203, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'O':
case 'o': goto yy205;
default: goto yy36;
}
yy204:
YYDEBUG(204, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '_': goto yy206;
default: goto yy36;
}
yy205:
YYDEBUG(205, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'N':
case 'n': goto yy207;
default: goto yy36;
}
yy206:
YYDEBUG(206, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'L':
case 'l': goto yy209;
default: goto yy36;
}
yy207:
YYDEBUG(207, YYPEEK ());
yyaccept = 24;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy208;
}
yy208:
YYDEBUG(208, YYPEEK ());
#line 207 "../gpr.re2c"
{*id = 7; continue;}
#line 6191 "../gpr_re2c.c"
yy209:
YYDEBUG(209, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'I':
case 'i': goto yy210;
default: goto yy36;
}
yy210:
YYDEBUG(210, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'S':
case 's': goto yy211;
default: goto yy36;
}
yy211:
YYDEBUG(211, YYPEEK ());
yyaccept = 1;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case 'T':
case 't': goto yy212;
default: goto yy36;
}
yy212:
YYDEBUG(212, YYPEEK ());
yyaccept = 25;
YYSKIP ();
YYBACKUP ();
yych = YYPEEK ();
switch (yych) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case '_':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
case 0xC2:
case 0xC3:
case 0xC4:
case 0xC5:
case 0xC6:
case 0xC7:
case 0xC8:
case 0xC9:
case 0xCA:
case 0xCB:
case 0xCC:
case 0xCD:
case 0xCE:
case 0xCF:
case 0xD0:
case 0xD1:
case 0xD2:
case 0xD3:
case 0xD4:
case 0xD5:
case 0xD6:
case 0xD7:
case 0xD8:
case 0xD9:
case 0xDA:
case 0xDB:
case 0xDC:
case 0xDD:
case 0xDE:
case 0xDF:
case 0xE0:
case 0xE1:
case 0xE2:
case 0xE3:
case 0xE4:
case 0xE5:
case 0xE6:
case 0xE7:
case 0xE8:
case 0xE9:
case 0xEA:
case 0xEB:
case 0xEC:
case 0xED:
case 0xEE:
case 0xEF:
case 0xF0:
case 0xF1:
case 0xF2:
case 0xF3:
case 0xF4: goto yy36;
default: goto yy213;
}
yy213:
YYDEBUG(213, YYPEEK ());
#line 211 "../gpr.re2c"
{*id = 11; continue;}
#line 6352 "../gpr_re2c.c"
}
#line 242 "../gpr.re2c"
}
/* lexer->cursor and lexer ->char_pos are one char past end of token */
*byte_position = lexer->byte_token_start - lexer->buffer + 1;
*byte_length = lexer->cursor - lexer->byte_token_start;
*char_position = lexer->char_token_start;
*char_length = lexer->char_pos - lexer->char_token_start;
*line_start = lexer->line_token_start;
return status;
}
|
the_stack_data/77620.c | /* Side effects in while condition: slight change with respect t0 while08; no implicit condition
*/
#include <stdio.h>
int while08()
{
int i, n;
i = 0;
n = 10;
while(--n>0) {
printf("loop: i=%d, n=%d, i+n=%d\n", i, n, i+n);
i++;
}
printf("exit: i=%d, n=%d, i+n=%d\n", i, n, i+n);
return i;
}
main()
{
int i;
i = while08();
// If the returned value is ignored, PIPS fails:
// while08();
}
|
the_stack_data/50166.c | #include <stdio.h>
void __attribute__((__no_instrument_function__))
__cyg_profile_func_enter(void *this_func, void *call_site) {
fprintf(stderr, "e %p %p\n", this_func, call_site);
}
void __attribute__((__no_instrument_function__))
__cyg_profile_func_exit(void *this_func, void *call_site) {
// do nothing
}
void h(int v);
static
void g(int v) {
printf("g says: %d\n", v);
if (v)
g(--v);
}
void f(int v) {
for (int i = 0; i < v; i++) {
printf("f says: %d\n", i);
g(i);
}
h(v);
}
int main(void) {
f(3);
return 0;
}
|
the_stack_data/8061.c | /* this file contains the actual definitions of */
/* the IIDs and CLSIDs */
/* link this file in with the server and any clients */
/* File created by MIDL compiler version 5.01.0164 */
/* at Fri Dec 12 17:18:21 2008
*/
/* Compiler settings for D:\WorkDir1\CxDatAcs\CxDatAcs.idl:
Oicf (OptLev=i2), W1, Zp8, env=Win32, ms_ext, c_ext
error checks: allocation ref bounds_check enum stub_data
*/
//@@MIDL_FILE_HEADING( )
#ifdef __cplusplus
extern "C"{
#endif
#ifndef __IID_DEFINED__
#define __IID_DEFINED__
typedef struct _IID
{
unsigned long x;
unsigned short s1;
unsigned short s2;
unsigned char c[8];
} IID;
#endif // __IID_DEFINED__
#ifndef CLSID_DEFINED
#define CLSID_DEFINED
typedef IID CLSID;
#endif // CLSID_DEFINED
const IID IID_ICxMutiDataAccess = {0xA947C3CB,0x33C9,0x407c,{0xB7,0x52,0x55,0x1D,0x94,0x17,0xDC,0xF8}};
const IID IID_ICxDataAccess = {0x16D09780,0x1548,0x4D76,{0x85,0x8C,0xBB,0x6A,0xE1,0x4D,0xCA,0x29}};
const IID IID_ICxDataRecord = {0x7E956574,0xEBEB,0x4A98,{0xA9,0x33,0x0B,0xA1,0x81,0x0B,0x71,0xCD}};
const IID LIBID_CXDATACSLib = {0x511B285E,0x998E,0x4319,{0xB6,0xF9,0xA6,0x01,0x43,0x61,0x44,0xA7}};
#ifdef __cplusplus
}
#endif
|
the_stack_data/40763864.c | /**
* union example
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* Version 2, December 2004
*
* Copyright (C) 2020 Christian Visintin
* Everyone is permitted to copy and distribute verbatim or modified
* copies of this license document, and changing it is allowed as long
* as the name is changed.
*
* DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
* TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
*
* 0. You just DO WHAT THE FUCK YOU WANT TO.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#define MAX_DATA_SIZE 256
typedef enum Endianness {
ENDIANNESS_BIG_ENDIAN,
ENDIANNESS_LITTLE_ENDIAN
} Endianness;
typedef enum EventType {
EventInput,
EventOutput,
EventReset
} EventType;
// Since we need structs aligned to the buffer, we need to use packed structure (packing prevents compiler from doing padding)
typedef struct __attribute__((__packed__)) HeartBeatMessage {
uint8_t error_state;
} HeartBeatMessage;
typedef struct __attribute__((__packed__)) EventMessage {
uint8_t event_type;
uint16_t event_id;
uint32_t duration;
} EventMessage;
typedef union MessageData {
uint8_t buffer[MAX_DATA_SIZE];
HeartBeatMessage heartbeat;
EventMessage event;
} MessageData;
typedef enum MessageType {
Heartbeat,
Event
} MessageType;
typedef struct Message {
MessageType msg_type;
size_t data_size;
MessageData data;
} Message;
void print_message(const Message* message) {
for (size_t i = 0; i < message->data_size; i++) {
printf("%02x ", message->data.buffer[i]);
}
printf("\n");
switch (message->msg_type) {
case Heartbeat:
printf("Heartbeat - error_state: %u\n", message->data.heartbeat.error_state);
break;
case Event:
printf("Event - event_type %u; event_id %u; duration %lu\n", message->data.event.event_type, message->data.event.event_id, message->data.event.duration);
break;
}
}
int main(int argc, char** argv) {
// @! Union example
Message message;
// Buffer to struct
printf("Buffer to struct\n");
const uint16_t ev_id = 8134;
const uint32_t duration = 12481297;
uint8_t data[MAX_DATA_SIZE] = {0};
data[0] = 0x02; // Reset
data[2] = ev_id >> 8;
data[1] = ev_id & 0xFF;
data[6] = (duration >> 24) & 0xFF;
data[5] = (duration >> 16) & 0xFF;
data[4] = (duration >> 8) & 0xFF;
data[3] = duration & 0xFF;
// Set message data
message.msg_type = Event;
message.data_size = 7;
for (size_t i = 0; i < message.data_size; i++) {
message.data.buffer[i] = data[i];
}
print_message(&message);
// Reset message
printf("\n===================================================================\n\n");
memset(message.data.buffer, 0x00, MAX_DATA_SIZE);
message.data_size = 0;
// Struct to buffer
printf("Struct to buffer\n");
message.data.event.duration = 12481297;
message.data.event.event_id = 8134;
message.data.event.event_type = EventReset;
message.data_size = 7;
print_message(&message);
return 0;
}
|
the_stack_data/111078365.c | //
// main.c
// Exercise 2-4
//
// Created by Yilun Yang on 6/30/20.
// Copyright © 2020 Yilun Yang. All rights reserved.
//
#include <stdio.h>
#define MAX 100
void squeeze(char s[], char t[]);
int main(int argc, const char * argv[]) {
char s[MAX], t[MAX], c;
printf("Input a char set here:\n");
int i = 0;
while ((c = getchar()) != '\n') {
s[i++] = c;
}
s[i] = '\0';
printf("Input another char set here:\n");
i = 0;
while ((c = getchar()) != '\n') {
t[i++] = c;
}
t[i] = '\0';
printf("The first char set is:\n%s\n",s);
printf("The second char set is:\n%s\n",t);
squeeze(s, t);
printf("squeeze:\n%s\n",s);
return 0;
}
void squeeze(char s[], char t[])
{
int i = 0, j = 0, k = 0;
while (s[i] != '\0') {
j = 0;
int flag = 0;
while (t[j] != '\0') {
if (s[i] == t[j]) {
flag = 1;
}
j++;
}
if (flag == 0) {
s[k++] = s[i];
}
i++;
}
s[k] = '\0';
}
|
the_stack_data/31386892.c | /* $OpenBSD: aa.c,v 1.2 2015/01/20 04:41:01 krw Exp $ */
/* the point of this library is to not define function ad() */
ad_notdefine()
{
}
/*
* libglobal is not defined by this library
* int libglobal;
*/
|
the_stack_data/146613.c | /* Code from Head First C.
Modified by Allen Downey.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
int listener_d = 0;
/* Print an error message and exit.
*/
void error(char *msg) {
fprintf(stderr, "%s: %s\n", msg, strerror(errno));
exit(1);
}
/* Set up the signal catcher.
*/
int catch_signal(int sig, void (*handler)(int)) {
struct sigaction action;
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
return sigaction(sig, &action, NULL);
}
/* Signal handler for SHUTDOWN
*/
void handle_shutdown(int sig) {
if (listener_d)
close(listener_d);
fprintf(stderr, "Bye!\n");
exit(EXIT_SUCCESS);
}
/* Create the listener socket.
*/
int open_listener_socket(void) {
int s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1)
error("Can't open listener socket");
return s;
}
/* Wait for clients to connect.
*/
int open_client_socket(void) {
static struct sockaddr_storage client_address;
static unsigned int address_size = sizeof(client_address);
int s;
if ((s = accept(listener_d, (struct sockaddr *)&client_address,
&address_size)) == -1)
error("Can't open client socket");
return s;
}
/* Bind the socket to a port.
*/
void bind_to_port(int socket, int port) {
struct sockaddr_in name;
name.sin_family = PF_INET;
name.sin_port = (in_port_t)htons(port);
name.sin_addr.s_addr = htonl(INADDR_ANY);
int reuse = 1;
int res = setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&reuse, sizeof(int));
if (res == -1)
error("Can't set the 'reuse' option on the socket");
res = bind(socket, (struct sockaddr *)&name, sizeof(name));
if (res == -1)
error("Can't bind to socket");
}
/* Send to the client.
*/
int say(int socket, char *s)
{
s[0] = 'f'; //Yup, the host stays running!
int res = send(socket, s, strlen(s), 0);
if (res == -1)
error("Error talking to the client");
return res;
}
/* Read from the client.
Returns: number of characters read.
*/
int read_in(int socket, char *buf, int len)
{
/* treat the socket stream as a regular IO stream,
so we can do character IO */
FILE *fp = fdopen(socket, "r");
int i = 0, ch;
/* eat any leading whitespace */
while (isspace(ch = fgetc(fp)) && ch != EOF) {
// do nothing
}
if (ferror(fp))
error("fgetc");
while (ch != '\n' && ch != EOF) {
if (i < len)
buf[i++] = ch;
ch = fgetc(fp);
}
if (ferror(fp))
error("fgetc");
/* terminate the string, eating any trailing whitespace */
while (isspace(buf[--i])) {
buf[i] = '\0';
}
return strlen(buf);
}
char intro_msg[] = "Internet Knock-Knock Protocol Server\nKnock, knock.\n";
int main(int argc, char *argv[])
{
char buf[255];
// set up the signal handler
if (catch_signal(SIGINT, handle_shutdown) == -1)
error("Setting interrupt handler");
// create the listening socket
int port = 28000;
listener_d = open_listener_socket();
bind_to_port(listener_d, port);
if (listen(listener_d, 10) == -1)
error("Can't listen");
while (1) {
printf("Waiting for connection on port %d\n", port);
int connect_d = open_client_socket();
if (!fork()) {
if (say(connect_d, intro_msg) == -1) {
close(connect_d);
continue;
}
read_in(connect_d, buf, sizeof(buf));
// TODO (optional): check to make sure they said "Who's there?"
if (say(connect_d, "Surrealist giraffe.\n") == -1) {
close(connect_d);
continue;
}
read_in(connect_d, buf, sizeof(buf));
// TODO (optional): check to make sure they said "Surrealist giraffe who?"
if (say(connect_d, "Bathtub full of brightly-colored machine tools.\n") == -1) {
close(connect_d);
continue;
}
close(connect_d);
exit(0);
}
close(connect_d);
}
return 0;
}
|
the_stack_data/175142169.c | #include<stdio.h>
int main()
{
int m;
scanf("%d",&m);
if(m==1)
printf("January\n");
if(m==2)
printf("February\n");
if(m==3)
printf("March\n");
if(m==4)
printf("April\n");
if(m==5)
printf("May\n");
if(m==6)
printf("June\n");
if(m==7)
printf("July\n");
if(m==8)
printf("August\n");
if(m==9)
printf("September\n");
if(m==10)
printf("October\n");
if(m==11)
printf("November\n");
if(m==12)
printf("December\n");
return 0;
}
|
the_stack_data/20451616.c | // RUN: %clang -target mipsel-unknown-linux -ccc-clang-archs mipsel -O3 -S -o - -emit-llvm %s | FileCheck %s -check-prefix=O32
// RUN: %clang -target mips64el-unknown-linux -ccc-clang-archs mips64el -O3 -S -mabi=n64 -o - -emit-llvm %s | FileCheck %s -check-prefix=N64
typedef struct {
float f[3];
} S0;
extern void foo2(S0);
// O32: define void @foo1(i32 %a0.coerce0, i32 %a0.coerce1, i32 %a0.coerce2)
// N64: define void @foo1(i64 %a0.coerce0, i32 %a0.coerce1)
void foo1(S0 a0) {
foo2(a0);
}
|
the_stack_data/349945.c | #include <stdio.h>
#include <stdlib.h>
#define N 32
#define REAL float
#define OFFSET(x, y, z) ((x) + (y) * N + (z) * N * N)
void kernel(float *g1, float *g2) {
int x, y, z;
int halo_width = 2;
for (z = halo_width; z < N-halo_width; ++z) {
for (y = halo_width; y < N-halo_width; ++y) {
for (x = halo_width; x < N-halo_width; ++x) {
float v = g1[OFFSET(x, y, z)] +
g1[OFFSET(x-1, y, z)] +
g1[OFFSET(((x+2)+N)%N, y, z)];
g2[OFFSET(x, y, z)] = v;
}
}
}
return;
}
void dump(float *input) {
int i;
for (i = 0; i < N*N*N; ++i) {
printf("%f\n", input[i]);
}
}
int main(int argc, char *argv[]) {
REAL *g1, *g2;
size_t nelms = N*N*N;
g1 = (REAL *)malloc(sizeof(REAL) * nelms);
g2 = (REAL *)malloc(sizeof(REAL) * nelms);
int i;
for (i = 0; i < (int)nelms; i++) {
g1[i] = i;
g2[i] = i;
}
kernel(g1, g2);
dump(g2);
free(g1);
free(g2);
return 0;
}
|
the_stack_data/248582044.c | #include <stdlib.h>
#include <stdio.h>
extern void rust_capitalize(char *);
int main() {
char str[] = "hello world";
rust_capitalize(str);
printf("%s\n",str);
return 0;
} |
the_stack_data/178265696.c |
//C Program to Count the number of ways to tile the floor of
//size n x m using 1 x m size tiles
int main(){
int t,i,m,n,count[100001];
//number of inputs
scanf("%d",&t);
while(t--){
//accepting the inputs
scanf("%d %d",&n,&m);
count[0]=0;
for(i=1;i<=n;i++){
//if i<m then store ! in count
if(i<m)
count[i]=1;
else if(i>m)
{
//if i>m then modulus with 1000000007
count[i]=count[i-1]+count[i-m];
count[i]%=1000000007;
}
else count[i]=2;
}
//print the result
printf("%d\n",count[n]);
}
return 0;
}
|
the_stack_data/181394037.c | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define MAX 10000000
int fact(int n) {
int ret = 1;
for (int i = 1; i <= n; i++) {
ret = ret * i;
}
return ret;
}
int main(void) {
int sum, n, d;
int ans = 0;
int factorials[10];
for (int i = 0; i < 10; i++) {
factorials[i] = fact(i);
}
for (int i = 3; i < 2540161; i++) {
sum = 0; n = i;
while (n > 0) {
d = n % 10; n /= 10;
sum += factorials[d];
}
if (sum == i) {
ans += i;
}
}
printf("%d\n", ans);
}
|
the_stack_data/89199211.c | // Jordan Lewis ([email protected])
// March 12 2017
// Reads an positive integer n and the prints the cubes of the integers from 1 to n
#include <stdio.h>
#include <math.h>
int get_input(char *prompt, int *x) {
printf("%s", prompt);
if (scanf("%d", x) == 0) {
printf("Value entered was not an integer.\n");
return 0;
}
return 1;
}
int main () {
int num;
if (get_input("Enter how many cubes: ", &num) == 0) {
return 1;
}
for (int i = 1; i <= num; i++) {
int cube = (int)pow((double)i,3);
printf("%d^3 = %d\n", i, cube);
}
return 0;
}
|
the_stack_data/86076633.c | #include <stdio.h>
int main (void){
int valor[2000];
int n, x, maior=0;
scanf("%d", &n);
for(x=0;x<2000;x++)
valor[x] = 0;
while(n>=1){
scanf("%d", &x);
if(x>maior)
maior = x;
valor[x-1]++;
n--;
}
for(n=0;n<=maior;n++)
if(valor[n] >= 1)
printf("%d aparece %d vez(es)\n", n+1,valor[n]);
return 0;
}
|
the_stack_data/959861.c | void test() {
int a = 0;
int i = 0;
while (i <= 100)
a = a + i++;
expecti(a, 5050);
a = 5;
i = 0;
while (i <= 100) {
a = a + i++;
}
expecti(a, 5055);
}
int main() {
init("while loop");
test();
return ok();
}
|
the_stack_data/198579776.c | /* This program reads a test score, calculates the letter
grade for the score, and prints the grade.
Written by: Park Beom Soon
Date: 2019. 05. 20
*/
#include <stdio.h>
// Function Declaration
char scoreToGrade(int number);
char addition(int number);
int main(void)
{
// Local Declaration
int score;
char grade;
char zeroone;
// Statement
printf("Enter your test score: ");
scanf_s("%d", &score);
grade = scoreToGrade(score);
zeroone = addition(score);
printf("The grade is: %c%c\n", grade, zeroone);
system("pause");
return 0;
} // Main Function
// Function scoreToGrade
char scoreToGrade(int score)
{
int testscore;
char grade;
testscore = score / 10;
switch (testscore)
{
case 10:
case 9: grade = 'A';
break;
case 8: grade = 'B';
break;
case 7: grade = 'C';
break;
case 6: grade = 'D';
break;
default: grade = 'F';
} // switch
return grade;
}
// Function zeroone
char addition(int score)
{
// Local Declaration
int zeroone;
char pluszero;
int score2;
// Statement
zeroone = score % 10;
score2 = score / 10;
switch (zeroone)
{
case 0:
case 1:
case 2:
case 3:
case 4:
pluszero = '0';
break;
default:
pluszero = '+';
}
switch (score) case 100: pluszero = '+';
switch (scoreToGrade(score)) case 'F': pluszero = ' ';
return pluszero;
} |
the_stack_data/59512416.c | /*C program to check whether matrix is symmetric or not*/
#include<stdio.h>
int main()
{
int m,i,j,flag=0; //Declaration
printf("Enter no. of rows:\n");
scanf("%d",&m); //input rows and columns
int a[m][m],b[m][m];
printf("Enter elements of Matrix:\n");
for(i=0;i<m;i++)
{
for(j=0;j<m;j++) //input elements of matrix
{
printf("a%d%d=",i+1,j+1);
scanf("%d",&a[i][j]);
}
}
printf("Given Matirx:-\n"); //printing given matrix
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
printf(" %d",a[i][j]);
}
printf("\n");
}
for(i=0;i<m;i++) //Transpose matrix
{
for(j=0;j<m;j++)
{
b[j][i]=a[i][j];
}
}
for(i=0;i<m;i++) //Checking
{
for(j=0;j<m;j++)
{
if(a[i][j]!=b[i][j])
{
flag=1;
break;
}
}
if(flag==1)
break;
}
if(flag==0)
printf("\nMatrix is Symmetric\n"); //Output
else
printf("\nMatrix is not Symmetric\n");
return 0;
} //End of program
|
the_stack_data/43886894.c | /*
* Copyright © 2009 CNRS
* Copyright © 2009-2017 Inria. All rights reserved.
* Copyright © 2009 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
*/
#include <hwloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
/* check that object userdata is properly initialized */
static void check_level(hwloc_topology_t topology, unsigned depth, unsigned width, unsigned arity)
{
unsigned j;
assert(hwloc_get_nbobjs_by_depth(topology, depth) == width);
for(j=0; j<width; j++) {
hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, j);
assert(obj);
assert(obj->arity == arity);
}
}
int main(void)
{
hwloc_topology_t topology;
unsigned depth;
char buffer[1024];
int err;
/* check a synthetic topology */
hwloc_topology_init(&topology);
err = hwloc_topology_set_synthetic(topology, "pack:2 numa:3 l2:4 core:5 pu:6");
assert(!err);
hwloc_topology_load(topology);
/* internal checks */
hwloc_topology_check(topology);
/* local checks */
depth = hwloc_topology_get_depth(topology);
assert(depth == 6);
check_level(topology, 0, 1, 2);
check_level(topology, 1, 2, 3);
check_level(topology, 2, 6, 4);
check_level(topology, 3, 24, 5);
check_level(topology, 4, 120, 6);
check_level(topology, 5, 720, 0);
check_level(topology, HWLOC_TYPE_DEPTH_NUMANODE, 6, 0);
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0);
assert(err == 53);
err = strcmp("Package:2 Group:3 L2Cache:4(size=4194304) Core:5 PU:6", buffer);
// FIXME NUMANode
assert(!err);
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES|HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS);
assert(err == 39);
err = strcmp("Package:2 Group:3 L2Cache:4 Core:5 PU:6", buffer);
// FIXME NUMANode
assert(!err);
hwloc_topology_destroy(topology);
hwloc_topology_init(&topology);
err = hwloc_topology_set_type_filter(topology, HWLOC_OBJ_L1ICACHE, HWLOC_TYPE_FILTER_KEEP_ALL);
err = hwloc_topology_set_synthetic(topology, "pack:2(indexes=3,5) numa:2(memory=256GB indexes=pack) l3u:1(size=20mb) l2:2 l1i:1(size=16kB) l1dcache:2 core:1 pu:2(indexes=l2)");
assert(!err);
hwloc_topology_load(topology);
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0);
assert(err == 133);
err = strcmp("Package:2 L3Cache:2(size=20971520) L2Cache:2(size=4194304) L1iCache:1(size=16384) L1dCache:2(size=32768) Core:1 PU:2(indexes=4*8:1*4)", buffer);
// FIXME NUMANode
assert(!err);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 1)->os_index == 5);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1)->os_index == 2);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 12)->os_index == 3);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 13)->os_index == 11);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 14)->os_index == 19);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 15)->os_index == 27);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 16)->os_index == 4);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 17)->os_index == 12);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 18)->os_index == 20);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 19)->os_index == 28);
hwloc_topology_destroy(topology);
hwloc_topology_init(&topology);
err = hwloc_topology_set_synthetic(topology, "pack:2 core:2 pu:2(indexes=0,4,2,6,1,5,3,7)");
assert(!err);
hwloc_topology_load(topology);
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0);
assert(err == 42);
err = strcmp("Package:2 Core:2 PU:2(indexes=4*2:2*2:1*2)", buffer);
// FIXME NUMANode
assert(!err);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0)->os_index == 0);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 1)->os_index == 4);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 2)->os_index == 2);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 3)->os_index == 6);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 4)->os_index == 1);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 5)->os_index == 5);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 6)->os_index == 3);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 7)->os_index == 7);
hwloc_topology_destroy(topology);
hwloc_topology_init(&topology);
err = hwloc_topology_set_synthetic(topology, "pack:2 numa:2 core:1 pu:2(indexes=0,4,2,6,1,3,5,7)");
assert(!err);
hwloc_topology_load(topology);
err = hwloc_topology_export_synthetic(topology, buffer, sizeof(buffer), 0);
assert(err == 46);
err = strcmp("Package:2 Core:2 PU:2(indexes=0,4,2,6,1,3,5,7)", buffer);
// FIXME NUMANode
assert(!err);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0)->os_index == 0);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 1)->os_index == 4);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 2)->os_index == 2);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 3)->os_index == 6);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 4)->os_index == 1);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 5)->os_index == 3);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 6)->os_index == 5);
assert(hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 7)->os_index == 7);
hwloc_topology_destroy(topology);
return 0;
}
|
the_stack_data/220455814.c | /*
İki Sayı Arasındaki Tam Sayıları Yazdırma
Program to print integers in a given range using recursion
// Özyinelemeli Fonksiyon (Recursive Function)
*/
#include <stdio.h>
#include <locale.h>
int fonk(int sayi1,int sayi2)
{
if (sayi2 >= sayi1)
{
printf("%d ", sayi1);
fonk(sayi1 + 1, sayi2);
}
else
return 0;
}
int main()
{
setlocale(LC_ALL, "Turkish");
int sayi1, sayi2;
printf("Lütfen bir tam sayı giriniz (AltSınır): ");
scanf("%d", &sayi1);
printf("\nLütfen bir tam sayı giriniz (Üst Sınır): ");
scanf("%d", &sayi2);
printf("\n%d ve %d arasındaki tam sayılar: \n", sayi1, sayi2);
printf("\n");
fonk(sayi1, sayi2);
return 0;
}
|
the_stack_data/115480.c | #include <unistd.h>
int main() {
char *argv[] = {"ls", "-l", "-h", "-a", NULL};
execvp(argv[0], argv);
return 0;
}
|
the_stack_data/64200614.c | //1207
#include <stdio.h>
//Find the cycle length of integer n
int findCycleLength(int n);
//Find the maximum cycle-length for integers between and including i and j
int findMaxCycleLength(int i, int j);
int main()
{
int i,j;
do{
scanf("%d %d",&i,&j);
printf("%d %d %d\n",i,j,findMaxCycleLength(i,j));
}while(1);//while(!(i == 1&& j == 1));
return 0;
}
int findCycleLength(int n)
{
int count = 1;//the cycle-length
while(n != 1)
{
if(n%2 == 1)
n = 3*n+1;
else
n = n/2;
count++;
}
return count;
}
int findMaxCycleLength(int i, int j)
{
int maxCycleLength = 0;//the maximum cycle-length
int temCycleLength = 0;//the temporary cycle-length
int curNumber = i;//the current number
if(i > j)
{
curNumber = j;
j = i;
}
for(curNumber;curNumber < j+1; curNumber++)
{
temCycleLength = findCycleLength(curNumber);
if(maxCycleLength < temCycleLength)
maxCycleLength = temCycleLength;
}
return maxCycleLength;
} |
the_stack_data/132953777.c | /*
* queue_sender.c - a program that reads messages with one of 3 identifiers
* to a message queue.
*/
#include <stdio.h> /* standard I/O functions. */
#include <stdlib.h> /* malloc(), free() etc. */
#include <string.h>
#include <sys/types.h> /* various type definitions. */
#include <sys/ipc.h> /* general SysV IPC structures */
#include <sys/msg.h> /* message queue functions and structs. */
#define MAX_MSG_SIZE 100
#define NUM_MESSAGES 3
//#include "queue_defs.h" /* definitions shared by both programs */
struct msgbuf {
long mtype; /* message type, must be > 0 */
char mtext[1]; /* message data */
};
int main(int argc, char* argv[])
{
int queue_id; /* ID of the created queue. */
struct msgbuf* msg; /* structure used for sent messages. */
/*struct msgbuf* recv_msg;*/
int i; /* loop counter */
int rc; /* error code retuend by system calls. */
/* create a public message queue, with access only to the owning user. */
queue_id = msgget(250, IPC_CREAT | IPC_EXCL | 0600);
if (queue_id == -1) {
perror("main: msgget");
exit(1);
}
printf("message queue created, queue id '%d'.\n", queue_id);
msg = (struct msgbuf*)malloc(sizeof(msg)+1+MAX_MSG_SIZE);
/* form a loop of creating messages and sending them. */
for (i=1; i <= NUM_MESSAGES; i++) {
msg->mtype = (i % 3) + 1; /* create message type between '1' and '3' */
sprintf(msg->mtext, "hello world - %d", i);
rc = msgsnd(queue_id, msg, strlen(msg->mtext)+1, 0);
if (rc == -1) {
perror("main: msgsnd");
exit(1);
}
}
/* free allocated memory. */
free(msg);
printf("generated %d messages, exiting.\n", NUM_MESSAGES);
return 0;
}
|
the_stack_data/40761537.c | /*
4 - Faça um programa que receba três números e mostre o maior
*/
#include <stdio.h>
int main() {
float numero1 = 0.0, numero2 = 0.0, numero3 = 0.0;
printf("Primeiro numero: ");
scanf("%f", &numero1);
printf("Segundo numero: ");
scanf("%f", &numero2);
printf("Terceiro numero: ");
scanf("%f", &numero3);
if (numero1 > numero2 && numero1 > numero3) {
printf("O %.2f e maior que os demais!\n", numero1);
} else if (numero2 > numero1 && numero2 > numero3) {
printf("O %.2f é maior que os demias!\n", numero2);
} else if (numero3 > numero1 && numero3 > numero2) {
printf("O %.2f é maior que os demais!\n", numero3);
}
return 1;
} |
the_stack_data/200144311.c | /*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 1996,2008 Oracle. All rights reserved.
*
* $Id: ex_env.c 63573 2008-05-23 21:43:21Z trent.nelson $
*/
#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <db.h>
#ifdef macintosh
#define DATABASE_HOME ":database"
#define CONFIG_DATA_DIR ":database"
#else
#ifdef DB_WIN32
#define DATABASE_HOME "\\tmp\\database"
#define CONFIG_DATA_DIR "\\database\\files"
#else
#define DATABASE_HOME "/tmp/database"
#define CONFIG_DATA_DIR "/database/files"
#endif
#endif
int db_setup __P((const char *, const char *, FILE *, const char *));
int db_teardown __P((const char *, const char *, FILE *, const char *));
int main __P((void));
/*
* An example of a program creating/configuring a Berkeley DB environment.
*/
int
main()
{
const char *data_dir, *home;
const char *progname = "ex_env"; /* Program name. */
/*
* All of the shared database files live in DATABASE_HOME, but
* data files will live in CONFIG_DATA_DIR.
*/
home = DATABASE_HOME;
data_dir = CONFIG_DATA_DIR;
printf("Setup env\n");
if (db_setup(home, data_dir, stderr, progname) != 0)
return (EXIT_FAILURE);
printf("Teardown env\n");
if (db_teardown(home, data_dir, stderr, progname) != 0)
return (EXIT_FAILURE);
return (EXIT_SUCCESS);
}
int
db_setup(home, data_dir, errfp, progname)
const char *home, *data_dir, *progname;
FILE *errfp;
{
DB_ENV *dbenv;
int ret;
/*
* Create an environment object and initialize it for error
* reporting.
*/
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(errfp, "%s: %s\n", progname, db_strerror(ret));
return (1);
}
dbenv->set_errfile(dbenv, errfp);
dbenv->set_errpfx(dbenv, progname);
/*
* We want to specify the shared memory buffer pool cachesize,
* but everything else is the default.
*/
if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0) {
dbenv->err(dbenv, ret, "set_cachesize");
dbenv->close(dbenv, 0);
return (1);
}
/* Databases are in a subdirectory. */
(void)dbenv->set_data_dir(dbenv, data_dir);
/* Open the environment with full transactional support. */
if ((ret = dbenv->open(dbenv, home,
DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN,
0)) != 0) {
dbenv->err(dbenv, ret, "environment open: %s", home);
dbenv->close(dbenv, 0);
return (1);
}
/* Do something interesting... */
/* Close the handle. */
if ((ret = dbenv->close(dbenv, 0)) != 0) {
fprintf(stderr, "DB_ENV->close: %s\n", db_strerror(ret));
return (1);
}
return (0);
}
int
db_teardown(home, data_dir, errfp, progname)
const char *home, *data_dir, *progname;
FILE *errfp;
{
DB_ENV *dbenv;
int ret;
/* Remove the shared database regions. */
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(errfp, "%s: %s\n", progname, db_strerror(ret));
return (1);
}
dbenv->set_errfile(dbenv, errfp);
dbenv->set_errpfx(dbenv, progname);
(void)dbenv->set_data_dir(dbenv, data_dir);
if ((ret = dbenv->remove(dbenv, home, 0)) != 0) {
fprintf(stderr, "DB_ENV->remove: %s\n", db_strerror(ret));
return (1);
}
return (0);
}
|
the_stack_data/87637212.c | #include <stdio.h>
typedef struct Data{
int dia;
int mes;
int ano;
} Date;
typedef struct aluno{
int matr;
Date dn;
}aln;
int main(){
Date dt[5],dth;
aln al[5];
int i,j;
for(i=0;i<5;i++){
printf("Informe A Matricula do Aluno: ");
scanf("%d",&al[i].matr);
printf("Informe o dia de Nasc: ");
scanf("%d",&al[i].dn.dia);
printf("Informe o mes de Nasc: ");
scanf("%d",&al[i].dn.mes);
printf("Informe o ano de Nasc: ");
scanf("%d",&al[i].dn.ano);
}
printf("Informe o Dia Atual: ");
scanf("%d",&dth.dia);
printf("Informe o Mes Atual: ");
scanf("%d",&dth.mes);
printf("Informe o Ano Atual: ");
scanf("%d",&dth.ano);
for(i=0,j=0;i<5;i++){
if(dth.mes==al[i].dn.mes){
dt[j].dia = al[i].dn.dia;
dt[j].mes = al[i].dn.mes;
dt[j].ano = al[i].dn.ano;
j++;
}
}
for(i=0;i<j;i++){
printf("%d/%d/%d\n",dt[i].dia,dt[i].mes,dt[i].ano);
}
return 0;
}
|
the_stack_data/114708.c | #include <stdio.h>
void mystrncpy(char *s, char *t, int n);
void mystrncat(char *s, char *t, int n);
int mystrncmp(char *s, char *t, int n);
int main(int argc, char *argv[])
{
char s1[] = "hello";
char t1[] = "world";
char s2[100] = "hello, ";
char t2[] = "world!";
char s3[] = "java";
char t3[] = "javascript";
int n = 3;
int result;
mystrncpy(s1, t1, n);
printf("results: %s\n", s1);
mystrncat(s2, t2, n);
printf("result: %s\n", s2);
result = mystrncmp(s3, t3, n);
printf("result: %d\n", result);
result = mystrncmp(s3, t3, 5);
printf("result: %d\n", result);
result = mystrncmp(t3, s3, 5);
printf("result: %d\n", result);
}
void mystrncpy(char *s, char *t, int n)
{
int i;
i = 0;
while (i < n && *t != '\0')
{
*s++ = *t++;
i++;
}
}
void mystrncat(char *s, char *t, int n)
{
int i;
i = 0;
while (*s != '\0')
{
*s++;
}
while (i < n && *t != '\0')
{
*s++ = *t++;
i++;
}
}
int mystrncmp(char *s, char *t, int n)
{
int i;
for (i = 0; i < n && *s == *t; s++, t++)
{
i++;
}
return *s - *t;
}
|
the_stack_data/6388062.c | #include<stdio.h>
#include<math.h>
#define PIE 3.14
void main()
{
double d,a,p;
d = sqrt(pow((5 - 2),2) + (pow((6 - 2),2)));//centre of circle = 0,0. point on circumference = 4,5.
a = PIE * d * d/4;
p = PIE * d;
printf("The area of the circle is %lf and perimeter is %lf\n",a,p);
} |
the_stack_data/159515542.c | /* stpcpy example.
Copyright (C) 1991-2012 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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, if not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <stdio.h>
int
main (void)
{
char buffer[10];
char *to = buffer;
to = stpcpy (to, "foo");
to = stpcpy (to, "bar");
puts (buffer);
return 0;
}
|
the_stack_data/243891917.c | double cross_entropy(const double **a, const double **b){
double loss = 0;
for(int i=0; i<2; i++){
for(int j=0; j<2; j++ ){
for(int k=0;k<1;k++){
loss = loss - (b[i][j] * log(a[i][j] + 0.00001));
}
}
}
return loss;
} |
the_stack_data/6387074.c | /*
So in this problem you must implement 6 seperate functions. The
first 4 are pretty easy to understand:
void lockA();
void lockB();
void unlockA();
void unlockB();
Basically A and B can be thought of as two independent mutexes. If
you call lockA() and some other thread has already locked A, lockA
will be stuck and will not return until the thread with A locked
calls unlockA(). lockB and unlockB act the same way. The lock
state of B has no effect on A and vice versa.
I say A and B can be "thought of as two independent mutexes" rather
than "are 2 mutexes" because you can implement these functions in
any way you wish, as long as you provide the normal guarentees. So
you can have 1 underlying mutex and just some condition variables -
or whatever.
You can also assume that no single thread will ever attempt to
aquire both "mutexes" at once:
lockA();
lockB(); // undefined behavior! Not allowed
If you wish, you can implement your lockA/lockB to error if someone
attempts this, but you can also just assume that this rule will not
be broken. Note that this rule applies to callers of your
lock/unlock functions - you can do whatever you wish, so long as you
behave correctly whenever the lock/unlock functions are called in a
legal way.
The two other functions you must implement are:
swapAB();
swapBA();
So the swap function allows the caller to exchange one "mutex" for
another. For example, you call swapAB() when your thread has mutexA
and when the function returns your thread will have released A but
will have aquired B. The key requirement of the swapAB is this:
there should never be a time when the caller of swapAB has already
released A but has not yet aquired B. Put another way, if B is not
available the function will wait for B holding A and not "swap"
until it is guarenteed to get B.
It is possible that 2 threads both want to swap (e.g. thread 1 is
trying to swapAB and is waiting because B is claimed, but then
thread 2 which has B executes a swapBA). In that case the swap
should happen conceptually "at the same time": both the swap
functions can return, and neither of the mutexes should ever be in
an available state where they could be stolen by a thread attempting
a lockA or lockB.
One thing to note and always remember is that the thread the locks a mutex lock
should be the one that unlocks it. Attempting to unlock another thread's mutex
lock results in undefined behavior. This problem can be circumvented by using a
semaphore, which you are not allowed to use in this problem.
*/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
int swap_mode = 0;
void lockA() {
}
void lockB() {
}
void unlockA() {
}
void unlockB() {
}
void swapAB() {
}
void swapBA() {
}
void assert_i_have_a() {
static int a_count = 0;
// my use of a_count in this function could
// theoretically be considered unprotected
// but only if more than 1 thread has a
if(a_count != 0) {
printf("ERROR multiple threads seem to have gotten A\n");
}
a_count++;
usleep(20);
if(a_count != 1) {
printf("ERROR multiple threads seem to have gotten A\n");
}
a_count--;
}
void assert_i_have_b() {
static int b_count = 0;
if(b_count != 0) {
printf("ERROR multiple threads seem to have gotten B\n");
}
b_count++;
usleep(5);
if(b_count != 1) {
printf("ERROR multiple threads seem to have gotten B\n");
}
b_count--;
}
void swapper() {
for(int i = 0; i < 10; i++) {
lockA();
assert_i_have_a();
unlockA();
lockB();
assert_i_have_b();
unlockB();
lockA();
assert_i_have_a();
swapAB();
assert_i_have_b();
swapBA();
assert_i_have_a();
unlockA();
}
}
int main(int argc, char **argv) {
pthread_t threads[10];
for(int i = 0; i < 10; i++) {
pthread_create(&threads[i], NULL, (void * (*)(void *)) swapper, NULL);
}
for(int i = 0; i < 10; i++) {
pthread_join(threads[i], NULL);
}
printf("Everything done.\n");
}
|
the_stack_data/454247.c | #include <stdio.h>
int main() {
int ret = 0;
int i;
for ( i = 0; i <= 999; i++ ) {
if ( (i%3 == 0) || (i%5 == 0) )
ret += i;
}
printf("%i\n", ret);
return 0;
}
|
the_stack_data/3261834.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 SLARNV returns a vector of random numbers from a uniform or normal distribution. */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download SLARNV + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarnv.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarnv.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarnv.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE SLARNV( IDIST, ISEED, N, X ) */
/* INTEGER IDIST, N */
/* INTEGER ISEED( 4 ) */
/* REAL X( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SLARNV returns a vector of n random real numbers from a uniform or */
/* > normal distribution. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] IDIST */
/* > \verbatim */
/* > IDIST is INTEGER */
/* > Specifies the distribution of the random numbers: */
/* > = 1: uniform (0,1) */
/* > = 2: uniform (-1,1) */
/* > = 3: normal (0,1) */
/* > \endverbatim */
/* > */
/* > \param[in,out] ISEED */
/* > \verbatim */
/* > ISEED is INTEGER array, dimension (4) */
/* > On entry, the seed of the random number generator; the array */
/* > elements must be between 0 and 4095, and ISEED(4) must be */
/* > odd. */
/* > On exit, the seed is updated. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of random numbers to be generated. */
/* > \endverbatim */
/* > */
/* > \param[out] X */
/* > \verbatim */
/* > X is REAL array, dimension (N) */
/* > The generated random numbers. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup OTHERauxiliary */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > This routine calls the auxiliary routine SLARUV to generate random */
/* > real numbers from a uniform (0,1) distribution, in batches of up to */
/* > 128 using vectorisable code. The Box-Muller method is used to */
/* > transform numbers from a uniform to a normal distribution. */
/* > \endverbatim */
/* > */
/* ===================================================================== */
/* Subroutine */ int slarnv_(integer *idist, integer *iseed, integer *n, real
*x)
{
/* System generated locals */
integer i__1, i__2, i__3;
/* Local variables */
integer i__;
real u[128];
integer il, iv, il2;
extern /* Subroutine */ int slaruv_(integer *, integer *, real *);
/* -- 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;
--iseed;
/* Function Body */
i__1 = *n;
for (iv = 1; iv <= i__1; iv += 64) {
/* Computing MIN */
i__2 = 64, i__3 = *n - iv + 1;
il = f2cmin(i__2,i__3);
if (*idist == 3) {
il2 = il << 1;
} else {
il2 = il;
}
/* Call SLARUV to generate IL2 numbers from a uniform (0,1) */
/* distribution (IL2 <= LV) */
slaruv_(&iseed[1], &il2, u);
if (*idist == 1) {
/* Copy generated numbers */
i__2 = il;
for (i__ = 1; i__ <= i__2; ++i__) {
x[iv + i__ - 1] = u[i__ - 1];
/* L10: */
}
} else if (*idist == 2) {
/* Convert generated numbers to uniform (-1,1) distribution */
i__2 = il;
for (i__ = 1; i__ <= i__2; ++i__) {
x[iv + i__ - 1] = u[i__ - 1] * 2.f - 1.f;
/* L20: */
}
} else if (*idist == 3) {
/* Convert generated numbers to normal (0,1) distribution */
i__2 = il;
for (i__ = 1; i__ <= i__2; ++i__) {
x[iv + i__ - 1] = sqrt(log(u[(i__ << 1) - 2]) * -2.f) * cos(u[
(i__ << 1) - 1] * 6.2831853071795864769252867663f);
/* L30: */
}
}
/* L40: */
}
return 0;
/* End of SLARNV */
} /* slarnv_ */
|
the_stack_data/87638204.c | /* PR rtl-optimization/59020 */
/* { dg-do compile { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-O2 -fmodulo-sched -fno-inline -march=corei7" } */
int a, b, d;
unsigned c;
void f()
{
unsigned q;
for(; a; a++)
if(((c %= d && 1) ? : 1) & 1)
for(; b; q++);
}
|
the_stack_data/140766463.c | #include <stdio.h>
#include <math.h>
#define PI 3.14
#define FREQ 1
void main(){ // Not like this program will ever return anything
unsigned long x = 0; // Creating a local unsigned long
float y = 0; // Creating a local float
while(1){ // A loop that will run while 1 = 1 i.e forever
++x; // Increments x by 1 and sets x to that value
y = (sin(FREQ*x*(PI/180))/2)+0.5; // Sets Y to the value specified in the instructions
printf("%*lu |%7.3f\n", 20, x, y); // Prints y with a width of 7 with 3 decimal places
}
}
|
the_stack_data/51699815.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
unsigned insert_counter =0;
unsigned merge_counter =0;
void merge (int* v, int left, int middle, int right)
{
int i,j,k;
int n1=middle-left+1;
int n2=right-middle;
int lv[n1],rv[n2];
for (i = 0; i < n1; i++)
{
lv[i]=v[left+i];
}
for (i = 0; i < n2; i++)
{
rv[i]=v[middle+1+i];
}
i=0; j=0; k=left;
while (i<n1 && j<n2)
{
if (lv[i]<rv[j])
{
v[k]=lv[i];
k++;
i++;
}
else
{
v[k]=rv[j];
k++;
j++;
}
merge_counter++;
}
while (i<n1)
{
v[k]=lv[i];
k++;
i++;
}
while (j<n2)
{
v[k]=rv[j];
k++;
j++;
}
}
void merge_sort(int *v, int left, int right)
{
if (left<right)
{
int middle = (left + right)/2;
merge_sort(v, left, middle);
merge_sort(v, middle+1, right);
merge(v,left,middle,right);
}
}
void insertion_sort (int *v, int n)
{
int i, j, aux;
for(i=1; i<n; i++)
{
aux=v[i];
for (j=i-1; j>=0 && v[j]>aux; j--)
{
v[j+1]=v[j];
insert_counter++;
}
v[j+1]=aux;
}
}
void populate_vect(int *v, int n)
{
srand(time(0));
for (int i=0; i<n; i++)
v[i]=rand()%1000;
}
void copy_vector(int *v_to, int *v_from, int n)
{
for (int i=0; i<n; i++)
v_to[i]=v_from[i];
}
void print_vect(int *v, int n)
{
for (int i = 0; i < n; ++i)
printf("%d ", v[i]);
putchar('\n');
}
void comp_merg_ins()
{
int n;
printf("Introduce vector dimension: ");
scanf("%d",&n);
int v[n],vIns[n],vMerge[n];
populate_vect(v,n);
copy_vector(vIns, v, n);
copy_vector(vMerge, v, n);
printf("Vector before sorting:\n");
print_vect(v,n);
printf("\nVector after sorting with insertion sort:\n");
insertion_sort(vIns,n);
print_vect(vIns,n);
printf("Total number of swaps: %d\n", insert_counter);
printf("\nVector after sorting with merge sort:\n");
merge_sort(vMerge,0,n-1);
print_vect(vMerge,n);
printf("Total number of swaps: %d\n", merge_counter);
}
int main ()
{
comp_merg_ins();
return 0;
} |
the_stack_data/12127.c | #define _GNU_SOURCE /* To get pthread_getattr_np() declaration */
#include <assert.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
void show_stack(pthread_attr_t *attr, pthread_t thread, char *prefix) {
size_t stack_size, guard_size;
void *stack_addr;
int rc;
rc = pthread_attr_getguardsize(attr, &guard_size);
assert(rc == 0);
rc = pthread_attr_getstack(attr, &stack_addr, &stack_size);
assert(rc == 0);
printf("Thread %s (id=%lu) stack:\n", prefix, thread);
printf("\tstart address\t= %p\n", stack_addr);
printf("\tend address\t= %p\n", stack_addr + stack_size);
printf("\tstack size\t= %.2f MB\n", stack_size / 1024.0 / 1024.0);
printf("\tguard size\t= %lu B\n", guard_size);
}
void *entry_point(void *arg) {
pthread_t thread = pthread_self();
int rc;
pthread_attr_t attr;
rc = pthread_getattr_np(thread, &attr);
assert(rc == 0);
pthread_mutex_lock(&lock);
show_stack(&attr, thread, (char *)arg);
pthread_mutex_unlock(&lock);
return NULL;
}
int main(int argc, char *argv[]) {
pthread_t p1, p2;
int rc;
rc = pthread_create(&p1, NULL, entry_point, "1");
assert(rc == 0);
rc = pthread_create(&p2, NULL, entry_point, "2");
assert(rc == 0);
entry_point("main");
rc = pthread_join(p1, NULL);
assert(rc == 0);
rc = pthread_join(p2, NULL);
assert(rc == 0);
return 0;
}
|
the_stack_data/921379.c | extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
bool _J1839, _x__J1839;
float x_2, _x_x_2;
bool _J1830, _x__J1830;
bool _J1823, _x__J1823;
bool _EL_U_1803, _x__EL_U_1803;
float x_16, _x_x_16;
float x_10, _x_x_10;
float x_4, _x_x_4;
bool _EL_U_1805, _x__EL_U_1805;
float x_13, _x_x_13;
bool _EL_U_1801, _x__EL_U_1801;
float x_0, _x_x_0;
float x_14, _x_x_14;
float x_17, _x_x_17;
float x_18, _x_x_18;
float x_3, _x_x_3;
float x_22, _x_x_22;
float x_1, _x_x_1;
float x_5, _x_x_5;
float x_6, _x_x_6;
float x_9, _x_x_9;
float x_11, _x_x_11;
float x_12, _x_x_12;
float x_15, _x_x_15;
float x_7, _x_x_7;
float x_19, _x_x_19;
float x_8, _x_x_8;
float x_20, _x_x_20;
float x_21, _x_x_21;
float x_23, _x_x_23;
int __steps_to_fair = __VERIFIER_nondet_int();
_J1839 = __VERIFIER_nondet_bool();
x_2 = __VERIFIER_nondet_float();
_J1830 = __VERIFIER_nondet_bool();
_J1823 = __VERIFIER_nondet_bool();
_EL_U_1803 = __VERIFIER_nondet_bool();
x_16 = __VERIFIER_nondet_float();
x_10 = __VERIFIER_nondet_float();
x_4 = __VERIFIER_nondet_float();
_EL_U_1805 = __VERIFIER_nondet_bool();
x_13 = __VERIFIER_nondet_float();
_EL_U_1801 = __VERIFIER_nondet_bool();
x_0 = __VERIFIER_nondet_float();
x_14 = __VERIFIER_nondet_float();
x_17 = __VERIFIER_nondet_float();
x_18 = __VERIFIER_nondet_float();
x_3 = __VERIFIER_nondet_float();
x_22 = __VERIFIER_nondet_float();
x_1 = __VERIFIER_nondet_float();
x_5 = __VERIFIER_nondet_float();
x_6 = __VERIFIER_nondet_float();
x_9 = __VERIFIER_nondet_float();
x_11 = __VERIFIER_nondet_float();
x_12 = __VERIFIER_nondet_float();
x_15 = __VERIFIER_nondet_float();
x_7 = __VERIFIER_nondet_float();
x_19 = __VERIFIER_nondet_float();
x_8 = __VERIFIER_nondet_float();
x_20 = __VERIFIER_nondet_float();
x_21 = __VERIFIER_nondet_float();
x_23 = __VERIFIER_nondet_float();
bool __ok = (1 && (((( !(( !(( !((x_0 + (-1.0 * x_10)) <= 12.0)) || _EL_U_1801)) || (_EL_U_1805 && ( !((20.0 <= (x_10 + (-1.0 * x_16))) || _EL_U_1803))))) && ( !_J1823)) && ( !_J1830)) && ( !_J1839)));
while (__steps_to_fair >= 0 && __ok) {
if (((_J1823 && _J1830) && _J1839)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__J1839 = __VERIFIER_nondet_bool();
_x_x_2 = __VERIFIER_nondet_float();
_x__J1830 = __VERIFIER_nondet_bool();
_x__J1823 = __VERIFIER_nondet_bool();
_x__EL_U_1803 = __VERIFIER_nondet_bool();
_x_x_16 = __VERIFIER_nondet_float();
_x_x_10 = __VERIFIER_nondet_float();
_x_x_4 = __VERIFIER_nondet_float();
_x__EL_U_1805 = __VERIFIER_nondet_bool();
_x_x_13 = __VERIFIER_nondet_float();
_x__EL_U_1801 = __VERIFIER_nondet_bool();
_x_x_0 = __VERIFIER_nondet_float();
_x_x_14 = __VERIFIER_nondet_float();
_x_x_17 = __VERIFIER_nondet_float();
_x_x_18 = __VERIFIER_nondet_float();
_x_x_3 = __VERIFIER_nondet_float();
_x_x_22 = __VERIFIER_nondet_float();
_x_x_1 = __VERIFIER_nondet_float();
_x_x_5 = __VERIFIER_nondet_float();
_x_x_6 = __VERIFIER_nondet_float();
_x_x_9 = __VERIFIER_nondet_float();
_x_x_11 = __VERIFIER_nondet_float();
_x_x_12 = __VERIFIER_nondet_float();
_x_x_15 = __VERIFIER_nondet_float();
_x_x_7 = __VERIFIER_nondet_float();
_x_x_19 = __VERIFIER_nondet_float();
_x_x_8 = __VERIFIER_nondet_float();
_x_x_20 = __VERIFIER_nondet_float();
_x_x_21 = __VERIFIER_nondet_float();
_x_x_23 = __VERIFIER_nondet_float();
__ok = ((((((((((((((((((((((((((((x_21 + (-1.0 * _x_x_0)) <= -9.0) && (((x_20 + (-1.0 * _x_x_0)) <= -2.0) && (((x_19 + (-1.0 * _x_x_0)) <= -7.0) && (((x_17 + (-1.0 * _x_x_0)) <= -2.0) && (((x_15 + (-1.0 * _x_x_0)) <= -6.0) && (((x_14 + (-1.0 * _x_x_0)) <= -1.0) && (((x_12 + (-1.0 * _x_x_0)) <= -7.0) && (((x_11 + (-1.0 * _x_x_0)) <= -14.0) && (((x_9 + (-1.0 * _x_x_0)) <= -8.0) && (((x_6 + (-1.0 * _x_x_0)) <= -18.0) && (((x_1 + (-1.0 * _x_x_0)) <= -20.0) && ((x_4 + (-1.0 * _x_x_0)) <= -14.0)))))))))))) && (((x_21 + (-1.0 * _x_x_0)) == -9.0) || (((x_20 + (-1.0 * _x_x_0)) == -2.0) || (((x_19 + (-1.0 * _x_x_0)) == -7.0) || (((x_17 + (-1.0 * _x_x_0)) == -2.0) || (((x_15 + (-1.0 * _x_x_0)) == -6.0) || (((x_14 + (-1.0 * _x_x_0)) == -1.0) || (((x_12 + (-1.0 * _x_x_0)) == -7.0) || (((x_11 + (-1.0 * _x_x_0)) == -14.0) || (((x_9 + (-1.0 * _x_x_0)) == -8.0) || (((x_6 + (-1.0 * _x_x_0)) == -18.0) || (((x_1 + (-1.0 * _x_x_0)) == -20.0) || ((x_4 + (-1.0 * _x_x_0)) == -14.0))))))))))))) && ((((x_23 + (-1.0 * _x_x_1)) <= -9.0) && (((x_22 + (-1.0 * _x_x_1)) <= -8.0) && (((x_17 + (-1.0 * _x_x_1)) <= -17.0) && (((x_14 + (-1.0 * _x_x_1)) <= -18.0) && (((x_13 + (-1.0 * _x_x_1)) <= -10.0) && (((x_11 + (-1.0 * _x_x_1)) <= -5.0) && (((x_9 + (-1.0 * _x_x_1)) <= -7.0) && (((x_8 + (-1.0 * _x_x_1)) <= -20.0) && (((x_7 + (-1.0 * _x_x_1)) <= -4.0) && (((x_4 + (-1.0 * _x_x_1)) <= -17.0) && (((x_1 + (-1.0 * _x_x_1)) <= -10.0) && ((x_3 + (-1.0 * _x_x_1)) <= -3.0)))))))))))) && (((x_23 + (-1.0 * _x_x_1)) == -9.0) || (((x_22 + (-1.0 * _x_x_1)) == -8.0) || (((x_17 + (-1.0 * _x_x_1)) == -17.0) || (((x_14 + (-1.0 * _x_x_1)) == -18.0) || (((x_13 + (-1.0 * _x_x_1)) == -10.0) || (((x_11 + (-1.0 * _x_x_1)) == -5.0) || (((x_9 + (-1.0 * _x_x_1)) == -7.0) || (((x_8 + (-1.0 * _x_x_1)) == -20.0) || (((x_7 + (-1.0 * _x_x_1)) == -4.0) || (((x_4 + (-1.0 * _x_x_1)) == -17.0) || (((x_1 + (-1.0 * _x_x_1)) == -10.0) || ((x_3 + (-1.0 * _x_x_1)) == -3.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_2)) <= -13.0) && (((x_18 + (-1.0 * _x_x_2)) <= -3.0) && (((x_17 + (-1.0 * _x_x_2)) <= -19.0) && (((x_16 + (-1.0 * _x_x_2)) <= -2.0) && (((x_15 + (-1.0 * _x_x_2)) <= -12.0) && (((x_14 + (-1.0 * _x_x_2)) <= -7.0) && (((x_12 + (-1.0 * _x_x_2)) <= -5.0) && (((x_10 + (-1.0 * _x_x_2)) <= -10.0) && (((x_9 + (-1.0 * _x_x_2)) <= -9.0) && (((x_6 + (-1.0 * _x_x_2)) <= -7.0) && (((x_1 + (-1.0 * _x_x_2)) <= -11.0) && ((x_2 + (-1.0 * _x_x_2)) <= -16.0)))))))))))) && (((x_21 + (-1.0 * _x_x_2)) == -13.0) || (((x_18 + (-1.0 * _x_x_2)) == -3.0) || (((x_17 + (-1.0 * _x_x_2)) == -19.0) || (((x_16 + (-1.0 * _x_x_2)) == -2.0) || (((x_15 + (-1.0 * _x_x_2)) == -12.0) || (((x_14 + (-1.0 * _x_x_2)) == -7.0) || (((x_12 + (-1.0 * _x_x_2)) == -5.0) || (((x_10 + (-1.0 * _x_x_2)) == -10.0) || (((x_9 + (-1.0 * _x_x_2)) == -9.0) || (((x_6 + (-1.0 * _x_x_2)) == -7.0) || (((x_1 + (-1.0 * _x_x_2)) == -11.0) || ((x_2 + (-1.0 * _x_x_2)) == -16.0)))))))))))))) && ((((x_19 + (-1.0 * _x_x_3)) <= -2.0) && (((x_17 + (-1.0 * _x_x_3)) <= -11.0) && (((x_16 + (-1.0 * _x_x_3)) <= -2.0) && (((x_15 + (-1.0 * _x_x_3)) <= -6.0) && (((x_14 + (-1.0 * _x_x_3)) <= -12.0) && (((x_12 + (-1.0 * _x_x_3)) <= -17.0) && (((x_8 + (-1.0 * _x_x_3)) <= -2.0) && (((x_7 + (-1.0 * _x_x_3)) <= -12.0) && (((x_6 + (-1.0 * _x_x_3)) <= -3.0) && (((x_3 + (-1.0 * _x_x_3)) <= -9.0) && (((x_1 + (-1.0 * _x_x_3)) <= -14.0) && ((x_2 + (-1.0 * _x_x_3)) <= -5.0)))))))))))) && (((x_19 + (-1.0 * _x_x_3)) == -2.0) || (((x_17 + (-1.0 * _x_x_3)) == -11.0) || (((x_16 + (-1.0 * _x_x_3)) == -2.0) || (((x_15 + (-1.0 * _x_x_3)) == -6.0) || (((x_14 + (-1.0 * _x_x_3)) == -12.0) || (((x_12 + (-1.0 * _x_x_3)) == -17.0) || (((x_8 + (-1.0 * _x_x_3)) == -2.0) || (((x_7 + (-1.0 * _x_x_3)) == -12.0) || (((x_6 + (-1.0 * _x_x_3)) == -3.0) || (((x_3 + (-1.0 * _x_x_3)) == -9.0) || (((x_1 + (-1.0 * _x_x_3)) == -14.0) || ((x_2 + (-1.0 * _x_x_3)) == -5.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_4)) <= -13.0) && (((x_19 + (-1.0 * _x_x_4)) <= -2.0) && (((x_18 + (-1.0 * _x_x_4)) <= -17.0) && (((x_17 + (-1.0 * _x_x_4)) <= -4.0) && (((x_15 + (-1.0 * _x_x_4)) <= -4.0) && (((x_13 + (-1.0 * _x_x_4)) <= -7.0) && (((x_7 + (-1.0 * _x_x_4)) <= -13.0) && (((x_6 + (-1.0 * _x_x_4)) <= -4.0) && (((x_4 + (-1.0 * _x_x_4)) <= -15.0) && (((x_3 + (-1.0 * _x_x_4)) <= -11.0) && (((x_0 + (-1.0 * _x_x_4)) <= -10.0) && ((x_2 + (-1.0 * _x_x_4)) <= -17.0)))))))))))) && (((x_23 + (-1.0 * _x_x_4)) == -13.0) || (((x_19 + (-1.0 * _x_x_4)) == -2.0) || (((x_18 + (-1.0 * _x_x_4)) == -17.0) || (((x_17 + (-1.0 * _x_x_4)) == -4.0) || (((x_15 + (-1.0 * _x_x_4)) == -4.0) || (((x_13 + (-1.0 * _x_x_4)) == -7.0) || (((x_7 + (-1.0 * _x_x_4)) == -13.0) || (((x_6 + (-1.0 * _x_x_4)) == -4.0) || (((x_4 + (-1.0 * _x_x_4)) == -15.0) || (((x_3 + (-1.0 * _x_x_4)) == -11.0) || (((x_0 + (-1.0 * _x_x_4)) == -10.0) || ((x_2 + (-1.0 * _x_x_4)) == -17.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_5)) <= -1.0) && (((x_17 + (-1.0 * _x_x_5)) <= -3.0) && (((x_15 + (-1.0 * _x_x_5)) <= -9.0) && (((x_14 + (-1.0 * _x_x_5)) <= -12.0) && (((x_13 + (-1.0 * _x_x_5)) <= -3.0) && (((x_12 + (-1.0 * _x_x_5)) <= -5.0) && (((x_8 + (-1.0 * _x_x_5)) <= -6.0) && (((x_7 + (-1.0 * _x_x_5)) <= -15.0) && (((x_5 + (-1.0 * _x_x_5)) <= -10.0) && (((x_4 + (-1.0 * _x_x_5)) <= -19.0) && (((x_0 + (-1.0 * _x_x_5)) <= -19.0) && ((x_3 + (-1.0 * _x_x_5)) <= -13.0)))))))))))) && (((x_23 + (-1.0 * _x_x_5)) == -1.0) || (((x_17 + (-1.0 * _x_x_5)) == -3.0) || (((x_15 + (-1.0 * _x_x_5)) == -9.0) || (((x_14 + (-1.0 * _x_x_5)) == -12.0) || (((x_13 + (-1.0 * _x_x_5)) == -3.0) || (((x_12 + (-1.0 * _x_x_5)) == -5.0) || (((x_8 + (-1.0 * _x_x_5)) == -6.0) || (((x_7 + (-1.0 * _x_x_5)) == -15.0) || (((x_5 + (-1.0 * _x_x_5)) == -10.0) || (((x_4 + (-1.0 * _x_x_5)) == -19.0) || (((x_0 + (-1.0 * _x_x_5)) == -19.0) || ((x_3 + (-1.0 * _x_x_5)) == -13.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_6)) <= -19.0) && (((x_22 + (-1.0 * _x_x_6)) <= -13.0) && (((x_19 + (-1.0 * _x_x_6)) <= -13.0) && (((x_17 + (-1.0 * _x_x_6)) <= -10.0) && (((x_16 + (-1.0 * _x_x_6)) <= -19.0) && (((x_15 + (-1.0 * _x_x_6)) <= -18.0) && (((x_14 + (-1.0 * _x_x_6)) <= -13.0) && (((x_9 + (-1.0 * _x_x_6)) <= -10.0) && (((x_7 + (-1.0 * _x_x_6)) <= -20.0) && (((x_5 + (-1.0 * _x_x_6)) <= -14.0) && (((x_2 + (-1.0 * _x_x_6)) <= -7.0) && ((x_4 + (-1.0 * _x_x_6)) <= -5.0)))))))))))) && (((x_23 + (-1.0 * _x_x_6)) == -19.0) || (((x_22 + (-1.0 * _x_x_6)) == -13.0) || (((x_19 + (-1.0 * _x_x_6)) == -13.0) || (((x_17 + (-1.0 * _x_x_6)) == -10.0) || (((x_16 + (-1.0 * _x_x_6)) == -19.0) || (((x_15 + (-1.0 * _x_x_6)) == -18.0) || (((x_14 + (-1.0 * _x_x_6)) == -13.0) || (((x_9 + (-1.0 * _x_x_6)) == -10.0) || (((x_7 + (-1.0 * _x_x_6)) == -20.0) || (((x_5 + (-1.0 * _x_x_6)) == -14.0) || (((x_2 + (-1.0 * _x_x_6)) == -7.0) || ((x_4 + (-1.0 * _x_x_6)) == -5.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_7)) <= -3.0) && (((x_19 + (-1.0 * _x_x_7)) <= -8.0) && (((x_18 + (-1.0 * _x_x_7)) <= -4.0) && (((x_16 + (-1.0 * _x_x_7)) <= -5.0) && (((x_15 + (-1.0 * _x_x_7)) <= -13.0) && (((x_12 + (-1.0 * _x_x_7)) <= -1.0) && (((x_11 + (-1.0 * _x_x_7)) <= -8.0) && (((x_9 + (-1.0 * _x_x_7)) <= -1.0) && (((x_8 + (-1.0 * _x_x_7)) <= -18.0) && (((x_7 + (-1.0 * _x_x_7)) <= -8.0) && (((x_2 + (-1.0 * _x_x_7)) <= -17.0) && ((x_5 + (-1.0 * _x_x_7)) <= -20.0)))))))))))) && (((x_23 + (-1.0 * _x_x_7)) == -3.0) || (((x_19 + (-1.0 * _x_x_7)) == -8.0) || (((x_18 + (-1.0 * _x_x_7)) == -4.0) || (((x_16 + (-1.0 * _x_x_7)) == -5.0) || (((x_15 + (-1.0 * _x_x_7)) == -13.0) || (((x_12 + (-1.0 * _x_x_7)) == -1.0) || (((x_11 + (-1.0 * _x_x_7)) == -8.0) || (((x_9 + (-1.0 * _x_x_7)) == -1.0) || (((x_8 + (-1.0 * _x_x_7)) == -18.0) || (((x_7 + (-1.0 * _x_x_7)) == -8.0) || (((x_2 + (-1.0 * _x_x_7)) == -17.0) || ((x_5 + (-1.0 * _x_x_7)) == -20.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_8)) <= -20.0) && (((x_19 + (-1.0 * _x_x_8)) <= -18.0) && (((x_15 + (-1.0 * _x_x_8)) <= -10.0) && (((x_14 + (-1.0 * _x_x_8)) <= -7.0) && (((x_11 + (-1.0 * _x_x_8)) <= -10.0) && (((x_9 + (-1.0 * _x_x_8)) <= -4.0) && (((x_8 + (-1.0 * _x_x_8)) <= -8.0) && (((x_7 + (-1.0 * _x_x_8)) <= -3.0) && (((x_6 + (-1.0 * _x_x_8)) <= -8.0) && (((x_5 + (-1.0 * _x_x_8)) <= -12.0) && (((x_1 + (-1.0 * _x_x_8)) <= -17.0) && ((x_3 + (-1.0 * _x_x_8)) <= -3.0)))))))))))) && (((x_21 + (-1.0 * _x_x_8)) == -20.0) || (((x_19 + (-1.0 * _x_x_8)) == -18.0) || (((x_15 + (-1.0 * _x_x_8)) == -10.0) || (((x_14 + (-1.0 * _x_x_8)) == -7.0) || (((x_11 + (-1.0 * _x_x_8)) == -10.0) || (((x_9 + (-1.0 * _x_x_8)) == -4.0) || (((x_8 + (-1.0 * _x_x_8)) == -8.0) || (((x_7 + (-1.0 * _x_x_8)) == -3.0) || (((x_6 + (-1.0 * _x_x_8)) == -8.0) || (((x_5 + (-1.0 * _x_x_8)) == -12.0) || (((x_1 + (-1.0 * _x_x_8)) == -17.0) || ((x_3 + (-1.0 * _x_x_8)) == -3.0)))))))))))))) && ((((x_20 + (-1.0 * _x_x_9)) <= -2.0) && (((x_19 + (-1.0 * _x_x_9)) <= -19.0) && (((x_18 + (-1.0 * _x_x_9)) <= -19.0) && (((x_17 + (-1.0 * _x_x_9)) <= -20.0) && (((x_14 + (-1.0 * _x_x_9)) <= -19.0) && (((x_11 + (-1.0 * _x_x_9)) <= -7.0) && (((x_8 + (-1.0 * _x_x_9)) <= -7.0) && (((x_7 + (-1.0 * _x_x_9)) <= -20.0) && (((x_4 + (-1.0 * _x_x_9)) <= -20.0) && (((x_3 + (-1.0 * _x_x_9)) <= -13.0) && (((x_1 + (-1.0 * _x_x_9)) <= -3.0) && ((x_2 + (-1.0 * _x_x_9)) <= -15.0)))))))))))) && (((x_20 + (-1.0 * _x_x_9)) == -2.0) || (((x_19 + (-1.0 * _x_x_9)) == -19.0) || (((x_18 + (-1.0 * _x_x_9)) == -19.0) || (((x_17 + (-1.0 * _x_x_9)) == -20.0) || (((x_14 + (-1.0 * _x_x_9)) == -19.0) || (((x_11 + (-1.0 * _x_x_9)) == -7.0) || (((x_8 + (-1.0 * _x_x_9)) == -7.0) || (((x_7 + (-1.0 * _x_x_9)) == -20.0) || (((x_4 + (-1.0 * _x_x_9)) == -20.0) || (((x_3 + (-1.0 * _x_x_9)) == -13.0) || (((x_1 + (-1.0 * _x_x_9)) == -3.0) || ((x_2 + (-1.0 * _x_x_9)) == -15.0)))))))))))))) && ((((x_19 + (-1.0 * _x_x_10)) <= -1.0) && (((x_18 + (-1.0 * _x_x_10)) <= -3.0) && (((x_16 + (-1.0 * _x_x_10)) <= -19.0) && (((x_15 + (-1.0 * _x_x_10)) <= -19.0) && (((x_13 + (-1.0 * _x_x_10)) <= -5.0) && (((x_12 + (-1.0 * _x_x_10)) <= -7.0) && (((x_10 + (-1.0 * _x_x_10)) <= -12.0) && (((x_8 + (-1.0 * _x_x_10)) <= -11.0) && (((x_5 + (-1.0 * _x_x_10)) <= -10.0) && (((x_2 + (-1.0 * _x_x_10)) <= -19.0) && (((x_0 + (-1.0 * _x_x_10)) <= -18.0) && ((x_1 + (-1.0 * _x_x_10)) <= -20.0)))))))))))) && (((x_19 + (-1.0 * _x_x_10)) == -1.0) || (((x_18 + (-1.0 * _x_x_10)) == -3.0) || (((x_16 + (-1.0 * _x_x_10)) == -19.0) || (((x_15 + (-1.0 * _x_x_10)) == -19.0) || (((x_13 + (-1.0 * _x_x_10)) == -5.0) || (((x_12 + (-1.0 * _x_x_10)) == -7.0) || (((x_10 + (-1.0 * _x_x_10)) == -12.0) || (((x_8 + (-1.0 * _x_x_10)) == -11.0) || (((x_5 + (-1.0 * _x_x_10)) == -10.0) || (((x_2 + (-1.0 * _x_x_10)) == -19.0) || (((x_0 + (-1.0 * _x_x_10)) == -18.0) || ((x_1 + (-1.0 * _x_x_10)) == -20.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_11)) <= -1.0) && (((x_22 + (-1.0 * _x_x_11)) <= -7.0) && (((x_20 + (-1.0 * _x_x_11)) <= -16.0) && (((x_18 + (-1.0 * _x_x_11)) <= -2.0) && (((x_17 + (-1.0 * _x_x_11)) <= -7.0) && (((x_15 + (-1.0 * _x_x_11)) <= -6.0) && (((x_13 + (-1.0 * _x_x_11)) <= -14.0) && (((x_12 + (-1.0 * _x_x_11)) <= -17.0) && (((x_10 + (-1.0 * _x_x_11)) <= -13.0) && (((x_3 + (-1.0 * _x_x_11)) <= -14.0) && (((x_1 + (-1.0 * _x_x_11)) <= -17.0) && ((x_2 + (-1.0 * _x_x_11)) <= -13.0)))))))))))) && (((x_23 + (-1.0 * _x_x_11)) == -1.0) || (((x_22 + (-1.0 * _x_x_11)) == -7.0) || (((x_20 + (-1.0 * _x_x_11)) == -16.0) || (((x_18 + (-1.0 * _x_x_11)) == -2.0) || (((x_17 + (-1.0 * _x_x_11)) == -7.0) || (((x_15 + (-1.0 * _x_x_11)) == -6.0) || (((x_13 + (-1.0 * _x_x_11)) == -14.0) || (((x_12 + (-1.0 * _x_x_11)) == -17.0) || (((x_10 + (-1.0 * _x_x_11)) == -13.0) || (((x_3 + (-1.0 * _x_x_11)) == -14.0) || (((x_1 + (-1.0 * _x_x_11)) == -17.0) || ((x_2 + (-1.0 * _x_x_11)) == -13.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_12)) <= -5.0) && (((x_22 + (-1.0 * _x_x_12)) <= -1.0) && (((x_18 + (-1.0 * _x_x_12)) <= -16.0) && (((x_16 + (-1.0 * _x_x_12)) <= -9.0) && (((x_12 + (-1.0 * _x_x_12)) <= -19.0) && (((x_10 + (-1.0 * _x_x_12)) <= -16.0) && (((x_9 + (-1.0 * _x_x_12)) <= -2.0) && (((x_8 + (-1.0 * _x_x_12)) <= -19.0) && (((x_5 + (-1.0 * _x_x_12)) <= -7.0) && (((x_3 + (-1.0 * _x_x_12)) <= -17.0) && (((x_1 + (-1.0 * _x_x_12)) <= -5.0) && ((x_2 + (-1.0 * _x_x_12)) <= -1.0)))))))))))) && (((x_23 + (-1.0 * _x_x_12)) == -5.0) || (((x_22 + (-1.0 * _x_x_12)) == -1.0) || (((x_18 + (-1.0 * _x_x_12)) == -16.0) || (((x_16 + (-1.0 * _x_x_12)) == -9.0) || (((x_12 + (-1.0 * _x_x_12)) == -19.0) || (((x_10 + (-1.0 * _x_x_12)) == -16.0) || (((x_9 + (-1.0 * _x_x_12)) == -2.0) || (((x_8 + (-1.0 * _x_x_12)) == -19.0) || (((x_5 + (-1.0 * _x_x_12)) == -7.0) || (((x_3 + (-1.0 * _x_x_12)) == -17.0) || (((x_1 + (-1.0 * _x_x_12)) == -5.0) || ((x_2 + (-1.0 * _x_x_12)) == -1.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_13)) <= -2.0) && (((x_22 + (-1.0 * _x_x_13)) <= -18.0) && (((x_20 + (-1.0 * _x_x_13)) <= -12.0) && (((x_16 + (-1.0 * _x_x_13)) <= -2.0) && (((x_15 + (-1.0 * _x_x_13)) <= -8.0) && (((x_14 + (-1.0 * _x_x_13)) <= -14.0) && (((x_11 + (-1.0 * _x_x_13)) <= -11.0) && (((x_9 + (-1.0 * _x_x_13)) <= -19.0) && (((x_7 + (-1.0 * _x_x_13)) <= -4.0) && (((x_6 + (-1.0 * _x_x_13)) <= -10.0) && (((x_0 + (-1.0 * _x_x_13)) <= -9.0) && ((x_3 + (-1.0 * _x_x_13)) <= -20.0)))))))))))) && (((x_23 + (-1.0 * _x_x_13)) == -2.0) || (((x_22 + (-1.0 * _x_x_13)) == -18.0) || (((x_20 + (-1.0 * _x_x_13)) == -12.0) || (((x_16 + (-1.0 * _x_x_13)) == -2.0) || (((x_15 + (-1.0 * _x_x_13)) == -8.0) || (((x_14 + (-1.0 * _x_x_13)) == -14.0) || (((x_11 + (-1.0 * _x_x_13)) == -11.0) || (((x_9 + (-1.0 * _x_x_13)) == -19.0) || (((x_7 + (-1.0 * _x_x_13)) == -4.0) || (((x_6 + (-1.0 * _x_x_13)) == -10.0) || (((x_0 + (-1.0 * _x_x_13)) == -9.0) || ((x_3 + (-1.0 * _x_x_13)) == -20.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_14)) <= -18.0) && (((x_21 + (-1.0 * _x_x_14)) <= -12.0) && (((x_20 + (-1.0 * _x_x_14)) <= -2.0) && (((x_18 + (-1.0 * _x_x_14)) <= -7.0) && (((x_15 + (-1.0 * _x_x_14)) <= -7.0) && (((x_14 + (-1.0 * _x_x_14)) <= -8.0) && (((x_13 + (-1.0 * _x_x_14)) <= -15.0) && (((x_6 + (-1.0 * _x_x_14)) <= -20.0) && (((x_5 + (-1.0 * _x_x_14)) <= -6.0) && (((x_3 + (-1.0 * _x_x_14)) <= -20.0) && (((x_1 + (-1.0 * _x_x_14)) <= -16.0) && ((x_2 + (-1.0 * _x_x_14)) <= -7.0)))))))))))) && (((x_23 + (-1.0 * _x_x_14)) == -18.0) || (((x_21 + (-1.0 * _x_x_14)) == -12.0) || (((x_20 + (-1.0 * _x_x_14)) == -2.0) || (((x_18 + (-1.0 * _x_x_14)) == -7.0) || (((x_15 + (-1.0 * _x_x_14)) == -7.0) || (((x_14 + (-1.0 * _x_x_14)) == -8.0) || (((x_13 + (-1.0 * _x_x_14)) == -15.0) || (((x_6 + (-1.0 * _x_x_14)) == -20.0) || (((x_5 + (-1.0 * _x_x_14)) == -6.0) || (((x_3 + (-1.0 * _x_x_14)) == -20.0) || (((x_1 + (-1.0 * _x_x_14)) == -16.0) || ((x_2 + (-1.0 * _x_x_14)) == -7.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_15)) <= -2.0) && (((x_21 + (-1.0 * _x_x_15)) <= -6.0) && (((x_19 + (-1.0 * _x_x_15)) <= -1.0) && (((x_16 + (-1.0 * _x_x_15)) <= -8.0) && (((x_12 + (-1.0 * _x_x_15)) <= -7.0) && (((x_11 + (-1.0 * _x_x_15)) <= -10.0) && (((x_7 + (-1.0 * _x_x_15)) <= -9.0) && (((x_6 + (-1.0 * _x_x_15)) <= -19.0) && (((x_5 + (-1.0 * _x_x_15)) <= -14.0) && (((x_4 + (-1.0 * _x_x_15)) <= -6.0) && (((x_0 + (-1.0 * _x_x_15)) <= -17.0) && ((x_2 + (-1.0 * _x_x_15)) <= -14.0)))))))))))) && (((x_23 + (-1.0 * _x_x_15)) == -2.0) || (((x_21 + (-1.0 * _x_x_15)) == -6.0) || (((x_19 + (-1.0 * _x_x_15)) == -1.0) || (((x_16 + (-1.0 * _x_x_15)) == -8.0) || (((x_12 + (-1.0 * _x_x_15)) == -7.0) || (((x_11 + (-1.0 * _x_x_15)) == -10.0) || (((x_7 + (-1.0 * _x_x_15)) == -9.0) || (((x_6 + (-1.0 * _x_x_15)) == -19.0) || (((x_5 + (-1.0 * _x_x_15)) == -14.0) || (((x_4 + (-1.0 * _x_x_15)) == -6.0) || (((x_0 + (-1.0 * _x_x_15)) == -17.0) || ((x_2 + (-1.0 * _x_x_15)) == -14.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_16)) <= -12.0) && (((x_17 + (-1.0 * _x_x_16)) <= -1.0) && (((x_16 + (-1.0 * _x_x_16)) <= -6.0) && (((x_15 + (-1.0 * _x_x_16)) <= -6.0) && (((x_13 + (-1.0 * _x_x_16)) <= -19.0) && (((x_12 + (-1.0 * _x_x_16)) <= -15.0) && (((x_11 + (-1.0 * _x_x_16)) <= -16.0) && (((x_10 + (-1.0 * _x_x_16)) <= -6.0) && (((x_7 + (-1.0 * _x_x_16)) <= -3.0) && (((x_5 + (-1.0 * _x_x_16)) <= -9.0) && (((x_1 + (-1.0 * _x_x_16)) <= -6.0) && ((x_2 + (-1.0 * _x_x_16)) <= -3.0)))))))))))) && (((x_21 + (-1.0 * _x_x_16)) == -12.0) || (((x_17 + (-1.0 * _x_x_16)) == -1.0) || (((x_16 + (-1.0 * _x_x_16)) == -6.0) || (((x_15 + (-1.0 * _x_x_16)) == -6.0) || (((x_13 + (-1.0 * _x_x_16)) == -19.0) || (((x_12 + (-1.0 * _x_x_16)) == -15.0) || (((x_11 + (-1.0 * _x_x_16)) == -16.0) || (((x_10 + (-1.0 * _x_x_16)) == -6.0) || (((x_7 + (-1.0 * _x_x_16)) == -3.0) || (((x_5 + (-1.0 * _x_x_16)) == -9.0) || (((x_1 + (-1.0 * _x_x_16)) == -6.0) || ((x_2 + (-1.0 * _x_x_16)) == -3.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_17)) <= -14.0) && (((x_19 + (-1.0 * _x_x_17)) <= -15.0) && (((x_18 + (-1.0 * _x_x_17)) <= -10.0) && (((x_17 + (-1.0 * _x_x_17)) <= -18.0) && (((x_12 + (-1.0 * _x_x_17)) <= -20.0) && (((x_10 + (-1.0 * _x_x_17)) <= -3.0) && (((x_9 + (-1.0 * _x_x_17)) <= -20.0) && (((x_8 + (-1.0 * _x_x_17)) <= -17.0) && (((x_5 + (-1.0 * _x_x_17)) <= -16.0) && (((x_4 + (-1.0 * _x_x_17)) <= -13.0) && (((x_0 + (-1.0 * _x_x_17)) <= -5.0) && ((x_2 + (-1.0 * _x_x_17)) <= -8.0)))))))))))) && (((x_23 + (-1.0 * _x_x_17)) == -14.0) || (((x_19 + (-1.0 * _x_x_17)) == -15.0) || (((x_18 + (-1.0 * _x_x_17)) == -10.0) || (((x_17 + (-1.0 * _x_x_17)) == -18.0) || (((x_12 + (-1.0 * _x_x_17)) == -20.0) || (((x_10 + (-1.0 * _x_x_17)) == -3.0) || (((x_9 + (-1.0 * _x_x_17)) == -20.0) || (((x_8 + (-1.0 * _x_x_17)) == -17.0) || (((x_5 + (-1.0 * _x_x_17)) == -16.0) || (((x_4 + (-1.0 * _x_x_17)) == -13.0) || (((x_0 + (-1.0 * _x_x_17)) == -5.0) || ((x_2 + (-1.0 * _x_x_17)) == -8.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_18)) <= -6.0) && (((x_22 + (-1.0 * _x_x_18)) <= -1.0) && (((x_18 + (-1.0 * _x_x_18)) <= -10.0) && (((x_16 + (-1.0 * _x_x_18)) <= -3.0) && (((x_15 + (-1.0 * _x_x_18)) <= -16.0) && (((x_13 + (-1.0 * _x_x_18)) <= -12.0) && (((x_12 + (-1.0 * _x_x_18)) <= -18.0) && (((x_9 + (-1.0 * _x_x_18)) <= -13.0) && (((x_6 + (-1.0 * _x_x_18)) <= -13.0) && (((x_3 + (-1.0 * _x_x_18)) <= -4.0) && (((x_0 + (-1.0 * _x_x_18)) <= -5.0) && ((x_2 + (-1.0 * _x_x_18)) <= -9.0)))))))))))) && (((x_23 + (-1.0 * _x_x_18)) == -6.0) || (((x_22 + (-1.0 * _x_x_18)) == -1.0) || (((x_18 + (-1.0 * _x_x_18)) == -10.0) || (((x_16 + (-1.0 * _x_x_18)) == -3.0) || (((x_15 + (-1.0 * _x_x_18)) == -16.0) || (((x_13 + (-1.0 * _x_x_18)) == -12.0) || (((x_12 + (-1.0 * _x_x_18)) == -18.0) || (((x_9 + (-1.0 * _x_x_18)) == -13.0) || (((x_6 + (-1.0 * _x_x_18)) == -13.0) || (((x_3 + (-1.0 * _x_x_18)) == -4.0) || (((x_0 + (-1.0 * _x_x_18)) == -5.0) || ((x_2 + (-1.0 * _x_x_18)) == -9.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_19)) <= -19.0) && (((x_22 + (-1.0 * _x_x_19)) <= -16.0) && (((x_19 + (-1.0 * _x_x_19)) <= -4.0) && (((x_18 + (-1.0 * _x_x_19)) <= -18.0) && (((x_13 + (-1.0 * _x_x_19)) <= -19.0) && (((x_12 + (-1.0 * _x_x_19)) <= -15.0) && (((x_11 + (-1.0 * _x_x_19)) <= -15.0) && (((x_6 + (-1.0 * _x_x_19)) <= -12.0) && (((x_4 + (-1.0 * _x_x_19)) <= -4.0) && (((x_3 + (-1.0 * _x_x_19)) <= -7.0) && (((x_0 + (-1.0 * _x_x_19)) <= -12.0) && ((x_2 + (-1.0 * _x_x_19)) <= -1.0)))))))))))) && (((x_23 + (-1.0 * _x_x_19)) == -19.0) || (((x_22 + (-1.0 * _x_x_19)) == -16.0) || (((x_19 + (-1.0 * _x_x_19)) == -4.0) || (((x_18 + (-1.0 * _x_x_19)) == -18.0) || (((x_13 + (-1.0 * _x_x_19)) == -19.0) || (((x_12 + (-1.0 * _x_x_19)) == -15.0) || (((x_11 + (-1.0 * _x_x_19)) == -15.0) || (((x_6 + (-1.0 * _x_x_19)) == -12.0) || (((x_4 + (-1.0 * _x_x_19)) == -4.0) || (((x_3 + (-1.0 * _x_x_19)) == -7.0) || (((x_0 + (-1.0 * _x_x_19)) == -12.0) || ((x_2 + (-1.0 * _x_x_19)) == -1.0)))))))))))))) && ((((x_22 + (-1.0 * _x_x_20)) <= -20.0) && (((x_21 + (-1.0 * _x_x_20)) <= -11.0) && (((x_20 + (-1.0 * _x_x_20)) <= -17.0) && (((x_18 + (-1.0 * _x_x_20)) <= -2.0) && (((x_16 + (-1.0 * _x_x_20)) <= -5.0) && (((x_15 + (-1.0 * _x_x_20)) <= -4.0) && (((x_14 + (-1.0 * _x_x_20)) <= -11.0) && (((x_11 + (-1.0 * _x_x_20)) <= -18.0) && (((x_9 + (-1.0 * _x_x_20)) <= -5.0) && (((x_7 + (-1.0 * _x_x_20)) <= -4.0) && (((x_4 + (-1.0 * _x_x_20)) <= -11.0) && ((x_5 + (-1.0 * _x_x_20)) <= -9.0)))))))))))) && (((x_22 + (-1.0 * _x_x_20)) == -20.0) || (((x_21 + (-1.0 * _x_x_20)) == -11.0) || (((x_20 + (-1.0 * _x_x_20)) == -17.0) || (((x_18 + (-1.0 * _x_x_20)) == -2.0) || (((x_16 + (-1.0 * _x_x_20)) == -5.0) || (((x_15 + (-1.0 * _x_x_20)) == -4.0) || (((x_14 + (-1.0 * _x_x_20)) == -11.0) || (((x_11 + (-1.0 * _x_x_20)) == -18.0) || (((x_9 + (-1.0 * _x_x_20)) == -5.0) || (((x_7 + (-1.0 * _x_x_20)) == -4.0) || (((x_4 + (-1.0 * _x_x_20)) == -11.0) || ((x_5 + (-1.0 * _x_x_20)) == -9.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_21)) <= -5.0) && (((x_19 + (-1.0 * _x_x_21)) <= -7.0) && (((x_18 + (-1.0 * _x_x_21)) <= -18.0) && (((x_17 + (-1.0 * _x_x_21)) <= -3.0) && (((x_16 + (-1.0 * _x_x_21)) <= -13.0) && (((x_11 + (-1.0 * _x_x_21)) <= -7.0) && (((x_10 + (-1.0 * _x_x_21)) <= -18.0) && (((x_7 + (-1.0 * _x_x_21)) <= -14.0) && (((x_6 + (-1.0 * _x_x_21)) <= -2.0) && (((x_5 + (-1.0 * _x_x_21)) <= -10.0) && (((x_1 + (-1.0 * _x_x_21)) <= -11.0) && ((x_2 + (-1.0 * _x_x_21)) <= -15.0)))))))))))) && (((x_21 + (-1.0 * _x_x_21)) == -5.0) || (((x_19 + (-1.0 * _x_x_21)) == -7.0) || (((x_18 + (-1.0 * _x_x_21)) == -18.0) || (((x_17 + (-1.0 * _x_x_21)) == -3.0) || (((x_16 + (-1.0 * _x_x_21)) == -13.0) || (((x_11 + (-1.0 * _x_x_21)) == -7.0) || (((x_10 + (-1.0 * _x_x_21)) == -18.0) || (((x_7 + (-1.0 * _x_x_21)) == -14.0) || (((x_6 + (-1.0 * _x_x_21)) == -2.0) || (((x_5 + (-1.0 * _x_x_21)) == -10.0) || (((x_1 + (-1.0 * _x_x_21)) == -11.0) || ((x_2 + (-1.0 * _x_x_21)) == -15.0)))))))))))))) && ((((x_22 + (-1.0 * _x_x_22)) <= -9.0) && (((x_21 + (-1.0 * _x_x_22)) <= -17.0) && (((x_18 + (-1.0 * _x_x_22)) <= -7.0) && (((x_17 + (-1.0 * _x_x_22)) <= -15.0) && (((x_16 + (-1.0 * _x_x_22)) <= -11.0) && (((x_15 + (-1.0 * _x_x_22)) <= -15.0) && (((x_13 + (-1.0 * _x_x_22)) <= -14.0) && (((x_12 + (-1.0 * _x_x_22)) <= -6.0) && (((x_5 + (-1.0 * _x_x_22)) <= -2.0) && (((x_3 + (-1.0 * _x_x_22)) <= -18.0) && (((x_1 + (-1.0 * _x_x_22)) <= -17.0) && ((x_2 + (-1.0 * _x_x_22)) <= -6.0)))))))))))) && (((x_22 + (-1.0 * _x_x_22)) == -9.0) || (((x_21 + (-1.0 * _x_x_22)) == -17.0) || (((x_18 + (-1.0 * _x_x_22)) == -7.0) || (((x_17 + (-1.0 * _x_x_22)) == -15.0) || (((x_16 + (-1.0 * _x_x_22)) == -11.0) || (((x_15 + (-1.0 * _x_x_22)) == -15.0) || (((x_13 + (-1.0 * _x_x_22)) == -14.0) || (((x_12 + (-1.0 * _x_x_22)) == -6.0) || (((x_5 + (-1.0 * _x_x_22)) == -2.0) || (((x_3 + (-1.0 * _x_x_22)) == -18.0) || (((x_1 + (-1.0 * _x_x_22)) == -17.0) || ((x_2 + (-1.0 * _x_x_22)) == -6.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_23)) <= -16.0) && (((x_20 + (-1.0 * _x_x_23)) <= -20.0) && (((x_19 + (-1.0 * _x_x_23)) <= -6.0) && (((x_16 + (-1.0 * _x_x_23)) <= -3.0) && (((x_15 + (-1.0 * _x_x_23)) <= -4.0) && (((x_12 + (-1.0 * _x_x_23)) <= -20.0) && (((x_11 + (-1.0 * _x_x_23)) <= -17.0) && (((x_9 + (-1.0 * _x_x_23)) <= -1.0) && (((x_6 + (-1.0 * _x_x_23)) <= -1.0) && (((x_5 + (-1.0 * _x_x_23)) <= -2.0) && (((x_1 + (-1.0 * _x_x_23)) <= -9.0) && ((x_3 + (-1.0 * _x_x_23)) <= -7.0)))))))))))) && (((x_21 + (-1.0 * _x_x_23)) == -16.0) || (((x_20 + (-1.0 * _x_x_23)) == -20.0) || (((x_19 + (-1.0 * _x_x_23)) == -6.0) || (((x_16 + (-1.0 * _x_x_23)) == -3.0) || (((x_15 + (-1.0 * _x_x_23)) == -4.0) || (((x_12 + (-1.0 * _x_x_23)) == -20.0) || (((x_11 + (-1.0 * _x_x_23)) == -17.0) || (((x_9 + (-1.0 * _x_x_23)) == -1.0) || (((x_6 + (-1.0 * _x_x_23)) == -1.0) || (((x_5 + (-1.0 * _x_x_23)) == -2.0) || (((x_1 + (-1.0 * _x_x_23)) == -9.0) || ((x_3 + (-1.0 * _x_x_23)) == -7.0)))))))))))))) && (((((_EL_U_1805 == ((_x__EL_U_1805 && ( !(_x__EL_U_1803 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_16)))))) || ( !(_x__EL_U_1801 || ( !((_x_x_0 + (-1.0 * _x_x_10)) <= 12.0)))))) && ((_EL_U_1801 == (_x__EL_U_1801 || ( !((_x_x_0 + (-1.0 * _x_x_10)) <= 12.0)))) && (_EL_U_1803 == (_x__EL_U_1803 || (20.0 <= (_x_x_10 + (-1.0 * _x_x_16))))))) && (_x__J1823 == (( !((_J1823 && _J1830) && _J1839)) && (((_J1823 && _J1830) && _J1839) || ((( !((x_0 + (-1.0 * x_10)) <= 12.0)) || ( !(( !((x_0 + (-1.0 * x_10)) <= 12.0)) || _EL_U_1801))) || _J1823))))) && (_x__J1830 == (( !((_J1823 && _J1830) && _J1839)) && (((_J1823 && _J1830) && _J1839) || (((20.0 <= (x_10 + (-1.0 * x_16))) || ( !((20.0 <= (x_10 + (-1.0 * x_16))) || _EL_U_1803))) || _J1830))))) && (_x__J1839 == (( !((_J1823 && _J1830) && _J1839)) && (((_J1823 && _J1830) && _J1839) || ((( !(( !((x_0 + (-1.0 * x_10)) <= 12.0)) || _EL_U_1801)) || ( !(( !(( !((x_0 + (-1.0 * x_10)) <= 12.0)) || _EL_U_1801)) || (_EL_U_1805 && ( !((20.0 <= (x_10 + (-1.0 * x_16))) || _EL_U_1803)))))) || _J1839))))));
_J1839 = _x__J1839;
x_2 = _x_x_2;
_J1830 = _x__J1830;
_J1823 = _x__J1823;
_EL_U_1803 = _x__EL_U_1803;
x_16 = _x_x_16;
x_10 = _x_x_10;
x_4 = _x_x_4;
_EL_U_1805 = _x__EL_U_1805;
x_13 = _x_x_13;
_EL_U_1801 = _x__EL_U_1801;
x_0 = _x_x_0;
x_14 = _x_x_14;
x_17 = _x_x_17;
x_18 = _x_x_18;
x_3 = _x_x_3;
x_22 = _x_x_22;
x_1 = _x_x_1;
x_5 = _x_x_5;
x_6 = _x_x_6;
x_9 = _x_x_9;
x_11 = _x_x_11;
x_12 = _x_x_12;
x_15 = _x_x_15;
x_7 = _x_x_7;
x_19 = _x_x_19;
x_8 = _x_x_8;
x_20 = _x_x_20;
x_21 = _x_x_21;
x_23 = _x_x_23;
}
}
|
the_stack_data/35661.c | // KASAN: use-after-free Write in padata_parallel_worker
// https://syzkaller.appspot.com/bug?id=81def6cbb5fbac9e86cb529131e43694bdaa7316
// status:open
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
intptr_t res = 0;
res = syscall(__NR_socket, 0x26, 5, 0);
if (res != -1)
r[0] = res;
*(uint16_t*)0x200003c0 = 0x26;
memcpy((void*)0x200003c2, "aead\000\000\000\000\000\000\000\000\000\000", 14);
*(uint32_t*)0x200003d0 = 0;
*(uint32_t*)0x200003d4 = 0;
memcpy((void*)0x200003d8, "pcrypt(gcm(aes))"
"\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000"
"\000\000\000\000\000\000\000\000\000\000\000\000",
64);
syscall(__NR_bind, r[0], 0x200003c0, 0x58);
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[1] = res;
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[2] = res;
*(uint16_t*)0x200000c0 = 0xa;
*(uint16_t*)0x200000c2 = htobe16(0x4e22);
*(uint32_t*)0x200000c4 = htobe32(0);
memcpy((void*)0x200000c8,
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
16);
*(uint32_t*)0x200000d8 = 0;
syscall(__NR_bind, r[2], 0x200000c0, 0x1c);
syscall(__NR_listen, r[2], 0);
*(uint16_t*)0x20000040 = 0xa;
*(uint16_t*)0x20000042 = htobe16(0x4e22);
*(uint32_t*)0x20000044 = htobe32(0);
*(uint64_t*)0x20000048 = htobe64(0);
*(uint64_t*)0x20000050 = htobe64(1);
*(uint32_t*)0x20000058 = 0;
syscall(__NR_sendto, r[1], 0, 0, 0x20004004, 0x20000040, 0x1c);
memcpy((void*)0x20000000, "tls\000", 4);
syscall(__NR_setsockopt, r[1], 6, 0x1f, 0x20000000, 0xc498ead121f97dd6);
*(uint16_t*)0x20000140 = 0x303;
*(uint16_t*)0x20000142 = 0x33;
memcpy((void*)0x20000144, "\xd4\x4e\xb8\xc7\x30\x8e\xc7\xc4", 8);
memcpy((void*)0x2000014c,
"\x44\x20\x65\x23\x89\x29\x35\x0a\xde\x91\x90\x0b\x51\xfc\x95\x34",
16);
memcpy((void*)0x2000015c, "\x6b\xdd\xa7\x20", 4);
memcpy((void*)0x20000160, "\x7e\xe5\x14\x30\xda\x3f\x51\xb3", 8);
syscall(__NR_setsockopt, r[1], 0x11a, 1, 0x20000140, 0x28);
syscall(__NR_sendto, r[1], 0x200005c0, 0xffffffffffffffc1, 0, 0,
0x1201000000003618);
return 0;
}
|
the_stack_data/231393442.c |
/*============================================================================
This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
Package, Release 3e, by John R. Hauser.
Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions, and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors may
be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=============================================================================*/
#ifdef HAVE_PLATFORM_H
#include "platform.h"
#endif
#if !defined(int32_t)
#include <stdint.h> /* C99 standard integers */
#endif
#ifndef softfloat_shiftRightJam32
uint32_t softfloat_shiftRightJam32( uint32_t a, uint_fast16_t dist )
{
return
(dist < 31) ? a>>dist | ((uint32_t) (a<<(-dist & 31)) != 0) : (a != 0);
}
#endif
|
the_stack_data/662893.c | #include<stdio.h>
#include<math.h>
int main(void){
int cont=0,aux=0,fa[5],fb[5];
double d=0;
char a[5000],b[5000],c[10000];
scanf("%[^\n]",c);
for(int i = 0; i-aux < 5000; i++){
if(c[i]!=';' && cont==0)
a[i] = c[i];
else{
if(c[i] == ';'){
cont++;
aux=i+1;
}else{
b[i-aux] = c[i];
}
}
}
if(cont!=1)
printf("FORMATO INVALIDO!\n");
else{
for(int i=0; i<5000; i++){
if(a[i]=='a' || a[i]=='A')
fa[0]++;
if(a[i]=='e' || a[i]=='E')
fa[1]++;
if(a[i]=='i' || a[i]=='I')
fa[2]++;
if(a[i]=='o' || a[i]=='O')
fa[3]++;
if(a[i]=='u' || a[i]=='U')
fa[4]++;
if(b[i]=='a' || b[i]=='A')
fb[0]++;
if(b[i]=='e' || b[i]=='E')
fb[1]++;
if(b[i]=='i' || b[i]=='I')
fb[2]++;
if(b[i]=='o' || b[i]=='O')
fb[3]++;
if(b[i]=='u' || b[i]=='U')
fb[4]++;
}
printf("(");
for(int i = 0; i < 5; i++){
printf("%d",fa[i]);
if(i<4)
printf(",");
else
printf(")");
}
printf("\n");
printf("(");
for(int i = 0; i < 5; i++){
printf("%d",fb[i]);
if(i<4)
printf(",");
else
printf(")");
}
printf("\n");
for(int i = 0; i < 5; i++){
d+=(fa[i]-fb[i])*(fa[i]-fb[i]);
}
d=sqrt(d);
printf("%.2lf\n",d);
}
return 0;
} |
the_stack_data/363346.c | #include <stdio.h>
main(){
int sum=1,num=0,max,i;
scanf("%d",&max);
for(i=0;i<max;i++){
scanf("%d",&num);
sum+=num-1;
}
printf("%d",sum);
} |
the_stack_data/104652.c | /*
* @Author: Huang Yuhui
* @Date: 2019-03-27 16:33:26
* @Last Modified by: Huang Yuhui
* @Last Modified time: 2019-03-27 16:59:21
*/
/*
* 程序设计题-题目描述如下:
*
* 请编写函数'fun',其功能是将一个数字字符串转换成其面值相同的长整型整数,可调用'strlen'函数求字符串的长度.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void NONO();
long fun(char *s)
{
int i, len, sum = 0;
len = strlen(s);
for (i = 0; i < len; i++)
{
//? 要把一个数字字符转化为相应的数字,只需要用它的'ASCII'码减去'48'即可,
//? 要把数字字符串转化为相应的数字,则要从左到右依次取出字符转化为相应的数字,乘'10'再加上下一位数字.
sum = sum * 10 + *s - 48;
s++;
}
return sum;
}
void main()
{
char s[10];
long r;
printf("请输入一个长度不超过9个字符的数字字符串 : ");
gets(s);
r = fun(s);
printf(" r = %ld\n", r);
NONO();
system("pause");
}
void NONO()
{ /* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *fp, *wf;
int i;
long r;
char s[10], *p;
fp = fopen("in.dat", "r");
wf = fopen("out.dat", "w");
for (i = 0; i < 10; i++)
{
fgets(s, 10, fp);
p = strchr(s, '\n');
if (p)
{
*p = 0;
}
r = fun(s);
fprintf(wf, "%ld\n", r);
}
fclose(fp);
fclose(wf);
}
/*The result be shown as followed:
请输入一个长度不超过9个字符的数字字符串 : 980109
r = 980109
Press any key to continue . . .
*/ |
the_stack_data/1135887.c | #include <stdlib.h>
int main()
{
char *p = NULL;
*p = 'c';
return 0;
}
|
the_stack_data/123114.c | //
// main.c
// heap
//
// Created by Ishan Arora on 04/04/20.
// Copyright © 2020 Ishan Arora. All rights reserved.
//
#include <stdio.h>
// This function is used to insert one element at a time in a heap.
// Check the readme of this section for the detailed logic of insert in simple english
void Insert(int A[],int n)
{
int temp,i=n;
temp=A[i];
while(i>1 && temp> A[i/2])
{
A[i]=A[i/2];
i=i/2;
}A[i]=temp;
}
// Deleting from a heap
// Check the readme of this section for the detailed logic of delete in simple english
int Delete(int A[], int n)
{
int x,i,j;
//Storing root element in a variable (This is the element getting deleted)
int val=A[1];
// Bringing the last element and making it as root
A[1]=A[n];
// This is the parent element(Root in this case)
i=1;
// This is the first child
j=2*i;
while(j<n-1)
{
int temp;
// Selecting the bigger child out of the 2 childs of a parent
if(A[j+1]>A[j])
{
j=j+1;
}
if(A[i]<A[j])
{
//swapping the parent with the bigger of children
temp=A[i];
A[i]=A[j];
A[j]=temp;
// New parent
i=j;
//New child
j=2*j;
}
else{
break;
}
}
return val;
}
int main(int argc, const char * argv[]) {
//First element of array as 0 as we want the index to start from 1.
//Lets assume that we have a heap of size 1 consisting of only 10
int H[]={0,14,15,5,20,30,8,40};
int i;
// For loop from 2 becuase firstly index is starting from one and secondly we have a heap of size one already.So we have to insert elements from 15 till 40
for(i=2;i<=7;i++)
{
Insert(H,i);
}
//for(i=7;i>1;i--)
// {
// Delete(H,i);
// }
for(i=1;i<=7;i++)
printf("%d ",H[i]);
printf("\n");
return 0; }
// insert code here...
|
the_stack_data/48574709.c | int main(void)
{
if (99.5 > 99.6 || 99) {
return 40 + (1 < 2 || 1 < 2) + (99 || 99);
} else {
return 0;
}
}
|
the_stack_data/150139845.c | #include <stdio.h>
int days_left(int d, int m) {
int days[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 25};
int days_left = 0;
for(int i = 0; i < 12; i++) {
if (i >= m - 1) {
days_left += days[i];
}
}
days_left -= d;
return days_left;
}
int main() {
int m, d;
while(scanf("%d %d", &m, &d) != EOF) {
if (m == 12) {
if (d == 24) printf("E vespera de natal!\n");
else if (d == 25) printf("E natal!\n");
if (d > 25) printf("Ja passou!\n");
} else {
printf("Faltam %d dias para o natal!\n", days_left(d, m));
}
}
return 0;
} |
the_stack_data/48575481.c | /* (C) Copyright 1993,1994 by Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Carnegie
* Mellon University not be used in advertising or publicity
* pertaining to distribution of the software without specific,
* written prior permission. Carnegie Mellon University makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <stdio.h>
#ifdef __OS2__
# include <io.h>
#endif
#if defined(__MSDOS__) || defined(__OS2__)
#define ERR(s, c) \
if (opterr) { \
char buff[3]; \
buff[0] = c; buff[1] = '\r'; buff[2] = '\n'; \
(void)write(2, av[0], strlen(av[0])); \
(void)write(2, s, strlen(s)); \
(void)write(2, buff, 3); \
}
#else /* __MSDOS__ */
#define ERR(s, c) \
if (opterr) { \
char buff[2]; \
buff[0] = c; buff[1] = '\n'; \
(void)write(2, av[0], strlen(av[0])); \
(void)write(2, s, strlen(s)); \
(void)write(2, buff, 2); \
}
#endif
int opterr = 1;
int optind = 1;
int optopt;
char *optarg;
/*
** Return options and their values from the command line.
** This comes from the AT&T public-domain getopt published in mod.sources
** (i.e., comp.sources.unix before the great Usenet renaming).
*/
int
getopt(int ac, char **av, char *opts)
{
extern char *strchr(const char *, int);
static int i = 1;
char *p;
/* Move to next value from argv? */
if (i == 1) {
if (optind >= ac ||
#if defined(__MSDOS__) || defined(__OS2__)
(av[optind][0] != '-' && av[optind][0] != '/')
#else
av[optind][0] != '-'
#endif
|| av[optind][1] == '\0')
return EOF;
if (strcmp(av[optind], "--") == 0) {
optind++;
return EOF;
}
}
/* Get next option character. */
if ((optopt = av[optind][i]) == ':'
|| (p = strchr(opts, optopt)) == NULL) {
ERR(": illegal option -- ", optopt);
if (av[optind][++i] == '\0') {
optind++;
i = 1;
}
return '?';
}
/* Snarf argument? */
if (*++p == ':') {
if (av[optind][i + 1] != '\0')
optarg = &av[optind++][i + 1];
else {
if (++optind >= ac) {
ERR(": option requires an argument -- ", optopt);
i = 1;
return '?';
}
optarg = av[optind++];
}
i = 1;
}
else {
if (av[optind][++i] == '\0') {
i = 1;
optind++;
}
optarg = NULL;
}
return optopt;
}
|
the_stack_data/90765782.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MTEXTSIZE 10
int
main(int argc, char* argv[]) {
int msgid;
struct msgbuf {
long mtype;
char mtext[MTEXTSIZE];
} mbuf;
if (argc != 2) {
fprintf(stderr, "Usage : %s msgid\n", argv[0]);
return 1;
}
msgid = atoi(argv[1]);
mbuf.mtype = 777;
memset(&mbuf.mtext, 0, MTEXTSIZE);
mbuf.mtext[0] = 'B';
if (msgsnd(msgid, &mbuf, MTEXTSIZE, 0) != 0) {
perror("msgsnd");
return 1;
}
return 0;
}
|
the_stack_data/9513688.c | #include <stdio.h>
int main(){
printf("OK\n");
return 0;
}
|
the_stack_data/165765657.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
void print_help();
typedef struct paren {
char *start;
struct paren *prev;
struct paren *next;
} paren;
char* hello_instrctions = "++++++++++[>+++++++>++++++++++>+++<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------."; // hello world
int main(int argc, char** argv) {
char* ip = hello_instrctions; // instruction pointer
short allow_incrementing_array = 0;
int start_length_of_data = 30000;
int max_length_of_data = 30000;
int c;
while((c = getopt(argc, argv, "hei:f:")) != -1) {
switch(c) {
case 'h':
print_help(argv[0]);
exit(0);
case 'e':
allow_incrementing_array = 1;
break;
case 'i':
start_length_of_data = atoi(optarg);
break;
case 'f':
max_length_of_data = atoi(optarg);
break;
case '?':
fprintf(stderr, "something fucked up\n");
exit(-1);
default:
fprintf(stderr, "argument parsing has gone wrong, please report the error the the creator of the module\n");
exit(-1);
}
}
// addjust arg array to read in options
argc -= optind;
argv += optind;
if(argc == 0) {
; // don't have to do anything just
} else if (argc == 1) {
FILE *file = fopen(argv[0], "r");
if(file == NULL) {
fprintf(stderr, "there was an error reading your instruction file: %s\n", argv[0]);
exit(1);
}
fseek(file, 0L, SEEK_END);
int file_size = ftell(file);
rewind(file);
int fd = fileno(file);
ip = mmap(NULL, file_size, PROT_READ, MAP_SHARED, fd, 0);
if(ip == MAP_FAILED) {
fprintf(stderr, "there was an error loading instructions into memory\n");
exit(1);
}
} else {
fprintf(stderr, "please specify only one code file\n");
exit(1);
}
// parentheses stack
paren *head = NULL;
paren *tail = NULL;
int curr_length_of_data = start_length_of_data;
unsigned char *data = calloc(sizeof(char), curr_length_of_data);
if(data == NULL) {
fprintf(stderr, "couldn't allocate enough memory for data\n");
exit(1);
}
int data_index = 0; // to be called data pointer but will work as an index for implementation purposes
int skipping = 0; // 0 for when executing instruction inside parens, 1 for when trying to find a matching parenthesis
int depth = 0; // amount of parenthesis deep that we're in when trying to skip
while (*ip != '\0' || *ip == EOF) {
// check if we are trying to locate parentheses
if(skipping == 1) {
if(*ip == '[') {
depth++;
} else if(*ip == ']') {
depth--;
if(depth == 0) {
skipping = 0;
}
}
ip++;
continue;
}
if(*ip == '+') { // increment data value
data[data_index]++;
} else if (*ip == '-') { // decrement data value
data[data_index]--;
} else if (*ip == '>') { // move the data pointer to the right one
data_index++;
if(data_index == curr_length_of_data) {
if(!allow_incrementing_array) {
fprintf(stderr, "Data pointer as reached an invalid location\n");
exit(1);
}
if(curr_length_of_data >= max_length_of_data) {
fprintf(stderr, "Data pointer as reached a value larger than the maximum list size\n");
exit(1);
}
// we need to increase the size of the array and continue execution
int new_data_size = (curr_length_of_data * 2 <= max_length_of_data)? curr_length_of_data * 2: max_length_of_data;
char *new_data = calloc(sizeof(char), new_data_size);
memcpy(new_data, data, curr_length_of_data);
curr_length_of_data = new_data_size;
data = new_data;
}
} else if (*ip == '<') { // move the data pointer to the left one
data_index--;
if(data_index < 0) {
fprintf(stderr, "Data pointer has reached a negative value\n");
exit(1);
}
} else if (*ip == '.') { // print current data value to stdout as a char
printf("%c", data[data_index]);
} else if (*ip == ',') { // get value from stdout and place it in current data locations
scanf(" %c", (char *)(data + data_index));
} else if (*ip == '[') { // if data value is 0 skip to matching paren otherwise execute code inside as normal
if(data[data_index] == 0) {
skipping = 1;
depth = 1;
} else {
paren *p = (paren *)malloc(sizeof(paren));
p->start = ip;
p->next = NULL;
p->prev = tail;
if(head == NULL) {
head = p;
} else {
tail->next = p;
}
tail = p;
}
} else if (*ip == ']') { // if data value is non 0 skip to matching opening paren otherwise continue
if(head == NULL) {
fprintf(stderr, "An extra closing paren was found\n");
exit(1);
}
if(data[data_index] == 0) {
if(head == tail) {
free(head);
head = NULL;
tail = NULL;
} else {
tail = tail->prev;
free(tail->next);
}
} else {
ip = tail->start; //incremented at the end, so the the paren isn't re-checked
}
}
ip++;
}
if(head != NULL || skipping == 1) {
fprintf(stderr, "End of execution was reached, and not enough closing parens where found\n");
exit(1);
} else {
exit(0);
}
}
void print_help(char *exec_name) {
printf("Usage: %s [-h] [-e] [-i inicial_data_length] [-f final_data_length] [file_path]\n", exec_name);
printf("\n");
printf("-h\tprint help information displayed here\n");
printf("-e\tallow for data array to be extended when filled up until it reaches final_data_length\n");
printf("-i\tset initial size of data array. Default to 30,000\n");
printf("-f\tset final size of data array after which expanding is not allowed, only relevant if extension is enabled\n");
printf("file_path:\tfile to read instructions from\n");
}
|
the_stack_data/231391911.c | /* PR c/20043 */
/* { dg-do compile } */
/* { dg-options "-std=gnu99" } */
extern void f0 (int *);
extern void f0 (int *__restrict);
extern void f1 (int *__restrict);
extern void f1 (int *);
typedef union { int *i; long *l; } U2
__attribute__((transparent_union));
extern void f2 (U2);
extern void f2 (int *);
typedef union { int *__restrict i; long *__restrict l; } U3
__attribute__((transparent_union));
extern void f3 (U3);
extern void f3 (int *__restrict);
extern void f4 (U3);
extern void f4 (int *);
extern void f5 (U2);
extern void f5 (int *__restrict);
typedef union { long *l; int *i; } U6
__attribute__((transparent_union));
extern void f6 (U6);
extern void f6 (int *);
typedef union { long *__restrict l; int *__restrict i; } U7
__attribute__((transparent_union));
extern void f7 (U7);
extern void f7 (int *__restrict);
extern void f8 (U7);
extern void f8 (int *);
extern void f9 (U6);
extern void f9 (int *__restrict);
extern void f10 (U2);
extern void f11 (U3);
extern void f12 (U6);
extern void f13 (U7);
int i;
long l;
int
main (void)
{
f0 (&i);
f0 (&l); /* { dg-warning "passing argument 1 of 'f0' from incompatible pointer type" } */
f1 (&i);
f1 (&l); /* { dg-warning "passing argument 1 of 'f1' from incompatible pointer type" } */
f2 (&i);
f2 (&l); /* { dg-warning "passing argument 1 of 'f2' from incompatible pointer type" } */
f3 (&i);
f3 (&l); /* { dg-warning "passing argument 1 of 'f3' from incompatible pointer type" } */
f4 (&i);
f4 (&l); /* { dg-warning "passing argument 1 of 'f4' from incompatible pointer type" } */
f5 (&i);
f5 (&l); /* { dg-warning "passing argument 1 of 'f5' from incompatible pointer type" } */
f6 (&i);
f6 (&l); /* { dg-warning "passing argument 1 of 'f6' from incompatible pointer type" } */
f7 (&i);
f7 (&l); /* { dg-warning "passing argument 1 of 'f7' from incompatible pointer type" } */
f8 (&i);
f8 (&l); /* { dg-warning "passing argument 1 of 'f8' from incompatible pointer type" } */
f9 (&i);
f9 (&l); /* { dg-warning "passing argument 1 of 'f9' from incompatible pointer type" } */
f10 (&i);
f10 (&l);
f11 (&i);
f11 (&l);
f12 (&i);
f12 (&l);
f13 (&i);
f13 (&l);
return 0;
}
/* { dg-message "note: expected '\[^\n'\]*' but argument is of type '\[^\n'\]*'" "note: expected" { target *-*-* } 0 } */
|
the_stack_data/149605.c | /*
* This file is part of uudeview, the simple and friendly multi-part multi-
* file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may
* be contacted at [email protected]
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/*
* The TCL Interface of UUDeview
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_TCL) || defined(HAVE_TK)
#ifdef SYSTEM_WINDLL
#include <windows.h>
#endif
#ifdef SYSTEM_OS2
#include <os2.h>
#endif
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_TK
#include <tk.h>
#else
#include <tcl.h>
#endif
/*
* The following variable is a special hack that is needed in order for
* Sun shared libraries to be used for Tcl.
*/
extern int matherr();
int *tclDummyMathPtr = (int *) matherr;
#include <uudeview.h>
#include <uuint.h>
#include <fptools.h>
/*
* As Windows DLL, we need a DllEntryPoint
*/
#ifdef SYSTEM_WINDLL
BOOL _export WINAPI
DllEntryPoint (HINSTANCE hInstance, DWORD seginfo,
LPVOID lpCmdLine)
{
/* Don't do anything, so just return true */
return TRUE;
}
#endif
/*
* Declare external functions as __cdecl for Watcom C
*/
#ifdef __WATCOMC__
#pragma aux (__cdecl) Tcl_Eval
#pragma aux (__cdecl) Tcl_GetVar
#pragma aux (__cdecl) Tcl_SetVar
#pragma aux (__cdecl) Tcl_AppendResult
#pragma aux (__cdecl) Tcl_SetResult
#pragma aux (__cdecl) Tcl_CreateCommand
#endif
/*
* cvs version
*/
char * uutcl_id = "$Id: uutcl.c,v 1.14 2002/03/06 13:52:45 fp Exp $";
/*
* data for our Callbacks
*/
static struct uutclcbdata {
Tcl_Interp *interp;
char tclproc[256];
} theDMcbdata, theBusycbdata;
/*
* Don't let Uu_Init initialize us twice
*/
static int uu_AlreadyInitialized = 0;
/*
* mail and news software
*/
#ifdef PROG_INEWS
char * uue_inewsprog = PROG_INEWS;
#else
char * uue_inewsprog = NULL;
#endif
#ifdef PROG_MAILER
char * uue_mailprog = PROG_MAILER;
#else
char * uue_mailprog = NULL;
#endif
#ifdef MAILER_NEEDS_SUBJECT
int uue_mpsubject = 1;
#else
int uue_mpsubject = 0;
#endif
/*
* Mail or Post a file. Remember to keep in sync with uuenview.c
*/
static int
SendAFile (Tcl_Interp *interp,
FILE *infile, char *infname,
int encoding, int linperfile,
char *outfname, char *towhom,
char *subject, char *from,
char *replyto, int isemail)
{
char *command, *rcptlist, *ptr;
FILE *thepipe, *theifile;
int len, count, res, part;
if (towhom==NULL ||
(outfname==NULL&&infname==NULL) || (infile&&infname==NULL) ||
(encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
Tcl_SetResult (interp, "oops: Parameter check failed in SendAFile()",
TCL_STATIC);
return UURET_ILLVAL;
}
#ifndef HAVE_POPEN
Tcl_SetResult (interp, "error: Your system does not support sending of files",
TCL_STATIC);
return UURET_ILLVAL;
#else
if (isemail && (uue_mailprog == NULL || *uue_mailprog == '\0')) {
Tcl_SetResult (interp, "error: Cannot Email file: option not configured",
TCL_STATIC);
return UURET_ILLVAL;
}
else if (!isemail && (uue_inewsprog == NULL || *uue_inewsprog == '\0')) {
Tcl_SetResult (interp, "error: Cannot Post file: option not configured",
TCL_STATIC);
return UURET_ILLVAL;
}
len = strlen ((isemail)?uue_mailprog:uue_inewsprog) +
((uue_mpsubject)?strlen(subject):0) +
((isemail)?0:strlen(towhom)) + 32;
if ((command = (char *) malloc (len)) == NULL) {
Tcl_SetResult (interp, "error: Out of memory allocating some bytes",
TCL_STATIC);
return UURET_NOMEM;
}
if ((rcptlist = (char *) malloc (strlen (towhom) + 16)) == NULL) {
Tcl_SetResult (interp, "error: Out of memory allocating some bytes",
TCL_STATIC);
_FP_free (command);
return UURET_NOMEM;
}
if (isemail) {
if (uue_mpsubject)
sprintf (command, "%s -s \"%s\"", uue_mailprog, subject);
else
sprintf (command, "%s", uue_mailprog);
/*
* Attach list of recipients to mailer command and compose another list
* of recipients
*/
count = 0;
rcptlist[0] = '\0';
ptr = _FP_strtok (towhom, ",; ");
while (ptr) {
strcat (command, " ");
strcat (command, ptr);
if (count++)
strcat (rcptlist, ",");
strcat (rcptlist, ptr);
ptr = _FP_strtok (NULL, ",; ");
}
}
else {
sprintf (command, "%s", uue_inewsprog);
count = 0;
rcptlist[0] = '\0';
ptr = _FP_strtok (towhom, ";, ");
while (ptr) {
if (count++)
strcat (rcptlist, ",");
strcat (rcptlist, ptr);
ptr = _FP_strtok (NULL, ";, ");
}
}
if (from && *from == '\0') {
from = NULL;
}
if (subject && *subject == '\0') {
subject = NULL;
}
if (replyto && *replyto == '\0') {
replyto = NULL;
}
/*
* Get going ...
*/
if (infile == NULL) {
if ((theifile = fopen (infname, "rb")) == NULL) {
_FP_free (rcptlist);
_FP_free (command);
return UURET_IOERR;
}
}
else {
theifile = infile;
}
for (part=1; !feof (theifile); part++) {
if ((thepipe = popen (command, "w")) == NULL) {
if (infile==NULL) fclose (theifile);
_FP_free (rcptlist);
_FP_free (command);
return UURET_IOERR;
}
if (UUGetOption(UUOPT_VERBOSE, NULL, NULL, 0)) {
#if 0
fprintf (stderr, "%s part %03d of %s to %s ... ",
(isemail)?"mailing":"posting",
part, (infname)?infname:outfname,
rcptlist);
fflush (stderr);
#endif
}
res = UUE_PrepPartialExt (thepipe, theifile, infname, encoding,
outfname, 0, part, linperfile, 0,
rcptlist, from, subject, replyto,
isemail);
#if 0
if (UUGetOption (UUOPT_VERBOSE, NULL, NULL, 0)) {
if (res == UURET_OK)
fprintf (stderr, "ok.\n");
else
fprintf (stderr, "%s\n", UUstrerror (res));
}
#endif
pclose (thepipe);
if (res != UURET_OK) {
if (infile == NULL) fclose (theifile);
_FP_free (rcptlist);
_FP_free (command);
return res;
}
}
if (infile == NULL) fclose (theifile);
_FP_free (rcptlist);
_FP_free (command);
return UURET_OK;
#endif
}
/*
* Display a Message in a dialog box
*/
static void
uutcl_DisplayMessage (void *param, char *message, int level)
{
struct uutclcbdata *data = (struct uutclcbdata *) param;
char tmpstring[2048];
if (data->interp && *data->tclproc) {
sprintf (tmpstring, "%s %d {%s}\n", data->tclproc, level, message);
Tcl_Eval (data->interp, tmpstring);
}
}
/*
* Our Busy Callback
*/
static int
uutcl_BusyCallback (void *param, uuprogress *progress)
{
struct uutclcbdata *data = (struct uutclcbdata *) param;
if (data->interp && *data->tclproc) {
Tcl_Eval (data->interp, data->tclproc);
}
return 0;
}
/*
* exchage variables with the interpreter
*/
static void
uutcl_UpdateParameter (Tcl_Interp *interp)
{
char *cval;
if ((cval = Tcl_GetVar (interp, "OptionFast", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_FAST, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionBracket", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_BRACKPOL, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionDesperate",TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_DESPERATE, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionDebug", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_DEBUG, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionDumbness", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_DUMBNESS, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionUsetext", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_USETEXT, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "SaveFilePath", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_SAVEPATH, 0, cval);
if ((cval = Tcl_GetVar (interp, "OptionRemove", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_REMOVE, atoi (cval), NULL);
if ((cval = Tcl_GetVar (interp, "OptionMoreMime", TCL_GLOBAL_ONLY))!=NULL)
UUSetOption (UUOPT_MOREMIME, atoi (cval), NULL);
}
/*
* configuration info
*/
static int
uutcl_HaveArg (int argc, char *argv[], char *string)
{
int index;
for (index=1; index<argc; index++) {
if (_FP_stricmp (argv[index], string) == 0)
return 1;
}
return 0;
}
static int UUTCLFUNC
uutcl_Info (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char temp[64], version[64];
if (argc==1 || uutcl_HaveArg (argc, argv, "version")) {
UUGetOption (UUOPT_VERSION, NULL, version, 64);
sprintf (temp, " { version %s } ", version);
Tcl_AppendResult (interp, temp, NULL);
}
if (argc==1 || uutcl_HaveArg (argc, argv, "have_tcl"))
#ifdef HAVE_TCL
Tcl_AppendResult (interp, " { have_tcl 1 } ", NULL);
#else
Tcl_AppendResult (interp, " { have_tcl 0 } ", NULL);
#endif
if (argc==1 || uutcl_HaveArg (argc, argv, "have_tk"))
#ifdef HAVE_TK
Tcl_AppendResult (interp, " { have_tk 1 } ", NULL);
#else
Tcl_AppendResult (interp, " { have_tk 0 } ", NULL);
#endif
if (argc==1 || uutcl_HaveArg (argc, argv, "have_mail")) {
#ifdef PROG_MAILER
if (*PROG_MAILER)
Tcl_AppendResult (interp, " { have_mail 1 } ", NULL);
else
Tcl_AppendResult (interp, " { have_mail 0 } ", NULL);
#else
Tcl_AppendResult (interp, " { have_mail 0 } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "prog_mailer")) {
#ifdef PROG_MAILER
sprintf (temp, " { prog_mailer \"%s\" } ", PROG_MAILER);
Tcl_AppendResult (interp, temp, NULL);
#else
Tcl_AppendResult (interp, " { prog_mailer (none) } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "have_news")) {
#ifdef HAVE_NEWS
Tcl_AppendResult (interp, " { have_news 1 } ", NULL);
#else
Tcl_AppendResult (interp, " { have_news 0 } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "prog_inews")) {
#ifdef PROG_INEWS
sprintf (temp, " { prog_inews \"%s\" } ", PROG_INEWS);
Tcl_AppendResult (interp, temp, NULL);
#else
Tcl_AppendResult (interp, " { prog_inews (none) } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "domainname")) {
#ifdef DOMAINNAME
sprintf (temp, " { domainname %s } ", DOMAINNAME);
Tcl_AppendResult (interp, temp, NULL);
#else
Tcl_AppendResult (interp, " { domainname (none) } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "nntpserver")) {
#ifdef NNTPSERVER
sprintf (temp, " { nntpserver %s } ", NNTPSERVER);
Tcl_AppendResult (interp, temp, NULL);
#else
Tcl_AppendResult (interp, " { nntpserver (none) } ", NULL);
#endif
}
if (argc==1 || uutcl_HaveArg (argc, argv, "need_nntpserver")) {
#ifdef NEED_NNTPSERVER
Tcl_AppendResult (interp, " { need_nntpserver 1 } ", NULL);
#else
Tcl_AppendResult (interp, " { need_nntpserver 0 } ", NULL);
#endif
}
return TCL_OK;
}
static int UUTCLFUNC
uutcl_SetMessageProc (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
uutcl_UpdateParameter (interp);
if (argc != 2) {
sprintf (tmpstring,
"wrong # args: should be \"%s procedure\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
theDMcbdata.interp = interp;
strcpy (theDMcbdata.tclproc, argv[1]);
return TCL_OK;
}
static int UUTCLFUNC
uutcl_SetBusyProc (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
long msecs;
uutcl_UpdateParameter (interp);
if (argc != 3) {
sprintf (tmpstring,
"wrong # args: should be \"%s procedure msecs\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((msecs = (long) atoi (argv[2])) > 0) {
UUSetBusyCallback (&theBusycbdata, uutcl_BusyCallback, msecs);
}
theBusycbdata.interp = interp;
strcpy (theBusycbdata.tclproc, argv[1]);
return TCL_OK;
}
static int UUTCLFUNC
uutcl_GetProgressInfo (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
uuprogress progress;
char tmpstring[32];
if (UUGetOption (UUOPT_PROGRESS, NULL,
(char *) &progress, sizeof (uuprogress)) != 0) {
Tcl_SetResult (interp, "oops, could not get info?", TCL_STATIC);
return TCL_ERROR;
}
sprintf (tmpstring, "%d", progress.action);
Tcl_AppendElement (interp, tmpstring);
Tcl_AppendElement (interp, progress.curfile);
sprintf (tmpstring, "%d", progress.partno);
Tcl_AppendElement (interp, tmpstring);
sprintf (tmpstring, "%d", progress.numparts);
Tcl_AppendElement (interp, tmpstring);
sprintf (tmpstring, "%d", progress.percent);
Tcl_AppendElement (interp, tmpstring);
return TCL_OK;
}
static int UUTCLFUNC
uutcl_GetListOfFiles (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[1024], t2[42];
int count=0, index=0;
uulist *iter;
uutcl_UpdateParameter (interp);
while ((iter=UUGetFileListItem(count))) {
if (((iter->state & UUFILE_OK) ||
UUGetOption (UUOPT_DESPERATE, NULL, NULL, 0)) && iter->filename) {
sprintf (tmpstring, " { %d %d {%s} %s %s {",
count, iter->state, iter->filename,
(iter->mimetype)?iter->mimetype:"{}",
(iter->uudet == UU_ENCODED) ? "UUdata " :
(iter->uudet == B64ENCODED) ? "Base64 " :
(iter->uudet == XX_ENCODED) ? "XXdata " :
(iter->uudet == BH_ENCODED) ? "Binhex " :
(iter->uudet == YENC_ENCODED) ? "yEnc" : "Text");
if (iter->haveparts) {
sprintf (t2, "%s%s%d ",
(iter->begin&&iter->begin==iter->haveparts[0])?"begin ":"",
(iter->end &&iter->end == iter->haveparts[0])?"end " :"",
iter->haveparts[0]);
strcat (tmpstring, t2);
for (index=1; iter->haveparts[index]; index++) {
sprintf (t2, "%s%s%d ",
(iter->begin==iter->haveparts[index]) ? "begin " : "",
(iter->end == iter->haveparts[index]) ? "end " : "",
iter->haveparts[index]);
strcat (tmpstring, t2);
}
}
if (iter->state & UUFILE_OK)
strcat (tmpstring, "OK");
strcat (tmpstring, "} }");
Tcl_AppendResult (interp, tmpstring, NULL);
}
count++;
}
return TCL_OK;
}
/*
* Load an encoded file
*/
static int UUTCLFUNC
uutcl_LoadFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
int res;
uutcl_UpdateParameter (interp);
if (argc != 2) {
sprintf (tmpstring,
"wrong # args: should be \"%s filename\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((res = UULoadFile (argv[1], NULL, 0)) != UURET_OK) {
sprintf (tmpstring, "couldn't read %s: %s (%s)",
argv[1], UUstrerror (res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
return TCL_OK;
}
/*
* Decode A File. This function overwrites files without asking, because
* this was already done by the script
*/
static int UUTCLFUNC
uutcl_DecodeFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
uulist *iter;
int res;
uutcl_UpdateParameter (interp);
if (argc < 2 || argc > 3) {
sprintf (tmpstring,
"wrong # args: should be \"%s number ?targetname?\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) {
Tcl_SetResult (interp, "invalid file number", TCL_STATIC);
return TCL_ERROR;
}
if ((res = UUDecodeFile (iter, (argc==3)?argv[2]:NULL)) != UURET_OK) {
sprintf (tmpstring, "Error while decoding %s (%s): %s (%s)",
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
UUstrerror (res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
return TCL_OK;
}
static int UUTCLFUNC
uutcl_GetTempFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
uulist *iter;
int res;
uutcl_UpdateParameter (interp);
if (argc != 2) {
sprintf (tmpstring,
"wrong # args: should be \"%s number\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) {
Tcl_SetResult (interp, "invalid file number", TCL_STATIC);
return TCL_ERROR;
}
if ((res = UUDecodeToTemp (iter)) != UURET_OK) {
sprintf (tmpstring, "Error while decoding %s (%s): %s (%s)",
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
UUstrerror (res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if (iter->binfile == NULL) {
Tcl_SetResult (interp, "unknown error while decoding", TCL_STATIC);
return TCL_ERROR;
}
Tcl_SetResult (interp, iter->binfile, TCL_VOLATILE);
return TCL_OK;
}
/*
* InfoFile takes two parameters: the number of the file to get info for,
* and the name of the text widget to send the text to
*/
struct uuInfoCBData {
Tcl_Interp *interp;
char * widget;
};
static int
uutcl_InfoCallback (void *param, char *string)
{
struct uuInfoCBData *data = (struct uuInfoCBData *) param;
char tmpstring[1024], *p;
sprintf (tmpstring, "%s insert end \"", data->widget);
p = tmpstring + strlen (tmpstring);
while (*string) {
switch (*string) {
case '"':
case '\\':
case '[':
case ']':
case '$':
*p++ = '\\';
/* fallthrough */
default:
*p++ = *string;
}
string++;
}
*p++ = '"';
*p++ = '\0';
if (Tcl_Eval (data->interp, tmpstring) != TCL_OK)
return 1;
return 0;
}
static int UUTCLFUNC
uutcl_InfoFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
struct uuInfoCBData data;
char tmpstring[256];
uulist *iter;
int res;
uutcl_UpdateParameter (interp);
if (argc != 3) {
sprintf (tmpstring,
"wrong # args: should be \"%s number textwidget\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) {
Tcl_SetResult (interp, "invalid file number", TCL_STATIC);
return TCL_ERROR;
}
sprintf (tmpstring, "%s delete 1.0 end", argv[2]);
if (Tcl_Eval (interp, tmpstring) != TCL_OK)
return TCL_ERROR;
data.interp = interp;
data.widget = argv[2];
if ((res = UUInfoFile (iter, &data, uutcl_InfoCallback)) != UURET_OK) {
sprintf (tmpstring, "Error while getting info for %s (%s): %s (%s)",
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
UUstrerror (res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
return TCL_OK;
}
/*
* ShowFile takes two parameters: the number of the file to get info for,
* and the name of the text widget to send the text to. We might have to
* decode the file before we can show it.
* Hey, the above callback worked so well, let's use it again!
*/
static int UUTCLFUNC
uutcl_ListFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
uulist *iter;
struct uuInfoCBData data;
char tmpstring[1024];
FILE *inpfile;
int res;
uutcl_UpdateParameter (interp);
if (argc != 3) {
sprintf (tmpstring,
"wrong # args: should be \"%s number textwidget\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) {
Tcl_SetResult (interp, "invalid file number", TCL_STATIC);
return TCL_ERROR;
}
if ((res = UUDecodeToTemp (iter)) != UURET_OK) {
sprintf (tmpstring, "Error while decoding %s (%s): %s (%s)",
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
UUstrerror(res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
sprintf (tmpstring, "%s delete 1.0 end", argv[2]);
if (Tcl_Eval (interp, tmpstring) != TCL_OK)
return TCL_ERROR;
if (iter->binfile==NULL || (inpfile=fopen (iter->binfile, "r"))==NULL) {
Tcl_SetResult (interp, "couldn't read file", TCL_STATIC);
return TCL_ERROR;
}
if ((inpfile = fopen (iter->binfile, "r")) == NULL) {
sprintf (tmpstring, "Could not open temp file %s of %s (%s): %s",
iter->binfile,
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
strerror (errno));
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
data.interp = interp;
data.widget = argv[2];
while (!feof (inpfile)) {
if (_FP_fgets (tmpstring, 512, inpfile) == NULL)
break;
if (ferror (inpfile))
break;
if (uutcl_InfoCallback (&data, tmpstring))
break;
}
if (ferror (inpfile)) {
sprintf (tmpstring, "Error while reading from temp file %s of %s (%s): %s",
iter->binfile,
(iter->filename) ? iter->filename : "",
(iter->subfname) ? iter->subfname : "",
strerror (errno));
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
fclose (inpfile);
return TCL_ERROR;
}
fclose (inpfile);
return TCL_OK;
}
static int UUTCLFUNC
uutcl_Rename (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
char tmpstring[256];
uulist *iter;
int res;
uutcl_UpdateParameter (interp);
if (argc != 3) {
sprintf (tmpstring,
"wrong # args: should be \"%s number newname\"",
argv[0]);
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
if (*argv[2] == '\0') {
Tcl_SetResult (interp, "illegal file name", TCL_STATIC);
return TCL_ERROR;
}
if ((iter = UUGetFileListItem (atoi (argv[1]))) == NULL) {
Tcl_SetResult (interp, "invalid file number", TCL_STATIC);
return TCL_ERROR;
}
if ((res = UURenameFile (iter, argv[2])) != UURET_OK) {
sprintf (tmpstring,
"could not rename %s to %s: %s (%s)",
(iter->filename) ? iter->filename : "",
argv[2], UUstrerror (res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, tmpstring, TCL_VOLATILE);
return TCL_ERROR;
}
return TCL_OK;
}
/*
* clean up memory and temp files
*/
static int UUTCLFUNC
uutcl_CleanUp (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
uutcl_UpdateParameter (interp);
UUCleanUp ();
return TCL_OK;
}
/*
* Generic function to extract the encoding and linperfile parameters
* from the command's command line
*/
static int
uutcl_GetEncodeParams (Tcl_Interp *interp,
int argc, char *argv[],
int argv1, int *encoding,
int argv2, int *linperfile)
{
if (argv2 && argv2 < argc) {
*linperfile = atoi (argv[argv2]);
if (*linperfile != 0 && *linperfile < 200) {
Tcl_SetResult (interp, "illegal number of lines per file", TCL_STATIC);
return TCL_ERROR;
}
}
if (argv1 && argv1 < argc) {
switch (*argv[argv1]) {
case '0':
case 'u':
case 'U':
*encoding = UU_ENCODED;
break;
case '1':
case 'x':
case 'X':
*encoding = XX_ENCODED;
break;
case '2':
case 'b':
case 'B':
*encoding = B64ENCODED;
break;
case '3':
case 't':
case 'T':
*encoding = PT_ENCODED;
break;
case '4':
case 'q':
case 'Q':
*encoding = QP_ENCODED;
break;
case '5':
case 'y':
case 'Y':
*encoding = YENC_ENCODED;
break;
default:
Tcl_SetResult (interp, "invalid encoding method", TCL_STATIC);
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
* Encode and store in a file.
* Syntax:
* uu_EncodeToFile source path \
* [ dest subject intro lines encoding from replyto]
*
* Most arguments are just for compatibilty with the other encoding procs.
*/
static int UUTCLFUNC
uutcl_EncodeToFile (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
int encoding=UU_ENCODED, linperfile=0, res;
char errstring[256], olddir[256];
if (argc < 3 || argc > 10) {
Tcl_SetResult (interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
uutcl_UpdateParameter (interp);
if (uutcl_GetEncodeParams (interp, argc, argv,
7, &encoding,
6, &linperfile) != TCL_OK)
return TCL_ERROR;
UUGetOption (UUOPT_SAVEPATH, NULL, olddir, 256);
UUSetOption (UUOPT_SAVEPATH, 0, argv[2]);
if ((res = UUEncodeToFile (NULL, argv[1], encoding,
(argc>3) ? argv[3] : NULL,
(argc>2) ? argv[2] : NULL,
linperfile)) != UURET_OK) {
UUSetOption (UUOPT_SAVEPATH, 0, olddir);
sprintf (errstring, "error while encoding %s to file: %s (%s)", argv[1],
UUstrerror(res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, errstring, TCL_VOLATILE);
return TCL_ERROR;
}
UUSetOption (UUOPT_SAVEPATH, 0, olddir);
return TCL_OK;
}
/*
* Encode and send by email
* Syntax:
* uu_EncodeToMail source addr \
* [ dest subject intro lines encoding from replyto ]
*
* addr can be a single address or a list of addresses
*/
static int UUTCLFUNC
uutcl_EncodeToMail (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
int encoding=UU_ENCODED, linperfile=0, res;
char errstring[256];
if (argc < 3 || argc > 10) {
Tcl_SetResult (interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
uutcl_UpdateParameter (interp);
if (uutcl_GetEncodeParams (interp, argc, argv,
7, &encoding,
6, &linperfile) != TCL_OK)
return TCL_ERROR;
if ((res = SendAFile (interp, NULL, argv[1], encoding, linperfile,
/* outfname */ (argc>3) ? argv[3] : NULL,
/* towhom */ argv[2],
/* subject */ (argc>4) ? argv[4] : NULL,
/* from */ (argc>8) ? argv[8] : NULL,
/* replyto */ (argc>9) ? argv[9] : NULL,
1)) != UURET_OK) {
/*
* If res==UURET_ILLVAL, SendAMail has already filled in the result
*/
if (res != UURET_ILLVAL) {
sprintf (errstring, "error while emailing %s: %s (%s)", argv[1],
UUstrerror(res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, errstring, TCL_VOLATILE);
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
* Encode and post to the news
* Syntax:
* uu_EncodeToNews source addr \
* [ dest subject intro lines encoding from replyto ]
*
* addr can be a single newsgroup or a list of newsgroups
*/
static int UUTCLFUNC
uutcl_EncodeToNews (ClientData clientData, Tcl_Interp *interp,
int argc, char *argv[])
{
int encoding=UU_ENCODED, linperfile=0, res;
char errstring[256];
if (argc < 3 || argc > 10) {
Tcl_SetResult (interp, "wrong # args", TCL_STATIC);
return TCL_ERROR;
}
uutcl_UpdateParameter (interp);
if (uutcl_GetEncodeParams (interp, argc, argv,
7, &encoding,
6, &linperfile) != TCL_OK)
return TCL_ERROR;
if ((res = SendAFile (interp, NULL, argv[1], encoding, linperfile,
/* outfname */ (argc>3) ? argv[3] : NULL,
/* towhom */ argv[2],
/* subject */ (argc>4) ? argv[4] : NULL,
/* from */ (argc>8) ? argv[8] : NULL,
/* replyto */ (argc>9) ? argv[9] : NULL,
0)) != UURET_OK) {
/*
* If res==UURET_ILLVAL, SendAMail has already filled in the result
*/
if (res != UURET_ILLVAL) {
sprintf (errstring, "error while posting %s: %s (%s)", argv[1],
UUstrerror(res),
(res==UURET_IOERR)?
strerror(UUGetOption(UUOPT_ERRNO,NULL,NULL,0)):"");
Tcl_SetResult (interp, errstring, TCL_VOLATILE);
}
return TCL_ERROR;
}
return TCL_OK;
}
/*
* Initialize the TCL package. The only function that is exported from
* this module.
*/
int UUTCLEXPORT UUTCLFUNC
Uu_Init (Tcl_Interp *interp)
{
char tmp[32];
/*
* Check whether we are already initialized
*/
if (uu_AlreadyInitialized++)
return TCL_OK;
/*
* Initialize decoding engine
*/
if (UUInitialize () != UURET_OK) {
Tcl_SetResult (interp, "Error initializing decoding engine", TCL_STATIC);
return TCL_ERROR;
}
/*
* register commands
*/
Tcl_CreateCommand (interp, "uu_Info", uutcl_Info, NULL, NULL);
Tcl_CreateCommand (interp, "uu_SetMessageProc",uutcl_SetMessageProc,
NULL, NULL);
Tcl_CreateCommand (interp, "uu_SetBusyProc", uutcl_SetBusyProc,NULL,NULL);
Tcl_CreateCommand (interp, "uu_GetProgressInfo",uutcl_GetProgressInfo,
NULL, NULL);
Tcl_CreateCommand (interp, "uu_GetListOfFiles",uutcl_GetListOfFiles,
NULL, NULL);
Tcl_CreateCommand (interp, "uu_LoadFile", uutcl_LoadFile, NULL, NULL);
Tcl_CreateCommand (interp, "uu_DecodeFile", uutcl_DecodeFile, NULL, NULL);
Tcl_CreateCommand (interp, "uu_GetTempFile", uutcl_GetTempFile,NULL,NULL);
Tcl_CreateCommand (interp, "uu_InfoFile", uutcl_InfoFile, NULL, NULL);
Tcl_CreateCommand (interp, "uu_ListFile", uutcl_ListFile, NULL, NULL);
Tcl_CreateCommand (interp, "uu_Rename", uutcl_Rename, NULL, NULL);
Tcl_CreateCommand (interp, "uu_CleanUp", uutcl_CleanUp, NULL, NULL);
Tcl_CreateCommand (interp, "uu_EncodeToFile", uutcl_EncodeToFile,NULL,NULL);
Tcl_CreateCommand (interp, "uu_EncodeToMail", uutcl_EncodeToMail,NULL,NULL);
Tcl_CreateCommand (interp, "uu_EncodeToNews", uutcl_EncodeToNews,NULL,NULL);
/*
* our message-handling function and busy callback
*/
theDMcbdata.interp = NULL;
theDMcbdata.tclproc[0] = '\0';
UUSetMsgCallback (&theDMcbdata, uutcl_DisplayMessage);
theBusycbdata.interp = NULL;
theBusycbdata.tclproc[0] = '\0';
UUSetBusyCallback (&theBusycbdata, uutcl_BusyCallback, 1000);
/*
* only set variables if they aren't set already
*/
sprintf (tmp, "%d", UUGetOption (UUOPT_FAST, NULL, NULL, 0));
if (Tcl_GetVar (interp, "OptionFast", TCL_GLOBAL_ONLY) == NULL)
Tcl_SetVar (interp, "OptionFast", tmp, TCL_GLOBAL_ONLY);
sprintf (tmp, "%d", UUGetOption (UUOPT_BRACKPOL, NULL, NULL, 0));
if (Tcl_GetVar (interp, "OptionBracket", TCL_GLOBAL_ONLY) == NULL)
Tcl_SetVar (interp, "OptionBracket", tmp, TCL_GLOBAL_ONLY);
sprintf (tmp, "%d", UUGetOption (UUOPT_DESPERATE, NULL, NULL, 0));
if (Tcl_GetVar (interp, "OptionDesperate", TCL_GLOBAL_ONLY) == NULL)
Tcl_SetVar (interp, "OptionDesperate", tmp, TCL_GLOBAL_ONLY);
sprintf (tmp, "%d", UUGetOption (UUOPT_DEBUG, NULL, NULL, 0));
if (Tcl_GetVar (interp, "OptionDebug", TCL_GLOBAL_ONLY) == NULL)
Tcl_SetVar (interp, "OptionDebug", tmp, TCL_GLOBAL_ONLY);
sprintf (tmp, "%d", UUGetOption (UUOPT_USETEXT, NULL, NULL, 0));
if (Tcl_GetVar (interp, "OptionUsetext", TCL_GLOBAL_ONLY) == NULL)
Tcl_SetVar (interp, "OptionUsetext", tmp, TCL_GLOBAL_ONLY);
return TCL_OK;
}
#endif
|
the_stack_data/9512500.c | #include <sys/types.h>
#include <sys/socket.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define CELL_DIGITS 3
#define BUFFER_SIZE 999
/*
* 01 COBOL-BUFFER PIC 9(CELL_DIGITS) OCCURS BUFFER_SIZE TIMES
*/
char msg_buf[BUFFER_SIZE];
#define STATE_DIGITS 2
// 01 CHANNEL-STATUS PIC 9(STATE_DIGITS)
#define EBADDEST 10
#define EOPENFAIL 20
#define EHUP 30
#define ESERV 40
#define DEFAULT_PORT "6667"
int sockfd;
#define RECV_BUF_SIZE 1024
char recv_buf[RECV_BUF_SIZE];
size_t recv_buf_pos = 0;
void channel_set_status(char *state, int value)
{
char buf[STATE_DIGITS + 1];
snprintf(buf, STATE_DIGITS + 1, "%.*hhu", STATE_DIGITS, (unsigned char)value);
memcpy(state, buf, STATE_DIGITS);
return;
}
void channel_from_cobol(char *cobol_buffer)
{
char buf[CELL_DIGITS + 1];
buf[CELL_DIGITS] = '\0';
memcpy(buf, cobol_buffer, CELL_DIGITS);
int i;
for(i = 0; i < BUFFER_SIZE; memcpy(buf, cobol_buffer + ++i * CELL_DIGITS, CELL_DIGITS)) {
msg_buf[i] = (char)strtol(buf, NULL, 10);
if(!msg_buf[i]) {
break;
}
}
if (i == BUFFER_SIZE) {
int message_length = 0;
for(i = 0; i < BUFFER_SIZE; i++) {
if(msg_buf[i] != ' ') {
message_length = i + 1;
}
}
if(message_length == BUFFER_SIZE) {
message_length--;
}
msg_buf[message_length] = '\0';
} else {
msg_buf[i] = '\0';
}
return;
}
void channel_to_cobol(char *cobol_buffer)
{
char buf[CELL_DIGITS + 1];
int i;
for(i = 0; i < BUFFER_SIZE - 1
&& msg_buf[i]
&& msg_buf[i] != '\n'
&& msg_buf[i] != '\r'
&& msg_buf[i]; i++) {
snprintf(buf, CELL_DIGITS + 1, "%.*hhu", CELL_DIGITS, msg_buf[i]);
memcpy(cobol_buffer + i * CELL_DIGITS, buf, CELL_DIGITS);
}
memset(cobol_buffer + i * CELL_DIGITS, (int)'0', CELL_DIGITS);
return;
}
void channel_string_to_cobol(char *cobol_buffer, const char *s)
{
strncpy(msg_buf, s, BUFFER_SIZE);
msg_buf[BUFFER_SIZE - 1] = '\0';
channel_to_cobol(cobol_buffer);
return;
}
/*
* ASCII "HOST[:PORT]$NUL$" IN COBOL-BUFFER
* CALL "CHANNEL-OPEN" USING COBOL-BUFFER, STATE.
*/
void CHANNEL__OPEN(char *cobol_buffer, char *state)
{
channel_from_cobol(cobol_buffer);
#ifdef DEBUG
printf("CHANNEL__OPEN: %s\n", msg_buf);
#endif
if(!strlen(msg_buf)) {
channel_string_to_cobol(cobol_buffer, "No host specified");
channel_set_status(state, EBADDEST);
return;
}
char *port = strchr(msg_buf, ':');
if(port) {
*port = '\0';
port++;
if(!strlen(port)) {
channel_string_to_cobol(cobol_buffer, "Port separator specified, but not port");
channel_set_status(state, EBADDEST);
return;
}
} else {
port = DEFAULT_PORT;
}
struct addrinfo hints, *res;
int status;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_ADDRCONFIG;
if((status = getaddrinfo(msg_buf, port, &hints, &res))) {
channel_string_to_cobol(cobol_buffer, gai_strerror(status));
channel_set_status(state, EBADDEST);
return;
}
struct addrinfo *curr_addr;
for(curr_addr = res; curr_addr; curr_addr = curr_addr->ai_next) {
sockfd = socket(curr_addr->ai_family, curr_addr->ai_socktype, curr_addr->ai_protocol);
if(sockfd == -1) {
perror("socket");
continue;
}
if(connect(sockfd, curr_addr->ai_addr, curr_addr->ai_addrlen) == -1) {
perror("connect");
close(sockfd);
continue;
}
break;
}
if(!curr_addr) {
channel_string_to_cobol(cobol_buffer, "Unable to connect to host");
channel_set_status(state, EOPENFAIL);
return;
}
channel_set_status(state, 0);
return;
}
// CALL "CHANNEL-SEND" USING COBOL-BUFFER, STATE.
void CHANNEL__SEND(char *cobol_buffer, char *state)
{
char *msg;
int sent, total;
channel_from_cobol(cobol_buffer);
#ifdef DEBUG
printf("Got from COBOL: %s\n", msg_buf);
#endif
sent = 0;
total = strlen(msg_buf);
if(msg_buf[total - 1] != '\n') {
if(total < BUFFER_SIZE) {
total++;
}
msg_buf[total - 1] = '\n';
msg_buf[total] = '\0';
}
#ifdef DEBUG
printf("Sending: %s\n", msg_buf);
#endif
/* Let's quit getting WOPO kicked off Freenode */
usleep(200000);
while(sent < total) {
int status = send(sockfd, msg_buf + sent, total - sent, 0);
if(status == -1) {
perror("send");
close(sockfd);
channel_string_to_cobol(cobol_buffer, "Hung up");
channel_set_status(state, EHUP);
return;
}
sent += status;
}
channel_set_status(state, 0);
return;
}
// CALL "CHANNEL-RECV" USING COBOL-BUFFER, STATE.
void CHANNEL__RECV(char *cobol_buffer, char *state)
{
char *message_end;
get_buffered:
message_end = memchr(recv_buf, '\n', recv_buf_pos);
if(message_end) {
size_t message_size = message_end - recv_buf;
if (message_size > BUFFER_SIZE) {
channel_string_to_cobol(cobol_buffer, "Server sent too-long message");
channel_set_status(state, ESERV);
return;
}
memcpy(msg_buf, recv_buf, message_size);
msg_buf[message_size] = '\0';
recv_buf_pos -= message_size + 1;
message_end++;
for(size_t i = 0; i < recv_buf_pos; i++) {
recv_buf[i] = message_end[i];
}
#ifdef DEBUG
printf("Received: %s\n", msg_buf);
#endif
channel_to_cobol(cobol_buffer);
channel_set_status(state, 0);
#ifdef DEBUG
printf("Line converted to COBOL ASCII string.\n");
#endif
return;
}
if(recv_buf_pos < RECV_BUF_SIZE - 1) {
ssize_t received = recv(sockfd, recv_buf + recv_buf_pos, RECV_BUF_SIZE - recv_buf_pos, 0);
if(received != -1) {
recv_buf_pos += received;
goto get_buffered;
}
perror("recv");
channel_string_to_cobol(cobol_buffer, "Hung up");
channel_set_status(state, EHUP);
return;
}
channel_string_to_cobol(cobol_buffer, "Server failed to send newline");
channel_set_status(state, ESERV);
return;
}
void CHANNEL__CLOSE(void)
{
close(sockfd);
return;
}
|
the_stack_data/107889.c | /*
* libc/stdio/fwrite.c
*/
#include <stdio.h>
size_t fwrite(const void * buf, size_t size, size_t count, FILE * f)
{
const unsigned char * p = buf;
size_t i;
for(i = 0; i < count; i++)
{
if(__stdio_write(f, p, size) != size)
break;
p += size;
}
return i;
}
EXPORT_SYMBOL(fwrite);
|
the_stack_data/111077373.c | #include <openssl/evp.h>
#include <openssl/objects.h>
#include <stdio.h>
void my_callback(const OBJ_NAME *obj, void *arg)
{
printf("Digest: %s\n", obj->name);
}
int main(int argc, char *argv)
{
void *my_arg;
OpenSSL_add_all_digests(); //make sure they're loaded
my_arg = NULL;
OBJ_NAME_do_all(OBJ_NAME_TYPE_MD_METH, my_callback, my_arg);
}
|
the_stack_data/153266876.c | #include <stdio.h>
int main ()
{
int i, j, n, count = 0;
scanf ("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n - 1; j++)
{
count++;
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
count++;
if (j == n - 1)
printf ("%d", count);
else
printf ("%d*", count);
}
count = count - 2 * n;
printf ("\n");
}
return 0;
}
|
the_stack_data/7077.c | #define _GNU_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/user.h>
#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif
static void prepare_pipe(int p[2])
{
if (pipe(p)) abort();
const unsigned pipe_size = fcntl(p[1], F_GETPIPE_SZ);
static char buffer[4096];
for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
write(p[1], buffer, n);
r -= n;
}
for (unsigned r = pipe_size; r > 0;) {
unsigned n = r > sizeof(buffer) ? sizeof(buffer) : r;
read(p[0], buffer, n);
r -= n;
}
}
int main(int argc, char **argv)
{
if (argc != 4) {
fprintf(stderr, "Usage: %s TARGETFILE OFFSET DATA\n", argv[0]);
return EXIT_FAILURE;
}
const char *const path = argv[1];
loff_t offset = strtoul(argv[2], NULL, 0);
const char *const data = argv[3];
const size_t data_size = strlen(data);
if (offset % PAGE_SIZE == 0) {
fprintf(stderr, "Sorry, cannot start writing at a page boundary\n");
return EXIT_FAILURE;
}
const loff_t next_page = (offset | (PAGE_SIZE - 1)) + 1;
const loff_t end_offset = offset + (loff_t)data_size;
if (end_offset > next_page) {
fprintf(stderr, "Sorry, cannot write across a page boundary\n");
return EXIT_FAILURE;
}
const int fd = open(path, O_RDONLY);
if (fd < 0) {
perror("open failed");
return EXIT_FAILURE;
}
struct stat st;
if (fstat(fd, &st)) {
perror("stat failed");
return EXIT_FAILURE;
}
if (offset > st.st_size) {
fprintf(stderr, "Offset is not inside the file\n");
return EXIT_FAILURE;
}
if (end_offset > st.st_size) {
fprintf(stderr, "Sorry, cannot enlarge the file\n");
return EXIT_FAILURE;
}
int p[2];
prepare_pipe(p);
--offset;
ssize_t nbytes = splice(fd, &offset, p[1], NULL, 1, 0);
if (nbytes < 0) {
perror("splice failed");
return EXIT_FAILURE;
}
if (nbytes == 0) {
fprintf(stderr, "short splice\n");
return EXIT_FAILURE;
}
nbytes = write(p[1], data, data_size);
if (nbytes < 0) {
perror("write failed");
return EXIT_FAILURE;
}
if ((size_t)nbytes < data_size) {
fprintf(stderr, "short write\n");
return EXIT_FAILURE;
}
printf("It worked!\n");
return EXIT_SUCCESS;
}
|
the_stack_data/3263567.c | #include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
#include<stdlib.h>
#include<stdio.h>
// Merges two subarrays of arr[].
// First subarray is arr[l..m]
// Second subarray is arr[m+1..r]
void merge(int arr[], int l, int m, int r)
{
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
/* create temp arrays */
int L[n1], R[n2];
/* Copy data to temp arrays L[] and R[] */
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge the temp arrays back into arr[l..r]*/
i = 0; // Initial index of first subarray
j = 0; // Initial index of second subarray
k = l; // Initial index of merged subarray
while (i < n1 && j < n2)
{
if (L[i] >= R[j])
{
arr[k] = L[i];
i++;
}
else
{
arr[k] = R[j];
j++;
}
k++;
}
/* Copy the remaining elements of L[], if there
are any */
while (i < n1)
{
arr[k] = L[i];
i++;
k++;
}
/* Copy the remaining elements of R[], if there
are any */
while (j < n2)
{
arr[k] = R[j];
j++;
k++;
}
}
/* l is for left index and r is right index of the
sub-array of arr to be sorted */
void mergeSort(int arr[], int l, int r)
{
if (l < r)
{
// Same as (l+r)/2, but avoids overflow for
// large l and h
int m = l+(r-l)/2;
// Sort first and second halves
mergeSort(arr, l, m);
mergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
int main(){
long int n,d,swap;
long int m;
long int i,j,c_i;
scanf("%ld %ld",&n,&m);
int dist[n];
long int *c =(long int*) malloc(sizeof(long int) * m);
for(c_i = 0; c_i < m; c_i++)
scanf("%ld",&c[c_i]);
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(c[j]==i)
{
dist[i]=0;
break;
}
else
{
for(j=0;j<m;j++)
{
d=abs(i-c[j]);
if(d<dist[i] || j==0)
dist[i]=d;
}
}
}
}
/*for (i = 0 ; i < ( n - 1 ); i++)
{
for (j = 0 ; j < n - i - 1; j++)
{
if (dist[j] < dist[j+1]) /* For decreasing order use <
{
swap = dist[j];
dist[j] = dist[j+1];
dist[j+1] = swap;
}
}
}*/
mergeSort(dist,0,n-1);
printf("%d",dist[0]);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.