2024-11-21 11:54:13 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* base header
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* This file is part of Gem-graph.
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* @cond LICENSE
|
|
|
|
* Copyright © 2021 Libre en Communs <contact@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Adrien Bourmault <neox@a-lec.org>
|
|
|
|
* Copyright © 2021-2024 Jean Sirmai <jean@a-lec.org>
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
|
|
* later version.
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
* details.
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* @endcond
|
2024-04-20 11:17:01 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <glib-2.0/glib.h>
|
2024-11-21 11:54:13 +01:00
|
|
|
|
2024-04-20 11:17:01 +02:00
|
|
|
//#define G_APPLICATION_DEFAULT_FLAGS 0
|
|
|
|
|
2024-11-21 11:54:13 +01:00
|
|
|
struct arrow_t { uint load; uint site; uint x; uint y; uint z; };
|
|
|
|
static inline char *read_file(char *filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* I'm standing on Earth (or any spinning spheroid)
|
|
|
|
* and looking towards its North pole,
|
|
|
|
*
|
|
|
|
* then :
|
|
|
|
*
|
|
|
|
* X - X = EAST - WEST = red - cyan
|
|
|
|
* Y - Y = ZENITH - NADIR = green - magenta (fuschia)
|
|
|
|
* Z - Z = SOUTH - NORTH = blue - yellow
|
|
|
|
*/
|
|
|
|
enum axis { X_AXIS, Y_AXIS, Z_AXIS, N_AXIS };
|
2024-04-20 11:17:01 +02:00
|
|
|
|
|
|
|
|
2024-11-21 11:54:13 +01:00
|
|
|
#define EAST 0 /**< +x red */
|
|
|
|
#define WEST 1 /**< -x cyan */
|
|
|
|
#define ZENITH 2 /**< +y green */
|
|
|
|
#define NADIR 3 /**< -y magenta or fuschia */
|
|
|
|
#define SOUTH 4 /**< +z blue */
|
|
|
|
#define NORTH 5 /**< -z yellow */
|
2024-04-20 11:17:01 +02:00
|
|
|
|
|
|
|
|
2024-11-21 11:54:13 +01:00
|
|
|
/**
|
|
|
|
* char *read_file(char *filename)
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* reads a file from filename into a provided buffer
|
2024-04-20 11:17:01 +02:00
|
|
|
*
|
2024-11-21 11:54:13 +01:00
|
|
|
* @param *filename
|
2024-04-20 11:17:01 +02:00
|
|
|
*/
|
|
|
|
static inline char *read_file(char *filename)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int filesize;
|
|
|
|
char *contents;
|
|
|
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
if(fd < 0) {
|
|
|
|
printf("Couldn't read file: %s\n",filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesize = lseek(fd, 0, SEEK_END) + 1 ;
|
|
|
|
contents = g_malloc(filesize * sizeof(char));
|
|
|
|
assert (contents);
|
|
|
|
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
|
|
|
read(fd,contents,filesize);
|
|
|
|
|
|
|
|
contents[filesize-1] = '\0';
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return contents;
|
|
|
|
}
|
|
|
|
|