-
Notifications
You must be signed in to change notification settings - Fork 0
/
pgcloader.c
76 lines (59 loc) · 1.4 KB
/
pgcloader.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdarg.h>
/* external libraries required by pgcloader */
#include "libs/libconfig/libconfig.h"
#include "libs/libcsv/csv.h"
#include <libpq-fe.h>
#include <iconv.h>
/* internals */
#include "loader.h"
#include "util.c"
#include "import.c"
/**
* CSV_PARSE field callback function
*/
void fieldHandler ( void *s, size_t i, void *p )
{
fieldCount++;
char *line = malloc ( i+1 );
int c,y = 0;
for ( c = 0; c < allowedFieldsCount; c++ )
{
if ( atoi ( allowedFields[c] ) == fieldCount ) // checking if current field is on allowed fields list
{
snprintf ( line, i+1, "%s\0", s );
strcpy ( currentFields[c], line );
}
}
free ( line );
}
/**
* CSV_PARSE end of line callback function
*/
void eolHandler (int c, void *p)
{
fieldCount = 0;
//printf ( "\n" );
}
int main ( int argc, char *argv[] )
{
initOptions ( argc, argv );
initConfig ( configFile );
pprintf ( 1, "Using config file %s", configFile );
if ( isatty ( fileno ( stdin ) ) )
{
FILE * file = fopen ( inputFile, "r" );
pprintf ( 1, "File to process: %s\n", inputFile );
importFromFile ( file );
}
else
{
pprintf ( 2, "File to process: STDIN\n" );
importFromSTDIN ();
}
return EXIT_SUCCESS;
}