Example #1
0
int
main(int argc, char **argv)
{
  lou_registerLogCallback(log_to_buffer);
  log_buffer_pos = 0;
  lou_setLogLevel(LOG_WARN);
  logMessage(LOG_ERROR, "foo");
  logMessage(LOG_INFO, "bar");
  lou_setLogLevel(LOG_INFO);
  logMessage(LOG_INFO, "baz");
  return assert_log_buffer_equals("[ERROR] foo\n[INFO] baz\n");
}
Example #2
0
int
main(int argc, char **argv)
{
  int success = 0;
  char * match;
  const char * tables[] = {"tablesWithMetadata/foo","tablesWithMetadata/bar",NULL};
  lou_setLogLevel(LOG_DEBUG);
  lou_indexTables(tables);
  match = lou_findTable("id:foo");
  success |= (!match || (strstr(match, "tablesWithMetadata/foo") == NULL));
  match = lou_findTable("language:en");
  success |= (!match || (strstr(match, "tablesWithMetadata/bar") == NULL));

  lou_free();
  return success;
}
Example #3
0
int
main (int argc, char **argv)
{
  int mode = 0;
  char *configFileList = NULL;
  char *inputFileName = "stdin";
  char *outputFileName = "stdout";
  char tempFileName[MAXNAMELEN];
  char logFileName[MAXNAMELEN];
  char whichProc = 0;
  char *configSettings = NULL;
  FILE *inputFile = NULL;
  FILE *tempFile;
  int ch = 0;
  int pch = 0;
  int nch = 0;
  int charsRead = 0;
  int k;
  UserData *ud;

  int optc;
  lbu_setLogLevel(LOU_LOG_WARN);
  lou_setLogLevel(LOU_LOG_WARN);
  set_program_name (argv[0]);
  logFileName[0] = 0;
  
  while ((optc =
	  getopt_long (argc, argv, "hvf:brpPtlw:TC:", longopts, NULL)) != 
	  -1)
    switch (optc)
      {
	/* --help and --version exit immediately, per GNU coding standards.  */
      case 'v':
	version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS,
		     (char *) NULL);
	exit (EXIT_SUCCESS);
	break;
      case 'h':
	print_help ();
	exit (EXIT_SUCCESS);
	break;
      case 'l':
	strcpy (logFileName, "file2brl.log");
	break;
      case 't':
	mode |= htmlDoc;
	break;
      case 'f':
	configFileList = optarg;
	break;
      case 'b':
      case 'p':
      case 'P':
      case 'r':
      case 'T':
      case '0':
	whichProc = optc;
	break;
      case 'C':
	if (configSettings == NULL)
	  {
	    configSettings = malloc (BUFSIZE);
	    configSettings[0] = 0;
	  }
	strcat (configSettings, optarg);
	strcat (configSettings, "\n");
	break;
       case 'w':
        lbu_setWriteablePath (optarg);
        break;
      default:
	fprintf (stderr, "Try `%s --help' for more information.\n",
		 program_name);
	exit (EXIT_FAILURE);
	break;
      }

  if (optind < argc)
    {
      if (optind == argc - 1)
	{
	  inputFileName = argv[optind];
	}
      else if (optind == argc - 2)
	{
	  if (strcmp (argv[optind], "-") != 0)
	    inputFileName = argv[optind];
	  outputFileName = argv[optind + 1];
	}
      else
	{
	  fprintf (stderr, "%s: extra operand: %s\n",
		   program_name, argv[optind + 2]);
	  fprintf (stderr, "Try `%s --help' for more information.\n",
		   program_name);
	  exit (EXIT_FAILURE);
	}
    }

  if (whichProc == 0)
    whichProc = '0';
  if (logFileName[0] != 0)
  {
  strcpy (logFileName, lbu_getWriteablePath());
  strcat (logFileName, "file2brl.log");
  }
  if (configSettings != NULL)
    for (k = 0; configSettings[k]; k++)
      if (configSettings[k] == '=' && configSettings[k - 1] != ' ')
	configSettings[k] = ' ';
  if (configFileList == NULL)
    configFileList = "preferences.cfg";
  if ((ud = lbu_initialize (configFileList, logFileName, 
  configSettings)) == NULL)
    exit (EXIT_FAILURE);
  if (strcmp (inputFileName, "stdin") != 0)
    {
      if (!(inputFile = fopen (inputFileName, "r")))
	{
	  logMessage (LOU_LOG_FATAL, "Can't open input file %s.\n", inputFileName);
	  exit (EXIT_FAILURE);
	}
    }
  else
    inputFile = stdin;
  /*Create somewhat edited temporary file to facilitate use of stdin. */
  strcpy (tempFileName, lbu_getWriteablePath ());
  strcat (tempFileName, "file2brl.temp");
  if (!(tempFile = fopen (tempFileName, "w")))
    {
      logMessage (LOU_LOG_FATAL, "Can't open temporary file.\n");
      exit (EXIT_FAILURE);
    }
  if (whichProc == 'p')
    {
      int ppch = 0;
      int firstCh = 0;
      int skipit = 0;
      while ((ch = fgetc (inputFile)) != EOF)
	{
	  if (firstCh == 0)
	    firstCh = ch;
	  if (ch == 12 || ch == 13)
	    continue;
	  if (ch == '<' && firstCh == '<')
	    {
	      skipit = 1;
	      continue;
	    }
	  if (skipit)
	    {
	      if (ch == '>')
		skipit = 0;
	      continue;
	    }
	  if (ch == '-')
	    {
	      nch = fgetc (inputFile);
	      if (nch == 10)
		continue;
	      ungetc (nch, inputFile);
	    }
	  if (!((pch == 10 && ch == 10) || (ppch == 10 && pch == 10)))
	    {
	      if (ch <= 32 && pch <= 32)
		continue;
	      if (!
		  (pch == 10 && ((ppch >= 97 && ppch <= 122) || ppch == ',')))
		{
		  if (pch == 10 && ch < 97)
		    fputc (10, tempFile);
		}
	    }
	  ppch = pch;
	  pch = ch;
	  fputc (ch, tempFile);
	  charsRead++;
	}
    }
  else
    while ((ch = fgetc (inputFile)) != EOF)
      {
	if (charsRead == 0 && ch <= ' ')
	  continue;
	if (ch == 13)
	  continue;
	if (charsRead == 0)
	  {
	    if (ch != '<' && whichProc == '0')
	      whichProc = 'T';
	    nch = fgetc (inputFile);
	    if (!(mode & htmlDoc) && whichProc == '0' && nch != '?')
	      fprintf (tempFile, "%s\n", ud->xml_header);
	  }
	if (pch == '>' && ch == '<')
	  fputc (10, tempFile);
	if (whichProc == 'P' && ch == 10 && pch != 10)
	  fputc (10, tempFile);
	fputc (ch, tempFile);
	pch = ch;
	charsRead++;
	if (charsRead == 1)
	  {
	    fputc (nch, tempFile);
	    charsRead++;
	  }
      }
  fclose (tempFile);
  if (inputFile != stdin)
    fclose (inputFile);
  if (charsRead > 2)
    switch (whichProc)
      {
      case 'b':
	if (!lbu_backTranslateFile (configFileList, tempFileName,
				    outputFileName, logFileName, configSettings,
				    mode))
	  exit (EXIT_FAILURE);
	break;
      case 'r':
	{
	  char temp2FileName[MAXNAMELEN];
	  strcpy (temp2FileName, lbu_getWriteablePath ());
	  strcat (temp2FileName, "file2brl2.temp");
	  if (!lbu_backTranslateFile (configFileList, tempFileName,
				      temp2FileName, logFileName,
				      configSettings, mode))
	    exit (EXIT_FAILURE);
	  if (ud->back_text == html)
	    if (!lbu_translateFile (configFileList, temp2FileName,
				    outputFileName, logFileName, configSettings,
				    mode))
	      exit (EXIT_FAILURE);
	  else
	    if (!lbu_translateTextFile (configFileList, temp2FileName,
					outputFileName, logFileName,
					configSettings, mode))
	      exit (EXIT_FAILURE);
	}
	break;
      case 'p':
	if (!lbu_translateTextFile (configFileList, tempFileName,
				    outputFileName, logFileName, configSettings,
				    mode))
	  exit (EXIT_FAILURE);
	break;
      case 'T':
	if (!lbu_translateTextFile (configFileList, tempFileName,
				    outputFileName,
				    logFileName, configSettings, mode))
	  exit (EXIT_FAILURE);
	break;
      case 't':
      case '0':
	if (!lbu_translateFile (configFileList, tempFileName, outputFileName,
				logFileName, configSettings, mode))
	  exit (EXIT_FAILURE);
	break;
      default:
	logMessage (LOU_LOG_FATAL, "Program bug %c\n", whichProc);
	break;
      }
  lbu_free ();
  if (configSettings != NULL)
    free (configSettings);
  return 0;
}