53 int regexScan(
char *regexStr, FILE *scanFilePtr,
char *fileName)
67 retCode = regcomp(®ex, regexStr, REG_ICASE+REG_EXTENDED);
70 fprintf(stderr,
"regex %s failed to compile\n", regexStr);
75 while (fgets(textBuff, 1024, scanFilePtr) != NULL)
78 retCode = regexec(®ex, textBuff, 1, rm, 0);
81 sprintf(msgBuff,
"%s: regex found at line %d at position %d. -> %.*s \n",
82 fileName, lineCount, rm[0].rm_so+1, rm[0].rm_eo-rm[0].rm_so, textBuff + rm[0].rm_so);
89 else if (retCode == REG_NOMATCH)
95 regerror(retCode, ®ex, msgBuff,
sizeof(msgBuff));
96 fprintf(stderr,
"Out of memory? - regex match failure: %s\n", msgBuff);
105 sprintf(msgBuff,
"%s: %s not found\n", fileName, regexStr);
121 printf(
"Usage: %s [options] [id [id ...]]\n",Name);
122 printf(
" -i :: initialize the database, then exit.\n");
123 printf(
" -c SYSCONFDIR :: FOSSology configuration directory.\n");
124 printf(
" -h :: show available command line options.\n");
125 printf(
" -v :: increase agent logging verbosity.\n");
126 printf(
" -r :: regex expression to load from command line.\n");
127 printf(
" filename :: filename to process with regex.\n");
131 int main (
int argc,
char *argv[])
133 int index, nonoptargs = 0;
148 char agent_rev[myBUFSIZ];
158 sprintf(agent_rev,
"%s.%s", VERSION, COMMIT_HASH);
160 fprintf(stdout,
"regexscan reports version info as '%s.%s'.\n", VERSION, COMMIT_HASH);
164 while((c = getopt(argc,argv,
"chir:v")) != -1)
174 sprintf(regexStr,
"%s", optarg);
189 for (index = optind; index < argc; index++)
204 printf(
"UploadPK is: %ld\n", UploadPK);
210 sprintf(fileName,
"%s", argv[optind]);
211 scanFilePtr = fopen(fileName,
"r");
214 fprintf(stderr,
"failed to open text inout file %s\n", fileName);
220 regexScan(regexStr, scanFilePtr, fileName);
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 ...
int fo_scheduler_userID()
Gets the id of the user that created the job that the agent is running.
char * fo_scheduler_current()
Get the last read string from the scheduler.
char * fo_scheduler_next()
Get the next data to process from the scheduler.
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.
int regexScan(char *regexStr, FILE *scanFilePtr, char *fileName)
Regex scanner.
PGconn * pgConn
Database connection.
Store the results of a regex match.