-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
94 lines (82 loc) · 2.77 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
#include <ctype.h>
#include <igraph.h>
#include "sia2graph.tab.h"
#include "sia.h"
char* __src_file_name;
extern FILE *zzin;
extern int zzparse( void** );
extern int zzlex_destroy();
int main( int argc, char **argv ) {
void* sias = NULL;
const char* build_path = NULL;
const char* format = NULL;
FILE* src_smx;
int c;
sia_t* symbols = NULL;
igraph_i_set_attribute_table( &igraph_cattribute_table );
while( ( c = getopt( argc, argv, "hvp:f:" ) ) != -1 )
switch( c ) {
case 'h':
printf( "Usage:\n %s [OPTION...] FILE\n\n", argv[0] );
printf( "Options:\n" );
printf( " -h This message\n" );
printf( " -v Version\n" );
printf( " -p 'path' Build path to folder where the output files will be stored\n" );
printf( " -f 'format' Format of the graph either 'gml' or 'graphml'\n" );
return 0;
case 'v':
printf( "smxc-v0.0.1\n" );
return 0;
case 'p':
build_path = optarg;
break;
case 'f':
format = optarg;
break;
case '?':
if( ( optopt == 'p' ) || ( optopt == 'f' ) )
fprintf ( stderr, "Option -%c requires an argument.\n",
optopt );
else if ( isprint (optopt) )
fprintf ( stderr, "Unknown option `-%c'.\n", optopt );
else
fprintf ( stderr, "Unknown option character `\\x%x'.\n",
optopt );
return 1;
default:
abort();
}
if( argc <= optind ) {
fprintf( stderr, "Missing argument!\n" );
return -1;
}
__src_file_name = argv[ optind ];
src_smx = fopen( __src_file_name, "r" );
// make sure it is valid:
if( !src_smx ) {
printf( "Cannot open file '%s'!\n", __src_file_name );
return -1;
}
if( format == NULL ) format = G_FMT_GRAPHML;
if( build_path == NULL ) build_path = "./build";
mkdir( build_path, 0755 );
// set flex to read from it instead of defaulting to STDIN yyin = myfile;
zzin = src_smx;
// parse through the input until there is no more:
do {
zzparse( &sias );
} while( !feof( zzin ) );
fclose( src_smx );
if( sias == NULL ) return -1;
sia_check( sias, &symbols );
sias_write( &symbols, build_path, format );
/* if( zznerrs > 0 ) printf( " Error count: %d\n", zznerrs ); */
// cleanup
sias_destroy( sias, &symbols );
zzlex_destroy();
return 0;
}