file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/67324309.c | #include <stdio.h>
#define BIO "Hello world\r\n" \
"I'm Mahendra Sondagar\r\n" \
"I'm an IoT geek\r\n" \
"Connect me on <[email protected]>"
int main(void)
{
printf(BIO);
} |
the_stack_data/742393.c | #include <stdio.h>
int my_strcmp(char *a, char *b);
int main(void) {
char *a = "This is a test";
char *b = "This is a test";
int l;
l = my_strcmp(a, b);
printf("Return val: %i\n", l);
return 0;
}
int my_strcmp(char *a, char *b) {
int i;
for (i = 0; a[i] == b[i]; ++i)
if (a[i] == 0)
return 0;
return a[i] - b[i];
}
|
the_stack_data/25896.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STACK_SIZE_MAX 100
#define EMPTY_TOS -1
typedef struct StackRecord *Stack;
typedef int EleType; // In this program, I will use int as Element Type of Stack.
struct StackRecord {
int Cap; // Capacity
int TOS; // Top Of Stack
EleType *Arr; // Array
};
// Function Declaration
Stack CreateStack(int MaxEle);
void Push(EleType X, Stack S);
void Pop(Stack S);
int IsFull(Stack S);
int IsEmpty(Stack S);
void FreeStack(Stack S);
// global variable for using in every functions
FILE *output;
void main() {
FILE *input;
int repeat, temp, i;
char func_selected[5]; // This will have "push" or "pop".
// Open files.
input = fopen("input.txt", "r");
output = fopen("output.txt", "w");
Stack S = CreateStack(STACK_SIZE_MAX);
if(S == NULL) {
printf("Exit program, because allocating Stack failed.\n");
fclose(input);
fclose(output);
return;
}
fscanf(input, "%d", &repeat);
for(i = 0; i < repeat; i++) {
fscanf(input, "%s", func_selected);
if(strcmp(func_selected, "push") == 0) { // push
fscanf(input, "%d", &temp);
Push(temp, S);
}
else if(strcmp(func_selected, "pop") == 0) { // pop
Pop(S);
}
else { // If the input text isn't "push" or "pop",
fprintf(output, "Error : The input text isn't ""push"" or ""pop"".\n");
}
}
// Free.
FreeStack(S);
// Close files.
fclose(input);
fclose(output);
}
// Input : Max Element Size of the Stack
// Function that create a Stack and initialize members of the struct
Stack CreateStack(int MaxEle) {
Stack S = (Stack)malloc(sizeof(struct StackRecord));
if(S == NULL) {
fprintf(output, "Failed to allocate. Out of space.\n");
return NULL;
}
S->Arr = (EleType*)malloc(sizeof(EleType)*MaxEle);
if(S->Arr == NULL) {
fprintf(output, "Failed to allocate. out of space.\n");
free(S);
return NULL;
}
S->Cap = MaxEle;
S->TOS = EMPTY_TOS;
return S;
}
// Input : Element X, Stack Pointer S
// Function that puts Element X into Stack S
void Push(EleType X, Stack S) {
if(IsFull(S)) {
fprintf(output, "Full\n");
}
else {
S->Arr[++S->TOS] = X; // Increase S->TOS, and then save X into S->Arr[S->TOS].
}
}
// Input : Stack Pointer S
// Function that pops (prints and deletes) the top element in the Stack S
void Pop(Stack S) {
if(IsEmpty(S)) {
fprintf(output, "Empty\n");
}
else {
fprintf(output, "%d\n", S->Arr[S->TOS--]); // Print S->Arr[S->TOS], and then decrease S->TOS.
}
}
// Input : Stack Pointer S
// Function that returns whether the Stack S is full or not
int IsFull(Stack S) {
if(S->TOS == S->Cap-1) {
return 1;
}
return 0;
}
// Input : Stack Pointer S
// Function that returns whether the Stack S is Empty or not
int IsEmpty(Stack S) {
if(S->TOS == EMPTY_TOS) {
return 1;
}
return 0;
}
// Input : Stack Pointer S
// Function that deallocate the Array of Stack S and Stack S.
void FreeStack(Stack S) {
free(S->Arr);
free(S);
}
|
the_stack_data/26700773.c | #include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MY_SYSTEM
#define BASH_PATH "/bin/bash"
int my_system(const char *command)
{
int status;
int pid = fork();
if (pid == 0)
{
// child process
// printf("Command: %s -c %s\n", BASH_PATH, command);
status = execl(BASH_PATH, "bash", "-c", command, (char*) NULL);
// child should be dead after 'execl'
// but if execl() has an error...
exit(-1);
}
else if (pid > 0)
{
// parent process
wait(&status);
}
else
{
// error on fork
exit(-2);
}
return status;
}
int main(int argc, char *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s <command>\n", argv[0]);
exit(1);
}
#ifdef MY_SYSTEM
return my_system(argv[1]);
#else
return system(argv[1]);
#endif
}
|
the_stack_data/225144053.c | #include <ctype.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
int j;
int ret;
if (argc == 3)
{
i = atoi(argv[1]);
j = -9;
while (j < 255)
{
ret = islower(j);
if (j % 10 == 0)
printf("%d ", ret);
else
printf("%d", ret);
j++;
}
}
return (0);
}
|
the_stack_data/67325081.c | /*
*
* Copyright (C) 2019, Broadband Forum
* Copyright (C) 2020, BT PLC
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* \file device_mqtt.c
*
* Implements the Device.MQTT data model object
*
*/
#ifdef ENABLE_MQTT
#include <time.h>
#include <string.h>
#include <limits.h>
#include "common_defs.h"
#include "data_model.h"
#include "usp_api.h"
#include "dm_access.h"
#include "dm_trans.h"
#include "kv_vector.h"
#include "mtp_exec.h"
#include "device.h"
#include "text_utils.h"
#include "mqtt.h"
#include "iso8601.h"
typedef struct
{
mqtt_conn_params_t conn_params;
mqtt_subscription_t subscriptions[MAX_MQTT_SUBSCRIPTIONS];
} client_t;
// Table used to convert from a textual representation of protocol version to an enumeration
const enum_entry_t mqtt_protocolver[kMqttProtocol_Max] =
{
{ kMqttProtocol_3_1, "3.1" }, // Use v3.1 MQTT
{ kMqttProtocol_3_1_1, "3.1.1" }, // Use v3.1.1 MQTT
{ kMqttProtocol_5_0, "5.0" }, // Use v5.0 MQTT (recommended)
};
// Table used to convert from a textual representation of Transport protocol to an enumeration
const enum_entry_t mqtt_tsprotocol[kMqttTSprotocol_Max] =
{
{ kMqttTSprotocol_tcpip, "TCP/IP" },
{ kMqttTSprotocol_tls, "TLS" },
{ kMqttTSprotocol_websocket, "WebSocket" },
};
//------------------------------------------------------------------------------
// Location of the MQTT Client table within the data model
#define DEVICE_MQTT_CLIENT "Device.MQTT.Client"
static const char device_mqtt_client_root[] = DEVICE_MQTT_CLIENT;
//------------------------------------------------------------------------------
// Cache of the parameters in the Device.MQTT.Client table
static client_t mqtt_client_params[MAX_MQTT_CLIENTS];
//------------------------------------------------------------------------------
// Forward declarations. Note these are not static, because we need them in the symbol table for USP_LOG_Callstack() to show them
//mqtt client
int ValidateAdd_Mqttclients(dm_req_t *req);
int Notify_MQTTClientAdded(dm_req_t *req);
int Notify_MqttClientDeleted(dm_req_t *req);
int NotifyChange_MQTTEnable(dm_req_t *req, char *value);
int NotifyChange_MQTTBrokerAddress(dm_req_t *req, char *value);
int Validate_MQTTBrokerPort(dm_req_t *req, char *value);
int NotifyChange_MQTTBrokerPort(dm_req_t *req, char *value);
int NotifyChange_MQTTUsername(dm_req_t *req, char *value);
int NotifyChange_MQTTPassword(dm_req_t *req, char *value);
int Validate_MQTTProtocolVersion(dm_req_t *req, char *value);
int NotifyChange_MQTTProtocolVersion(dm_req_t *req, char *value);
int Validate_MQTTKeepAliveTime(dm_req_t *req, char *value);
int NotifyChange_MQTTKeepAliveTime(dm_req_t *req, char *value);
int NotifyChange_MQTTClientId(dm_req_t *req, char *value);
int NotifyChange_MQTTName(dm_req_t *req, char *value);
int Validate_MQTTTransportProtocol(dm_req_t *req, char *value);
int NotifyChange_MQTTTransportProtocol(dm_req_t *req, char *value);
int NotifyChange_MQTTCleanSession(dm_req_t *req, char *value);
int NotifyChange_MQTTCleanStart(dm_req_t *req, char *value);
int NotifyChange_MQTTRequestResponseInfo(dm_req_t *req, char *value);
int NotifyChange_MQTTRequestProblemInfo(dm_req_t *req, char *value);
#if 0
// TODO: Removed as these are not yet used
int NotifyChange_MQTTSessionExpiryInterval(dm_req_t *req, char *value);
int NotifyChange_MQTTReceiveMaximum(dm_req_t *req, char *value);
int NotifyChange_MQTTMaximumPacketSize(dm_req_t *req, char *value);
int Validate_MQTTTopicAliasMaximum(dm_req_t *req, char *value);
int NotifyChange_MQTTTopicAliasMaximum(dm_req_t *req, char *value);
int NotifyChange_MQTTWillEnable(dm_req_t *req, char *value);
int Validate_MQTTWillQoS(dm_req_t *req, char *value);
int NotifyChange_MQTTWillQoS(dm_req_t *req, char *value);
int NotifyChange_MQTTWillRetain(dm_req_t *req, char *value);
int NotifyChange_MQTTWillDelayInterval(dm_req_t *req, char *value);
int NotifyChange_MQTTWillMessageExpiryInterval(dm_req_t *req, char *value);
int NotifyChange_MQTTWillContentType(dm_req_t *req, char *value);
int NotifyChange_MQTTWillResponseTopic(dm_req_t *req, char *value);
int NotifyChange_MQTTWillTopic(dm_req_t *req, char *value);
int NotifyChange_MQTTTWillValue(dm_req_t *req, char *value);
int NotifyChange_MQTTPublishMessageExpiryInterval(dm_req_t *req, char *value);
int Validate_MQTTMessageRetryTime(dm_req_t *req, char *value);
int NotifyChange_MQTTMessageRetryTime(dm_req_t *req, char *value);
int NotifyChange_MQTTAuthenticationMethod(dm_req_t *req, char *value);
#endif
int Validate_MQTTConnectRetryTime(dm_req_t *req, char *value);
int NotifyChange_MQTTConnectRetryTime(dm_req_t *req, char *value);
int Validate_MQTTConnectRetryIntervalMultiplier(dm_req_t *req, char *value);
int NotifyChange_MQTTConnectRetryIntervalMultiplier(dm_req_t *req, char *value);
int Validate_MQTTConnectRetryMaxInterval(dm_req_t *req, char *value);
int NotifyChange_MQTTConnectRetryMaxInterval(dm_req_t *req, char *value);
int Get_MqttClientStatus(dm_req_t *req, char *buf, int len);
/*MQTT Subscriptions*/
int ValidateAdd_MqttClientSubscriptions(dm_req_t *req);
int Notify_MqttClientSubcriptionsAdded(dm_req_t *req);
int Notify_MqttClientSubscriptionsDeleted(dm_req_t *req);
int NotifyChange_MQTTSubscriptionEnable(dm_req_t *req, char *value);
int NotifyChange_MQTTSubscriptionTopic(dm_req_t *req, char *value);
int Validate_MQTTSubscriptionQoS(dm_req_t *req, char *value);
int NotifyChange_MQTTSubscriptionQoS(dm_req_t *req, char *value);
mqtt_conn_params_t *FindMqttParamsByInstance(int instance);
mqtt_conn_params_t *FindUnusedMqttParams(void);
mqtt_subscription_t* FindUnusedSubscriptionInMqttClient(client_t* client);
client_t *FindUnusedMqttClient(void);
client_t *FindDevMqttClientByInstance(int instance);
void DestroyMQTTClient(client_t *client);
int ProcessMqttClientAdded(int instance);
int ProcessMqttSubscriptionAdded(int instance, int sub_instance);
int DEVICE_MQTT_StartAllClients(void);
int EnableMQTTClient(mqtt_conn_params_t *mp, mqtt_subscription_t subscriptions[MAX_MQTT_SUBSCRIPTIONS]);
void ScheduleMqttReconnect(mqtt_conn_params_t *mp);
void ScheduleMQTTResubscribe(client_t *mqttclient, mqtt_subscription_t *sub);
int ClientNumberOfEntries(void);
int SubscriptionNumberofEntries(int instance);
/*********************************************************************//**
**
** DEVICE_MQTT_Init
**
** Initialises this component, and registers all parameters which it implements
**
** \param None
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int DEVICE_MQTT_Init(void)
{
int err = USP_ERR_OK;
int i, j;
mqtt_conn_params_t *mp;
mqtt_subscription_t *subs;
// Exit if unable to initialise the lower level MQTT component
err = MQTT_Init();
if (err != USP_ERR_OK)
{
return err;
}
// Initialise all of the client parameters
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
mp = &mqtt_client_params[i].conn_params;
MQTT_InitConnParams(mp);
// Initialise the subsciption mappings
memset(&mqtt_client_params[i].subscriptions, 0, sizeof(mqtt_client_params->subscriptions));
for (j=0; j<MAX_MQTT_SUBSCRIPTIONS; j++)
{
subs = &mqtt_client_params[i].subscriptions[j];
subs->state = kMqttSubState_Unsubscribed;
subs->instance = INVALID;
}
}
// Register parameters implemented by this component
err |= USP_REGISTER_Object(DEVICE_MQTT_CLIENT ".{i}", ValidateAdd_Mqttclients, NULL,
Notify_MQTTClientAdded, NULL, NULL, Notify_MqttClientDeleted);
if (err != USP_ERR_OK)
{
USP_LOG_Error("MQTT object registration failed\n");
return err;
}
err |= USP_REGISTER_Param_NumEntries("Device.MQTT.ClientNumberOfEntries", DEVICE_MQTT_CLIENT ".{i}");
err |= USP_REGISTER_DBParam_Alias(DEVICE_MQTT_CLIENT ".{i}.Alias", NULL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Enable", "false", NULL, NotifyChange_MQTTEnable, DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.BrokerAddress", NULL, NULL, NotifyChange_MQTTBrokerAddress, DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.BrokerPort", "1883", Validate_MQTTBrokerPort, NotifyChange_MQTTBrokerPort, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Username", NULL, NULL, NotifyChange_MQTTUsername, DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Password", NULL, NULL, NotifyChange_MQTTPassword, DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.KeepAliveTime", "60", Validate_MQTTKeepAliveTime, NotifyChange_MQTTKeepAliveTime, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ProtocolVersion", "5.0", Validate_MQTTProtocolVersion, NotifyChange_MQTTProtocolVersion , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ClientID", "", NULL, NotifyChange_MQTTClientId, DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Name", NULL, NULL, NotifyChange_MQTTName , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.TransportProtocol", "TCP/IP", Validate_MQTTTransportProtocol, NotifyChange_MQTTTransportProtocol , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.CleanSession", "true", NULL, NotifyChange_MQTTCleanSession , DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.CleanStart", "true", NULL, NotifyChange_MQTTCleanStart , DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.RequestResponseInfo", "false", NULL, NotifyChange_MQTTRequestResponseInfo , DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.RequestProblemInfo", "false", NULL, NotifyChange_MQTTRequestProblemInfo , DM_BOOL);
#if 0
// TODO: Removed as these are not yet used
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.SessionExpiryInterval", NULL, NULL, NotifyChange_MQTTSessionExpiryInterval, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ReceiveMaximum", NULL, NULL, NotifyChange_MQTTReceiveMaximum, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.MaximumPacketSize", NULL, NULL, NotifyChange_MQTTMaximumPacketSize, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.TopicAliasMaximum", NULL, Validate_MQTTTopicAliasMaximum, NotifyChange_MQTTTopicAliasMaximum, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillEnable", "false", NULL, NotifyChange_MQTTWillEnable , DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillQoS", NULL, Validate_MQTTWillQoS, NotifyChange_MQTTWillQoS, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillRetain", "false", NULL, NotifyChange_MQTTWillRetain , DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillDelayInterval", NULL, NULL, NotifyChange_MQTTWillDelayInterval, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillMessageExpiryInterval", NULL, NULL, NotifyChange_MQTTWillMessageExpiryInterval, DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillContentType", NULL, NULL, NotifyChange_MQTTWillContentType , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillResponseTopic", NULL, NULL, NotifyChange_MQTTWillResponseTopic , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillTopic", NULL, NULL, NotifyChange_MQTTWillTopic , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.WillValue", NULL, NULL, NotifyChange_MQTTTWillValue , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.AuthenticationMethod", NULL, NULL, NotifyChange_MQTTAuthenticationMethod , DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.MessageRetryTime", "5", Validate_MQTTMessageRetryTime, NotifyChange_MQTTMessageRetryTime , DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.PublishMessageExpiryInterval", NULL, NULL, NotifyChange_MQTTPublishMessageExpiryInterval , DM_UINT);
#endif
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ConnectRetryTime", "5", Validate_MQTTConnectRetryTime, NotifyChange_MQTTConnectRetryTime , DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ConnectRetryIntervalMultiplier", "2000", Validate_MQTTConnectRetryIntervalMultiplier, NotifyChange_MQTTConnectRetryIntervalMultiplier , DM_UINT);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.ConnectRetryMaxInterval", "30720", Validate_MQTTConnectRetryMaxInterval, NotifyChange_MQTTConnectRetryMaxInterval , DM_UINT);
err |= USP_REGISTER_DBParam_ReadOnly(DEVICE_MQTT_CLIENT ".{i}.ResponseInformation", "", DM_STRING);
err |= USP_REGISTER_VendorParam_ReadOnly(DEVICE_MQTT_CLIENT ".{i}.Status", Get_MqttClientStatus, DM_STRING);
err |= USP_REGISTER_Object(DEVICE_MQTT_CLIENT ".{i}.Subscription.{i}.", ValidateAdd_MqttClientSubscriptions, NULL, Notify_MqttClientSubcriptionsAdded,
NULL, NULL, Notify_MqttClientSubscriptionsDeleted);
err |= USP_REGISTER_Param_NumEntries(DEVICE_MQTT_CLIENT ".{i}.SubscriptionNumberOfEntries", DEVICE_MQTT_CLIENT".{i}.Subscription.{i}");
err |= USP_REGISTER_DBParam_Alias(DEVICE_MQTT_CLIENT ".{i}.Subscription.{i}.Alias", NULL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Subscription.{i}.Enable", "false", NULL, NotifyChange_MQTTSubscriptionEnable, DM_BOOL);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Subscription.{i}.Topic", NULL, NULL, NotifyChange_MQTTSubscriptionTopic, DM_STRING);
err |= USP_REGISTER_DBParam_ReadWrite(DEVICE_MQTT_CLIENT ".{i}.Subscription.{i}.QoS", NULL, Validate_MQTTSubscriptionQoS, NotifyChange_MQTTSubscriptionQoS, DM_UINT);
// Exit if any errors occurred
if (err != USP_ERR_OK)
{
USP_LOG_Error("%s: Unable to Register MQTT", __FUNCTION__);
return USP_ERR_INTERNAL_ERROR;
}
// If the code gets here, then registration was successful
return USP_ERR_OK;
}
/*********************************************************************//**
**
** DEVICE_MQTT_Start
**
** Initialises the mqtt connection array from the DB
**
** \param None
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int DEVICE_MQTT_Start(void)
{
int i;
int err;
int_vector_t iv;
int instance;
char path[MAX_DM_PATH];
// Exit if unable to get the object instance numbers present in the mqtt client table
err = DATA_MODEL_GetInstances(DEVICE_MQTT_CLIENT, &iv);
if (err != USP_ERR_OK)
{
USP_LOG_Error("%s: Unable to start Device MQTT", __FUNCTION__);
return err;
}
// Exit, issuing a warning, if no MQTT clients are present in database
if (iv.num_entries == 0)
{
USP_LOG_Warning("%s: WARNING: No instances in %s", __FUNCTION__, DEVICE_MQTT_CLIENT);
err = USP_ERR_OK;
goto exit;
}
// Add all MQTT clients to the MQTT client array
for (i=0; i < iv.num_entries; i++)
{
instance = iv.vector[i];
err = ProcessMqttClientAdded(instance);
if (err != USP_ERR_OK)
{
// Exit if unable to delete a MQTT connection with bad parameters from the DB
USP_SNPRINTF(path, sizeof(path), "%s.%d", device_mqtt_client_root, instance);
USP_LOG_Warning("%s: Deleting %s as it contained invalid parameters.", __FUNCTION__, path);
err = DATA_MODEL_DeleteInstance(path, 0);
if (err != USP_ERR_OK)
{
goto exit;
}
}
}
err = MQTT_Start();
if (err != USP_ERR_OK)
{
USP_LOG_Error("%s: Unable to start MQTT", __FUNCTION__);
return err;
}
err = USP_ERR_OK;
exit:
// Destroy the vector of instance numbers for the table
INT_VECTOR_Destroy(&iv);
return err;
}
/*********************************************************************//**
**
** DEVICE_MQTT_Stop
**
** Frees up all memory associated with this module
**
** \param None
**
** \return None
**
**************************************************************************/
void DEVICE_MQTT_Stop(void)
{
// Destroy all clients
for (int i = 0; i < MAX_MQTT_CLIENTS; i++)
{
DestroyMQTTClient(&mqtt_client_params[i]);
}
// Delete all the clients and mosquitto in the core
MQTT_Destroy();
}
/*********************************************************************//**
**
** DEVICE_MQTT_StartAllClients
**
** Starts all MQTT clients
**
** \param None
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int DEVICE_MQTT_StartAllClients(void)
{
int i;
client_t *mqttclient;
int err;
// Iterate over all MQTT clients, starting the ones that are enabled
for (i=0; i<ClientNumberOfEntries(); i++)
{
mqttclient = &mqtt_client_params[i];
if ((mqttclient->conn_params.instance != INVALID) && (mqttclient->conn_params.enable == true))
{
// Exit if no free slots to enable the connection. (Enable is successful, even if the connection is trying to reconnect)
err = EnableMQTTClient(&mqttclient->conn_params, mqttclient->subscriptions);
if (err != USP_ERR_OK)
{
return err;
}
}
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** DEVICE_MQTT_ScheduleReconnect
**
** Schedules a reconnect to the specified MQTT client, once that connection has finished sending any response
**
** \param instance - instance number of the connection in Device.MQTT.Client.{i}
**
** \return None
**
**************************************************************************/
void DEVICE_MQTT_ScheduleReconnect(int instance)
{
mqtt_conn_params_t *mp;
// Exit if unable to find the specified MQTT connection
mp = FindMqttParamsByInstance(instance);
if (mp == NULL)
{
return;
}
// Schedule a reconnect if this MQTT client enabled
if (mp->enable)
{
ScheduleMqttReconnect(mp);
}
}
/*********************************************************************//**
**
** Get_MqttClientStatus
**
** Gets the value of Device.MQTT.Client.{i}.Status
**
** \param req - pointer to structure identifying the path
** \param buf - pointer to buffer into which to return the value of the parameter (as a textual string)
** \param len - length of buffer in which to return the value of the parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Get_MqttClientStatus(dm_req_t *req, char *buf, int len)
{
mqtt_conn_params_t* conn_params;
const char *status;
// Determine stomp connection to be read
conn_params = FindMqttParamsByInstance(inst1);
USP_ASSERT(conn_params != NULL);
if (conn_params->enable == false)
{
status = "Disabled";
}
else
{
status = MQTT_GetClientStatus(conn_params->instance);
}
USP_STRNCPY(buf, status, len);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** DEVICE_MQTT_GetMtpStatus
**
** Function called to get the value of Device.LocalAgent.MTP.{i}.Status for a MTPP client**
** \param instance - instance number of the connection in Device.MQTT.Client.{i}
**
** \return Status of the MQTT client
**
**************************************************************************/
mtp_status_t DEVICE_MQTT_GetMtpStatus(int instance)
{
mqtt_conn_params_t *mp;
// Exit if unable to find the specified MQTT client
// NOTE: This could occur if the connection was disabled, or the connection reference was incorrect
mp = FindMqttParamsByInstance(instance);
if ((mp == NULL) || (mp->enable == false))
{
return kMtpStatus_Down;
}
return MQTT_GetMtpStatus(mp->instance);
}
/*********************************************************************//**
**
** DEVICE_MQTT_CountEnabledConnections
**
** Returns a count of the number of enabled MQTT clients
**
** \param None
**
** \return returns a count of the number of enabled MQTT clients
**
**************************************************************************/
int DEVICE_MQTT_CountEnabledConnections(void)
{
int i;
int count = 0;
client_t *mqttclient;
// Iterate over all MQTT connections
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
// Increase the count if found an enabled connection
mqttclient = &mqtt_client_params[i];
if ((mqttclient->conn_params.instance != INVALID) && (mqttclient->conn_params.enable))
{
count++;
}
}
return count;
}
/*********************************************************************//**
**
** DEVICE_MQTT_QueueBinaryMessage
**
** Function called to queue a message on the specified MQTT connection
**
** \param usp_msg_type - Type of USP message contained in pbuf. This is used for debug logging when the message is sent by the MTP.
** \param instance - instance number of the MQTT connection in Device.MQTT.Client.{i}
** \param topic - MQTT client subscribed topic
** \param pbuf - pointer to buffer containing binary protobuf message. Ownership of this buffer passes to this code, if successful
** \param pbuf_len - length of buffer containing protobuf binary message
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int DEVICE_MQTT_QueueBinaryMessage(Usp__Header__MsgType usp_msg_type, int instance, char *topic, char *response_topic, unsigned char *pbuf, int pbuf_len)
{
mqtt_conn_params_t *mp;
// Exit if unable to find the specified MQTT client
mp = FindMqttParamsByInstance(instance);
if ((mp == NULL) || (mp->enable == false))
{
USP_ERR_SetMessage("%s: No internal MQTT connection matching Device.MQTT.Client.%d", __FUNCTION__, instance);
return USP_ERR_INTERNAL_ERROR;
}
if (MQTT_QueueBinaryMessage(usp_msg_type, instance, topic, pbuf, pbuf_len) != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: No internal MQTT Queue Binary message for topic %s", __FUNCTION__, topic);
return USP_ERR_INTERNAL_ERROR;
}
return USP_ERR_OK;
}
int ClientNumberOfEntries(void)
{
int clientnumofentries, err;
err = DM_ACCESS_GetInteger("Device.MQTT.ClientNumberOfEntries", &clientnumofentries);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Client number of entries failed", __FUNCTION__);
return -1;
}
return clientnumofentries;
}
int SubscriptionNumberofEntries(int instance)
{
int subsnumofentries, err;
char path[MAX_DM_PATH];
USP_SNPRINTF(path, sizeof(path), "%s.%d.SubscriptionNumberOfEntries", device_mqtt_client_root, instance);
err = DM_ACCESS_GetInteger(path, &subsnumofentries);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Subscription number of entries failed", __FUNCTION__);
return -1;
}
return subsnumofentries;
}
/*********************************************************************//**
**
** ProcessMqttClientAdded
*
** Reads the parameters for the specified Mqtt Client from the database and processes them
**
** \param instance - instance number of the Mqtt client
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int ProcessMqttClientAdded(int instance)
{
int err;
char path[MAX_DM_PATH];
client_t *mqttclient;
mqttclient = FindUnusedMqttClient();
// Initialise to defaults
if (mqttclient == NULL)
{
return USP_ERR_RESOURCES_EXCEEDED;
}
mqttclient->conn_params.instance = instance;
// Exit if unable to get the enable for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.Enable", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.enable);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the host for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.BrokerAddress", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.host);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the port for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.BrokerPort", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.port);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the protocol version for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ProtocolVersion", device_mqtt_client_root, instance);
err = DM_ACCESS_GetEnum(path, &mqttclient->conn_params.version, mqtt_protocolver, NUM_ELEM(mqtt_protocolver));
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the keepalive for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.KeepAliveTime", device_mqtt_client_root, instance);
err = DM_ACCESS_GetInteger(path, &mqttclient->conn_params.keepalive);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the username for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.Username", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.username);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the password for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.Password", device_mqtt_client_root, instance);
err = DM_ACCESS_GetPassword(path, &mqttclient->conn_params.password);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the clientid for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ClientID", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.client_id);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the name for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.Name", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.name);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the transport protocol for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.TransportProtocol", device_mqtt_client_root, instance);
err = DM_ACCESS_GetEnum(path, &mqttclient->conn_params.ts_protocol, mqtt_tsprotocol, NUM_ELEM(mqtt_tsprotocol));
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the CleanSession for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.CleanSession", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.clean_session);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the Cleanstart for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.CleanStart", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.clean_start);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the RequestResponseInfo for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.RequestResponseInfo", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.request_response_info);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the RequestProblemInfo for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.RequestProblemInfo", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.request_problem_info);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the Response Information for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ResponseInformation", device_mqtt_client_root, instance);
USP_SAFE_FREE(mqttclient->conn_params.response_information);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.response_information);
if (err != USP_ERR_OK)
{
goto exit;
}
#if 0
// TODO: Removed as these are not yet used
// Exit if unable to get the SessionExpiryInterval for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.SessionExpiryInterval", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.session_expiry);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the ReceiveMaximum for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ReceiveMaximum", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.receive_max);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the MaximumPacketSize for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.MaximumPacketSize", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.max_packet_size);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the TopicAliasMaximum for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.TopicAliasMaximum", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.topic_alias_max);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillEnable for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillEnable", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.will_enable);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillQoS for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillQoS", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.will_qos);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillRetain for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillRetain", device_mqtt_client_root, instance);
err = DM_ACCESS_GetBool(path, &mqttclient->conn_params.will_retain);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillDelayInterval for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillDelayInterval", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.will_delay_interval);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillMessageExpiryInterval for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillMessageExpiryInterval", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.will_message_expiry);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillContentType for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillContentType", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.will_content_type);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillResponseTopic for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillResponseTopic", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.will_response_topic);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillTopic for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillTopic", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.will_topic);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the WillValue for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.WillValue", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.will_value);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the Authentication Method for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.AuthenticationMethod", device_mqtt_client_root, instance);
err = DM_ACCESS_GetString(path, &mqttclient->conn_params.auth_method);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the PublishMessageExpiryInterval for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.PublishMessageExpiryInterval", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.pubmsg_expinterval);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the MessageRetryTime for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.MessageRetryTime", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.message_retrytime);
if (err != USP_ERR_OK)
{
goto exit;
}
#endif
// Exit if unable to get the ConnectRetryTime for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ConnectRetryTime", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.retry.connect_retrytime);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the ConnectRetryIntervalMultiplier for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ConnectRetryIntervalMultiplier", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.retry.interval_multiplier);
if (err != USP_ERR_OK)
{
goto exit;
}
// Exit if unable to get the ConnectRetryMaxInterval for this MQTT client
USP_SNPRINTF(path, sizeof(path), "%s.%d.ConnectRetryMaxInterval", device_mqtt_client_root, instance);
err = DM_ACCESS_GetUnsigned(path, &mqttclient->conn_params.retry.max_interval);
if (err != USP_ERR_OK)
{
goto exit;
}
// If the code gets here, then we successfully retrieved all data about the MQTT client
err = USP_ERR_OK;
exit:
if (err != USP_ERR_OK)
{
DestroyMQTTClient(mqttclient);
}
return err;
}
/*********************************************************************//**
**
** EnableMQTTClient
**
** Wrapper function to enable a MQTT client with the current connection parameters
**
** \param mp - MQTT connection parameters
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int EnableMQTTClient(mqtt_conn_params_t *mp, mqtt_subscription_t subscriptions[MAX_MQTT_SUBSCRIPTIONS])
{
int err;
USP_SAFE_FREE(mp->topic);
USP_SAFE_FREE(mp->response_topic);
mp->topic = USP_STRDUP(DEVICE_CONTROLLER_GetControllerTopic(mp->instance));
mp->response_topic = USP_STRDUP(DEVICE_MTP_GetAgentMqttResponseTopic(mp->instance));
// Check the error condition
err = MQTT_EnableClient(mp, subscriptions);
if (err != USP_ERR_OK)
{
USP_LOG_Error("%s MQTT failed to enable the client", __FUNCTION__);
return err;
}
return err;
}
/*********************************************************************//**
**
** ProcessMqttSubscriptionAdded
*
** Reads the parameters for the specified Mqtt Client subscriotion from the
** database and processes them
**
** \param instance - instance number of the MQTT client
** \param sub_instance - instance number of the MQTT Subscription
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int ProcessMqttSubscriptionAdded(int instance, int sub_instance)
{
int err = USP_ERR_OK;
char path[MAX_DM_PATH];
client_t *client = NULL;
// Refactor.
client = FindDevMqttClientByInstance(instance);
USP_ASSERT(client != NULL);
mqtt_subscription_t* sub = FindUnusedSubscriptionInMqttClient(client);
if (sub == NULL)
{
USP_LOG_Error("%s: Failed to find empty subscription.", __FUNCTION__);
return USP_ERR_RESOURCES_EXCEEDED;
}
sub->instance = sub_instance;
USP_SNPRINTF(path, sizeof(path), "%s.%d.Subscription.%d.Enable", device_mqtt_client_root, instance, sub_instance);
err = DM_ACCESS_GetBool(path, &sub->enabled);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Client Subscription %d enable failed", __FUNCTION__, sub_instance);
return err;
}
USP_SNPRINTF(path, sizeof(path), "%s.%d.Subscription.%d.Topic", device_mqtt_client_root, instance, sub_instance);
USP_SAFE_FREE(sub->topic);
err = DM_ACCESS_GetString(path, &sub->topic);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Client Subscription %d Topic failed", __FUNCTION__, sub_instance);
return err;
}
USP_SNPRINTF(path, sizeof(path), "%s.%d.Subscription.%d.QoS", device_mqtt_client_root, instance, sub_instance);
err = DM_ACCESS_GetUnsigned(path, &sub->qos);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Client Subscription %d QoS failed", __FUNCTION__, sub_instance);
return err;
}
err = MQTT_AddSubscription(instance, sub);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: client subscribe failed\n", __FUNCTION__);
return err;
}
return err;
}
/*********************************************************************//**
**
** NotifyChange_MQTTEnable
**
** Function called when Device.MQTT.Connection.{i}.Enable is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTEnable(dm_req_t *req, char *value)
{
client_t *mqttclient;
bool old_value;
int err;
// Determine mqtt client to be updated
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL);
old_value = mqttclient->conn_params.enable;
// Stop the connection if it has been disabled
// NOTE: This code does not support sending a response back to a controller that disables it's own MQTT connection
// However, as it is unlikely to be the case that a controller would ever do this, I have not added extra code to support this
if ((old_value == true) && (val_bool == false))
{
MQTT_DisableClient(mqttclient->conn_params.instance, true);
}
// Set the new value, we do this inbetween stopping and starting the connection because both must have the enable set to true
mqttclient->conn_params.enable = val_bool;
// Start the connection if it has been enabled
if ((old_value == false) && (val_bool == true))
{
// Exit if no free slots to enable the connection. (Enable is successful, even if the connection is trying to reconnect)
err = EnableMQTTClient(&mqttclient->conn_params, mqttclient->subscriptions);
if (err != USP_ERR_OK)
{
return err;
}
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTBrokerAddress
**
** Function called when Device.MQTT.Client.{i}.BrokerAddress is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTBrokerAddress(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((strcmp(mp->host, value) != 0) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->host);
mp->host = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTBrokerPort
**
** Validates Device.MQTT.Client.{i}.BrokerPort by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTBrokerPort(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 1, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTBrokerPort
**
** Function called when Device.MQTT.Client.{i}.BrokerPort is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTBrokerPort(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt connection to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((mp->port != val_uint) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->port = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTUsername
**
** Function called when Device.MQTT.Client.{i}.Username is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTUsername(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((strcmp(mp->username, value) != 0) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->username);
mp->username = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTPassword
**
** Function called when Device.MQTT.Client.{i}.Password is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTPassword(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
//char buf[MAX_DM_SHORT_VALUE_LEN];
//dm_vendor_get_mtp_password_cb_t get_mtp_password_cb;
//int err;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((strcmp(mp->password, value) != 0) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->password);
mp->password = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTKeepAliveTime
**
** Validates Device.MQTT.Client.{i}.KeepAliveTime by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTKeepAliveTime(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 0, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTKeepAliveTime
**
** Function called when Device.MQTT.Client.{i}.KeepAliveTime is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTKeepAliveTime(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((mp->keepalive != val_uint) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->keepalive = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTProtocolVersion
**
** Validates Device.MQTT.Client.{i}.ProtocolVersion
** by checking that it matches the mqtt protocol version we support
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTProtocolVersion(dm_req_t *req, char *value)
{
mqtt_protocolver_t protocol;
// Exit if the protocol was invalid
protocol = TEXT_UTILS_StringToEnum(value, mqtt_protocolver, NUM_ELEM(mqtt_protocolver));
if (protocol == INVALID)
{
USP_ERR_SetMessage("%s: Invalid or unsupported protocol %s", __FUNCTION__, value);
return USP_ERR_INVALID_VALUE;
}
return USP_ERR_OK;
}
/*************************************************************************
**
** NotifyChange_MQTTProtocolVersion
**
** Function called when Device.MQTT.Client.{i}.ProtocolVersion is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTProtocolVersion(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
mqtt_protocolver_t new_protocol;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Extract the new value
new_protocol = TEXT_UTILS_StringToEnum(value, mqtt_protocolver, NUM_ELEM(mqtt_protocolver));
USP_ASSERT(new_protocol != INVALID); // Value must already have validated to have got here
// Exit if protocol has not changed
if (new_protocol == mp->version)
{
return USP_ERR_OK;
}
// Store new protocol
mp->version = new_protocol;
if ((mp->enable) && (mp->instance != INVALID))
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTClientID
**
** Function called when Device.MQTT.Client.{i}.ClientID is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTClientId(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((strcmp(mp->client_id, value) != 0) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->client_id);
mp->client_id = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTName
**
** Function called when Device.MQTT.Client.{i}.Name is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTName(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Determine whether to schedule a reconnect
if ((strcmp(mp->name, value) != 0) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->name);
mp->name = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTTransportProtocol
**
** Validates Device.MQTT.Client.{i}.TransportProtocol
** by checking that it matches the mqtt Transport protocol we support
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTTransportProtocol(dm_req_t *req, char *value)
{
mqtt_tsprotocol_t tsprotocol;
// Exit if the protocol was invalid
tsprotocol = TEXT_UTILS_StringToEnum(value, mqtt_tsprotocol, NUM_ELEM(mqtt_tsprotocol));
if (tsprotocol == INVALID)
{
USP_ERR_SetMessage("%s: Invalid or unsupported transport protocol %s", __FUNCTION__, value);
return USP_ERR_INVALID_VALUE;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTTransportProtocol
**
** Function called when Device.MQTT.Client.{i}.TransportProtocol is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTTransportProtocol(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
mqtt_tsprotocol_t new_tsprotocol;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Extract the new value
new_tsprotocol = TEXT_UTILS_StringToEnum(value, mqtt_tsprotocol, NUM_ELEM(mqtt_tsprotocol));
USP_ASSERT(new_tsprotocol != INVALID); // Value must already have validated to have got here
// Exit if protocol has not changed
if (new_tsprotocol == mp->ts_protocol)
{
return USP_ERR_OK;
}
// Store new protocol
mp->ts_protocol = new_tsprotocol;
if ((mp->enable) && (mp->instance != INVALID))
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTCleanSession
**
** Function called when Device.MQTT.Client.{i}.CleanSession is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTCleanSession(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->clean_session = val_bool;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTCleanStart
**
** Function called when Device.MQTT.Client.{i}.CleanStart is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTCleanStart(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->clean_start = val_bool;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTRequestResponseInfo
**
** Function called when Device.MQTT.Client.{i}.RequestResponseInfo is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTRequestResponseInfo(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->request_response_info != val_bool) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->request_response_info = val_bool;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTRequestProblemInfo
**
** Function called when Device.MQTT.Client.{i}.RequestProblemInfo is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTRequestProblemInfo(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->request_problem_info != val_bool) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->request_problem_info = val_bool;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
#if 0
// TODO: These are removed as they are not used
/*********************************************************************//**
**
** NotifyChange_MQTTSessionExpiryInterval
**
** Function called when Device.MQTT.Client.{i}.SessionExpiryInterval is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTSessionExpiryInterval(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->session_expiry != val_uint) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->session_expiry = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTReceiveMaximum
**
** Function called when Device.MQTT.Client.{i}.ReceiveMaximum is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTReceiveMaximum(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->receive_max != val_uint) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->receive_max = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTMaximumPacketSize
**
** Function called when Device.MQTT.Client.{i}.MaximumPacketSize is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTMaximumPacketSize(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->max_packet_size != val_uint) && (mp->enable))
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->max_packet_size = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTTopicAliasMaximum
**
** Validates Device.MQTT.Client.{i}.TopicAliasMaximum by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTTopicAliasMaximum(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 0, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTTopicAliasMaximum
**
** Function called when Device.MQTT.Client.{i}.TopicAliasMaximum is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTTopicAliasMaximum(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
bool schedule_reconnect = false;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return EOK;
}
// Determine whether to schedule a reconnect
if ((mp->topic_alias_max != val_uint) && (mp->enable) && val_uint)
{
schedule_reconnect = true;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->topic_alias_max = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect)
{
ScheduleMqttReconnect(mp);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillEnable
**
** Function called when Device.MQTT.Client.{i}.WillEnable is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillEnable(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->will_enable = val_bool;
if( mp->will_enable && (!mp->will_topic || !mp->will_value))
{
return USP_ERR_INTERNAL_ERROR;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTWillQoS
**
** Validates Device.MQTT.Client.{i}.WillQoS by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTWillQoS(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 0, 2);
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillQoS
**
** Function called when Device.MQTT.Client.{i}.WillQoS is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillQoS(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->will_qos = val_uint;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillRetain
**
** Function called when Device.MQTT.Client.{i}.WillRetain is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillRetain(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value
// NOTE: We purposefully do not schedule a reconnect. This change takes effect, the next time USP Agent connects to the MQTT Broker
mp->will_retain = val_bool;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillDelayInterval
**
** Function called when Device.MQTT.Client.{i}.WillDelayInterval is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillDelayInterval(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->will_delay_interval = val_uint;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillMessageExpiryInterval
**
** Function called when Device.MQTT.Client.{i}.WillMessageExpiryInterval
** is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillMessageExpiryInterval(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->will_message_expiry = val_uint;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillContentType
**
** Function called when Device.MQTT.Client.{i}.WillContentType is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillContentType(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->will_content_type);
mp->will_content_type = USP_STRDUP(value);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillResponseTopic
**
** Function called when Device.MQTT.Client.{i}.WillResponseTopic is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillResponseTopic(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->will_response_topic);
mp->will_response_topic = USP_STRDUP(value);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTWillTopic
**
** Function called when Device.MQTT.Client.{i}.WillTopic is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTWillTopic(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->will_topic);
mp->will_topic = USP_STRDUP(value);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTTWillValue
**
** Function called when Device.MQTT.Client.{i}.WillValue is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTTWillValue(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->will_value);
mp->will_value = USP_STRDUP(value);
return USP_ERR_OK;
}
#endif
/*********************************************************************//**
**
** Validate_MQTTConnectRetryTime
**
** Validates Device.MQTT.Client.{i}.ConnectRetryTime by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTConnectRetryTime(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 1, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTConnectRetryTime
**
** Function called when Device.MQTT.Client.{i}.ConnectRetryTime is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTConnectRetryTime(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value.
mp->retry.connect_retrytime = val_uint;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTConnectRetryIntervalMultiplier
**
** Validates Device.MQTT.Client.{i}.ConnectRetryIntervalMultiplier by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTConnectRetryIntervalMultiplier(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 1000, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTConnectRetryIntervalMultiplier
**
** Function called when Device.MQTT.Client.{i}.ConnectRetryIntervalMultiplier is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTConnectRetryIntervalMultiplier(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value.
mp->retry.interval_multiplier = val_int;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTConnectRetryMaxInterval
**
** Validates Device.MQTT.Client.{i}.ConnectRetryMaxInterval by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTConnectRetryMaxInterval(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 1, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTConnectRetryMaxInterval
**
** Function called when Device.MQTT.Client.{i}.ConnectRetryMaxInterval is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTConnectRetryMaxInterval(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
// Set the new value.
mp->retry.max_interval = val_uint;
return USP_ERR_OK;
}
#if 0
// TODO: Removed as these are not yet used
/*********************************************************************//**
**
** NotifyChange_MQTTAuthenticationMethod
**
** Function called when Device.MQTT.Client.{i}.AuthenticationMethod is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTAuthenticationMethod(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return USP_ERR_INTERNAL_ERROR;
}
// Set the new name. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(mp->auth_method);
mp->auth_method = USP_STRDUP(value);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTPublishMessageExpiryInterval
**
** Function called when Device.MQTT.Client.{i}.PublishMessageExpiryInterval is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTPublishMessageExpiryInterval(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 5.0
if(mp->version != kMqttProtocol_5_0)
{
return USP_ERR_INTERNAL_ERROR;
}
// Set the new value. This must be done before scheduling a reconnect, so that the reconnect uses the correct values
mp->pubmsg_expinterval = val_uint;
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTMessageRetryTime
**
** Validates Device.MQTT.Client.{i}.MessageRetryTime by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTMessageRetryTime(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 1, 65535);
}
/*********************************************************************//**
**
** NotifyChange_MQTTMessageRetryTime
**
** Function called when Device.MQTT.Client.{i}.MessageRetryTime is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTMessageRetryTime(dm_req_t *req, char *value)
{
mqtt_conn_params_t *mp;
// Determine mqtt client to be updated
mp = FindMqttParamsByInstance(inst1);
USP_ASSERT(mp != NULL);
//this parameter only supports protocol version 3.1
if(mp->version != kMqttProtocol_3_1)
{
return USP_ERR_INTERNAL_ERROR;
}
// Set the new value.
mp->message_retrytime = val_uint;
return USP_ERR_OK;
}
#endif
/*********************************************************************//**
**
** ScheduleMQTTReconnect
**
** Wrapper function to schedule a MQTT reconnect with the current connection parameters
**
** \param mp - MQTT connection parameters
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
void ScheduleMqttReconnect(mqtt_conn_params_t *mp)
{
USP_SAFE_FREE(mp->response_topic);
USP_SAFE_FREE(mp->topic);
mp->response_topic = USP_STRDUP(DEVICE_MTP_GetAgentMqttResponseTopic(mp->instance));
mp->topic = USP_STRDUP(DEVICE_CONTROLLER_GetControllerTopic(mp->instance));
if( (mp->response_topic == NULL) || (mp->topic == NULL))
{
USP_LOG_Error("%s repsonse topic or topic not found", __FUNCTION__);
return;
}
MQTT_ScheduleReconnect(mp);
}
/*********************************************************************//**
**
** ScheduleMQTTResubscribe
**
** Wrapper function to schedule a MQTT resubscribe with current MQTT subscriptions
**
** \param mqttclient - MQTT client parameters
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
void ScheduleMQTTResubscribe(client_t *mqttclient, mqtt_subscription_t *sub)
{
USP_SAFE_FREE(mqttclient->conn_params.response_topic);
USP_SAFE_FREE(mqttclient->conn_params.topic);
mqttclient->conn_params.response_topic = USP_STRDUP(DEVICE_MTP_GetAgentMqttResponseTopic(mqttclient->conn_params.instance));
mqttclient->conn_params.topic = USP_STRDUP(DEVICE_CONTROLLER_GetControllerTopic(mqttclient->conn_params.instance));
if ((mqttclient->conn_params.response_topic == NULL) || (mqttclient->conn_params.topic == NULL))
{
USP_LOG_Error("%s repsonse topic or topic not found", __FUNCTION__);
return;
}
if ((mqttclient->conn_params.instance != INVALID) && (sub->instance != INVALID))
{
MQTT_ScheduleResubscription(mqttclient->conn_params.instance, sub);
}
}
/*********************************************************************//**
**
** ValidateAdd_Mqttclients
**
** Function called to determine whether a new MQTT client may be added
**
** \param req - pointer to structure identifying the Mqtt client
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int ValidateAdd_Mqttclients(dm_req_t *req)
{
mqtt_conn_params_t *mp;
// Exit if unable to find a free MQTT Client
mp = FindUnusedMqttParams();
if (mp == NULL)
{
USP_LOG_Error("Resources exceeded error\n");
return USP_ERR_RESOURCES_EXCEEDED;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Notify_MQTTClientAdded
**
** Function called when a Mqtt client has been added to Device.MQTT.Client.{i}
**
** \param req - pointer to structure identifying the MQTT client
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Notify_MQTTClientAdded(dm_req_t *req)
{
int err;
client_t *mqttclient;
// Exit if failed to copy from DB into mqtt client array
err = ProcessMqttClientAdded(inst1);
if (err != USP_ERR_OK)
{
USP_LOG_Error("Process MQTT client add failed");
return err;
}
// Start the connection (if enabled)
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL); // As we had just successfully added it
// Exit if no free slots to enable the connection. (Enable is successful, even if the connection is trying to reconnect)
err = EnableMQTTClient(&mqttclient->conn_params, mqttclient->subscriptions);
if (err != USP_ERR_OK)
{
USP_LOG_Error("Enable client failed");
return err;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** FindMQTTParamsByInstance
**
** Finds the mqtt params slot by it's data model instance number
**
** \param instance - instance number of the MQTT client in the data model
**
** \return pointer to slot, or NULL if slot was not found
**
**************************************************************************/
mqtt_conn_params_t *FindMqttParamsByInstance(int instance)
{
int i = 0;
mqtt_conn_params_t *mp = NULL;
// Iterate over all MQTT connections
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
// Exit if found a mqtt connection that matches the instance number
mp = &mqtt_client_params[i].conn_params;
if (mp->instance == instance)
{
return mp;
}
}
USP_LOG_Error("%s: failed", __FUNCTION__);
// If the code gets here, then no matching slot was found
return NULL;
}
/*********************************************************************//**
**
** FindDevMqttClientByInstance
**
** Finds the mqtt client by it's connect params instance number
**
** \param instance - instance number of the MQTT client in the data model
**
** \return pointer to slot, or NULL if slot was not found
**
**************************************************************************/
client_t *FindDevMqttClientByInstance(int instance)
{
int i;
client_t *mqttclient;
// Iterate over all MQTT connections
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
mqttclient = &mqtt_client_params[i];
// Exit if found a mqtt connection that matches the instance number
if (mqttclient->conn_params.instance == instance)
{
return mqttclient;
}
}
// If the code gets here, then no matching slot was found
return NULL;
}
/*************************************************************************
**
** Notify_MqttClientDeleted
**
** Function called when a MQTT Client has been deleted from Device.MQTT.Client.{i}
**
** \param req - pointer to structure identifying the connection
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Notify_MqttClientDeleted(dm_req_t *req)
{
client_t* client;
client = FindDevMqttClientByInstance(inst1);
// If we couldn't find it, it's probably ok - must have been deleted?
if (client == NULL)
{
return USP_ERR_OK;
}
DestroyMQTTClient(client);
// Unpick references to this connection
DEVICE_CONTROLLER_NotifyMqttConnDeleted(inst1);
DEVICE_MTP_NotifyMqttConnDeleted(inst1);
return USP_ERR_OK;
}
/*********************************************************************//**
**
** DestroyMQTTClient
**
** Frees all memory associated with the specified MQTT client
**
** \param mp - pointer to MQTT client to free
**
** \return None
**
**************************************************************************/
void DestroyMQTTClient(client_t *client)
{
mqtt_conn_params_t* mp = &client->conn_params;
// Disable the lower level connection
MQTT_DisableClient(mp->instance, true);
// Free and DeInitialise the slot
MQTT_DestroyConnParams(mp);
for (int i = 0; i < MAX_MQTT_SUBSCRIPTIONS; i++)
{
USP_SAFE_FREE(client->subscriptions[i].topic);
}
}
/*********************************************************************//**
**
** FindUnusedMqttParams
**
** Finds the first free mqtt params slot
**
** \param None
**
** \return Pointer to first free slot, or NULL if no slot was found
**
**************************************************************************/
mqtt_conn_params_t *FindUnusedMqttParams(void)
{
int i;
mqtt_conn_params_t *mp;
// Iterate over all MQTT clients
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
// Exit if found an unused slot
mp = &mqtt_client_params[i].conn_params;
if (mp->instance == INVALID)
{
return mp;
}
}
// If the code gets here, then no free slot has been found
USP_ERR_SetMessage("%s: Only %d MQTT clients are supported.", __FUNCTION__, MAX_MQTT_CLIENTS);
return NULL;
}
/*********************************************************************//**
**
** FindUnusedMqttClient
**
** Finds the first free mqtt client slot
**
** \param None
**
** \return Pointer to first free slot, or NULL if no slot was found
**
**************************************************************************/
client_t *FindUnusedMqttClient(void)
{
int i;
client_t *mqttclient;
// Iterate over all MQTT clients
for (i=0; i<MAX_MQTT_CLIENTS; i++)
{
// Exit if found an unused slot
mqttclient = &mqtt_client_params[i];
if (mqttclient->conn_params.instance == INVALID)
{
return mqttclient;
}
}
// If the code gets here, then no free slot has been found
USP_ERR_SetMessage("%s: Only %d MQTT clients are supported.", __FUNCTION__, MAX_MQTT_CLIENTS);
return NULL;
}
/*********************************************************************//**
**
** FindUnusedSubscriptionInMqttClient
**
** Finds the first free mqtt subscription slot within a client
**
** \param client_t - pointer to client object to check
**
** \return Pointer to first free subscription slot, or NULL if no slot was found
**
**************************************************************************/
mqtt_subscription_t* FindSubscriptionInMqttClient(client_t* client, int instance)
{
mqtt_subscription_t* sub = NULL;
for(int i = 0; i < MAX_MQTT_SUBSCRIPTIONS; i++)
{
sub = &client->subscriptions[i];
if (sub->instance == instance)
{
return sub;
}
}
return NULL;
}
/*********************************************************************//**
**
** FindUnusedSubscriptionInMqttClient
**
** Finds the first free mqtt subscription slot within a client
**
** \param client_t - pointer to client object to check
**
** \return Pointer to first free subscription slot, or NULL if no slot was found
**
**************************************************************************/
mqtt_subscription_t* FindUnusedSubscriptionInMqttClient(client_t* client)
{
// Just find a subscription with an INVALID instance
mqtt_subscription_t* sub = FindSubscriptionInMqttClient(client, INVALID);
if (sub != NULL)
{
// Success - return early
return sub;
}
// If the code gets here, then no free slot has been found
USP_ERR_SetMessage("%s: Only %d MQTT subscriptions are supported.", __FUNCTION__, MAX_MQTT_SUBSCRIPTIONS);
return NULL;
}
/*********************************************************************//**
**
** ValidateAdd_MqttClientSubscriptions
**
** Function called to determine whether a new MQTT client Subs may be added
**
** \param req - pointer to structure identifying the Mqtt client
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int ValidateAdd_MqttClientSubscriptions(dm_req_t *req)
{
client_t *mqttclient;
// Exit if unable to find a free MQTT subscription
mqttclient = FindDevMqttClientByInstance(inst1);
if (mqttclient == NULL)
{
USP_LOG_Error("No matching MQTT client for instance: %d\n", inst1);
return USP_ERR_RESOURCES_EXCEEDED;
}
mqtt_subscription_t* sub = FindUnusedSubscriptionInMqttClient(mqttclient);
if (sub == NULL)
{
return USP_ERR_RESOURCES_EXCEEDED;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Notify_MqttClientSubcriptionsAdded
**
** Function called when a Mqtt client subs has been added to
** Device.MQTT.Client.{i}.Subscritptions.{i}
**
** \param req - pointer to structure identifying the MQTT client
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Notify_MqttClientSubcriptionsAdded(dm_req_t *req)
{
int err;
client_t *mqttclient;
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL); // As we had just successfully added it
// Exit if failed to copy from DB into mqtt client array
err = ProcessMqttSubscriptionAdded(inst1, inst2);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage(" %s: Process MQTT client added failed\n", __FUNCTION__);
return err;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Notify_MqttClientSubscriptionsDeleted
**
** Function called when a MQTT Client subs has been deleted from
** Device.MQTT.Client.{i}.Subscriptions.{i}.
**
** \param req - pointer to structure identifying the connection
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Notify_MqttClientSubscriptionsDeleted(dm_req_t *req)
{
client_t *mqttclient;
int err = USP_ERR_OK;
mqttclient = FindDevMqttClientByInstance(inst1);
if (mqttclient == NULL)
{
return USP_ERR_OK;
}
mqtt_subscription_t* sub = FindSubscriptionInMqttClient(mqttclient, inst2);
if (sub == NULL)
{
USP_ERR_SetMessage("%s: Delete subscription failed\n", __FUNCTION__);
return USP_ERR_INTERNAL_ERROR;
}
// Delete the subscription from device_mqtt
MQTT_SubscriptionDestroy(sub);
// Delete the subscription from core mqtt
err = MQTT_DeleteSubscription(inst1, inst2);
if (err != USP_ERR_OK)
{
USP_ERR_SetMessage("%s: Delete subscription failed\n", __FUNCTION__);
return err;
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** NotifyChange_MQTTSubscriptionEnable
**
** Function called when Device.MQTT.Connection.{i}.Subscription.{j}.
** Enable is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTSubscriptionEnable(dm_req_t *req, char *value)
{
client_t *mqttclient;
mqtt_subscription_t *sub;
bool old_value;
// Initialise to defaults
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL);
sub = FindSubscriptionInMqttClient(mqttclient, inst2);
if (sub == NULL)
{
USP_ERR_SetMessage("%s: Subscription enable change failed\n", __FUNCTION__);
return USP_ERR_INTERNAL_ERROR;
}
old_value = sub->enabled;
// Exit early if enable has not changed
if (old_value == val_bool)
{
return USP_ERR_OK;
}
// Store new subscription state
sub->enabled = val_bool;
if ((mqttclient->conn_params.instance != INVALID) && (sub->instance != INVALID))
{
ScheduleMQTTResubscribe(mqttclient, sub);
}
return USP_ERR_OK;
}
/*************************************************************************
**
** NotifyChange_MQTTSubscriptionTopic
**
** Function called when Device.MQTT.Client.{i}.Subscriptions.{j}.Topic
** is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTSubscriptionTopic(dm_req_t *req, char *value)
{
client_t *mqttclient;
mqtt_subscription_t *sub;
bool schedule_reconnect = false;
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL);
// inst2 is the subscriptions starting from 1, not 0
// So we need -1
sub = FindSubscriptionInMqttClient(mqttclient, inst2);
if (sub == NULL)
{
USP_ERR_SetMessage("%s: Subscription topic change failed\n", __FUNCTION__);
return USP_ERR_INTERNAL_ERROR;
}
if((strcmp(sub->topic, value)) && (sub->enabled))
{
schedule_reconnect = true;
}
// Set the new value.
// This must be done before scheduling a reconnect, so that the reconnect uses the correct values
USP_SAFE_FREE(sub->topic);
sub->topic = USP_STRDUP(value);
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect && (sub->instance != INVALID))
{
ScheduleMQTTResubscribe(mqttclient, sub);
}
return USP_ERR_OK;
}
/*********************************************************************//**
**
** Validate_MQTTSubscriptionQoS
**
** Validates Device.MQTT.Client.{i}.Subscriptions.{j}.QoS by checking if valid number
**
** \param req - pointer to structure identifying the parameter
** \param value - value that the controller would like to set the parameter to
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int Validate_MQTTSubscriptionQoS(dm_req_t *req, char *value)
{
return DM_ACCESS_ValidateRange_Unsigned(req, 0, 2);
}
/*************************************************************************
**
** NotifyChange_MQTTSubscriptionQoS
**
** Function called when Device.MQTT.Client.{i}.Subscriptions.{j}.QoS
** is modified
**
** \param req - pointer to structure identifying the path
** \param value - new value of this parameter
**
** \return USP_ERR_OK if successful
**
**************************************************************************/
int NotifyChange_MQTTSubscriptionQoS(dm_req_t *req, char *value)
{
client_t *mqttclient;
mqtt_subscription_t *sub;
mqtt_qos_t old_qos;
bool schedule_reconnect = false;
// Initialise to defaults
//mqttclient = FindDevMqttClientSubscriptionByInstance(inst1, inst2);
mqttclient = FindDevMqttClientByInstance(inst1);
USP_ASSERT(mqttclient != NULL);
// inst2 is the subscription index starting from 1
// Not 0, so we need to -1 to the array index
sub = FindSubscriptionInMqttClient(mqttclient, inst2);
if (sub == NULL)
{
USP_ERR_SetMessage("%s: Subscription QoS change failed\n", __FUNCTION__);
return USP_ERR_INTERNAL_ERROR;
}
old_qos = sub->qos;
if(old_qos != val_uint && (sub->enabled))
{
schedule_reconnect = true;
}
sub->qos = val_uint;
// Schedule a reconnect after the present response has been sent, if the value has changed
if (schedule_reconnect && (sub->instance != INVALID))
{
ScheduleMQTTResubscribe(mqttclient, sub);
}
return USP_ERR_OK;
}
#endif
|
the_stack_data/117328188.c | /*
*
* This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
*
* Copyright 2007-2020 Broadcom Inc. All rights reserved.
*
* netserve: proxy server for stdio.
*
* This daemon connects a network socket to stdio of a local
* application through a pseudo TTY, thus enabling access to
* the application from a telnet client. Terminating the
* telnet session does not terminate the application, i.e.
* it is possible to connect several times to the same
* instance of the application.
*
* Example launching bcm.user on port 5611:
*
* netserve -d 5611 bcm.user
*
* Now connect to bcm.user, e.g. like this:
*
* telnet 127.0.0.1 5611
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <pty.h>
#include <arpa/inet.h>
/* Telnet definitions */
#define T_CMD 255
#define T_DONT 254
#define T_DO 253
#define T_WONT 252
#define T_WILL 251
#define T_ECHO 1
#define T_SGA 3
static unsigned char will_sga[] = { T_CMD, T_WILL, T_SGA };
static unsigned char will_echo[] = { T_CMD, T_WILL, T_ECHO };
static unsigned char dont_echo[] = { T_CMD, T_DONT, T_ECHO };
/* Network server */
static volatile int _netfd = -1;
static int _server_socket;
static int
_setup_socket(int port)
{
struct sockaddr_in addr;
int i;
int sockfd;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("server: can't open stream socket");
exit(1);
}
/*
* Set socket option to reuse local address. This is supposed
* to have the effect of freeing up the local address.
*/
i = 1;
if (setsockopt(sockfd, SOL_SOCKET,
SO_REUSEADDR, (char *) &i, 4) < 0) {
perror("setsockopt");
}
/* Set up server address */
memset((void *) &addr,0x0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_port = htons(port);
/* Bind our local address and port */
if (bind(sockfd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("server: can't bind local address");
exit(1);
}
/* Only process one connection at a time */
listen(sockfd, 1);
return sockfd;
}
static int
_wait_for_connection(int sockfd)
{
struct sockaddr_in addr;
socklen_t len;
int newsockfd;
len = sizeof(addr);
if ((newsockfd = accept(sockfd, (struct sockaddr *) &addr, &len)) < 0) {
perror("accept");
exit(1);
}
/* Telnet response required for correct interaction with app */
write(newsockfd, will_sga, sizeof(will_sga));
write(newsockfd, will_echo, sizeof(will_echo));
write(newsockfd, dont_echo, sizeof(dont_echo));
return newsockfd;
}
static void
_do_telnet(int ifd, int ofd)
{
unsigned char cmd[8];
int i;
/* Read command */
for (i = 1; i < 3; i++) {
if (read(ifd, &cmd[i], 1) != 1) {
return;
}
}
/* Select negative response */
switch (cmd[1]) {
case T_WILL:
case T_WONT:
cmd[1] = T_DONT;
break;
case T_DO:
case T_DONT:
cmd[1] = T_WONT;
break;
default:
/* Ignore */
return;
}
/* Ignore responses to our own commands */
switch (cmd[2]) {
case T_ECHO:
case T_SGA:
return;
}
/* Send response */
cmd[0] = T_CMD;
write(ofd, &cmd, 3);
}
static void *
_net2tty(void *arg)
{
int fd = *((int *)arg);
unsigned char data;
while (1) {
while (_netfd < 0) {
usleep(100000);
}
if (read(_netfd, &data, 1) != 1) {
/* Broken pipe -- client quit */
close(_netfd);
_netfd = -1;
raise(SIGUSR2);
} else if (data == T_CMD) {
_do_telnet(_netfd, fd);
} else {
write(fd, &data, 1);
fsync(fd);
}
}
return NULL;
}
static void *
_tty2net(void *arg)
{
int fd = *((int *)arg);
unsigned char data;
while (1) {
if (read(fd, &data, 1) != 1) {
/* Broken pipe -- app quit */
close(fd);
break;
}
if (_netfd >= 0) {
write(_netfd, &data, 1);
fsync(_netfd);
}
}
return NULL;
}
static int
_start_app(char **args, int s)
{
pid_t pid;
if ((pid = fork()) < 0) {
perror ("fork");
return -1;
}
if (pid > 0) {
return pid;
}
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
execv(*args, args);
exit(0);
}
static void
_restart(void)
{
int s;
if ((s = _wait_for_connection(_server_socket)) < 0) {
fprintf(stderr, "connection error\n");
exit(0);
}
/* Reenable the proxies with the new fd */
_netfd = s;
}
static void
_sig(int sig)
{
if (sig == SIGUSR2) {
_restart();
}
}
int
main(int argc, char *argv[])
{
int p;
int pid;
int do_fork = 0;
int ttyfd, appfd;
pthread_t id;
argv++;
if (!*argv || !strcmp(*argv, "--help") || !strcmp(*argv, "-h")) {
printf("usage: netserve [-d] <port> <program> [args]\n");
exit(0);
}
if (!strcmp(*argv, "-d")) {
do_fork = 1;
argv++;
}
if ((p = atoi(*argv++)) == 0) {
fprintf(stderr, "bad port number\n");
exit(0);
}
if (do_fork) {
/* Daemonize */
pid = fork();
if (pid < 0) {
perror("fork()");
exit(0);
}
if (pid > 0) {
exit(0);
}
setsid();
}
/* Broken pipes are not a problem */
signal(SIGPIPE, SIG_IGN);
/* Get a pseudo tty */
if (openpty(&ttyfd, &appfd, NULL, NULL, NULL) < 0) {
perror("open pty");
exit(0);
}
/* Start the application up with sv[1] as its stdio */
pid = _start_app(argv, appfd);
/* Start proxy for input */
if (pthread_create(&id, NULL, _net2tty, (void *)&ttyfd) < 0) {
perror("pthread_create");
exit(0);
}
/* Start proxy for output */
if (pthread_create(&id, NULL, _tty2net, (void *)&ttyfd) < 0) {
perror("pthread_create");
exit(0);
}
/* Setup server */
_server_socket = _setup_socket(p);
/* SIGUSR2 restarts the server when the client connection closes */
signal(SIGUSR2, _sig);
/* Start the first server */
raise(SIGUSR2);
/* Wait for our child to exit */
waitpid(pid, &p, 0);
return 0;
}
|
the_stack_data/145765.c | #include"stdio.h"
void increament(double a[],int n)
{
int i;
for(i=0;i<n;i++)
a[i]+=2;
}
void dis(double a[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("\n%.1f",a[i]);
}
}
main()
{
double a[20];
int i,n;
printf("Please enter the number of elements\n");
scanf("%d",&n);
if(n>20)
printf("overflow \ntry for less than or equal to value 20\n");
else
{
printf("Please enter the array elements\n");
for(i=0;i<n;i++)
{
scanf("%lf",&a[i]);
}
dis(a,n);
printf("\n");
increament(a,n);
dis(a,n);
printf("\n");
}
}
|
the_stack_data/162023.c | #include <math.h>
#include <stdbool.h>
#include <stdio.h>
#define EP 0.00001
int main() {
double x, y = 1.0, new_y;
printf("Enter a positive number: ");
scanf("%lf", &x);
while (true) {
new_y = (y + x / y) / 2;
if (fabs(new_y - y) < EP * y)
break;
else
y = new_y;
}
printf("Square root: %lf\n", y);
return 0;
}
// Enter a positive number: 3 |
the_stack_data/305537.c | #include <stdio.h>
void calculate(float a, float b, int operator);
int main() {
float a, b;
int operator;
printf("main\n");
printf("Insert first number: ");
scanf("%f", &a);
printf("Insert second number: ");
scanf("%f", &b);
printf("Insert operator (1=+, 2=-, 3=*, 4=/): ");
scanf("%d", &operator);
calculate(a, b, operator);
printf("Come back to main and finish\n");
return 0;
}
void calculate(float a, float b, int operator) {
float result;
printf("I am in procedure\n");
switch (operator) {
case 1:
result = a + b;
break;
case 2:
result = a - b;
break;
case 3:
result = a * b;
break;
case 4:
result = a / b;
break;
default:
result = a + b;
break;
}
printf("The result is: %f\n", result);
} |
the_stack_data/156392392.c | /* ヘッダファイルのインクルード */
#include <stdio.h> /* 標準入出力 */
#include <stdlib.h> /* 標準ユーティリティ */
#include <string.h> /* 文字列操作 */
/* 関数のプロトタイプ宣言 */
void create(char **ptr); /* 動的配列を作成し, 初期文字列を入れる関数createの宣言. */
void destroy(char **ptr); /* 動的配列を破棄する関数destroyの宣言. */
/* main関数の定義 */
int main(void){
/* ポインタへのポインタの宣言と, ポインタの初期化. */
int **ptr_to_ptr; /* int型ポインタへのポインタptr_to_ptr. */
int i; /* ループ用変数i */
int j; /* ループ用変数j */
char *buf_ptr = NULL; /* 文字列を格納するバッファへのポインタbuf_ptr(自ら確保する必要はない.). */
/* int型ポインタ動的配列の生成. */
ptr_to_ptr = (int **)malloc(sizeof(int *) * 5); /* mallocでint型ポインタ動的配列(要素数5)を生成し, 戻り値のポインタはptr_to_ptrに格納. */
/* int型動的配列生成し, そのポインタをint型ポインタ動的配列の各要素に格納. */
for (i = 0; i < 5; i++){ /* 0から4まで5回繰り返す. */
*(ptr_to_ptr + i) = (int *)malloc(sizeof(int) * 5); /* mallocでint型動的配列(要素数5)を生成し, 戻り値のポインタはptr_to_ptrに格納. */
}
/* 各要素への値の代入. */
for (i = 0; i < 5; i++){ /* iが0から4まで5回繰り返す. */
for (j = 0; j < 5; j++){ /* jが0から4まで5回繰り返す. */
*(*(ptr_to_ptr + i) + j) = 5 * i + j; /* 5 * i + jを格納. */
}
}
/* 各要素の値を出力. */
for (i = 0; i < 5; i++){ /* iが0から4まで5回繰り返す. */
for (j = 0; j < 5; j++){ /* jが0から4まで5回繰り返す. */
printf("*(*(ptr_to_ptr + %d) + %d) = %d\n", i, j, *(*(ptr_to_ptr + i) + j)); /* *(*(ptr_to_ptr + i) + j)を出力. */
}
}
/* 動的配列の破棄 */
for (i = 0; i < 5; i++){ /* 0から4まで5回繰り返す. */
free(*(ptr_to_ptr + i)); /* freeで*(ptr_to_ptr + i)を破棄. */
}
free(ptr_to_ptr); /* ポインタへのポインタを破棄. */
/* 文字列の生成 */
create(&buf_ptr); /* createにbuf_ptrのアドレスを渡す. */
/* 文字列の出力 */
printf("buf_ptr = %s\n", buf_ptr); /* printfでbuf_ptrを出力. */
/* 文字列の破棄 */
destroy(&buf_ptr); /* destroyにbuf_ptrのアドレス渡す. */
/* プログラムの終了 */
return 0;
}
/* 関数createの定義 */
void create(char **ptr){
/* 動的配列の生成と文字列のセット. */
*ptr = (char *)malloc(sizeof(char) * 6); /* mallocでNULL文字含めて6文字分入る動的配列を生成. */
strcpy(*ptr, "ABCDE"); /* strcpyで*ptrに"ABCDE"をコピー. */
}
/* 関数destroyの定義 */
void destroy(char **ptr){
/* 動的配列の破棄 */
free(*ptr); /* freeで*ptrを破棄. */
*ptr = NULL; /* *ptrをNULLで埋める. */
}
|
the_stack_data/1223953.c | #include <stdio.h>
int main (){
float x;
scanf("%f", &x);
if(x >= 0 && x <= 25){
printf("Intervalo [0,25]\n");
}
else if(x > 25 && x <= 50){
printf("Intervalo (25,50]\n");
}
else if(x > 50 && x <= 75){
printf("Intervalo (50,75]\n");
}
else if(x > 75 && x <= 100){
printf("Intervalo (75,100]\n");
}
else if(x < 0 || x > 100){
printf("Fora de intervalo\n");
}
return 0;
}
|
the_stack_data/95198.c | #include <stdio.h>
int main() {
long long int N, num, contaUm = 0, maior = 0;
scanf("%lld", &N);
while (N > 0) {
scanf("%lld", &num);
while (num != 0) {
if (num % 2) {
contaUm++;
if (contaUm >= maior) {
maior = contaUm;
}
} else {
contaUm = 0;
}
num /= 2;
}
printf("%lld\n", maior);
contaUm = 0;
maior = 0;
N--;
}
return 0;
} |
the_stack_data/43886739.c | #include <stdio.h>
void soma(){
int n1,n2,soma=0;
printf("Por favor insira aqui o seu primeiro numero: \n");
scanf("%d", &n1);
printf("Por favor insira aqui o seu segundo numero: \n");
scanf("%d", &n2);
soma=n1+n2;
printf("O resultado da soma dos dois valores e de: %d\n",soma);
}
int main(){
soma();
printf("E as contas continuam!\n");
soma();
soma();
soma();
}
|
the_stack_data/53010.c | #include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#define N 5
#define LEFT phil
#define RIGHT ((phil + 1) % N)
pthread_mutex_t arbitrator;
pthread_mutex_t mtxs[N];
pthread_t philosophers[N];
int num[N] = {0, 1, 2, 3, 4};
static inline void nonOptimizedBusyWait(void){
for(long i = 0; i < 10000000; i++){
// "Memory clobber" - tells the compiler to optimize that all the memory
// is being touched, and that therefore the loop cannot be optimized out
asm volatile("" ::: "memory");
}
}
void take_fork(int num){
pthread_mutex_lock(&mtxs[num]);
}
void give_fork(int num){
pthread_mutex_unlock(&mtxs[num]);
}
void* fn(void* args){
int* j = args;
int phil = *j;
printf("Philosopher %d\n", phil);
pthread_mutex_lock(&arbitrator);
printf("Philosopher %d taking fork %d\n", phil, LEFT);
take_fork(LEFT);
printf("Philosopher %d took fork %d\n", phil, LEFT);
nonOptimizedBusyWait();
printf("Philosopher %d taking fork %d\n", phil, RIGHT);
take_fork(RIGHT);
printf("Philosopher %d took fork %d\n", phil, RIGHT);
pthread_mutex_unlock(&arbitrator);
// EATING
printf("Philosopher %d eating\n", phil);
nonOptimizedBusyWait();
printf("Philosopher %d giving fork %d\n", phil, RIGHT);
give_fork(RIGHT);
printf("Philosopher %d gave fork %d\n", phil, RIGHT);
nonOptimizedBusyWait();
printf("Philosopher %d giving fork %d\n", phil, LEFT);
give_fork(LEFT);
printf("Philosopher %d gave fork %d\n", phil, LEFT);
return NULL;
}
int main(){
pthread_mutex_init(&arbitrator, NULL);
for (int i = 0; i < N; i++){
pthread_mutex_init(&mtxs[i], NULL);
}
for (int i = 0; i < N; i++){
pthread_create(&philosophers[i], NULL, fn, &num[i]);
}
for (int i = 0; i < N; i++){
pthread_join(philosophers[i], NULL);
}
for (int i = 0; i < N; i++){
pthread_mutex_destroy(&mtxs[i]);
}
pthread_mutex_destroy(&arbitrator);
} |
the_stack_data/74756.c | /* uncompr.c -- decompress a memory buffer
* Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id: uncompr.c,v 1.7 2010/04/21 20:36:23 drolon Exp $ */
#define ZLIB_INTERNAL
#include "zlib.h"
/* ===========================================================================
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
int ZEXPORT uncompress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
err = inflateInit(&stream);
if (err != Z_OK) return err;
err = inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
err = inflateEnd(&stream);
return err;
}
|
the_stack_data/179830613.c | /*Bloque 4.2*/
#include<stdio.h>
int factorial(int a);
int main(){
int x,y,fac1,fac2;
printf("Escriba el numero que desee saber su factorial: "); scanf("%i",&x);
printf("Ahora, el segundo numero que desee saber su factorial: "); scanf("%i",&y);
fac1 = factorial(x);
fac2 = factorial(y);
printf("El primer factorial es: %i.\n\n",fac1);
printf("El segundo factorial es: %i.\n\n",fac2);
system("pause");
return 0;
}
int factorial(int a){
int i,aux=1;
for(i=1;i<=a;i++){
aux *= i;
}
return aux;
}
|
the_stack_data/234348.c |
void print(int n){}
void fibonacci1() {
int lo = 0;
int hi = 1;
while (hi < 10000) {
int tmp = hi;
hi = hi + lo;
lo = tmp;
print(lo);
}
}
int main() {
return 0;
}
|
the_stack_data/59513833.c | char *components = "components";
|
the_stack_data/161081652.c | const unsigned char logo[] ={
0x00, 0x80, 0x80, 0x80, 0xF8, 0x88, 0x88, 0x88, 0x08, 0x08, 0x0F, 0x08, 0x08, 0x08, 0x08, 0xF8, // 0x0010 (16) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0xFF, 0xFF, 0x63, 0x21, 0x61, 0xE3, // 0x0020 (32) pixels
0x9E, 0x1E, 0x00, 0x00, 0x00, 0x10, 0xF7, 0xF3, 0x00, 0x00, 0x00, 0x10, 0xF8, 0xF0, 0x10, 0x10, // 0x0030 (48) pixels
0x18, 0xF0, 0xE0, 0x00, 0x00, 0x01, 0x03, 0xFF, 0x80, 0x80, 0xD0, 0x30, 0x10, 0x10, 0x00, 0x20, // 0x0040 (64) pixels
0xF0, 0xF0, 0x00, 0x00, 0xF0, 0x30, 0x00, 0x80, 0x80, 0xC0, 0x80, 0x01, 0x03, 0xFF, 0xFF, 0x01, // 0x0050 (80) pixels
0x01, 0x01, 0x01, 0x06, 0xFE, 0xF8, 0x60, 0x00, 0x00, 0x10, 0xF7, 0xF3, 0x00, 0x00, 0x00, 0x10, // 0x0060 (96) pixels
0xF8, 0xF0, 0x10, 0x10, 0x18, 0xF0, 0xE0, 0x00, 0x00, 0x01, 0x03, 0xFF, 0x80, 0x80, 0xD0, 0x30, // 0x0070 (112) pixels
0x10, 0x10, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x08, 0x08, 0x88, // 0x0080 (128) pixels
0x68, 0x1F, 0x68, 0x88, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x0F, 0x0F, 0x08, 0x08, // 0x0090 (144) pixels
0x00, 0x03, 0x0F, 0x0E, 0x0C, 0x04, 0x00, 0x08, 0x0F, 0x0F, 0x08, 0x00, 0x00, 0x08, 0x0F, 0x0F, // 0x00A0 (160) pixels
0x00, 0x00, 0x08, 0x0F, 0x0D, 0x08, 0x00, 0x08, 0x0C, 0x0F, 0x09, 0x09, 0x0B, 0x0E, 0x0C, 0x08, // 0x00B0 (176) pixels
0x00, 0xC0, 0x80, 0xC7, 0x3C, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0C, 0x0F, // 0x00C0 (192) pixels
0x0F, 0x08, 0x08, 0x08, 0x08, 0x0C, 0x07, 0x03, 0x00, 0x00, 0x00, 0x08, 0x0F, 0x0F, 0x08, 0x00, // 0x00D0 (208) pixels
0x00, 0x08, 0x0F, 0x0F, 0x00, 0x00, 0x08, 0x0F, 0x0D, 0x08, 0x00, 0x08, 0x0C, 0x0F, 0x09, 0x09, // 0x00E0 (224) pixels
0x0B, 0x0E, 0x0C, 0x08, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x38, // 0x00F0 (240) pixels
0x26, 0x21, 0x20, 0xE0, 0x20, 0x21, 0x26, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x18, // 0x0100 (256) pixels
0xF8, 0xF8, 0x18, 0x08, 0xC8, 0x08, 0x38, 0xF8, 0x00, 0x00, 0x18, 0xF8, 0x38, 0x00, 0x00, 0x80, // 0x0110 (272) pixels
0xC0, 0x40, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0xC0, 0xC0, // 0x0120 (288) pixels
0xF0, 0xC0, 0xC0, 0x01, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, // 0x0130 (304) pixels
0xC0, 0x80, 0x80, 0x00, 0x00, 0x80, 0xC0, 0x80, 0x80, 0x80, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, // 0x0140 (320) pixels
0x80, 0xB8, 0x98, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x80, 0xC0, 0x40, // 0x0150 (336) pixels
0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x1F, 0x11, 0x11, 0x11, 0x10, 0x10, // 0x0160 (352) pixels
0xF0, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x0170 (368) pixels
0x40, 0x60, 0x7F, 0x7F, 0x41, 0x43, 0x47, 0x40, 0x60, 0x78, 0x08, 0x00, 0x40, 0x7F, 0x7F, 0x40, // 0x0180 (384) pixels
0x0E, 0x3F, 0x64, 0x44, 0x44, 0x67, 0x37, 0x00, 0x00, 0x3E, 0x7F, 0x40, 0xC0, 0x47, 0x77, 0x20, // 0x0190 (400) pixels
0x00, 0x3E, 0xFF, 0x40, 0x40, 0x30, 0x00, 0x61, 0x7F, 0x41, 0x01, 0x01, 0x01, 0x00, 0x00, 0x1E, // 0x01A0 (416) pixels
0x3F, 0x41, 0x40, 0x40, 0x61, 0x3F, 0x0E, 0x40, 0x7F, 0x7F, 0x00, 0x00, 0x40, 0x7F, 0x6F, 0x40, // 0x01B0 (432) pixels
0x00, 0x00, 0x40, 0x7F, 0x7F, 0x40, 0x00, 0x3E, 0x7F, 0x40, 0xC0, 0x47, 0x77, 0x20, 0x00, 0xF7, // 0x01C0 (448) pixels
0x46, 0x8C, 0x8C, 0x5D, 0x38, 0x00, 0x00, 0x00,
};
const unsigned char The_End[] ={
0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, // 0x0010 (16) pixels
0x80, 0xC0, 0xC0, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0020 (32) pixels
0xC0, 0xC0, 0xC0, 0xC0, 0xE0, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0xC0, 0xC0, 0xE0, // 0x0030 (48) pixels
0xE0, 0xC0, 0xC0, 0xC0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0xC0, 0x00, 0x00, // 0x0040 (64) pixels
0x00, 0x00, 0x80, 0xE0, 0xF0, 0xF0, 0x60, 0x40, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, // 0x0050 (80) pixels
0x80, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x81, 0xFC, 0xFF, 0x0F, 0x03, 0x00, 0x00, 0x00, // 0x0060 (96) pixels
0xEE, 0x6F, 0x67, 0xFF, 0xFF, 0x7F, 0x71, 0x30, 0xF0, 0xFF, 0x3F, 0x39, 0x38, 0x18, 0x00, 0x01, // 0x0070 (112) pixels
0x00, 0xF8, 0xFF, 0x1F, 0x0F, 0x0C, 0x0D, 0x8D, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // 0x0080 (128) pixels
0x00, 0xC0, 0xFF, 0x7F, 0x0F, 0x0C, 0x0D, 0x0D, 0x84, 0x80, 0x80, 0x07, 0x07, 0x83, 0xFF, 0xFF, // 0x0090 (144) pixels
0x1F, 0x3F, 0xFE, 0xF8, 0xF8, 0xFE, 0xDF, 0x03, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xFF, 0x1F, 0x00, // 0x00A0 (160) pixels
0x00, 0x80, 0x81, 0xC3, 0xE7, 0x7F, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x06, 0x07, 0x07, 0x03, 0x00, // 0x00B0 (176) pixels
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x0F, 0x0F, 0x07, 0x00, // 0x00C0 (192) pixels
0x00, 0x06, 0x06, 0x3F, 0x1F, 0x0F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x03, 0x00, 0x00, // 0x00D0 (208) pixels
0x00, 0x00, 0x06, 0x1F, 0x3F, 0x1F, 0x0F, 0x0E, 0x06, 0x06, 0x06, 0x07, 0x07, 0x07, 0x03, 0x00, // 0x00E0 (224) pixels
0x06, 0x0F, 0x07, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x07, 0x03, 0x00, 0x00, 0x18, 0x1C, 0x1F, // 0x00F0 (240) pixels
0x0F, 0x07, 0x06, 0x07, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00,
};
const unsigned char pacman1[] ={
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3E, 0x1C, // 0x0010 (16) pixels
0x0C, 0x00, 0x00, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
0xF0, 0xE0, 0xC0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00,
};
const unsigned char pacman2[] ={
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0x7C, // 0x0010 (16) pixels
0x7C, 0x38, 0x20, 0x00, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF9, // 0x0020 (32) pixels
0xF9, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03, 0x01, 0x00, 0x00,
};
const unsigned char pacman3[] ={
0x80, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFC, // 0x0010 (16) pixels
0xF8, 0xF0, 0xE0, 0x80, 0x1F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0x0020 (32) pixels
0xFF, 0xFF, 0xFF, 0xFF, 0xFB, 0xF9, 0x79, 0x19, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x07, 0x0F, // 0x0030 (48) pixels
0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00,
};
const unsigned char pill[] ={
0x0E, 0x1F, 0x1F, 0x1F, 0x0E,
};
|
the_stack_data/52398.c | /*
** 2015-05-25
**
** 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 is a utility program designed to aid running regressions tests on
** the SQLite library using data from an external fuzzer, such as American
** Fuzzy Lop (AFL) (http://lcamtuf.coredump.cx/afl/).
**
** This program reads content from an SQLite database file with the following
** schema:
**
** CREATE TABLE db(
** dbid INTEGER PRIMARY KEY, -- database id
** dbcontent BLOB -- database disk file image
** );
** CREATE TABLE xsql(
** sqlid INTEGER PRIMARY KEY, -- SQL script id
** sqltext TEXT -- Text of SQL statements to run
** );
** CREATE TABLE IF NOT EXISTS readme(
** msg TEXT -- Human-readable description of this test collection
** );
**
** For each database file in the DB table, the SQL text in the XSQL table
** is run against that database. All README.MSG values are printed prior
** to the start of the test (unless the --quiet option is used). If the
** DB table is empty, then all entries in XSQL are run against an empty
** in-memory database.
**
** This program is looking for crashes, assertion faults, and/or memory leaks.
** No attempt is made to verify the output. The assumption is that either all
** of the database files or all of the SQL statements are malformed inputs,
** generated by a fuzzer, that need to be checked to make sure they do not
** present a security risk.
**
** This program also includes some command-line options to help with
** creation and maintenance of the source content database. The command
**
** ./fuzzcheck database.db --load-sql FILE...
**
** Loads all FILE... arguments into the XSQL table. The --load-db option
** works the same but loads the files into the DB table. The -m option can
** be used to initialize the README table. The "database.db" file is created
** if it does not previously exist. Example:
**
** ./fuzzcheck new.db --load-sql *.sql
** ./fuzzcheck new.db --load-db *.db
** ./fuzzcheck new.db -m 'New test cases'
**
** The three commands above will create the "new.db" file and initialize all
** tables. Then do "./fuzzcheck new.db" to run the tests.
**
** DEBUGGING HINTS:
**
** If fuzzcheck does crash, it can be run in the debugger and the content
** of the global variable g.zTextName[] will identify the specific XSQL and
** DB values that were running when the crash occurred.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include "sqlite3.h"
#include <assert.h>
#define ISSPACE(X) isspace((unsigned char)(X))
#define ISDIGIT(X) isdigit((unsigned char)(X))
#ifdef __unix__
# include <signal.h>
# include <unistd.h>
#endif
/*
** Files in the virtual file system.
*/
typedef struct VFile VFile;
struct VFile {
char *zFilename; /* Filename. NULL for delete-on-close. From malloc() */
int sz; /* Size of the file in bytes */
int nRef; /* Number of references to this file */
unsigned char *a; /* Content of the file. From malloc() */
};
typedef struct VHandle VHandle;
struct VHandle {
sqlite3_file base; /* Base class. Must be first */
VFile *pVFile; /* The underlying file */
};
/*
** The value of a database file template, or of an SQL script
*/
typedef struct Blob Blob;
struct Blob {
Blob *pNext; /* Next in a list */
int id; /* Id of this Blob */
int seq; /* Sequence number */
int sz; /* Size of this Blob in bytes */
unsigned char a[1]; /* Blob content. Extra space allocated as needed. */
};
/*
** Maximum number of files in the in-memory virtual filesystem.
*/
#define MX_FILE 10
/*
** Maximum allowed file size
*/
#define MX_FILE_SZ 10000000
/*
** All global variables are gathered into the "g" singleton.
*/
static struct GlobalVars {
const char *zArgv0; /* Name of program */
VFile aFile[MX_FILE]; /* The virtual filesystem */
int nDb; /* Number of template databases */
Blob *pFirstDb; /* Content of first template database */
int nSql; /* Number of SQL scripts */
Blob *pFirstSql; /* First SQL script */
char zTestName[100]; /* Name of current test */
} g;
/*
** Print an error message and quit.
*/
static void fatalError(const char *zFormat, ...){
va_list ap;
if( g.zTestName[0] ){
fprintf(stderr, "%s (%s): ", g.zArgv0, g.zTestName);
}else{
fprintf(stderr, "%s: ", g.zArgv0);
}
va_start(ap, zFormat);
vfprintf(stderr, zFormat, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
/*
** Timeout handler
*/
#ifdef __unix__
static void timeoutHandler(int NotUsed){
(void)NotUsed;
fatalError("timeout\n");
}
#endif
/*
** Set the an alarm to go off after N seconds. Disable the alarm
** if N==0
*/
static void setAlarm(int N){
#ifdef __unix__
alarm(N);
#else
(void)N;
#endif
}
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
/*
** This an SQL progress handler. After an SQL statement has run for
** many steps, we want to interrupt it. This guards against infinite
** loops from recursive common table expressions.
**
** *pVdbeLimitFlag is true if the --limit-vdbe command-line option is used.
** In that case, hitting the progress handler is a fatal error.
*/
static int progressHandler(void *pVdbeLimitFlag){
if( *(int*)pVdbeLimitFlag ) fatalError("too many VDBE cycles");
return 1;
}
#endif
/*
** Reallocate memory. Show and error and quit if unable.
*/
static void *safe_realloc(void *pOld, int szNew){
void *pNew = realloc(pOld, szNew<=0 ? 1 : szNew);
if( pNew==0 ) fatalError("unable to realloc for %d bytes", szNew);
return pNew;
}
/*
** Initialize the virtual file system.
*/
static void formatVfs(void){
int i;
for(i=0; i<MX_FILE; i++){
g.aFile[i].sz = -1;
g.aFile[i].zFilename = 0;
g.aFile[i].a = 0;
g.aFile[i].nRef = 0;
}
}
/*
** Erase all information in the virtual file system.
*/
static void reformatVfs(void){
int i;
for(i=0; i<MX_FILE; i++){
if( g.aFile[i].sz<0 ) continue;
if( g.aFile[i].zFilename ){
free(g.aFile[i].zFilename);
g.aFile[i].zFilename = 0;
}
if( g.aFile[i].nRef>0 ){
fatalError("file %d still open. nRef=%d", i, g.aFile[i].nRef);
}
g.aFile[i].sz = -1;
free(g.aFile[i].a);
g.aFile[i].a = 0;
g.aFile[i].nRef = 0;
}
}
/*
** Find a VFile by name
*/
static VFile *findVFile(const char *zName){
int i;
if( zName==0 ) return 0;
for(i=0; i<MX_FILE; i++){
if( g.aFile[i].zFilename==0 ) continue;
if( strcmp(g.aFile[i].zFilename, zName)==0 ) return &g.aFile[i];
}
return 0;
}
/*
** Find a VFile by name. Create it if it does not already exist and
** initialize it to the size and content given.
**
** Return NULL only if the filesystem is full.
*/
static VFile *createVFile(const char *zName, int sz, unsigned char *pData){
VFile *pNew = findVFile(zName);
int i;
if( pNew ) return pNew;
for(i=0; i<MX_FILE && g.aFile[i].sz>=0; i++){}
if( i>=MX_FILE ) return 0;
pNew = &g.aFile[i];
if( zName ){
int nName = (int)strlen(zName)+1;
pNew->zFilename = safe_realloc(0, nName);
memcpy(pNew->zFilename, zName, nName);
}else{
pNew->zFilename = 0;
}
pNew->nRef = 0;
pNew->sz = sz;
pNew->a = safe_realloc(0, sz);
if( sz>0 ) memcpy(pNew->a, pData, sz);
return pNew;
}
/*
** Implementation of the "readfile(X)" SQL function. The entire content
** of the file named X is read and returned as a BLOB. NULL is returned
** if the file does not exist or is unreadable.
*/
static void readfileFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const char *zName;
FILE *in;
long nIn;
void *pBuf;
zName = (const char*)sqlite3_value_text(argv[0]);
if( zName==0 ) return;
in = fopen(zName, "rb");
if( in==0 ) return;
fseek(in, 0, SEEK_END);
nIn = ftell(in);
rewind(in);
pBuf = sqlite3_malloc64( nIn );
if( pBuf && 1==fread(pBuf, nIn, 1, in) ){
sqlite3_result_blob(context, pBuf, nIn, sqlite3_free);
}else{
sqlite3_free(pBuf);
}
fclose(in);
}
/*
** Implementation of the "writefile(X,Y)" SQL function. The argument Y
** is written into file X. The number of bytes written is returned. Or
** NULL is returned if something goes wrong, such as being unable to open
** file X for writing.
*/
static void writefileFunc(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
FILE *out;
const char *z;
sqlite3_int64 rc;
const char *zFile;
(void)argc;
zFile = (const char*)sqlite3_value_text(argv[0]);
if( zFile==0 ) return;
out = fopen(zFile, "wb");
if( out==0 ) return;
z = (const char*)sqlite3_value_blob(argv[1]);
if( z==0 ){
rc = 0;
}else{
rc = fwrite(z, 1, sqlite3_value_bytes(argv[1]), out);
}
fclose(out);
sqlite3_result_int64(context, rc);
}
/*
** Load a list of Blob objects from the database
*/
static void blobListLoadFromDb(
sqlite3 *db, /* Read from this database */
const char *zSql, /* Query used to extract the blobs */
int onlyId, /* Only load where id is this value */
int *pN, /* OUT: Write number of blobs loaded here */
Blob **ppList /* OUT: Write the head of the blob list here */
){
Blob head;
Blob *p;
sqlite3_stmt *pStmt;
int n = 0;
int rc;
char *z2;
if( onlyId>0 ){
z2 = sqlite3_mprintf("%s WHERE rowid=%d", zSql, onlyId);
}else{
z2 = sqlite3_mprintf("%s", zSql);
}
rc = sqlite3_prepare_v2(db, z2, -1, &pStmt, 0);
sqlite3_free(z2);
if( rc ) fatalError("%s", sqlite3_errmsg(db));
head.pNext = 0;
p = &head;
while( SQLITE_ROW==sqlite3_step(pStmt) ){
int sz = sqlite3_column_bytes(pStmt, 1);
Blob *pNew = safe_realloc(0, sizeof(*pNew)+sz );
pNew->id = sqlite3_column_int(pStmt, 0);
pNew->sz = sz;
pNew->seq = n++;
pNew->pNext = 0;
memcpy(pNew->a, sqlite3_column_blob(pStmt,1), sz);
pNew->a[sz] = 0;
p->pNext = pNew;
p = pNew;
}
sqlite3_finalize(pStmt);
*pN = n;
*ppList = head.pNext;
}
/*
** Free a list of Blob objects
*/
static void blobListFree(Blob *p){
Blob *pNext;
while( p ){
pNext = p->pNext;
free(p);
p = pNext;
}
}
/* Return the current wall-clock time */
static sqlite3_int64 timeOfDay(void){
static sqlite3_vfs *clockVfs = 0;
sqlite3_int64 t;
if( clockVfs==0 ) clockVfs = sqlite3_vfs_find(0);
if( clockVfs->iVersion>=1 && clockVfs->xCurrentTimeInt64!=0 ){
clockVfs->xCurrentTimeInt64(clockVfs, &t);
}else{
double r;
clockVfs->xCurrentTime(clockVfs, &r);
t = (sqlite3_int64)(r*86400000.0);
}
return t;
}
/* Methods for the VHandle object
*/
static int inmemClose(sqlite3_file *pFile){
VHandle *p = (VHandle*)pFile;
VFile *pVFile = p->pVFile;
pVFile->nRef--;
if( pVFile->nRef==0 && pVFile->zFilename==0 ){
pVFile->sz = -1;
free(pVFile->a);
pVFile->a = 0;
}
return SQLITE_OK;
}
static int inmemRead(
sqlite3_file *pFile, /* Read from this open file */
void *pData, /* Store content in this buffer */
int iAmt, /* Bytes of content */
sqlite3_int64 iOfst /* Start reading here */
){
VHandle *pHandle = (VHandle*)pFile;
VFile *pVFile = pHandle->pVFile;
if( iOfst<0 || iOfst>=pVFile->sz ){
memset(pData, 0, iAmt);
return SQLITE_IOERR_SHORT_READ;
}
if( iOfst+iAmt>pVFile->sz ){
memset(pData, 0, iAmt);
iAmt = (int)(pVFile->sz - iOfst);
memcpy(pData, pVFile->a, iAmt);
return SQLITE_IOERR_SHORT_READ;
}
memcpy(pData, pVFile->a + iOfst, iAmt);
return SQLITE_OK;
}
static int inmemWrite(
sqlite3_file *pFile, /* Write to this file */
const void *pData, /* Content to write */
int iAmt, /* bytes to write */
sqlite3_int64 iOfst /* Start writing here */
){
VHandle *pHandle = (VHandle*)pFile;
VFile *pVFile = pHandle->pVFile;
if( iOfst+iAmt > pVFile->sz ){
if( iOfst+iAmt >= MX_FILE_SZ ){
return SQLITE_FULL;
}
pVFile->a = safe_realloc(pVFile->a, (int)(iOfst+iAmt));
if( iOfst > pVFile->sz ){
memset(pVFile->a + pVFile->sz, 0, (int)(iOfst - pVFile->sz));
}
pVFile->sz = (int)(iOfst + iAmt);
}
memcpy(pVFile->a + iOfst, pData, iAmt);
return SQLITE_OK;
}
static int inmemTruncate(sqlite3_file *pFile, sqlite3_int64 iSize){
VHandle *pHandle = (VHandle*)pFile;
VFile *pVFile = pHandle->pVFile;
if( pVFile->sz>iSize && iSize>=0 ) pVFile->sz = (int)iSize;
return SQLITE_OK;
}
static int inmemSync(sqlite3_file *pFile, int flags){
return SQLITE_OK;
}
static int inmemFileSize(sqlite3_file *pFile, sqlite3_int64 *pSize){
*pSize = ((VHandle*)pFile)->pVFile->sz;
return SQLITE_OK;
}
static int inmemLock(sqlite3_file *pFile, int type){
return SQLITE_OK;
}
static int inmemUnlock(sqlite3_file *pFile, int type){
return SQLITE_OK;
}
static int inmemCheckReservedLock(sqlite3_file *pFile, int *pOut){
*pOut = 0;
return SQLITE_OK;
}
static int inmemFileControl(sqlite3_file *pFile, int op, void *pArg){
return SQLITE_NOTFOUND;
}
static int inmemSectorSize(sqlite3_file *pFile){
return 512;
}
static int inmemDeviceCharacteristics(sqlite3_file *pFile){
return
SQLITE_IOCAP_SAFE_APPEND |
SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
SQLITE_IOCAP_POWERSAFE_OVERWRITE;
}
/* Method table for VHandle
*/
static sqlite3_io_methods VHandleMethods = {
/* iVersion */ 1,
/* xClose */ inmemClose,
/* xRead */ inmemRead,
/* xWrite */ inmemWrite,
/* xTruncate */ inmemTruncate,
/* xSync */ inmemSync,
/* xFileSize */ inmemFileSize,
/* xLock */ inmemLock,
/* xUnlock */ inmemUnlock,
/* xCheck... */ inmemCheckReservedLock,
/* xFileCtrl */ inmemFileControl,
/* xSectorSz */ inmemSectorSize,
/* xDevchar */ inmemDeviceCharacteristics,
/* xShmMap */ 0,
/* xShmLock */ 0,
/* xShmBarrier */ 0,
/* xShmUnmap */ 0,
/* xFetch */ 0,
/* xUnfetch */ 0
};
/*
** Open a new file in the inmem VFS. All files are anonymous and are
** delete-on-close.
*/
static int inmemOpen(
sqlite3_vfs *pVfs,
const char *zFilename,
sqlite3_file *pFile,
int openFlags,
int *pOutFlags
){
VFile *pVFile = createVFile(zFilename, 0, (unsigned char*)"");
VHandle *pHandle = (VHandle*)pFile;
if( pVFile==0 ){
return SQLITE_FULL;
}
pHandle->pVFile = pVFile;
pVFile->nRef++;
pFile->pMethods = &VHandleMethods;
if( pOutFlags ) *pOutFlags = openFlags;
return SQLITE_OK;
}
/*
** Delete a file by name
*/
static int inmemDelete(
sqlite3_vfs *pVfs,
const char *zFilename,
int syncdir
){
VFile *pVFile = findVFile(zFilename);
if( pVFile==0 ) return SQLITE_OK;
if( pVFile->nRef==0 ){
free(pVFile->zFilename);
pVFile->zFilename = 0;
pVFile->sz = -1;
free(pVFile->a);
pVFile->a = 0;
return SQLITE_OK;
}
return SQLITE_IOERR_DELETE;
}
/* Check for the existance of a file
*/
static int inmemAccess(
sqlite3_vfs *pVfs,
const char *zFilename,
int flags,
int *pResOut
){
VFile *pVFile = findVFile(zFilename);
*pResOut = pVFile!=0;
return SQLITE_OK;
}
/* Get the canonical pathname for a file
*/
static int inmemFullPathname(
sqlite3_vfs *pVfs,
const char *zFilename,
int nOut,
char *zOut
){
sqlite3_snprintf(nOut, zOut, "%s", zFilename);
return SQLITE_OK;
}
/*
** Register the VFS that reads from the g.aFile[] set of files.
*/
static void inmemVfsRegister(void){
static sqlite3_vfs inmemVfs;
sqlite3_vfs *pDefault = sqlite3_vfs_find(0);
inmemVfs.iVersion = 3;
inmemVfs.szOsFile = sizeof(VHandle);
inmemVfs.mxPathname = 200;
inmemVfs.zName = "inmem";
inmemVfs.xOpen = inmemOpen;
inmemVfs.xDelete = inmemDelete;
inmemVfs.xAccess = inmemAccess;
inmemVfs.xFullPathname = inmemFullPathname;
inmemVfs.xRandomness = pDefault->xRandomness;
inmemVfs.xSleep = pDefault->xSleep;
inmemVfs.xCurrentTimeInt64 = pDefault->xCurrentTimeInt64;
sqlite3_vfs_register(&inmemVfs, 0);
};
/*
** Allowed values for the runFlags parameter to runSql()
*/
#define SQL_TRACE 0x0001 /* Print each SQL statement as it is prepared */
#define SQL_OUTPUT 0x0002 /* Show the SQL output */
/*
** Run multiple commands of SQL. Similar to sqlite3_exec(), but does not
** stop if an error is encountered.
*/
static void runSql(sqlite3 *db, const char *zSql, unsigned runFlags){
const char *zMore;
const char *zEnd = &zSql[strlen(zSql)];
sqlite3_stmt *pStmt;
while( zSql && zSql[0] ){
zMore = 0;
pStmt = 0;
sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zMore);
assert( zMore<=zEnd );
if( zMore==zSql ) break;
if( runFlags & SQL_TRACE ){
const char *z = zSql;
int n;
while( z<zMore && ISSPACE(z[0]) ) z++;
n = (int)(zMore - z);
while( n>0 && ISSPACE(z[n-1]) ) n--;
if( n==0 ) break;
if( pStmt==0 ){
printf("TRACE: %.*s (error: %s)\n", n, z, sqlite3_errmsg(db));
}else{
printf("TRACE: %.*s\n", n, z);
}
}
zSql = zMore;
if( pStmt ){
if( (runFlags & SQL_OUTPUT)==0 ){
while( SQLITE_ROW==sqlite3_step(pStmt) ){}
}else{
int nCol = -1;
while( SQLITE_ROW==sqlite3_step(pStmt) ){
int i;
if( nCol<0 ){
nCol = sqlite3_column_count(pStmt);
}else if( nCol>0 ){
printf("--------------------------------------------\n");
}
for(i=0; i<nCol; i++){
int eType = sqlite3_column_type(pStmt,i);
printf("%s = ", sqlite3_column_name(pStmt,i));
switch( eType ){
case SQLITE_NULL: {
printf("NULL\n");
break;
}
case SQLITE_INTEGER: {
printf("INT %s\n", sqlite3_column_text(pStmt,i));
break;
}
case SQLITE_FLOAT: {
printf("FLOAT %s\n", sqlite3_column_text(pStmt,i));
break;
}
case SQLITE_TEXT: {
printf("TEXT [%s]\n", sqlite3_column_text(pStmt,i));
break;
}
case SQLITE_BLOB: {
printf("BLOB (%d bytes)\n", sqlite3_column_bytes(pStmt,i));
break;
}
}
}
}
}
sqlite3_finalize(pStmt);
}
}
}
/*
** Rebuild the database file.
**
** (1) Remove duplicate entries
** (2) Put all entries in order
** (3) Vacuum
*/
static void rebuild_database(sqlite3 *db){
int rc;
rc = sqlite3_exec(db,
"BEGIN;\n"
"CREATE TEMP TABLE dbx AS SELECT DISTINCT dbcontent FROM db;\n"
"DELETE FROM db;\n"
"INSERT INTO db(dbid, dbcontent) SELECT NULL, dbcontent FROM dbx ORDER BY 2;\n"
"DROP TABLE dbx;\n"
"CREATE TEMP TABLE sx AS SELECT DISTINCT sqltext FROM xsql;\n"
"DELETE FROM xsql;\n"
"INSERT INTO xsql(sqlid,sqltext) SELECT NULL, sqltext FROM sx ORDER BY 2;\n"
"DROP TABLE sx;\n"
"COMMIT;\n"
"PRAGMA page_size=1024;\n"
"VACUUM;\n", 0, 0, 0);
if( rc ) fatalError("cannot rebuild: %s", sqlite3_errmsg(db));
}
/*
** Return the value of a hexadecimal digit. Return -1 if the input
** is not a hex digit.
*/
static int hexDigitValue(char c){
if( c>='0' && c<='9' ) return c - '0';
if( c>='a' && c<='f' ) return c - 'a' + 10;
if( c>='A' && c<='F' ) return c - 'A' + 10;
return -1;
}
/*
** Interpret zArg as an integer value, possibly with suffixes.
*/
static int integerValue(const char *zArg){
sqlite3_int64 v = 0;
static const struct { char *zSuffix; int iMult; } aMult[] = {
{ "KiB", 1024 },
{ "MiB", 1024*1024 },
{ "GiB", 1024*1024*1024 },
{ "KB", 1000 },
{ "MB", 1000000 },
{ "GB", 1000000000 },
{ "K", 1000 },
{ "M", 1000000 },
{ "G", 1000000000 },
};
int i;
int isNeg = 0;
if( zArg[0]=='-' ){
isNeg = 1;
zArg++;
}else if( zArg[0]=='+' ){
zArg++;
}
if( zArg[0]=='0' && zArg[1]=='x' ){
int x;
zArg += 2;
while( (x = hexDigitValue(zArg[0]))>=0 ){
v = (v<<4) + x;
zArg++;
}
}else{
while( ISDIGIT(zArg[0]) ){
v = v*10 + zArg[0] - '0';
zArg++;
}
}
for(i=0; i<sizeof(aMult)/sizeof(aMult[0]); i++){
if( sqlite3_stricmp(aMult[i].zSuffix, zArg)==0 ){
v *= aMult[i].iMult;
break;
}
}
if( v>0x7fffffff ) fatalError("parameter too large - max 2147483648");
return (int)(isNeg? -v : v);
}
/*
** Print sketchy documentation for this utility program
*/
static void showHelp(void){
printf("Usage: %s [options] SOURCE-DB ?ARGS...?\n", g.zArgv0);
printf(
"Read databases and SQL scripts from SOURCE-DB and execute each script against\n"
"each database, checking for crashes and memory leaks.\n"
"Options:\n"
" --cell-size-check Set the PRAGMA cell_size_check=ON\n"
" --dbid N Use only the database where dbid=N\n"
" --export-db DIR Write databases to files(s) in DIR. Works with --dbid\n"
" --export-sql DIR Write SQL to file(s) in DIR. Also works with --sqlid\n"
" --help Show this help text\n"
" -q|--quiet Reduced output\n"
" --limit-mem N Limit memory used by test SQLite instance to N bytes\n"
" --limit-vdbe Panic if an sync SQL runs for more than 100,000 cycles\n"
" --load-sql ARGS... Load SQL scripts fro files into SOURCE-DB\n"
" --load-db ARGS... Load template databases from files into SOURCE_DB\n"
" -m TEXT Add a description to the database\n"
" --native-vfs Use the native VFS for initially empty database files\n"
" --rebuild Rebuild and vacuum the database file\n"
" --result-trace Show the results of each SQL command\n"
" --sqlid N Use only SQL where sqlid=N\n"
" --timeout N Abort if any single test case needs more than N seconds\n"
" -v|--verbose Increased output. Repeat for more output.\n"
);
}
int main(int argc, char **argv){
sqlite3_int64 iBegin; /* Start time of this program */
int quietFlag = 0; /* True if --quiet or -q */
int verboseFlag = 0; /* True if --verbose or -v */
char *zInsSql = 0; /* SQL statement for --load-db or --load-sql */
int iFirstInsArg = 0; /* First argv[] to use for --load-db or --load-sql */
sqlite3 *db = 0; /* The open database connection */
sqlite3_stmt *pStmt; /* A prepared statement */
int rc; /* Result code from SQLite interface calls */
Blob *pSql; /* For looping over SQL scripts */
Blob *pDb; /* For looping over template databases */
int i; /* Loop index for the argv[] loop */
int onlySqlid = -1; /* --sqlid */
int onlyDbid = -1; /* --dbid */
int nativeFlag = 0; /* --native-vfs */
int rebuildFlag = 0; /* --rebuild */
int vdbeLimitFlag = 0; /* --limit-vdbe */
int timeoutTest = 0; /* undocumented --timeout-test flag */
int runFlags = 0; /* Flags sent to runSql() */
char *zMsg = 0; /* Add this message */
int nSrcDb = 0; /* Number of source databases */
char **azSrcDb = 0; /* Array of source database names */
int iSrcDb; /* Loop over all source databases */
int nTest = 0; /* Total number of tests performed */
char *zDbName = ""; /* Appreviated name of a source database */
const char *zFailCode = 0; /* Value of the TEST_FAILURE environment variable */
int cellSzCkFlag = 0; /* --cell-size-check */
int sqlFuzz = 0; /* True for SQL fuzz testing. False for DB fuzz */
int iTimeout = 120; /* Default 120-second timeout */
int nMem = 0; /* Memory limit */
char *zExpDb = 0; /* Write Databases to files in this directory */
char *zExpSql = 0; /* Write SQL to files in this directory */
void *pHeap = 0; /* Heap for use by SQLite */
iBegin = timeOfDay();
#ifdef __unix__
signal(SIGALRM, timeoutHandler);
#endif
g.zArgv0 = argv[0];
zFailCode = getenv("TEST_FAILURE");
for(i=1; i<argc; i++){
const char *z = argv[i];
if( z[0]=='-' ){
z++;
if( z[0]=='-' ) z++;
if( strcmp(z,"cell-size-check")==0 ){
cellSzCkFlag = 1;
}else
if( strcmp(z,"dbid")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
onlyDbid = integerValue(argv[++i]);
}else
if( strcmp(z,"export-db")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
zExpDb = argv[++i];
}else
if( strcmp(z,"export-sql")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
zExpSql = argv[++i];
}else
if( strcmp(z,"help")==0 ){
showHelp();
return 0;
}else
if( strcmp(z,"limit-mem")==0 ){
#if !defined(SQLITE_ENABLE_MEMSYS3) && !defined(SQLITE_ENABLE_MEMSYS5)
fatalError("the %s option requires -DSQLITE_ENABLE_MEMSYS5 or _MEMSYS3",
argv[i]);
#else
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
nMem = integerValue(argv[++i]);
#endif
}else
if( strcmp(z,"limit-vdbe")==0 ){
vdbeLimitFlag = 1;
}else
if( strcmp(z,"load-sql")==0 ){
zInsSql = "INSERT INTO xsql(sqltext) VALUES(CAST(readfile(?1) AS text))";
iFirstInsArg = i+1;
break;
}else
if( strcmp(z,"load-db")==0 ){
zInsSql = "INSERT INTO db(dbcontent) VALUES(readfile(?1))";
iFirstInsArg = i+1;
break;
}else
if( strcmp(z,"m")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
zMsg = argv[++i];
}else
if( strcmp(z,"native-vfs")==0 ){
nativeFlag = 1;
}else
if( strcmp(z,"quiet")==0 || strcmp(z,"q")==0 ){
quietFlag = 1;
verboseFlag = 0;
}else
if( strcmp(z,"rebuild")==0 ){
rebuildFlag = 1;
}else
if( strcmp(z,"result-trace")==0 ){
runFlags |= SQL_OUTPUT;
}else
if( strcmp(z,"sqlid")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
onlySqlid = integerValue(argv[++i]);
}else
if( strcmp(z,"timeout")==0 ){
if( i>=argc-1 ) fatalError("missing arguments on %s", argv[i]);
iTimeout = integerValue(argv[++i]);
}else
if( strcmp(z,"timeout-test")==0 ){
timeoutTest = 1;
#ifndef __unix__
fatalError("timeout is not available on non-unix systems");
#endif
}else
if( strcmp(z,"verbose")==0 || strcmp(z,"v")==0 ){
quietFlag = 0;
verboseFlag++;
if( verboseFlag>1 ) runFlags |= SQL_TRACE;
}else
{
fatalError("unknown option: %s", argv[i]);
}
}else{
nSrcDb++;
azSrcDb = safe_realloc(azSrcDb, nSrcDb*sizeof(azSrcDb[0]));
azSrcDb[nSrcDb-1] = argv[i];
}
}
if( nSrcDb==0 ) fatalError("no source database specified");
if( nSrcDb>1 ){
if( zMsg ){
fatalError("cannot change the description of more than one database");
}
if( zInsSql ){
fatalError("cannot import into more than one database");
}
}
/* Process each source database separately */
for(iSrcDb=0; iSrcDb<nSrcDb; iSrcDb++){
rc = sqlite3_open(azSrcDb[iSrcDb], &db);
if( rc ){
fatalError("cannot open source database %s - %s",
azSrcDb[iSrcDb], sqlite3_errmsg(db));
}
rc = sqlite3_exec(db,
"CREATE TABLE IF NOT EXISTS db(\n"
" dbid INTEGER PRIMARY KEY, -- database id\n"
" dbcontent BLOB -- database disk file image\n"
");\n"
"CREATE TABLE IF NOT EXISTS xsql(\n"
" sqlid INTEGER PRIMARY KEY, -- SQL script id\n"
" sqltext TEXT -- Text of SQL statements to run\n"
");"
"CREATE TABLE IF NOT EXISTS readme(\n"
" msg TEXT -- Human-readable description of this file\n"
");", 0, 0, 0);
if( rc ) fatalError("cannot create schema: %s", sqlite3_errmsg(db));
if( zMsg ){
char *zSql;
zSql = sqlite3_mprintf(
"DELETE FROM readme; INSERT INTO readme(msg) VALUES(%Q)", zMsg);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);
if( rc ) fatalError("cannot change description: %s", sqlite3_errmsg(db));
}
if( zInsSql ){
sqlite3_create_function(db, "readfile", 1, SQLITE_UTF8, 0,
readfileFunc, 0, 0);
rc = sqlite3_prepare_v2(db, zInsSql, -1, &pStmt, 0);
if( rc ) fatalError("cannot prepare statement [%s]: %s",
zInsSql, sqlite3_errmsg(db));
rc = sqlite3_exec(db, "BEGIN", 0, 0, 0);
if( rc ) fatalError("cannot start a transaction");
for(i=iFirstInsArg; i<argc; i++){
sqlite3_bind_text(pStmt, 1, argv[i], -1, SQLITE_STATIC);
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
if( rc ) fatalError("insert failed for %s", argv[i]);
}
sqlite3_finalize(pStmt);
rc = sqlite3_exec(db, "COMMIT", 0, 0, 0);
if( rc ) fatalError("cannot commit the transaction: %s", sqlite3_errmsg(db));
rebuild_database(db);
sqlite3_close(db);
return 0;
}
if( zExpDb!=0 || zExpSql!=0 ){
sqlite3_create_function(db, "writefile", 2, SQLITE_UTF8, 0,
writefileFunc, 0, 0);
if( zExpDb!=0 ){
const char *zExDb =
"SELECT writefile(printf('%s/db%06d.db',?1,dbid),dbcontent),"
" dbid, printf('%s/db%06d.db',?1,dbid), length(dbcontent)"
" FROM db WHERE ?2<0 OR dbid=?2;";
rc = sqlite3_prepare_v2(db, zExDb, -1, &pStmt, 0);
if( rc ) fatalError("cannot prepare statement [%s]: %s",
zExDb, sqlite3_errmsg(db));
sqlite3_bind_text64(pStmt, 1, zExpDb, strlen(zExpDb),
SQLITE_STATIC, SQLITE_UTF8);
sqlite3_bind_int(pStmt, 2, onlyDbid);
while( sqlite3_step(pStmt)==SQLITE_ROW ){
printf("write db-%d (%d bytes) into %s\n",
sqlite3_column_int(pStmt,1),
sqlite3_column_int(pStmt,3),
sqlite3_column_text(pStmt,2));
}
sqlite3_finalize(pStmt);
}
if( zExpSql!=0 ){
const char *zExSql =
"SELECT writefile(printf('%s/sql%06d.txt',?1,sqlid),sqltext),"
" sqlid, printf('%s/sql%06d.txt',?1,sqlid), length(sqltext)"
" FROM xsql WHERE ?2<0 OR sqlid=?2;";
rc = sqlite3_prepare_v2(db, zExSql, -1, &pStmt, 0);
if( rc ) fatalError("cannot prepare statement [%s]: %s",
zExSql, sqlite3_errmsg(db));
sqlite3_bind_text64(pStmt, 1, zExpSql, strlen(zExpSql),
SQLITE_STATIC, SQLITE_UTF8);
sqlite3_bind_int(pStmt, 2, onlySqlid);
while( sqlite3_step(pStmt)==SQLITE_ROW ){
printf("write sql-%d (%d bytes) into %s\n",
sqlite3_column_int(pStmt,1),
sqlite3_column_int(pStmt,3),
sqlite3_column_text(pStmt,2));
}
sqlite3_finalize(pStmt);
}
sqlite3_close(db);
return 0;
}
/* Load all SQL script content and all initial database images from the
** source db
*/
blobListLoadFromDb(db, "SELECT sqlid, sqltext FROM xsql", onlySqlid,
&g.nSql, &g.pFirstSql);
if( g.nSql==0 ) fatalError("need at least one SQL script");
blobListLoadFromDb(db, "SELECT dbid, dbcontent FROM db", onlyDbid,
&g.nDb, &g.pFirstDb);
if( g.nDb==0 ){
g.pFirstDb = safe_realloc(0, sizeof(Blob));
memset(g.pFirstDb, 0, sizeof(Blob));
g.pFirstDb->id = 1;
g.pFirstDb->seq = 0;
g.nDb = 1;
sqlFuzz = 1;
}
/* Print the description, if there is one */
if( !quietFlag ){
zDbName = azSrcDb[iSrcDb];
i = (int)strlen(zDbName) - 1;
while( i>0 && zDbName[i-1]!='/' && zDbName[i-1]!='\\' ){ i--; }
zDbName += i;
sqlite3_prepare_v2(db, "SELECT msg FROM readme", -1, &pStmt, 0);
if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
printf("%s: %s\n", zDbName, sqlite3_column_text(pStmt,0));
}
sqlite3_finalize(pStmt);
}
/* Rebuild the database, if requested */
if( rebuildFlag ){
if( !quietFlag ){
printf("%s: rebuilding... ", zDbName);
fflush(stdout);
}
rebuild_database(db);
if( !quietFlag ) printf("done\n");
}
/* Close the source database. Verify that no SQLite memory allocations are
** outstanding.
*/
sqlite3_close(db);
if( sqlite3_memory_used()>0 ){
fatalError("SQLite has memory in use before the start of testing");
}
/* Limit available memory, if requested */
if( nMem>0 ){
sqlite3_shutdown();
pHeap = malloc(nMem);
if( pHeap==0 ){
fatalError("failed to allocate %d bytes of heap memory", nMem);
}
sqlite3_config(SQLITE_CONFIG_HEAP, pHeap, nMem, 128);
}
/* Register the in-memory virtual filesystem
*/
formatVfs();
inmemVfsRegister();
/* Run a test using each SQL script against each database.
*/
if( !verboseFlag && !quietFlag ) printf("%s:", zDbName);
for(pSql=g.pFirstSql; pSql; pSql=pSql->pNext){
for(pDb=g.pFirstDb; pDb; pDb=pDb->pNext){
int openFlags;
const char *zVfs = "inmem";
sqlite3_snprintf(sizeof(g.zTestName), g.zTestName, "sqlid=%d,dbid=%d",
pSql->id, pDb->id);
if( verboseFlag ){
printf("%s\n", g.zTestName);
fflush(stdout);
}else if( !quietFlag ){
static int prevAmt = -1;
int idx = pSql->seq*g.nDb + pDb->id - 1;
int amt = idx*10/(g.nDb*g.nSql);
if( amt!=prevAmt ){
printf(" %d%%", amt*10);
fflush(stdout);
prevAmt = amt;
}
}
createVFile("main.db", pDb->sz, pDb->a);
openFlags = SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE;
if( nativeFlag && pDb->sz==0 ){
openFlags |= SQLITE_OPEN_MEMORY;
zVfs = 0;
}
rc = sqlite3_open_v2("main.db", &db, openFlags, zVfs);
if( rc ) fatalError("cannot open inmem database");
if( cellSzCkFlag ) runSql(db, "PRAGMA cell_size_check=ON", runFlags);
setAlarm(iTimeout);
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
if( sqlFuzz || vdbeLimitFlag ){
sqlite3_progress_handler(db, 100000, progressHandler, &vdbeLimitFlag);
}
#endif
do{
runSql(db, (char*)pSql->a, runFlags);
}while( timeoutTest );
setAlarm(0);
sqlite3_close(db);
if( sqlite3_memory_used()>0 ) fatalError("memory leak");
reformatVfs();
nTest++;
g.zTestName[0] = 0;
/* Simulate an error if the TEST_FAILURE environment variable is "5".
** This is used to verify that automated test script really do spot
** errors that occur in this test program.
*/
if( zFailCode ){
if( zFailCode[0]=='5' && zFailCode[1]==0 ){
fatalError("simulated failure");
}else if( zFailCode[0]!=0 ){
/* If TEST_FAILURE is something other than 5, just exit the test
** early */
printf("\nExit early due to TEST_FAILURE being set\n");
iSrcDb = nSrcDb-1;
goto sourcedb_cleanup;
}
}
}
}
if( !quietFlag && !verboseFlag ){
printf(" 100%% - %d tests\n", g.nDb*g.nSql);
}
/* Clean up at the end of processing a single source database
*/
sourcedb_cleanup:
blobListFree(g.pFirstSql);
blobListFree(g.pFirstDb);
reformatVfs();
} /* End loop over all source databases */
if( !quietFlag ){
sqlite3_int64 iElapse = timeOfDay() - iBegin;
printf("fuzzcheck: 0 errors out of %d tests in %d.%03d seconds\n"
"SQLite %s %s\n",
nTest, (int)(iElapse/1000), (int)(iElapse%1000),
sqlite3_libversion(), sqlite3_sourceid());
}
free(azSrcDb);
free(pHeap);
return 0;
}
|
the_stack_data/220454431.c | void test(int bi_private, int bmd){
bi_private = bmd ;} |
the_stack_data/94210.c | #include <stdio.h>
//typedef unsigned long long ull;
int C(int n,int m)
{
int P = 1, Q = 1;
int i;
for (i = 1;i<=m;i++)
{
P *= (n - i + 1);
Q *= i;
}
return P / Q;
}
int main()
{
int m,n;
scanf("%d%d",&m,&n);
printf("%d\n",C(m,n));
return 0;
} |
the_stack_data/7949074.c | #include <assert.h>
#include <stdbool.h>
#include <stdio.h>
typedef struct nodo {
int dato;
struct nodo *prox;
} nodo_t;
typedef struct {
nodo_t *prim;
} lista_t;
// HACER: escribir la implementacion, en forma RECURSIVA. (Puede ser necesario
// agregar una funcion privada).
bool esta_ordenada(lista_t *lista) {
if (lista == NULL || lista->prim == NULL)
return false;
nodo_t *nodo_act = lista->prim;
nodo_t *nodo_sig = nodo_act->prox;
if (nodo_sig == NULL)
return true;
if (nodo_act->dato < nodo_sig->dato){
lista_t lista_nueva = {.prim = nodo_sig};
return esta_ordenada(&lista_nueva);
}
return false;
}
int main(void) {
// [3] -> [5] -> [8] -> [11]
nodo_t n3 = {.dato = 11, .prox = NULL};
nodo_t n2 = {.dato = 8, .prox = &n3};
nodo_t n1 = {.dato = 5, .prox = &n2};
nodo_t n0 = {.dato = 3, .prox = &n1};
lista_t lista = {.prim = &n0};
assert(esta_ordenada(&lista));
// OPCIONAL: Pruebas adicionales. Sugerencias:
// - Repetir la prueba con una lista desordenada, y verificar que la
// funcion devuelve false
// - Repetir la prueba con una lista vacia (es indistinto lo que devuelve
// la funcion, pero no deberia fallar)
printf("%s: OK\n", __FILE__);
return 0;
}
//9 min |
the_stack_data/38489.c | #include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#define READ_BUFFER (2048)
#define FILE_PATH ("test.txt")
int testRead(char* file_path);
int testFread(char* file_path);
int testFreadWithBuffer(char* file_path);
int main()
{
testRead(FILE_PATH);
testFread(FILE_PATH);
testFreadWithBuffer(FILE_PATH);
return 0;
}
int testRead(char* file_path)
{
clock_t begin = clock();
int fd = open(file_path, O_RDONLY);
if(fd < 0)
{
printf("can't read test file %s\n", FILE_PATH);
return errno;
}
char buffer[READ_BUFFER];
int length = sizeof(buffer);
int read_count;
while((read_count = read(fd, buffer, length)) != 0)
{
//printBuffer(buffer, read_count);
}
close(fd);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%s\t%lf\n", __func__, time_spent);
}
int testFread(char* file_path)
{
clock_t begin = clock();
FILE* file = fopen(file_path, "r");
if(file == NULL)
{
printf("can't read test file %s\n", FILE_PATH);
return errno;
}
char buffer[READ_BUFFER];
int length = sizeof(buffer);
int read_count;
while((read_count = fread(buffer, 1, length, file)) != 0)
{
// printBuffer(buffer, read_count);
}
fclose(file);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%s\t%lf\n", __func__, time_spent);
}
int testFreadWithBuffer(char* file_path)
{
clock_t begin = clock();
FILE* file = fopen(file_path, "r");
if(file == NULL)
{
printf("can't read test file %s\n", FILE_PATH);
return errno;
}
char buffer[READ_BUFFER];
int length = sizeof(buffer);
setvbuf(file, NULL, _IOFBF, READ_BUFFER*4 ); // large buffer
int read_count;
while((read_count = fread(buffer, 1, length, file)) != 0)
{
// printBuffer(buffer, read_count);
}
fclose(file);
clock_t end = clock();
double time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("%s\t%lf\n", __func__, time_spent);
}
void printBuffer(char* buffer, int count)
{
int length = sizeof(buffer);
if(count == length)
{
printf("%s", buffer);
}
else
{
for(int i=0; i< count; i++)
printf("%c", buffer[i]);
}
}
|
the_stack_data/130138.c | #include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void monitorselect(int fd[], int numfds);
void docommand(char *buf, int num) {
fprintf(stderr,"Got command !%.*s!\n",num,buf);
}
int main(int argc, char *argv[]){
int *fds;
int i;
if (argc <= 1) {
fprintf(stderr,"Usage: %s pipe1 pipe2 ...\n",argv[0]);
return 1;
}
fds = (int *)malloc((argc-1)*sizeof(int));
if (fds == NULL) {
fprintf(stderr,"Malloc error\n");
return 1;
}
for (i=0;i<argc-1;i++) {
fds[i] = open(argv[i+1],O_RDONLY);
if (fds[i] == -1) {
fprintf(stderr,"Error opening %s for read\n",argv[i+1]);
return 1;
}
}
monitorselect(fds,argc-1);
return 0;
}
|
the_stack_data/23574083.c | #include <stdio.h>
int
test()
{
int arr[2];
int *p;
p = &arr[1];
p -= 1;
*p = 123;
if(arr[0] != 123)
return 1;
return 0;
}
int main () {
int x;
x = test();
printf("%d\n", x);
return 0;
} |
the_stack_data/711100.c | #include <stdio.h>
/**
* Write a program to copy its input to its output replacing each tab by \t,
* each backspace by \b, and each backslash by \\. This makes tabs and
* backspaces visible in an unambiguous way.
*/
main()
{
int c;
while ((c = getchar()) != EOF) {
if (c == '\t')
printf("\\t");
else if (c == '\b')
printf("\\b");
else if (c == '\\')
printf("\\\\");
else
putchar(c);
}
} |
the_stack_data/40762441.c | #include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
const char *program_name; //
void print_usage(FILE *stream, int exit_code) { //
fprintf(stream, "Usage: %s options [ inputfile ... ]\n", program_name);
fprintf(stream, " -h --help .\n"
" -o --output filename.\n"
" -v --version.\n");
exit(exit_code);
}
int main(int argc, char *argv[]) {
int next_option;
const char *const short_options = "ho:v"; //
const struct option long_options[] = { //
{ "help", 0, NULL, 'h' }, //no arg
{ "output", 1, NULL, 'o' }, //must have a arg
{ "version", 0, NULL, 'v' },
{ NULL, 0, NULL, 0}
};
const char *output_filename = NULL;
program_name = argv[0];
do {
next_option = getopt_long(argc, argv, short_options, long_options, NULL);
switch (next_option) {
case 'h':
print_usage(stdout, 0);
break;
case 'o': //-o
output_filename = optarg;
execl("/bin/cat", "cat", output_filename, NULL);
break;
case 'v': //-v
printf("the version is v1.0\n");
break;
case ':': //
break;
case '?': //
print_usage(stderr, 1);
break;
default: //
print_usage(stderr, 1);
break;
}
} while (next_option != -1);
return 0;
}
|
the_stack_data/154826959.c | /*
* Serial C implementation of vector add
*/
void add_vects(const int* a, const int* b, int* c, int size)
{
int i;
for(i = 0; i < size; i++)
c[i] = a[i] + b[i];
}
|
the_stack_data/1046114.c | /**************************************************************************************************************************
* 7.4.1 Feladat *
* Írjon függvényt, amely két memóriacímet kap paraméterül és megcseréli az értékeiket, amennyiben az első számé nagyobb *
* Olvasson be egy tízelemű tömböt *
* Rendezze a tömböt növekvő sorrendbe az előzőleg megírt függvény segítségével *
* Jelenítse meg a tömböt *
**************************************************************************************************************************/
#include <stdio.h>
#define N 10
void csereHaNagyobb(int *a, int *b)
{
if ((*a)>(*b))
{
int csere=*a;
*a=*b;
*b=csere;
}
}
int main()
{
int tomb[N];
int i, j;
printf("Kerem a tomb elemeit:\n");
for (i=0; i<N; i++)
{
scanf("%d", &tomb[i]);
}
for (i=0; i<N-1; i++)
{
for (j=i+1; j<N; j++)
{
csereHaNagyobb(&tomb[i], &tomb[j]); // egy kicsit masfajta rendezes, de a lenyeg itt is az, hogy az elso ciklus utan a legkisebb szam lesz az elso, stb
}
}
printf("A tomb rendezes utan:\n");
for (i=0; i<N; i++)
{
printf("%d ", tomb[i]);
}
printf("\n");
return 0;
}
|
the_stack_data/39701.c | /* Created by David Emelu on 2022-01-16.
* Names.c
*
* Prints a list of names with their hometowns
* and intended major
*/
#include <stdio.h>
int main()
{
printf("\n");
printf("\tName\t\t\tHometown\n");
printf("\t====\t\t\t========\n");
printf("\tAlbert Einstein\t\tUlm\n");
printf("\tDavid Emelu \t Edmonton\n");
printf("\n");
return 0;
}
|
the_stack_data/220456962.c | /*******************************************************************************
* FILE: pgm_io.c
* This code was written by Mike Heath. [email protected] (in 1995).
*******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/******************************************************************************
* Function: read_pgm_image
* Purpose: This function reads in an image in PGM format. The image can be
* read in from either a file or from standard input. The image is only read
* from standard input when infilename = NULL. Because the PGM format includes
* the number of columns and the number of rows in the image, these are read
* from the file. Memory to store the image is allocated in this function.
* All comments in the header are discarded in the process of reading the
* image. Upon failure, this function returns 0, upon sucess it returns 1.
******************************************************************************/
int read_pgm_image(char *infilename, unsigned char **image, int *rows,
int *cols)
{
FILE *fp;
char buf[71];
/***************************************************************************
* Open the input image file for reading if a filename was given. If no
* filename was provided, set fp to read from standard input.
***************************************************************************/
if(infilename == NULL) fp = stdin;
else{
if((fp = fopen(infilename, "r")) == NULL){
fprintf(stderr, "Error reading the file %s in read_pgm_image().\n",
infilename);
return(0);
}
}
/***************************************************************************
* Verify that the image is in PGM format, read in the number of columns
* and rows in the image and scan past all of the header information.
***************************************************************************/
fgets(buf, 70, fp);
if(strncmp(buf,"P5",2) != 0){
fprintf(stderr, "The file %s is not in PGM format in ", infilename);
fprintf(stderr, "read_pgm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
do{ fgets(buf, 70, fp); }while(buf[0] == '#'); /* skip all comment lines */
sscanf(buf, "%d %d", cols, rows);
do{ fgets(buf, 70, fp); }while(buf[0] == '#'); /* skip all comment lines */
/***************************************************************************
* Allocate memory to store the image then read the image from the file.
***************************************************************************/
if(((*image) = (unsigned char *) malloc((*rows)*(*cols))) == NULL){
fprintf(stderr, "Memory allocation failure in read_pgm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
if((*rows) != fread((*image), (*cols), (*rows), fp)){
fprintf(stderr, "Error reading the image data in read_pgm_image().\n");
if(fp != stdin) fclose(fp);
free((*image));
return(0);
}
if(fp != stdin) fclose(fp);
return(1);
}
/******************************************************************************
* Function: write_pgm_image
* Purpose: This function writes an image in PGM format. The file is either
* written to the file specified by outfilename or to standard output if
* outfilename = NULL. A comment can be written to the header if coment != NULL.
******************************************************************************/
int write_pgm_image(char *outfilename, unsigned char *image, int rows,
int cols, char *comment, int maxval)
{
FILE *fp;
/***************************************************************************
* Open the output image file for writing if a filename was given. If no
* filename was provided, set fp to write to standard output.
***************************************************************************/
if(outfilename == NULL) fp = stdout;
else{
if((fp = fopen(outfilename, "w")) == NULL){
fprintf(stderr, "Error writing the file %s in write_pgm_image().\n",
outfilename);
return(0);
}
}
/***************************************************************************
* Write the header information to the PGM file.
***************************************************************************/
fprintf(fp, "P5\n%d %d\n", cols, rows);
if(comment != NULL)
if(strlen(comment) <= 70) fprintf(fp, "# %s\n", comment);
fprintf(fp, "%d\n", maxval);
/***************************************************************************
* Write the image data to the file.
***************************************************************************/
if(rows != fwrite(image, cols, rows, fp)){
fprintf(stderr, "Error writing the image data in write_pgm_image().\n");
if(fp != stdout) fclose(fp);
return(0);
}
if(fp != stdout) fclose(fp);
return(1);
}
/******************************************************************************
* Function: read_ppm_image
* Purpose: This function reads in an image in PPM format. The image can be
* read in from either a file or from standard input. The image is only read
* from standard input when infilename = NULL. Because the PPM format includes
* the number of columns and the number of rows in the image, these are read
* from the file. Memory to store the image is allocated in this function.
* All comments in the header are discarded in the process of reading the
* image. Upon failure, this function returns 0, upon sucess it returns 1.
******************************************************************************/
int read_ppm_image(char *infilename, unsigned char **image_red,
unsigned char **image_grn, unsigned char **image_blu, int *rows,
int *cols)
{
FILE *fp;
char buf[71];
int p, size;
/***************************************************************************
* Open the input image file for reading if a filename was given. If no
* filename was provided, set fp to read from standard input.
***************************************************************************/
if(infilename == NULL) fp = stdin;
else{
if((fp = fopen(infilename, "r")) == NULL){
fprintf(stderr, "Error reading the file %s in read_ppm_image().\n",
infilename);
return(0);
}
}
/***************************************************************************
* Verify that the image is in PPM format, read in the number of columns
* and rows in the image and scan past all of the header information.
***************************************************************************/
fgets(buf, 70, fp);
if(strncmp(buf,"P6",2) != 0){
fprintf(stderr, "The file %s is not in PPM format in ", infilename);
fprintf(stderr, "read_ppm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
do{ fgets(buf, 70, fp); }while(buf[0] == '#'); /* skip all comment lines */
sscanf(buf, "%d %d", cols, rows);
do{ fgets(buf, 70, fp); }while(buf[0] == '#'); /* skip all comment lines */
/***************************************************************************
* Allocate memory to store the image then read the image from the file.
***************************************************************************/
if(((*image_red) = (unsigned char *) malloc((*rows)*(*cols))) == NULL){
fprintf(stderr, "Memory allocation failure in read_ppm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
if(((*image_grn) = (unsigned char *) malloc((*rows)*(*cols))) == NULL){
fprintf(stderr, "Memory allocation failure in read_ppm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
if(((*image_blu) = (unsigned char *) malloc((*rows)*(*cols))) == NULL){
fprintf(stderr, "Memory allocation failure in read_ppm_image().\n");
if(fp != stdin) fclose(fp);
return(0);
}
size = (*rows)*(*cols);
for(p=0;p<size;p++){
(*image_red)[p] = (unsigned char)fgetc(fp);
(*image_grn)[p] = (unsigned char)fgetc(fp);
(*image_blu)[p] = (unsigned char)fgetc(fp);
}
if(fp != stdin) fclose(fp);
return(1);
}
/******************************************************************************
* Function: write_ppm_image
* Purpose: This function writes an image in PPM format. The file is either
* written to the file specified by outfilename or to standard output if
* outfilename = NULL. A comment can be written to the header if coment != NULL.
******************************************************************************/
int write_ppm_image(char *outfilename, unsigned char *image_red,
unsigned char *image_grn, unsigned char *image_blu, int rows,
int cols, char *comment, int maxval)
{
FILE *fp;
long size, p;
/***************************************************************************
* Open the output image file for writing if a filename was given. If no
* filename was provided, set fp to write to standard output.
***************************************************************************/
if(outfilename == NULL) fp = stdout;
else{
if((fp = fopen(outfilename, "w")) == NULL){
fprintf(stderr, "Error writing the file %s in write_pgm_image().\n",
outfilename);
return(0);
}
}
/***************************************************************************
* Write the header information to the PGM file.
***************************************************************************/
fprintf(fp, "P6\n%d %d\n", cols, rows);
if(comment != NULL)
if(strlen(comment) <= 70) fprintf(fp, "# %s\n", comment);
fprintf(fp, "%d\n", maxval);
/***************************************************************************
* Write the image data to the file.
***************************************************************************/
size = (long)rows * (long)cols;
for(p=0;p<size;p++){ /* Write the image in pixel interleaved format. */
fputc(image_red[p], fp);
fputc(image_grn[p], fp);
fputc(image_blu[p], fp);
}
if(fp != stdout) fclose(fp);
return(1);
} |
the_stack_data/596152.c | #include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool strlonger (const char *s1, const char *s2) {
return strlen(s1) > strlen(s2);
}
int main (void)
{
const char *s1 = "looooooong";
const char *s2 = "short";
printf("'%s' is %lu letters long\n", s1, strlen(s1));
printf("'%s' is %lu letters long\n", s2, strlen(s2));
if(strlonger(s1,s2))
printf("'%s' is longer than '%s'\n", s1, s2);
else
printf("'%s' is longer than '%s'\n", s2, s1);
return 0;
}
|
the_stack_data/59511560.c | #include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include<ctype.h>
#define TElemType int
#define MAXL 42
int top = 0;
int Biarr[MAXL];
char c;
int firstnum,secondnum;
void getArr(int arr[]);
int getnum(void);
void Initialize(int arr[]);
void displayElem(int pos);
int searchPre(int m,int n);
typedef struct BiTNode{
TElemType data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
void Initialize(int arr[]){
memset(arr,0,MAXL*sizeof(int));
}
void getArr(int arr[]){
extern char c;
extern int firstnum,secondnum;
int i = 1;
int state = 0;
int mid;
while (c!=EOF && c!='\n')
{
if(c==',')
i++;
if(c==';')
state++;
mid = getnum();
switch(state){
case 0:
while(mid!=-1 && i!=1 && arr[i/2]==-1)
i++;
arr[i] = mid;
break;
case 1:
firstnum = mid;
break;
case 2:
secondnum = mid;
break;
default:
return;
}
}
arr[0] = i;
}
int getnum(void){
extern char c;
char m;
int num = 0;
int sign = 1;
while((c=getchar())!=EOF && c!='\n' && (isdigit(c)||c=='-')){
if(c=='-')
sign = -1;
num = num*10 + c - '0';
}
if(c=='n'){
m = getchar();
m = getchar();
m = getchar();
return -1;
}
return num*sign;
}
int searchPre(int m,int n){
int i,j;
i = j = 0;
for(int k=1;k<MAXL;k++){
if(Biarr[k] == m)
i = k;
if(Biarr[k] == n)
j = k;
if(i!=0 && j!=0)
break;
}
while(i!=j){
if(i<j)
j /= 2;
else
i /= 2;
}
return i;
}
int main(){
Initialize(Biarr);
getArr(Biarr);
printf("%d",Biarr[searchPre(firstnum,secondnum)]);
return 0;
}
|
the_stack_data/348560.c | /* $OpenBSD: uthread_listen.c,v 1.3 1999/11/25 07:01:38 d Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <[email protected]>
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by John Birrell.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* 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.
*
* $FreeBSD: uthread_listen.c,v 1.5 1999/08/28 00:03:38 peter Exp $
*/
#include <sys/types.h>
#include <sys/socket.h>
#ifdef _THREAD_SAFE
#include <pthread.h>
#include "pthread_private.h"
int
listen(int fd, int backlog)
{
int ret;
if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) {
ret = _thread_sys_listen(fd, backlog);
_FD_UNLOCK(fd, FD_RDWR);
}
return (ret);
}
#endif
|
the_stack_data/108732.c | #include <stdio.h>
unsigned getbits(unsigned int x, int p, int n);
int main() {
unsigned int x;
int p, n;
x = 155;
p = 4;
n = 3;
x = getbits(x, p, n);
printf("%u", x);
return 0;
}
/* get n bits from position p (zero-indexed) */
unsigned getbits(unsigned int x, int p, int n) {
return (x >> (p + 1 - n)) & ~(~0 << n);
}
|
the_stack_data/180836.c | /* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */
/*
* Print the error indicated
* in the cerror cell.
*/
extern int errno;
extern int sys_nerr;
extern char *sys_errlist[];
perror(s)
char *s;
{
register char *c;
register n;
c = "Unknown error";
if(errno < sys_nerr)
c = sys_errlist[errno];
n = strlen(s);
if(n) {
write(2, s, n);
write(2, ": ", 2);
}
write(2, c, strlen(c));
write(2, "\n", 1);
}
|
the_stack_data/86075745.c | /*Implemente um programa que recebe 11 números inteiro e diga se eles são pares ou impares. (PAR OU IMPAR)
A saída deve ser uma por linha, como mostra os exemplos abaixo.*/
#include <stdio.h>
int main(){
int ent;
for(int cont =1; cont <=11; cont++){
scanf("%d", &ent);
if(ent % 2 == 0){
printf("Par \n");
}else{
printf("Impar \n");
}
}
return 0;
} |
the_stack_data/767986.c | /*
@Author: Kishan Adhikari
@Created Date: 2078/05/06
@filename: biggest.c
@Description:Program to find biggest among three numbers using pointer.
*/
#include <stdio.h>
int main()
{
int n1, n2, n3;
int *p1, *p2, *p3;
printf("Enter three numbers:\n");
scanf("%d%d%d", &n1, &n2, &n3);
p1 = &n1, p2 = &n2, p3 = &n3;
if (*p1 > *p2 && *p1 > *p3)
{
printf("%d is largest\n", *p1);
}
else if (*p2 > *p1 && *p2 > *p3)
{
printf("%d is largest\n", *p2);
}
else
{
printf("%d is largest\n", *p3);
}
return 0;
} |
the_stack_data/728482.c | #include <assert.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define NAME ("/linuxquestions.org")
int main()
{
int fd;
assert((fd = shm_open(NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR)) >= 0);
sleep(30);
assert(close(fd) == 0);
assert(shm_unlink(NAME) == 0);
return 0;
}
|
the_stack_data/248581132.c | // RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck %s
_Complex long double a, b, c, d;
void test_fp128_compound_assign(void) {
// CHECK: call { fp128, fp128 } @__multc3
a *= b;
// CHECK: call { fp128, fp128 } @__divtc3
c /= d;
}
|
the_stack_data/153268445.c | #include <stdlib.h>
int main() {
int i, a;
scanf("%d", &a);
if (a % 2 == 0) a++;
for (i = 0; i < 6; i++) {
printf("%d\n", a + i * 2);
}
return 0;
} |
the_stack_data/173579000.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lkaba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/22 16:09:21 by lkaba #+# #+# */
/* Updated: 2017/11/22 16:09:22 by lkaba ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memchr(const void *s, int c, size_t n)
{
size_t i;
i = 0;
while (i < n)
{
if (((unsigned char *)s)[i] == (unsigned char)c)
return (((void *)&((unsigned char *)s)[i]));
i++;
}
return (NULL);
}
|
the_stack_data/380776.c | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
void flag() {
system("/bin/cat flag.txt");
}
int main() {
gid_t gid = getegid();
setresgid(gid, gid, gid);
setvbuf(stdin, NULL, _IONBF, 0);
setvbuf(stdout, NULL, _IONBF, 0);
char item[60];
printf("What item would you like to purchase? ");
fgets(item, sizeof(item), stdin);
item[strlen(item)-1] = 0;
if (strcmp(item, "nothing") == 0) {
printf("Then why did you even come here? ");
} else {
printf("You don't have any money to buy ");
printf(item);
printf("s. You're wasting your time! We don't even sell ");
printf(item);
printf("s. Leave this place and buy ");
printf(item);
printf(" somewhere else. ");
}
printf("Get out!\n");
return 0;
} |
the_stack_data/9513925.c | #include <stdint.h>
#include <stdio.h>
int32_t cmTestFunc(void);
int main(void)
{
if (cmTestFunc() > 4200)
{
printf("Test success.\n");
return 0;
}
else
{
printf("Test failure.\n");
return 1;
}
}
|
the_stack_data/834336.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
char *code(int v)
{
if (v == 0)
return "val0";
else if (v == 1)
return "val1";
return "val2";
}
int main()
{
(time(0));
int val = rand() % 3;
printf("%s\n", code(val));
return 0;
}
|
the_stack_data/153267453.c | #include<stdio.h>
int main()
{
int num1=10, num2=20, num3=30;
printf( " num1 is %d\n num2 is %d\n num3 is %d",num1, num2, num3);
return 0;
}
|
the_stack_data/813470.c | #include <stdio.h>
int main (void){
double salario, z;
scanf("%lf", &salario);
if(salario <= 2000.00){
printf("Isento\n");
} else if(salario <= 3000.00){
z = ((salario - 2000)*0.08);
printf("R$ %.2lf\n", z);
} else if(salario <= 4500.00){
z = ((salario - 3000)*0.18 + 1000*0.08);
printf("R$ %.2lf\n", z);
} else {
z = ((salario - 4500)*0.28 + 1000*0.08 + 1500*0.18);
printf("R$ %.2lf\n", z);
}
return 0;
}
|
the_stack_data/82951125.c | #include <stdio.h>
#include <stdlib.h>
struct
{
int valor;
struct nodo *next;
} typedef *NODO;
int main()
{
NODO a = (NODO *)malloc(sizeof(NODO));
a->valor = 10;
a->next = NULL;
printf("%d\n", a->valor);
return (0);
} |
the_stack_data/120062.c | /* pem_x509.c */
/*
* Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project
* 2001.
*/
/* ====================================================================
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 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 acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* [email protected].
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``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 OpenSSL PROJECT OR
* ITS 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.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* ([email protected]). This product includes software written by Tim
* Hudson ([email protected]). */
#include "stdio.h"
#include "openssl/bio.h"
#include "openssl/evp.h"
#include "openssl/pem.h"
#include "openssl/x509.h"
IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
|
the_stack_data/107724.c | /* APPLE LOCAL testsuite nested functions */
/* { dg-options "-fnested-functions" } */
/* Test whether tree inlining works with prototyped nested functions. */
extern void foo (char *x);
void bar (void);
void bar (void)
{
auto void baz (void);
void baz (void)
{
char tmp[2];
foo (tmp);
}
baz ();
}
|
the_stack_data/25138549.c | // written for real mode
extern unsigned short _low_int_0x13(unsigned short ax, unsigned short bx,
unsigned short cx, unsigned short dx,
unsigned short es);
int load_sectors(unsigned int full_address, unsigned char drive,
unsigned int lba, // 0-based
unsigned int count) {
// we don't expect disk_16 (used by bootloader) to load more than 255
// sectors.
int es = (full_address & 0xFFFF0) >> 4;
int es_address = full_address & 0x000F;
int cylinder_head = (lba / 63);
int sector_index = lba % 63 + 1;
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=02h:_Read_Sectors_From_Drive
_low_int_0x13((0x02 << 8) | count, es_address,
((cylinder_head >> 2) & 0xFFC0) | (sector_index),
((cylinder_head << 8) & 0xFF00) | (drive), es);
// https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH=01h:_Get_Status_of_Last_Drive_Operation
unsigned short ax = _low_int_0x13((0x01 << 8), 0, 0, drive, 0);
int status = ax >> 8;
return status;
} |
the_stack_data/173578388.c | /*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1994-1997, by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* __ftoul(x) converts float x to unsigned long.
*/
unsigned long
__ftoul(float x)
{
union {
float f;
unsigned int l;
} u;
u.f = x;
/* handle cases for which float->unsigned long differs from */
/* float->signed long */
if ((u.l >> 23) == 0xbe) {
/* 2^63 <= x < 2^64 */
return (0x8000000000000000ul | ((long)u.l << 40));
}
/* for all other cases, just convert to signed long */
return ((long)x);
}
|
the_stack_data/32949591.c | /*Exercío 07 - Criar em linguagem C e utilizando o comando
DO WHILE, um programa que imprima uma contagem regressiva
do numero que você digitar.*/
#include <stdio.h>
#include <locale.h>
int main(void){
setlocale(LC_ALL, "Portuguese");
int cont;
printf("digite um número: ");
scanf("%d \n", &cont);
do{
printf("%d", cont);
cont--;
}while (cont>=0);
printf("\n");
}
|
the_stack_data/1071708.c | //
// main.c
// SUPERPUPERSTROKA
//
// Created by Roman on 03.11.14.
// Copyright (c) 2014 Roman. All rights reserved.
//
#include <stdio.h>
#include <string.h>
int overlap(char* a, char* b);
int max(int a, int b){
if(a>b)
return a;
return b;
}
int overlap(char* a, char* b){
unsigned long len_a = strlen(a), len_b = strlen(b);
int i, j=0, count=0;
if((len_a==0)||(len_b==0))
return 0;
i = 0;
while(i<len_b){
if(a[j]==b[i]){
count++;
j++;
}
else{
i = i-count;
count = 0;
j = 0;
}
i++;
}
return count;
}
int main(int argc, const char * argv[]) {
unsigned long i, j, k, m, max = 0, index1=0, index2=0, super = 0, len1=0, len2=0, over=0;
int n;
scanf("%d\n", &n);
unsigned long a[n];
char strings[n][100];
for(i = 0; i < n; i++){
fgets(strings[i], 100, stdin);
//gets(strings[i]);
strings[i][strlen(strings[i])-1] = '\0';
}
for(i = 0; i<n; i++)
a[i] = strlen(strings[i]);
for(m = 0; m<n; m++){
for(j = 0; j<n-1; j++){
for(k = j+1; k<n; k++){
if (overlap(strings[j], strings[k]) > max){
max = overlap(strings[j], strings[k]);
index1 = k;
index2 = j;
len1 = strlen(strings[k]);
len2 = strlen(strings[j]);
}
if (overlap(strings[k], strings[j]) > max){
max = overlap(strings[k], strings[j]);
index1 = j;
index2 = k;
len1 = strlen(strings[j]);
len2 = strlen(strings[k]);
}
}
}
if(max>0){
over = max;
for (i = len1; i<len1+len2-over; i++)
strings[index1][i] = strings[index2][max++];
strings[index2][0] = '\0';
strings[index1][len1+len2-over+1]='\0';
a[index1] = len1+len2-over;
a[index2] = 0;
}
max = 0;
}
for(i = 0; i < n; i++){
super +=a[i];
}
//strings[super][strlen(strings[super])-1] = '\0';
printf("%lu\n", super);
return 0;
}
|
the_stack_data/242331336.c | #include <inttypes.h>
int main() {
int x=1, y=2;
int *p = &x + 1;
int *q = &y;
if ((uintptr_t)p == (uintptr_t)q) {
*p = 11; // UB
}
}
|
the_stack_data/36717.c | /*
* Copyright (C) 2020 National Cheng Kung University, Taiwan.
* Copyright (C) 2011-2012 Roman Arutyunyan ([email protected])
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR 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.
*/
/*
* htstress - Fast HTTP Benchmarking tool
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <inttypes.h>
#include <malloc.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <pthread.h>
#include <signal.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/un.h>
#include <unistd.h>
typedef void (*sighandler_t)(int);
#define HTTP_REQUEST_PREFIX "http://"
#define HTTP_REQUEST_FMT "GET %s HTTP/1.0\r\nHost: %s\r\n\r\n"
#define HTTP_REQUEST_DEBUG 0x01
#define HTTP_RESPONSE_DEBUG 0x02
#define INBUFSIZE 1024
#define BAD_REQUEST 0x1
#define MAX_EVENTS 256
struct econn {
int fd;
size_t offs;
int flags;
};
static char *outbuf;
static size_t outbufsize;
static struct sockaddr_storage sss;
static socklen_t sssln = 0;
static int concurrency = 1;
static int num_threads = 1;
static char *udaddr = "";
static volatile _Atomic uint64_t num_requests = 0;
static volatile uint64_t max_requests = 0;
static volatile _Atomic uint64_t good_requests = 0;
static volatile _Atomic uint64_t bad_requests = 0;
static volatile _Atomic uint64_t socket_errors = 0;
static volatile uint64_t in_bytes = 0;
static volatile uint64_t out_bytes = 0;
static uint64_t ticks;
static int debug = 0;
static int exit_i = 0;
static struct timeval tv, tve;
static const char short_options[] = "n:c:t:u:h:d46";
static const struct option long_options[] = {
{"number", 1, NULL, 'n'}, {"concurrency", 1, NULL, 'c'},
{"threads", 0, NULL, 't'}, {"udaddr", 1, NULL, 'u'},
{"host", 1, NULL, 'h'}, {"debug", 0, NULL, 'd'},
{"help", 0, NULL, '%'}, {NULL, 0, NULL, 0}};
static void sigint_handler(int arg)
{
(void) arg;
max_requests = num_requests;
}
static void start_time()
{
if (gettimeofday(&tv, NULL)) {
perror("gettimeofday");
exit(1);
}
}
static void end_time()
{
if (gettimeofday(&tve, NULL)) {
perror("gettimeofday");
exit(1);
}
}
static void init_conn(int efd, struct econn *ec)
{
int ret;
ec->fd = socket(sss.ss_family, SOCK_STREAM, 0);
ec->offs = 0;
ec->flags = 0;
if (ec->fd == -1) {
perror("socket() failed");
exit(1);
}
fcntl(ec->fd, F_SETFL, O_NONBLOCK);
do {
ret = connect(ec->fd, (struct sockaddr *) &sss, sssln);
} while (ret && errno == EAGAIN);
if (ret && errno != EINPROGRESS) {
perror("connect() failed");
exit(1);
}
struct epoll_event evt = {
.events = EPOLLOUT,
.data.ptr = ec,
};
if (epoll_ctl(efd, EPOLL_CTL_ADD, ec->fd, &evt)) {
perror("epoll_ctl");
exit(1);
}
}
static void *worker(void *arg)
{
int ret, nevts;
struct epoll_event evts[MAX_EVENTS];
char inbuf[INBUFSIZE];
struct econn ecs[concurrency], *ec;
(void) arg;
int efd = epoll_create(concurrency);
if (efd == -1) {
perror("epoll");
exit(1);
}
for (int n = 0; n < concurrency; ++n)
init_conn(efd, ecs + n);
for (;;) {
do {
nevts = epoll_wait(efd, evts, sizeof(evts) / sizeof(evts[0]), -1);
} while (!exit_i && nevts < 0 && errno == EINTR);
if (exit_i != 0) {
exit(0);
}
if (nevts == -1) {
perror("epoll_wait");
exit(1);
}
for (int n = 0; n < nevts; ++n) {
ec = (struct econn *) evts[n].data.ptr;
if (!ec) {
fprintf(stderr, "fatal: NULL econn\n");
exit(1);
}
if (evts[n].events & EPOLLERR) {
/* normally this should not happen */
static unsigned int number_of_errors_logged = 0;
int error = 0;
socklen_t errlen = sizeof(error);
number_of_errors_logged += 1;
if (getsockopt(efd, SOL_SOCKET, SO_ERROR, (void *) &error,
&errlen) == 0) {
fprintf(stderr, "error = %s\n", strerror(error));
}
if (number_of_errors_logged % 100 == 0) {
fprintf(stderr, "EPOLLERR caused by unknown error\n");
}
atomic_fetch_add(&socket_errors, 1);
close(ec->fd);
if (num_requests > max_requests)
continue;
init_conn(efd, ec);
continue;
}
if (evts[n].events & EPOLLHUP) {
/* This can happen for HTTP/1.0 */
fprintf(stderr, "EPOLLHUP\n");
exit(1);
}
if (evts[n].events & EPOLLOUT) {
ret = send(ec->fd, outbuf + ec->offs, outbufsize - ec->offs, 0);
//printf("outbuf + ec->offs : %s\n", outbuf + ec->offs);
//printf("ec->offs : %lu\n", ec->offs);
if (ret == -1 && errno != EAGAIN) {
/* TODO: something better than this */
perror("send");
exit(1);
}
if (ret > 0) {
if (debug & HTTP_REQUEST_DEBUG)
write(2, outbuf + ec->offs, outbufsize - ec->offs);
ec->offs += ret;
/* write done? schedule read */
if (ec->offs == outbufsize) {
evts[n].events = EPOLLIN;
evts[n].data.ptr = ec;
ec->offs = 0;
if (epoll_ctl(efd, EPOLL_CTL_MOD, ec->fd, evts + n)) {
perror("epoll_ctl");
exit(1);
}
}
}
} else if (evts[n].events & EPOLLIN) {
for (;;) {
ret = recv(ec->fd, inbuf, sizeof(inbuf), 0);
//printf("inbuf : %s\n", inbuf);
if (ret == -1 && errno != EAGAIN) {
perror("recv");
exit(1);
}
if (ret <= 0)
break;
if (ec->offs <= 9 && ec->offs + ret > 10) {
char c = inbuf[9 - ec->offs];
if (c == '4' || c == '5')
ec->flags |= BAD_REQUEST;
}
if (debug & HTTP_RESPONSE_DEBUG)
write(2, inbuf, ret);
ec->offs += ret;
}
if (!ret) {
close(ec->fd);
int m = atomic_fetch_add(&num_requests, 1);
if (max_requests && (m + 1 > (int) max_requests))
atomic_fetch_sub(&num_requests, 1);
else if (ec->flags & BAD_REQUEST)
atomic_fetch_add(&bad_requests, 1);
else
atomic_fetch_add(&good_requests, 1);
if (max_requests && (m + 1 >= (int) max_requests)) {
end_time();
// 把 thread 給砍掉
return NULL;
}
if (ticks && m % ticks == 0)
printf("%d requests\n", m);
init_conn(efd, ec);
}
}
}
}
}
static void signal_exit(int signal)
{
(void) signal;
exit_i++;
}
static void print_usage()
{
printf(
"Usage: htstress [options] [http://]hostname[:port]/path\n"
"Options:\n"
" -n, --number total number of requests (0 for inifinite, "
"Ctrl-C to abort)\n"
" -c, --concurrency number of concurrent connections\n"
" -t, --threads number of threads (set this to the number of "
"CPU cores)\n"
" -u, --udaddr path to unix domain socket\n"
" -h, --host host to use for http request\n"
" -d, --debug debug HTTP response\n"
" --help display this message\n");
exit(0);
}
int main(int argc, char *argv[])
{
pthread_t useless_thread;
char *host = NULL;
char *node = NULL;
char *port = "http";
struct sockaddr_in *ssin = (struct sockaddr_in *) &sss;
struct sockaddr_in6 *ssin6 = (struct sockaddr_in6 *) &sss;
struct sockaddr_un *ssun = (struct sockaddr_un *) &sss;
struct addrinfo *result, *rp;
struct addrinfo hints;
// sighandler_t ??
// signal ??
sighandler_t ret = signal(SIGINT, signal_exit);
if (ret == SIG_ERR) {
perror("signal(SIGINT, handler)");
exit(0);
}
ret = signal(SIGTERM, signal_exit);
if (ret == SIG_ERR) {
perror("signal(SIGTERM, handler)");
exit(0);
}
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_V4MAPPED | AI_ADDRCONFIG;
memset(&sss, 0, sizeof(struct sockaddr_storage));
if (argc == 1)
print_usage();
// getopt_long ??
//
// 為什麼 next_option 是用 int 來裝??
// 我猜是因為最後有一個 -1
// 而且 getopt_long 本來就是回傳 int
int next_option;
do {
next_option =
getopt_long(argc, argv, short_options, long_options, NULL);
switch (next_option) {
case 'n':
max_requests = strtoull(optarg, 0, 10);
break;
case 'c':
concurrency = atoi(optarg);
break;
case 't':
num_threads = atoi(optarg);
break;
case 'u':
udaddr = optarg;
break;
case 'd':
debug = 0x03;
break;
case 'h':
host = optarg;
break;
case '4':
hints.ai_family = PF_INET;
break;
case '6':
hints.ai_family = PF_INET6;
break;
case '%':
print_usage();
case -1:
break;
default:
printf("Unexpected argument: '%c'\n", next_option);
return 1;
}
} while (next_option != -1);
if (optind >= argc) {
printf("Missing URL\n");
return 1;
}
/* parse URL */
// strpbrk ??
// strndup ??
// strchr ??
//
char *s = argv[optind];
if (!strncmp(s, HTTP_REQUEST_PREFIX, sizeof(HTTP_REQUEST_PREFIX) - 1))
s += (sizeof(HTTP_REQUEST_PREFIX) - 1);
node = s;
char *rq = strpbrk(s, ":/");
if (!rq)
rq = "/";
else if (*rq == '/') {
node = strndup(s, rq - s);
if (!node) {
perror("node = strndup(s, rq - s)");
exit(EXIT_FAILURE);
}
} else if (*rq == ':') {
*rq++ = 0;
port = rq;
rq = strchr(rq, '/');
if (*rq == '/') {
port = strndup(port, rq - port);
if (!port) {
perror("port = strndup(rq, rq - port)");
exit(EXIT_FAILURE);
}
} else
rq = "/";
}
// rq 應該就是可以設定 fib 參數的地方
printf("rq : %s\n", rq);
printf("node : %s\n", node);
printf("port : %s\n", port);
printf("maxrequest : %ld\n", max_requests);
if (strnlen(udaddr, sizeof(ssun->sun_path) - 1) == 0) {
int j = getaddrinfo(node, port, &hints, &result);
if (j) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(j));
exit(EXIT_FAILURE);
}
for (rp = result; rp; rp = rp->ai_next) {
int testfd =
socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (testfd == -1)
continue;
if (connect(testfd, rp->ai_addr, rp->ai_addrlen) == 0) {
close(testfd);
break;
}
close(testfd);
}
if (!rp) { /* No address succeeded */
fprintf(stderr, "getaddrinfo failed\n");
exit(EXIT_FAILURE);
}
if (rp->ai_addr->sa_family == PF_INET) {
*ssin = *(struct sockaddr_in *) rp->ai_addr;
} else if (rp->ai_addr->sa_family == PF_INET6) {
*ssin6 = *(struct sockaddr_in6 *) rp->ai_addr;
} else {
fprintf(stderr, "invalid family %d from getaddrinfo\n",
rp->ai_addr->sa_family);
exit(EXIT_FAILURE);
}
sssln = rp->ai_addrlen;
freeaddrinfo(result);
} else {
ssun->sun_family = PF_UNIX;
strncpy(ssun->sun_path, udaddr, sizeof(ssun->sun_path) - 1);
sssln = sizeof(struct sockaddr_un);
}
// end parse url
/* prepare request buffer */
if (!host)
host = node;
outbufsize = strlen(rq) + sizeof(HTTP_REQUEST_FMT) + strlen(host);
outbuf = malloc(outbufsize);
outbufsize = snprintf(outbuf, outbufsize, HTTP_REQUEST_FMT, rq, host);
printf("outbuf : %s\n", outbuf);
ticks = max_requests / 10;
signal(SIGINT, &sigint_handler);
if (!max_requests) {
ticks = 1000;
printf("[Press Ctrl-C to finish]\n");
}
// 開始計時
start_time();
/* run test */
// 新增 t-1 個 thread
// t-1 是因為在下面也有一個 worker
for (int n = 0; n < num_threads - 1; ++n) {
pthread_create(&useless_thread, 0, &worker, 0);
}
worker(0);
/* output result */
// 將 start-time 減去 end_time
double delta =
tve.tv_sec - tv.tv_sec + ((double) (tve.tv_usec - tv.tv_usec)) / 1e6;
printf(
"\n"
"requests: %" PRIu64
"\n"
"good requests: %" PRIu64
" [%d%%]\n"
"bad requests: %" PRIu64
" [%d%%]\n"
"socker errors: %" PRIu64
" [%d%%]\n"
"seconds: %.3f\n"
"requests/sec: %.3f\n"
"\n",
num_requests, good_requests,
(int) (num_requests ? good_requests * 100 / num_requests : 0),
bad_requests,
(int) (num_requests ? bad_requests * 100 / num_requests : 0),
socket_errors,
(int) (num_requests ? socket_errors * 100 / num_requests : 0), delta,
delta > 0 ? max_requests / delta : 0);
return 0;
}
/*
start_time 開始計時後,會不斷地用 4 個 thread 丟 request ,每丟一次就加一次 counter
當丟的次數符合需求後,就用 end_time 來紀錄結束的時間,並結束執行。
每個 thread 都會執行一個無窮迴圈。當發出的 request 數量符合要求後,就會跳出迴圈並結束
*/
|
the_stack_data/490131.c | // Test string s1 overflow in strcspn function
// RUN: %clang_asan %s -o %t && %env_asan_opts=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
// Test intercept_strspn asan option
// RUN: %env_asan_opts=intercept_strspn=false %run %t 2>&1
#include <assert.h>
#include <string.h>
#include <sanitizer/asan_interface.h>
int main(int argc, char **argv) {
size_t r;
char s2[] = "ab";
char s1[4] = "caB";
__asan_poison_memory_region ((char *)&s1[2], 2);
r = strcspn(s1, s2);
// CHECK:'s1'{{.*}} <== Memory access at offset {{[0-9]+}} partially overflows this variable
assert(r == 1);
return 0;
}
|
the_stack_data/1187377.c |
#include <stdio.h>
int power(int, int);
int main()
{
int n, sum = 0, temp, remainder, digits = 0;
printf("Input an integer\n");
scanf("%d", &n);
temp = n;
// Count number of digits
while (temp != 0) {
digits++;
temp = temp/10;
}
temp = n;
while (temp != 0) {
remainder = temp%10;
sum = sum + power(remainder, digits);
temp = temp/10;
}
if (n == sum)
printf("%d is an Armstrong number.\n", n);
else
printf("%d isn't an Armstrong number.\n", n);
return 0;
}
int power(int n, int r) {
int c, p = 1;
for (c = 1; c <= r; c++)
p = p*n;
return p;
}
|
the_stack_data/11051.c | /*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
*
* 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 copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __clang__
unsigned char __builtin_subcb(unsigned char, unsigned char, unsigned char, unsigned char *);
#endif
int main(int argc, const char **argv) {
unsigned char carryout, res;
res = __builtin_subcb((unsigned char)0x0, (unsigned char)0x0, 0, &carryout);
if (res != 0x0 || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFF, (unsigned char)0x0, 0, &carryout);
if (res != 0xFF || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0x0, (unsigned char)0xFF, 0, &carryout);
if (res != 0x01 || carryout != 1) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFF, (unsigned char)0x1, 0, &carryout);
if (res != 0xFE || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0x1, (unsigned char)0xFF, 0, &carryout);
if (res != 0x2 || carryout != 1) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFF, (unsigned char)0xFF, 0, &carryout);
if (res != 0x0 || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0x8F, (unsigned char)0x0F, 0, &carryout);
if (res != 0x80 || carryout != 0) {
return res;
}
res = __builtin_subcb((unsigned char)0x0, (unsigned char)0xFE, 1, &carryout);
if (res != 0x1 || carryout != 1) {
return -1;
}
res = __builtin_subcb((unsigned char)0x0, (unsigned char)0xFF, 1, &carryout);
if (res != 0x0 || carryout != 1) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFE, (unsigned char)0x0, 1, &carryout);
if (res != 0xFD || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFE, (unsigned char)0xFE, 1, &carryout);
if (res != 0xFF || carryout != 1) {
return res;
}
res = __builtin_subcb((unsigned char)0xFE, (unsigned char)0xFF, 0, &carryout);
if (res != 0xFF || carryout != 1) {
return res;
}
res = __builtin_subcb((unsigned char)0xFE, (unsigned char)0xFF, 1, &carryout);
if (res != 0xFE || carryout != 1) {
return res;
}
res = __builtin_subcb((unsigned char)0xFF, (unsigned char)0x0, 1, &carryout);
if (res != 0xFE || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0xFF, (unsigned char)0xFF, 1, &carryout);
if (res != 0xFF || carryout != 1) {
return -1;
}
res = __builtin_subcb((unsigned char)0x0F, (unsigned char)0x1, 0, &carryout);
if (res != 0x0E || carryout != 0) {
return -1;
}
res = __builtin_subcb((unsigned char)0x0F, (unsigned char)0x1, 1, &carryout);
if (res != 0x0D || carryout != 0) {
return -1;
}
return 0;
}
|
the_stack_data/140765515.c | #include <stdio.h>
int ft_str_is_alpha(char *str)
{
int i;
int a;
i = 0;
a = 1;
while (str[i] != '\0')
{
if (!((str[i] > 64) && (str[i] < 91)))
{
if (!((str[i] > 96) && (str[i] < 123)))
a = 0;
}
i++;
}
return (a);
}
|
the_stack_data/1261912.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2014 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation 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 INTEL OR
ITS 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.
END_LEGAL */
// features.h does not exist on FreeBSD
#ifndef TARGET_BSD
// features initializes the system's state, including the state of __USE_GNU
#include <features.h>
#endif
// If __USE_GNU is defined, we don't need to do anything.
// If we defined it ourselves, we need to undefine it later.
#ifndef __USE_GNU
#define __USE_GNU
#define APP_UNDEF_USE_GNU
#endif
#include <ucontext.h>
// If we defined __USE_GNU ourselves, we need to undefine it here.
#ifdef APP_UNDEF_USE_GNU
#undef __USE_GNU
#undef APP_UNDEF_USE_GNU
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#ifdef TARGET_IA32
#define REG_IP REG_EIP
#else
#define REG_IP REG_RIP
#endif
void *DivideByZeroRetPoint;
int DivideByZero()
{
unsigned int i;
volatile unsigned int zero = 0;
fprintf(stderr, "Going to divide by zero\n");
i = 1 / zero;
return i/i;
}
#define DIV_OPCODE 0xf7
#define MODRM_REG 0xc0
#define MODRM_DISP8 0x40
#define MODRM_DISP32 0x80
#define IS_REG_MODE(modrmByte) ((modrmByte & MODRM_REG) == MODRM_REG)
#define IS_DISP8_MODE(modrmByte) ((modrmByte & MODRM_DISP8) == MODRM_DISP8)
#define IS_DISP32_MODE(modrmByte) ((modrmByte & MODRM_DISP32) == MODRM_DISP32)
void div0_signal_handler(int signum, siginfo_t *siginfo, void *uctxt)
{
printf("Inside div0 handler\n");
ucontext_t *frameContext = (ucontext_t *)uctxt;
unsigned char *bytes = (unsigned char *)frameContext->uc_mcontext.gregs[REG_IP];
if (bytes[0] == DIV_OPCODE)
{
if (IS_REG_MODE(bytes[1]))
{
printf("div %reg instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 2;
return;
}
if (IS_DISP8_MODE(bytes[1]))
{
printf("div mem8 instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 3;
return;
}
if (IS_DISP32_MODE(bytes[1]))
{
printf("div mem32 instruction\n");
// set IP pointing to the next instruction
frameContext->uc_mcontext.gregs[REG_IP] += 6;
return;
}
}
printf("Unexpected instruction at address 0x%lx\n", (unsigned long)frameContext->uc_mcontext.gregs[REG_IP]);
exit(-1);
}
int main()
{
int ret;
struct sigaction sSigaction;
/* Register the signal hander using the siginfo interface*/
sSigaction.sa_sigaction = div0_signal_handler;
sSigaction.sa_flags = SA_SIGINFO;
/* mask all other signals */
sigfillset(&sSigaction.sa_mask);
ret = sigaction(SIGFPE, &sSigaction, NULL);
if(ret)
{
perror("ERROR, sigaction failed");
exit(-1);
}
if(DivideByZero() != 1)
{
exit (-1);
}
return 0;
}
|
the_stack_data/630625.c | /*
* Copyright (c) 2013, 2014 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* libgen/basename.c
* Returns the name part of a path.
*/
#include <libgen.h>
#include <string.h>
static const char current_directory[2] = ".";
char* basename(char* path)
{
if (!path || !*path)
return (char*) current_directory;
size_t path_len = strlen(path);
while (2 <= path_len && path[path_len - 1] == '/')
path[--path_len] = '\0';
if (strcmp(path, "/") == 0)
return path;
char* last_slash = strrchr(path, '/');
if (!last_slash)
return path;
return last_slash + 1;
}
|
the_stack_data/118668.c | #include <stdio.h>
main () {
int M,N,L1,L2,H;
printf ("\n ** CALCULO DOS LADOS E DA HIPOTENUSA ** \n");
printf ("\nDigite o valor de M: ");
scanf ("%i",&M);
printf ("Digite o valor de N (M>N): ");
scanf ("%i",&N);
L1 = M * M - N * N;
L2 = 2 * M * N;
H = M * M + N * N;
printf ("\nO valor do lado 1 e: %i.\n",L1);
printf ("O valor do lado 2 e: %i.\n",L2);
printf ("O valor da hipotenusa e: %i.\n",H);
printf ("\n\n<< Marco_Tulio >>\n");
getchar(),getchar();
}
|
the_stack_data/3262942.c | #include <sys/stat.h>
int mkfifo(const char *path, mode_t mode)
{
return mknod(path, mode | S_IFIFO, 0);
}
|
the_stack_data/243892861.c | #include <stdint.h>
#include <string.h>
#if defined(__x86_64__)
struct x86_64_regs {
uint64_t rax, rbx, rcx, rdx, rdi, rsi, rbp, r8, r9, r10, r11, r12, r13, r14,
r15;
union {
uint64_t rip;
uint64_t pc;
};
union {
uint64_t rsp;
uint64_t sp;
};
union {
uint64_t rflags;
uint64_t flags;
};
uint8_t zmm_regs[32][64];
};
void afl_persistent_hook(struct x86_64_regs *regs, uint64_t guest_base,
uint8_t *input_buf, uint32_t input_buf_len) {
memcpy((void *)regs->rdi, input_buf, input_buf_len);
regs->rsi = input_buf_len;
}
#elif defined(__i386__)
struct x86_regs {
uint32_t eax, ebx, ecx, edx, edi, esi, ebp;
union {
uint32_t eip;
uint32_t pc;
};
union {
uint32_t esp;
uint32_t sp;
};
union {
uint32_t eflags;
uint32_t flags;
};
uint8_t xmm_regs[8][16];
};
void afl_persistent_hook(struct x86_regs *regs, uint64_t guest_base,
uint8_t *input_buf, uint32_t input_buf_len) {
void **esp = (void **)regs->esp;
void * arg1 = esp[1];
void **arg2 = &esp[2];
memcpy(arg1, input_buf, input_buf_len);
*arg2 = (void *)input_buf_len;
}
#else
#pragma error "Unsupported architecture"
#endif
int afl_persistent_hook_init(void) {
// 1 for shared memory input (faster), 0 for normal input (you have to use
// read(), input_buf will be NULL)
return 1;
}
|
the_stack_data/159516434.c | /*
PsychSourceGL/Source/Common/Screen/PsychMovieSupportGStreamer.c
PLATFORMS: All
AUTHORS:
[email protected] mk Mario Kleiner
HISTORY:
28.11.2010 mk Wrote it.
20.08.2014 mk Ported to GStreamer-1.4.x and later.
DESCRIPTION:
Psychtoolbox functions for dealing with movies. This is the operating system independent
version which uses the GStreamer media framework, version 1.4 or later.
These PsychGSxxx functions are called from the dispatcher in
Common/Screen/PsychMovieSupport.[hc].
*/
#ifdef PTB_USE_GSTREAMER
#include "Screen.h"
#include <glib.h>
#include "PsychMovieSupportGStreamer.h"
#include <gst/gst.h>
#if GST_CHECK_VERSION(1,0,0)
#include <gst/app/gstappsink.h>
#include <gst/video/video.h>
// Need to define this for playbin as it is not defined
// in any header file: (Expected behaviour - not a bug)
typedef enum {
GST_PLAY_FLAG_VIDEO = (1 << 0),
GST_PLAY_FLAG_AUDIO = (1 << 1),
GST_PLAY_FLAG_TEXT = (1 << 2),
GST_PLAY_FLAG_VIS = (1 << 3),
GST_PLAY_FLAG_SOFT_VOLUME = (1 << 4),
GST_PLAY_FLAG_NATIVE_AUDIO = (1 << 5),
GST_PLAY_FLAG_NATIVE_VIDEO = (1 << 6),
GST_PLAY_FLAG_DOWNLOAD = (1 << 7),
GST_PLAY_FLAG_BUFFERING = (1 << 8),
GST_PLAY_FLAG_DEINTERLACE = (1 << 9)
} GstPlayFlags;
#define PSYCH_MAX_MOVIES 100
typedef struct {
psych_mutex mutex;
psych_condition condition;
double pts;
GstElement *theMovie;
GMainLoop *MovieContext;
GstElement *videosink;
PsychWindowRecordType* parentRecord;
unsigned char *imageBuffer;
int frameAvail;
int preRollAvail;
double rate;
int startPending;
int endOfFetch;
int specialFlags1;
int pixelFormat;
int loopflag;
double movieduration;
int nrframes;
double fps;
int width;
int height;
double aspectRatio;
int bitdepth;
double last_pts;
int nr_droppedframes;
int nrAudioTracks;
int nrVideoTracks;
char movieLocation[FILENAME_MAX];
char movieName[FILENAME_MAX];
GLuint cached_texture;
} PsychMovieRecordType;
static PsychMovieRecordType movieRecordBANK[PSYCH_MAX_MOVIES];
static int numMovieRecords = 0;
static psych_bool firsttime = TRUE;
/*
* PsychGSMovieInit() -- Initialize movie subsystem.
* This routine is called by Screen's RegisterProject.c PsychModuleInit()
* routine at Screen load-time. It clears out the movieRecordBANK to
* bring the subsystem into a clean initial state.
*/
void PsychGSMovieInit(void)
{
// Initialize movieRecordBANK with NULL-entries:
int i;
for (i=0; i < PSYCH_MAX_MOVIES; i++) {
memset(&movieRecordBANK[i], 0, sizeof(PsychMovieRecordType));
}
numMovieRecords = 0;
// Note: This is deprecated and not needed anymore on GLib 2.31.0 and later, as
// GLib's threading system auto-initializes on first use since that version. We
// keep it for now to stay compatible to older systems, e.g., Ubuntu 10.04 LTS,
// conditionally on the GLib version we build against:
#if !GLIB_CHECK_VERSION (2, 31, 0)
// Initialize GLib's threading system early:
if (!g_thread_supported()) g_thread_init(NULL);
#endif
return;
}
int PsychGSGetMovieCount(void) {
return(numMovieRecords);
}
// Forward declaration:
static gboolean PsychMovieBusCallback(GstBus *bus, GstMessage *msg, gpointer dataptr);
/* Perform context loop iterations (for bus message handling) if doWait == false,
* as long as there is work to do, or at least two seconds worth of iterations
* if doWait == true. This drives the message-bus callback, so needs to be
* performed to get any error reporting etc.
*/
int PsychGSProcessMovieContext(PsychMovieRecordType* movie, psych_bool doWait)
{
GstBus* bus;
GstMessage *msg;
psych_bool workdone = FALSE;
double tdeadline, tnow;
PsychGetAdjustedPrecisionTimerSeconds(&tdeadline);
tnow = tdeadline;
tdeadline+=2.0;
// New style:
bus = gst_pipeline_get_bus(GST_PIPELINE(movie->theMovie));
msg = NULL;
// If doWait, try to perform iterations until 2 seconds elapsed or at least one event handled:
while (doWait && (tnow < tdeadline) && !gst_bus_have_pending(bus)) {
// Update time:
PsychYieldIntervalSeconds(0.010);
PsychGetAdjustedPrecisionTimerSeconds(&tnow);
}
msg = gst_bus_pop(bus);
while (msg) {
workdone = TRUE;
PsychMovieBusCallback(bus, msg, movie);
gst_message_unref(msg);
msg = gst_bus_pop(bus);
}
gst_object_unref(bus);
return(workdone);
}
/* Initiate pipeline state changes: Startup, Preroll, Playback, Pause, Standby, Shutdown. */
static psych_bool PsychMoviePipelineSetState(GstElement* theMovie, GstState state, double timeoutSecs)
{
GstState state_pending;
GstStateChangeReturn rcstate;
gst_element_set_state(theMovie, state);
// Non-Blocking, async?
if (timeoutSecs < 0) return(TRUE);
// Wait for up to timeoutSecs for state change to complete or fail:
rcstate = gst_element_get_state(theMovie, &state, &state_pending, (GstClockTime) (timeoutSecs * 1e9));
switch(rcstate) {
case GST_STATE_CHANGE_SUCCESS:
//printf("PTB-DEBUG: Statechange completed with GST_STATE_CHANGE_SUCCESS.\n");
break;
case GST_STATE_CHANGE_ASYNC:
printf("PTB-INFO: Statechange in progress with GST_STATE_CHANGE_ASYNC.\n");
break;
case GST_STATE_CHANGE_NO_PREROLL:
//printf("PTB-INFO: Statechange completed with GST_STATE_CHANGE_NO_PREROLL.\n");
break;
case GST_STATE_CHANGE_FAILURE:
printf("PTB-ERROR: Statechange failed with GST_STATE_CHANGE_FAILURE!\n");
return(FALSE);
break;
default:
printf("PTB-ERROR: Unknown state-change result in preroll.\n");
return(FALSE);
}
return(TRUE);
}
psych_bool PsychIsMovieSeekable(PsychMovieRecordType* movie)
{
GstQuery *query;
gint64 start, end;
gboolean seekable = FALSE;
query = gst_query_new_seeking(GST_FORMAT_TIME);
if (gst_element_query(movie->theMovie, query)) {
gst_query_parse_seeking(query, NULL, &seekable, &start, &end);
if (seekable) {
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-DEBUG: Seeking is enabled from %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT "\n",
GST_TIME_ARGS (start), GST_TIME_ARGS (end));
}
}
else {
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Seeking is disabled for this movie stream.\n");
}
}
else {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Seeking query failed!\n");
}
gst_query_unref(query);
return((psych_bool) seekable);
}
/* Receive messages from the playback pipeline message bus and handle them: */
static gboolean PsychMovieBusCallback(GstBus *bus, GstMessage *msg, gpointer dataptr)
{
GstSeekFlags rewindFlags = 0;
PsychMovieRecordType* movie = (PsychMovieRecordType*) dataptr;
(void) bus;
if (PsychPrefStateGet_Verbosity() > 11) printf("PTB-DEBUG: PsychMovieBusCallback: Msg source name and type: %s : %s\n", GST_MESSAGE_SRC_NAME(msg), GST_MESSAGE_TYPE_NAME(msg));
switch (GST_MESSAGE_TYPE (msg)) {
case GST_MESSAGE_SEGMENT_DONE:
// We usually receive segment done message instead of eos if looped playback is active and
// the end of the stream is approaching, so we fallthrough to message eos for rewinding...
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: PsychMovieBusCallback: Message SEGMENT_DONE received.\n");
case GST_MESSAGE_EOS: {
// Rewind at end of movie if looped playback enabled:
if ((GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) && (PsychPrefStateGet_Verbosity() > 4)) printf("PTB-DEBUG: PsychMovieBusCallback: Message EOS received.\n");
// Looping via seek requested (method 0x1) and playback active?
if ((movie->loopflag & 0x1) && (movie->rate != 0)) {
// Perform loop via rewind via seek:
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: PsychMovieBusCallback: End of iteration in active looped playback reached: Rewinding...\n");
// Seek: We normally don't GST_SEEK_FLAG_FLUSH here, so the rewinding is smooth because we don't throw away buffers queued in the pipeline,
// unless we are at the end of the stream (EOS), so there ain't anything queued in the pipeline, or code requests an explicit pipeline flush via flag 0x8.
// This seems to make no sense (why flush an already EOS - empty pipeline?) but is neccessary for some movies with sound on some systems:
if ((GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS) || (movie->loopflag & 0x8)) rewindFlags |= GST_SEEK_FLAG_FLUSH;
// On some movies and configurations, we need a segment seek as indicated by flag 0x4:
if (movie->loopflag & 0x4) rewindFlags |= GST_SEEK_FLAG_SEGMENT;
// Seek method depends on playback direction:
if (movie->rate > 0) {
if (!gst_element_seek(movie->theMovie, movie->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE | rewindFlags, GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Rewinding video in forward playback failed!\n");
}
}
else {
if (!gst_element_seek(movie->theMovie, movie->rate, GST_FORMAT_TIME, GST_SEEK_FLAG_ACCURATE | rewindFlags, GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE, GST_SEEK_TYPE_END, 0)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Rewinding video in reverse playback failed!\n");
}
}
}
break;
}
case GST_MESSAGE_BUFFERING: {
// Pipeline is buffering data, e.g., during network streaming playback.
// Print some optional status info:
gint percent = 0;
gst_message_parse_buffering(msg, &percent);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie '%s', buffering video data: %i percent done ...\n", movie->movieName, (int) percent);
break;
}
case GST_MESSAGE_WARNING: {
gchar *debug;
GError *error;
gst_message_parse_warning(msg, &error, &debug);
if (PsychPrefStateGet_Verbosity() > 3) {
printf("PTB-WARNING: GStreamer movie playback engine reports this warning:\n"
" Warning from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
printf(" Additional debug info: %s.\n", (debug) ? debug : "None");
}
g_free(debug);
g_error_free(error);
break;
}
case GST_MESSAGE_ERROR: {
gchar *debug;
GError *error;
gst_message_parse_error(msg, &error, &debug);
if (PsychPrefStateGet_Verbosity() > 0) {
// Most common case, "File not found" error? If so, we provide a pretty-printed error message:
if ((error->domain == GST_RESOURCE_ERROR) && (error->code == GST_RESOURCE_ERROR_NOT_FOUND)) {
printf("PTB-ERROR: Could not open movie file [%s] for playback! No such moviefile with the given absolute path and filename.\n",
movie->movieName);
printf("PTB-ERROR: Please note that you *must* provide an absolute path and filename for your movie file, filename alone won't work.\n");
printf("PTB-ERROR: The specific file URI of the missing movie was: %s.\n", movie->movieLocation);
}
else {
// Nope, something more special. Provide detailed GStreamer error output:
printf("PTB-ERROR: GStreamer movie playback engine reports this error:\n"
" Error from element %s: %s\n", GST_OBJECT_NAME(msg->src), error->message);
printf(" Additional debug info: %s.\n\n", (debug) ? debug : "None");
// And some interpretation for our technically challenged users ;-):
if ((error->domain == GST_RESOURCE_ERROR) && (error->code != GST_RESOURCE_ERROR_NOT_FOUND)) {
printf(" This means that there was some problem with reading the movie file (permissions etc.).\n\n");
}
}
}
g_free(debug);
g_error_free(error);
break;
}
default:
break;
}
return TRUE;
}
/* Called at each end-of-stream event at end of playback: */
static void PsychEOSCallback(GstAppSink *sink, gpointer user_data)
{
(void) sink, (void) user_data;
//PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
//PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: Videosink reached EOS.\n");
//PsychSignalCondition(&movie->condition);
//PsychUnlockMutex(&movie->mutex);
return;
}
/* Called whenever an active seek has completed or pipeline goes into pause.
* Signals/handles arrival of preroll buffers. Used to detect/signal when
* new videobuffers are available in non-playback mode.
*/
static GstFlowReturn PsychNewPrerollCallback(GstAppSink *sink, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
(void) sink;
PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New PrerollBuffer received.\n");
movie->preRollAvail++;
PsychSignalCondition(&movie->condition);
PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
/* Called whenever pipeline is in active playback and a new video frame arrives.
* Used to detect/signal when new videobuffers are available in playback mode.
*/
static GstFlowReturn PsychNewBufferCallback(GstAppSink *sink, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
(void) sink;
PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New Buffer received.\n");
movie->frameAvail++;
PsychSignalCondition(&movie->condition);
PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
/* Not used by us, but needs to be defined as no-op anyway: */
/* // There are only 3 function pointers in GstAppSinkCallbacks now
static GstFlowReturn PsychNewBufferListCallback(GstAppSink *sink, gpointer user_data)
{
(void) sink, (void) user_data;
//PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
//PsychLockMutex(&movie->mutex);
//printf("PTB-DEBUG: New Bufferlist received.\n");
//PsychSignalCondition(&movie->condition);
//PsychUnlockMutex(&movie->mutex);
return(GST_FLOW_OK);
}
*/
/* Not used by us, but needs to be defined as no-op anyway: */
static void PsychDestroyNotifyCallback(gpointer user_data)
{
(void) user_data;
return;
}
/* This callback is called when the pipeline is about to finish playback
* of the current movie stream. If looped playback via method 0x2 is enabled,
* this needs to trigger a repetition by rescheduling the movie URI for playback.
*
* Allows gapless playback, but doesn't work reliable on all media types.
*
*/
static void PsychMovieAboutToFinishCB(GstElement *theMovie, gpointer user_data)
{
PsychMovieRecordType* movie = (PsychMovieRecordType*) user_data;
// Loop method 0x2 active?
if ((movie->loopflag & 0x2) && (movie->rate != 0)) {
g_object_set(G_OBJECT(theMovie), "uri", movie->movieLocation, NULL);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: About-to-finish received: Rewinding via uri method.\n");
}
return;
}
/* Not used, didn't work, but left here in case we find a use for it in the future. */
/*
static void PsychMessageErrorCB(GstBus *bus, GstMessage *msg)
{
gchar *debug;
GError *error;
(void) bus;
gst_message_parse_error (msg, &error, &debug);
g_free (debug);
printf("PTB-BUSERROR: %s\n", error->message);
g_error_free (error);
return;
}
*/
static GstAppSinkCallbacks videosinkCallbacks = {
PsychEOSCallback,
PsychNewPrerollCallback,
PsychNewBufferCallback,
{0}
};
/*
* PsychGSCreateMovie() -- Create a movie object.
*
* This function tries to open a moviefile (with or without audio/video tracks)
* and create an associated movie object for it.
*
* win = Pointer to window record of associated onscreen window.
* moviename = char* with the name of the moviefile.
* preloadSecs = How many seconds of the movie should be preloaded/prefetched into RAM at movie open time?
* moviehandle = handle to the new movie.
* asyncFlag = As passed to 'OpenMovie'
* specialFlags1 = As passed to 'OpenMovie'
* pixelFormat = As passed to 'OpenMovie'
* maxNumberThreads = Maximum number of decode threads to use (0 = auto, 1 = One, ...);
* movieOptions = Options string with additional options for movie playback.
*/
void PsychGSCreateMovie(PsychWindowRecordType *win, const char* moviename, double preloadSecs, int* moviehandle, int asyncFlag, int specialFlags1, int pixelFormat, int maxNumberThreads, char* movieOptions)
{
GValue item = G_VALUE_INIT;
GstCaps *colorcaps = NULL;
GstElement *theMovie = NULL;
GstElement *videocodec = NULL;
GstElement *videosink = NULL;
GstElement *audiosink;
gchar* pstring;
gint64 length_format;
GstPad *pad, *peerpad;
const GstCaps *caps;
GstStructure *str;
gint width,height;
gint rate1, rate2;
int i, slotid;
int max_video_threads;
char movieLocation[FILENAME_MAX];
psych_bool printErrors;
GstIterator *it;
psych_bool done;
GstPlayFlags playflags = 0;
psych_bool needCodecSetup = FALSE;
// Suppress output of error-messages if moviehandle == 1000. That means we
// run in our own Posix-Thread, not in the Matlab-Thread. Printing via Matlabs
// printing facilities would likely cause a terrible crash.
printErrors = (*moviehandle == -1000) ? FALSE : TRUE;
// Gapless playback requested? Normally *moviehandle is == -1, so a positive
// handle requests this mode and defines the actual handle of the movie to use:
if (*moviehandle >= 0) {
// Queueing a new moviename of a movie to play next: This only works
// for already opened/created movies whose pipeline is at least in
// READY state, better PAUSED or PLAYING. Validate preconditions:
// Valid handle for existing movie?
if (*moviehandle < 0 || *moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[*moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Ok, this means we have a handle to an existing, fully operational
// playback pipeline. Convert moviename to a valid URL and queue it:
// Create name-string for moviename: If an URI qualifier is at the beginning,
// we're fine and just pass the URI as-is. Otherwise we add the file:// URI prefix.
if (strstr(moviename, "://") || ((strstr(moviename, "v4l") == moviename) && strstr(moviename, "//"))) {
snprintf(movieLocation, sizeof(movieLocation)-1, "%s", moviename);
} else {
snprintf(movieLocation, sizeof(movieLocation)-1, "file:///%s", moviename);
}
strncpy(movieRecordBANK[*moviehandle].movieLocation, movieLocation, FILENAME_MAX);
strncpy(movieRecordBANK[*moviehandle].movieName, moviename, FILENAME_MAX);
// Assign name of movie to play to pipeline. If the pipeline is not in playing
// state, this will switch to the specified movieLocation immediately. If it
// is playing, it will switch to it at the end of the current playback iteration:
g_object_set(G_OBJECT(theMovie), "uri", movieLocation, NULL);
// Ready.
return;
}
// Set movie handle to "failed" initially:
*moviehandle = -1;
// We start GStreamer only on first invocation.
if (firsttime) {
// Initialize GStreamer: The routine is defined in PsychVideoCaptureSupportGStreamer.c
PsychGSCheckInit("movie playback");
firsttime = FALSE;
}
if (win && !PsychIsOnscreenWindow(win)) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Provided windowPtr is not an onscreen window.");
else
return;
}
// As a side effect of some PsychGSCheckInit() some broken GStreamer runtimes can change
// the OpenGL context binding behind our back to some GStreamer internal context.
// Make sure our own context is bound after return from PsychGSCheckInit() to protect
// against the state bleeding this would cause:
if (win) PsychSetGLContext(win);
if (NULL == moviename) {
if (printErrors)
PsychErrorExitMsg(PsychError_internal, "NULL-Ptr instead of moviename passed!");
else
return;
}
if (numMovieRecords >= PSYCH_MAX_MOVIES) {
*moviehandle = -2;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Allowed maximum number of simultaneously open movies exceeded!");
else
return;
}
// Search first free slot in movieRecordBANK:
for (i = 0; (i < PSYCH_MAX_MOVIES) && (movieRecordBANK[i].theMovie); i++);
if (i >= PSYCH_MAX_MOVIES) {
*moviehandle = -2;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Allowed maximum number of simultaneously open movies exceeded!");
else
return;
}
// Slot slotid will contain the movie record for our new movie object:
slotid=i;
// Zero-out new record in moviebank:
memset(&movieRecordBANK[slotid], 0, sizeof(PsychMovieRecordType));
// Store specialFlags1 from open call:
movieRecordBANK[slotid].specialFlags1 = specialFlags1;
// Create name-string for moviename: If an URI qualifier is at the beginning,
// we're fine and just pass the URI as-is. Otherwise we add the file:// URI prefix.
if (strstr(moviename, "://") || ((strstr(moviename, "v4l") == moviename) && strstr(moviename, "//"))) {
snprintf(movieLocation, sizeof(movieLocation)-1, "%s", moviename);
} else {
snprintf(movieLocation, sizeof(movieLocation)-1, "file:///%s", moviename);
}
strncpy(movieRecordBANK[slotid].movieLocation, movieLocation, FILENAME_MAX);
strncpy(movieRecordBANK[slotid].movieName, moviename, FILENAME_MAX);
// Create movie playback pipeline:
if (TRUE) {
// Use playbin:
theMovie = gst_element_factory_make("playbin", "ptbmovieplaybackpipeline");
movieRecordBANK[slotid].theMovie = theMovie;
if (theMovie == NULL) {
printf("PTB-ERROR: Failed to create GStreamer playbin element! Your GStreamer installation is\n");
printf("PTB-ERROR: incomplete or damaged and misses at least the gst-plugins-base set of plugins!\n");
if (printErrors)
PsychErrorExitMsg(PsychError_system, "Opening the movie failed. GStreamer configuration problem.");
else
return;
}
// Assign name of movie to play:
g_object_set(G_OBJECT(theMovie), "uri", movieLocation, NULL);
// Default flags for playbin: Decode video ...
playflags = GST_PLAY_FLAG_VIDEO;
// ... and deinterlace it if needed, unless prevented by specialFlags setting 256:
if (!(specialFlags1 & 256)) playflags|= GST_PLAY_FLAG_DEINTERLACE;
// Decode and play audio by default, with software audio volume control, unless specialFlags setting 2 enabled:
if (!(specialFlags1 & 2)) playflags |= GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_SOFT_VOLUME;
// Enable network buffering for network videos of at least 10 seconds, or preloadSecs seconds,
// whatever is bigger.
// Setup without any buffering and caching (aka preloadSecs == 0) requested?
// Note: For now treat the default preloadSecs value 1 as a zero -> No buffering and caching.
// Why? Because the usefulness of this extra setup is not yet proven and the specific choice
// of buffering parameters may need a bit of tuning. We don't want to cause regressions in
// performance of existing scripts, so we stick to the GStreamer default buffering behaviour
// until more time has been spent tuning & testing this setup code.
if ((preloadSecs != 0) && (preloadSecs != 1)) {
// No: Use internal buffering/caching [BUFFERING] of demultiplexed/parsed data, e.g., for fast
// recycling during looped video playback, random access out-of-order frame fetching, fast
// seeking and reverse playback:
playflags |= GST_PLAY_FLAG_BUFFERING;
// Ok, this is ugly: Some movie formats, when streamed from the internet, need progressive
// download buffering to work without problems, whereas other formats will cause problems
// with progressive download buffering. So far we know that some .mov Quicktime movies, e.g.,
// Apple's commercials need it, whereas some .webm movies choke on it. Let's be optimistic
// and assume it works with everything except .webm. Also provide secret cheat code == -2
// to override the blacklisting of .webm to allow for further experiments:
if ((preloadSecs == -2) || (!strstr(moviename, ".webm"))) {
// Want some local progressive download buffering [DOWNLOAD] for network video streams,
// as temporary file on local filesystem:
playflags |= GST_PLAY_FLAG_DOWNLOAD;
}
// Undo our cheat-code if used: Map to 10 seconds preload time:
if (preloadSecs == -2) preloadSecs = 10;
// Setting maximum size of internal RAM ringbuffer supported? (since v0.10.31)
if (g_object_class_find_property(G_OBJECT_GET_CLASS(theMovie), "ring-buffer-max-size")) {
// Supported. The ringbuffer is disabled by default, we enable it with a certain maximum
// size in bytes. For preloadSecs == -1, aka "unlimited buffering", we set it to its
// allowable maximum of G_MAXUINT == 4 GB. For a given finite preloadSecs we have
// to set something reasonable. Set it to preloadSecs buffer duration (in seconds) multiplied
// by some assumed maximum datarate in bytes/second. We use 4e6 bytes, which is roughly
// 4 MB/sec. Why? This is a generously padded value, assuming a max. fps of 60 Hz, max.
// resolution 1920x1080p HD video + HD audio. Numbers are based on the bit rates of
// a HD movie trailer (Warner Brothers "I am Legend" public HD movie trailer), which has
// 7887 kbits/s for 1920x816 H264/AVC progessive scan video at 24 fps and 258 kbits/s for
// MPEG-4 AAC audio in Surround 5.1 format with 48 kHz sampling rate. This upscaled to
// research use and padded should give a good value for our purpose. Also at a default
// preloadSecs value of 1 second, this wastes at most 4 MB for buffering - a safe default:
g_object_set(G_OBJECT(theMovie), "ring-buffer-max-size", ((preloadSecs == -1) ? G_MAXUINT : (guint64) (preloadSecs * (double) 4e6)), NULL);
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will use adapted RAM ring-buffer-max-size of %f MB.\n", slotid,
(float) (((double) ((preloadSecs == -1) ? G_MAXUINT : preloadSecs * (double) 4e6)) / 1024.0 / 1024.0));
}
}
// Setting of maximum buffer duration for network video stream playback:
if (preloadSecs == -1) {
// "Unlimited" - Set maximum buffering size to G_MAXINT == 2 GB.
g_object_set(G_OBJECT(theMovie), "buffer-size", (gint) G_MAXINT, NULL);
}
else {
// Limited - Set maximum buffer-duration to preloadSecs, the playbin will derive
// a proper maximum buffering size from duration and streaming bitrate:
g_object_set(G_OBJECT(theMovie), "buffer-duration", (gint64) (preloadSecs * (double) 1e9), NULL);
}
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will use RAM buffering. Additional prebuffering for network streams is\n", slotid);
printf("PTB-INFO: limited to %f %s.\n", (preloadSecs == -1) ? 2 : preloadSecs, (preloadSecs == -1) ? "GB" : "seconds");
if (playflags & GST_PLAY_FLAG_DOWNLOAD) printf("PTB-INFO: Network video streams will be additionally cached to the filesystem.\n");
}
// All in all, we can end up with up to 6*x GB RAM and 6 GB disc consumption for the "unlimited" setting,
// about 4*x MB RAM and 4 MB disc consumption for the default setting of 1, and preloadSecs multiples of
// that for a given value. x is an unkown factor, depending on which internal plugins maintain ringbuffers,
// but assume x somewhere between 1 and maybe 4.
}
else {
if (PsychPrefStateGet_Verbosity() > 4) {
printf("PTB-INFO: Playback for movie %i will not use additional buffering or caching due to 'preloadSecs' setting %i.\n", slotid, (int) preloadSecs);
}
}
// Setup final playback control flags:
g_object_set(G_OBJECT(theMovie), "flags", playflags , NULL);
// Connect callback to about-to-finish signal: Signal is emitted as soon as
// end of current playback iteration is approaching. The callback checks if
// looped playback is requested. If so, it schedules a new playback iteration.
g_signal_connect(G_OBJECT(theMovie), "about-to-finish", G_CALLBACK(PsychMovieAboutToFinishCB), &(movieRecordBANK[slotid]));
}
else {
// Self-Assembled pipeline: Does not work for some not yet investigated reason,
// but is not needed anyway, so we disable it and just leave it for documentation,
// in case it will be needed in the future:
sprintf(movieLocation, "filesrc location='%s' ! qtdemux ! queue ! ffdec_h264 ! ffmpegcolorspace ! appsink name=ptbsink0", moviename);
theMovie = gst_parse_launch((const gchar*) movieLocation, NULL);
movieRecordBANK[slotid].theMovie = theMovie;
videosink = gst_bin_get_by_name(GST_BIN(theMovie), "ptbsink0");
printf("LAUNCHLINE[%p]: %s\n", videosink, movieLocation);
}
// Assign a fakesink named "ptbsink0" as destination video-sink for
// all video content. This allows us to get hold of the video frame buffers for
// converting them into PTB OpenGL textures:
if (!videosink)
videosink = gst_element_factory_make ("appsink", "ptbsink0");
if (!videosink) {
printf("PTB-ERROR: Failed to create video-sink appsink ptbsink! Your GStreamer installation is\n");
printf("PTB-ERROR: incomplete or damaged and misses at least the gst-plugins-base set of plugins!\n");
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_system, "Opening the movie failed. Reason hopefully given above.");
else
return;
}
movieRecordBANK[slotid].videosink = videosink;
// Setting flag 1 in specialFlags1 is equivalent to setting pixelFormat == 5, to retain
// backwards compatibility to previous ptb releases:
if (specialFlags1 & 0x1) pixelFormat = 5;
// Assign initial pixelFormat to use, as requested by usercode:
movieRecordBANK[slotid].pixelFormat = pixelFormat;
// Default to 8 bpc bitdepth as a starter:
movieRecordBANK[slotid].bitdepth = 8;
// Our OpenGL texture creation routine usually needs GL_BGRA8 data in G_UNSIGNED_8_8_8_8_REV
// format, but the pipeline usually delivers YUV data in planar format. Therefore
// need to perform colorspace/colorformat conversion. We build a little videobin
// which consists of a ffmpegcolorspace converter plugin connected to our appsink
// plugin which will deliver video data to us for conversion into textures.
// The "sink" pad of the converter plugin is connected as the "sink" pad of our
// videobin, and the videobin is connected to the video-sink output of the pipeline,
// thereby receiving decoded video data. We place a videocaps filter inbetween the
// converter and the appsink to enforce a color format conversion to the "colorcaps"
// we need. colorcaps define the needed data format for efficient conversion into
// a RGBA8 texture. Some GPU + driver combos do support direct handling of UYVU YCrCb 4:2:2
// packed pixel data as textures. If we are on such a GPU we request UYVY data and upload it
// directly in this format to the GPU. This more efficient both for the GStreamers decode
// pipeline, and the later Videobuffer -> OpenGL texture conversion:
if (win && (win->gfxcaps & kPsychGfxCapUYVYTexture) && (movieRecordBANK[slotid].pixelFormat == 5)) {
// GPU supports handling and decoding of UYVY type yuv textures: We use these,
// as they are more efficient to decode and handle by typical video codecs:
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "UYVY",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use UYVY YCrCb 4:2:2 textures for optimized decode and rendering.\n", slotid);
}
else if ((movieRecordBANK[slotid].pixelFormat == 6) && win && (win->gfxcaps & kPsychGfxCapFBO) && PsychAssignPlanarI420TextureShader(NULL, win)) {
// Usercode wants YUV I420 planar encoded format and GPU suppports needed fragment shaders and FBO's.
// Ask for I420 decoded video. This is the native output format of HuffYUV and H264 codecs, so using it
// allows to skip colorspace conversion in GStreamer. The format is also highly efficient for texture
// creation and upload to the GPU, but requires a fragment shader for colorspace conversion during drawing:
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, "I420",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use YUV-I420 planar textures for optimized decode and rendering.\n", slotid);
}
else if (((movieRecordBANK[slotid].pixelFormat == 7) || (movieRecordBANK[slotid].pixelFormat == 8)) && win && (win->gfxcaps & kPsychGfxCapFBO) && PsychAssignPlanarI800TextureShader(NULL, win)) {
// Usercode wants Y8/Y800 planar encoded format and GPU suppports needed fragment shaders and FBO's.
// Ask for I420 or Y800 decoded video. I420 is the native output format of HuffYUV and H264 codecs, so using it
// allows to skip colorspace conversion in GStreamer. The format is also highly efficient for texture
// creation and upload to the GPU, but requires a fragment shader for colorspace conversion during drawing:
// Note: The FOURCC 'Y800' is equivalent to 'Y8 ' and 'GREY' as far as we know. As of June 2012, using the
// Y800 decoding doesn't have any performance benefits compared to I420 decoding, actually performance is a
// little bit lower. Apparently the video codecs don't take the Y800 format into account, ie., they don't skip
// decoding of the chroma components, instead they probably decode as usual and the colorspace conversion then
// throws away the unwanted chroma planes, causing possible extra overhead for discarding this data. We leave
// the option in anyway, because there may be codecs (possibly in future GStreamer versions) that can take
// advantage of Y800 format for higher performance.
colorcaps = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING,
(movieRecordBANK[slotid].pixelFormat == 8) ? "Y800" : "I420",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use Y8-I800 planar textures for optimized decode and rendering.\n", slotid);
}
else {
// GPU does not support yuv textures or shader based decoding. Need to go brute-force and convert
// video into RGBA8 format:
// Force unsupportable formats to RGBA8 aka format 4, except for formats 7/8, which map
// to 1 == L8, and map 2 == LA8 to 1 == L8:
switch (movieRecordBANK[slotid].pixelFormat) {
case 1: // 1 is fine.
break;
case 3: // 3 is handled after switch-case.
break;
case 4: // 4 is fine.
break;
case 2:
case 7:
case 8:
movieRecordBANK[slotid].pixelFormat = 1;
break;
case 5:
case 6:
movieRecordBANK[slotid].pixelFormat = 4;
break;
case 9: // 9 and 10 are fine:
case 10:
break;
default:
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Invalid 'pixelFormat' parameter specified!");
else
// Revert to something safe, RGBA8, as we can not error abort here:
movieRecordBANK[slotid].pixelFormat = 4;
break;
}
// Map 3 == RGB8 to 4 == RGBA8, unless it is our special proprietary 16 bpc encoding:
if ((movieRecordBANK[slotid].pixelFormat == 3) && !(specialFlags1 & 512)) movieRecordBANK[slotid].pixelFormat = 4;
// At this point we can have any of these pixelFormats: 1, 3, 4, 9, 10. Handle them:
if (movieRecordBANK[slotid].pixelFormat == 4) {
// Use RGBA8 format:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "BGRA",
NULL);
if ((PsychPrefStateGet_Verbosity() > 3) && (pixelFormat == 5)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures due to lack of YUV-422 texture support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && (pixelFormat == 6)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures due to lack of YUV-I420 support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && ((pixelFormat == 7) || (pixelFormat == 8))) printf("PTB-INFO: Movie playback for movie %i will use L8 textures due to lack of Y8-I800 support on GPU.\n", slotid);
if ((PsychPrefStateGet_Verbosity() > 3) && !(pixelFormat < 5)) printf("PTB-INFO: Movie playback for movie %i will use RGBA8 textures.\n", slotid);
}
if ((movieRecordBANK[slotid].pixelFormat == 1) && !(specialFlags1 & 512)) {
// Use LUMINANCE8 format:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "GRAY8",
NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use L8 luminance textures.\n", slotid);
}
// Psychtoolbox proprietary 16 bpc pixelformat for 1 or 3 channel data?
if ((pixelFormat == 1 || pixelFormat == 3) && (specialFlags1 & 512)) {
// Yes. Need to always decode as RGB8 24 bpp: Texture creation will then handle this further.
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "RGB",
NULL);
movieRecordBANK[slotid].pixelFormat = pixelFormat;
}
if (movieRecordBANK[slotid].pixelFormat == 9) {
// Use GRAY 16 bpc format for 16 bpc decoding:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "GRAY16_LE",
NULL);
// Switch to 16 bpc bitdepth and single channel pixelFormat:
movieRecordBANK[slotid].bitdepth = 16;
movieRecordBANK[slotid].pixelFormat = 1;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use 16 bpc LUMINANCE 16 float textures.\n", slotid);
}
if (movieRecordBANK[slotid].pixelFormat == 10) {
// Use ARGB64 16 bpc per color channel format for 16 bpc decoding:
colorcaps = gst_caps_new_simple("video/x-raw",
"format", G_TYPE_STRING, "ARGB64",
NULL);
// Switch to 16 bpc bitdepth and 4-channel RGBA pixelFormat:
movieRecordBANK[slotid].bitdepth = 16;
movieRecordBANK[slotid].pixelFormat = 4;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Movie playback for movie %i will use 16 bpc RGBA 16 bpc float textures.\n", slotid);
}
}
// Assign 'colorcaps' as caps to our videosink. This marks the videosink so
// that it can only receive video image data in the format defined by colorcaps,
// i.e., a format that is easy to consume for OpenGL's texture creation on std.
// gpu's. It is the job of the video pipeline's autoplugger to plug in proper
// color & format conversion plugins to satisfy videosink's needs.
gst_app_sink_set_caps(GST_APP_SINK(videosink), colorcaps);
// Assign our special appsink 'videosink' as video-sink of the pipeline:
g_object_set(G_OBJECT(theMovie), "video-sink", videosink, NULL);
gst_caps_unref(colorcaps);
// Get the pad from the final sink for probing width x height of movie frames and nominal framerate of movie:
pad = gst_element_get_static_pad(videosink, "sink");
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), FALSE);
// Attach custom made audio sink?
if ((pstring = strstr(movieOptions, "AudioSink="))) {
pstring += strlen("AudioSink=");
pstring = strdup(pstring);
if (strstr(pstring, ":::") != NULL) *(strstr(pstring, ":::")) = 0;
audiosink = gst_parse_bin_from_description((const gchar *) pstring, TRUE, NULL);
if (audiosink) {
g_object_set(G_OBJECT(theMovie), "audio-sink", audiosink, NULL);
audiosink = NULL;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Attached custom audio sink for playback of movie. Spec: '%s'\n", pstring);
free(pstring); pstring = NULL;
}
else {
printf("PTB-ERROR: Could not create requested audio sink for playback of movie! Failing sink spec was: '%s'\n", pstring);
free(pstring); pstring = NULL;
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Failed to create custom audio sink for movie playback.");
else
return;
}
}
// Preload / Preroll the pipeline:
if (!PsychMoviePipelineSetState(theMovie, GST_STATE_PAUSED, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed I. Reason given above.");
else
return;
}
// Set video decoder parameters:
// First we try to find the video decoder plugin in the media graph. We iterate over all
// elements and try to find one whose properties match known properties of video codecs:
// Note: The typeid/name or classid/name proved useless for finding the video codec, as
// the video codecs are not derived from some "video codec class", but each codec defines
// its own type and class.
it = gst_bin_iterate_recurse(GST_BIN(theMovie));
done = FALSE;
videocodec = NULL;
while (!done) {
switch (gst_iterator_next(it, &item)) {
case GST_ITERATOR_OK:
videocodec = g_value_peek_pointer(&item);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: In pipeline: Child element name: %s\n", (const char*) gst_object_get_name(GST_OBJECT(videocodec)));
// Our current match critera for video codecs: Having at least one of the properties "max-threads" or "lowres":
if ((g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "lowres")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv")) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame"))) {
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Found video decoder element %s.\n", (const char*) gst_object_get_name(GST_OBJECT(videocodec)));
done = TRUE;
} else {
videocodec = NULL;
g_value_reset(&item);
}
break;
case GST_ITERATOR_RESYNC:
gst_iterator_resync(it);
break;
case GST_ITERATOR_DONE:
done = TRUE;
break;
default:
videocodec = NULL;
}
}
g_value_unset(&item);
gst_iterator_free(it);
it = NULL;
// Check if some codec properties need to be changed.
// This happens if usercode provides some supported non-default override parameter for the codec,
// or if the codec is multi-threaded and usercode wants us to configure its multi-threading behaviour:
needCodecSetup = FALSE;
if (videocodec && ((g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads") && (maxNumberThreads > -1)) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "lowres") && (specialFlags1 & (0))) || /* MK: 'lowres' disabled for now. */
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv") && (specialFlags1 & 4)) ||
(g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame") && (specialFlags1 & 8))
)) {
needCodecSetup = TRUE;
}
// Set videocodec state to "ready" if parameter change is needed, as the codec only
// accepts the new settings in that state:
if (needCodecSetup) {
// Ready the video codec, so a new max thread count or other parameters can be set:
if (!PsychMoviePipelineSetState(videocodec, GST_STATE_READY, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed III. Reason given above.");
else
return;
}
}
// Drawing of motion vectors requested by usercode specialflags1 flag 4? If so, enable it:
if (needCodecSetup && (specialFlags1 & 4) && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "debug-mv"))) {
g_object_set(G_OBJECT(videocodec), "debug-mv", 1, NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Playback for movie %i will display motion vectors for visualizaton of optic flow.\n", slotid);
}
// Skipping of B-Frames video decoding requested by usercode specialflags1 flag 8? If so, enable skipping:
if (needCodecSetup && (specialFlags1 & 8) && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "skip-frame"))) {
g_object_set(G_OBJECT(videocodec), "skip-frame", 1, NULL);
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Playback for movie %i will skip B-Frames during video decoding for higher speed.\n", slotid);
}
// Multi-threaded codec and usercode requests setup? If so, set its multi-threading behaviour:
// By default many codecs would only use one single thread on any system, even if they are multi-threading capable.
if (needCodecSetup && (g_object_class_find_property(G_OBJECT_GET_CLASS(videocodec), "max-threads")) && (maxNumberThreads > -1)) {
max_video_threads = 1;
g_object_get(G_OBJECT(videocodec), "max-threads", &max_video_threads, NULL);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-INFO: Movie playback for movie %i uses video decoder with a default maximum number of %i processing threads.\n", slotid, max_video_threads);
// Specific number of threads requested, or zero for auto-select?
if (maxNumberThreads > 0) {
// Specific value provided: Use it.
max_video_threads = maxNumberThreads;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Setting video decoder to use a maximum of %i processing threads.\n", max_video_threads);
} else {
// Default behaviour: A settig of zero asks GStreamer to auto-detect the optimal
// setting for the given host computer -- typically number of threads == number of processor cores:
max_video_threads = 0;
if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-INFO: Setting video decoder to use auto-selected optimal number of processing threads.\n");
}
// Assign new setting:
g_object_set(G_OBJECT(videocodec), "max-threads", max_video_threads, NULL);
// Requery:
g_object_get(G_OBJECT(videocodec), "max-threads", &max_video_threads, NULL);
if (PsychPrefStateGet_Verbosity() > 4) {
if (max_video_threads != 0) {
printf("PTB-INFO: Movie playback for movie %i uses video decoder with a current maximum number of %i processing threads.\n", slotid, max_video_threads);
} else {
printf("PTB-INFO: Movie playback for movie %i uses video decoder with a current auto-detected optimal number of processing threads.\n", slotid);
}
}
}
// Bring codec back to paused state, so it is ready to do its job with the
// new codec parameters set:
if (needCodecSetup) {
// Pause the video codec, so the new max thread count is accepted:
if (!PsychMoviePipelineSetState(videocodec, GST_STATE_PAUSED, 30.0)) {
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), TRUE);
if (printErrors)
PsychErrorExitMsg(PsychError_user, "In OpenMovie: Opening the movie failed IV. Reason given above.");
else
return;
}
}
// NULL out videocodec, we must not unref it, as we didn't aquire or own private ref:
videocodec = NULL;
// Query number of available video and audio tracks in movie:
g_object_get (G_OBJECT(theMovie),
"n-video", &movieRecordBANK[slotid].nrVideoTracks,
"n-audio", &movieRecordBANK[slotid].nrAudioTracks,
NULL);
// We need a valid onscreen window handle for real video playback:
if ((NULL == win) && (movieRecordBANK[slotid].nrVideoTracks > 0)) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "No windowPtr to an onscreen window provided. Must do so for movies with videotrack!");
else
return;
}
PsychGSProcessMovieContext(&(movieRecordBANK[slotid]), FALSE);
PsychInitMutex(&movieRecordBANK[slotid].mutex);
PsychInitCondition(&movieRecordBANK[slotid].condition, NULL);
// Install callbacks used by the videosink (appsink) to announce various events:
gst_app_sink_set_callbacks(GST_APP_SINK(videosink), &videosinkCallbacks, &(movieRecordBANK[slotid]), PsychDestroyNotifyCallback);
// Assign harmless initial settings for fps and frame size:
rate1 = 0;
rate2 = 1;
width = height = 0;
// Videotrack available?
if (movieRecordBANK[slotid].nrVideoTracks > 0) {
// Yes: Query size and framerate of movie:
peerpad = gst_pad_get_peer(pad);
caps=gst_pad_get_current_caps(peerpad);
if (caps) {
str=gst_caps_get_structure(caps,0);
/* Get some data about the frame */
rate1 = 1; rate2 = 1;
gst_structure_get_fraction(str, "pixel-aspect-ratio", &rate1, &rate2);
movieRecordBANK[slotid].aspectRatio = (double) rate1 / (double) rate2;
gst_structure_get_int(str,"width",&width);
gst_structure_get_int(str,"height",&height);
rate1 = 0; rate2 = 1;
gst_structure_get_fraction(str, "framerate", &rate1, &rate2);
} else {
printf("PTB-DEBUG: No frame info available after preroll.\n");
}
}
if (strstr(moviename, "v4l2:")) {
// Special case: The "movie" is actually a video4linux2 live source.
// Need to make parameters up for now, so it to work as "movie":
rate1 = 30; width = 640; height = 480;
movieRecordBANK[slotid].nrVideoTracks = 1;
// Uglyness at its best ;-)
if (strstr(moviename, "320")) { width = 320; height = 240; };
}
// Release the pad:
gst_object_unref(pad);
// Assign new record in moviebank:
movieRecordBANK[slotid].theMovie = theMovie;
movieRecordBANK[slotid].loopflag = 0;
movieRecordBANK[slotid].frameAvail = 0;
movieRecordBANK[slotid].imageBuffer = NULL;
movieRecordBANK[slotid].startPending = 0;
movieRecordBANK[slotid].endOfFetch = 0;
*moviehandle = slotid;
// Increase counter:
numMovieRecords++;
// Compute basic movie properties - Duration and fps as well as image size:
// Retrieve duration in seconds:
if (gst_element_query_duration(theMovie, GST_FORMAT_TIME, &length_format)) {
// This returns nsecs, so convert to seconds:
movieRecordBANK[slotid].movieduration = (double) length_format / (double) 1e9;
//printf("PTB-DEBUG: Duration of movie %i [%s] is %lf seconds.\n", slotid, moviename, movieRecordBANK[slotid].movieduration);
} else {
movieRecordBANK[slotid].movieduration = DBL_MAX;
printf("PTB-WARNING: Could not query duration of movie %i [%s] in seconds. Returning infinity.\n", slotid, moviename);
}
// Assign expected framerate, assuming a linear spacing between frames:
movieRecordBANK[slotid].fps = (double) rate1 / (double) rate2;
//printf("PTB-DEBUG: Framerate fps of movie %i [%s] is %lf fps.\n", slotid, moviename, movieRecordBANK[slotid].fps);
// Drop frames if callback can't pull buffers fast enough, unless ascynFlags & 4 is set:
// This together with a max queue lengths of 1 allows to
// maintain audio-video sync by framedropping if needed.
gst_app_sink_set_drop(GST_APP_SINK(videosink), (asyncFlag & 4) ? FALSE : TRUE);
// Buffering of decoded video frames requested?
if (asyncFlag & 4) {
// Yes: If a specific preloadSecs and a valid fps playback framerate is available, we
// set the maximum buffer capacity to the number of frames corresponding to the given 'preloadSecs'.
// Otherwise we set it to zero, which means "unlimited capacity", ie., until RAM full:
gst_app_sink_set_max_buffers(GST_APP_SINK(videosink),
((movieRecordBANK[slotid].fps > 0) && (preloadSecs >= 0)) ? ((int) (movieRecordBANK[slotid].fps * preloadSecs) + 1) : 0);
}
else {
// No: Only allow one queued buffer before dropping, to avoid optimal audio-video sync:
gst_app_sink_set_max_buffers(GST_APP_SINK(videosink), 1);
}
// Compute framecount from fps and duration:
movieRecordBANK[slotid].nrframes = (int)(movieRecordBANK[slotid].fps * movieRecordBANK[slotid].movieduration + 0.5);
//printf("PTB-DEBUG: Number of frames in movie %i [%s] is %i.\n", slotid, moviename, movieRecordBANK[slotid].nrframes);
// Is this movie supposed to be encoded in Psychtoolbox special proprietary "16 bpc stuffed into 8 bpc" format?
if (specialFlags1 & 512) {
// Yes. Invert the hacks applied during encoding/writing of movie:
// Only 1 layer and 3 layer are supported:
if (pixelFormat != 1 && pixelFormat !=3) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "You specified 'specialFlags1' setting 512 for Psychtoolbox proprietary 16 bpc decoding, but pixelFormat is not 1 or 3 as required for this decoding method!");
else
return;
}
// Set bitdepth of movie to 16 bpc for later texture creation from decoded video frames:
movieRecordBANK[slotid].bitdepth = 16;
// 1-layer: 1 bpc 16 gray pixel stored in 2/3 RGB8 pixel. This was achieved by multiplying
// height by 2/3 in encoding, so invert by multiplying with 3/2:
if (pixelFormat == 1) height = height * 3 / 2;
// 3-layer: 1 RGB16 pixel stored in two adjacent RGB8 pixels. This was achieved by doubling
// width, so undo by dividing width by 2:
if (pixelFormat == 3) width = width / 2;
if (PsychPrefStateGet_Verbosity() > 2) printf("PTB-INFO: Playing back movie in Psychtoolbox proprietary 16 bpc %i channel encoding.\n", pixelFormat);
}
// Make sure the input format for raw Bayer sensor data is actually 1 layer grayscale, and that PTB for this OS supports debayering:
if (specialFlags1 & 1024) {
if (movieRecordBANK[slotid].pixelFormat != 1) {
if (printErrors)
PsychErrorExitMsg(PsychError_user, "specialFlags1 & 1024 set to indicate this movie consists of raw Bayer sensor data, but pixelFormat is not == 1, as required!");
else
return;
}
// Abort early if libdc1394 support is not available on this configuration:
#ifndef PTBVIDEOCAPTURE_LIBDC
if (printErrors)
PsychErrorExitMsg(PsychError_user, "Sorry, Bayer filtering of video frames, as requested by specialFlags1 setting & 1024, is not supported on this operating system.");
else
return;
#endif
}
// Define size of images in movie:
movieRecordBANK[slotid].width = width;
movieRecordBANK[slotid].height = height;
// Assign parent window record, for use in movie deletion code:
movieRecordBANK[slotid].parentRecord = win;
// Should we dump the whole decoding pipeline graph to a file for visualization
// with GraphViz? This can be controlled via PsychTweak('GStreamerDumpFilterGraph' dirname);
if (getenv("GST_DEBUG_DUMP_DOT_DIR")) {
// Dump complete decoding filter graph to a .dot file for later visualization with GraphViz:
printf("PTB-DEBUG: Dumping movie decoder graph for movie %s to directory %s.\n", moviename, getenv("GST_DEBUG_DUMP_DOT_DIR"));
GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS(GST_BIN(movieRecordBANK[slotid].theMovie), GST_DEBUG_GRAPH_SHOW_ALL, "PsychMoviePlaybackGraph");
}
// Ready to rock!
return;
}
/*
* PsychGSGetMovieInfos() - Return basic information about a movie.
*
* framecount = Total number of video frames in the movie, determined by counting.
* durationsecs = Total playback duration of the movie, in seconds.
* framerate = Estimated video playback framerate in frames per second (fps).
* width = Width of movie images in pixels.
* height = Height of movie images in pixels.
* nrdroppedframes = Total count of videoframes that had to be dropped during last movie playback,
* in order to keep the movie synced with the realtime clock.
*/
void PsychGSGetMovieInfos(int moviehandle, int* width, int* height, int* framecount, double* durationsecs, double* framerate, int* nrdroppedframes, double* aspectRatio)
{
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
if (movieRecordBANK[moviehandle].theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
if (framecount) *framecount = movieRecordBANK[moviehandle].nrframes;
if (durationsecs) *durationsecs = movieRecordBANK[moviehandle].movieduration;
if (framerate) *framerate = movieRecordBANK[moviehandle].fps;
if (nrdroppedframes) *nrdroppedframes = movieRecordBANK[moviehandle].nr_droppedframes;
if (width) *width = movieRecordBANK[moviehandle].width;
if (height) *height = movieRecordBANK[moviehandle].height;
if (aspectRatio) *aspectRatio = movieRecordBANK[moviehandle].aspectRatio;
return;
}
/*
* PsychGSDeleteMovie() -- Delete a movie object and release all associated ressources.
*/
void PsychGSDeleteMovie(int moviehandle)
{
PsychWindowRecordType **windowRecordArray;
int i, numWindows;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
if (movieRecordBANK[moviehandle].theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Stop movie playback immediately:
PsychMoviePipelineSetState(movieRecordBANK[moviehandle].theMovie, GST_STATE_NULL, 20.0);
// Delete movieobject for this handle:
gst_object_unref(GST_OBJECT(movieRecordBANK[moviehandle].theMovie));
movieRecordBANK[moviehandle].theMovie=NULL;
// Delete visual context for this movie:
movieRecordBANK[moviehandle].MovieContext = NULL;
PsychDestroyMutex(&movieRecordBANK[moviehandle].mutex);
PsychDestroyCondition(&movieRecordBANK[moviehandle].condition);
free(movieRecordBANK[moviehandle].imageBuffer);
movieRecordBANK[moviehandle].imageBuffer = NULL;
movieRecordBANK[moviehandle].videosink = NULL;
// Recycled texture in texture cache?
if ((movieRecordBANK[moviehandle].parentRecord) && (movieRecordBANK[moviehandle].cached_texture > 0)) {
// Yes. Release it.
PsychSetGLContext(movieRecordBANK[moviehandle].parentRecord);
glDeleteTextures(1, &(movieRecordBANK[moviehandle].cached_texture));
movieRecordBANK[moviehandle].cached_texture = 0;
}
// Delete all references to us in textures originally originating from us:
PsychCreateVolatileWindowRecordPointerList(&numWindows, &windowRecordArray);
for(i = 0; i < numWindows; i++) {
if ((windowRecordArray[i]->windowType == kPsychTexture) && (windowRecordArray[i]->texturecache_slot == moviehandle)) {
// This one is referencing us. Reset its reference to "undefined" to detach it from us:
windowRecordArray[i]->texturecache_slot = -1;
}
}
PsychDestroyVolatileWindowRecordPointerList(windowRecordArray);
// Decrease counter:
if (numMovieRecords>0) numMovieRecords--;
return;
}
/*
* PsychGSDeleteAllMovies() -- Delete all movie objects and release all associated ressources.
*/
void PsychGSDeleteAllMovies(void)
{
int i;
for (i=0; i<PSYCH_MAX_MOVIES; i++) {
if (movieRecordBANK[i].theMovie) PsychGSDeleteMovie(i);
}
return;
}
/*
* PsychGSGetTextureFromMovie() -- Create an OpenGL texture map from a specific videoframe from given movie object.
*
* win = Window pointer of onscreen window for which a OpenGL texture should be created.
* moviehandle = Handle to the movie object.
* checkForImage = 0 == Retrieve the image, blocking until error timeout if necessary.
* 1 == Check for new image in polling fashion.
* 2 == Check for new image in blocking fashion. Wait up to 5 seconds blocking for a new frame.
* timeindex = When not in playback mode, this allows specification of a requested frame by presentation time.
* If set to -1, or if in realtime playback mode, this parameter is ignored and the next video frame is returned.
* out_texture = Pointer to the Psychtoolbox texture-record where the new texture should be stored.
* presentation_timestamp = A ptr to a double variable, where the presentation timestamp of the returned frame should be stored.
*
* Returns true (1) on success, false (0) if no new image available, -1 if no new image available and there won't be any in future.
*/
int PsychGSGetTextureFromMovie(PsychWindowRecordType *win, int moviehandle, int checkForImage, double timeindex,
PsychWindowRecordType *out_texture, double *presentation_timestamp)
{
GstElement *theMovie;
double rate;
double targetdelta, realdelta, frames;
GstBuffer *videoBuffer = NULL;
GstSample *videoSample = NULL;
gint64 bufferIndex;
double deltaT = 0;
GstEvent *event;
static double tStart = 0;
double tNow;
double preT, postT;
unsigned char* releaseMemPtr = NULL;
#if PSYCH_SYSTEM == PSYCH_WINDOWS
#pragma warning( disable : 4068 )
#endif
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
GstMapInfo mapinfo = GST_MAP_INFO_INIT;
#pragma GCC diagnostic pop
if (!PsychIsOnscreenWindow(win)) {
PsychErrorExitMsg(PsychError_user, "Need onscreen window ptr!!!");
}
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided.");
}
if ((timeindex!=-1) && (timeindex < 0 || timeindex >= 100000.0)) {
PsychErrorExitMsg(PsychError_user, "Invalid timeindex provided.");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle.");
}
// Deferred start of movie playback requested? This so if movie is supposed to be
// actively playing (rate != 0) and the startPending flag marks a pending deferred start:
if ((movieRecordBANK[moviehandle].rate != 0) && movieRecordBANK[moviehandle].startPending) {
// Deferred start: Reset flag, start pipeline with a max timeout of 1 second:
movieRecordBANK[moviehandle].startPending = 0;
PsychMoviePipelineSetState(theMovie, GST_STATE_PLAYING, 1);
// This point is reached after either the pipeline is fully started, or the
// timeout has elapsed. In the latter case, a GST_STATE_CHANGE_ASYNC message
// is printed and start of pipeline continues asynchronously. No big deal for
// us, as we'll simply block in the rest of the texture fetch (checkForImage) path
// until the first frame is ready and audio playback has started. The main purpose
// of setting a reasonable timeout above is to avoid cluttering the console with
// status messages (timeout big enough for common case) but allow user to interrupt
// ops that take too long (timeout small enough to avoid long user-perceived exec-hangs).
// 1 Second is used to cater to the common case of playing files from disc, but coping
// with multi-second delays for network streaming (buffering delays in preroll).
}
// Allow context task to do its internal bookkeeping and cleanup work:
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// If this is a pure audio "movie" with no video tracks, we always return failed,
// as those certainly don't have movie frames associated.
if (movieRecordBANK[moviehandle].nrVideoTracks == 0) return((checkForImage) ? -1 : FALSE);
// Get current playback rate:
rate = movieRecordBANK[moviehandle].rate;
// Is movie actively playing (automatic async playback, possibly with synced sound)?
// If so, then we ignore the 'timeindex' parameter, because the automatic playback
// process determines which frames should be delivered to PTB when. This function will
// simply wait or poll for arrival/presence of a new frame that hasn't been fetched
// in previous calls.
if (0 == rate) {
// Movie playback inactive. We are in "manual" mode: No automatic async playback,
// no synced audio output. The user just wants to manually fetch movie frames into
// textures for manual playback in a standard Matlab-loop.
// First pass - checking for new image?
if (checkForImage) {
// Image for specific point in time requested?
if (timeindex >= 0) {
// Yes. We try to retrieve the next possible image for requested timeindex.
// Seek to target timeindex:
PsychGSSetMovieTimeIndex(moviehandle, timeindex, FALSE);
}
// Check for frame availability happens down there in the shared check code...
}
}
// Should we just check for new image? If so, just return availability status:
if (checkForImage) {
// Take reference timestamps of fetch start:
if (tStart == 0) PsychGetAdjustedPrecisionTimerSeconds(&tStart);
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
if ((((0 != rate) && movieRecordBANK[moviehandle].frameAvail) || ((0 == rate) && movieRecordBANK[moviehandle].preRollAvail)) &&
!gst_app_sink_is_eos(GST_APP_SINK(movieRecordBANK[moviehandle].videosink))) {
// New frame available. Unlock and report success:
//printf("PTB-DEBUG: NEW FRAME %d\n", movieRecordBANK[moviehandle].frameAvail);
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(TRUE);
}
// None available. Any chance there will be one in the future?
if (((rate != 0) && gst_app_sink_is_eos(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) && (movieRecordBANK[moviehandle].loopflag == 0)) ||
((rate == 0) && (movieRecordBANK[moviehandle].endOfFetch))) {
// No new frame available and there won't be any in the future, because this is a non-looping
// movie that has reached its end.
movieRecordBANK[moviehandle].endOfFetch = 0;
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(-1);
}
else {
// No new frame available yet:
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// In the polling check, we return with statue "no new frame yet" aka false:
if (checkForImage < 2) return(FALSE);
// Otherwise (blocking/waiting check) we fall-through the wait code below...
}
}
// If we reach this point, then an image fetch is requested. If no new data
// is available we shall block:
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
// printf("PTB-DEBUG: Blocking fetch start %d\n", movieRecordBANK[moviehandle].frameAvail);
if (((0 != rate) && !movieRecordBANK[moviehandle].frameAvail) ||
((0 == rate) && !movieRecordBANK[moviehandle].preRollAvail)) {
// No new frame available. Perform a blocking wait with timeout of 0.5 seconds:
PsychTimedWaitCondition(&movieRecordBANK[moviehandle].condition, &movieRecordBANK[moviehandle].mutex, 0.5);
// Allow context task to do its internal bookkeeping and cleanup work:
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// Recheck:
if (((0 != rate) && !movieRecordBANK[moviehandle].frameAvail) ||
((0 == rate) && !movieRecordBANK[moviehandle].preRollAvail)) {
// Wait timed out after 0.5 secs.
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: No frame received after timed blocking wait of 0.5 seconds.\n");
// This is the end of a "up to 0.5 seconds blocking wait" style checkForImage of type 2.
// Return "no new frame available yet". The calling code will retry the wait until its own
// higher master timeout value is reached:
return(FALSE);
}
// At this point we should have at least one frame available.
// printf("PTB-DEBUG: After blocking fetch start %d\n", movieRecordBANK[moviehandle].frameAvail);
}
// We're here with at least one frame available and the mutex lock held.
// Was this a pure "blocking check for new image"?
if (checkForImage) {
// Yes. Unlock mutex and signal success to caller - A new frame is ready.
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
return(TRUE);
}
// If we reach this point, then at least 1 frame should be available and we are
// asked to fetch it now and return it as a new OpenGL texture. The mutex is locked:
// Preroll case is simple:
movieRecordBANK[moviehandle].preRollAvail = 0;
// Perform texture fetch & creation:
// Active playback mode?
if (0 != rate) {
// Active playback mode:
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: Pulling buffer from videosink, %d buffers decoded and queued.\n", movieRecordBANK[moviehandle].frameAvail);
// Clamp frameAvail to maximum queue capacity, unless queue capacity is zero == "unlimited" capacity:
if (((int) gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) < movieRecordBANK[moviehandle].frameAvail) &&
(gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink)) > 0)) {
movieRecordBANK[moviehandle].frameAvail = (int) gst_app_sink_get_max_buffers(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
}
// One less frame available after our fetch:
movieRecordBANK[moviehandle].frameAvail--;
// We can unlock early, thanks to videosink's internal buffering: XXX FIXME: Perfectly race-free to do this before the pull?
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// This will pull the oldest video buffer from the videosink. It would block if none were available,
// but that won't happen as we wouldn't reach this statement if none were available. It would return
// NULL if the stream would be EOS or the pipeline off, but that shouldn't ever happen:
videoSample = gst_app_sink_pull_sample(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
} else {
// Passive fetch mode: Use prerolled buffers after seek:
// These are available even after eos...
// We can unlock early, thanks to videosink's internal buffering: XXX FIXME: Perfectly race-free to do this before the pull?
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
videoSample = gst_app_sink_pull_preroll(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
}
// Sample received?
if (videoSample) {
// Get pointer to buffer - no ownership transfer, no unref needed:
videoBuffer = gst_sample_get_buffer(videoSample);
// Assign pts presentation timestamp in pipeline stream time and convert to seconds:
movieRecordBANK[moviehandle].pts = (double) GST_BUFFER_PTS(videoBuffer) / (double) 1e9;
// Iff forward playback is active and a target timeindex was specified and this buffer is not at least of
// that timeindex and at least one more buffer is queued, then skip this buffer, pull the next one and check
// if that one meets the required pts:
while ((rate > 0) && (timeindex >= 0) && (movieRecordBANK[moviehandle].pts < timeindex) && (movieRecordBANK[moviehandle].frameAvail > 0)) {
// Tell user about reason for rejecting this buffer:
if (PsychPrefStateGet_Verbosity() > 5) {
printf("PTB-DEBUG: Fast-Skipped buffer id %i with pts %f secs < targetpts %f secs.\n", (int) GST_BUFFER_OFFSET(videoBuffer), movieRecordBANK[moviehandle].pts, timeindex);
}
// Decrement available frame counter:
PsychLockMutex(&movieRecordBANK[moviehandle].mutex);
movieRecordBANK[moviehandle].frameAvail--;
PsychUnlockMutex(&movieRecordBANK[moviehandle].mutex);
// Return the unused sample to queue:
gst_sample_unref(videoSample);
// Pull the next one. As frameAvail was > 0 at check-time, we know there is at least one pending,
// so there shouldn't be a danger of hanging here:
videoSample = gst_app_sink_pull_sample(GST_APP_SINK(movieRecordBANK[moviehandle].videosink));
if (NULL == videoSample) {
// This should never happen!
printf("PTB-ERROR: No new video frame received in gst_app_sink_pull_sample skipper loop! Something's wrong. Aborting fetch.\n");
return(FALSE);
}
// Get pointer to buffer - no ownership transfer, no unref needed:
videoBuffer = gst_sample_get_buffer(videoSample);
// Assign updated pts presentation timestamp of new candidate in pipeline stream time and convert to seconds:
movieRecordBANK[moviehandle].pts = (double) GST_BUFFER_PTS(videoBuffer) / (double) 1e9;
// Recheck if this is a better candidate...
}
// Compute timedelta and bufferindex:
if (GST_CLOCK_TIME_IS_VALID(GST_BUFFER_DURATION(videoBuffer)))
deltaT = (double) GST_BUFFER_DURATION(videoBuffer) / (double) 1e9;
bufferIndex = GST_BUFFER_OFFSET(videoBuffer);
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: pts %f secs, dT %f secs, bufferId %i.\n", movieRecordBANK[moviehandle].pts, deltaT, (int) bufferIndex);
// Assign pointer to videoBuffer's data directly:
if (out_texture) {
// Map the buffers memory for reading:
if (!gst_buffer_map(videoBuffer, &mapinfo, GST_MAP_READ)) {
printf("PTB-ERROR: Failed to map video data of movie frame! Something's wrong. Aborting fetch.\n");
gst_sample_unref(videoSample);
videoBuffer = NULL;
return(FALSE);
}
out_texture->textureMemory = (GLuint*) mapinfo.data;
}
} else {
printf("PTB-ERROR: No new video frame received in gst_app_sink_pull_sample! Something's wrong. Aborting fetch.\n");
return(FALSE);
}
if (PsychPrefStateGet_Verbosity() > 5) printf("PTB-DEBUG: ...done.\n");
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Start of frame query to decode completion: %f msecs.\n", (tNow - tStart) * 1000.0);
tStart = tNow;
// Assign presentation_timestamp:
if (presentation_timestamp) *presentation_timestamp = movieRecordBANK[moviehandle].pts;
// Only create actual OpenGL texture if out_texture is non-NULL. Otherwise we're
// just skipping this. Useful for benchmarks, fast forward seeking, etc.
if (out_texture) {
// Activate OpenGL context of target window:
PsychSetGLContext(win);
#if PSYCH_SYSTEM == PSYCH_OSX
// Explicitely disable Apple's Client storage extensions. For now they are not really useful to us.
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
#endif
// Build a standard PTB texture record:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height);
// Set texture orientation as if it were an inverted Offscreen window: Upside-down.
out_texture->textureOrientation = 3;
// We use zero client storage memory bytes:
out_texture->textureMemorySizeBytes = 0;
// Assign default number of effective color channels:
out_texture->nrchannels = movieRecordBANK[moviehandle].pixelFormat;
// Is this grayscale movie actually a Bayer-encoded RGB movie? specialFlags1 & 1024 would indicate that:
if (movieRecordBANK[moviehandle].specialFlags1 & 1024) {
// This is Bayer raw sensor data which needs to get decoded into full RGB images.
#ifdef PTBVIDEOCAPTURE_LIBDC
// Ok, need to convert this grayscale image which actually contains raw Bayer sensor data into
// a RGB image. Need to perform software Bayer filtering via libdc1394 Debayering routines.
out_texture->textureMemory = (GLuint*) PsychDCDebayerFrame((unsigned char*) (out_texture->textureMemory), movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height, movieRecordBANK[moviehandle].bitdepth);
// Return failure if Debayering did not work:
if (out_texture->textureMemory == NULL) {
gst_buffer_unmap(videoBuffer, &mapinfo);
gst_sample_unref(videoSample);
videoBuffer = NULL;
return(FALSE);
}
releaseMemPtr = (unsigned char*) out_texture->textureMemory;
out_texture->nrchannels = 3; // Always 3 for RGB.
#else
// Won't ever reach this, as already Screen('OpenMovie') would have bailed out
// if libdc1394 is not supported.
return(FALSE);
#endif
}
// Assign default depth according to number of channels:
out_texture->depth = out_texture->nrchannels * movieRecordBANK[moviehandle].bitdepth;
if (out_texture->nrchannels < 4) {
// For 1-3 channel textures, play safe, don't assume alignment:
out_texture->textureByteAligned = 1;
}
else {
// 4 channel format:
// Textures are aligned on at least 4 Byte boundaries because texels are RGBA8. For
// frames of even-numbered pixel width, we can even get 8 Byte alignment:
out_texture->textureByteAligned = (movieRecordBANK[moviehandle].width % 2) ? 4 : 8;
}
// Assign texturehandle of our cached texture, if any, so it gets recycled now:
out_texture->textureNumber = movieRecordBANK[moviehandle].cached_texture;
// Mark this texture as originating from us, ie., our moviehandle, so texture recycling
// actually gets used:
out_texture->texturecache_slot = moviehandle;
// YUV 422 packed pixel upload requested?
if ((win->gfxcaps & kPsychGfxCapUYVYTexture) && (movieRecordBANK[moviehandle].pixelFormat == 5)) {
// GPU supports UYVY textures and we get data in that YCbCr format. Tell
// texture creation routine to use this optimized format:
if (!glewIsSupported("GL_APPLE_ycbcr_422")) {
// No support for more powerful Apple extension. Use Linux MESA extension:
out_texture->textureinternalformat = GL_YCBCR_MESA;
out_texture->textureexternalformat = GL_YCBCR_MESA;
} else {
// Apple extension supported:
out_texture->textureinternalformat = GL_RGB8;
out_texture->textureexternalformat = GL_YCBCR_422_APPLE;
}
// Same enumerant for Apple and Mesa:
out_texture->textureexternaltype = GL_UNSIGNED_SHORT_8_8_MESA;
// Number of effective channels is 3 for RGB8:
out_texture->nrchannels = 3;
// And 24 bpp depth:
out_texture->depth = 24;
// Byte alignment: For even number of pixels, assume at least 4 Byte alignment due to packing of 2 effective
// pixels into one 32-Bit packet, maybe even 8 Byte alignment if divideable by 4. For other width's, assume
// no alignment ie., 1 Byte:
out_texture->textureByteAligned = (movieRecordBANK[moviehandle].width % 2) ? 1 : ((movieRecordBANK[moviehandle].width % 4) ? 4 : 8);
}
// Upload of a "pseudo YUV" planar texture with only 8 bits Y component requested?
if ((movieRecordBANK[moviehandle].pixelFormat == 7) || (movieRecordBANK[moviehandle].pixelFormat == 8)) {
// We encode Y luminance data inside a 8 bit per pixel luminance texture. The
// "Y" luminance plane is stored at full 1 sample per pixel resolution with 8 bits.
// As such the texture appears to OpenGL as a normal LUMINANCE8 texture. Conversion of the Y
// luminance data into useable RGBA8 pixel fragments will happen during rendering via a suitable fragment
// shader. The net gain of this is that we can skip any kind of cpu based colorspace conversion
// for video formats/codecs which provide YUV data, by offloading the conversion to the GPU:
out_texture->textureinternalformat = 0;
// Mark texture as planar encoded, so proper conversion shader gets applied during
// call to PsychNormalizeTextureOrientation(), prior to any render-to-texture operation, e.g.,
// if used as an offscreen window, or as a participant of a Screen('TransformTexture') call:
out_texture->specialflags |= kPsychPlanarTexture;
// Assign special filter shader for Y8 -> RGBA8 color-space conversion of the
// planar texture during drawing or PsychNormalizeTextureOrientation():
if (!PsychAssignPlanarI800TextureShader(out_texture, win)) PsychErrorExitMsg(PsychError_user, "Assignment of Y8-Y800 video decoding shader failed during movie texture creation!");
// Number of effective channels is 1 for L8:
out_texture->nrchannels = 1;
// And 8 bpp depth: This will trigger bog-standard LUMINANCE8 texture creation in PsychCreateTexture():
out_texture->depth = 8;
// Byte alignment - Only depends on width of an image row, given the 1 Byte per pixel data:
out_texture->textureByteAligned = 1;
if (movieRecordBANK[moviehandle].width % 2 == 0) out_texture->textureByteAligned = 2;
if (movieRecordBANK[moviehandle].width % 4 == 0) out_texture->textureByteAligned = 4;
if (movieRecordBANK[moviehandle].width % 8 == 0) out_texture->textureByteAligned = 8;
}
// YUV I420 planar pixel upload requested?
if (movieRecordBANK[moviehandle].pixelFormat == 6) {
// We encode I420 planar data inside a 8 bit per pixel luminance texture of
// 1.5x times the height of the video frame. First the "Y" luminance plane
// is stored at full 1 sample per pixel resolution with 8 bits. Then a 0.25x
// height slice with "U" Cr chrominance data at half the horizontal and vertical
// resolution aka 1 sample per 2x2 pixel quad. Then a 0.25x height slice with "V"
// Cb chrominance data at 1 sample per 2x2 pixel quad resolution. As such the texture
// appears to OpenGL as a normal LUMINANCE8 texture. Conversion of the planar format
// into useable RGBA8 pixel fragments will happen during rendering via a suitable fragment
// shader. The net gain of this is that we effectively only need 1.5 Bytes per pixel instead
// of 3 Bytes for RGB8 or 4 Bytes for RGBA8:
out_texture->textureexternaltype = GL_UNSIGNED_BYTE;
out_texture->textureexternalformat = GL_LUMINANCE;
out_texture->textureinternalformat = GL_LUMINANCE8;
// Define a rect of 1.5 times the video frame height, so PsychCreateTexture() will source
// the whole input data buffer:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height * 1.5);
// Check if 1.5x height texture fits within hardware limits of this GPU:
if (movieRecordBANK[moviehandle].height * 1.5 > win->maxTextureSize) PsychErrorExitMsg(PsychError_user, "Videoframe size too big for this graphics card and pixelFormat! Please retry with a pixelFormat of 4 in 'OpenMovie'.");
// Byte alignment: Assume no alignment for now:
out_texture->textureByteAligned = 1;
// Create planar "I420 inside L8" texture:
PsychCreateTexture(out_texture);
// Restore rect and clientrect of texture to effective size of video frame:
PsychMakeRect(out_texture->rect, 0, 0, movieRecordBANK[moviehandle].width, movieRecordBANK[moviehandle].height);
PsychCopyRect(out_texture->clientrect, out_texture->rect);
// Mark texture as planar encoded, so proper conversion shader gets applied during
// call to PsychNormalizeTextureOrientation(), prior to any render-to-texture operation, e.g.,
// if used as an offscreen window, or as a participant of a Screen('TransformTexture') call:
out_texture->specialflags |= kPsychPlanarTexture;
// Assign special filter shader for sampling and color-space conversion of the
// planar texture during drawing or PsychNormalizeTextureOrientation():
if (!PsychAssignPlanarI420TextureShader(out_texture, win)) PsychErrorExitMsg(PsychError_user, "Assignment of I420 video decoding shader failed during movie texture creation!");
// Number of effective channels is 3 for RGB8:
out_texture->nrchannels = 3;
// And 24 bpp depth:
out_texture->depth = 24;
}
else if (movieRecordBANK[moviehandle].bitdepth > 8) {
// Is this a > 8 bpc image format? If not, we ain't nothing more to prepare.
// If yes, we need to use a high precision floating point texture to represent
// the > 8 bpc image payload without loss of image information:
// highbitthreshold: If the net bpc value is greater than this, then use 32bpc floats
// instead of 16 bpc half-floats, because 16 bpc would not be sufficient to represent
// more than highbitthreshold bits faithfully:
const int highbitthreshold = 11;
unsigned int w = movieRecordBANK[moviehandle].width;
// 9 - 16 bpc color/luminance resolution:
out_texture->depth = out_texture->nrchannels * ((movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? 32 : 16);
// Byte alignment: Assume at least 2 Byte alignment due to 16 bit per component aka 2 Byte input:
out_texture->textureByteAligned = 2;
if (out_texture->nrchannels == 1) {
// 1 layer Luminance:
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_LUMINANCE_FLOAT32_APPLE : GL_LUMINANCE_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_LUMINANCE;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_LUMINANCE16_SNORM;
out_texture->textureByteAligned = (w % 2) ? 2 : ((w % 4) ? 4 : 8);
}
else if (out_texture->nrchannels == 3) {
// 3 layer RGB:
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_RGB_FLOAT32_APPLE : GL_RGB_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_RGB;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_RGB16_SNORM;
out_texture->textureByteAligned = (w % 2) ? 2 : ((w % 4) ? 4 : 8);
}
else {
// 4 layer RGBA:
out_texture->textureinternalformat = (movieRecordBANK[moviehandle].bitdepth > highbitthreshold) ? GL_RGBA_FLOAT32_APPLE : GL_RGBA_FLOAT16_APPLE;
out_texture->textureexternalformat = GL_RGBA;
// Override for missing floating point texture support: Try to use 16 bit fixed point signed normalized textures [-1.0 ; 1.0] resolved at 15 bits:
if (!(win->gfxcaps & kPsychGfxCapFPTex16)) out_texture->textureinternalformat = GL_RGBA16_SNORM;
// Always 8 Byte aligned:
out_texture->textureByteAligned = 8;
}
// External datatype is 16 bit unsigned integer, each color component encoded in a 16 bit value:
out_texture->textureexternaltype = GL_UNSIGNED_SHORT;
// Scale input data, so highest significant bit of payload is in bit 16:
glPixelTransferi(GL_RED_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
glPixelTransferi(GL_GREEN_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
glPixelTransferi(GL_BLUE_SCALE, 1 << (16 - movieRecordBANK[moviehandle].bitdepth));
// Let PsychCreateTexture() do the rest of the job of creating, setting up and
// filling an OpenGL texture with content:
PsychCreateTexture(out_texture);
// Undo scaling:
glPixelTransferi(GL_RED_SCALE, 1);
glPixelTransferi(GL_GREEN_SCALE, 1);
glPixelTransferi(GL_BLUE_SCALE, 1);
}
else {
// Let PsychCreateTexture() do the rest of the job of creating, setting up and
// filling an OpenGL texture with content:
PsychCreateTexture(out_texture);
}
// Release buffer for target RGB debayered image, if any:
if ((movieRecordBANK[moviehandle].specialFlags1 & 1024) && releaseMemPtr) free(releaseMemPtr);
// NULL-out the texture memory pointer after PsychCreateTexture(). This is not strictly
// needed, as PsychCreateTexture() did it already, but we add it here as an annotation
// to make it obvious during code correctness review that we won't touch or free() the
// video memory buffer anymore, which is owned and only memory-managed by GStreamer:
out_texture->textureMemory = NULL;
// After PsychCreateTexture() the cached texture object from our cache is used
// and no longer available for recycling. We mark the cache as empty:
// It will be filled with a new textureid for recycling if a texture gets
// deleted in PsychMovieDeleteTexture()....
movieRecordBANK[moviehandle].cached_texture = 0;
// Does usercode want immediate conversion of texture into standard RGBA8 packed pixel
// upright format for use as a render-target? If so, do it:
if (movieRecordBANK[moviehandle].specialFlags1 & 16) {
// Transform out_texture video texture into a normalized, upright texture if it isn't already in
// that format. We require this standard orientation for simplified shader design.
PsychSetShader(win, 0);
PsychNormalizeTextureOrientation(out_texture);
}
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Decode completion to texture created: %f msecs.\n", (tNow - tStart) * 1000.0);
tStart = tNow;
// End of texture creation code.
}
// Detection of dropped frames: This is a heuristic. We'll see how well it works out...
// TODO: GstBuffer videoBuffer provides special flags that should allow to do a more
// robust job, although nothing's wrong with the current approach per se...
if (rate && presentation_timestamp) {
// Try to check for dropped frames in playback mode:
// Expected delta between successive presentation timestamps:
// This is not dependent on playback rate, as it measures time in the
// GStreamer movies timeline == Assuming 1x playback rate.
targetdelta = 1.0f / movieRecordBANK[moviehandle].fps;
// Compute real delta, given rate and playback direction:
if (rate > 0) {
realdelta = *presentation_timestamp - movieRecordBANK[moviehandle].last_pts;
if (realdelta < 0) realdelta = 0;
}
else {
realdelta = -1.0 * (*presentation_timestamp - movieRecordBANK[moviehandle].last_pts);
if (realdelta < 0) realdelta = 0;
}
frames = realdelta / targetdelta;
// Dropped frames?
if (frames > 1 && movieRecordBANK[moviehandle].last_pts >= 0) {
movieRecordBANK[moviehandle].nr_droppedframes += (int) (frames - 1 + 0.5);
}
movieRecordBANK[moviehandle].last_pts = *presentation_timestamp;
}
// Unlock.
gst_buffer_unmap(videoBuffer, &mapinfo);
gst_sample_unref(videoSample);
videoBuffer = NULL;
// Manually advance movie time, if in fetch mode:
if (0 == rate) {
// We are in manual fetch mode: Need to manually advance movie to next
// media sample:
movieRecordBANK[moviehandle].endOfFetch = 0;
preT = PsychGSGetMovieTimeIndex(moviehandle);
event = gst_event_new_step(GST_FORMAT_BUFFERS, 1, 1.0, TRUE, FALSE);
// Send the seek event *only* to the videosink. This follows recommendations from GStreamer SDK tutorial 13 (Playback speed) to
// not send to high level playbin itself, as that would propagate to all sinks and trigger multiple seeks. While this was not
// ever a problem in the past on Linux or with upstream GStreamer, it caused deadlocks, timeouts and seek failures when done
// with the GStreamer SDK on some movie files that have audio tracks, e.g., our standard demo movie! Sending only to videosink
// fixes this problem:
if (!gst_element_send_event(movieRecordBANK[moviehandle].videosink, event)) printf("PTB-DEBUG: In single-step seek I - Failed.\n");
// Block until seek completed, failed, or timeout of 10 seconds reached:
if (GST_STATE_CHANGE_SUCCESS != gst_element_get_state(theMovie, NULL, NULL, (GstClockTime) (10 * 1e9))) printf("PTB-DEBUG: In single-step seek II - Failed.\n");
postT = PsychGSGetMovieTimeIndex(moviehandle);
if (PsychPrefStateGet_Verbosity() > 6) printf("PTB-DEBUG: Movie fetch advance: preT %f postT %f DELTA %lf %s\n", preT, postT, postT - preT, (postT - preT < 0.001) ? "SAME" : "DIFF");
// Signal end-of-fetch if time no longer progresses signficiantly:
if (postT - preT < 0.001) movieRecordBANK[moviehandle].endOfFetch = 1;
}
PsychGetAdjustedPrecisionTimerSeconds(&tNow);
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-DEBUG: Texture created to fetch completion: %f msecs.\n", (tNow - tStart) * 1000.0);
// Reset tStart for next fetch cycle:
tStart = 0;
return(TRUE);
}
/*
* PsychGSFreeMovieTexture() - Release texture memory for a texture.
*
* This routine is called by PsychDeleteTexture() in PsychTextureSupport.c
* It performs the special cleanup necessary for cached movie textures.
*/
void PsychGSFreeMovieTexture(PsychWindowRecordType *win)
{
// Is this a GStreamer movietexture? If not, just skip this routine.
if (win->windowType!=kPsychTexture || win->textureOrientation != 3 || win->texturecache_slot < 0) return;
// Movie texture: Check if we can move it into our recycler cache
// for later reuse...
if (movieRecordBANK[win->texturecache_slot].cached_texture == 0) {
// Cache free. Put this texture object into it for later reuse:
movieRecordBANK[win->texturecache_slot].cached_texture = win->textureNumber;
// 0-out the textureNumber so our standard cleanup routine (glDeleteTextures) gets
// skipped - if we wouldn't do this, our caching scheme would screw up.
win->textureNumber = 0;
}
else {
// Cache already occupied. We don't do anything but leave the cleanup work for
// this texture to the standard PsychDeleteTexture() routine...
}
return;
}
/*
* PsychGSPlaybackRate() - Start- and stop movieplayback, set playback parameters.
*
* moviehandle = Movie to start-/stop.
* playbackrate = zero == Stop playback, non-zero == Play movie with spec. rate,
* e.g., 1 = forward, 2 = double speed forward, -1 = backward, ...
* loop = 0 = Play once. 1 = Loop, aka rewind at end of movie and restart.
* soundvolume = 0 == Mute sound playback, between 0.0 and 1.0 == Set volume to 0 - 100 %.
* Returns Number of dropped frames to keep playback in sync.
*/
int PsychGSPlaybackRate(int moviehandle, double playbackrate, int loop, double soundvolume)
{
GstElement *audiosink, *actual_audiosink;
gchar* pstring;
int dropped = 0;
GstElement *theMovie = NULL;
double timeindex;
GstSeekFlags seekFlags = 0;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Try to set movie playback rate to value identical to current value?
if (playbackrate == movieRecordBANK[moviehandle].rate) {
// Yes: This would be a no-op, except we allow to change the sound output volume
// dynamically and on-the-fly with low overhead this way:
// Set volume and mute state for audio:
g_object_set(G_OBJECT(theMovie), "mute", (soundvolume <= 0) ? TRUE : FALSE, NULL);
g_object_set(G_OBJECT(theMovie), "volume", soundvolume, NULL);
// Done. Return success status code:
return(0);
}
if (playbackrate != 0) {
// Start playback of movie:
// Set volume and mute state for audio:
g_object_set(G_OBJECT(theMovie), "mute", (soundvolume <= 0) ? TRUE : FALSE, NULL);
g_object_set(G_OBJECT(theMovie), "volume", soundvolume, NULL);
// Set playback rate: An explicit seek to the position we are already (supposed to be)
// is needed to avoid jumps in movies with bad encoding or keyframe placement:
timeindex = PsychGSGetMovieTimeIndex(moviehandle);
// Which loop setting?
if (loop <= 0) {
// Looped playback disabled. Set to well defined off value zero:
loop = 0;
}
else {
// Looped playback requested. With default settings (==1)?
// Otherwise we'll just pass on any special != 1 setting as a
// user-override:
if (loop == 1) {
// Playback with defaults. Apply default setup + specialFlags1 quirks:
// specialFlags & 32? Use 'uri' injection method for looped playback, instead of seek method:
if (movieRecordBANK[moviehandle].specialFlags1 & 32) loop = 2;
// specialFlags & 64? Use segment seeks.
if (movieRecordBANK[moviehandle].specialFlags1 & 64) loop |= 4;
// specialFlags & 128? Use pipeline flushing seeks
if (movieRecordBANK[moviehandle].specialFlags1 & 128) loop |= 8;
}
}
// On some movies and configurations, we need a segment seek as indicated by flag 0x4:
if (loop & 0x4) seekFlags |= GST_SEEK_FLAG_SEGMENT;
if (playbackrate > 0) {
gst_element_seek(theMovie, playbackrate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | ((loop & 0x1) ? seekFlags : 0), GST_SEEK_TYPE_SET,
(gint64) (timeindex * (double) 1e9), GST_SEEK_TYPE_NONE, GST_CLOCK_TIME_NONE);
}
else {
gst_element_seek(theMovie, playbackrate, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE | ((loop & 0x1) ? seekFlags : 0), GST_SEEK_TYPE_SET,
0, GST_SEEK_TYPE_SET, (gint64) (timeindex * (double) 1e9));
}
movieRecordBANK[moviehandle].loopflag = loop;
movieRecordBANK[moviehandle].last_pts = -1.0;
movieRecordBANK[moviehandle].nr_droppedframes = 0;
movieRecordBANK[moviehandle].rate = playbackrate;
movieRecordBANK[moviehandle].frameAvail = 0;
movieRecordBANK[moviehandle].preRollAvail = 0;
// Is this a movie with actual videotracks and frame-dropping on videosink full enabled?
if ((movieRecordBANK[moviehandle].nrVideoTracks > 0) && gst_app_sink_get_drop(GST_APP_SINK(movieRecordBANK[moviehandle].videosink))) {
// Yes: We only schedule deferred start of playback at first Screen('GetMovieImage')
// frame fetch. This to avoid dropped frames due to random delays between
// call to Screen('PlayMovie') and Screen('GetMovieImage'):
movieRecordBANK[moviehandle].startPending = 1;
}
else {
// Only soundtrack or framedropping disabled with videotracks - Start it immediately:
movieRecordBANK[moviehandle].startPending = 0;
PsychMoviePipelineSetState(theMovie, GST_STATE_PLAYING, 10.0);
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
}
}
else {
// Stop playback of movie:
movieRecordBANK[moviehandle].rate = 0;
movieRecordBANK[moviehandle].startPending = 0;
movieRecordBANK[moviehandle].loopflag = 0;
movieRecordBANK[moviehandle].endOfFetch = 0;
// Print name of audio sink - the output device which was actually playing the sound, if requested:
// This is a Linux only feature, as GStreamer for MS-Windows doesn't support such queries at all,
// and GStreamer for OSX doesn't expose the information in a way that would be in any way meaningful for us.
if ((PSYCH_SYSTEM == PSYCH_LINUX) && (PsychPrefStateGet_Verbosity() > 3)) {
audiosink = NULL;
if (g_object_class_find_property(G_OBJECT_GET_CLASS(theMovie), "audio-sink")) {
g_object_get(G_OBJECT(theMovie), "audio-sink", &audiosink, NULL);
}
if (audiosink) {
actual_audiosink = NULL;
actual_audiosink = (GST_IS_CHILD_PROXY(audiosink)) ? ((GstElement*) gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(audiosink), 0)) : audiosink;
if (actual_audiosink) {
if (g_object_class_find_property(G_OBJECT_GET_CLASS(actual_audiosink), "device")) {
pstring = NULL;
g_object_get(G_OBJECT(actual_audiosink), "device", &pstring, NULL);
if (pstring) {
printf("PTB-INFO: Audio output device name for movie playback was '%s'", pstring);
g_free(pstring); pstring = NULL;
}
}
if (g_object_class_find_property(G_OBJECT_GET_CLASS(actual_audiosink), "device-name")) {
pstring = NULL;
g_object_get(G_OBJECT(actual_audiosink), "device-name", &pstring, NULL);
if (pstring) {
printf(" [%s].", pstring);
g_free(pstring); pstring = NULL;
}
}
printf("\n");
if (actual_audiosink != audiosink) gst_object_unref(actual_audiosink);
}
gst_object_unref(audiosink);
}
}
PsychMoviePipelineSetState(theMovie, GST_STATE_PAUSED, 10.0);
PsychGSProcessMovieContext(&(movieRecordBANK[moviehandle]), FALSE);
// Output count of dropped frames:
if ((dropped=movieRecordBANK[moviehandle].nr_droppedframes) > 0) {
if (PsychPrefStateGet_Verbosity()>2) {
printf("PTB-INFO: Movie playback had to drop %i frames of movie %i to keep playback in sync.\n", movieRecordBANK[moviehandle].nr_droppedframes, moviehandle);
}
}
}
return(dropped);
}
/*
* void PsychGSExitMovies() - Shutdown handler.
*
* This routine is called by Screen('CloseAll') and on clear Screen time to
* do final cleanup. It releases all movie objects.
*
*/
void PsychGSExitMovies(void)
{
// Release all movies:
PsychGSDeleteAllMovies();
firsttime = TRUE;
return;
}
/*
* PsychGSGetMovieTimeIndex() -- Return current playback time of movie.
*/
double PsychGSGetMovieTimeIndex(int moviehandle)
{
GstElement *theMovie = NULL;
gint64 pos_nsecs;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
if (!gst_element_query_position(theMovie, GST_FORMAT_TIME, &pos_nsecs)) {
if (PsychPrefStateGet_Verbosity() > 1) printf("PTB-WARNING: Could not query position in movie %i in seconds. Returning zero.\n", moviehandle);
pos_nsecs = 0;
}
// Retrieve timeindex:
return((double) pos_nsecs / (double) 1e9);
}
/*
* PsychGSSetMovieTimeIndex() -- Set current playback time of movie, perform active seek if needed.
*/
double PsychGSSetMovieTimeIndex(int moviehandle, double timeindex, psych_bool indexIsFrames)
{
GstElement *theMovie;
double oldtime;
gint64 targetIndex;
GstSeekFlags flags;
if (moviehandle < 0 || moviehandle >= PSYCH_MAX_MOVIES) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided!");
}
// Fetch references to objects we need:
theMovie = movieRecordBANK[moviehandle].theMovie;
if (theMovie == NULL) {
PsychErrorExitMsg(PsychError_user, "Invalid moviehandle provided. No movie associated with this handle !!!");
}
// Retrieve current timeindex:
oldtime = PsychGSGetMovieTimeIndex(moviehandle);
// NOTE: We could use GST_SEEK_FLAG_SKIP to allow framedropping on fast forward/reverse playback...
flags = GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE;
// Need segment seek flag for seek during active looped playback if also flag 0x4 is set:
if ((movieRecordBANK[moviehandle].rate != 0) && (movieRecordBANK[moviehandle].loopflag & 0x1) && (movieRecordBANK[moviehandle].loopflag & 0x4)) {
flags |= GST_SEEK_FLAG_SEGMENT;
}
// Index based or target time based seeking?
if (indexIsFrames) {
// Index based seeking:
targetIndex = (gint64) (timeindex + 0.5);
// Simple seek, videobuffer (index) oriented, with pipeline flush and accurate seek,
// i.e., not locked to keyframes, but frame-accurate:
if (!gst_element_seek_simple(theMovie, GST_FORMAT_DEFAULT, flags, targetIndex)) {
// Failed: This can happen on various movie formats as not all codecs and formats support frame-based seeks.
// Fallback to time-based seek by faking a target time for given targetIndex:
timeindex = (double) targetIndex / (double) movieRecordBANK[moviehandle].fps;
if (PsychPrefStateGet_Verbosity() > 1) {
printf("PTB-WARNING: Could not seek to frame index %i via frame-based seeking in movie %i.\n", (int) targetIndex, moviehandle);
printf("PTB-WARNING: Will do a time-based seek to approximately equivalent time %f seconds instead.\n", timeindex);
printf("PTB-WARNING: Not all movie formats support frame-based seeking. Please change your movie format for better precision.\n");
}
if (!gst_element_seek_simple(theMovie, GST_FORMAT_TIME, flags, (gint64) (timeindex * (double) 1e9)) &&
(PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: Time-based seek failed as well! Something is wrong with this movie!\n");
}
}
}
else {
// Time based seeking:
// Set new timeindex as time in seconds:
// Simple seek, time-oriented, with pipeline flush and accurate seek,
// i.e., not locked to keyframes, but frame-accurate:
if (!gst_element_seek_simple(theMovie, GST_FORMAT_TIME, flags, (gint64) (timeindex * (double) 1e9)) &&
(PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: Time-based seek to %f seconds in movie %i failed. Something is wrong with this movie or the target time.\n", timeindex, moviehandle);
}
}
// Block until seek completed, failed or timeout of 30 seconds reached:
if (GST_STATE_CHANGE_FAILURE == gst_element_get_state(theMovie, NULL, NULL, (GstClockTime) (30 * 1e9)) && (PsychPrefStateGet_Verbosity() > 1)) {
printf("PTB-WARNING: SetTimeIndex on movie %i failed. Something is wrong with this movie or the target position. [Statechange-Failure in seek]\n", moviehandle);
printf("PTB-WARNING: Requested target position was %f %s. This could happen if the movie is not efficiently seekable and a timeout was hit.\n",
timeindex, (indexIsFrames) ? "frames" : "seconds");
}
if (PsychPrefStateGet_Verbosity() > 4) printf("PTB-INFO: Seeked to position %f secs in movie %i.\n", PsychGSGetMovieTimeIndex(moviehandle), moviehandle);
// Reset fetch flag:
movieRecordBANK[moviehandle].endOfFetch = 0;
// Return old time value of previous position:
return(oldtime);
}
// #if GST_CHECK_VERSION(1,0,0)
#endif
// #ifdef PTB_USE_GSTREAMER
#endif
|
the_stack_data/753141.c |
/*
* gpio_relay.c - example of driving a relay using the GPIO peripheral on a BCM2835 (Raspberry Pi)
*
* Copyright 2012 Kevin Sangeelee.
* Released as GPLv2, see <http://www.gnu.org/licenses/>
*
* This is intended as an example of using Raspberry Pi hardware registers to drive a relay using GPIO. Use at your own
* risk or not at all. As far as possible, I've omitted anything that doesn't relate to the Raspi registers. There are more
* conventional ways of doing this using kernel drivers.
*
* Additions (c) Paul Hermann, 2015-2016 under the same license terms
* -Control of Raspberry pi GPIO for amplifier power
* -Launch script on power status change from LMS
*/
#if GPIO
#define BCM2708_PERI_BASE 0x20000000
#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include "squeezelite.h"
#define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024)
int mem_fd;
void *gpio_map;
// I/O access
volatile unsigned *gpio;
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1<<(((g)%10)*3))
#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
#define GPIO_SET *(gpio+7) // sets bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio+10) // clears bits which are 1 ignores bits which are 0
void setup_io();
int gpio_state = -1;
int initialized = -1;
int power_state = -1;
void relay( int state) {
gpio_state = state;
// Set up gpi pointer for direct register access
if (initialized == -1){
setup_io();
initialized = 1;
INP_GPIO(gpio_pin); // must use INP_GPIO before we can use OUT_GPIO
OUT_GPIO(gpio_pin);
}
// Set GPIO pin to output
if(gpio_state == 1)
GPIO_CLR = 1<<gpio_pin;
else if(gpio_state == 0)
GPIO_SET = 1<<gpio_pin;
usleep(1); // Delay to allow any change in state to be reflected in the LEVn, register bit.
// Done!
}
//
// Set up a memory regions to access GPIO
//
void setup_io()
{
/* open /dev/mem */
if ((mem_fd = open("/dev/mem", O_RDWR|O_SYNC) ) < 0) {
printf("can't open /dev/mem \n");
exit(-1);
}
/* mmap GPIO */
gpio_map = mmap(
NULL, //Any adddress in our space will do
BLOCK_SIZE, //Map length
PROT_READ|PROT_WRITE,// Enable reading & writting to mapped memory
MAP_SHARED, //Shared with other processes
mem_fd, //File to map
GPIO_BASE //Offset to GPIO peripheral
);
close(mem_fd); //No need to keep mem_fd open after mmap
if (gpio_map == MAP_FAILED) {
printf("mmap error %d\n", (int)gpio_map);//errno also set!
exit(-1);
}
// Always use volatile pointer!
gpio = (volatile unsigned *)gpio_map;
} // setup_io
char *cmdline;
int argloc;
void relay_script( int state) {
gpio_state = state;
int err;
// Call script with init parameter
if (initialized == -1){
int strsize = strlen(power_script);
cmdline = (char*) malloc(strsize+3);
argloc = strsize + 1;
strcpy(cmdline, power_script);
strcat(cmdline, " 2");
if ((err = system(cmdline)) != 0){
fprintf (stderr, "%s exit status = %d\n", cmdline, err);
}
else{
initialized = 1;
}
}
// Call Script to turn on or off on = 1, off = 0
// Checks current status to avoid calling script excessivly on track changes where alsa re-inits.
if( (gpio_state == 1) && (power_state != 1)){
cmdline[argloc] = '1';
if ((err = system(cmdline)) != 0){
fprintf (stderr, "%s exit status = %d\n", cmdline, err);
}
else {
power_state = 1;
}
}
else if( (gpio_state == 0) && (power_state != 0)){
cmdline[argloc] = '0';
if ((err = system(cmdline)) != 0){
fprintf (stderr, "%s exit status = %d\n", cmdline, err);
}
else {
power_state = 0;
}
}
// Done!
}
#endif // GPIO
|
the_stack_data/68886702.c | /* {"title":"2D array global, initialized","platform":"unix","tags":["unix"]} */
#include <stdio.h>
int a[][2] = {{1, 2}, {3, 4}};
int main() {
printf("%d %d\n", a[0][0], a[0][1]);
printf("%d %d\n", a[1][0], a[1][1]);
printf("%d %d %d %d\n", **a, *(*a + 1), **(a + 1), *(*(a + 1) + 1));
}
|
the_stack_data/3261799.c | // Test strict_string_checks option in atoi function
// RUN: %clang_asan %s -o %t
// RUN: %run %t test1 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test1 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
// RUN: %run %t test2 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test2 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
// RUN: %run %t test3 2>&1
// RUN: %env_asan_opts=strict_string_checks=false %run %t test3 2>&1
// RUN: %env_asan_opts=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
#include <assert.h>
#include <stdlib.h>
#include <string.h>
void test1(char *array) {
// Last symbol is non-digit
memset(array, '1', 10);
array[9] = 'a';
int r = atoi(array);
assert(r == 111111111);
}
void test2(char *array) {
// Single non-digit symbol
array[9] = 'a';
int r = atoi(array + 9);
assert(r == 0);
}
void test3(char *array) {
// Incorrect number format
memset(array, ' ', 10);
array[9] = '-';
array[8] = '-';
int r = atoi(array);
assert(r == 0);
}
int main(int argc, char **argv) {
char *array = (char*)malloc(10);
if (argc != 2) return 1;
if (!strcmp(argv[1], "test1")) test1(array);
// CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK1: READ of size 11
if (!strcmp(argv[1], "test2")) test2(array);
// CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK2: READ of size 2
if (!strcmp(argv[1], "test3")) test3(array);
// CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
// CHECK3: READ of size 11
free(array);
return 0;
}
|
the_stack_data/5289.c | // Check passing options to the assembler for MIPS targets.
//
// RUN: %clang -target mips-linux-gnu -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-EB-AS %s
// RUN: %clang -target mipsel-linux-gnu -### \
// RUN: -no-integrated-as -c -EB %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-EB-AS %s
// MIPS32R2-EB-AS: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
// MIPS32R2-EB-AS-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-KPIC"
//
// RUN: %clang -target mips-linux-gnu -### \
// RUN: -no-integrated-as -fPIC -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-EB-PIC %s
// MIPS32R2-EB-PIC: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-call_nonpic" "-EB"
// MIPS32R2-EB-PIC: "-KPIC"
//
// RUN: %clang -target mipsel-linux-gnu -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-DEF-EL-AS %s
// MIPS32R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EL"
//
// RUN: %clang -target mips64-linux-gnu -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS64R2-EB-AS %s
// MIPS64R2-EB-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64el-linux-gnu -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS64R2-DEF-EL-AS %s
// MIPS64R2-DEF-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-KPIC" "-EL"
//
// RUN: %clang -target mips-linux-gnu -mabi=eabi -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-EABI %s
// MIPS-EABI: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "eabi" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mabi=n32 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-N32 %s
// MIPS-N32: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "n32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mipsel-linux-gnu -mabi=32 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-EL-AS %s
// RUN: %clang -target mips-linux-gnu -mabi=32 -### \
// RUN: -no-integrated-as -c %s -EL 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS32R2-EL-AS %s
// MIPS32R2-EL-AS: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EL"
//
// RUN: %clang -target mips64el-linux-gnu -mabi=64 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS64R2-EL-AS %s
// MIPS64R2-EL-AS: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-KPIC" "-EL"
//
// RUN: %clang -target mips-linux-gnu -march=mips32r2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-32R2 %s
// MIPS-32R2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -march=p5600 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-P5600 %s
// MIPS-P5600: as{{(.exe)?}}" "-march" "p5600" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -march=octeon -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-OCTEON %s
// MIPS-OCTEON: as{{(.exe)?}}" "-march" "octeon" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips1 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-1 %s
// MIPS-ALIAS-1: as{{(.exe)?}}" "-march" "mips1" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-2 %s
// MIPS-ALIAS-2: as{{(.exe)?}}" "-march" "mips2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips3 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-3 %s
// MIPS-ALIAS-3: as{{(.exe)?}}" "-march" "mips3" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips4 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-4 %s
// MIPS-ALIAS-4: as{{(.exe)?}}" "-march" "mips4" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips5 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-5 %s
// MIPS-ALIAS-5: as{{(.exe)?}}" "-march" "mips5" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips32 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-32 %s
// MIPS-ALIAS-32: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips32r2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-32R2 %s
// MIPS-ALIAS-32R2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips32r3 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-32R3 %s
// MIPS-ALIAS-32R3: as{{(.exe)?}}" "-march" "mips32r3" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips32r5 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-32R5 %s
// MIPS-ALIAS-32R5: as{{(.exe)?}}" "-march" "mips32r5" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mips32r6 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-32R6 %s
// MIPS-ALIAS-32R6: as{{(.exe)?}}" "-march" "mips32r6" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mips64 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-64 %s
// MIPS-ALIAS-64: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mips64r2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R2 %s
// MIPS-ALIAS-64R2: as{{(.exe)?}}" "-march" "mips64r2" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mips64r3 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R3 %s
// MIPS-ALIAS-64R3: as{{(.exe)?}}" "-march" "mips64r3" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mips64r5 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R5 %s
// MIPS-ALIAS-64R5: as{{(.exe)?}}" "-march" "mips64r5" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -mips64r6 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-ALIAS-64R6 %s
// MIPS-ALIAS-64R6: as{{(.exe)?}}" "-march" "mips64r6" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips-linux-gnu -mno-mips16 -mips16 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-16 %s
// MIPS-16: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mips16"
//
// RUN: %clang -target mips-linux-gnu -mips16 -mno-mips16 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-N16 %s
// MIPS-N16: as{{(.exe)?}}"
// MIPS-N16: -no-mips16
//
// RUN: %clang -target mips-linux-gnu -mno-micromips -mmicromips -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MICRO %s
// MIPS-MICRO: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmicromips"
//
// RUN: %clang -target mips-linux-gnu -mmicromips -mno-micromips -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NMICRO %s
// MIPS-NMICRO: as{{(.exe)?}}"
// MIPS-NMICRO-NOT: {{[A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mmicromips"
//
// RUN: %clang -target mips-linux-gnu -mno-dsp -mdsp -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-DSP %s
// MIPS-DSP: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdsp"
//
// RUN: %clang -target mips-linux-gnu -mdsp -mno-dsp -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NDSP %s
// MIPS-NDSP: as{{(.exe)?}}"
// MIPS-NDSP-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mdsp"
//
// RUN: %clang -target mips-linux-gnu -mno-dspr2 -mdspr2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-DSPR2 %s
// MIPS-DSPR2: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mdspr2"
//
// RUN: %clang -target mips-linux-gnu -mdspr2 -mno-dspr2 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NDSPR2 %s
// MIPS-NDSPR2: as{{(.exe)?}}"
// MIPS-NDSPR2-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mdspr2"
//
// RUN: %clang -target mips-linux-gnu -mnan=legacy -mnan=2008 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NAN2008 %s
// MIPS-NAN2008: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mnan=2008"
//
// RUN: %clang -target mips-linux-gnu -mnan=2008 -mnan=legacy -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NAN-LEGACY %s
// MIPS-NAN-LEGACY: as{{(.exe)?}}"
// MIPS-NAN-LEGACY-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mnan={{.*}}"
//
// RUN: %clang -target mips-linux-gnu -mfp64 -mfpxx -mfp32 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MFP32 %s
// MIPS-MFP32: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfp32"
//
// RUN: %clang -target mips-linux-gnu -mfp32 -mfp64 -mfpxx -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MFPXX %s
// MIPS-MFPXX: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfpxx"
//
// RUN: %clang -target mips-linux-gnu -mfpxx -mfp32 -mfp64 -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MFP64 %s
// MIPS-MFP64: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mfp64"
//
// RUN: %clang -target mips-linux-gnu -mno-msa -mmsa -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-MSA %s
// MIPS-MSA: as{{(.exe)?}}" "-march" "mips32r2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB" "-mmsa"
//
// RUN: %clang -target mips-linux-gnu -mmsa -mno-msa -### \
// RUN: -no-integrated-as -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MIPS-NMSA %s
// MIPS-NMSA: as{{(.exe)?}}"
// MIPS-NMSA-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-mmsa"
//
// We've already tested MIPS32r2 and MIPS64r2 thoroughly. Do minimal tests on
// the remaining CPU's since it was possible to pass on a -mabi with no value
// when the CPU name is absent from a StringSwitch in getMipsCPUAndABI()
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -c %s -mcpu=mips1 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS1-EB-AS %s
// MIPS1-EB-AS: as{{(.exe)?}}" "-march" "mips1" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
// MIPS1-EB-AS-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-KPIC"
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -c %s -mcpu=mips2 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS2-EB-AS %s
// MIPS2-EB-AS: as{{(.exe)?}}" "-march" "mips2" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
// MIPS2-EB-AS-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-KPIC"
//
// RUN: %clang -target mips64-linux-gnu -### -no-integrated-as -c %s -mcpu=mips3 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS3-EB-AS %s
// MIPS3-EB-AS: as{{(.exe)?}}" "-march" "mips3" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -### -no-integrated-as -c %s -mcpu=mips4 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS4-EB-AS %s
// MIPS4-EB-AS: as{{(.exe)?}}" "-march" "mips4" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -### -no-integrated-as -c %s -mcpu=mips5 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS5-EB-AS %s
// MIPS5-EB-AS: as{{(.exe)?}}" "-march" "mips5" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -c %s -mcpu=mips32 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS32-EB-AS %s
// MIPS32-EB-AS: as{{(.exe)?}}" "-march" "mips32" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
// MIPS32-EB-AS-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-KPIC"
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -c %s -mcpu=mips32r6 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS32R6-EB-AS %s
// MIPS32R6-EB-AS: as{{(.exe)?}}" "-march" "mips32r6" "-mabi" "32" "-mno-shared" "-call_nonpic" "-EB"
// MIPS32R6-EB-AS-NOT: "{{[ A-Za-z\\\/]*}}as{{(.exe)?}}{{.*}}"-KPIC"
//
// RUN: %clang -target mips64-linux-gnu -### -no-integrated-as -c %s -mcpu=mips64 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS64-EB-AS %s
// MIPS64-EB-AS: as{{(.exe)?}}" "-march" "mips64" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips64-linux-gnu -### -no-integrated-as -c %s -mcpu=mips64r6 \
// RUN: 2>&1 | FileCheck -check-prefix=MIPS64R6-EB-AS %s
// MIPS64R6-EB-AS: as{{(.exe)?}}" "-march" "mips64r6" "-mabi" "64" "-mno-shared" "-KPIC" "-EB"
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msoft-float -mhard-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=HARDFLOAT --implicit-check-not=-msoft-float %s
// HARDFLOAT: as{{(.exe)?}}"
// HARDFLOAT: -mhard-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -mhard-float -msoft-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SOFTFLOAT --implicit-check-not=-mhard-float %s
// SOFTFLOAT: as{{(.exe)?}}"
// SOFTFLOAT: -msoft-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -mno-odd-spreg -modd-spreg -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=ODDSPREG --implicit-check-not=-mno-odd-spreg %s
// ODDSPREG: as{{(.exe)?}}"
// ODDSPREG: -modd-spreg
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -modd-spreg -mno-odd-spreg -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=NOODDSPREG --implicit-check-not=-modd-spreg %s
// NOODDSPREG: as{{(.exe)?}}"
// NOODDSPREG: -mno-odd-spreg
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -mdouble-float -msingle-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SINGLEFLOAT --implicit-check-not=-mdouble-float %s
// SINGLEFLOAT: as{{(.exe)?}}"
// SINGLEFLOAT: -msingle-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msingle-float -mdouble-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=DOUBLEFLOAT --implicit-check-not=-msingle-float %s
// DOUBLEFLOAT: as{{(.exe)?}}"
// DOUBLEFLOAT: -mdouble-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msoft-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SOFTFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// SOFTFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// SOFTFLOAT-IMPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msoft-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SOFTFLOAT-EXPLICIT-FPXX %s
// SOFTFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// SOFTFLOAT-EXPLICIT-FPXX: -mfpxx
// SOFTFLOAT-EXPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-mti-linux-gnu -### -no-integrated-as -msoft-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MTI-SOFTFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// MTI-SOFTFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// MTI-SOFTFLOAT-IMPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-mti-linux-gnu -### -no-integrated-as -msoft-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MTI-SOFTFLOAT-EXPLICIT-FPXX %s
// MTI-SOFTFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// MTI-SOFTFLOAT-EXPLICIT-FPXX: -mfpxx
// MTI-SOFTFLOAT-EXPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-img-linux-gnu -### -no-integrated-as -msoft-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IMG-SOFTFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// IMG-SOFTFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// IMG-SOFTFLOAT-IMPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-img-linux-gnu -### -no-integrated-as -msoft-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IMG-SOFTFLOAT-EXPLICIT-FPXX %s
// IMG-SOFTFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// IMG-SOFTFLOAT-EXPLICIT-FPXX: -mfpxx
// IMG-SOFTFLOAT-EXPLICIT-FPXX: -msoft-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msingle-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SINGLEFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// SINGLEFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// SINGLEFLOAT-IMPLICIT-FPXX: -msingle-float
//
// RUN: %clang -target mips-linux-gnu -### -no-integrated-as -msingle-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=SINGLEFLOAT-EXPLICIT-FPXX %s
// SINGLEFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// SINGLEFLOAT-EXPLICIT-FPXX: -mfpxx
// SINGLEFLOAT-EXPLICIT-FPXX: -msingle-float
//
// RUN: %clang -target mips-mti-linux-gnu -### -no-integrated-as -msingle-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MTI-SINGLEFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// MTI-SINGLEFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// MTI-SINGLEFLOAT-IMPLICIT-FPXX: -msingle-float
//
// RUN: %clang -target mips-mti-linux-gnu -### -no-integrated-as -msingle-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=MTI-SINGLEFLOAT-EXPLICIT-FPXX %s
// MTI-SINGLEFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// MTI-SINGLEFLOAT-EXPLICIT-FPXX: -mfpxx
// MTI-SINGLEFLOAT-EXPLICIT-FPXX: -msingle-float
//
// RUN: %clang -target mips-img-linux-gnu -### -no-integrated-as -msingle-float -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IMG-SINGLEFLOAT-IMPLICIT-FPXX --implicit-check-not=-mfpxx %s
// IMG-SINGLEFLOAT-IMPLICIT-FPXX: as{{(.exe)?}}"
// IMG-SINGLEFLOAT-IMPLICIT-FPXX: -msingle-float
//
// RUN: %clang -target mips-img-linux-gnu -### -no-integrated-as -msingle-float -mfpxx -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=IMG-SINGLEFLOAT-EXPLICIT-FPXX %s
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: as{{(.exe)?}}"
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: -mfpxx
// IMG-SINGLEFLOAT-EXPLICIT-FPXX: -msingle-float
|
the_stack_data/97011909.c | #include <stdio.h>
enum coordinate_type {RECT=1,POLAR};
int main(void){
//int RECT;
printf("%d %d\n",RECT,POLAR);
return 0;
}
|
the_stack_data/72013055.c | #include <stdio.h>
int a[10];
int main(){
for(int i=0;i<10;i++)
a[i] = i+1;
for(int i=0;i<10;i++)
printf("%d\n", a[i]);
return 0;
}
|
the_stack_data/159514967.c | /*CH-230-A
Urfan Alvani
[email protected] */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
double scalar(double v[],double w[],int n)
{
double sum=0;
for(int i=0;i<n;i++)
{
sum+=(v[i]*w[i]);
}
return sum;
}
void smallest(double n[],int i)
{
double a;
int b;
a=n[0];
b=0;
for(int x=1;x<i;x++)
{
if(n[x]<a);
{
a=n[x];
b=x;
}
}
printf("The smallest=%f\n",a);
printf("Position of smallest= %d\n",b);
}
void largest(double n[],int i)
{
double a;
int b;
a=n[0];
b=0;
for(int x=1;x<i;x++)
{
if(n[x]>a)
{
a=n[x];
b=x;
}
}
printf("The largest = %lf\n",a);
printf("Position of largest = %d\n",b);
}
int main()
{
int n;
scanf("%d",&n);
double v[n],w[n];
for(int i=0;i<n;i++)
{
scanf("%lf",&v[i]);
}
for(int i=0;i<n;i++)
{
scanf("%lf",&w[i]);
}
printf("Scalar product=%lf\n",scalar(v,w,n));
smallest(v,n);
largest(v,n);
smallest(w,n);
largest(w,n);
return 0;
}
|
the_stack_data/4101.c | #include <stdio.h>
int main(void) {
int a, b;
char str[10];
scanf("%d %d", &a, &b);
int sum = a + b;
if (sum < 0) {
sum = -sum;
putchar('-');
}
int len = sprintf(str, "%d", sum);
int n = (len - 1) / 3;
int pos = len - n * 3;
for (int i = 0; i < len; i++) {
if (pos == i) {
pos = pos + 3;
putchar(',');
}
putchar(str[i]);
}
} |
the_stack_data/811923.c | // Copyright 2019 Google LLC
//
// 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ptrace.h>
int sumsymbol = 5;
typedef struct sum_params_s {
int a;
int b;
int ret;
} sum_params;
extern int ftest(FILE *f) {
return f->_offset;
}
extern int sum(int a, int b) {
return a + b;
}
extern void sums(sum_params* params) {
params->ret = params->a + params->b;
}
extern long double addf(float a, double b, long double c) {
return a + b + c;
}
extern int sub(int a, int b) {
return a - b;
}
extern int mul(int a, int b) {
return a * b;
}
extern int divs(int a, int b) {
return a / b;
}
extern double muld(double a, float b) {
return a * b;
}
extern void crash(void) {
void(*die)() = (void(*)())(0x0000dead);
die();
}
extern void violate(void) {
// Issue a PTRACE_CONT that will always fail, since we are not in stopped
// state. The actual call should be caught by the sandbox policy.
ptrace(PTRACE_CONT, 0, NULL, NULL);
}
extern int sumarr(int* input, size_t nelem) {
int s = 0, i;
for (i = 0; i < nelem; i++) {
s += input[i];
}
return s;
}
extern void testptr(void *ptr) {
if (ptr) {
puts("Is Not a NULL-ptr");
} else {
puts("Is a NULL-ptr");
}
}
extern int read_int(int fd) {
char buf[10] = {0};
int ret = read(fd, buf, sizeof(buf) - 1);
if(ret > 0) {
ret = atoi(buf);
}
return ret;
}
extern void sleep_for_sec(int sec) {
sleep(sec);
}
|
the_stack_data/9511476.c | /*
* Copyright (c) 2017, 2018, Oracle and/or its affiliates.
*
* 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 copyright holder nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int main() {
int shift = sizeof(int) * 8 - 1;
return (-1 >> shift) + 2;
}
|
the_stack_data/918956.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <scsi/sg.h>
int main(int argc, char *argv[])
{
int fd;
if (argc != 2) {
printf("Usage: %s <path to sg device of LTO drive>\n", argv[0]);
return 1;
}
fd = open(argv[1], O_RDWR);
if (fd < 0) {
puts("Error!");
return 1;
}
struct sg_io_hdr scsi_cmd;
unsigned char cmd[] = {0x4D, 0x00, 0x31 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00};
unsigned char dxfer[36];
memset(&scsi_cmd, 0, sizeof(scsi_cmd));
memset(&dxfer, 0, sizeof(dxfer));
scsi_cmd.interface_id = 'S';
scsi_cmd.dxfer_direction = SG_DXFER_FROM_DEV;
scsi_cmd.cmd_len = sizeof(cmd);
scsi_cmd.cmdp = cmd;
scsi_cmd.dxfer_len = sizeof(dxfer);
scsi_cmd.dxferp = dxfer;
ioctl(fd, SG_IO, &scsi_cmd);
unsigned int tmp;
tmp = dxfer[11] | (dxfer[10] << 8) | (dxfer[9] << 16) | (dxfer[8] << 24);
printf("Remaining (Partition 0): %u MiB / ", tmp);
tmp = dxfer[27] | (dxfer[26] << 8) | (dxfer[25] << 16) | (dxfer[24] << 24);
printf("%d MiB\n", tmp);
tmp = dxfer[19] | (dxfer[18] << 8) | (dxfer[17] << 16) | (dxfer[16] << 24);
printf("Remaining (Partition 1): %u MiB / ", tmp);
tmp = dxfer[35] | (dxfer[34] << 8) | (dxfer[33] << 16) | (dxfer[32] << 24);
printf("%d MiB\n", tmp);
close(fd);
return 0;
}
|
the_stack_data/65584.c |
#line 3 "lex.yy.c"
#define YY_INT_ALIGNED short int
/* A lexical scanner generated by flex */
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 6
#define YY_FLEX_SUBMINOR_VERSION 4
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
/* First, we deal with platform-specific or compiler-specific issues. */
/* begin standard C headers. */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
/* end standard C headers. */
/* flex integer type definitions */
#ifndef FLEXINT_H
#define FLEXINT_H
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
* if you want the limit (max/min) macros for int types.
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS 1
#endif
#include <inttypes.h>
typedef int8_t flex_int8_t;
typedef uint8_t flex_uint8_t;
typedef int16_t flex_int16_t;
typedef uint16_t flex_uint16_t;
typedef int32_t flex_int32_t;
typedef uint32_t flex_uint32_t;
#else
typedef signed char flex_int8_t;
typedef short int flex_int16_t;
typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
/* Limits of integral types. */
#ifndef INT8_MIN
#define INT8_MIN (-128)
#endif
#ifndef INT16_MIN
#define INT16_MIN (-32767-1)
#endif
#ifndef INT32_MIN
#define INT32_MIN (-2147483647-1)
#endif
#ifndef INT8_MAX
#define INT8_MAX (127)
#endif
#ifndef INT16_MAX
#define INT16_MAX (32767)
#endif
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX (255U)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX (65535U)
#endif
#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif
#ifndef SIZE_MAX
#define SIZE_MAX (~(size_t)0)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
/* begin standard C++ headers. */
/* TODO: this is always defined, so inline it */
#define yyconst const
#if defined(__GNUC__) && __GNUC__ >= 3
#define yynoreturn __attribute__((__noreturn__))
#else
#define yynoreturn
#endif
/* Returned upon end-of-file. */
#define YY_NULL 0
/* Promotes a possibly negative, possibly signed char to an
* integer in range [0..255] for use as an array index.
*/
#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
/* Enter a start condition. This macro really ought to take a parameter,
* but we do it the disgusting crufty way forced on us by the ()-less
* definition of BEGIN.
*/
#define BEGIN (yy_start) = 1 + 2 *
/* Translate the current start state into a value that can be later handed
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START (((yy_start) - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
/* Special action meaning "start processing a new file". */
#define YY_NEW_FILE yyrestart( yyin )
#define YY_END_OF_BUFFER_CHAR 0
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
*/
#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
#define YY_TYPEDEF_YY_BUFFER_STATE
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
extern int yyleng;
extern FILE *yyin, *yyout;
#define EOB_ACT_CONTINUE_SCAN 0
#define EOB_ACT_END_OF_FILE 1
#define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
do \
{ \
/* Undo effects of setting up yytext. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
*yy_cp = (yy_hold_char); \
YY_RESTORE_YY_MORE_OFFSET \
(yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
YY_DO_BEFORE_ACTION; /* set up yytext again */ \
} \
while ( 0 )
#define unput(c) yyunput( c, (yytext_ptr) )
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
{
FILE *yy_input_file;
char *yy_ch_buf; /* input buffer */
char *yy_buf_pos; /* current position in input buffer */
/* Size of input buffer in bytes, not including room for EOB
* characters.
*/
int yy_buf_size;
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
* delete it.
*/
int yy_is_our_buffer;
/* Whether this is an "interactive" input source; if so, and
* if we're using stdio for input, then we want to use getc()
* instead of fread(), to make sure we stop fetching input after
* each newline.
*/
int yy_is_interactive;
/* Whether we're considered to be at the beginning of a line.
* If so, '^' rules will be active on the next match, otherwise
* not.
*/
int yy_at_bol;
int yy_bs_lineno; /**< The line count. */
int yy_bs_column; /**< The column count. */
/* Whether to try to fill the input buffer when we reach the
* end of it.
*/
int yy_fill_buffer;
int yy_buffer_status;
#define YY_BUFFER_NEW 0
#define YY_BUFFER_NORMAL 1
/* When an EOF's been seen but there's still some text to process
* then we mark the buffer as YY_EOF_PENDING, to indicate that we
* shouldn't try reading from the input source any more. We might
* still have a bunch of tokens to match, though, because of
* possible backing-up.
*
* When we actually see the EOF, we change the status to "new"
* (via yyrestart()), so that the user can continue scanning by
* just pointing yyin at a new input file.
*/
#define YY_BUFFER_EOF_PENDING 2
};
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
/* Stack of input buffers. */
static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */
static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */
static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */
/* We provide macros for accessing buffer states in case in the
* future we want to put the buffer states in a more general
* "scanner state".
*
* Returns the top of the stack, or NULL.
*/
#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
? (yy_buffer_stack)[(yy_buffer_stack_top)] \
: NULL)
/* Same as previous macro, but useful when we know that the buffer stack is not
* NULL or when we need an lvalue. For internal use only.
*/
#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
int yyleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = NULL;
static int yy_init = 0; /* whether we need to initialize */
static int yy_start = 0; /* start state number */
/* Flag which is used to allow yywrap()'s to do buffer switches
* instead of setting up a fresh yyin. A bit of a hack ...
*/
static int yy_did_buffer_switch_on_eof;
void yyrestart ( FILE *input_file );
void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer );
YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size );
void yy_delete_buffer ( YY_BUFFER_STATE b );
void yy_flush_buffer ( YY_BUFFER_STATE b );
void yypush_buffer_state ( YY_BUFFER_STATE new_buffer );
void yypop_buffer_state ( void );
static void yyensure_buffer_stack ( void );
static void yy_load_buffer_state ( void );
static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file );
#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER )
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size );
YY_BUFFER_STATE yy_scan_string ( const char *yy_str );
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len );
void *yyalloc ( yy_size_t );
void *yyrealloc ( void *, yy_size_t );
void yyfree ( void * );
#define yy_new_buffer yy_create_buffer
#define yy_set_interactive(is_interactive) \
{ \
if ( ! YY_CURRENT_BUFFER ){ \
yyensure_buffer_stack (); \
YY_CURRENT_BUFFER_LVALUE = \
yy_create_buffer( yyin, YY_BUF_SIZE ); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
}
#define yy_set_bol(at_bol) \
{ \
if ( ! YY_CURRENT_BUFFER ){\
yyensure_buffer_stack (); \
YY_CURRENT_BUFFER_LVALUE = \
yy_create_buffer( yyin, YY_BUF_SIZE ); \
} \
YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
}
#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
/* Begin user sect3 */
typedef flex_uint8_t YY_CHAR;
FILE *yyin = NULL, *yyout = NULL;
typedef int yy_state_type;
extern int yylineno;
int yylineno = 1;
extern char *yytext;
#ifdef yytext_ptr
#undef yytext_ptr
#endif
#define yytext_ptr yytext
static yy_state_type yy_get_previous_state ( void );
static yy_state_type yy_try_NUL_trans ( yy_state_type current_state );
static int yy_get_next_buffer ( void );
static void yynoreturn yy_fatal_error ( const char* msg );
/* Done after the current pattern has been matched and before the
* corresponding action - sets up yytext.
*/
#define YY_DO_BEFORE_ACTION \
(yytext_ptr) = yy_bp; \
yyleng = (int) (yy_cp - yy_bp); \
(yy_hold_char) = *yy_cp; \
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 4
#define YY_END_OF_BUFFER 5
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
{
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static const flex_int16_t yy_accept[9] =
{ 0,
0, 0, 5, 3, 2, 1, 1, 0
} ;
static const YY_CHAR yy_ec[256] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1
} ;
static const YY_CHAR yy_meta[4] =
{ 0,
1, 1, 2
} ;
static const flex_int16_t yy_base[10] =
{ 0,
0, 0, 5, 6, 6, 0, 0, 6, 2
} ;
static const flex_int16_t yy_def[10] =
{ 0,
8, 1, 8, 8, 8, 9, 9, 0, 8
} ;
static const flex_int16_t yy_nxt[10] =
{ 0,
4, 5, 6, 7, 8, 3, 8, 8, 8
} ;
static const flex_int16_t yy_chk[10] =
{ 0,
1, 1, 1, 9, 3, 8, 8, 8, 8
} ;
static yy_state_type yy_last_accepting_state;
static char *yy_last_accepting_cpos;
extern int yy_flex_debug;
int yy_flex_debug = 0;
/* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed.
*/
#define REJECT reject_used_but_not_detected
#define yymore() yymore_used_but_not_detected
#define YY_MORE_ADJ 0
#define YY_RESTORE_YY_MORE_OFFSET
char *yytext;
#line 1 "even.l"
/* */
#line 3 "even.l"
int allEvens = 0;
int i;
#line 445 "lex.yy.c"
#line 446 "lex.yy.c"
#define INITIAL 0
#ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way
* down here because we want the user's section 1 to have been scanned first.
* The user has a chance to override it with an option.
*/
#include <unistd.h>
#endif
#ifndef YY_EXTRA_TYPE
#define YY_EXTRA_TYPE void *
#endif
static int yy_init_globals ( void );
/* Accessor methods to globals.
These are made visible to non-reentrant scanners for convenience. */
int yylex_destroy ( void );
int yyget_debug ( void );
void yyset_debug ( int debug_flag );
YY_EXTRA_TYPE yyget_extra ( void );
void yyset_extra ( YY_EXTRA_TYPE user_defined );
FILE *yyget_in ( void );
void yyset_in ( FILE * _in_str );
FILE *yyget_out ( void );
void yyset_out ( FILE * _out_str );
int yyget_leng ( void );
char *yyget_text ( void );
int yyget_lineno ( void );
void yyset_lineno ( int _line_number );
/* Macros after this point can all be overridden by user definitions in
* section 1.
*/
#ifndef YY_SKIP_YYWRAP
#ifdef __cplusplus
extern "C" int yywrap ( void );
#else
extern int yywrap ( void );
#endif
#endif
#ifndef YY_NO_UNPUT
static void yyunput ( int c, char *buf_ptr );
#endif
#ifndef yytext_ptr
static void yy_flex_strncpy ( char *, const char *, int );
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen ( const char * );
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput ( void );
#else
static int input ( void );
#endif
#endif
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
#ifndef ECHO
/* This used to be an fputs(), but since the string might contain NUL's,
* we now use fwrite().
*/
#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
#endif
/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL,
* is returned in "result".
*/
#ifndef YY_INPUT
#define YY_INPUT(buf,result,max_size) \
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
int n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
if ( c == '\n' ) \
buf[n++] = (char) c; \
if ( c == EOF && ferror( yyin ) ) \
YY_FATAL_ERROR( "input in flex scanner failed" ); \
result = n; \
} \
else \
{ \
errno=0; \
while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
{ \
if( errno != EINTR) \
{ \
YY_FATAL_ERROR( "input in flex scanner failed" ); \
break; \
} \
errno=0; \
clearerr(yyin); \
} \
}\
\
#endif
/* No semi-colon after return; correct usage is to write "yyterminate();" -
* we don't want an extra ';' after the "return" because that will cause
* some compilers to complain about unreachable statements.
*/
#ifndef yyterminate
#define yyterminate() return YY_NULL
#endif
/* Number of entries by which start-condition stack grows. */
#ifndef YY_START_STACK_INCR
#define YY_START_STACK_INCR 25
#endif
/* Report a fatal error. */
#ifndef YY_FATAL_ERROR
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg )
#endif
/* end tables serialization structures and prototypes */
/* Default declaration of generated scanner - a define so the user can
* easily add parameters.
*/
#ifndef YY_DECL
#define YY_DECL_IS_OURS 1
extern int yylex (void);
#define YY_DECL int yylex (void)
#endif /* !YY_DECL */
/* Code executed at the beginning of each rule, after yytext and yyleng
* have been set up.
*/
#ifndef YY_USER_ACTION
#define YY_USER_ACTION
#endif
/* Code executed at the end of each rule. */
#ifndef YY_BREAK
#define YY_BREAK /*LINTED*/break;
#endif
#define YY_RULE_SETUP \
YY_USER_ACTION
/** The main scanner function which does all the work.
*/
YY_DECL
{
yy_state_type yy_current_state;
char *yy_cp, *yy_bp;
int yy_act;
if ( !(yy_init) )
{
(yy_init) = 1;
#ifdef YY_USER_INIT
YY_USER_INIT;
#endif
if ( ! (yy_start) )
(yy_start) = 1; /* first start state */
if ( ! yyin )
yyin = stdin;
if ( ! yyout )
yyout = stdout;
if ( ! YY_CURRENT_BUFFER ) {
yyensure_buffer_stack ();
YY_CURRENT_BUFFER_LVALUE =
yy_create_buffer( yyin, YY_BUF_SIZE );
}
yy_load_buffer_state( );
}
{
#line 7 "even.l"
#line 665 "lex.yy.c"
while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */
{
yy_cp = (yy_c_buf_p);
/* Support of yytext. */
*yy_cp = (yy_hold_char);
/* yy_bp points to the position in yy_ch_buf of the start of
* the current run.
*/
yy_bp = yy_cp;
yy_current_state = (yy_start);
yy_match:
do
{
YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 9 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 6 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
if ( yy_act == 0 )
{ /* have to back up */
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
yy_act = yy_accept[yy_current_state];
}
YY_DO_BEFORE_ACTION;
do_action: /* This label is used only to access EOF actions. */
switch ( yy_act )
{ /* beginning of action switch */
case 0: /* must back up */
/* undo the effects of YY_DO_BEFORE_ACTION */
*yy_cp = (yy_hold_char);
yy_cp = (yy_last_accepting_cpos);
yy_current_state = (yy_last_accepting_state);
goto yy_find_action;
case 1:
YY_RULE_SETUP
#line 8 "even.l"
{ i = atoi(yytext); if(i%2==0){allEvens++;} }
YY_BREAK
case 2:
/* rule 2 can match eol */
YY_RULE_SETUP
#line 9 "even.l"
{}
YY_BREAK
case 3:
YY_RULE_SETUP
#line 10 "even.l"
{}
YY_BREAK
case 4:
YY_RULE_SETUP
#line 11 "even.l"
ECHO;
YY_BREAK
#line 743 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
case YY_END_OF_BUFFER:
{
/* Amount of text matched not including the EOB char. */
int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1;
/* Undo the effects of YY_DO_BEFORE_ACTION. */
*yy_cp = (yy_hold_char);
YY_RESTORE_YY_MORE_OFFSET
if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
{
/* We're scanning a new file or input source. It's
* possible that this happened because the user
* just pointed yyin at a new source and called
* yylex(). If so, then we have to assure
* consistency between YY_CURRENT_BUFFER and our
* globals. Here is the right place to do so, because
* this is the first action (other than possibly a
* back-up) that will match for the new input source.
*/
(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
}
/* Note that here we test for yy_c_buf_p "<=" to the position
* of the first EOB in the buffer, since yy_c_buf_p will
* already have been incremented past the NUL character
* (since all states make transitions on EOB to the
* end-of-buffer state). Contrast this with the test
* in input().
*/
if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
{ /* This was really a NUL. */
yy_state_type yy_next_state;
(yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state( );
/* Okay, we're now positioned to make the NUL
* transition. We couldn't have
* yy_get_previous_state() go ahead and do it
* for us because it doesn't know how to deal
* with the possibility of jamming (and we don't
* want to build jamming into it because then it
* will run more slowly).
*/
yy_next_state = yy_try_NUL_trans( yy_current_state );
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
if ( yy_next_state )
{
/* Consume the NUL. */
yy_cp = ++(yy_c_buf_p);
yy_current_state = yy_next_state;
goto yy_match;
}
else
{
yy_cp = (yy_c_buf_p);
goto yy_find_action;
}
}
else switch ( yy_get_next_buffer( ) )
{
case EOB_ACT_END_OF_FILE:
{
(yy_did_buffer_switch_on_eof) = 0;
if ( yywrap( ) )
{
/* Note: because we've taken care in
* yy_get_next_buffer() to have set up
* yytext, we can now set up
* yy_c_buf_p so that if some total
* hoser (like flex itself) wants to
* call the scanner after we return the
* YY_NULL, it'll still work - another
* YY_NULL will get returned.
*/
(yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ;
yy_act = YY_STATE_EOF(YY_START);
goto do_action;
}
else
{
if ( ! (yy_did_buffer_switch_on_eof) )
YY_NEW_FILE;
}
break;
}
case EOB_ACT_CONTINUE_SCAN:
(yy_c_buf_p) =
(yytext_ptr) + yy_amount_of_matched_text;
yy_current_state = yy_get_previous_state( );
yy_cp = (yy_c_buf_p);
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
goto yy_match;
case EOB_ACT_LAST_MATCH:
(yy_c_buf_p) =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)];
yy_current_state = yy_get_previous_state( );
yy_cp = (yy_c_buf_p);
yy_bp = (yytext_ptr) + YY_MORE_ADJ;
goto yy_find_action;
}
break;
}
default:
YY_FATAL_ERROR(
"fatal flex scanner internal error--no action found" );
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
*
* Returns a code representing an action:
* EOB_ACT_LAST_MATCH -
* EOB_ACT_CONTINUE_SCAN - continue scanning from current position
* EOB_ACT_END_OF_FILE - end of file
*/
static int yy_get_next_buffer (void)
{
char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
char *source = (yytext_ptr);
int number_to_move, i;
int ret_val;
if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] )
YY_FATAL_ERROR(
"fatal flex scanner internal error--end of buffer missed" );
if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
{ /* Don't try to fill the buffer, so this is an EOF. */
if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 )
{
/* We matched a single character, the EOB, so
* treat this as a final EOF.
*/
return EOB_ACT_END_OF_FILE;
}
else
{
/* We matched some text prior to the EOB, first
* process it.
*/
return EOB_ACT_LAST_MATCH;
}
}
/* Try to read more data. */
/* First move last chars to start of buffer. */
number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr) - 1);
for ( i = 0; i < number_to_move; ++i )
*(dest++) = *(source++);
if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
/* don't do the read, it's not guaranteed to return an EOF,
* just force an EOF
*/
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0;
else
{
int num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
else
b->yy_buf_size *= 2;
b->yy_ch_buf = (char *)
/* Include room in for 2 EOB chars. */
yyrealloc( (void *) b->yy_ch_buf,
(yy_size_t) (b->yy_buf_size + 2) );
}
else
/* Can't grow it, we don't own it. */
b->yy_ch_buf = NULL;
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR(
"fatal error - scanner input buffer overflow" );
(yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset];
num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
number_to_move - 1;
}
if ( num_to_read > YY_READ_BUF_SIZE )
num_to_read = YY_READ_BUF_SIZE;
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
(yy_n_chars), num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
if ( (yy_n_chars) == 0 )
{
if ( number_to_move == YY_MORE_ADJ )
{
ret_val = EOB_ACT_END_OF_FILE;
yyrestart( yyin );
}
else
{
ret_val = EOB_ACT_LAST_MATCH;
YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
YY_BUFFER_EOF_PENDING;
}
}
else
ret_val = EOB_ACT_CONTINUE_SCAN;
if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
/* Extend the array by 50%, plus the number we really need. */
int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1);
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
(void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size );
if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
/* "- 2" to take care of EOB's */
YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
}
(yy_n_chars) += number_to_move;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR;
YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR;
(yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
return ret_val;
}
/* yy_get_previous_state - get the state just before the EOB char was reached */
static yy_state_type yy_get_previous_state (void)
{
yy_state_type yy_current_state;
char *yy_cp;
yy_current_state = (yy_start);
for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp )
{
YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 9 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
}
return yy_current_state;
}
/* yy_try_NUL_trans - try to make a transition on the NUL character
*
* synopsis
* next_state = yy_try_NUL_trans( current_state );
*/
static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state )
{
int yy_is_jam;
char *yy_cp = (yy_c_buf_p);
YY_CHAR yy_c = 1;
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
(yy_last_accepting_cpos) = yy_cp;
}
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 9 )
yy_c = yy_meta[yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
yy_is_jam = (yy_current_state == 8);
return yy_is_jam ? 0 : yy_current_state;
}
#ifndef YY_NO_UNPUT
static void yyunput (int c, char * yy_bp )
{
char *yy_cp;
yy_cp = (yy_c_buf_p);
/* undo effects of setting up yytext */
*yy_cp = (yy_hold_char);
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
int number_to_move = (yy_n_chars) + 2;
char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
char *source =
&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move];
while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
*--dest = *--source;
yy_cp += (int) (dest - source);
yy_bp += (int) (dest - source);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars =
(yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
YY_FATAL_ERROR( "flex scanner push-back overflow" );
}
*--yy_cp = (char) c;
(yytext_ptr) = yy_bp;
(yy_hold_char) = *yy_cp;
(yy_c_buf_p) = yy_cp;
}
#endif
#ifndef YY_NO_INPUT
#ifdef __cplusplus
static int yyinput (void)
#else
static int input (void)
#endif
{
int c;
*(yy_c_buf_p) = (yy_hold_char);
if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR )
{
/* yy_c_buf_p now points to the character we want to return.
* If this occurs *before* the EOB characters, then it's a
* valid NUL; if not, then we've hit the end of the buffer.
*/
if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
/* This was really a NUL. */
*(yy_c_buf_p) = '\0';
else
{ /* need more input */
int offset = (int) ((yy_c_buf_p) - (yytext_ptr));
++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) )
{
case EOB_ACT_LAST_MATCH:
/* This happens because yy_g_n_b()
* sees that we've accumulated a
* token and flags that we need to
* try matching the token before
* proceeding. But for input(),
* there's no matching to consider.
* So convert the EOB_ACT_LAST_MATCH
* to EOB_ACT_END_OF_FILE.
*/
/* Reset buffer status. */
yyrestart( yyin );
/*FALLTHROUGH*/
case EOB_ACT_END_OF_FILE:
{
if ( yywrap( ) )
return 0;
if ( ! (yy_did_buffer_switch_on_eof) )
YY_NEW_FILE;
#ifdef __cplusplus
return yyinput();
#else
return input();
#endif
}
case EOB_ACT_CONTINUE_SCAN:
(yy_c_buf_p) = (yytext_ptr) + offset;
break;
}
}
}
c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */
*(yy_c_buf_p) = '\0'; /* preserve yytext */
(yy_hold_char) = *++(yy_c_buf_p);
return c;
}
#endif /* ifndef YY_NO_INPUT */
/** Immediately switch to a different input stream.
* @param input_file A readable stream.
*
* @note This function does not reset the start condition to @c INITIAL .
*/
void yyrestart (FILE * input_file )
{
if ( ! YY_CURRENT_BUFFER ){
yyensure_buffer_stack ();
YY_CURRENT_BUFFER_LVALUE =
yy_create_buffer( yyin, YY_BUF_SIZE );
}
yy_init_buffer( YY_CURRENT_BUFFER, input_file );
yy_load_buffer_state( );
}
/** Switch to a different input buffer.
* @param new_buffer The new input buffer.
*
*/
void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer )
{
/* TODO. We should be able to replace this entire function body
* with
* yypop_buffer_state();
* yypush_buffer_state(new_buffer);
*/
yyensure_buffer_stack ();
if ( YY_CURRENT_BUFFER == new_buffer )
return;
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
YY_CURRENT_BUFFER_LVALUE = new_buffer;
yy_load_buffer_state( );
/* We don't actually know whether we did this switch during
* EOF (yywrap()) processing, but the only time this flag
* is looked at is after yywrap() is called, so it's safe
* to go ahead and always set it.
*/
(yy_did_buffer_switch_on_eof) = 1;
}
static void yy_load_buffer_state (void)
{
(yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
(yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
(yy_hold_char) = *(yy_c_buf_p);
}
/** Allocate and initialize an input buffer state.
* @param file A readable stream.
* @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
*
* @return the allocated buffer state.
*/
YY_BUFFER_STATE yy_create_buffer (FILE * file, int size )
{
YY_BUFFER_STATE b;
b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_buf_size = size;
/* yy_ch_buf has to be 2 characters longer than the size given because
* we need to put in 2 end-of-buffer characters.
*/
b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) );
if ( ! b->yy_ch_buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
b->yy_is_our_buffer = 1;
yy_init_buffer( b, file );
return b;
}
/** Destroy the buffer.
* @param b a buffer created with yy_create_buffer()
*
*/
void yy_delete_buffer (YY_BUFFER_STATE b )
{
if ( ! b )
return;
if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
if ( b->yy_is_our_buffer )
yyfree( (void *) b->yy_ch_buf );
yyfree( (void *) b );
}
/* Initializes or reinitializes a buffer.
* This function is sometimes called more than once on the same buffer,
* such as during a yyrestart() or at EOF.
*/
static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file )
{
int oerrno = errno;
yy_flush_buffer( b );
b->yy_input_file = file;
b->yy_fill_buffer = 1;
/* If b is the current buffer, then yy_init_buffer was _probably_
* called from yyrestart() or through yy_get_next_buffer.
* In that case, we don't want to reset the lineno or column.
*/
if (b != YY_CURRENT_BUFFER){
b->yy_bs_lineno = 1;
b->yy_bs_column = 0;
}
b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
errno = oerrno;
}
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
* @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
*
*/
void yy_flush_buffer (YY_BUFFER_STATE b )
{
if ( ! b )
return;
b->yy_n_chars = 0;
/* We always need two end-of-buffer characters. The first causes
* a transition to the end-of-buffer state. The second causes
* a jam in that state.
*/
b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
b->yy_buf_pos = &b->yy_ch_buf[0];
b->yy_at_bol = 1;
b->yy_buffer_status = YY_BUFFER_NEW;
if ( b == YY_CURRENT_BUFFER )
yy_load_buffer_state( );
}
/** Pushes the new state onto the stack. The new state becomes
* the current state. This function will allocate the stack
* if necessary.
* @param new_buffer The new state.
*
*/
void yypush_buffer_state (YY_BUFFER_STATE new_buffer )
{
if (new_buffer == NULL)
return;
yyensure_buffer_stack();
/* This block is copied from yy_switch_to_buffer. */
if ( YY_CURRENT_BUFFER )
{
/* Flush out information for old buffer. */
*(yy_c_buf_p) = (yy_hold_char);
YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p);
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
/* Only push if top exists. Otherwise, replace top. */
if (YY_CURRENT_BUFFER)
(yy_buffer_stack_top)++;
YY_CURRENT_BUFFER_LVALUE = new_buffer;
/* copied from yy_switch_to_buffer. */
yy_load_buffer_state( );
(yy_did_buffer_switch_on_eof) = 1;
}
/** Removes and deletes the top of the stack, if present.
* The next element becomes the new top.
*
*/
void yypop_buffer_state (void)
{
if (!YY_CURRENT_BUFFER)
return;
yy_delete_buffer(YY_CURRENT_BUFFER );
YY_CURRENT_BUFFER_LVALUE = NULL;
if ((yy_buffer_stack_top) > 0)
--(yy_buffer_stack_top);
if (YY_CURRENT_BUFFER) {
yy_load_buffer_state( );
(yy_did_buffer_switch_on_eof) = 1;
}
}
/* Allocates the stack if it does not exist.
* Guarantees space for at least one push.
*/
static void yyensure_buffer_stack (void)
{
yy_size_t num_to_alloc;
if (!(yy_buffer_stack)) {
/* First allocation is just for 2 elements, since we don't know if this
* scanner will even need a stack. We use 2 instead of 1 to avoid an
* immediate realloc on the next call.
*/
num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
(yy_buffer_stack) = (struct yy_buffer_state**)yyalloc
(num_to_alloc * sizeof(struct yy_buffer_state*)
);
if ( ! (yy_buffer_stack) )
YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
(yy_buffer_stack_max) = num_to_alloc;
(yy_buffer_stack_top) = 0;
return;
}
if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){
/* Increase the buffer to prepare for a possible push. */
yy_size_t grow_size = 8 /* arbitrary grow size */;
num_to_alloc = (yy_buffer_stack_max) + grow_size;
(yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc
((yy_buffer_stack),
num_to_alloc * sizeof(struct yy_buffer_state*)
);
if ( ! (yy_buffer_stack) )
YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
/* zero only the new slots.*/
memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*));
(yy_buffer_stack_max) = num_to_alloc;
}
}
/** Setup the input buffer state to scan directly from a user-specified character buffer.
* @param base the character buffer
* @param size the size in bytes of the character buffer
*
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size )
{
YY_BUFFER_STATE b;
if ( size < 2 ||
base[size-2] != YY_END_OF_BUFFER_CHAR ||
base[size-1] != YY_END_OF_BUFFER_CHAR )
/* They forgot to leave room for the EOB's. */
return NULL;
b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) );
if ( ! b )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */
b->yy_buf_pos = b->yy_ch_buf = base;
b->yy_is_our_buffer = 0;
b->yy_input_file = NULL;
b->yy_n_chars = b->yy_buf_size;
b->yy_is_interactive = 0;
b->yy_at_bol = 1;
b->yy_fill_buffer = 0;
b->yy_buffer_status = YY_BUFFER_NEW;
yy_switch_to_buffer( b );
return b;
}
/** Setup the input buffer state to scan a string. The next call to yylex() will
* scan from a @e copy of @a str.
* @param yystr a NUL-terminated string to scan
*
* @return the newly allocated buffer state object.
* @note If you want to scan bytes that may contain NUL values, then use
* yy_scan_bytes() instead.
*/
YY_BUFFER_STATE yy_scan_string (const char * yystr )
{
return yy_scan_bytes( yystr, (int) strlen(yystr) );
}
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
* scan from a @e copy of @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
*
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len )
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
int i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = (yy_size_t) (_yybytes_len + 2);
buf = (char *) yyalloc( n );
if ( ! buf )
YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
for ( i = 0; i < _yybytes_len; ++i )
buf[i] = yybytes[i];
buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
b = yy_scan_buffer( buf, n );
if ( ! b )
YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
/* It's okay to grow etc. this buffer, and we should throw it
* away when we're done.
*/
b->yy_is_our_buffer = 1;
return b;
}
#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif
static void yynoreturn yy_fatal_error (const char* msg )
{
fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
/* Redefine yyless() so it works in section 3 code. */
#undef yyless
#define yyless(n) \
do \
{ \
/* Undo effects of setting up yytext. */ \
int yyless_macro_arg = (n); \
YY_LESS_LINENO(yyless_macro_arg);\
yytext[yyleng] = (yy_hold_char); \
(yy_c_buf_p) = yytext + yyless_macro_arg; \
(yy_hold_char) = *(yy_c_buf_p); \
*(yy_c_buf_p) = '\0'; \
yyleng = yyless_macro_arg; \
} \
while ( 0 )
/* Accessor methods (get/set functions) to struct members. */
/** Get the current line number.
*
*/
int yyget_lineno (void)
{
return yylineno;
}
/** Get the input stream.
*
*/
FILE *yyget_in (void)
{
return yyin;
}
/** Get the output stream.
*
*/
FILE *yyget_out (void)
{
return yyout;
}
/** Get the length of the current token.
*
*/
int yyget_leng (void)
{
return yyleng;
}
/** Get the current token.
*
*/
char *yyget_text (void)
{
return yytext;
}
/** Set the current line number.
* @param _line_number line number
*
*/
void yyset_lineno (int _line_number )
{
yylineno = _line_number;
}
/** Set the input stream. This does not discard the current
* input buffer.
* @param _in_str A readable stream.
*
* @see yy_switch_to_buffer
*/
void yyset_in (FILE * _in_str )
{
yyin = _in_str ;
}
void yyset_out (FILE * _out_str )
{
yyout = _out_str ;
}
int yyget_debug (void)
{
return yy_flex_debug;
}
void yyset_debug (int _bdebug )
{
yy_flex_debug = _bdebug ;
}
static int yy_init_globals (void)
{
/* Initialization is the same as for the non-reentrant scanner.
* This function is called from yylex_destroy(), so don't allocate here.
*/
(yy_buffer_stack) = NULL;
(yy_buffer_stack_top) = 0;
(yy_buffer_stack_max) = 0;
(yy_c_buf_p) = NULL;
(yy_init) = 0;
(yy_start) = 0;
/* Defined in main.c */
#ifdef YY_STDINIT
yyin = stdin;
yyout = stdout;
#else
yyin = NULL;
yyout = NULL;
#endif
/* For future reference: Set errno on error, since we are called by
* yylex_init()
*/
return 0;
}
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
int yylex_destroy (void)
{
/* Pop the buffer stack, destroying each element. */
while(YY_CURRENT_BUFFER){
yy_delete_buffer( YY_CURRENT_BUFFER );
YY_CURRENT_BUFFER_LVALUE = NULL;
yypop_buffer_state();
}
/* Destroy the stack itself. */
yyfree((yy_buffer_stack) );
(yy_buffer_stack) = NULL;
/* Reset the globals. This is important in a non-reentrant scanner so the next time
* yylex() is called, initialization will occur. */
yy_init_globals( );
return 0;
}
/*
* Internal utility routines.
*/
#ifndef yytext_ptr
static void yy_flex_strncpy (char* s1, const char * s2, int n )
{
int i;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
#endif
#ifdef YY_NEED_STRLEN
static int yy_flex_strlen (const char * s )
{
int n;
for ( n = 0; s[n]; ++n )
;
return n;
}
#endif
void *yyalloc (yy_size_t size )
{
return malloc(size);
}
void *yyrealloc (void * ptr, yy_size_t size )
{
/* The cast to (char *) in the following accommodates both
* implementations that use char* generic pointers, and those
* that use void* generic pointers. It works with the latter
* because both ANSI C and C++ allow castless assignment from
* any pointer type to void*, and deal with argument conversions
* as though doing an assignment.
*/
return realloc(ptr, size);
}
void yyfree (void * ptr )
{
free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
}
#define YYTABLES_NAME "yytables"
#line 11 "even.l"
int main()
{
yylex();
printf("%d\n",allEvens);
return 0;
}
|
the_stack_data/231392867.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
/* > \brief \b CLANTR returns the value of the 1-norm, or the Frobenius norm, or the infinity norm, or the ele
ment of largest absolute value of a trapezoidal or triangular matrix. */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download CLANTR + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clantr.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clantr.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clantr.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* REAL FUNCTION CLANTR( NORM, UPLO, DIAG, M, N, A, LDA, */
/* WORK ) */
/* CHARACTER DIAG, NORM, UPLO */
/* INTEGER LDA, M, N */
/* REAL WORK( * ) */
/* COMPLEX A( LDA, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > CLANTR returns the value of the one norm, or the Frobenius norm, or */
/* > the infinity norm, or the element of largest absolute value of a */
/* > trapezoidal or triangular matrix A. */
/* > \endverbatim */
/* > */
/* > \return CLANTR */
/* > \verbatim */
/* > */
/* > CLANTR = ( f2cmax(abs(A(i,j))), NORM = 'M' or 'm' */
/* > ( */
/* > ( norm1(A), NORM = '1', 'O' or 'o' */
/* > ( */
/* > ( normI(A), NORM = 'I' or 'i' */
/* > ( */
/* > ( normF(A), NORM = 'F', 'f', 'E' or 'e' */
/* > */
/* > where norm1 denotes the one norm of a matrix (maximum column sum), */
/* > normI denotes the infinity norm of a matrix (maximum row sum) and */
/* > normF denotes the Frobenius norm of a matrix (square root of sum of */
/* > squares). Note that f2cmax(abs(A(i,j))) is not a consistent matrix norm. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] NORM */
/* > \verbatim */
/* > NORM is CHARACTER*1 */
/* > Specifies the value to be returned in CLANTR as described */
/* > above. */
/* > \endverbatim */
/* > */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > Specifies whether the matrix A is upper or lower trapezoidal. */
/* > = 'U': Upper trapezoidal */
/* > = 'L': Lower trapezoidal */
/* > Note that A is triangular instead of trapezoidal if M = N. */
/* > \endverbatim */
/* > */
/* > \param[in] DIAG */
/* > \verbatim */
/* > DIAG is CHARACTER*1 */
/* > Specifies whether or not the matrix A has unit diagonal. */
/* > = 'N': Non-unit diagonal */
/* > = 'U': Unit diagonal */
/* > \endverbatim */
/* > */
/* > \param[in] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The number of rows of the matrix A. M >= 0, and if */
/* > UPLO = 'U', M <= N. When M = 0, CLANTR is set to zero. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of columns of the matrix A. N >= 0, and if */
/* > UPLO = 'L', N <= M. When N = 0, CLANTR is set to zero. */
/* > \endverbatim */
/* > */
/* > \param[in] A */
/* > \verbatim */
/* > A is COMPLEX array, dimension (LDA,N) */
/* > The trapezoidal matrix A (A is triangular if M = N). */
/* > If UPLO = 'U', the leading m by n upper trapezoidal part of */
/* > the array A contains the upper trapezoidal matrix, and the */
/* > strictly lower triangular part of A is not referenced. */
/* > If UPLO = 'L', the leading m by n lower trapezoidal part of */
/* > the array A contains the lower trapezoidal matrix, and the */
/* > strictly upper triangular part of A is not referenced. Note */
/* > that when DIAG = 'U', the diagonal elements of A are not */
/* > referenced and are assumed to be one. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(M,1). */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is REAL array, dimension (MAX(1,LWORK)), */
/* > where LWORK >= M when NORM = 'I'; otherwise, WORK is not */
/* > referenced. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup complexOTHERauxiliary */
/* ===================================================================== */
real clantr_(char *norm, char *uplo, char *diag, integer *m, integer *n,
complex *a, integer *lda, real *work)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2, i__3, i__4;
real ret_val;
/* Local variables */
extern /* Subroutine */ int scombssq_(real *, real *);
integer i__, j;
logical udiag;
extern logical lsame_(char *, char *);
real value;
extern /* Subroutine */ int classq_(integer *, complex *, integer *, real
*, real *);
extern logical sisnan_(real *);
real colssq[2], sum, ssq[2];
/* -- 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 */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--work;
/* Function Body */
if (f2cmin(*m,*n) == 0) {
value = 0.f;
} else if (lsame_(norm, "M")) {
/* Find f2cmax(abs(A(i,j))). */
if (lsame_(diag, "U")) {
value = 1.f;
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
/* Computing MIN */
i__3 = *m, i__4 = j - 1;
i__2 = f2cmin(i__3,i__4);
for (i__ = 1; i__ <= i__2; ++i__) {
sum = c_abs(&a[i__ + j * a_dim1]);
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L10: */
}
/* L20: */
}
} else {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *m;
for (i__ = j + 1; i__ <= i__2; ++i__) {
sum = c_abs(&a[i__ + j * a_dim1]);
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L30: */
}
/* L40: */
}
}
} else {
value = 0.f;
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = f2cmin(*m,j);
for (i__ = 1; i__ <= i__2; ++i__) {
sum = c_abs(&a[i__ + j * a_dim1]);
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L50: */
}
/* L60: */
}
} else {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *m;
for (i__ = j; i__ <= i__2; ++i__) {
sum = c_abs(&a[i__ + j * a_dim1]);
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L70: */
}
/* L80: */
}
}
}
} else if (lsame_(norm, "O") || *(unsigned char *)
norm == '1') {
/* Find norm1(A). */
value = 0.f;
udiag = lsame_(diag, "U");
if (lsame_(uplo, "U")) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
if (udiag && j <= *m) {
sum = 1.f;
i__2 = j - 1;
for (i__ = 1; i__ <= i__2; ++i__) {
sum += c_abs(&a[i__ + j * a_dim1]);
/* L90: */
}
} else {
sum = 0.f;
i__2 = f2cmin(*m,j);
for (i__ = 1; i__ <= i__2; ++i__) {
sum += c_abs(&a[i__ + j * a_dim1]);
/* L100: */
}
}
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L110: */
}
} else {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
if (udiag) {
sum = 1.f;
i__2 = *m;
for (i__ = j + 1; i__ <= i__2; ++i__) {
sum += c_abs(&a[i__ + j * a_dim1]);
/* L120: */
}
} else {
sum = 0.f;
i__2 = *m;
for (i__ = j; i__ <= i__2; ++i__) {
sum += c_abs(&a[i__ + j * a_dim1]);
/* L130: */
}
}
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L140: */
}
}
} else if (lsame_(norm, "I")) {
/* Find normI(A). */
if (lsame_(uplo, "U")) {
if (lsame_(diag, "U")) {
i__1 = *m;
for (i__ = 1; i__ <= i__1; ++i__) {
work[i__] = 1.f;
/* L150: */
}
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
/* Computing MIN */
i__3 = *m, i__4 = j - 1;
i__2 = f2cmin(i__3,i__4);
for (i__ = 1; i__ <= i__2; ++i__) {
work[i__] += c_abs(&a[i__ + j * a_dim1]);
/* L160: */
}
/* L170: */
}
} else {
i__1 = *m;
for (i__ = 1; i__ <= i__1; ++i__) {
work[i__] = 0.f;
/* L180: */
}
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = f2cmin(*m,j);
for (i__ = 1; i__ <= i__2; ++i__) {
work[i__] += c_abs(&a[i__ + j * a_dim1]);
/* L190: */
}
/* L200: */
}
}
} else {
if (lsame_(diag, "U")) {
i__1 = f2cmin(*m,*n);
for (i__ = 1; i__ <= i__1; ++i__) {
work[i__] = 1.f;
/* L210: */
}
i__1 = *m;
for (i__ = *n + 1; i__ <= i__1; ++i__) {
work[i__] = 0.f;
/* L220: */
}
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *m;
for (i__ = j + 1; i__ <= i__2; ++i__) {
work[i__] += c_abs(&a[i__ + j * a_dim1]);
/* L230: */
}
/* L240: */
}
} else {
i__1 = *m;
for (i__ = 1; i__ <= i__1; ++i__) {
work[i__] = 0.f;
/* L250: */
}
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *m;
for (i__ = j; i__ <= i__2; ++i__) {
work[i__] += c_abs(&a[i__ + j * a_dim1]);
/* L260: */
}
/* L270: */
}
}
}
value = 0.f;
i__1 = *m;
for (i__ = 1; i__ <= i__1; ++i__) {
sum = work[i__];
if (value < sum || sisnan_(&sum)) {
value = sum;
}
/* L280: */
}
} else if (lsame_(norm, "F") || lsame_(norm, "E")) {
/* Find normF(A). */
/* SSQ(1) is scale */
/* SSQ(2) is sum-of-squares */
/* For better accuracy, sum each column separately. */
if (lsame_(uplo, "U")) {
if (lsame_(diag, "U")) {
ssq[0] = 1.f;
ssq[1] = (real) f2cmin(*m,*n);
i__1 = *n;
for (j = 2; j <= i__1; ++j) {
colssq[0] = 0.f;
colssq[1] = 1.f;
/* Computing MIN */
i__3 = *m, i__4 = j - 1;
i__2 = f2cmin(i__3,i__4);
classq_(&i__2, &a[j * a_dim1 + 1], &c__1, colssq, &colssq[
1]);
scombssq_(ssq, colssq);
/* L290: */
}
} else {
ssq[0] = 0.f;
ssq[1] = 1.f;
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
colssq[0] = 0.f;
colssq[1] = 1.f;
i__2 = f2cmin(*m,j);
classq_(&i__2, &a[j * a_dim1 + 1], &c__1, colssq, &colssq[
1]);
scombssq_(ssq, colssq);
/* L300: */
}
}
} else {
if (lsame_(diag, "U")) {
ssq[0] = 1.f;
ssq[1] = (real) f2cmin(*m,*n);
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
colssq[0] = 0.f;
colssq[1] = 1.f;
i__2 = *m - j;
/* Computing MIN */
i__3 = *m, i__4 = j + 1;
classq_(&i__2, &a[f2cmin(i__3,i__4) + j * a_dim1], &c__1,
colssq, &colssq[1]);
scombssq_(ssq, colssq);
/* L310: */
}
} else {
ssq[0] = 0.f;
ssq[1] = 1.f;
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
colssq[0] = 0.f;
colssq[1] = 1.f;
i__2 = *m - j + 1;
classq_(&i__2, &a[j + j * a_dim1], &c__1, colssq, &colssq[
1]);
scombssq_(ssq, colssq);
/* L320: */
}
}
}
value = ssq[0] * sqrt(ssq[1]);
}
ret_val = value;
return ret_val;
/* End of CLANTR */
} /* clantr_ */
|
the_stack_data/57949162.c | int f() { return 1; }
int main() {
#pragma spf transform inline
{
if (1)
f();
return 1;
}
}
|
the_stack_data/165766721.c | // This tool is used to generate the various installation files:
// a .deb file which is a shell script for creating a deb and a tarball package
// a .iss file for InnoSetup
// a .mac file, which is a shell script for creating the webots directory
#include <ctype.h> // tolower
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#ifdef __APPLE__
#include <CommonCrypto/CommonDigest.h>
#elif defined(__linux__)
#include <openssl/md5.h>
#else // _WIN32
#include <windows.h>
#include "openssl/md5.h"
#endif
#ifdef __APPLE__
#define MD5_CTX CC_MD5_CTX
#define MD5_Init(a) CC_MD5_Init(a)
#define MD5_Update(a, b, c) CC_MD5_Update(a, b, c)
#define MD5_Final(a, b) CC_MD5_Final(a, b)
#endif
#ifdef _WIN32
#define DIR_SEP '\\'
#else
#define DIR_SEP '/'
#endif
#define SetForegroundColorToRed() printf("\033[22;31;1m")
#define SetForegroundColorToDefault() printf("\033[22;30;0m")
// added the bool type
#ifndef bool
#define bool char
#endif
#ifndef true
// clang-format off
#define true ((bool)1)
// clang-format on
#endif
#ifndef false
// clang-format off
#define false ((bool)0)
// clang-format on
#endif
// globals
static FILE *fd;
static int mode; // either DEB, ISS or MAC
#ifdef __x86_64__
static const char *arch = "amd64";
static const char *arch2 = "x86-64";
#else
static const char *arch = "i386";
static const char *arch2 = "i386";
#endif
static const char *webots_home;
static char application_name[32];
static char bundle_name[32];
static char application_name_lowercase_and_dashes[32];
static char distribution_path[256];
#define ISS 1 // Windows Inno Setup file format -> webots*.iss
#define MAC 2 // macOS shell script to create dmg file -> webots*.mac
#define DEB 3 // Linux shell script to create a deb and a tarball package -> webots.deb
#define SNAP 4 // Linux shell script to create a snap package -> webots.snap
// ORable flags for file type defined in files.txt [linux,mac,windows,exe,dll,sig]
#define TYPE_LINUX 1
#define TYPE_MAC 2
#define TYPE_WINDOWS 4
#define TYPE_EXE 8
#define TYPE_DLL 16
#define UNIX2DOS(s, d) \
{ \
int _i = 0; \
do \
if (s[_i] == '/') \
d[_i] = '\\'; \
else \
d[_i] = s[_i]; \
while (s[_i++]); \
}
static int year = 0;
#define BUFFER_SIZE 2048
static bool dir_exists(const char *path) {
struct stat info;
if (stat(path, &info) != 0)
return false;
else if (info.st_mode & S_IFDIR)
return true;
else
return false;
}
// source: http://coding.debuntu.org/c-implementing-str_replace-replace-all-occurrences-substring
// Note: str_replace() creates a new string with malloc which should be freed.
char *str_replace(const char *string, const char *substr, const char *replacement) {
char *tok = NULL;
char *newstr = NULL;
char *oldstr = NULL;
char *head = NULL;
if (substr == NULL || replacement == NULL)
return strdup(string);
newstr = strdup(string);
head = newstr;
while ((tok = strstr(head, substr))) {
oldstr = newstr;
newstr = malloc(strlen(oldstr) - strlen(substr) + strlen(replacement) + 1);
if (newstr == NULL) {
free(oldstr);
return NULL;
}
memcpy(newstr, oldstr, tok - oldstr);
memcpy(newstr + (tok - oldstr), replacement, strlen(replacement));
memcpy(newstr + (tok - oldstr) + strlen(replacement), tok + strlen(substr),
strlen(oldstr) - strlen(substr) - (tok - oldstr));
memset(newstr + strlen(oldstr) - strlen(substr) + strlen(replacement), 0, 1);
head = newstr + (tok - oldstr) + strlen(replacement);
free(oldstr);
}
return newstr;
}
static void test_file(const char *file) {
char file1[BUFFER_SIZE];
int i;
if (file[0] == '/' || file[0] == '$')
return; // ignore absolute file names
for (i = 0; file[i]; i++)
if (file[i] == '*')
return; // ignore wildcard filenames
#ifndef _WIN32
char *f = str_replace(file, "\\ ", " ");
sprintf(file1, "../../%s", f);
free(f);
#else
sprintf(file1, "../../%s", file);
#endif
if (access(file1, F_OK) == 0)
return;
SetForegroundColorToRed();
printf("Missing file: %s\n", file);
SetForegroundColorToDefault();
exit(-1);
}
static void test_dir(const char *dir) {
char dir1[BUFFER_SIZE];
if (strcmp(dir, "util") == 0)
return; // this one is created and copied from elsewhere
sprintf(dir1, "../../%s", dir);
if (access(dir1, F_OK) == 0)
return;
SetForegroundColorToRed();
printf("Missing dir: %s\n", dir);
SetForegroundColorToDefault();
exit(-1);
}
static void copy_file(const char *file) {
char file2[BUFFER_SIZE];
char dest[BUFFER_SIZE];
char dest2[BUFFER_SIZE];
int i, l, k;
test_file(file);
l = strlen(file);
sprintf(dest, "%s", file);
k = 0;
for (i = l - 1; i > 0; i--)
if (dest[i] == '/') {
if (k == 0)
dest[i] = '\0';
k++;
}
if (k == 0)
dest[0] = '\0';
if (mode != ISS) { // protect the $ character (mainly for java nested classes)
k = 0;
for (i = 0; i < l; i++) {
if (file[i] == '$')
file2[k++] = '\\';
file2[k++] = file[i];
}
file2[k] = '\0';
k = 0;
for (i = 0; i < ((int)strlen(dest)); i++) {
if (dest[i] == '$')
dest2[k++] = '\\';
dest2[k++] = dest[i];
}
dest2[k] = '\0';
}
#ifndef _WIN32
// protect parentheses in unix systems
char *protected_filename1 = str_replace(file2, "(", "\\(");
char *protected_filename2 = str_replace(protected_filename1, ")", "\\)");
free(protected_filename1);
#endif
switch (mode) {
case ISS:
UNIX2DOS(file, file2);
UNIX2DOS(dest, dest2);
l = strlen(file2);
for (i = l - 1; file2[i] != '\\'; i--)
;
fprintf(fd, "Source: \"%s\"; DestDir: \"{app}\\%s\"", file2, dest2);
if (file2[i + 1] == '.')
fprintf(fd, "; Attribs: hidden");
if ((file2[l - 4] == '.' && file2[l - 3] == 'j' && file2[l - 2] == 'p' && file2[l - 1] == 'g') ||
(file2[l - 4] == '.' && file2[l - 3] == 'p' && file2[l - 2] == 'n' && file2[l - 1] == 'g'))
fprintf(fd, "; Flags: nocompression");
fprintf(fd, "\n");
break;
#ifndef _WIN32
case MAC:
fprintf(fd, "cp -a $WEBOTS_HOME/%s \"%s/%s/%s/\"\n", protected_filename2, distribution_path, bundle_name, dest2);
break;
case DEB:
fprintf(fd, "cp -a $WEBOTS_HOME/%s %s/debian/usr/local/%s/%s\n", protected_filename2, distribution_path,
application_name_lowercase_and_dashes, dest2);
break;
case SNAP:
fprintf(fd, "cp -a $WEBOTS_HOME/%s $DESTDIR/usr/share/%s/%s\n", protected_filename2,
application_name_lowercase_and_dashes, dest2);
break;
#endif
default:
break;
}
#ifndef _WIN32
free(protected_filename2);
#endif
}
static bool compute_md5_of_file(const char *file_name, unsigned char *out) {
FILE *file;
file = fopen(file_name, "r");
if (file == NULL)
return false;
unsigned char buffer[8192];
unsigned char bufferUnix[8192];
MD5_CTX mc;
MD5_Init(&mc);
size_t len = fread(buffer, 1, sizeof(buffer), file);
while (len > 0) {
// convert all line endings to Unix '\n'
int i = 0;
int lenUnix = 0;
while (i < len) {
if (buffer[i] != '\r') {
// copy char
bufferUnix[lenUnix] = buffer[i];
++lenUnix;
}
++i;
}
MD5_Update(&mc, bufferUnix, lenUnix);
len = fread(buffer, 1, sizeof(buffer), file);
}
fclose(file);
MD5_Final(out, &mc);
return true;
}
static void make_dir(const char *directory) {
char directory2[BUFFER_SIZE];
test_dir(directory);
switch (mode) {
case MAC:
fprintf(fd, "mkdir \"%s/%s/%s\"\n", distribution_path, bundle_name, directory);
break;
case ISS:
UNIX2DOS(directory, directory2);
fprintf(fd, "Name: \"{app}\\%s\"\n", directory2);
break;
case DEB:
fprintf(fd, "mkdir %s/debian/usr/local/%s/%s\n", distribution_path, application_name_lowercase_and_dashes, directory);
break;
case SNAP:
fprintf(fd, "mkdir $DESTDIR/usr/share/%s/%s\n", application_name_lowercase_and_dashes, directory);
default:
break;
}
}
// this function works only for simple wildcard match,
// like "/home/user/*.class" or "/home/user/file-*.c"
static int wildcard_match(const char *str, const char *pattern) {
enum State {
Exact, // exact match
Any, // ?
AnyRepeat // *
};
const char *s = str;
const char *p = pattern;
const char *q = 0;
int state = 0;
bool match = true;
while (match && *p) {
if (*p == '*') {
state = AnyRepeat;
q = p + 1;
} else if (*p == '?')
state = Any;
else
state = Exact;
if (*s == 0)
break;
switch (state) {
case Exact:
match = *s == *p;
s++;
p++;
break;
case Any:
match = true;
s++;
p++;
break;
case AnyRepeat:
match = true;
s++;
if (*s == *q)
p++;
break;
}
}
if (state == AnyRepeat)
return (*s == *q);
else if (state == Any)
return (*s == *p);
else
return match && (*s == *p);
}
static char **expand_wildcard_filename(const char *big_buffer, int *n) {
DIR *dd;
int i;
struct dirent *d;
char **r = NULL;
*n = 0;
int l = strlen(big_buffer);
char *directory_name = (char *)malloc(l + 1);
strcpy(directory_name, big_buffer);
char *pattern = NULL;
for (i = l - 1; i >= 0; i--)
if (directory_name[i] == '/') {
directory_name[i] = '\0';
pattern = &directory_name[i + 1];
break;
}
dd = opendir(directory_name);
while ((d = readdir(dd))) {
if (d->d_name[0] == '.')
continue; // skip hidden files, . and .. directories
if (wildcard_match(d->d_name, pattern)) {
(*n)++;
r = (char **)realloc(r, (*n) * sizeof(char *));
l = strlen(directory_name) + 1 + strlen(d->d_name);
r[(*n) - 1] = (char *)malloc(l + 1);
snprintf(r[(*n) - 1], l + 1, "%s/%s", directory_name, d->d_name);
}
}
closedir(dd);
free(directory_name);
return r;
}
static void create_file(const char *name, int m) {
char filename[256];
char version[64]; // for example "R2018a revision 1"
char package_version[64]; // for example "R2018a-rev1"
char buffer[BUFFER_SIZE];
char big_buffer[2 * BUFFER_SIZE];
FILE *projects_fd;
FILE *data_fd;
int i, j, l, type;
snprintf(application_name, 32, "%s", name);
#ifdef __APPLE__
snprintf(bundle_name, 32, "%s.app", name);
#endif
snprintf(application_name_lowercase_and_dashes, 32, "%s", name);
l = strlen(name);
for (i = 0; i < l; i++) {
application_name_lowercase_and_dashes[i] = tolower(application_name_lowercase_and_dashes[i]);
if (application_name_lowercase_and_dashes[i] == ' ')
application_name_lowercase_and_dashes[i] = '-';
}
mode = m;
switch (mode) {
case ISS:
snprintf(filename, 256, "%s.iss", application_name_lowercase_and_dashes);
break;
case MAC:
snprintf(filename, 256, "%s.mac", application_name_lowercase_and_dashes);
break;
case DEB:
snprintf(filename, 256, "%s.deb", application_name_lowercase_and_dashes);
break;
case SNAP:
snprintf(filename, 256, "%s.snap", application_name_lowercase_and_dashes);
break;
default:
break;
}
fd = fopen(filename, "w+");
if (fd == NULL) {
fprintf(stderr, "could not open file: %s\n", filename);
exit(-1);
}
data_fd = fopen("webots_version.txt", "r");
if (data_fd == NULL) {
fprintf(stderr, "could not open file: webots_version.txt\n");
exit(-1);
}
fgets(version, 64, data_fd);
l = strlen(version);
if (version[l - 1] == '\n')
version[l - 1] = '\0'; // remove final new line character
printf("# creating %s version %s", filename, version);
fflush(stdout);
fclose(data_fd);
char major[16], revision_string[16];
int revision_number;
int matches = sscanf(version, "%15s %15s %d", major, revision_string, &revision_number);
if (matches > 1)
sprintf(package_version, "%s-rev%d", major, revision_number);
else
sprintf(package_version, "%s", major);
switch (mode) {
case MAC:
fprintf(fd, "#!/bin/bash\n");
fprintf(fd, "# run this script to build %s-%s.dmg in \"%s/\"\n\n", application_name_lowercase_and_dashes, package_version,
distribution_path);
fprintf(fd, "rm -rf \"%s/%s/Contents\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/webots\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/docs\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/bin\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/bin/qt\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/include\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/lib\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/projects\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/resources\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/transfer\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -rf \"%s/%s/util\"\n", distribution_path, bundle_name);
fprintf(fd, "rm -f \"%s/%s-%s.dmg\"\n\n", distribution_path, application_name_lowercase_and_dashes, package_version);
fprintf(fd, "mkdir -p \"%s/%s\"\n\n", distribution_path, bundle_name);
break;
case ISS:
fprintf(fd,
"[Setup]\n"
"SourceDir=..\\..\n"
"AppId=Webots\n"
"AppName=%s\n"
"AppVersion=%s\n"
"AppVerName=%s %s\n"
"AppCopyright=Copyright (c) %d Cyberbotics, Ltd.\n"
"AppPublisher=Cyberbotics, Ltd.\n"
"AppPublisherURL=https://www.cyberbotics.com\n"
"ChangesEnvironment=yes\n" // tells Windows Explorer to reload environment variables (e.g., WEBOTS_HOME)
"Compression=lzma2/fast\n"
"DefaultDirName={autopf}\\%s\n"
"DefaultGroupName=Cyberbotics\n"
"UninstallDisplayIcon={app}\\msys64\\mingw64\\bin\\webots.exe\n"
"PrivilegesRequired=lowest\n"
"UsePreviousPrivileges=no\n"
"PrivilegesRequiredOverridesAllowed=dialog\n",
application_name, version, application_name, version, year, application_name);
fprintf(fd, "OutputBaseFileName=%s-%s_setup\n", application_name_lowercase_and_dashes, package_version);
fprintf(fd,
"OutputDir=%s\n"
"ChangesAssociations=yes\n"
"DisableStartupPrompt=yes\n"
"ArchitecturesInstallIn64BitMode=x64\n"
"ArchitecturesAllowed=x64\n"
"\n[Dirs]\n",
distribution_path);
break;
case DEB:
fprintf(fd, "#!/bin/bash\n");
fprintf(fd, "# run this auto-generated script to install %s in \"$HOME/develop/%s\"\n\n", application_name,
application_name_lowercase_and_dashes);
fprintf(fd, "rm -rf %s/debian # cleanup\n", distribution_path);
fprintf(fd, "rm -f %s/%s-%s_*.deb\n\n", distribution_path, application_name_lowercase_and_dashes, package_version);
fprintf(fd, "mkdir %s/debian\n", distribution_path);
fprintf(fd, "mkdir %s/debian/usr\n", distribution_path);
fprintf(fd, "mkdir %s/debian/usr/local\n", distribution_path);
fprintf(fd, "mkdir %s/debian/usr/local/%s\n", distribution_path, application_name_lowercase_and_dashes);
break;
case SNAP:
fprintf(fd, "#!/bin/bash\n");
fprintf(fd, "# run this auto-generated script to install the %s snap in \"$DESTDIR\"\n\n",
application_name_lowercase_and_dashes);
fprintf(fd, "mkdir -p $DESTDIR\n");
fprintf(fd, "mkdir -p $DESTDIR/lib\n");
fprintf(fd, "mkdir -p $DESTDIR/lib/x86_64-linux-gnu\n");
fprintf(fd, "mkdir -p $DESTDIR/usr\n");
fprintf(fd, "mkdir -p $DESTDIR/usr/share\n");
fprintf(fd, "mkdir -p $DESTDIR/usr/bin\n");
fprintf(fd, "mkdir -p $DESTDIR/usr/lib\n");
fprintf(fd, "mkdir -p $DESTDIR/usr/lib/x86_64-linux-gnu\n");
fprintf(fd, "mkdir $DESTDIR/usr/share/%s\n", application_name_lowercase_and_dashes);
default:
break;
}
// creating all the subdirectories listed in files.txt
projects_fd = fopen("files.txt", "r");
if (projects_fd == NULL) {
fprintf(stderr, "Cannot open files.txt file!\n");
exit(-1);
}
while (fgets(buffer, BUFFER_SIZE, projects_fd)) {
l = strlen(buffer) - 2; // skipping the final '\n'
for (i = 0; i < l; i++)
if (buffer[i] == ' ' && buffer[i + 1] == '#') {
l = i - 1;
break;
} // skip comment
type = 0;
while (buffer[l] == ' ' || buffer[l] == '\t')
l--;
if (buffer[0] == '#' || l < 1)
continue;
if (buffer[l] == ']') {
while (buffer[l] != '[' && l > 0)
l--;
if (l == 0) {
fprintf(stderr, "missing opening bracket in files.txt: [\n");
exit(-1);
}
i = l - 1;
l++;
do {
switch (buffer[l++]) {
case 'l':
type |= TYPE_LINUX;
break;
case 'm':
type |= TYPE_MAC;
break;
case 'w':
type |= TYPE_WINDOWS;
break;
case 'e': // exe
case 'd': // dll
break;
default:
fprintf(stderr, "unknown option: %s\n", &buffer[l - 1]);
break;
}
for (;;)
if (buffer[l] == ',') {
l++;
break;
} else if (buffer[l] == ']')
break;
else
l++;
} while (buffer[l] != ']');
if ((type & (TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS)) == 0)
type |= (TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS);
l = i;
} else {
l++;
type = TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS;
}
buffer[l--] = '\0';
if (buffer[l] == '/') {
buffer[l] = '\0';
if (((type & TYPE_LINUX) && (mode == DEB || mode == SNAP)) || ((type & TYPE_WINDOWS) && (mode == ISS)) ||
((type & TYPE_MAC) && (mode == MAC)))
make_dir(buffer);
}
}
rewind(projects_fd);
if (mode == ISS) {
FILE *f = fopen("msys64_folders.iss", "r");
while (fgets(buffer, sizeof(buffer), f) != NULL)
fprintf(fd, "%s", buffer);
fclose(f);
fprintf(fd, "\n[Files]\n");
}
// copying all the remaining necessary files listed in files.txt
while (fgets(buffer, BUFFER_SIZE, projects_fd)) {
l = strlen(buffer) - 2; /* skipping the final '\n' */
for (i = 0; i < l; i++)
if (buffer[i] == ' ' && buffer[i + 1] == '#') {
l = i - 1;
break;
} // skip comment
while (buffer[l] == ' ' || buffer[l] == '\t')
l--;
if (buffer[l] == '/' || buffer[0] == '#' || l < 1)
continue;
type = 0;
if (buffer[l] == ']') {
while (buffer[l] != '[' && l > 0)
l--;
if (l == 0) {
fprintf(stderr, "missing opening bracket in files.txt: [\n");
exit(-1);
}
i = l - 1;
l++;
do {
switch (buffer[l++]) {
case 'l':
type |= TYPE_LINUX;
break;
case 'm':
type |= TYPE_MAC;
break;
case 'w':
type |= TYPE_WINDOWS;
break;
case 'e':
type |= TYPE_EXE;
break;
case 'd':
type |= TYPE_DLL;
break;
default:
fprintf(stderr, "unknown option: %s\n", &buffer[l - 1]);
break;
}
for (;;)
if (buffer[l] == ',') {
l++;
break;
} else if (buffer[l] == ']')
break;
else
l++;
} while (buffer[l] != ']');
if ((type & (TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS)) == 0)
type |= (TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS);
if (type & TYPE_DLL && (mode == MAC || mode == DEB || mode == SNAP)) { // prefix "lib" to the basename
j = i - 1;
while (buffer[j] != '/' && j >= 0)
j--;
if (buffer[j + 1] != '_') {
if (j >= 0) {
j = i - 1;
while (buffer[j] != '/' && j >= 0) {
buffer[j + 3] = buffer[j];
j--;
}
buffer[++j] = 'l';
buffer[++j] = 'i';
buffer[++j] = 'b';
i += 3;
} else
fprintf(stderr, "DLL parsing: Reached the beggining of the string without finding a '/' character.");
}
}
if (mode == ISS) {
if (type & TYPE_EXE) {
buffer[i++] = '.';
buffer[i++] = 'e';
buffer[i++] = 'x';
buffer[i++] = 'e';
} else if (type & TYPE_DLL) {
buffer[i++] = '.';
buffer[i++] = 'd';
buffer[i++] = 'l';
buffer[i++] = 'l';
}
} else if (mode == MAC) {
if (type & TYPE_DLL) {
buffer[i++] = '.';
buffer[i++] = 'd';
buffer[i++] = 'y';
buffer[i++] = 'l';
buffer[i++] = 'i';
buffer[i++] = 'b';
}
} else { /* linux */
if (type & TYPE_DLL) {
buffer[i++] = '.';
buffer[i++] = 's';
buffer[i++] = 'o';
}
}
l = i;
} else {
l++;
type = TYPE_LINUX | TYPE_MAC | TYPE_WINDOWS;
}
buffer[l] = '\0';
if (buffer[l - 1] == '/')
continue;
if (((type & TYPE_LINUX) && (mode == DEB || mode == SNAP)) || ((type & TYPE_WINDOWS) && (mode == ISS)) ||
((type & TYPE_MAC) && (mode == MAC))) {
copy_file(buffer);
// copy the .*.wbproj hidden files
if (strcasecmp(&buffer[l - 4], ".wbt") == 0 && strstr(buffer, "/worlds/")) {
sprintf(big_buffer, "%s/%s", webots_home, buffer);
// we need to expand the possible wildcard
int n;
char **expanded_filename = expand_wildcard_filename(big_buffer, &n);
for (i = 0; i < n; i++) {
int l = strlen(expanded_filename[i]);
char *project_filename = (char *)malloc(l + 5); // ".%swbproj", including the final '\0' minus 'wbt'
strcpy(project_filename, expanded_filename[i]);
l--;
for (; l >= 0; l--)
if (project_filename[l] == '/')
break;
l++;
project_filename[l] = '.';
do
project_filename[l + 1] = expanded_filename[i][l];
while (expanded_filename[i][l++]);
project_filename[--l] = '\0'; // remove the last 't'
strcat(project_filename, "proj");
#ifdef _WIN32 // we need to mark this file with the hidden attribute using the Windows C API
SetFileAttributes(project_filename, FILE_ATTRIBUTE_HIDDEN);
#endif
copy_file(&project_filename[strlen(webots_home) + 1]);
free(project_filename);
free(expanded_filename[i]);
}
free(expanded_filename);
}
// check and copy the .*.cache hidden files
if (strcasecmp(&buffer[l - 6], ".proto") == 0 && strstr(buffer, "/protos/")) {
sprintf(big_buffer, "%s/%s", webots_home, buffer);
// we need to expand the possible wildcard
int n;
char **expanded_filename = expand_wildcard_filename(big_buffer, &n);
for (i = 0; i < n; i++) {
int l = strlen(expanded_filename[i]);
char *project_filename = (char *)malloc(l + 2); // ".%scache", including the final '\0' minus 'proto'
strcpy(project_filename, expanded_filename[i]);
l--;
for (; l >= 0; l--)
if (project_filename[l] == '/')
break;
l++;
project_filename[l] = '.';
do
project_filename[l + 1] = expanded_filename[i][l];
while (expanded_filename[i][l++]);
l -= 5;
project_filename[l] = '\0'; // remove the last 'proto'
strcat(project_filename, "cache");
// compute MD5 of PROTO file
const int md5_len = 16;
unsigned char md5Value[md5_len];
if (!compute_md5_of_file(expanded_filename[i], md5Value)) {
SetForegroundColorToRed();
printf("Missing file: %s\n", &expanded_filename[i][strlen(webots_home) + 1]);
SetForegroundColorToDefault();
exit(-1);
}
// read cache file and check MD5 value
FILE *cacheFile;
char line[256];
int maxLen = 256;
cacheFile = fopen(project_filename, "r");
if (cacheFile == NULL) {
SetForegroundColorToRed();
printf("Missing file: %s\n", &project_filename[strlen(webots_home) + 1]);
SetForegroundColorToDefault();
exit(-1);
}
const char *header = "protoFileHash: ";
char md5Sum[33];
for (j = 0; j < 16; j++)
sprintf(&md5Sum[2 * j], "%02x", md5Value[j]);
md5Sum[32] = '\0';
while (fgets(line, maxLen, cacheFile) != NULL) {
if (strncmp(line, header, strlen(header)) == 0) {
if (strncmp(md5Sum, &line[strlen(header)], 32) != 0) {
SetForegroundColorToRed();
printf("Out-of-date file: %s\n", &project_filename[strlen(webots_home) + 1]);
SetForegroundColorToDefault();
exit(-1);
}
}
}
fclose(cacheFile);
#ifdef _WIN32 // we need to mark this file with the hidden attribute using the Windows C API
SetFileAttributes(project_filename, FILE_ATTRIBUTE_HIDDEN);
#endif
copy_file(&project_filename[strlen(webots_home) + 1]);
free(project_filename);
free(expanded_filename[i]);
}
free(expanded_filename);
}
// printf("created: %s (%d)\n",buffer,type);
}
}
fclose(projects_fd);
if (mode == ISS) {
FILE *f = fopen("msys64_files.iss", "r");
while (fgets(buffer, sizeof(buffer), f) != NULL)
fprintf(fd, "%s", buffer);
fclose(f);
}
switch (mode) {
case MAC:
fprintf(fd, "cd \"%s/%s/lib/webots\"\n", distribution_path, bundle_name);
fprintf(fd, "ln -s libssl.1.0.0.dylib libssl.dylib\n");
fprintf(fd, "ln -s libcrypto.1.0.0.dylib libcrypto.dylib\n");
fprintf(fd, "ln -s libopencv_core.2.4.3.dylib libopencv_core.2.4.dylib\n");
fprintf(fd, "ln -s libopencv_core.2.4.3.dylib libopencv_core.dylib\n");
fprintf(fd, "ln -s libopencv_imgproc.2.4.3.dylib libopencv_imgproc.2.4.dylib\n");
fprintf(fd, "ln -s libopencv_imgproc.2.4.3.dylib libopencv_imgproc.dylib\n");
fprintf(fd, "ln -s libssh.4.dylib libssh.dylib\n");
fprintf(fd, "ln -s libzip.2.dylib libzip.dylib\n");
fprintf(fd, "cd \"%s/%s/Contents/Frameworks\"\n", distribution_path, bundle_name);
fprintf(fd, "cd QtConcurrent.framework\n");
fprintf(fd, "ln -fs Versions/5/QtConcurrent QtConcurrent\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtCore.framework\n");
fprintf(fd, "ln -fs Versions/5/QtCore QtCore\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtDBus.framework\n");
fprintf(fd, "ln -fs Versions/5/QtDBus QtDBus\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtGui.framework\n");
fprintf(fd, "ln -fs Versions/5/QtGui QtGui\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtMultimedia.framework\n");
fprintf(fd, "ln -fs Versions/5/QtMultimedia QtMultimedia\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtMultimediaWidgets.framework\n");
fprintf(fd, "ln -fs Versions/5/QtMultimediaWidgets QtMultimediaWidgets\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtNetwork.framework\n");
fprintf(fd, "ln -fs Versions/5/QtNetwork QtNetwork\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtOpenGL.framework\n");
fprintf(fd, "ln -fs Versions/5/QtOpenGL QtOpenGL\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtPositioning.framework\n");
fprintf(fd, "ln -fs Versions/5/QtPositioning QtPositioning\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtPrintSupport.framework\n");
fprintf(fd, "ln -fs Versions/5/QtPrintSupport QtPrintSupport\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtQml.framework\n");
fprintf(fd, "ln -fs Versions/5/QtQml QtQml\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtQuick.framework\n");
fprintf(fd, "ln -fs Versions/5/QtQuick QtQuick\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtQuickWidgets.framework\n");
fprintf(fd, "ln -fs Versions/5/QtQuickWidgets QtQuickWidgets\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtSensors.framework\n");
fprintf(fd, "ln -fs Versions/5/QtSensors QtSensors\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtSql.framework\n");
fprintf(fd, "ln -fs Versions/5/QtSql QtSql\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWebChannel.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWebChannel QtWebChannel\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWebEngine.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWebEngine QtWebEngine\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWebEngineCore.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWebEngineCore QtWebEngineCore\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "ln -Fs Versions/5/Helpers Helpers\n");
fprintf(fd, "ln -Fs Versions/5/Resources Resources\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWebEngineWidgets.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWebEngineWidgets QtWebEngineWidgets\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWebSockets.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWebSockets QtWebSockets\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtWidgets.framework\n");
fprintf(fd, "ln -fs Versions/5/QtWidgets QtWidgets\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd ..\n");
fprintf(fd, "cd QtXml.framework\n");
fprintf(fd, "ln -fs Versions/5/QtXml QtXml\n");
fprintf(fd, "ln -Fs Versions/5/Headers Headers\n");
fprintf(fd, "cd %s/\n", distribution_path);
fprintf(fd, "echo \"{\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"title\\\": \\\"Webots\\\",\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"icon\\\": \\\"%s/Contents/Resources/webots_icon.icns\\\",\" >> appdmg.json\n", webots_home);
fprintf(fd, "echo \" \\\"icon-size\\\": 72,\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"background\\\": \\\"%s/src/packaging/MacOSXBackground.png\\\",\" >> appdmg.json\n",
webots_home);
fprintf(fd, "echo \" \\\"format\\\": \\\"UDBZ\\\",\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"window\\\": {\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"position\\\": { \\\"x\\\": 400, \\\"y\\\": 100 },\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"size\\\": { \\\"width\\\": 480, \\\"height\\\": 580 }\" >> appdmg.json\n");
fprintf(fd, "echo \" },\" >> appdmg.json\n");
fprintf(fd, "echo \" \\\"contents\\\": [\" >> appdmg.json\n");
fprintf(fd, "echo \" { \\\"x\\\": 375, \\\"y\\\": 100, \\\"type\\\": \\\"link\\\", \\\"path\\\": "
"\\\"/Applications\\\" },\" >> appdmg.json\n");
fprintf(fd,
"echo \" { \\\"x\\\": 100, \\\"y\\\": 100, \\\"type\\\": \\\"file\\\", \\\"path\\\": \\\"%s\\\" }\" >> "
"appdmg.json\n",
bundle_name);
fprintf(fd, "echo \" ]\" >> appdmg.json\n");
fprintf(fd, "echo \"}\" >> appdmg.json\n");
fprintf(fd, "appdmg appdmg.json %s-%s.dmg\n", application_name_lowercase_and_dashes, package_version);
fprintf(fd, "rm -rf appdmg.json\n");
break;
case ISS:
fprintf(fd, "\n[Icons]\n");
fprintf(fd,
"Name: \"{app}\\%s\"; Filename: \"{app}\\msys64\\mingw64\\bin\\webots.exe\"; WorkingDir: \"{app}\"; Comment: "
"\"Robot simulator\"\n"
"Name: \"{group}\\%s\"; Filename: \"{app}\\msys64\\mingw64\\bin\\webots.exe\"; WorkingDir: \"{app}\"; Comment: "
"\"Robot simulator\"\n"
"Name: \"{userdesktop}\\%s\"; Filename: \"{app}\\msys64\\mingw64\\bin\\webots.exe\"; WorkingDir: \"{app}\"; "
"Comment: \"Robot simulator\"\n",
application_name, application_name, application_name);
fprintf(
fd, "Name: \"{group}\\Uninstall %s\"; Filename: \"{uninstallexe}\"; WorkingDir: \"{app}\"; Comment: \"Uninstall %s\"\n",
application_name, application_name);
fprintf(fd,
"\n[Registry]\n"
"Root: HKA; SubKey: \"Software\\Classes\\.wbt\"; ValueType: string; ValueData: \"webotsfile\"; "
"Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\.wbt\"; ValueType: string; ValueName: \"Content Type\"; "
"ValueData: \"application/webotsfile\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\webotsfile\\DefaultIcon\"; ValueType: string; "
"ValueData: \"{app}\\resources\\icons\\core\\webots_doc.ico\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\webotsfile\\shell\\open\"; ValueType: string; "
"ValueName: \"FriendlyAppName\"; ValueData: \"Webots\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\webotsfile\\shell\\open\\command\"; ValueType: string; ValueData: "
"\"\"\"{app}\\msys64\\mingw64\\bin\\webots.exe\"\" \"\"%%1\"\"\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\Applications\\webots.exe\"; ValueType: string; "
"ValueName: \"SupportedTypes\"; ValueData: \".wbt\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"Software\\Classes\\Applications\\webots.exe\"; ValueType: string; "
"ValueName: \"FriendlyAppName\"; ValueData: \"Webots\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\webots.exe\"; ValueType: string; "
"ValueData: \"{app}\\msys64\\mingw64\\bin\\webots.exe\"; Flags: uninsdeletekey\n"
"Root: HKA; SubKey: \"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\webots.exe\"; ValueType: string; "
"ValueName: \"Path\"; ValueData: \"{app}\\msys64\\mingw64\\bin;{app}\\msys64\\usr\\bin\"; Flags: uninsdeletekey\n"
"Root: HKCU; SubKey: \"Software\\Cyberbotics\"; Flags: uninsdeletekeyifempty dontcreatekey\n"
"Root: HKCU; SubKey: \"Software\\Cyberbotics\\%s %s\"; Flags: uninsdeletekey dontcreatekey\n"
"Root: HKA; SubKey: \"SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment\"; ValueType: string; "
"ValueName: \"WEBOTS_HOME\"; ValueData: \"{app}\"; Flags: preservestringtype\n",
application_name, version);
fprintf(fd, "Root: HKA; SubKey: \"Software\\Classes\\webotsfile\"; "
"Flags: uninsdeletekey dontcreatekey\n");
// On some systems (as already reported by two Chinese users), some unknown third party software badly installs a
// zlib1.dll and libeay32.dll in the C:\Windows\System32 folder.
// A similar problem occurs with the OpenSSL library needed to build ROS2 on Windows:
// https://index.ros.org/doc/ros2/Installation/Dashing/Windows-Install-Binary/#install-openssl
// recommends to install OpenSSL from https://slproweb.com/products/Win32OpenSSL.html
// By default, this installer copies libcrypto-1_1-x64.dll and libssl-1_1-x64.dll in C:\Windows\System32.
// This is a very bad practise as such DLLs conflicts with the same DLLs provided in the msys64 folder of Webots.
// So, we will delete any of these libraries from the C:\Windows\System32 folder before installing Webots.
fprintf(fd, "\n[InstallDelete]\n");
fprintf(fd, "Type: files; Name: \"{sys}\\zlib1.dll\"\n");
fprintf(fd, "Type: files; Name: \"{sys}\\libeay32.dll\"\n");
fprintf(fd, "Type: files; Name: \"{sys}\\libcrypto-1_1-x64.dll\"\n");
fprintf(fd, "Type: files; Name: \"{sys}\\libssl-1_1-x64.dll\"\n");
fprintf(fd, "\n[Code]\n");
fprintf(fd, "function InitializeSetup(): Boolean;\n");
fprintf(fd, "var\n");
fprintf(fd, " ResultCode: Integer;\n");
fprintf(fd, " Uninstall: String;\n");
fprintf(fd, "begin\n");
fprintf(fd, " if isAdmin and RegQueryStringValue(HKLM, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
"Webots_is1', 'UninstallString', Uninstall) then begin\n");
fprintf(fd, " if MsgBox('A version of Webots is already installed for all users on this computer.' #13 "
"'It will be removed and replaced by the version you are installing.', mbInformation, MB_OKCANCEL) = IDOK "
"then begin\n");
fprintf(fd, " Exec(RemoveQuotes(Uninstall), ' /SILENT', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := FALSE;\n");
fprintf(fd, " end;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end;\n");
fprintf(fd, " if RegQueryStringValue(HKCU, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"
"Webots_is1', 'UninstallString', Uninstall) then begin\n");
fprintf(fd, " if MsgBox('A version of Webots is already installed for the current user on this computer.' #13 'It "
"will be removed and replaced by the version you are installing.', mbInformation, MB_OKCANCEL) = IDOK "
"then begin\n");
fprintf(fd, " Exec(RemoveQuotes(Uninstall), ' /SILENT', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := FALSE;\n");
fprintf(fd, " end;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end;\n");
fprintf(fd, " if RegQueryStringValue(HKLM32, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Webots_is1', "
"'UninstallString', Uninstall) then begin\n");
fprintf(fd, " if MsgBox('A version of Webots (32 bit) is already installed on this computer.' #13 'It will be removed "
"and replaced by the version (64 bit) you are installing.', mbInformation, MB_OKCANCEL) = IDOK then begin\n");
fprintf(fd, " Exec(RemoveQuotes(Uninstall), ' /SILENT', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode);\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := FALSE;\n");
fprintf(fd, " end;\n");
fprintf(fd, " end else begin\n");
fprintf(fd, " Result := TRUE;\n");
fprintf(fd, " end;\n");
fprintf(fd, "end;\n");
fprintf(fd, "\n[Run]\n");
fprintf(fd, "Filename: {app}\\msys64\\mingw64\\bin\\webots.bat; Description: \"Launch Webots\"; Flags: nowait "
"postinstall skipifsilent\n");
// we launch the bat file (and not the exe file) because the installer doesn't have yet the PATH set to msys64/usr/bin
// for webots.exe and hence webots cannot compile
break;
case DEB:
#ifdef WEBOTS_UBUNTU_16_04
copy_file("lib/webots/libssl.so.1.1");
copy_file("lib/webots/libcrypto.so.1.1");
#endif
// copy libraries that depends on OS and cannot be included in files_*.txt
fprintf(fd, "cd %s/debian\n", distribution_path);
fprintf(fd, "mkdir usr/share\n");
fprintf(fd, "mkdir usr/share/mime-info\n");
fprintf(fd, "mkdir usr/share/pixmaps\n");
fprintf(fd, "mkdir usr/share/application-registry\n");
fprintf(fd, "mkdir usr/share/applications\n");
fprintf(fd, "mkdir usr/share/app-install\n");
fprintf(fd, "mkdir usr/share/app-install/desktop\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.mime usr/share/mime-info/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.keys usr/share/mime-info/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.png usr/share/pixmaps/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots_doc.png usr/share/pixmaps/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.applications usr/share/application-registry/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.desktop usr/share/applications/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.desktop usr/share/app-install/desktop/\n");
fprintf(fd, "mkdir usr/local/bin\n");
fprintf(fd, "ln -s /usr/local/%s/webots usr/local/bin/webots\n", application_name_lowercase_and_dashes);
fprintf(fd, "cd %s/debian\n", distribution_path);
// add the wrapper library corresponding to the default Python 3 versions
#ifdef WEBOTS_UBUNTU_16_04
fprintf(fd, "mkdir usr/local/webots/lib/controller/python35\n");
fprintf(fd, "cp $WEBOTS_HOME/lib/controller/python35/*.py usr/local/webots/lib/controller/python35/\n");
fprintf(fd, "cp $WEBOTS_HOME/lib/controller/python35/_*.so usr/local/webots/lib/controller/python35/\n");
// include system libraries in package that are needed on Ubuntu 18.04
fprintf(fd, "cd %s/debian/usr/local/%s/lib/webots\n", distribution_path, application_name_lowercase_and_dashes);
fprintf(fd, "ln -s libssl.so.1.1 libssl.so\n");
fprintf(fd, "ln -s libcrypto.so.1.1 libcrypto.so\n");
fprintf(fd, "cd %s/debian\n", distribution_path);
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libpng12.so.0 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libvpx.so.3 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libwebp.so.5 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libwebpmux.so.1 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libwebpdemux.so.1 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libjasper.so.1 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libevent-2.0.so.5 usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libassimp.so.3 usr/local/webots/lib/webots\n");
#endif
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libminizip.so.1 usr/local/webots/lib/webots\n");
fprintf(fd, "mkdir DEBIAN\n");
fprintf(fd, "echo \"Package: %s\" > DEBIAN/control\n", application_name_lowercase_and_dashes);
fprintf(fd, "echo \"Version: %s\" >> DEBIAN/control\n", package_version + 1); // remove initial R not supported
fprintf(fd, "echo \"Section: science\" >> DEBIAN/control\n");
fprintf(fd, "echo \"Priority: optional\" >> DEBIAN/control\n");
fprintf(fd, "echo \"Architecture: %s\" >> DEBIAN/control\n", arch);
fprintf(fd, "echo -n \"Installed-Size: \" >> DEBIAN/control\n");
fprintf(fd, "du -sx %s/debian | awk '{print $1}' >> DEBIAN/control\n", distribution_path);
fprintf(fd, "echo \"Depends: make, g++, libatk1.0-0 (>= 1.9.0), ffmpeg, libdbus-1-3, libfreeimage3 (>= 3.15.4-3), ");
fprintf(fd, "libglib2.0-0 (>= 2.10.0), libglu1-mesa | libglu1, libgtk-3-0, libjpeg8-dev, ");
fprintf(fd, "libnss3, libstdc++6 (>= 4.0.2-4), libxaw7, libxrandr2, libxrender1, ");
fprintf(fd, "libzzip-0-13 (>= 0.13.62-2), libssh-dev, libzip-dev, xserver-xorg-core, libxslt1.1, ");
fprintf(fd, "libgd3, libfreetype6\" >> DEBIAN/control\n");
if (!strcmp(application_name_lowercase_and_dashes, "webots")) {
fprintf(fd, "echo \"Conflicts: webots-for-nao\" >> DEBIAN/control\n");
fprintf(fd, "echo \"Maintainer: Olivier Michel <[email protected]>\" >> DEBIAN/control\n");
fprintf(fd, "echo \"Description: Mobile robot simulation software\" >> DEBIAN/control\n");
fprintf(fd, "echo \" Webots is a fast prototyping and simulation software\" >> DEBIAN/control\n");
fprintf(fd, "echo \" which allows you to model, program and simulate any mobile\" >> DEBIAN/control\n");
fprintf(fd, "echo \" robot, including wheeled, legged, swimming and flying robots.\" >> DEBIAN/control\n");
fprintf(fd, "echo \" Transfer facilities allows you to transfer the robot\" >> DEBIAN/control\n");
fprintf(fd, "echo \" controller from the simulation onto a real robot.\" >> DEBIAN/control\n");
fprintf(fd, "cd ..\n");
}
#ifdef WEBOTS_UBUNTU_16_04
fprintf(fd, "fakeroot dpkg-deb -Zgzip --build debian %s\n", distribution_path);
#endif
fprintf(fd, "echo creating the %s/%s-%s-%s.tar.bz2 tarball\n", distribution_path, application_name_lowercase_and_dashes,
package_version, arch2);
// copy include directories of libzip and libssh in tarball package
fprintf(fd, "mkdir debian/usr/local/webots/include/libssh\n");
fprintf(fd, "cp -a /usr/include/libssh debian/usr/local/webots/include/libssh/\n");
fprintf(fd, "mkdir debian/usr/local/webots/include/libzip\n");
fprintf(fd, "cp -a /usr/include/zip.h debian/usr/local/webots/include/libzip/\n");
fprintf(fd, "cp /usr/include/x86_64-linux-gnu/zipconf.h debian/usr/local/webots/include/libzip/\n");
// add the required libraries in order to avoid conflicts on other Linux distributions
#ifdef WEBOTS_UBUNTU_16_04
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libraw.so.15 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libvpx.so.3 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libx264.so.148 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libavcodec-ffmpeg.so.56 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libpng12.so.0 debian/usr/local/webots/lib/webots\n");
#elif defined(WEBOTS_UBUNTU_18_04)
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libraw.so.16 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libvpx.so.5 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libx264.so.152 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libavcodec.so.57 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libwebp.so.6 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libwebpmux.so.3 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libpng16.so.16 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libassimp.so.4 debian/usr/local/webots/lib/webots\n");
#endif
// libraries common to Ubuntu 16.04 and 18.04
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libfreeimage.so.3 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libjxrglue.so.0 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libopenjp2.so.7 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libjpegxr.so.0 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libHalf.so.12 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libIex-2_2.so.12 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libIexMath-2_2.so.12 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libIlmThread-2_2.so.12 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libzip.so.4 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libzzip-0.so.13 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libjbig.so.0 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libtiff.so.5 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libjpeg.so.8 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libgomp.so.1 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/liblcms2.so.2 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libXi.so.6 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libXrender.so.1 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libxslt.so.1 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libgd.so.3 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libssh.so.4 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/libfreetype.so.6 debian/usr/local/webots/lib/webots\n");
fprintf(fd, "cd debian/usr/local\n");
fprintf(fd, "tar cf ../../../%s-%s-%s.tar.bz2 --use-compress-prog=pbzip2 %s\n", application_name_lowercase_and_dashes,
package_version, arch2, application_name_lowercase_and_dashes);
fprintf(fd, "rm -rf debian\n");
break;
case SNAP: {
const char *usr_lib_x68_64_linux_gnu[] = {
"libraw.so.16", "libvpx.so.5", "libx264.so.152", "libavcodec.so.57", "libwebp.so.6",
"libwebpmux.so.3", "libpng16.so.16", "libassimp.so.4", "libfreeimage.so.3", "libjxrglue.so.0",
"libopenjp2.so.7", "libjpegxr.so.0", "libHalf.so.12", "libIex-2_2.so.12", "libIexMath-2_2.so.12",
"libIlmThread-2_2.so.12", "libIlmImf-2_2.so.22", "libzip.so.4", "libzzip-0.so.13", "libjbig.so.0",
"libtiff.so.5", "libjpeg.so.8", "libgomp.so.1", "liblcms2.so.2", "libXi.so.6",
"libXrender.so.1", "libfontconfig.so.1", "libxslt.so.1", "libgd.so.3", "libssh.so.4",
"libfreetype.so.6"};
for (int i = 0; i < sizeof(usr_lib_x68_64_linux_gnu) / sizeof(char *); i++)
fprintf(fd, "cp /usr/lib/x86_64-linux-gnu/%s $DESTDIR/usr/lib/x86_64-linux-gnu/\n", usr_lib_x68_64_linux_gnu[i]);
fprintf(fd, "mkdir $DESTDIR/usr/share/webots/include/libssh\n");
fprintf(fd, "cp -a /usr/include/libssh $DESTDIR/usr/share/webots/include/libssh/\n");
fprintf(fd, "mkdir $DESTDIR/usr/share/webots/include/libzip\n");
fprintf(fd, "cp -a /usr/include/zip.h $DESTDIR/usr/share/webots/include/libzip/\n");
fprintf(fd, "cp /usr/include/x86_64-linux-gnu/zipconf.h $DESTDIR/usr/share/webots/include/libzip/\n");
fprintf(fd, "cp $WEBOTS_HOME/src/packaging/webots.desktop $DESTDIR/usr/share/webots/resources/\n");
break;
}
default:
break;
}
fclose(fd);
if (mode == MAC) {
snprintf(buffer, BUFFER_SIZE, "chmod a+x %s.mac", application_name_lowercase_and_dashes);
system(buffer);
} else if (mode == DEB) {
snprintf(buffer, BUFFER_SIZE, "chmod a+x %s.deb", application_name_lowercase_and_dashes);
system(buffer);
} else if (mode == SNAP) {
snprintf(buffer, BUFFER_SIZE, "chmod a+x %s.snap", application_name_lowercase_and_dashes);
system(buffer);
}
printf(": done\n");
fflush(stdout);
}
static void add_folder_recursively(FILE *fd, const char *folder, const char *options) {
char path[1024];
DIR *dd;
struct dirent *d;
struct stat s;
fprintf(fd, "%s/", folder);
if (options)
fprintf(fd, " %s", options);
fprintf(fd, "\n");
sprintf(path, "%s/%s", webots_home, folder);
dd = opendir(path);
while ((d = readdir(dd))) {
if (d->d_name[0] == '.' && d->d_name[1] == 0)
continue; // skip . directory
if (d->d_name[0] == '.' && d->d_name[1] == '.' && d->d_name[2] == 0)
continue; // skip .. directory
sprintf(path, "%s/%s/%s", webots_home, folder, d->d_name);
bool success = stat(path, &s) == 0;
if (!success) {
fprintf(stderr, "Cannot stat \"%s\". This can be caused by a broken symbolic link.\n", path);
exit(-1);
}
if (S_ISDIR(s.st_mode)) { /* directory */
sprintf(path, "%s/%s", folder, d->d_name);
add_folder_recursively(fd, path, options);
} else if (S_ISREG(s.st_mode)) { /* regular file */
char *protected_name =
#ifndef _WIN32
str_replace(d->d_name, " ", "\\ ");
#else
strdup(d->d_name);
#endif
const int name_length = strlen(protected_name);
if (strcmp(protected_name, ".gitignore") != 0 && strcmp(protected_name, ".DS_Store") != 0 &&
strcmp(protected_name, ".DS_Store?") != 0 && strcmp(protected_name, ".Spotlight-V100") != 0 &&
strcmp(protected_name, ".Trashes") != 0 && strcmp(protected_name, "ehthumbs.db") != 0 &&
strcmp(protected_name, "Thumbs.db") != 0 && strncmp("._", protected_name, 2) != 0 &&
(name_length < 3 || strcmp(protected_name + name_length - 4, ".swp") != 0) &&
(name_length < 3 || strcmp(protected_name + name_length - 4, ".bak") != 0) &&
strcmp(protected_name + name_length - 1, "~") != 0) {
fprintf(fd, "%s/%s", folder, protected_name);
if (options)
fprintf(fd, " %s", options);
fprintf(fd, "\n");
}
free(protected_name);
}
}
closedir(dd);
}
#ifdef _WIN32
static void add_msys64_files() {
FILE *fd = fopen("files.txt", "a");
fprintf(fd, "\n# msys64 files (Windows only)\n\n");
add_folder_recursively(fd, "msys64", "[windows]");
fclose(fd);
}
#endif
static void add_files(const char *filename) {
char line[1024];
FILE *fd = fopen("files.txt", "a");
FILE *fd2 = fopen(filename, "r");
while (fgets(line, 1024, fd2)) {
int l = strlen(line);
if (l > 10 && strcmp(&line[l - 10], "[recurse]\n") == 0) {
line[l - 11] = '\0';
add_folder_recursively(fd, line, NULL);
} else
fputs(line, fd);
}
fclose(fd2);
fclose(fd);
}
static void create_distributions(int m) {
unlink("files.txt");
add_files("files_core.txt");
#ifdef _WIN32
add_msys64_files();
#endif
add_files("files_doc.txt");
add_files("files_projects.txt");
create_file("Webots", m);
}
int main(int argc, char *argv[]) {
char month[16];
int day;
sscanf(__DATE__, "%15s %d %d", month, &day, &year);
webots_home = getenv("WEBOTS_HOME");
if (webots_home == NULL || webots_home[0] == '\0') {
fprintf(stderr, "WEBOTS_HOME not defined\n");
exit(-1);
}
const char *custom_distribution_path = getenv("WEBOTS_DISTRIBUTION_PATH");
if (custom_distribution_path && !dir_exists(custom_distribution_path)) {
fprintf(stderr, "WEBOTS_DISTRIBUTION_PATH is set to a directory (%s) who doesn't exists\n", custom_distribution_path);
exit(-1);
}
if (custom_distribution_path)
strcpy(distribution_path, custom_distribution_path);
else
snprintf(distribution_path, 256, "%s%cdistribution", webots_home, DIR_SEP);
if (!dir_exists(distribution_path)) {
fprintf(stderr, "distribution path (%s) doesn't exists\n", distribution_path);
exit(-1);
}
#ifdef _WIN32
create_distributions(ISS);
#endif
#ifdef __APPLE__
create_distributions(MAC);
#endif
#ifdef __linux__
create_distributions(DEB);
create_distributions(SNAP);
#endif
return 0;
}
|
the_stack_data/70449465.c | #include<stdio.h>/*あらかじめ用意されているC言語の入出力関係の機能(ライブラリ)を「使いますよ」という宣言をしています。*/
int main(void)/*C言語のプログラムでは「int main(void)」から実行が始まります*/
{/*「main(void){」で始まり「}」で終わります*/
int i;
int j;
int data[10][10];
/* カウンタにiとjを使う */
for (i = 0; i < 10; i++){
for (j = 0; j < 10; j++){
data[i][j] = 1;
}
}
for (i = 0; i <10; i++){
for (j = 0; j < 10; j++){
printf("%d",data[i][j]);
}
printf("\n");
}
return 0;/*プログラムを終了する命令です*/
}/*「main(void){」で始まり「}」で終わります*/ |
the_stack_data/15763011.c | # include <stdio.h>
# include <limits.h>
# include <float.h>
int max_int(int *, int);
int max_double_index(double *, int);
double max_difference(double *, int);
int main(int agrv, char ** argc)
{
int ls_int[6] = {7 , 8, 10, 18, 0, 6};
double ls_double[5] = {12.3, 87.8, 100.9, 129.1, -10.12};
printf("Max int : %d\n", max_int(ls_int, 6));
printf("The index of max double : %d\n", max_double_index(ls_double, 5));
printf("The max difference of double array : %.2f\n", max_difference(ls_double, 5));
return 0;
}
int max_int(int * pt, int length)
{
int max = INT_MIN;
for ( int i = 0; i < length; i++ )
{
if (max < pt[i]) max = pt[i];
}
return max;
}
int max_double_index(double * pt, int length)
{
double max = DBL_MIN;
int idx = 0;
for ( int i = 0; i < length; i++ )
{
if (max < pt[i])
{
max = pt[i];
idx = i;
}
}
return idx;
}
double max_difference(double * pt, int length)
{
double min = DBL_MAX, max = DBL_MIN;
for (int i = 0; i < length; i++)
{
if (max < pt[i]) max = pt[i];
if (min > pt[i]) min = pt[i];
}
return max - min;
} |
the_stack_data/198580976.c | /*Exercise 3 - Repetition
Write a C program to calculate the sum of the numbers from 1 to n.
Where n is a keyboard input.
e.g.
n -> 100
sum = 1+2+3+....+ 99+100 = 5050
n -> 1-
sum = 1+2+3+...+10 = 55 */
#include <stdio.h>
int main()
{
int num, i, sum=0;
printf("Enter the number :");
scanf("%d", &num);
for(i=1; i<=num; i++)
{
sum=sum+i;
}
printf("Sum : %d", sum);
return 0;
}
|
the_stack_data/161079477.c | #include <math.h>
#include <stdio.h>
int main()
{
float a,b,c,d;
printf("Please input the coordinates of two points:\n");
printf("point 1(x,y): \n");scanf("(%f,%f)",&a,&b);
printf("point 2(x,y): \n");scanf(" (%f,%f)",&c,&d);
printf("This distance is: %.4lf\n",sqrtf((a-c)*(a-c)+(b-d)*(b-d)));
return 0;
}
|
the_stack_data/442917.c | #include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<netdb.h>
#define SERV_TCP_PORT 5035
int main()
{
int sockfd, len, n;
struct sockaddr_in cli_addr;
//struct hostent *server;
len = sizeof(cli_addr);
char buffer[200];
sockfd = socket(AF_INET, SOCK_STREAM, 0);
cli_addr.sin_family = AF_INET;
cli_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
cli_addr.sin_port = htons(SERV_TCP_PORT);
printf("Ready for sending...\n");
connect(sockfd, (struct sockaddr*)&cli_addr, len);
printf("Enter the message to send\n");
printf("Client:\n");
fgets(buffer, 200, stdin);
write(sockfd, buffer, sizeof(buffer));
n = read(sockfd, buffer, sizeof(buffer));
buffer[n] = 0;
printf("Serverecho:%s\n", buffer);
close(sockfd);
return 0;
}
|
the_stack_data/1253472.c | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_IMG_ALARM_16PX
#define LV_COLOR_DEPTH 32
//#define LV_COLOR_DEPTH 16
#define LV_IMG_PX_SIZE_ALPHA_BYTE 4 /* for 32 bit color */
//#define LV_IMG_PX_SIZE_ALPHA_BYTE 3 /* for 16 bit color */
#define LV_IMG_CF_TRUE_COLOR_ALPHA 5 /* for 32 bit color */
// #define LV_IMG_CF_TRUE_COLOR_ALPHA 3 /* for 16 bit color */
// #define LV_COLOR_16_SWAP 1
/** Image header it is compatible with
* the result from image converter utility*/
typedef struct {
uint32_t cf : 5; /* Color format: See `lv_img_color_format_t`*/
uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
non-printable character*/
uint32_t reserved : 2; /*Reserved to be used later*/
uint32_t w : 11; /*Width of the image map*/
uint32_t h : 11; /*Height of the image map*/
} lv_img_header_t;
typedef struct {
lv_img_header_t header;
uint32_t data_size;
const uint8_t * data;
} lv_img_dsc_t;
#ifndef LV_ATTRIBUTE_MEM_ALIGN
#define LV_ATTRIBUTE_MEM_ALIGN
#endif
#ifndef LV_ATTRIBUTE_IMG_EXIT_32PX
#define LV_ATTRIBUTE_IMG_EXIT_32PX
#endif
const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_EXIT_32PX uint8_t exit_32px_map[] = {
#if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8
/*Pixel format: Alpha 8 bit, Red: 3 bit, Green: 3 bit, Blue: 2 bit*/
0xff, 0x00, 0xff, 0x50, 0xff, 0xd0, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xd0, 0xff, 0x50, 0xff, 0x00,
0xff, 0x50, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0x50,
0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7c, 0xff, 0x4c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x4c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x24, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x5f, 0xff, 0xab, 0xff, 0xab, 0xff, 0xab,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x5f, 0xff, 0xa8, 0xff, 0xa8, 0xff, 0xa8,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x24, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xf8, 0xff, 0x4c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x7c, 0xff, 0x4c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0x8c, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0x50, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0x50,
0xff, 0x00, 0xff, 0x50, 0xff, 0xd0, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xd0, 0xff, 0x50, 0xff, 0x00,
#endif
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0
/*Pixel format: Alpha 8 bit, Red: 5 bit, Green: 6 bit, Blue: 5 bit*/
0xff, 0xff, 0x00, 0xff, 0xff, 0x50, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xd0, 0xff, 0xff, 0x50, 0xff, 0xff, 0x00,
0xff, 0xff, 0x50, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0x50,
0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x24, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xab, 0xff, 0xff, 0xab, 0xff, 0xff, 0xab,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xa8,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x24, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0x50, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0x50,
0xff, 0xff, 0x00, 0xff, 0xff, 0x50, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xd0, 0xff, 0xff, 0x50, 0xff, 0xff, 0x00,
#endif
#if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP != 0
/*Pixel format: Alpha 8 bit, Red: 5 bit, Green: 6 bit, Blue: 5 bit BUT the 2 color bytes are swapped*/
0xff, 0xff, 0x00, 0xff, 0xff, 0x50, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xd0, 0xff, 0xff, 0x50, 0xff, 0xff, 0x00,
0xff, 0xff, 0x50, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0x50,
0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x24, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xab, 0xff, 0xff, 0xab, 0xff, 0xff, 0xab,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xa8,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x24, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x7c, 0xff, 0xff, 0x4c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x00, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0x50, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0x50,
0xff, 0xff, 0x00, 0xff, 0xff, 0x50, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xd0, 0xff, 0xff, 0x50, 0xff, 0xff, 0x00,
#endif
#if LV_COLOR_DEPTH == 32
0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x50,
0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7c, 0xff, 0xff, 0xff, 0x4c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x4c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x24, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xff, 0xab, 0xff, 0xff, 0xff, 0xab, 0xff, 0xff, 0xff, 0xab,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7b, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7, 0xff, 0xff, 0xff, 0xc7,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x78, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x5f, 0xff, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xff, 0xa8, 0xff, 0xff, 0xff, 0xa8,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x24, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0xff, 0xff, 0xff, 0x4c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x7c, 0xff, 0xff, 0xff, 0x4c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0x8c, 0xff, 0xff, 0xff, 0xcc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xd0,
0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0x50,
0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0xff, 0xff, 0xff, 0xd0, 0xff, 0xff, 0xff, 0x50, 0xff, 0xff, 0xff, 0x00,
#endif
};
const lv_img_dsc_t exit_32px = {
.header.always_zero = 0,
.header.w = 32,
.header.h = 32,
.data_size = 1024 * LV_IMG_PX_SIZE_ALPHA_BYTE,
.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA,
.data = exit_32px_map,
};
/*
* writing the pixel map
*/
int main(int argc, char **argv) {
FILE *fp;
char *binFile;
binFile="exit_32px_argb8888.bin"; /* 32 bit color */
fp = fopen(binFile, "wb");
fwrite(exit_32px_map,exit_32px.data_size,1,fp);
fclose(fp);
}
|
the_stack_data/50139093.c | /* $begin 010-multmain-c */
#include <stdio.h>
void multstore(long, long, long *);
int main() {
long d;
multstore(2, 3, &d);
printf("2 * 3 --> %ld\n", d);
return 0;
}
long mult2(long a, long b) {
long s = a * b;
return s;
}
/* $end 010-multmain-c */
|
the_stack_data/15762399.c | int main()
{
int i = 0;
inc(i);
}
|
the_stack_data/182952885.c | #include <stdio.h>
int main(void)
{
int ratingCounters[11], i, response;
for ( i = 1; i < 11; ++i)
ratingCounters[i] = 0;
printf("Enter your responses\n");
for ( ; ;) {
scanf ("%i", &response);
if (response == 999)
break;
else if (response < 1 || response > 10)
printf("Bad response: %i\n", response);
else
++ratingCounters[response];
}
printf ("\n\nRating Number of Responses\n");
printf ("------- -------------\n");
for (i = 1; i < 11; ++i)
printf ("%4i%14i\n", i, ratingCounters[i]);
return 0;
}
|
the_stack_data/1104491.c | #include<stdio.h>
#include<stdlib.h>
#define SIZE 10
void show(int Data[], int top);
int push(int Data[], int information, int top);
int pop(int Data[], int top, int LeaveID);
int main(){
int top=-1;
int data;
int Container[SIZE];
int request;
int LeaveID;
while(1){
puts("\nPlz input the request:");
scanf("%d", &request);
puts("\n");
switch(request){
case 1:
puts("Plz input the data:\n"
"------------------------------\n");
scanf("%d", &data);
top = push(Container, data, top);
break;
case 2:
printf("Plz input the Leave Data:");
scanf("%d", &LeaveID);
top = pop(Container, top, LeaveID);
break;
case 3:
puts("data:\n"
"------------------------------\n");
show(Container, top);
puts("\n");
break;
case 4:
exit(1);
break;
default:
puts("Error\n");
break;
}
}
return 0;
}
void show(int Data[], int top){
int i;
system("clear");
printf("Data: ");
for(i=0; i<=top; i++){
printf("%d ", Data[i]);
}
}
int push(int Data[], int information, int top){
top++;
if(top > SIZE){
top--;
system("clear");
show(Data, top);
printf("full\n");
}else{
Data[top] = information;
show(Data, top);
}
return top;
}
int pop(int Data[], int top, int LeaveID){
int i;
int Leave;
if(top < 0){
printf("Empty\n");
}
else{
/* Find the Leave Number's Address in Array */
for(i=0; i<=top; i++){
if(Data[i] == LeaveID){
Leave = i;
break;
}
}
/* Delete Leave number and adjust Array */
for(i=Leave; i<top; i++){
Data[i] = Data[i+1];
}
Data[top] = 0;
top--;
printf("pop: %d\n", Data[top]);
puts("------------------------------\n");
show(Data, top);
}
return top;
}
|
the_stack_data/940327.c | #include <stdio.h>
int main(void) {
int t;
scanf("%d",&t);
while(t--)
{
int d,n,dup,age;
int risk=0,nonrisk=0;
scanf("%d%d",&n,&d);
dup=n;
while(n--)
{
scanf("%d",&age);
if(age>=80 || age <=9)
{
risk++;
}
else
{
nonrisk++;
}
}
if(d==1)
{
printf("\n%d",dup);
}else
{
int rem,days;
rem=risk%d;
if(rem)
{
days=risk/d+1;
}else
{
days=risk/d;
}
rem=nonrisk%d;
if(rem)
{
days+=nonrisk/d+1;
}else
{
days+=nonrisk/d;
}
printf("\n%d",days);
}
}
return 0;
}
|
the_stack_data/12637287.c | // RUN: rm -rf %t*
// RUN: 3c -base-dir=%S -alltypes -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" %s
// RUN: 3c -base-dir=%S -addcr %s -- | %clang -c -fcheckedc-extension -x c -o /dev/null -
// RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %s --
// RUN: 3c -base-dir=%t.checked -alltypes %t.checked/b23_explicitunsafecast.c -- | diff %t.checked/b23_explicitunsafecast.c -
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int *sus(int *x, int *y) {
//CHECK_NOALL: _Ptr<int> sus(int *x : itype(_Ptr<int>), _Ptr<int> y) {
//CHECK_ALL: _Ptr<int> sus(_Array_ptr<int> x, _Ptr<int> y) {
int *z = malloc(sizeof(int));
//CHECK: _Ptr<int> z = malloc<int>(sizeof(int));
*z = 1;
x++;
*x = 2;
return z;
}
int *foo() {
//CHECK: _Ptr<int> foo(void) {
int sx = 3, sy = 4;
int *x = &sx;
//CHECK_NOALL: _Ptr<int> x = &sx;
//CHECK_ALL: int *x = &sx;
int *y = &sy;
//CHECK: _Ptr<int> y = &sy;
int *z = (int *)sus(x, y);
//CHECK_NOALL: _Ptr<int> z = (_Ptr<int>)sus(x, y);
//CHECK_ALL: _Ptr<int> z = (_Ptr<int>)sus(_Assume_bounds_cast<_Array_ptr<int>>(x, bounds(unknown)), y);
*z = *z + 1;
return z;
}
char *bar() {
//CHECK: char *bar(void) : itype(_Ptr<char>) {
int sx = 3, sy = 4;
int *x = &sx;
//CHECK_NOALL: _Ptr<int> x = &sx;
//CHECK_ALL: int *x = &sx;
int *y = &sy;
//CHECK: _Ptr<int> y = &sy;
char *z = (char *)(sus(x, y));
//CHECK_NOALL: char *z = (char *)(((int *)sus(x, y)));
//CHECK_ALL: char *z = (char *)(((int *)sus(_Assume_bounds_cast<_Array_ptr<int>>(x, bounds(unknown)), y)));
return z;
}
|
the_stack_data/653485.c | #include <unistd.h>
uid_t geteuid(void) {
uid_t euid;
getresuid(NULL, &euid, NULL);
return euid;
}
|
the_stack_data/73179.c | /* sizeOf.c- Program to tell the size of the C variable */
/* type in bytes.*/
#include <stdio.h>
int main (void)
{
printf("\nA char is %d bytes", sizeof(char));
printf("\nAn int is %d bytes", sizeof(int));
printf("\nA short is %d bytes", sizeof(short));
printf("\nA long is %d bytes", sizeof(long));
printf("\nA long long is %d bytes \n", sizeof (long long));
printf("\nAn unsigned char is %d bytes", sizeof(unsigned char));
printf("\nAn unsigned int is %d bytes", sizeof(unsigned int));
printf("\nAn unsigned short is %d bytes", sizeof(unsigned short));
printf("\nAn unsigned long is %d bytes", sizeof(unsigned long));
printf("\nAn unsigned long long is %d bytes\n", sizeof(unsigned long long));
printf("\nA float is %d bytes", sizeof(float));
printf("\nA double is %d bytes\n", sizeof(double));
printf("\nA long double is %d bytes\n", sizeof(long double));
return 0;
} |
the_stack_data/214221.c | #include <stdio.h>
int main()
{
int num, fat;
printf("\n Digite o numero a ser calculado o fatorial :: ");
scanf(" %d", &num);
if (num==0)
printf("\n RESULTADO DO FATORIAL :: %d! = %d", 0, 1);
else
{
int termos[num];
int *ptr=termos;
*ptr=num;
while ( ptr!=&termos[num-1] )
{
*(ptr+1)= *ptr -1;
ptr++;
}
for ( ptr=termos, fat=*ptr; ptr<=&termos[num-2]; ptr++ )
{
fat=fat**(ptr+1);
}
printf("\n RESULTADO DO FATORIAL :: %d! = %d", num, fat);
}
return 0;
}
|
the_stack_data/694685.c | #include <dirent.h>
#include <stdlib.h>
#include <stdio.h>
#include<sys/wait.h>
#include <string.h>
#include <time.h>
void print_date(struct tm *time_pointer) // for printing global and local time
{
char buf[256]={0};
strftime(buf,256,"%A",time_pointer); //National full weekday name
printf("%s\t",buf);
printf("%d\t", time_pointer->tm_mday); //the day of the month
memset(buf,0,256);
strftime(buf,256,"%B",time_pointer); //National full month name
printf("%s\t",buf);
memset(buf,0,256);
strftime(buf,256,"%Y",time_pointer); //Year
printf("%s\t",buf);
memset(buf,0,256);
strftime(buf,256,"%r",time_pointer); //12-hour clock time
printf("%s\t",buf);
memset(buf,0,256);
strftime(buf,256,"%Z",time_pointer); //Timezone name
printf("%s\n",buf);
}
int date_command(char const *str,int simple)
{
time_t tim=time(NULL);
if(tim==-1)
{
perror("Time falied");
return 1;
}
if(simple)
{
struct tm *time_pointer=localtime(&tim);
if(time_pointer==NULL)
{
perror("struct tm falied in localtime");
return 1;
}
print_date(time_pointer);
}
else
{
if(!strcmp(str,"-u\n") || !strcmp(str,"-u"))
{
struct tm *UTC_timePointer = gmtime(&tim);
if(UTC_timePointer==NULL)
{
perror("struct tm falied in gmtime");
return 1;
}
print_date(UTC_timePointer);
}
else if(!strcmp(str,"-I\n") || !strcmp(str,"-I"))
{
struct tm *time_pointer=localtime(&tim);
if(time_pointer==NULL)
{
perror("struct tm falied in localtime");
return 1;
}
char buf[256]={0};
strftime(buf,256,"%F",time_pointer); //National full month name
printf("%s\n",buf);
memset(buf,0,256);
}
else{
printf("%s\n","no such command in date");
}
}
}
int main(int argc, char const *argv[])
{
int i=atoi(argv[1]);
if(i==1)
{
date_command(NULL,i);
}
else{
date_command(argv[0],0);
}
return 0;
} |
the_stack_data/965932.c | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
// The menu includes all operations upon arrays
struct Array
{
int *A;
int size;
int length;
};
// Displays the entire array
void display(struct Array arr)
{
for (int i = 0; i < arr.size; i++)
{
printf("%d ", arr.A[i]);
}
printf("\n");
}
// Inserts a new item at a given index that already contains a value
void insert(struct Array *arr, int index, int item)
{
if (index >= 0 && index <= arr->length)
{
for (int i = arr->length; i > index; i--)
{
arr->A[i] = arr->A[i - 1];
}
arr->A[index] = item;
arr->length++;
}
}
// Deletes item at a given index
int delete_item(struct Array *arr, int index)
{
int x = 0;
int i;
if (index >= 0 && index < arr->length)
{
x = arr->A[index];
for(i = index; i < arr->length; i++)
{
arr->A[i] = arr->A[i + 1];
}
arr->length--;
return x;
}
return 0;
}
// Searches a unique element (key) in the array and returns its index
int linear_search(struct Array arr, int key)
{
for (int i = 0; i < arr.length; i++)
{
if (arr.A[i] == key)
{
return i;
}
}
return -1;
}
/* Searches a unique element (key) in the array and returns its index
The array must be sorted */
int binary_search(struct Array arr, int key)
{
int middle;
int lower = 0;
int higher = arr.length - 1;
while (lower <= higher)
{
middle = (lower + higher) / 2;
if (arr.A[middle] == key)
{
return middle;
}
else if (key < arr.A[middle])
{
higher = middle - 1;
}
else
{
lower = middle + 1;
}
}
return -1;
}
// Sums all elements
int sum(struct Array arr)
{
int total = 0;
for (int i = 0; i < arr.length; i++)
{
total += arr.A[i];
}
return total;
}
// Appends an element next to the last value in the array
void append(struct Array *arr, int x)
{
if (arr->length < arr->size)
{
arr->A[arr->length++] = x;
}
}
// Helper function that swaps elements
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
// Get: retrieves an element at the given index
int get(struct Array arr, int index)
{
if (index >= 0 && index < arr.length)
{
return arr.A[index];
}
return -1;
}
// Set: replaces a value at a particular index
void set(struct Array *arr, int index, int new_value)
{
if (index >= 0 && index < arr->length)
{
arr->A[index] = new_value;
}
}
// Max: finds the highest number among the elements
int max(struct Array arr) // f(n)=2n+1 -> O(n)
{
int max = arr.A[0];
for (int i = 1; i < arr.length; i++)
{
if (arr.A[i] > max)
{
max = arr.A[i];
}
}
return max;
}
// Min: finds the smallest number among the elements
int min(struct Array arr)
{
int min = arr.A[0];
for (int i = 1; i < arr.length; i++)
{
if (arr.A[i] < min)
{
min = arr.A[i];
}
}
return min;
}
// Average: Sum of all elements divided by the number of elements
float average(struct Array arr, int length)
{
int total = 0;
for (int i = 0; i < arr.length; i++)
{
total += arr.A[i];
}
// Average can be even simpler: return sum(arr)/arr.length
return (float) total / length;
}
// Reverse: one of the methods use an auxiliary array, O(n)
void reverse(struct Array *arr)
{
int *B;
B = (int *)malloc(arr->length * sizeof(int));
for (int i = 0, j = arr->length - 1; i < arr->length; i++, j--)
{
B[j] = arr->A[i];
}
for (int i = 0; i < arr->length; i++)
{
arr->A[i] = B[i];
}
return arr;
}
// Reverse: this other method is by swapping the elements
void reverse_swap(struct Array *arr)
{
int temp;
for (int i = 0, j = arr->length - 1; i < arr->length; i++, j--)
{
if (i > j)
{
break;
}
temp = arr->A[i];
arr->A[i] = arr->A[j];
arr->A[j] = temp;
}
return arr;
};
void insert_sort(struct Array *arr, int key)
{
if (arr->length == arr->size) // There needs to be at least one vacant space
{
return;
}
// While loop is useful when you don't know how many times to iterate
int i = arr->length - 1;
while (i >= 0 && arr->A[i] > key)
{
arr->A[i + 1] = arr->A[i];
i--;
}
arr->A[i + 1] = key;
arr->length++;
}
bool is_sorted(struct Array arr)
{
for (int i = 0; i < arr.length - 1; i++)
{
if (arr.A[i] > arr.A[i + 1])
{
return false;
}
}
return true;
}
// Rearrange: negative numbers on the left side and positive on the right
void neg_left_side(struct Array *arr) // O(n)
{
int i = 0;
int j = arr->length;
while (i < j)
{
while (arr->A[i] < 0)
{
i++;
}
while (arr->A[j] >= 0)
{
j--;
}
if (i < j)
{
int temp = arr->A[i];
arr->A[i] = arr->A[j];
arr->A[j] = temp;
}
}
}
struct Array * merge(struct Array *arr1, struct Array *arr2) // Theta(m+n)
{
struct Array *arr3 = (struct Array *)malloc(sizeof(struct Array));
int i, j, k;
i = j = k = 0;
while (i < arr1->length && j < arr2->length)
{
if (arr1->A[i] < arr2->A[j])
{
arr3->A[k++] = arr1->A[i++];
}
else
{
arr3->A[k++] = arr2->A[j++];
}
}
for (; i < arr1->length; i++)
{
arr3->A[k++] = arr1->A[i];
}
for (; j < arr2->length; j++)
{
arr3->A[k++] = arr2->A[j];
}
arr3->length = arr1->length + arr2->length;
arr3->size = 10;
return arr3;
}
// Union: new array with all the elements from A and B, but without duplicates
struct Array * union_sorted(struct Array *arr1, struct Array *arr2) // For sorted arrays
{
struct Array *arr3 = (struct Array *)malloc(sizeof(struct Array));
int i, j, k;
i = j = k = 0;
while (i < arr1->length && j < arr2->length)
{
if (arr1->A[i] < arr2->A[j])
{
arr3->A[k++] = arr1->A[i++];
}
else if (arr2->A[j] < arr1->A[i])
{
arr3->A[k++] = arr2->A[j++];
}
else
{
arr3->A[k++] = arr1->A[i++];
j++;
}
}
for (; i < arr1->length; i++)
{
arr3->A[k++] = arr1->A[i];
}
for (; j < arr2->length; j++)
{
arr3->A[k++] = arr2->A[j];
}
arr3->length = k;
arr3->size = 10;
return arr3;
}
// Intersection: the third array contains elements that are shared by A and B
struct Array * intersection_sorted(struct Array *arr1, struct Array *arr2) // For sorted arrays
{
struct Array *arr3 = (struct Array *)malloc(sizeof(struct Array));
int i, j, k;
i = j = k = 0;
while (i < arr1->length && j < arr2->length)
{
if (arr1->A[i] < arr2->A[j])
{
i++;
}
else if (arr2->A[j] < arr1->A[i])
{
j++;
}
else if (arr1->A[i] == arr2->A[j])
{
arr3->A[k++] = arr1->A[i++];
j++;
}
}
arr3->length = k;
arr3->size = 10;
return arr3;
}
// Difference: A - B, this means the third array contains elements from A that aren't in B.
struct Array * difference_sorted(struct Array *arr1, struct Array *arr2) // For sorted arrays
{
struct Array *arr3 = (struct Array *)malloc(sizeof(struct Array));
int i, j, k;
i = j = k = 0;
while (i < arr1->length && j < arr2->length)
{
if (arr1->A[i] < arr2->A[j])
{
arr3->A[k++] = arr1->A[i++];
}
else if (arr2->A[j] < arr1->A[i])
{
j++;
}
else
{
i++;
j++;
}
}
for (; i < arr1->length; i++)
{
arr3->A[k++] = arr1->A[i];
}
arr3->length = k;
arr3->size = 10;
return arr3;
}
int main(void) {
struct Array arr1;
int choice, item, index, sorted;
printf("Enter the size of the array: ");
scanf("%d", &arr1.size);
arr1.A = (int *)malloc(arr1.size * sizeof(int));
memset(arr1.A, 0, arr1.size*sizeof(int));
arr1.length = 0;
do
{
printf("Menu\n");
printf("1. Display\n");
printf("2. Insert\n");
printf("3. Delete\n");
printf("4. Search\n");
printf("5. Sum\n");
printf("6. Append\n");
printf("7. Get\n");
printf("8. Set\n");
printf("9. Max\n");
printf("10. Min\n");
printf("11. Average\n");
printf("12. Reverse\n");
printf("13. Reverse Swap\n");
printf("14. Insert Sort\n");
printf("15. Is it sorted?\n");
printf("16. Negative to Left\n");
printf("17. Length\n");
printf("18. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice)
{
case 1: display(arr1);
break;
case 2: printf("Enter an item and index: ");
scanf("%d%d", &item, &index);
insert(&arr1, index, item);
break;
case 3: printf("Enter an index: ");
scanf("%d", &index);
printf("The deleted item is %d\n", delete_item(&arr1, index));
break;
case 4: printf("Is the array sorted? 0: No | 1: Yes: ");
scanf("%d", &sorted);
if (sorted == 0)
{
printf("Enter the item: ");
scanf("%d", &item);
printf("Found at index: %d\n", linear_search(arr1, item));
}
else
{
printf("Enter the item: ");
scanf("%d", &item);
printf("Found at index: %d\n", binary_search(arr1, item));
}
break;
case 5: printf("The sum is %d\n", sum(arr1));
break;
case 6: printf("Enter the item: ");
scanf("%d", &item);
append(&arr1, item);
break;
case 7: printf("Enter an index: ");
scanf("%d", &index);
printf("Got: %d\n", get(arr1, index));
break;
case 8: printf("Enter the item: ");
scanf("%d", &item);
printf("Enter an index: ");
scanf("%d", &index);
set(&arr1, index, item);
break;
case 9: printf("Max: %d\n", max(arr1));
break;
case 10: printf("Min: %d\n", min(arr1));
break;
case 11: printf("Average: %.2f\n", average(arr1, arr1.length));
break;
case 12: reverse(&arr1);
break;
case 13: reverse_swap(&arr1);
break;
case 14: printf("Enter the item: ");
scanf("%d", &item);
insert_sort(&arr1, item);
case 15: printf("%d\n", is_sorted(arr1));
break;
case 16: neg_left_side(&arr1);
break;
case 17: printf("Length: %d\n", arr1.length);
break;
}
} while (choice < 18);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.