FOSSology  4.4.0
Open Source License Compliance by Open Source Software
regexscan-Stage1.c
Go to the documentation of this file.
1 /*
2  regexscan: Scan file(s) for regular expression(s)
3 
4  SPDX-FileCopyrightText: © 2007-2013 Hewlett-Packard Development Company, L.P.
5 
6  SPDX-License-Identifier: GPL-2.0-only
7 */
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 #include <string.h>
22 #include <ctype.h>
23 #include <signal.h>
24 #include <libgen.h>
25 
26 #include "libfossology.h"
27 
28 #define MAXCMD 4096
29 char SQL[256];
30 
31 #define myBUFSIZ 2048
32 
33 /*
34 #ifdef COMMIT_HASH
35 char BuildVersion[]="Build version: " COMMIT_HASH ".\n";
36 #endif
37 */
38 
39 PGconn *pgConn = NULL; // Database connection
40 
44 void Usage (char *Name)
45 {
46  printf("Usage: %s [options] [id [id ...]]\n",Name);
47  printf(" -i :: initialize the database, then exit.\n");
48  printf(" -c SYSCONFDIR :: FOSSology configuration directory.\n");
49  printf(" -h :: show available command line options.\n");
50  printf(" -v :: increase agent logging verbosity.\n");
51 } /* Usage() */
52 
53 /*********************************************************/
54 int main (int argc, char *argv[])
55 {
56  int c;
57 
58  char *COMMIT_HASH;
59  char *VERSION;
60  char agent_rev[myBUFSIZ];
61 
62  /* connect to scheduler. Noop if not run from scheduler. */
63  fo_scheduler_connect(&argc, argv, &pgConn);
64 
65 /*
66  Version reporting.
67 */
68  COMMIT_HASH = fo_sysconfig("regexscan", "COMMIT_HASH");
69  VERSION = fo_sysconfig("regexscan", "VERSION");
70  sprintf(agent_rev, "%s.%s", VERSION, COMMIT_HASH);
71 
72  fprintf(stdout, "regexscan reports version info as '%s.%s'.\n", VERSION, COMMIT_HASH);
73 
74  /* Process command-line */
75  while((c = getopt(argc,argv,"civ")) != -1)
76  {
77  switch(c)
78  {
79  case 'c':
80  break; /* handled by fo_scheduler_connect() */
81  case 'i':
82  PQfinish(pgConn);
83  return(0);
84  case 'v':
85  agent_verbose++;
86  break;
87  case 'h':
88  default:
89  Usage(argv[0]);
90  fflush(stdout);
91  PQfinish(pgConn);
92  exit(-1);
93  }
94  }
95 
96  PQfinish(pgConn);
98 
99  return 0;
100 } /* main() */
101 
The main FOSSology C library.
void fo_scheduler_disconnect(int retcode)
Disconnect the scheduler connection.
char * fo_sysconfig(const char *sectionname, const char *variablename)
gets a system configuration variable from the configuration data.
int agent_verbose
Common verbose flags for the agents, this is used so that the scheduler can change the verbose level ...
void fo_scheduler_connect(int *argc, char **argv, PGconn **db_conn)
Establish a connection between an agent and the scheduler.
void Usage(char *Name)
Say how to run this program.
char SQL[256]
For DB.
PGconn * pgConn
Database connection.