I have a problem running an example code from hdf5 called h5_rdwt.c (in eclipse). You can find this here:
http://www.hdfgroup.org/HDF5/Tutor/rdwt.html#rdwr
The code is:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help#hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This example illustrates how to write and read data in an existing
* dataset. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
int main() {
hid_t file_id, dataset_id; /* identifiers */
herr_t status;
int i, j, dset_data[4][6];
/* Initialize the dataset. */
for (i = 0; i < 4; i++)
for (j = 0; j < 6; j++)
dset_data[i][j] = i * 6 + j + 1;
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
/* Write the dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
/* Close the dataset. */
status = H5Dclose(dataset_id);
/* Close the file. */
status = H5Fclose(file_id);
}
Before I did so, I created a file named "dset.h5" with:
#include "hdf5.h"
#define FILE "dset.h5"
main() {
hid_t file_id; /* file identifier */
herr_t status;
/* Create a new file using default properties. */
file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Terminate access to the file. */
status = H5Fclose(file_id);
}
Building is no problem, but when I try to run this I get the message:
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: ../../src/H5D.c line 334 in H5Dopen2(): not found
major: Dataset
minor: Object not found
#001: ../../src/H5Gloc.c line 430 in H5G_loc_find(): can't find object
major: Symbol table
minor: Object not found
#002: ../../src/H5Gtraverse.c line 861 in H5G_traverse(): internal path traversal failed
major: Symbol table
minor: Object not found
#003: ../../src/H5Gtraverse.c line 641 in H5G_traverse_real(): traversal operator failed
major: Symbol table
minor: Callback failed
#004: ../../src/H5Gloc.c line 385 in H5G_loc_find_cb(): object 'dset' doesn't exist
major: Symbol table
minor: Object not found
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: ../../src/H5Dio.c line 234 in H5Dwrite(): can't prepare for writing data
major: Dataset
minor: Write failed
#001: ../../src/H5Dio.c line 266 in H5D__pre_write(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: ../../src/H5Dio.c line 140 in H5Dread(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: ../../src/H5D.c line 391 in H5Dclose(): not a dataset
major: Invalid arguments to routine
minor: Inappropriate type
Does someone know what went wrong?
Thank you!
The main routine in your program includes the lines
/* Open an existing dataset. */
dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
but there's no evidence from what you have posted that the file in question contains any datasets to open. You seem to have created a file called dset but that's not the same thing as a dataset. From what you've posted your file is empty.
The clue to this is given in the error report which states, inter alia
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: ../../src/H5D.c line 334 in H5Dopen2(): not found
major: Dataset
minor: Object not found
You have to create the dataset as well before accessing it. There is an example for that on the hdf5-page as well:
ftp://www.hdfgroup.org/HDF5/examples/introductory/C/h5_crtdat.c
Short: using H5Screate_simple to create dataspace and H5Dcreate2 to create the dataset.
Related
I'am studying apr libiary source code, and I saw the struct apr_allocator_t:
struct apr_allocator_t {
/** largest used index into free[], always < MAX_INDEX */
apr_size_t max_index;
/** Total size (in BOUNDARY_SIZE multiples) of unused memory before
* blocks are given back. #see apr_allocator_max_free_set().
* #note Initialized to APR_ALLOCATOR_MAX_FREE_UNLIMITED,
* which means to never give back blocks.
*/
apr_size_t max_free_index;
/**
* Memory size (in BOUNDARY_SIZE multiples) that currently must be freed
* before blocks are given back. Range: 0..max_free_index
*/
apr_size_t current_free_index;
#if APR_HAS_THREADS
apr_thread_mutex_t *mutex;
#endif /* APR_HAS_THREADS */
apr_pool_t *owner;
/**
* Lists of free nodes. Slot 0 is used for oversized nodes,
* and the slots 1..MAX_INDEX-1 contain nodes of sizes
* (i+1) * BOUNDARY_SIZE. Example for BOUNDARY_INDEX == 12:
* slot 0: nodes larger than 81920
* slot 1: size 8192
* slot 2: size 12288
* ...
* slot 19: size 81920
*/
apr_memnode_t *free[MAX_INDEX];
};
I'm confused with the member current_free_index (don't understand the comments) and the usage of it in function
APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator, apr_size_t in_size)
{
...
max_free_index = APR_ALIGN(size, BOUNDARY_SIZE) >> BOUNDARY_INDEX;
allocator->current_free_index += max_free_index; // why it need to change here?
allocator->current_free_index -= allocator->max_free_index;
allocator->max_free_index = max_free_index;
if (allocator->current_free_index > max_free_index)
allocator->current_free_index = max_free_index;
...
}
and in function
static APR_INLINE
void allocator_free(apr_allocator_t *allocator, apr_memnode_t *node)
{
...
current_free_index = allocator->current_free_index;
...
index = node->index;
if (max_free_index != APR_ALLOCATOR_MAX_FREE_UNLIMITED
&& index + 1 > current_free_index) {
node->next = freelist;
freelist = node;
} // what "index + 1 > current_free_index" means?
...
}
is also seems to be strange to me
Thinks to #kiner_shah, I fixed the problem. The answer is just like kiner_shah said:
current_free_index is the size of memory which must be freed in order for that memory to be reused again for allocating.
And the max_free_index is the user defined thredshold. In other words, current_free_index indicates how much memory size you need to free to reach the threshold for destorying the apr_memnode_t
I’m trying to fix some proprietary compiler directives by using a filter. I discovered that if I pass a file through a filter, the file documentation is generated correctly, but auto-linking seems broken!
I came up with a very simple example. My filter is implemented in Python and it just opens the file and prints every single line, it doesn’t change anything. I confirmed this by comparing the filter’s input and output (by redirection) with a diff and there are no differences at all.
I redirected the filter’s output to a file called filtered_c.h. If I include this file as a source file, I get auto-link to work. If I pass the original header file through the filter, auto-linking is broken and I get a warning
latex_double.md:7: warning: unable to resolve reference to `some_c_function' for \ref command
If I comment out the FILTER_PATTERNS line in the Doxyfile, auto-linking works.
This is really an issue for me, as I’m also supporting parsing assembly files through a filter script and I see the same behavior there: the file documentation is perfect, but no auto-linking.
I'm using Doxygen 1.8.15 in windows 10.
Any thoughts are very welcome! Thanks!
Doxyfile:
# General options
PROJECT_NAME = "Double table headers in LaTeX"
INPUT = doc/latex_double.md
INPUT += include/regular_c.h
#INPUT += filtered_c.h
#You should not need to change the rest of the file
OUTPUT_DIRECTORY = output_doc
GENERATE_HTML = YES
GENERATE_TREEVIEW = YES
GENERATE_LATEX = YES
OPTIMIZE_OUTPUT_FOR_C = YES
FILTER_PATTERNS += *.h="c:\Python27\python filter\dummy_filter.py"
Filter Script:
from __future__ import print_function
import sys
if len(sys.argv) != 2:
sys.exit(1)
def extract_globals(filename):
with open(filename, 'r') as infile:
for line in infile:
print(line, end='')
extract_globals(sys.argv[1])
Markdown source:
# Chapter Title {#chapter_title}
Some text here
# Introduction {#chapter_intro}
Loren Ipsum #ref some_c_function
regular_c.h
/**
* #file regular_c.h
* #brief This is a simple C header file with some examples.
*/
#ifndef REGULAR_C_H_
#define REGULAR_C_H_
/* ----------------------------------------------------------------------------
* If building with a C++ compiler, make all of the definitions in this header
* have a C binding.
* ------------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C"
{
#endif /* ifdef __cplusplus */
/* ----------------------------------------------------------------------------
* Include files
* --------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------
* Defines
* --------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------
* Global variables and types
* --------------------------------------------------------------------------*/
/**
* This enumeration has the return codes for the #ref some_c_function function.
*/
typedef enum __SOME_C_FUNCTION_RETURN {
SOME_C_FUNCTION_RETURN_everthing_ok = 0, ///< Nothing to see here
SOME_C_FUNCTION_RETURN_some_weird_error, ///< This is not the error you're looking for
SOME_C_FUNCTION_RETURN_some_very_bad_error, ///< This is not the error we are looking for
SOME_C_FUNCTION_RETURN_life_is_sad_just_cope ///< Move along
} SOME_C_FUNCTION_RETURN;
/* ----------------------------------------------------------------------------
* Function prototype definitions
* --------------------------------------------------------------------------*/
/**
* #brief Some C function that is here just as an example.
*
* This function doesn't actually do anything useful.
*
* #param[in] v We do something with this value.
* #param[out] ptr Some value will be written here.
*
* #return Returns a value that depends on what happened:
* - #ref SOME_C_FUNCTION_RETURN_everthing_ok
* Uh, everything is under control. Situation normal.
* - #ref SOME_C_FUNCTION_RETURN_some_weird_error
* Uh, had a slight weapons malfunction.
* - #ref SOME_C_FUNCTION_RETURN_some_very_bad_error
* We had a reactor leak here now. Give us a few minutes to lock it down.
* Large leak... very dangerous.
* - #ref SOME_C_FUNCTION_RETURN_life_is_sad_just_cope
* Who is this?? What's your operating number?
*
*/
int some_c_function(uint32_t v, void* ptr);
/* ----------------------------------------------------------------------------
* Close the 'extern "C"' block
* ------------------------------------------------------------------------- */
#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */
#endif /* REGULAR_C_H_ */
filtered_c.h
/**
* #file filtered_c.h
* #brief This is a simple C header file with some examples.
*/
#ifndef REGULAR_C_H_
#define REGULAR_C_H_
/* ----------------------------------------------------------------------------
* If building with a C++ compiler, make all of the definitions in this header
* have a C binding.
* ------------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C"
{
#endif /* ifdef __cplusplus */
/* ----------------------------------------------------------------------------
* Include files
* --------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------
* Defines
* --------------------------------------------------------------------------*/
/* ----------------------------------------------------------------------------
* Global variables and types
* --------------------------------------------------------------------------*/
/**
* This enumeration has the return codes for the #ref some_c_function function.
*/
typedef enum __SOME_C_FUNCTION_RETURN {
SOME_C_FUNCTION_RETURN_everthing_ok = 0, ///< Nothing to see here
SOME_C_FUNCTION_RETURN_some_weird_error, ///< This is not the error you're looking for
SOME_C_FUNCTION_RETURN_some_very_bad_error, ///< This is not the error we are looking for
SOME_C_FUNCTION_RETURN_life_is_sad_just_cope ///< Move along
} SOME_C_FUNCTION_RETURN;
/* ----------------------------------------------------------------------------
* Function prototype definitions
* --------------------------------------------------------------------------*/
/**
* #brief Some C function that is here just as an example.
*
* This function doesn't actually do anything useful.
*
* #param[in] v We do something with this value.
* #param[out] ptr Some value will be written here.
*
* #return Returns a value that depends on what happened:
* - #ref SOME_C_FUNCTION_RETURN_everthing_ok
* Uh, everything is under control. Situation normal.
* - #ref SOME_C_FUNCTION_RETURN_some_weird_error
* Uh, had a slight weapons malfunction.
* - #ref SOME_C_FUNCTION_RETURN_some_very_bad_error
* We had a reactor leak here now. Give us a few minutes to lock it down.
* Large leak... very dangerous.
* - #ref SOME_C_FUNCTION_RETURN_life_is_sad_just_cope
* Who is this?? What's your operating number?
*
*/
int some_c_function(uint32_t v, void* ptr);
/* ----------------------------------------------------------------------------
* Close the 'extern "C"' block
* ------------------------------------------------------------------------- */
#ifdef __cplusplus
}
#endif /* ifdef __cplusplus */
#endif /* REGULAR_C_H_ */
I'm facing the problem when trying to get 2 SPI masters working at same time. They both have different pins(mosi, miso, sck, ss) and one is used by SD-Card and another one accelerometer. My device is nRF52832 and I have been trying to use SPI drivers from nRF52 SDK 15.2.0.
I'm not sure if they can be initialized and in use same time, but its feeling quite wrong if the program needs to init and uninit another spi instance whenever it needs to communicate with another one.
Seems that whenever one instance gets initialized the second one does not work correctly. The program does not give any error. This is my first touch to embedded systems and because of that, my skill level is the novice. I really would appreciate all the help.
/**
* Copyright (c) 2016 - 2018, Nordic Semiconductor ASA
*
* 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, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, 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 Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA 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
* #defgroup fatfs_example_main main.c
* #{
* #ingroup fatfs_example
* #brief FATFS Example Application main file.
*
* This file contains the source code for a sample application using FAT filesystem and SD card library.
*
*/
#include "nrf.h"
#include "bsp.h"
#include "ff.h"
#include "diskio_blkdev.h"
#include "nrf_block_dev_sdc.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "nrf_drv_spi.h"
#define FILE_NAME "NORDIC.TXT"
#define TEST_STRING "SD card example."
#define SDC_SCK_PIN 16 ///< SDC serial clock (SCK) pin.
#define SDC_MOSI_PIN 17 ///< SDC serial data in (DI) pin.
#define SDC_MISO_PIN 18 ///< SDC serial data out (DO) pin.
#define SDC_CS_PIN 11 ///< SDC chip select (CS) pin.
#define SDC2_SCK_PIN 5
#define SDC2_MOSI_PIN 4
#define SDC2_MISO_PIN 3
#define SDC2_CS_PIN 12
#define SPI_AC_INSTANCE 1
static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_AC_INSTANCE);
/**
* #brief SDC block device definition
* */
NRF_BLOCK_DEV_SDC_DEFINE(
m_block_dev_sdc,
NRF_BLOCK_DEV_SDC_CONFIG(
SDC_SECTOR_SIZE,
APP_SDCARD_CONFIG(SDC_MOSI_PIN, SDC_MISO_PIN, SDC_SCK_PIN, SDC_CS_PIN)
),
NFR_BLOCK_DEV_INFO_CONFIG("Nordic", "SDC", "1.00")
);
/**
* #brief Function for demonstrating FAFTS usage.
*/
static void fatfs_example()
{
static FATFS fs;
static DIR dir;
static FILINFO fno;
static FIL file;
uint32_t bytes_written;
FRESULT ff_result;
DSTATUS disk_state = STA_NOINIT;
// Initialize FATFS disk I/O interface by providing the block device.
static diskio_blkdev_t drives[] =
{
DISKIO_BLOCKDEV_CONFIG(NRF_BLOCKDEV_BASE_ADDR(m_block_dev_sdc, block_dev), NULL)
};
diskio_blockdev_register(drives, ARRAY_SIZE(drives));
NRF_LOG_INFO("Initializing disk 0 (SDC)...");
for (uint32_t retries = 3; retries && disk_state; --retries)
{
disk_state = disk_initialize(0);
}
if (disk_state)
{
NRF_LOG_INFO("Disk initialization failed.");
return;
}
uint32_t blocks_per_mb = (1024uL * 1024uL) / m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_size;
uint32_t capacity = m_block_dev_sdc.block_dev.p_ops->geometry(&m_block_dev_sdc.block_dev)->blk_count / blocks_per_mb;
NRF_LOG_INFO("Capacity: %d MB", capacity);
NRF_LOG_INFO("Mounting volume...");
ff_result = f_mount(&fs, "", 1);
if (ff_result)
{
NRF_LOG_INFO("Mount failed.");
return;
}
NRF_LOG_INFO("\r\n Listing directory: /");
ff_result = f_opendir(&dir, "/");
if (ff_result)
{
NRF_LOG_INFO("Directory listing failed!");
return;
}
do
{
ff_result = f_readdir(&dir, &fno);
if (ff_result != FR_OK)
{
NRF_LOG_INFO("Directory read failed.");
return;
}
if (fno.fname[0])
{
if (fno.fattrib & AM_DIR)
{
NRF_LOG_RAW_INFO(" <DIR> %s",(uint32_t)fno.fname);
}
else
{
NRF_LOG_RAW_INFO("%9lu %s", fno.fsize, (uint32_t)fno.fname);
}
}
}
while (fno.fname[0]);
NRF_LOG_RAW_INFO("");
NRF_LOG_INFO("Writing to file " FILE_NAME "...");
ff_result = f_open(&file, FILE_NAME, FA_READ | FA_WRITE | FA_OPEN_APPEND);
if (ff_result != FR_OK)
{
NRF_LOG_INFO("Unable to open or create file: " FILE_NAME ".");
return;
}
ff_result = f_write(&file, TEST_STRING, sizeof(TEST_STRING) - 1, (UINT *) &bytes_written);
if (ff_result != FR_OK)
{
NRF_LOG_INFO("Write failed\r\n.");
}
else
{
NRF_LOG_INFO("%d bytes written.", bytes_written);
}
(void) f_close(&file);
return;
}
static uint8_t tx_buf[3];
static uint8_t rx_buf[10]; /**< RX buffer. */
uint8_t accReadByte(uint8_t RegisterAddress)
{
tx_buf[0] = 0x7F & RegisterAddress;
tx_buf[1] = 0x80 & RegisterAddress;
APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, tx_buf, 2, rx_buf, 1+2));
return rx_buf[2];
}
void initAcc()
{
//nrf_gpio_set_cfg_output(SDC2_CS_PIN);
nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
spi_config.ss_pin = SDC2_CS_PIN;
spi_config.miso_pin = SDC2_MISO_PIN;
spi_config.mosi_pin = SDC2_MOSI_PIN;
spi_config.sck_pin = SDC2_SCK_PIN;
spi_config.frequency = NRF_SPI_FREQ_250K;
APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, NULL, NULL));
}
/**
* #brief Function for main application entry.
*/
int main(void)
{
bsp_board_init(BSP_INIT_LEDS);
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("FATFS example started.");
fatfs_example();
initAcc();
if ( accReadByte(0x0D) == 0x6A )
{
NRF_LOG_INFO("Got right whoami!");
}
while (true)
{
__WFE();
}
}
/** #} */
Problem solved. SD-Card and the accelerometer both have different serial bus in default. When initialized another one first, second one failed in bus initialization and that caused nRF52832 not to get the right answer.
I am trying to create an application that reads an excel file using libxls.
I've already downloaded libxls but I do not know how to use it.
Can someone please show me a minimum program to read from a XLS file
If you mean libxls:
There are tests inside the source archive which can be used as sample code.
Here's the content of libxls-1.4.0/test/test2.c:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* This file is part of libxls -- A multiplatform, C/C++ library
* for parsing Excel(TM) files.
*
* 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 David Hoerl ''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 David Hoerl 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.
*
* Copyright 2004 Komarov Valery
* Copyright 2006 Christophe Leitienne
* Copyright 2008-2012 David Hoerl
*
*/
// THIS FILE LETS YOU QUICKLY FEED A .xls FILE FOR PARSING
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "libxls/xls.h"
int main(int argc, char *argv[])
{
xlsWorkBook* pWB;
xlsWorkSheet* pWS;
unsigned int i;
if(argc != 2) {
printf("Need file arg\n");
exit(0);
}
struct st_row_data* row;
WORD t,tt;
pWB=xls_open(argv[1],"UTF-8");
if (pWB!=NULL)
{
for (i=0;i<pWB->sheets.count;i++)
printf("Sheet N%i (%s) pos %i\n",i,pWB->sheets.sheet[i].name,pWB->sheets.sheet[i].filepos);
pWS=xls_getWorkSheet(pWB,0);
xls_parseWorkSheet(pWS);
printf("pWS->rows.lastrow %d\n", pWS->rows.lastrow);
for (t=0;t<=pWS->rows.lastrow;t++)
{
printf("DO IT");
row=&pWS->rows.row[t];
xls_showROW(row);
for (tt=0;tt<=pWS->rows.lastcol;tt++)
{
xls_showCell(&row->cells.cell[tt]);
}
}
printf("Count of rows: %i\n",pWS->rows.lastrow);
printf("Max col: %i\n",pWS->rows.lastcol);
printf("Count of sheets: %i\n",pWB->sheets.count);
xls_showBookInfo(pWB);
} else {
printf("pWB == NULL\n");
}
return 0;
}
If you mean libxl:
Below you'll find a data reading example written in C from http://www.libxl.com/.
Furthermore they provide documentation and more examples on their homepage.
BookHandle book = xlCreateBook();
if(book)
{
if(xlBookLoad(book, L"example.xls"))
{
SheetHandle sheet = xlBookGetSheet(book, 0);
if(sheet)
{
double d;
const wchar_t* s = xlSheetReadStr(sheet, 2, 1, NULL);
if(s) wprintf(L"%s\n", s);
d = xlSheetReadNum(sheet, 3, 1, NULL);
printf("%g\n", d);
}
}
xlBookRelease(book);
}
I'm doing this interesting experiment. But it can be really complicated to understand. I got at least 2 questions.
We have faked a VMA and msync_interval will get it as the comment says. But how does msync_interval get this fake VMA?
Why does it need to consume a lot VMAs?
Many thanks in advance.
/*
* first create fake vma structs.
*
*
* let's have 3 threads, t1, t2 and t3.
* t1 and t2 have common vm.
*
* t3:
* - wait4sig (will come back from t2)
* - write(fd3, bigmem, bigfile_size)
* - exit()
* t1:
* - fd3 = empty file
* - fd1 = bigfile, writing it took 16 secs
* - bigmem = mmap(NULL, bigfile_size, fd1, 0);
* - t3 = fork()
* - t2 = clone()
* - fd2 = munmap_file, size of ram.
* - mumem = mmap(NULL, munmap_file_size, fd2)
* - mmap(mumem, 4096, ANONYMOUS) // for extending do_brk check
* - mmap lots of vmas
* - close(fd2);
* - create evil lib
* - free lot of vmas
* - sig # t2
* - evil_lib->do_munmap(mumem + 4096, munmap_file_size - 4096);
* - sem = 1
* - waitpid
* t2:
* - wait4sig
* - sleep(100msec)
* - mmap(mumem, fd3, 4096) // this is being protected by i_sem !
* - sendsig # t3
* - sleep(100msec)
* - if (sem) error
* - msync(mumem, 8192) - will wait for write() to finish. munmap finishes by that
* time
* - if (!sem) error
* - if it does return we failed, otherwise shell.
*
*/