68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
/* *****************************************************************************
|
|
* mcsfile/main.c -- mcsfile main source.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of p7utils.
|
|
* p7utils is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2.0 of the License,
|
|
* or (at your option) any later version.
|
|
*
|
|
* p7utils 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************** */
|
|
#include "main.h"
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <locale.h>
|
|
#define cry(S, ...) fprintf(stderr, (S), ##__VA_ARGS__)
|
|
|
|
/**
|
|
* main:
|
|
* Entry point of the program.
|
|
*
|
|
* @arg ac the arguments count.
|
|
* @arg av the arguments values.
|
|
* @return the status code (0 if ok).
|
|
*/
|
|
|
|
int main(int ac, char **av)
|
|
{
|
|
/* set the locale */
|
|
setlocale(LC_ALL, "");
|
|
|
|
/* parse arguments */
|
|
const char *path;
|
|
if (parse_args(ac, av, &path))
|
|
return (0);
|
|
|
|
/* parse */
|
|
g1m_t *handle; int err;
|
|
if ((err = g1m_open(&handle, path, g1m_type_mcs))) switch (err) {
|
|
case g1m_error_wrong_type:
|
|
cry("An MCS file was expected (g1m/g1r, g1m/g2r, g3m)\n");
|
|
return (0);
|
|
case g1m_error_nostream:
|
|
cry("Could not open file: %s\n", strerror(errno));
|
|
return (0);
|
|
case g1m_error_magic:
|
|
cry("Magic error: file might be corrupted\n");
|
|
return (0);
|
|
case g1m_error_eof:
|
|
cry("Unexpected end of file\n");
|
|
return (0);
|
|
}
|
|
|
|
/* read */
|
|
put_files(handle);
|
|
|
|
/* no error */
|
|
g1m_free(handle);
|
|
return (0);
|
|
}
|