|
funkalicious 0.1
|
#include <errno.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <gio/gio.h>#include <glib-2.0/glib.h>#include "material_slice_args.h"#include "config.h"
Include dependency graph for material_slice_args.c:Go to the source code of this file.
Defines | |
| #define | MATERIAL_SLICE_ARGS_DOMAIN 1025 |
Functions | |
| void | program_print_version (FILE *f) |
| void | libdotcode_print_version (FILE *f) |
| double * | new_double_from_string (const char *s, GError **err) |
| int * | new_int_from_string (const char *s, GError **err) |
| struct args * | process_args (int argc, char **argv, GError **err) |
Variables | |
| struct args | args |
| #define MATERIAL_SLICE_ARGS_DOMAIN 1025 |
Definition at line 39 of file material_slice_args.c.
Referenced by new_double_from_string(), new_int_from_string(), and process_args().
| void libdotcode_print_version | ( | FILE * | f | ) |
| double* new_double_from_string | ( | const char * | s, |
| GError ** | err | ||
| ) |
Definition at line 48 of file material_slice_args.c.
References MATERIAL_SLICE_ARGS_DOMAIN.
{
double* d = (double*)malloc(sizeof(double));
if(d == NULL) {
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 1, "getChainPotential_args.c::new_double_from_string: Error occurred converting string (%s) to double: out of memory/malloc failed", s);
return NULL;
}
char *end;
errno = 0;
*d = strtod(s, &end);
if(((end == s) && (*d == 0)) || (errno != 0)) {
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 2, "getChainPotential_args.c::new_double_from_string: Error occurred converting string (%s) to double: %s", s, strerror(errno));
free(d);
return NULL;
}
return d;
}
| int* new_int_from_string | ( | const char * | s, |
| GError ** | err | ||
| ) |
Definition at line 65 of file material_slice_args.c.
References MATERIAL_SLICE_ARGS_DOMAIN.
{
int* d = (int*)malloc(sizeof(int));
if(d == NULL) {
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 1, "getChainPotential_args.c::new_int_from_string: Error occurred converting string (%s) to int: out of memory/malloc failed", s);
return NULL;
}
char *end;
errno = 0;
*d = strtod(s, &end);
if(((end == s) && (*d == 0)) || (errno != 0)) {
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 2, "getChainPotential_args.c::new_int_from_string: Error occurred converting string (%s) to int: %s", s, strerror(errno));
free(d);
return NULL;
}
return d;
}
| struct args* process_args | ( | int | argc, |
| char ** | argv, | ||
| GError ** | err | ||
| ) | [read] |
Processes the arguments to process_args
| argc | argc from main |
| argv | argv from main |
Definition at line 82 of file material_slice_args.c.
References args, e, GET_VHARTREE_SLICE_ARGS_GERROR_DOMAIN, libdotcode_print_version(), MATERIAL_SLICE_ARGS_DOMAIN, new_int_from_string(), PACKAGE_NAME, print_version(), program_print_version(), SIZEOF_DOUBLE, SIZEOF_INT, args::struct_list, VERSION, args::xslices, args::yslices, and args::zslices.
{
int errored = 0;
gchar **file_names = NULL;
gboolean print_version = FALSE;
gchar** xslices = NULL;
gchar** yslices = NULL;
gchar** zslices = NULL;
GOptionEntry options[] = {
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &file_names,},
{ "version", 'v', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_NONE, &print_version, "Print version information about this program", NULL },
{ "xslice", 'X', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(xslices), "x coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", NULL},
{ "yslice", 'Y', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(yslices), "y coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", NULL},
{ "zslice", 'Z', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_STRING_ARRAY, &(zslices), "z coordinate (in grid sites) along which to output a 2D slice of the total density and the resulting potential", NULL},
{NULL}
};
GOptionContext *ctx;
ctx = g_option_context_new("- create a dotcode potential for the specified grid of nearest neighbors");
g_option_context_add_main_entries(ctx, options, "Options");
g_option_context_parse(ctx, &argc, &argv, NULL);
args.xslices = NULL;
int *d;
GError *e = NULL;
if(xslices != NULL) {
for(int i=0; xslices[i] != NULL; i++) {
if((d=new_int_from_string(xslices[i], &e)) != NULL) {
args.xslices = g_list_append(args.xslices, d);
}else{
*err = e;
return NULL;
}
}
}
args.yslices = NULL;
e = NULL;
if(yslices != NULL) {
for(int i=0; yslices[i] != NULL; i++) {
if((d=new_int_from_string(yslices[i], &e)) != NULL) {
args.yslices = g_list_append(args.yslices, d);
}else{
*err = e;
return NULL;
}
}
}
args.zslices = NULL;
e = NULL;
if(zslices != NULL) {
for(int i=0; zslices[i] != NULL; i++) {
if((d=new_int_from_string(zslices[i], &e)) != NULL) {
args.zslices = g_list_append(args.zslices, d);
}else{
*err = e;
return NULL;
}
}
}
gchar* htext = g_option_context_get_help(ctx, FALSE, NULL);
g_option_context_free(ctx);
args.struct_list = NULL;
if(file_names != NULL) {
for(int i = 0; file_names[i] != NULL; i++) {
args.struct_list = g_list_append(args.struct_list, g_file_new_for_commandline_arg(file_names[i]));
}
}
if(args.struct_list == NULL) {
fprintf(stderr, "ERROR: you MUST give at least one grid to process!\n");
errored=1;
}
if(errored){
printf("%s", htext);
printf("\n\n**For version and compilation information, run with --version***");
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 7, "\n");
return NULL;
}
if(print_version){
program_print_version(stdout);
libdotcode_print_version(stdout);
printf("autotools info:\n\tProject: %s\n\tVersion: %s\n", PACKAGE_NAME, VERSION);
printf("Platform information:\n\tSize of int=%d double=%d\n\tEndianness: %s\n", SIZEOF_INT, SIZEOF_DOUBLE,
#ifdef WORDS_BIGENDIAN
"big"
#else
"little"
#endif
);
*err = g_error_new(MATERIAL_SLICE_ARGS_DOMAIN, 7, "\n");
return NULL;
}
if(errored){
return NULL;
}
return &args;
}
Here is the call graph for this function:| void program_print_version | ( | FILE * | f | ) |
{
.struct_list = NULL,
.xslices = NULL,
.yslices = NULL,
.zslices = NULL,
}
Definition at line 41 of file material_slice_args.c.