add -o option (output filename)

This commit is contained in:
tTh 2023-04-30 01:03:49 +02:00
parent 7cefa36d62
commit b12bdfe306
3 changed files with 32 additions and 20 deletions

View File

@ -175,9 +175,9 @@ return 0;
}
/* --------------------------------------------------------------------- */
/*
*
* The main procedure, who contains a lot of things.
*/
int try_to_read_an_OBJ_file(char *infname, int outstyle)
int try_to_read_an_OBJ_file(char *infname, char *ofname, int outstyle)
{
FILE *fpin;
char line[LINE_SZ+1], *cptr, *token;
@ -188,7 +188,8 @@ Bubulle bubulle;
char *outfname, *baseptr;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' %d )\n\n", __func__, infname, outstyle);
fprintf(stderr, ">>> %s ( '%s' '%s' %d )\n\n", __func__,
infname, ofname, outstyle);
#endif
/* get memory for generated output filename(s) */
@ -314,8 +315,8 @@ fclose(fpin);
fprintf(stderr, " ***************************************\n");
if(verbosity) {
fprintf(stderr, "%s(): %d vertices loaded\n", __func__, bublist->fidx);
fprintf(stderr, "%s(): %d edges loaded\n", __func__, edges->fidx);
fprintf(stderr, "%s(): %9d vertices loaded\n", __func__, bublist->fidx);
fprintf(stderr, "%s(): %9d edges loaded\n", __func__, edges->fidx);
}
if (verbosity > 1) {
@ -323,7 +324,7 @@ if (verbosity > 1) {
print_edgelist_desc(edges, 0);
}
if (outstyle) { /* two ascii files */
if (outstyle) { /* two ascii files */
strcpy(outfname, infname);
cptr = rindex(outfname, '.');
fprintf(stderr, "rindex -> [%s]\n", cptr);
@ -331,15 +332,23 @@ if (outstyle) { /* two ascii files */
bubulles_to_data(outfname, NULL, bublist, 0);
// edges_to_data(file_edges, edges, 0);
}
else { /* one 'evblob' file */
strcpy(outfname, infname);
/* see manpage basename(3) */
baseptr = basename(outfname);
// fprintf(stderr, "baseptr -> [%s]\n", baseptr);
cptr = rindex(baseptr, '.');
strcpy(cptr, ".evblob");
// fprintf(stderr, "baseptr-> [%s]\n", baseptr);
foo = x_write_vertedges(baseptr, bublist, edges);
else { /* one 'evblob' file */
if (NULL == ofname) {
strcpy(outfname, infname);
/* see manpage basename(3) */
baseptr = basename(outfname);
// fprintf(stderr, "baseptr -> [%s]\n", baseptr);
cptr = rindex(baseptr, '.');
strcpy(cptr, ".evblob");
fprintf(stderr, "baseptr-> [%s]\n", baseptr);
cptr = baseptr;
}
else {
cptr = ofname;
fprintf(stderr, "writing to %s\n", cptr);
}
foo = x_write_vertedges(cptr, bublist, edges);
if (foo) {
fprintf(stderr, "Err #%d when writing edges&vertices file\n", foo);
}

View File

@ -15,7 +15,7 @@ typedef struct {
} EdgesAndVertices;
/* in importobj.c */
int try_to_read_an_OBJ_file(char *fname, int outstyle);
int try_to_read_an_OBJ_file(char *fname, char *oname, int outstyle);
/* in rdwredges.c */
int x_write_vertedges (char *filename, BBList *bblist, EdgeList *edges);

View File

@ -25,7 +25,7 @@ exit(0);
int main(int argc, char *argv[])
{
int foo, opt;
// char *fname; /* see manpage basename(3) */
char *ofname = NULL;
fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__);
@ -34,10 +34,13 @@ if (1 == argc) {
exit(0);
}
while ((opt = getopt(argc, argv, "hv")) != -1) {
while ((opt = getopt(argc, argv, "ho:v")) != -1) {
switch(opt) {
case 'h':
help(); break;
case 'o':
ofname = optarg;
break;
case 'v':
verbosity++; break;
default:
@ -48,8 +51,8 @@ while ((opt = getopt(argc, argv, "hv")) != -1) {
if (optind < argc) {
// fprintf(stderr, "ARG = %s\n", argv[optind]);
foo = try_to_read_an_OBJ_file(argv[optind], 0);
fprintf(stderr, "arg = %s\n", argv[optind]);
foo = try_to_read_an_OBJ_file(argv[optind], ofname, 0);
if (foo) {
fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]);
exit(1);