Going on
This commit is contained in:
parent
86f0da1e3a
commit
bca3f3fb88
62
src/c99.c
62
src/c99.c
@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
/* types */
|
/* types */
|
||||||
@ -41,18 +44,77 @@ static int _c99_error(char const * message, int ret)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _c99_do_c(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp);
|
||||||
|
static int _c99_do_E(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp);
|
||||||
|
static int _c99_do_o(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp);
|
||||||
static int _c99_do(Prefs * prefs, char const * outfile, FILE * outfp,
|
static int _c99_do(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
char * infile)
|
char * infile)
|
||||||
{
|
{
|
||||||
FILE * infp;
|
FILE * infp;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if((infp = fopen(infile, "r")) == NULL)
|
if((infp = fopen(infile, "r")) == NULL)
|
||||||
return _c99_error(infile, 1);
|
return _c99_error(infile, 1);
|
||||||
|
if(*prefs & PREFS_c)
|
||||||
|
ret = _c99_do_c(prefs, outfile, outfp, infile, infp);
|
||||||
|
else if(*prefs & PREFS_E)
|
||||||
|
ret = _c99_do_E(prefs, outfile, outfp, infile, infp);
|
||||||
|
else
|
||||||
|
ret = _c99_do_o(prefs, outfile, outfp, infile, infp);
|
||||||
/* FIXME implement */
|
/* FIXME implement */
|
||||||
fclose(infp);
|
fclose(infp);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _c99_do_c(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
char * o = NULL;
|
||||||
|
|
||||||
|
if(outfile == NULL)
|
||||||
|
{
|
||||||
|
if((len = strlen(infile)) < 3 || infile[len-2] != '.'
|
||||||
|
|| infile[len-1] != 'c')
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
|
return _c99_error(infile, 1);
|
||||||
|
}
|
||||||
|
if((o = strdup(infile)) == NULL)
|
||||||
|
return _c99_error("strdup", 1);
|
||||||
|
o[len-1] = 'o';
|
||||||
|
if((outfp = fopen(o, "w")) == NULL)
|
||||||
|
{
|
||||||
|
free(o);
|
||||||
|
return _c99_error(o, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* FIXME implement */
|
||||||
|
if(o != NULL)
|
||||||
|
{
|
||||||
|
fclose(outfp);
|
||||||
|
free(o);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _c99_do_E(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp)
|
||||||
|
{
|
||||||
|
/* FIXME implement */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _c99_do_o(Prefs * prefs, char const * outfile, FILE * outfp,
|
||||||
|
char * infile, FILE * infp)
|
||||||
|
{
|
||||||
|
/* FIXME implement */
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user