FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
licenses.c
Go to the documentation of this file.
1 /***************************************************************
2  Copyright (C) 2006-2013 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17  ***************************************************************/
18 /* Equivalent to core nomos v1.48 */
19 
27 #define _GNU_SOURCE
28 
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <time.h>
33 #include <signal.h>
34 #include <libgen.h>
35 #include <limits.h>
36 #include <stdlib.h>
37 
38 #include "nomos.h"
39 #include "licenses.h"
40 #include "nomos_utils.h"
41 #include "util.h"
42 #include "list.h"
43 #include "nomos_regex.h"
44 #include "parse.h"
45 #include "_autodefs.h"
46 
47 #define HASHES "#####################"
48 #define DEBCPYRIGHT "debian/copyright"
49 
50 static void makeLicenseSummary(list_t *, int, char *, int);
51 static void noLicenseFound();
52 #ifdef notdef
53 static void licenseStringChecks();
54 static void findLines(char *, char *, int, int, list_t *);
55 #endif /* notdef */
56 static int searchStrategy(int, char *, int);
57 static void saveLicenseData(scanres_t *, int, int, int);
58 static int scoreCompare(const void *, const void *);
59 static void printHighlightInfo(GArray* keyWords, GArray* theMatches);
60 static char any[6];
61 static char some[7];
62 static char few[6];
63 static char year[7];
64 
65 #ifdef MEMSTATS
66 extern void memStats();
67 #endif /* MEMSTATS */
68 #ifdef STOPWATCH
69 DECL_TIMER;
70 int timerBytes;
71 char timerName[64];
72 #endif /* STOPWATCH */
73 
74 #ifndef MAX
75 #define MAX(a, b) ((a) > (b) ? a : b)
76 #define MIN(a, b) ((a) < (b) ? a : b)
77 #endif
78 
82 void licenseInit() {
83 
84  int i;
85  int len;
86  int same;
87  int ssAbove = 0;
88  int ssBelow = 0;
89  item_t *p;
90  char *cp;
91  char buf[myBUFSIZ];
92 
93 #ifdef PROC_TRACE
94  traceFunc("== licenseInit()\n");
95 #endif /* PROC_TRACE */
96 
97  strcpy(any, "=ANY=");
98  strcpy(some, "=SOME=");
99  strcpy(few, "=FEW=");
100  strcpy(year, "=YEAR=");
101  listInit(&gl.sHash, 0, "search-cache"); /* CDB - Added */
102 
110  for (i = 0; i < NFOOTPRINTS; i++) {
111  same = 0;
112  len = licSpec[i].seed.csLen;
113  if (licSpec[i].text.csData == NULL_STR) {
114  licText[i].tseed = "(null)";
115  }
116  if ((licSpec[i].text.csLen == 1) && (*(licSpec[i].text.csData) == '.')) {
117  same++;
118  /*CDB -- CHanged next line to use ! */
119  }
120  else if ((licSpec[i].seed.csLen == licSpec[i].text.csLen) && !memcmp(
121  licSpec[i].seed.csData, licSpec[i].text.csData, len)) {
122  same++;
123  }
130 #ifdef FIX_STRINGS
131  fixSearchString(buf, sizeof(buf), i, YES);
132 #endif /* FIX_STRINGS */
133 
134  licText[i].tseed = licSpec[i].seed.csData;
135 
136  /*---------------------------------------*/
137  /* CDB - This is the code that I inadvertently removed. */
141  if ((p = listGetItem(&gl.sHash, licText[i].tseed)) == NULL_ITEM) {
142  LOG_FATAL("Cannot enqueue search-cache item \"%s\"", licText[i].tseed)
143  Bail(-__LINE__);
144  }
145  p->refCount++;
146 
147  /*--------------------------------*/
148 
152  if (strcmp(licText[i].tseed, "=NULL=") == 0) { /* null */
153 #ifdef OLD_DECRYPT
154  memFree(licText[i].tseed, MTAG_SEEDTEXT);
155 #endif /* OLD_DECRYPT */
156  licText[i].tseed = NULL_STR;
157  licText[i].nAbove = licText->nBelow = -1;
158  }
159  if (same) { /* seed == phrase */
160  licText[i].regex = licText[i].tseed;
161 #if 0
162  ssBelow = searchStrategy(i, buf, NO);
163  licText[i].nBelow = MIN(ssBelow, 2);
164 #endif
165  licText[i].nAbove = licText[i].nBelow = 0;
166  }
172  else { /* seed != phrase */
173  len = licSpec[i].text.csLen;
174  memcpy(buf, licSpec[i].text.csData, (size_t)(len + 1));
175 #ifdef OLD_DECRYPT
176  decrypt(buf, len);
177 #endif /* OLD_DECRYPT */
178  ssAbove = searchStrategy(i, buf, YES);
179  ssBelow = searchStrategy(i, buf, NO);
180 #if 0
181  licText[i].nAbove = MIN(ssAbove, 3);
182  licText[i].nBelow = MIN(ssBelow, 6);
183 #endif
184  licText[i].nAbove = licText[i].nBelow = 1; /* for now... */
185 #ifdef FIX_STRINGS
186  fixSearchString(buf, sizeof(buf), i, NO);
187 #endif /* FIX_STRINGS */
188  licText[i].regex = copyString(buf, MTAG_SRCHTEXT);
189  }
190  if (p->ssComp < (ssAbove * 100) + ssBelow) {
191  p->ssComp = (ssAbove * 100) + ssBelow;
192  }
193  licText[i].compiled = 0;
194  licText[i].plain = 1; /* assume plain-text for now */
195  }
203  for (i = 0; i < NFOOTPRINTS; i++) {
204  if (licText[i].tseed == NULL_STR) {
205 #ifdef LICENSE_DEBUG
206  LOG_NOTICE("License[%d] configured with NULL seed", i)
207 #endif /* LICENSE_DEBUG */
208  continue;
209  }
210  if (licText[i].tseed == licText[i].regex) {
211 #ifdef LICENSE_DEBUG
212  LOG_NOTICE("License[%d] seed == regex", i)
213 #endif /* LICENSE_DEBUG */
214  continue;
215  }
216  licText[i].nAbove = p->ssComp / 100;
217  licText[i].nBelow = p->ssComp % 100;
218  }
219 
226  for (i = 0; i < NFOOTPRINTS; i++) {
227  for (cp = _REGEX(i); licText[i].plain && *cp; cp++) {
228  switch (*cp) {
229  case '.':
230  case '*':
231  case '+':
232  case '|':
233  case '[':
234  case ']':
235  case '(':
236  case ')':
237  case '^':
238  case '$':
239  case '?':
240  case ',':
241  case '<':
242  case '>':
243  case '{':
244  case '}':
245  case '\\':
246  licText[i].plain = 0;
247  break;
248  }
249  }
250  if (i >= _CR_first && i <= _CR_last) {
251  continue;
252  }
253  }
254  return;
255 }
256 
257 #define LINE_BYTES 50
258 #define LINE_WORDS 8
259 #define WC_BYTES 30
260 #define WC_WORDS 3
261 #define PUNT_LINES 3
262 #define MIN_LINES 1
285 static int searchStrategy(int index, char *regex, int aboveCalc) {
286  char *start;
287  char *cp;
288  char *s;
289  char seed[myBUFSIZ];
290  int words;
291  int lines;
292  int bytes;
293  int minLines;
294  int matchWild;
295  int matchSeed;
296 
297 #ifdef PROC_TRACE
298  traceFunc("== searchStrategy(%d(%s), \"%s\", %d)\n", index,
299  _SEED(index), regex, aboveCalc);
300 #endif /* PROC_TRACE */
301 
302  s = _SEED(index);
303  if (s == NULL_STR || strlen(s) == 0) {
304 #ifdef LICENSE_DEBUG
305  LOG_NOTICE("Lic[%d] has NULL seed", index)
306 #endif /* LICENSE_DEBUG */
307  return (0);
308  }
309  if (regex == NULL_STR || strlen(regex) == 0) {
310 #ifdef LICENSE_DEBUG
311  Assert(NO, "searchStrategy(%d) called with NULL data", index);
312 #endif /* LICENSE_DEBUG */
313  return (0);
314  }
315  if (strcmp(s, regex) == 0) {
316  return (0);
317  }
318  bytes = words = lines = 0;
319  (void) strcpy(seed, s);
320  while (seed[strlen(seed) - 1] == ' ') {
321  seed[strlen(seed) - 1] = NULL_CHAR;
322  }
323  /* how far ABOVE to look depends on location of the seed in footprint */
324  if (aboveCalc) {
325  if (strGrep(seed, regex, REG_ICASE) == 0) {
326 #ifdef LICENSE_DEBUG
327  printf("DEBUG: seed(%d) no hit in regex!\n", index);
328 #endif /* LICENSE_DEBUG */
329  return (PUNT_LINES); /* guess */
330  }
331  start = regex;
332  cp = start;
333  for (minLines = 0; cp != NULL; start = cp + 1) {
334  matchWild = matchSeed = 0;
335  if ((cp = strchr(start, ' ')) != NULL_STR) {
336  *cp = NULL_CHAR;
337  }
338  matchWild = (strcmp(start, any) == 0 || strcmp(start, some) == 0
339  || strcmp(start, few));
340  matchSeed = strcmp(start, seed) == 0;
341  if (!matchSeed) {
342  bytes += (matchWild ? WC_BYTES : strlen(start) + 1);
343  words += (matchWild ? WC_WORDS : 1);
344  }
345  if (cp != NULL_STR) {
346  *cp = ' ';
347  }
348  if (matchSeed) { /* found seed? */
349  break;
350  }
351  }
352  /* optimization for single-lines: */
353  minLines += (words >= LINE_WORDS / 2 && words < LINE_WORDS);
354  lines = MAX(bytes/LINE_BYTES, words/LINE_WORDS) + minLines;
355 #ifdef LICENSE_DEBUG
356  printf("ABOVE: .... bytes=%d, words=%d; max(%d,%d)+%d == %d\n",
357  bytes, words, bytes/LINE_BYTES, words/LINE_WORDS,
358  minLines, lines);
359 #endif /* LICENSE_DEBUG */
360  return (words == 0 ? 0 : lines);
361  }
362  /* calculate how far below to look -- depends on length of footprint */
363  for (minLines = MIN_LINES, cp = start = regex; cp; start = cp + 1) {
364  matchWild = matchSeed = 0;
365  if ((cp = strchr(start, ' ')) != NULL_STR) {
366  *cp = NULL_CHAR;
367  }
368  matchWild = (strcmp(start, any) == 0 || strcmp(start, some) == 0
369  || strcmp(start, few));
370  matchSeed = strcmp(start, seed) == 0;
371  if (matchSeed) {
372  bytes = words = 0;
373  /*minLines = MIN_LINES+1;*/
374  }
375  else {
376  bytes += (matchWild ? WC_BYTES : strlen(start) + 1);
377  words += (matchWild ? WC_WORDS : 1);
378  }
379  if (cp != NULL_STR) {
380  *cp = ' ';
381  }
382  }
383  lines = MAX(bytes/LINE_BYTES, words/LINE_WORDS) + minLines;
384 #ifdef LICENSE_DEBUG
385  printf("BELOW: .... bytes=%d, words=%d; max(%d,%d)+%d == %d\n",
386  bytes, words, bytes/LINE_BYTES, words/LINE_WORDS, minLines, lines);
387 #endif /* LICENSE_DEBUG */
388  return (lines);
389 }
390 
391 #ifdef FIX_STRINGS
392 static void fixSearchString(char *s, int size, int i, int wildcardBad)
393 {
394  char *cp;
395  int len;
396  char wildCard[16];
397  /* */
398 #ifdef PROC_TRACE
399  traceFunc("== fixSearchString(\"%s\", %d, %d, %d)\n", s, size, i,
400  wildcardBad);
401 #endif /* PROC_TRACE */
402  /* */
415  cp = s;
416  while (isspace(*cp)) {
417  cp++;
418  }
419  if (strncmp(cp, any, sizeof(any)-1) == 0 ||
420  strncmp(cp, some, sizeof(some)-1) == 0 ||
421  strncmp(cp, few, sizeof(few)-1) == 0) {
422  printf("string %d == \"%s\"\n", i, cp);
423  LOG_FATAL("Text-spec %d begins with a wild-card", i)
424  Bail(-__LINE__);
425  }
426  /*
427  * We'll replace the string " =ANY=" (6 chars) with ".*" (2 chars).
428  * The token MUST OCCUR BY ITSELF (e.g., not a substring)!
429  */
430  (void) sprintf(wildCard, " %s", any);
431  len = strlen(wildCard);
432  for (cp = s; strGrep(wildCard, cp, 0); ) {
433  if (wildcardBad) {
434  LOG_FATAL("OOPS, regex %d, wild-card not allowed here", i)
435  Bail(-__LINE__);
436  }
437  if (*(cp+cur.regm.rm_eo) == NULL_CHAR) {
438  LOG_FATAL("String %d ends in a wild-card", i)
439  Bail(-__LINE__);
440  }
441  else if (*(cp+cur.regm.rm_eo) == ' ') {
442 #ifdef DEBUG
443  printf("BEFORE(any): %s\n", s);
444 #endif /* DEBUG */
445  cp += cur.regm.rm_so;
446  *cp++ = '.';
447  *cp++ = '*';
448  memmove(cp, cp+len-1, strlen(cp+len)+2);
449 #ifdef DEBUG
450  printf("_AFTER(any): %s\n", s);
451 #endif /* DEBUG */
452  }
453  else {
454  LOG_NOTICE("Wild-card \"%s\" sub-string, phrase %d", wildCard, i)
455  cp += cur.regm.rm_eo;
456  }
457  }
458  /*
459  * Ditto for replacing " =SOME= " (8 chars) with ".{0,60}" (7 chars)
460  */
461  (void) sprintf(wildCard, " %s", some);
462  len = strlen(wildCard);
463  for (cp = s; strGrep(wildCard, cp, 0); ) {
464  if (wildcardBad) {
465  LOG_FATAL("OOPS, regex %d, wild-card not allowed here", i)
466  Bail(-__LINE__);
467  }
468  if (*(cp+cur.regm.rm_eo) == NULL_CHAR) {
469  LOG_FATAL("String %d ends in a wild-card", i)
470  Bail(-__LINE__);
471  }
472  else if (*(cp+cur.regm.rm_eo) == ' ') {
473 #ifdef DEBUG
474  printf("BEFORE(some): %s\n", s);
475 #endif /* DEBUG */
476  cp += cur.regm.rm_so;
477  *cp++ = '.';
478  *cp++ = '{';
479  *cp++ = '0';
480  *cp++ = ',';
481  *cp++ = '6';
482  *cp++ = '0';
483  *cp++ = '}';
484  memmove(cp, cp+len-6, strlen(cp+len)+7);
485 #ifdef DEBUG
486  printf("_AFTER(some): %s\n", s);
487 #endif /* DEBUG */
488  }
489  else {
490  LOG_NOTICE("Wild-card \"%s\" sub-string, phrase %d", wildCard, i)
491  cp += cur.regm.rm_eo;
492  }
493  }
494  /*
495  * And, same for replacing " =FEW= " (7 chars) with ".{0,15}" (7 chars)
496  */
497  (void) sprintf(wildCard, " %s", few);
498  len = strlen(wildCard);
499  for (cp = s; strGrep(wildCard, cp, 0); ) {
500  if (wildcardBad) {
501  LOG_FATAL("OOPS, regex %d, wild-card not allowed here", i)
502  Bail(-__LINE__);
503  }
504  if (*(cp+cur.regm.rm_eo) == NULL_CHAR) {
505  LOG_FATAL("String %d ends in a wild-card", i)
506  Bail(-__LINE__);
507  }
508  else if (*(cp+cur.regm.rm_eo) == ' ') {
509 #ifdef DEBUG
510  printf("BEFORE(few): %s\n", s);
511 #endif /* DEBUG */
512  cp += cur.regm.rm_so;
513  *cp++ = '.';
514  *cp++ = '{';
515  *cp++ = '0';
516  *cp++ = ',';
517  *cp++ = '3';
518  *cp++ = '0';
519  *cp++ = '}';
520  memmove(cp, cp+len-6, strlen(cp+len)+7);
521 #ifdef DEBUG
522  printf("_AFTER(few): %s\n", s);
523 #endif /* DEBUG */
524  }
525  else {
526  LOG_NOTICE("Wild-card \"%s\" sub-string, phrase %d", wildCard, i)
527  cp += cur.regm.rm_eo;
528  }
529  }
530  /*
531  * AND, replace the string "=YEAR=" with "[12][0-9][0-9][0-9][,- ]*".
532  * The former is 6 chars in length, the latter is 24. We must be careful
533  * not to overflow the buffer we're passed.
534  */
535  len = strlen(year);
536  while (strGrep(year, s, 0)) {
537  if (strlen(s)+25 >= size) { /* 24 plus 1(NULL) */
538  LOG_FATAL("buffer overflow, text-spec %d", i)
539  Bail(-__LINE__);
540  }
541  cp = (char *)(s+cur.regm.rm_so);
542 #ifdef DEBUG
543  printf("BEFORE: %s\n", s);
544 #endif /* DEBUG */
545  memmove(cp+25, cp+6, strlen(cp+len)+1); /* was 26, 6 */
546  memset(cp+6, '_', 19);
547 #ifdef DEBUG
548  printf("_MOVED: %s\n", s);
549 #endif /* DEBUG */
550  *cp = *(cp+4) = *(cp+9) = *(cp+14) = *(cp+19) = '[';
551  *(cp+1) = '1';
552  *(cp+2) = '2';
553  *(cp+5) = *(cp+10) = *(cp+15) = '0';
554  *(cp+6) = *(cp+11) = *(cp+16) = '-';
555  *(cp+7) = *(cp+12) = *(cp+17) = '9';
556  *(cp+3) = *(cp+8) = *(cp+13) = *(cp+18) = *(cp+23) = ']';
557  *(cp+20) = ' ';
558  *(cp+21) = ',';
559  *(cp+22) = '-';
560  *(cp+24) = '*';
561 #ifdef DEBUG
562  printf("_AFTER: %s\n", s);
563 #endif /* DEBUG */
564  }
565  return;
566 }
567 #endif /* FIX_STRINGS */
568 
569 char* createRelativePath(item_t *p, scanres_t *scp)
570 {
571  char* cp;
572  if (*(p->str) == '/')
573  {
574  strcpy(scp->fullpath, p->str);
575  scp->nameOffset = (size_t) (cur.targetLen + 1);
576  cp = scp->fullpath; /* full pathname */
577  }
578  else
579  {
580  strncpy(scp->fullpath, cur.cwd, sizeof(scp->fullpath)-1);
581  strncat(scp->fullpath, "/", sizeof(scp->fullpath)-1);
582  strncat(scp->fullpath, p->str, sizeof(scp->fullpath)-1);
583  scp->nameOffset = (size_t) (cur.cwdLen + 1);
584  cp = p->str; /* relative path == faster open() */
585  }
586 
587  return cp;
588 }
589 
606 void scanForKeywordsAndSetScore(scanres_t* scores, list_t* licenseList)
607 {
608  /*
609  CDB -- Some other part of FOSSology has already decided we
610  want to scan this file, so we need to look into removing this
611  file scoring stuff.
612  */
613  scanres_t* scp;
614  int c;
615  item_t* p;
616  char* textp;
617  char* cp;
618  for (scp = scores; (p = listIterate(licenseList)) != NULL_ITEM ; scp++)
619  {
620 
621  /*
622  * Use *relative* pathnames wherever possible -- we'll spend less time in
623  * the kernel looking up inodes and pathname components that way.
624  */
625  cp = createRelativePath(p, scp);
626 
627 #ifdef DEBUG
628  printf("licenseScan: scan %s\n",
629  (char *)(scp->fullpath+scp->nameOffset));
630 #endif /* DEBUG */
631  /*
632  * Zero-length files are of no interest; there's nothing in them!
633  * CDB - We need to report this error somehow... and clean up
634  * /tmp/nomos.tmpdir (or equivalent).
635  */
636  if ((textp = mmapFile(cp)) == NULL_STR) {
637  /* perror(cp); */
638  /*printf("Zero length file: %s\n", cp); */
639  continue;
640  }
641  scp->size = cur.stbuf.st_size; /* Where did this get set ? CDB */
642  /*
643  * Disinterest #3 (discriminate-by-file-content):
644  * Files not of a known-good type (as reported by file(1)/magic(3)) should
645  * also be skipped (some are quite large!). _UTIL_MAGIC (see _autodata.c)
646  * contains a regex for MOST of the files we're interested in, but there
647  * ARE some exceptions (logged below).
648  *
649  *****
650  * exception (A): patch/diff files are sometimes identified as "data".
651  *****
652  * FIX-ME: we don't currently use _UTIL_FILTER, which is set up to
653  * exclude some files by filename.
654  */
655  /*
656  * Scan for keywords (_KW_), and use the number found for the score.
657  */
658  assert(NKEYWORDS >= sizeof(scp->kwbm));
659 
660  for (scp->kwbm = c = 0; c < NKEYWORDS; c++)
661  {
662  if (idxGrep_recordPosition(c + _KW_first, textp, REG_EXTENDED | REG_ICASE))
663  {
664  scp->kwbm |= (1 << c); // put a one at c'th position in kwbm (KeywordByteMap)
665  scp->score++;
666 #if (DEBUG > 5)
667  printf("Keyword %d (\"%s\"): YES\n", c, _REGEX(c+_KW_first));
668 #endif /* DEBUG > 5 */
669  }
670  }
671  munmapFile(textp);
672 #if (DEBUG > 5)
673  printf("%s = %d\n", (char *)(scp->fullpath+scp->nameOffset),
674  scp->score);
675 #endif /* DEBUG > 5 */
676 
677  }
678  return;
679 }
680 
692 {
693  /*
694  * CDB - It is always the case that we are doing one file at a time.
695  */
696  if (scores->score == 0)
697  {
698  scores->score = 1;
699  }
700 }
701 
713 int fiterResultsOfKeywordScan(int lowWater, scanres_t* scores, int nFiles)
714 {
715  int nCand;
716 
717  scanres_t* scp;
718  int i;
719 
720  for (scp = scores, i = nCand = 0; i < nFiles; i++, scp++)
721  {
722  scp->relpath = (char *) (scp->fullpath + scp->nameOffset);
723  if (idxGrep(_FN_LICENSEPATT, pathBasename(scp->relpath), REG_ICASE
724  | REG_EXTENDED)) {
725  scp->flag = 1;
726  if (idxGrep(_FN_DEBCPYRT, scp->relpath, REG_ICASE)) {
727  scp->flag = 2;
728  }
729  }
730  else if (scp->score >= lowWater) {
731  scp->flag |= 1;
732  }
733  /*
734  * So now, save any license candidate EITHER named "debian/copyright*"
735  * OR having a score > 0
736  */
737  if (scp->flag == 2 || (scp->score && scp->flag)) {
738 #if (DEBUG > 3)
739  printf("%s [score: %d], %07o\n", scp->fullpath,
740  scp->score, scp->kwbm);
741 #endif /* DEBUG > 3 */
742  nCand++;
743  }
744  }
745  return nCand;
746 }
747 
759 void licenseScan(list_t *licenseList)
760 {
761  int lowWater = 1; // constant
762 
763  int nCand; //relevant output
764 
765  //fields
766  int counts[NKEYWORDS + 1];
767  scanres_t *scores;
768 
769  //recycled temp variables
770  scanres_t *scp;
771  int nFilesInList;
772 
773 #ifdef PROC_TRACE
774  traceFunc("== licenseScan(%p, %d)\n", l);
775 #endif /* PROC_TRACE */
776 
777 #ifdef MEMSTATS
778  printf("... allocating %d bytes for scanres_t[] array\n",
779  sizeof(*scp)*licenseList->used);
780 #endif /* MEMSTATS */
781 
782  scores = (scanres_t *) memAlloc(sizeof(*scp) * licenseList->used, MTAG_SCANRES);
783  memset((void *) counts, 0, (size_t) ((NKEYWORDS + 1) * sizeof(int)));
784 
785  scanForKeywordsAndSetScore(scores, licenseList);
787 
788 #ifdef PROC_TRACE
789  traceFunc("=> invoking qsort(): callback == scoreCompare()\n");
790 #endif /* PROC_TRACE */
791 
792  nFilesInList = licenseList->used;
793  qsort(scores, (size_t) nFilesInList, sizeof(*scp), scoreCompare);
794 
795  //recycled temp variables
796  nCand = fiterResultsOfKeywordScan(lowWater, scores, nFilesInList);
797  /*
798  * OF SPECIAL INTEREST: saveLicenseData() changes directory (to "..")!!!
799  */
800  /* DBug: printf("licenseScan: gl.initwd is:%s\n",gl.initwd); */
801  saveLicenseData(scores, nCand, nFilesInList, lowWater);
802  /*
803  * At this point, we don't need either the raw-source directory or the
804  * unpacked results anymore, so get rid of 'em.
805  */
806  if (scores->licenses) free(scores->licenses);
807  memFree((char *) scores, "scores table");
808  return;
809 } /* licenseScan */
810 
821 static int scoreCompare(const void *arg1, const void *arg2) {
822  scanres_t *sc1 = (scanres_t *) arg1;
823  scanres_t *sc2 = (scanres_t *) arg2;
824 
825  if (sc1->score > sc2->score) {
826  return (-1);
827  }
828  else if (sc1->score < sc2->score) {
829  return (1);
830  }
831  else if ((sc1->fullpath != NULL_STR) && (sc2->fullpath == NULL_STR)) {
832  return (-1);
833  }
834  else if ((sc2->fullpath != NULL_STR) && (sc1->fullpath == NULL_STR)) {
835  return (1);
836  }
837  else {
838  return (-strcmp(sc1->fullpath, sc2->fullpath));
839  }
840 }
841 
845 static void noLicenseFound() {
846 
847 #ifdef PROC_TRACE
848  traceFunc("== noLicenseFound\n");
849 #endif /* PROC_TRACE */
850 
851  (void) strcpy(cur.compLic, LS_NOSUM);
852  return;
853 }
854 
866 static void printHighlightInfo(GArray* keyWords, GArray* theMatches){
867  if ( optionIsSet(OPTS_HIGHLIGHT_STDOUT) )
868  {
869  printf(" Highlighting Info at");
870  int currentKeyw;
871  for (currentKeyw=0; currentKeyw < keyWords->len; ++currentKeyw ) {
872  MatchPositionAndType* ourMatchv = getMatchfromHighlightInfo(keyWords,currentKeyw );
873  printf(" Keyword at %i, length %i, index = 0,", ourMatchv->start, ourMatchv->end - ourMatchv->start );
874  }
875  int currentLicence;
876  for (currentLicence = 0; currentLicence < theMatches->len; ++currentLicence)
877  {
878  LicenceAndMatchPositions* theLicence = getLicenceAndMatchPositions(theMatches, currentLicence);
879 
880  int highl;
881  for (highl = 0; highl < theLicence->matchPositions->len; ++highl)
882  {
883  MatchPositionAndType* ourMatchv = getMatchfromHighlightInfo(theLicence->matchPositions, highl);
884  printf(" License #%s# at %i, length %i, index = %i,", theLicence->licenceName , ourMatchv->start, ourMatchv->end - ourMatchv->start, ourMatchv->index );
885 
886  }
887  }
888  }
889  printf("\n");
890  return;
891 }
892 
896 static void printKeyWordMatches(scanres_t *scores, int idx)
897 {
898  int c;
899  int base;
900  char miscbuf[myBUFSIZ];
901  int offset;
902  /*
903  * construct the list of keywords that matched in licenseScan()
904  */
905  (void) strcpy(miscbuf, "Matches: ");
906  offset = 9; /* e.g., strlen("Matches: ") */
907  for (base = c = 0; c < NKEYWORDS; c++)
908  {
909  if (scores[idx].kwbm & (1 << c))
910  {
911  if (base++)
912  {
913  miscbuf[offset++] = ',';
914  miscbuf[offset++] = ' ';
915  }
916  offset += sprintf(miscbuf + offset, "%s", _REGEX(c + _KW_first));
917  }
918  }
919 
920  printf("%s\n", miscbuf);
921 
922 }
923 
928 static gint compare_integer(gconstpointer a, gconstpointer b)
929 {
930  gint out;
931 
932  if (a < b)
933  out = -1;
934  else if (a == b)
935  out = 0;
936  else
937  out = 1;
938  return out;
939 
940 }
941 
948 static void rescanOriginalTextForFoundLicences(char* textp, int isFileMarkupLanguage, int isPS){
949  if (cur.theMatches->len > 0 )
950  {
951  if (cur.cliMode == 1 && !optionIsSet(OPTS_HIGHLIGHT_STDOUT) ) return;
952  // do a fresh doctoring of the buffer
953  g_array_free(cur.docBufferPositionsAndOffsets, TRUE);
954  cur.docBufferPositionsAndOffsets = g_array_new(FALSE, FALSE, sizeof(pairPosOff));
955  doctorBuffer(textp, isFileMarkupLanguage, isPS, NO);
956 
957  for (cur.currentLicenceIndex = 0; cur.currentLicenceIndex < cur.theMatches->len; ++cur.currentLicenceIndex)
958  {
959  LicenceAndMatchPositions* currentLicence = getLicenceAndMatchPositions(cur.theMatches, cur.currentLicenceIndex);
960 
961  //we want to only look for each found index once
962  g_array_sort(currentLicence->indexList, compare_integer);
963 
964  int myIndex;
965  int lastindex = -1;
966  for (myIndex = 0; myIndex < currentLicence->indexList->len; ++myIndex)
967  {
968  int currentIndex = g_array_index(currentLicence->indexList, int, myIndex);
969  if (currentIndex == lastindex) continue;
970  idxGrep_recordPositionDoctored(currentIndex, textp, REG_ICASE | REG_EXTENDED);
971  lastindex = currentIndex;
972  }
973  }
974  }
975 }
976 
994 static void saveLicenseData(scanres_t *scores, int nCand, int nElem,
995  int lowWater) {
996  int i;
997  // int c;
998  // int base;
999  int size;
1000  int highScore = scores->score;
1001  int isFileMarkupLanguage = 0;
1002  int isPS = 0;
1003  // int offset;
1004  int idx;
1005  char *fileName;
1006  char *textp;
1007  item_t *p;
1008  char realPathOfTarget[PATH_MAX];
1009 
1010 #ifdef PROC_TRACE
1011  traceFunc("== saveLicenseData(%p, %d, %d, %d, %d)\n", scores, nCand,
1012  nElem, lowWater);
1013 #endif /* PROC_TRACE */
1014 
1015  /* DBug: printf("saveLicenseData on entry gl.initwd is:%s\n",gl.initwd); */
1016  /*
1017  * Save the necessary licensing information in a list of files...
1018  */
1019 #ifdef DEBUG
1020  printf("saveLicenseData: %d candidates\n", nCand);
1021 #endif /* DEBUG */
1022 
1023  /* changeDir("..");*//* CDB- Why?!!!! */
1024 
1025  /* BE PERFORMANCE-CONSCIOUS WITHIN THIS LOOP (it runs a LOT!) */
1026  /*
1027  * OPTIMIZE-ME: should we store local variables and use lots of
1028  * registers instead of accessing everything through the scanres
1029  * array? We've got to be doing some serious address calculations.
1030  */
1031  i = 1;
1032 
1033  for (idx = 0; i <= nCand; idx++) {
1034  /*
1035  * If we didn't flag this file as needing to be saved, ignore it.
1036  */
1037  if (scores[idx].flag == 0) {
1038  continue;
1039  }
1040  (void) sprintf(scores[idx].linkname, "Link%03d.txt", i++);
1041 #if DEBUG > 5
1042  printf("name: %s\n[%s]\n", scores[idx].relpath, scores[idx].fullpath);
1043 #endif /* DEBUG > 5 */
1044  /*
1045  * Kludge up the pointer to the relative-path in scores[idx].fullpath
1046  * so we don't
1047  * have to as many directory entries to open each file... this works for
1048  * anything EXCEPT 'distribution files'.
1049  */
1050  fileName = scores[idx].fullpath;
1051  if (optionIsSet(OPTS_DEBUG)) {
1052  printf("File name: %s\n", fileName);
1053  }
1054  if ((textp = mmapFile(fileName)) == NULL_STR) {
1055 
1056  /* Fatal("Null mmapFile(), path=%s", fileName); */
1057  noLicenseFound();
1058  continue;
1059  }
1060  /* CDB size = (int) cur.stbuf.st_size; */
1061  size = scores[idx].size;
1062  if (scores[idx].dataOffset) {
1063  textp += scores[idx].dataOffset;
1064  }
1065 
1066  /* wordCount() sets nLines in global structure "cur". */
1067  wordCount(textp);
1068 
1069  /*
1070  * Report which package (if any) this file came from
1071  */
1072 
1073  /*
1074  * Since we hard-wire the score of every file (invoked as --file), a score
1075  * of 1 could be either 0 or 1, so scores[idx].kwbm tells the real story...
1076  */
1077  if (optionIsSet(OPTS_DEBUG)) {
1078  printf("File score: %d (0x%06x)\n",
1079  (scores[idx].kwbm ? scores[idx].score : scores[idx].kwbm),
1080  scores[idx].kwbm);
1081  if (scores[idx].kwbm) {
1082  printKeyWordMatches(scores, idx);
1083  }
1084  }
1085  /*
1086  * Print the license claim (e.g., what's listed in the package)
1087  */
1088  /*
1089  * determine licenses in the file, and record 'em; wrap up by including
1090  * the file contents
1091  *****
1092  * FIX-ME: we should filter some names out like the shellscript does.
1093  * For instance, word-spell-dictionary files will score high but will
1094  * likely NOT contain a license. But the shellscript filters these
1095  * names AFTER they're already scanned. Think about it.
1096  *****
1097  FILTERPATTERNS="(/man|\.[0-9]|\.[0-9][a-z]|rfc[0-9].*|.po|.pot"
1098  FILTERPATTERNS="$FILTERPATTERNS|words.*|.*spelling.*|spell)$"
1099  */
1100 #if defined(DEBUG) || defined(DOCTOR_DEBUG) || defined(LTSR_DEBUG) \
1101  || defined(BATCH_DEBUG) || defined(PARSE_STOPWATCH) || defined(MEMSTATS) \
1102  || defined(MEM_DEBUG) || defined(UNKNOWN_CHECK_DEBUG)
1103  printf("*** PROCESS File: %s\n", scores[idx].relpath);
1104  printf("... %d bytes, score %d\n", scores[idx].size, scores[idx].score);
1105 #endif /* DEBUG || DOCTOR_DEBUG || LTSR_DEBUG || BATCH_DEBUG || PARSE_STOPWATCH || MEMSTATS || MEM_DEBUG || defined(UNKNOWN_CHECK_DEBUG)*/
1106 
1107  isFileMarkupLanguage = idxGrep(_UTIL_MARKUP, textp, REG_ICASE | REG_EXTENDED);
1108 
1109 #ifdef DOCTOR_DEBUG
1110  printf("idxGrep(ML) returns %d\n", isFileMarkupLanguage);
1111  if (isFileMarkupLanguage)
1112  {
1113  int n;
1114  printf("isMarkUp@%d: [", cur.regm.rm_so);
1115  for (n = cur.regm.rm_so; n <= cur.regm.rm_eo; n++) {
1116  printf("%c", *(textp+n));
1117  }
1118  printf("]\n");
1119  }
1120 #endif /* DOCTOR_DEBUG */
1121  /*
1122  * BUG: When _FTYP_POSTSCR is "(postscript|utf-8 unicode)", the resulting
1123  * license-parse yields 'NoLicenseFound' but when both "postscript" and
1124  * "utf-8 unicode" are searched independently, parsing definitely finds
1125  * quantifiable licenses. WHY?
1126  */
1127 #ifdef DOCTOR_DEBUG
1128  printf("idxGrep(PS) returns %d\n", isPS);
1129  if (isPS) {
1130  int n;
1131  printf("isPostScript@%d: [", cur.regm.rm_so);
1132  printf("]\n");
1133  }
1134 #endif /* DOCTOR_DEBUG */
1135  /*
1136  * Interesting - copyString(parseLicenses(args), MTAG_FILELIC)...
1137  * will randomly segfault on 32-bit Debian releases. Split the calls.
1138  */
1139  fileName = parseLicenses(textp, size, &scores[idx], isFileMarkupLanguage, isPS);
1140  scores[idx].licenses = copyString(fileName, MTAG_FILELIC);
1141 #ifdef QA_CHECKS
1142  if (fileName == NULL_STR) {
1143  Assert(NO, "Expected non-null parseLicenses return!");
1144  }
1145  if (scores[idx].licenses == NULL_STR) {
1146  Assert(NO, "Expected non-null license summary!");
1147  }
1148 #endif /* QA_CHECKS */
1149 #ifdef STOPWATCH
1150  timerBytes += size;
1151 #endif /* STOPWATCH */
1152 #ifdef FLAG_NO_COPYRIGHT
1153  if (gl.flags & FL_NOCOPYRIGHT) {
1154  p = listGetItem(&cur.nocpyrtList, scores[idx].relpath);
1155  p->buf = copyString(scores[idx].linkname, MTAG_PATHBASE);
1156  p->num = scores[idx].score;
1157  }
1158 #endif /* FLAG_NO_COPYRIGHT */
1159  if (cur.licPara != NULL_STR) {
1160  memFree(cur.licPara, MTAG_TEXTPARA); /* be free! */
1161  cur.licPara = NULL_STR; /* remember */
1162  }
1163 
1164 
1165  if( !optionIsSet(OPTS_NO_HIGHLIGHTINFO) ) {
1166  //careful this function changes the content of textp
1167  rescanOriginalTextForFoundLicences(textp, isFileMarkupLanguage, isPS);
1168  //but as it is freed right here we do not make a copy..
1169  }
1170 
1171  munmapFile(textp);
1172 
1173  /*
1174  * Remember this license in this file...
1175  */
1176  p = listGetItem(&cur.lList, scores[idx].licenses);
1177  p->refCount++;
1178  /*
1179  * Clear out the buffer-offsets list
1180  */
1181 #ifdef fix_later
1182  /* CDB - need to move this code to a point after we save the license info */
1183 #ifdef PHRASE_DEBUG
1184  listDump(&cur.offList, NO);
1185 #endif /* PHRASE_DEBUG */
1186  while ((p = listIterate(&cur.offList)) != 0) {
1187  listClear(p->buf, YES);
1188  }
1189  listClear(&cur.offList, NO);
1190 #endif /* fix_later */
1191  }
1192 
1193  listSort(&cur.lList, SORT_BY_COUNT_DSC);
1194 
1195 #ifdef QA_CHECKS
1196  if (cur.lList.used == 0) {
1197  Assert(NO, "No entries in license-list");
1198  }
1199 #endif /* QA_CHECKS */
1200 
1201  /*
1202  * Construct a 'computed license'. Wherever possible, leave off the
1203  * entries for None and LikelyNot; those are individual-file results
1204  * and we're making an 'aggregate summary' here.
1205  */
1206  if (cur.parseList.used == 0) {
1207  noLicenseFound();
1208  }
1209  else {
1210  makeLicenseSummary(&cur.parseList, highScore, cur.compLic,
1211  sizeof(cur.compLic));
1212  }
1213  if (optionIsSet(OPTS_DEBUG)) {
1214  printf("==> ");
1215  }
1216  /* CDB - Debug code */
1217  /*
1218  printf("saveLicData: the offset list is:\n");
1219  listDump(&cur.offList, YES);
1220 
1221  while ((p = listIterate(&cur.offList)) != 0) {
1222  listDump(p->buf, YES);
1223  }
1224  */
1225  /* print results if running from the command line */
1226  /* DBug: printf("saveLicenseData on return gl.initwd is:%s\n",gl.initwd); */
1227  if(cur.cliMode)
1228  {
1229  if (optionIsSet(OPTS_JSON_OUTPUT))
1230  {
1231  writeJson();
1232  } else {
1233  if (optionIsSet(OPTS_LONG_CMD_OUTPUT) && realpath(cur.targetFile, realPathOfTarget))
1234  {
1235  printf("File %s contains license(s) %s", realPathOfTarget, cur.compLic);
1236  }
1237  else
1238  {
1239  printf("File %s contains license(s) %s", basename(cur.targetFile), cur.compLic);
1240  }
1242  }
1243  }
1244  return;
1245 } /* saveLicenseData */
1246 
1247 
1276 static void makeLicenseSummary(list_t *l, int highScore, char *target, int size) {
1277  item_t *p;
1278  int printCount = 0;
1279  int len = 0;
1280  int new;
1281  int goodStuff;
1282 
1283 #ifdef PROC_TRACE
1284  traceFunc("== makeLicenseSummary(%p, %d, %p, %d)\n", l, highScore,
1285  target, size);
1286 #endif /* PROC_TRACE */
1287 
1288  if (l->used == 0) { /* zero/nothing */
1289  (void) strcpy(target, LS_NOSUM);
1290  return;
1291  }
1292  /*
1293  * Now we know there's something in the list of AT LEAST marginal interest
1294  * in the component-list. If listCount() is zero, ALL data is 'marginal';
1295  * else we have 'good stuff'. For the latter, we only summarize items with
1296  * a 'val' > 0 (the really interesting stuff).
1297  */
1298  listSort(l, SORT_BY_COUNT_DSC); /* sort components */
1299  size--; /* maximum strlen, adjust to allow *1* NULL */
1300  for (goodStuff = 0; (p = listIterate(l)) != NULL_ITEM; /*nada */) {
1301  if (p->iLevel) {
1302  goodStuff = 1; /* interesting license */
1303  l->ix = -1; /* reset saved index */
1304  break;
1305  }
1306  }
1307  while ((p = listIterate(l)) != NULL_ITEM) {
1308  if (goodStuff && (p->iLevel <= IL_LOW)) { /* uninteresting */
1309  continue;
1310  }
1311  if (printCount) {
1312  target[len++] = ',';
1313  }
1314  printCount++;
1315  new = sprintf(target + len, "%s", p->str);
1316  if ((len += new) > size) {
1317  LOG_FATAL("Buffer-overwrite, marginal license components")
1318  Bail(-__LINE__);
1319  }
1320  new = 0;
1321  }
1322  return;
1323 }
1324 
1325 #ifdef LICENSE_DEBUG
1326 dumpLicenses()
1327 {
1328  int i;
1329 
1330 #ifdef PROC_TRACE
1331  traceFunc("== dumpLicenses()\n");
1332 #endif /* PROC_TRACE */
1333 
1334  for (i = 0; i < NFOOTPRINTS; i++) {
1335  printf("License[%d]: seedlen=%d, regexlen=%d\n", i,
1336  licSpec[i].seed.csLen, licSpec[i].text.csLen);
1337  }
1338  printf("[NFOOTPRINTS = %d\n", NFOOTPRINTS);
1339 }
1340 #endif /* LICENSE_DEBUG */
void writeJson()
Write the scan output as a JSON.
Definition: json_writer.c:25
char * str
Definition: nomos.h:291
#define YES
Definition: nomos.h:188
int cliMode
Definition: nomos.h:425
void licenseScan(list_t *licenseList)
scan the list for a license(s)
Definition: licenses.c:759
char targetFile[myBUFSIZ]
Definition: nomos.h:407
void doctorBuffer(char *buf, int isML, int isPS, int isCR)
Convert a buffer of multiple stuff to text-only, separated by spaces.
static void printHighlightInfo(GArray *keyWords, GArray *theMatches)
Print highlight info about matches.
Definition: licenses.c:866
int optionIsSet(int val)
Check if an CLI option is set.
Definition: nomos_utils.c:568
static void noLicenseFound()
Mark curent scan as LS_NOSUM (No_license_found)
Definition: licenses.c:845
static void printKeyWordMatches(scanres_t *scores, int idx)
Prints keywords match to STDOUT.
Definition: licenses.c:896
tricky data structure used for a list of &#39;items&#39;
Definition: nomos.h:287
if(!$Test &&$OptionQ) if($stdin_flag) if($Verbose) else
Definition: cp2foss.php:551
searchString_t text
License text.
Definition: nomos.h:348
static gint compare_integer(gconstpointer a, gconstpointer b)
Compare two integers.
Definition: licenses.c:928
int idxGrep_recordPosition(int index, char *data, int flags)
compile a regex, perform the search and record findings
Definition: nomos_regex.c:231
#define WC_WORDS
Definition: licenses.c:260
char * tseed
unencrypted license text
Definition: nomos.h:449
int used
Definition: nomos.h:323
int score
License match score.
Definition: nomos.h:470
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:48
char * wordCount(char *textp)
VERY simple line count, does NOT have to be perfect!
Definition: util.c:563
#define WC_BYTES
Definition: licenses.c:259
GArray * matchPositions
Match positions.
Definition: nomos.h:392
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:541
if(!preg_match("/\s$projectGroup\s/", $groups)&&(posix_getgid()!=$gInfo['gid']))
get monk license list of one specified uploadtree_id
Definition: migratetest.php:44
#define memFree(x, y)
Definition: nomos.h:544
int idxGrep_recordPositionDoctored(int index, char *data, int flags)
compile a regex, perform the search and record findings
Definition: nomos_regex.c:252
int start
Start position of match.
Definition: nomos.h:383
static void rescanOriginalTextForFoundLicences(char *textp, int isFileMarkupLanguage, int isPS)
Rescan original content for the licenses already found.
Definition: licenses.c:948
void listInit(list_t *l, int size, char *label)
intialize a list, if the list is not empty, empty it (initialize it to zero&#39;s).
Definition: list.c:67
int csLen
String length.
Definition: nomos.h:338
FUNCTION MatchPositionAndType * getMatchfromHighlightInfo(GArray *in, int index)
Get the MatchPositionAndType for a given index in highlight array.
Definition: nomos_utils.c:909
GArray * theMatches
Definition: nomos.h:430
item_t * listGetItem(list_t *l, char *s)
get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist...
Definition: list.c:259
char * csData
String data.
Definition: nomos.h:339
int flags
Flags.
Definition: nomos.h:361
#define NULL_CHAR
NULL character.
Definition: nomos.h:247
static int scoreCompare(const void *, const void *)
Compare two scores.
Definition: licenses.c:821
static void makeLicenseSummary(list_t *, int, char *, int)
Construct a &#39;computed license&#39;. Wherever possible, leave off the entries for None and LikelyNot; thos...
Definition: licenses.c:1276
static void saveLicenseData(scanres_t *, int, int, int)
Save/creates all the license-data in a specific directory temp directory?
Definition: licenses.c:994
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
Definition: util.c:1407
searchString_t seed
License seed.
Definition: nomos.h:347
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
Definition: pkgConfig.php:1225
#define _REGEX(x)
Definition: nomos.h:460
int idxGrep(int index, char *data, int flags)
compile a regex, and perform the search (on data?)
Definition: nomos_regex.c:216
int flag
Flags.
Definition: nomos.h:473
char * mmapFile(char *pathname)
Blarg. Files that are EXACTLY a multiple of the system pagesize do not get a NULL on the end of the b...
Definition: util.c:1094
char * parseLicenses(char *filetext, int size, scanres_t *scp, int isML, int isPS)
Parse a file to check all the possible licenses and add them to matches.
Definition: parse.c:371
#define MIN_LINES
Definition: licenses.c:262
#define MIN(a, b)
Min of two.
Definition: licenses.c:76
#define MAX(a, b)
Max of two.
Definition: licenses.c:75
char * copyString(char *s, char *label)
Create a copy of a string.
Definition: util.c:605
FUNCTION LicenceAndMatchPositions * getLicenceAndMatchPositions(GArray *in, int index)
Get the LicenceAndMatchPositions for a given index in match array.
Definition: nomos_utils.c:921
void licenseInit()
license initialization
Definition: licenses.c:82
void relaxScoreCriterionForSingleFile(scanres_t *scores)
Reset scores to 1 if it is 0.
Definition: licenses.c:691
char * pathBasename(char *path)
Get the basename from a file path.
Definition: util.c:627
char * licenceName
License names.
Definition: nomos.h:394
int index
Enums from index (Entrynumber) in STRINGS.in.
Definition: nomos.h:385
licText_t licText[]
int fiterResultsOfKeywordScan(int lowWater, scanres_t *scores, int nFiles)
Run through the list once more.
Definition: licenses.c:713
int end
End position of match.
Definition: nomos.h:384
char compLic[myBUFSIZ]
Definition: nomos.h:422
void listSort(list_t *l, int sortType)
Sort the list as per the sortType passed.
Definition: list.c:644
#define NULL_STR
NULL string.
Definition: nomos.h:248
#define _SEED(x)
Definition: nomos.h:464
static int searchStrategy(int, char *, int)
Definition: licenses.c:285
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
int strGrep(char *regex, char *data, int flags)
General-purpose grep function, used for one-time-only searches.
Definition: nomos_regex.c:150
#define LINE_BYTES
Definition: licenses.c:257
Nomos header file.
GArray * indexList
License indexes.
Definition: nomos.h:393
char cwd[myBUFSIZ]
Definition: nomos.h:405
void listDump(list_t *l, int verbose)
print the passed in list
Definition: list.c:842
void munmapFile(void *ptr)
Definition: util.c:1209
void listClear(list_t *l, int deallocFlag)
Destroy list_t.
Definition: list.c:119
#define NULL_ITEM
NULL item.
Definition: nomos.h:244
#define OPTS_DEBUG
Definition: nomos.h:151
#define PUNT_LINES
Definition: licenses.c:261
#define LINE_WORDS
Definition: licenses.c:258
list_t sHash
Hashes.
Definition: nomos.h:370
#define NO
Definition: nomos.h:184
void * buf
Definition: nomos.h:292
char * regex
License regex.
Definition: nomos.h:448
void scanForKeywordsAndSetScore(scanres_t *scores, list_t *licenseList)
Definition: licenses.c:606
GArray * keywordPositions
Definition: nomos.h:431
item_t * listIterate(list_t *l)
return a pointer to listitem, returns a NULL_ITEM when no more items to return.
Definition: list.c:490
int ix
Definition: nomos.h:325
#define MTAG_SEEDTEXT
Definition: nomos.h:506