00001 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00002 * 00003 * Redistribution and use in source and binary forms, with or without 00004 * modification, are permitted provided that the following conditions are met: 00005 * 00006 * 1. Redistributions of source code must retain the above copyright notice, this 00007 * list of conditions and the following disclaimer. 00008 * 00009 * 2. Redistributions in binary form must reproduce the above copyright notice, 00010 * this list of conditions and the following disclaimer in the documentation 00011 * and/or other materials provided with the distribution. 00012 * 00013 * 3. The name of Atmel may not be used to endorse or promote products derived 00014 * from this software without specific prior written permission. 00015 * 00016 * 4. This software may only be redistributed and used in connection with an Atmel 00017 * AVR product. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00020 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00021 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00022 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00029 * 00030 */ 00031 00032 #include <stdio.h> 00033 #include <stdlib.h> 00034 #include "error_management.h" 00035 #include "format_data.h" 00036 00037 void format_data(char *_path, char *_pattern, int n_arg) 00038 { 00039 char *_buffer; 00040 int n, n_data; 00041 FILE *_file; 00042 float *_data; 00043 00044 ASSERT(_path); 00045 00046 // Open the file 00047 _file = fopen(_path, "rb"); 00048 ASSERT(_file); 00049 // Get the length of the file and store it into n 00050 fseek(_file, 0, SEEK_END); 00051 n = ftell(_file); 00052 // allocate a buffer of the size of the file 00053 _buffer = (char *) malloc(n + 1); 00054 ASSERT(_buffer); 00055 _buffer[n] = '\0'; 00056 // Go to the beginning of the file 00057 fseek(_file, 0, SEEK_SET); 00058 // Read it 00059 fread(_buffer, 1, n, _file); 00060 fclose(_file); 00061 00062 // Extract data from a buffer 00063 n_data = format_data_get_data(_buffer, _pattern, n_arg); 00064 00065 free(_buffer); 00066 } 00067 00068 // Main function 00069 int main(int argc, char *argv[]) 00070 { 00071 00072 // If there arguments passed to this program 00073 if (argc == 4) 00074 format_data(argv[1], argv[2], atoi(argv[3])); 00075 // Else print the usage 00076 else 00077 printf("Usage: DataExtract input_buffer_file_path pattern n_arg\n\r"); 00078 00079 return 0; 00080 }