"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/main/extract.c" between
libextractor-1.10.tar.gz and libextractor-1.11.tar.gz

About: GNU libextractor is a library used to extract meta-data from files of arbitrary type.

extract.c  (libextractor-1.10):extract.c  (libextractor-1.11)
skipping to change at line 72 skipping to change at line 72
memset (&sig, 0, sizeof (struct sigaction)); memset (&sig, 0, sizeof (struct sigaction));
sig.sa_handler = SIG_IGN; sig.sa_handler = SIG_IGN;
sigemptyset (&sig.sa_mask); sigemptyset (&sig.sa_mask);
#ifdef SA_INTERRUPT #ifdef SA_INTERRUPT
sig.sa_flags = SA_INTERRUPT; /* SunOS */ sig.sa_flags = SA_INTERRUPT; /* SunOS */
#else #else
sig.sa_flags = SA_RESTART; sig.sa_flags = SA_RESTART;
#endif #endif
if (0 != sigaction (SIGPIPE, &sig, &oldsig)) if (0 != sigaction (SIGPIPE, &sig, &oldsig))
FPRINTF (stderr, fprintf (stderr,
"Failed to install SIGPIPE handler: %s\n", strerror (errno)); "Failed to install SIGPIPE handler: %s\n", strerror (errno));
} }
#endif #endif
/** /**
* Information about command-line options. * Information about command-line options.
*/ */
struct Help struct Help
{ {
skipping to change at line 286 skipping to change at line 286
char *keyword; char *keyword;
#if HAVE_ICONV #if HAVE_ICONV
iconv_t cd; iconv_t cd;
#endif #endif
const char *stype; const char *stype;
const char *mt; const char *mt;
if (YES != print[type]) if (YES != print[type])
return 0; return 0;
if (verbose > 3) if (verbose > 3)
FPRINTF (stdout, fprintf (stdout,
_ ("Found by `%s' plugin:\n"), _ ("Found by `%s' plugin:\n"),
plugin_name); plugin_name);
mt = EXTRACTOR_metatype_to_string (type); mt = EXTRACTOR_metatype_to_string (type);
stype = (NULL == mt) ? _ ("unknown") : gettext (mt); stype = (NULL == mt) ? _ ("unknown") : gettext (mt);
switch (format) switch (format)
{ {
case EXTRACTOR_METAFORMAT_UNKNOWN: case EXTRACTOR_METAFORMAT_UNKNOWN:
FPRINTF (stdout, fprintf (stdout,
_ ("%s - (unknown, %u bytes)\n"), _ ("%s - (unknown, %u bytes)\n"),
stype, stype,
(unsigned int) data_len); (unsigned int) data_len);
break; break;
case EXTRACTOR_METAFORMAT_UTF8: case EXTRACTOR_METAFORMAT_UTF8:
if (0 == data_len) if (0 == data_len)
break; break;
#if HAVE_ICONV #if HAVE_ICONV
cd = iconv_open (nl_langinfo (CODESET), "UTF-8"); cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
if (((iconv_t) -1) != cd) if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd, keyword = iconv_helper (cd,
data, data,
data_len); data_len);
else else
#endif #endif
keyword = strdup (data); keyword = strdup (data);
if (NULL != keyword) if (NULL != keyword)
{ {
FPRINTF (stdout, fprintf (stdout,
"%s - %s\n", "%s - %s\n",
stype, stype,
keyword); keyword);
free (keyword); free (keyword);
} }
#if HAVE_ICONV #if HAVE_ICONV
if (((iconv_t) -1) != cd) if (((iconv_t) -1) != cd)
iconv_close (cd); iconv_close (cd);
#endif #endif
break; break;
case EXTRACTOR_METAFORMAT_BINARY: case EXTRACTOR_METAFORMAT_BINARY:
FPRINTF (stdout, fprintf (stdout,
_ ("%s - (binary, %u bytes)\n"), _ ("%s - (binary, %u bytes)\n"),
stype, stype,
(unsigned int) data_len); (unsigned int) data_len);
break; break;
case EXTRACTOR_METAFORMAT_C_STRING: case EXTRACTOR_METAFORMAT_C_STRING:
FPRINTF (stdout, fprintf (stdout,
"%s - %.*s\n", "%s - %.*s\n",
stype, stype,
(int) data_len, (int) data_len,
data); data);
break; break;
default: default:
break; break;
} }
return 0; return 0;
} }
skipping to change at line 387 skipping to change at line 387
if (NULL == mt) if (NULL == mt)
mt = gettext_noop ("unknown"); mt = gettext_noop ("unknown");
switch (format) switch (format)
{ {
case EXTRACTOR_METAFORMAT_UNKNOWN: case EXTRACTOR_METAFORMAT_UNKNOWN:
break; break;
case EXTRACTOR_METAFORMAT_UTF8: case EXTRACTOR_METAFORMAT_UTF8:
if (0 == data_len) if (0 == data_len)
return 0; return 0;
if (verbose > 1) if (verbose > 1)
FPRINTF (stdout, fprintf (stdout,
"%s: ", "%s: ",
gettext (mt)); gettext (mt));
#if HAVE_ICONV #if HAVE_ICONV
cd = iconv_open (nl_langinfo (CODESET), "UTF-8"); cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
if (((iconv_t) -1) != cd) if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd, keyword = iconv_helper (cd,
data, data,
data_len); data_len);
else else
#endif #endif
keyword = strdup (data); keyword = strdup (data);
if (NULL != keyword) if (NULL != keyword)
{ {
FPRINTF (stdout, fprintf (stdout,
"`%s' ", "`%s' ",
keyword); keyword);
free (keyword); free (keyword);
} }
#if HAVE_ICONV #if HAVE_ICONV
if (((iconv_t) -1) != cd) if (((iconv_t) -1) != cd)
iconv_close (cd); iconv_close (cd);
#endif #endif
break; break;
case EXTRACTOR_METAFORMAT_BINARY: case EXTRACTOR_METAFORMAT_BINARY:
break; break;
case EXTRACTOR_METAFORMAT_C_STRING: case EXTRACTOR_METAFORMAT_C_STRING:
if (verbose > 1) if (verbose > 1)
FPRINTF (stdout, fprintf (stdout,
"%s ", "%s ",
gettext (mt)); gettext (mt));
FPRINTF (stdout, fprintf (stdout,
"`%s'", "`%s'",
data); data);
break; break;
default: default:
break; break;
} }
return 0; return 0;
} }
/** /**
skipping to change at line 565 skipping to change at line 565
const char *et; const char *et;
char temp[20]; char temp[20];
if (NULL != entry_type) if (NULL != entry_type)
et = entry_type; et = entry_type;
else else
et = "misc"; et = "misc";
if ( (NULL == btm[0].value) || if ( (NULL == btm[0].value) ||
(NULL == btm[1].value) || (NULL == btm[1].value) ||
(NULL == btm[2].value) ) (NULL == btm[2].value) )
FPRINTF (stdout, fprintf (stdout,
"@%s %s { ", "@%s %s { ",
et, et,
fn); fn);
else else
{ {
snprintf (temp, snprintf (temp,
sizeof (temp), sizeof (temp),
"%.5s%.5s%.5s", "%.5s%.5s%.5s",
btm[2].value, btm[2].value,
btm[1].value, btm[1].value,
btm[0].value); btm[0].value);
for (n = strlen (temp) - 1; n>=0; n--) for (n = strlen (temp) - 1; n>=0; n--)
if (! isalnum ( (unsigned char) temp[n]) ) if (! isalnum ( (unsigned char) temp[n]) )
temp[n] = '_'; temp[n] = '_';
else else
temp[n] = tolower ( (unsigned char) temp[n]); temp[n] = tolower ( (unsigned char) temp[n]);
FPRINTF (stdout, fprintf (stdout,
"@%s %s { ", "@%s %s { ",
et, et,
temp); temp);
} }
for (i = 0; NULL != btm[i].bibTexName; i++) for (i = 0; NULL != btm[i].bibTexName; i++)
if (NULL != btm[i].value) if (NULL != btm[i].value)
FPRINTF (stdout, fprintf (stdout,
"\t%s = {%s},\n", "\t%s = {%s},\n",
btm[i].bibTexName, btm[i].bibTexName,
btm[i].value); btm[i].value);
FPRINTF (stdout, "%s", "}\n\n"); fprintf (stdout, "%s", "}\n\n");
} }
#ifdef WINDOWS #ifdef WINDOWS
static int static int
_wchar_to_str (const wchar_t *wstr, char **retstr, UINT cp) _wchar_to_str (const wchar_t *wstr, char **retstr, UINT cp)
{ {
char *str; char *str;
int len, lenc; int len, lenc;
BOOL lossy = FALSE; BOOL lossy = FALSE;
DWORD error; DWORD error;
skipping to change at line 760 skipping to change at line 760
#if ENABLE_NLS #if ENABLE_NLS
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
textdomain (PACKAGE); textdomain (PACKAGE);
#endif #endif
#ifndef WINDOWS #ifndef WINDOWS
ignore_sigpipe (); ignore_sigpipe ();
#endif #endif
if (NULL == (print = malloc (sizeof (int) * EXTRACTOR_metatype_get_max ()))) if (NULL == (print = malloc (sizeof (int) * EXTRACTOR_metatype_get_max ())))
{ {
FPRINTF (stderr, fprintf (stderr,
"malloc failed: %s\n", "malloc failed: %s\n",
strerror (errno)); strerror (errno));
return 1; return 1;
} }
for (i = 0; i < EXTRACTOR_metatype_get_max (); i++) for (i = 0; i < EXTRACTOR_metatype_get_max (); i++)
print[i] = YES; /* default: print everything */ print[i] = YES; /* default: print everything */
if (0 != _get_utf8_args (argc, argv, &utf8_argc, &utf8_argv)) if (0 != _get_utf8_args (argc, argv, &utf8_argc, &utf8_argv))
{ {
FPRINTF (stderr, "Failed to get arguments: %s\n", strerror (errno)); fprintf (stderr, "Failed to get arguments: %s\n", strerror (errno));
return 1; return 1;
} }
while (1) while (1)
{ {
static struct option long_options[] = { static struct option long_options[] = {
{"bibtex", 0, 0, 'b'}, {"bibtex", 0, 0, 'b'},
{"grep-friendly", 0, 0, 'g'}, {"grep-friendly", 0, 0, 'g'},
{"help", 0, 0, 'h'}, {"help", 0, 0, 'h'},
{"in-process", 0, 0, 'i'}, {"in-process", 0, 0, 'i'},
skipping to change at line 806 skipping to change at line 806
&option_index); &option_index);
if (c == -1) if (c == -1)
break; /* No more flags to process */ break; /* No more flags to process */
switch (c) switch (c)
{ {
case 'b': case 'b':
bibtex = YES; bibtex = YES;
if (NULL != processor) if (NULL != processor)
{ {
FPRINTF (stderr, fprintf (stderr,
"%s", "%s",
_ ( _ (
"Illegal combination of options, cannot combine multiple styl es of printing.\n")); "Illegal combination of options, cannot combine multiple styl es of printing.\n"));
free (utf8_argv); free (utf8_argv);
return 0; return 0;
} }
processor = &print_bibtex; processor = &print_bibtex;
break; break;
case 'g': case 'g':
grepfriendly = YES; grepfriendly = YES;
if (NULL != processor) if (NULL != processor)
{ {
FPRINTF (stderr, fprintf (stderr,
"%s", "%s",
_ ( _ (
"Illegal combination of options, cannot combine multiple styl es of printing.\n")); "Illegal combination of options, cannot combine multiple styl es of printing.\n"));
free (utf8_argv); free (utf8_argv);
return 0; return 0;
} }
processor = &print_selected_keywords_grep_friendly; processor = &print_selected_keywords_grep_friendly;
break; break;
case 'h': case 'h':
print_help (); print_help ();
skipping to change at line 854 skipping to change at line 854
printf ("%s\n", printf ("%s\n",
gettext (EXTRACTOR_metatype_to_string (i++))); gettext (EXTRACTOR_metatype_to_string (i++)));
free (utf8_argv); free (utf8_argv);
return 0; return 0;
case 'n': case 'n':
nodefault = YES; nodefault = YES;
break; break;
case 'p': case 'p':
if (NULL == optarg) if (NULL == optarg)
{ {
FPRINTF (stderr, fprintf (stderr,
_ ( _ (
"You must specify an argument for the `%s' option (option ign ored).\n"), "You must specify an argument for the `%s' option (option ign ored).\n"),
"-p"); "-p");
break; break;
} }
if (YES == defaultAll) if (YES == defaultAll)
{ {
defaultAll = NO; defaultAll = NO;
i = 0; i = 0;
while (NULL != EXTRACTOR_metatype_to_string (i)) while (NULL != EXTRACTOR_metatype_to_string (i))
skipping to change at line 883 skipping to change at line 883
gettext (EXTRACTOR_metatype_to_string (i)))) ) gettext (EXTRACTOR_metatype_to_string (i)))) )
{ {
print[i] = YES; print[i] = YES;
break; break;
} }
i++; i++;
} }
if (NULL == EXTRACTOR_metatype_to_string (i)) if (NULL == EXTRACTOR_metatype_to_string (i))
{ {
FPRINTF (stderr, fprintf (stderr,
"Unknown keyword type `%s', use option `%s' to get a list.\n", "Unknown keyword type `%s', use option `%s' to get a list.\n",
optarg, optarg,
"-L"); "-L");
free (utf8_argv); free (utf8_argv);
return -1; return -1;
} }
break; break;
case 'v': case 'v':
printf ("extract v%s\n", PACKAGE_VERSION); printf ("extract v%s\n", PACKAGE_VERSION);
free (utf8_argv); free (utf8_argv);
skipping to change at line 914 skipping to change at line 914
(0 == strcmp (optarg, (0 == strcmp (optarg,
gettext (EXTRACTOR_metatype_to_string (i)))) ) gettext (EXTRACTOR_metatype_to_string (i)))) )
{ {
print[i] = NO; print[i] = NO;
break; break;
} }
i++; i++;
} }
if (NULL == EXTRACTOR_metatype_to_string (i)) if (NULL == EXTRACTOR_metatype_to_string (i))
{ {
FPRINTF (stderr, fprintf (stderr,
"Unknown keyword type `%s', use option `%s' to get a list.\n", "Unknown keyword type `%s', use option `%s' to get a list.\n",
optarg, optarg,
"-L"); "-L");
free (utf8_argv); free (utf8_argv);
return -1; return -1;
} }
break; break;
default: default:
FPRINTF (stderr, fprintf (stderr,
"%s", "%s",
_ ("Use --help to get a list of options.\n")); _ ("Use --help to get a list of options.\n"));
free (utf8_argv); free (utf8_argv);
return -1; return -1;
} /* end of parsing commandline */ } /* end of parsing commandline */
} /* while (1) */ } /* while (1) */
if (optind < 0) if (optind < 0)
{ {
FPRINTF (stderr, fprintf (stderr,
"%s", "Unknown error parsing options\n"); "%s", "Unknown error parsing options\n");
free (print); free (print);
free (utf8_argv); free (utf8_argv);
return -1; return -1;
} }
if (utf8_argc - optind < 1) if (utf8_argc - optind < 1)
{ {
FPRINTF (stderr, fprintf (stderr,
"%s", "Invoke with list of filenames to extract keywords form!\n"); "%s", "Invoke with list of filenames to extract keywords form!\n");
free (print); free (print);
free (utf8_argv); free (utf8_argv);
return -1; return -1;
} }
/* build list of libraries */ /* build list of libraries */
if (NO == nodefault) if (NO == nodefault)
plugins = EXTRACTOR_plugin_add_defaults (in_process plugins = EXTRACTOR_plugin_add_defaults (in_process
? EXTRACTOR_OPTION_IN_PROCESS ? EXTRACTOR_OPTION_IN_PROCESS
skipping to change at line 965 skipping to change at line 965
plugins = EXTRACTOR_plugin_add_config (plugins, plugins = EXTRACTOR_plugin_add_config (plugins,
libraries, libraries,
in_process in_process
? EXTRACTOR_OPTION_IN_PROCESS ? EXTRACTOR_OPTION_IN_PROCESS
: EXTRACTOR_OPTION_DEFAULT_POLICY); : EXTRACTOR_OPTION_DEFAULT_POLICY);
if (NULL == processor) if (NULL == processor)
processor = &print_selected_keywords; processor = &print_selected_keywords;
/* extract keywords */ /* extract keywords */
if (YES == bibtex) if (YES == bibtex)
FPRINTF (stdout, fprintf (stdout,
"%s", _ ("% BiBTeX file\n")); "%s", _ ("% BiBTeX file\n"));
for (i = optind; i < utf8_argc; i++) for (i = optind; i < utf8_argc; i++)
{ {
errno = 0; errno = 0;
if (YES == grepfriendly) if (YES == grepfriendly)
FPRINTF (stdout, "%s ", utf8_argv[i]); fprintf (stdout, "%s ", utf8_argv[i]);
else if (NO == bibtex) else if (NO == bibtex)
FPRINTF (stdout, fprintf (stdout,
_ ("Keywords for file %s:\n"), _ ("Keywords for file %s:\n"),
utf8_argv[i]); utf8_argv[i]);
else else
cleanup_bibtex (); cleanup_bibtex ();
if (NO == from_memory) if (NO == from_memory)
EXTRACTOR_extract (plugins, EXTRACTOR_extract (plugins,
utf8_argv[i], utf8_argv[i],
NULL, 0, NULL, 0,
processor, processor,
NULL); NULL);
else else
{ {
struct stat sb; struct stat sb;
unsigned char *data = NULL; unsigned char *data = NULL;
int f = OPEN (utf8_argv[i], O_RDONLY int f = open (utf8_argv[i], O_RDONLY
#if WINDOWS #if WINDOWS
| O_BINARY | O_BINARY
#endif #endif
); );
if ( (-1 != f) && if ( (-1 != f) &&
(0 == FSTAT (f, &sb)) && (0 == fstat (f, &sb)) &&
(NULL != (data = malloc ((size_t) sb.st_size))) && (NULL != (data = malloc ((size_t) sb.st_size))) &&
(sb.st_size == READ (f, data, (size_t) sb.st_size) ) ) (sb.st_size == read (f, data, (size_t) sb.st_size) ) )
{ {
EXTRACTOR_extract (plugins, EXTRACTOR_extract (plugins,
NULL, NULL,
data, sb.st_size, data, sb.st_size,
processor, processor,
NULL); NULL);
} }
else else
{ {
if (verbose > 0) if (verbose > 0)
FPRINTF (stderr, fprintf (stderr,
"%s: %s: %s\n", "%s: %s: %s\n",
utf8_argv[0], utf8_argv[i], strerror (errno)); utf8_argv[0], utf8_argv[i], strerror (errno));
ret = 1; ret = 1;
} }
if (NULL != data) if (NULL != data)
free (data); free (data);
if (-1 != f) if (-1 != f)
(void) CLOSE (f); (void) close (f);
} }
if (YES == grepfriendly) if (YES == grepfriendly)
FPRINTF (stdout, "%s", "\n"); fprintf (stdout, "%s", "\n");
continue; continue;
} }
if (YES == grepfriendly) if (YES == grepfriendly)
FPRINTF (stdout, "%s", "\n"); fprintf (stdout, "%s", "\n");
if (bibtex) if (bibtex)
finish_bibtex (utf8_argv[i]); finish_bibtex (utf8_argv[i]);
if (verbose > 0) if (verbose > 0)
FPRINTF (stdout, "%s", "\n"); fprintf (stdout, "%s", "\n");
free (print); free (print);
free (utf8_argv); free (utf8_argv);
EXTRACTOR_plugin_remove_all (plugins); EXTRACTOR_plugin_remove_all (plugins);
plugins = NULL; plugins = NULL;
cleanup_bibtex (); /* actually free's stuff */ cleanup_bibtex (); /* actually free's stuff */
return ret; return ret;
} }
/* end of extract.c */ /* end of extract.c */
 End of changes. 35 change blocks. 
35 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)