-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
85 lines (69 loc) · 1.49 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
// main.c
//
#include <getopt.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "ideadb.h"
#include "eyeoh.h"
int verbose = 0;
int term_width;
ideas_t ideas;
void displayHelp( void )
{
return;
}
int main ( int argc, char* argv[] )
{
int c;
char *db_dir;
struct winsize w;
ioctl( STDOUT_FILENO, TIOCGWINSZ, &w );
term_width = w.ws_col;
db_dir = getenv( "HOME" );
while (( c = getopt( argc, argv, "hvd:")) != -1 )
{
switch( c )
{
case 'v':
verbose = 1;
break;
case 'h':
displayHelp( );
return 0;
case 'd':
{
DIR* dir = opendir( optarg );
if ( dir )
{
db_dir = optarg;
closedir( dir );
}
else if ( errno == ENOENT )
{
printf("Specified subdirectory does not exist.\n");
return 0;
}
}
break;
default:
printf( "Unknown option %c\n", (char)c );
break;
}
}
if (verbose)
{
printf("Using directory %s\n", db_dir);
}
srand( time( NULL ) );
listInit( &ideas );
// Try to read the idea database into the list
readDatabase( &ideas, db_dir );
execInterpreter( &ideas );
storeDatabase( &ideas, db_dir );
return 0;
}