FMI Library: part of JModelica.org
compress_test_fmu_zip.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Modelon AB
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the BSD style license.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  FMILIB_License.txt file for more details.
11 
12  You should have received a copy of the FMILIB_License.txt file
13  along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <JM/jm_types.h>
19 #include <JM/jm_callbacks.h>
20 #include <FMI/fmi_zip_zip.h>
21 
22 static void importlogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
23 {
24  printf("module = %s, log level = %d: %s\n", module, log_level, message);
25 }
26 
27 int main(int argc, char *argv[])
28 {
29  jm_status_enu_t status;
31  char* output_name;
32  const char** files_to_zip;
33  int n_files_to_zip;
34 
35  callbacks.malloc = malloc;
36  callbacks.calloc = calloc;
37  callbacks.realloc = realloc;
38  callbacks.free = free;
39  callbacks.logger = importlogger;
40  callbacks.log_level = jm_log_level_debug;
41 
42  callbacks.context = 0;
43 
44  if (argc < 3) {
45  printf("Not enought input arguments\n");
46  return 1;
47  }
48 
49  output_name = argv[1];
50  files_to_zip = &argv[2];
51  n_files_to_zip = argc - 2;
52 
53  status = fmi_zip_zip(output_name, n_files_to_zip, files_to_zip, &callbacks);
54 
55  if (status == jm_status_error) {
56  printf("Failed to compress the file\n");
57  return 1;
58  } else {
59  printf("Succesfully compressed the file\n");
60  return 0;
61  }
62 
63 }
jm_calloc_f calloc
Allocate zero initialized memory.
Definition: jm_callbacks.h:77
size_t jm_callbacks * c
jm_log_level_enu_t
Log levels supported via the logger functions in jm_callbacks.
Definition: jm_types.h:51
jm_log_level_enu_t log_level
Logging level.
Definition: jm_callbacks.h:85
v callbacks
static void importlogger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
Verbose messages.
Definition: jm_types.h:58
jm_malloc_f malloc
Allocate non-initialized memory.
Definition: jm_callbacks.h:75
jm_voidp context
Arbitrary context pointer passed to the logger function.
Definition: jm_callbacks.h:87
const char * jm_string
A constant string.
Definition: jm_types.h:33
The callbacks struct is sent to all the modules in the library.
Definition: jm_callbacks.h:73
jm_realloc_f realloc
Re-allocate memory.
Definition: jm_callbacks.h:79
jm_status_enu_t
Return status codes.
Definition: jm_types.h:44
int main(int argc, char *argv[])
jm_free_f free
Free-allocated memory.
Definition: jm_callbacks.h:81
jm_logger_f logger
Logging callback.
Definition: jm_callbacks.h:83