Пример #1
0
int
initialize_contents (void)
{

  saved_braillePageNumberFormat = ud->brl_page_num_format;
  widestrcpy (saved_printPageNumber, ud->print_page_number);
  widestrcpy (saved_printPageNumberFirst, ud->print_page_number_first);
  widestrcpy (saved_printPageNumberLast, ud->print_page_number_last);
  widestrcpy (saved_pageSeparatorNumberFirst, ud->page_separator_number_first);
  widestrcpy (saved_pageSeparatorNumberLast, ud->page_separator_number_last);
  saved_runningHeadLength = ud->running_head_length;
  saved_footerLength = ud->footer_length;
  widecharcpy (saved_runningHead, ud->running_head, ud->running_head_length);
  widecharcpy (saved_footer, ud->footer, ud->footer_length);
  ud->after_contents = 1;
  saved_udContents = ud->contents;
  saved_linesOnPage = ud->lines_on_page;
  saved_braillePageNumber = ud->braille_page_number;
  ud->contents = 1;
  firstHeading = NULL;
  lastHeading = NULL;
  saved_lastHeading = NULL;
  saved_firstHeading = NULL;
  saved_outFile = ud->outFile;
  strcpy (tempFileName, lbu_getWriteablePath ());
  strcat (tempFileName, "lbx_body.temp");
  if (!(tempFile = fopen (tempFileName, "w")))
    {
      logMessage (LOG_ERROR, "Can't open temporary file.\n");
      return 0;
    }
  ud->outFile = tempFile;
  ud->lines_on_page = 0;
  if (ud->has_contentsheader)
    ud->braille_page_number = ud->beginning_braille_page_number;
  else
    ud->braille_page_number = 1;
  return 1;
}
Пример #2
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;
}
Пример #3
0
int
set_paths (const char *configPath)
{
  char currentPath[MAXNAMELEN];
  char *dataPath = NULL;
  char *writePath = NULL;

/*Set configuration path first*/
  ud->config_path = NULL;
  if (configPath != NULL && configPath[0] != 0)
    {
      ud->config_path = alloc_string (configPath);
      if (!addPath (configPath))
	return 0;
    }

/*Set other paths here*/

/* First, see if the program has set a path. */
  dataPath = lou_getDataPath ();
  if (dataPath)
    {
#ifdef _Win32
      strcpy (currentPath, dataPath);
      strcat (currentPath, "\\liblouis\\tables\\");
      if (!addPath (currentPath))
	return 0;
      strcpy (currentPath, dataPath);
      strcat (currentPath, "\\liblouisutdml\\lbu_files\\");
      ud->lbu_files_path = alloc_string (currentPath);
      if (!addPath (currentPath))
	return 0;
#else
      strcpy (currentPath, dataPath);
      strcat (currentPath, "/liblouis/tables/");
      if (!addPath (currentPath))
	return 0;
      strcpy (currentPath, dataPath);
      strcat (currentPath, "/liblouisutdml/lbu_files/");
      ud->lbu_files_path = alloc_string (currentPath);
      if (!addPath (currentPath))
	return 0;
#endif
    }
  else
    {
#ifdef _WIN32
/* Set Windows Paths */
      {
	char louisPath[MAXNAMELEN];
	char lbuPath[MAXNAMELEN];
	strcpy (currentPath, lou_getProgramPath ());
	strcat (currentPath, "..\\");
	if (!addPath (currentPath))
	  return 0;
	strcpy (lbuPath, currentPath);
	strcat (lbuPath, "share\\liblouisutdml\\lbu_files\\");
      ud->lbu_files_path = alloc_string (lbuPath);
	strcpy (louisPath, currentPath);
	strcat (louisPath, "share\\liblouis\\tables\\");
	addPath (louisPath);
	addPath (lbuPath);
      }
#else
/* Set Unix paths (Linux, Mac OS X, etc.) */
      addPath (LIBLOUIS_TABLES_PATH);
      addPath (LBU_PATH);
      ud->lbu_files_path = alloc_string (LBU_PATH);
#endif /*WWIN32 */
    }

/* set current directory last*/
  currentPath[0] = '.';
  currentPath[1] = ud->file_separator;
  currentPath[2] = 0;
  if (!addPath (currentPath))
    return 0;
  if ((writePath = lbu_getWriteablePath ()) == NULL)
    lbu_setWriteablePath (lastPath);
  else
    {
      currentPath[0] = ud->file_separator;
      currentPath[1] = 0;
      strcat (writePath, currentPath);
    }
  return 1;
}