Exemplo n.º 1
0
int main(int argc, char **argv) {
  int optc;
  char *table;
  set_program_name(argv[0]);
  while ((optc = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) {
    switch (optc) {
      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;
      default:
        fprintf (stderr, "Try `%s --help' for more information.\n", program_name);
        exit(EXIT_FAILURE);
        break; }}
  if (optind != argc - 1) {
    if (optind < argc - 1)
      fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]);
    else
      fprintf(stderr, "%s: no table specified\n", program_name);
    fprintf(stderr, "Try `%s --help' for more information.\n", program_name);
    exit(EXIT_FAILURE); }
  table = argv[optind];
  if (!lou_getTable(table)) {
    lou_free();
    exit(EXIT_FAILURE); }
  main_loop(table);
  lou_free();
  exit(EXIT_SUCCESS);
}
Exemplo n.º 2
0
int
main (int argc, char **argv)
{
  const TranslationTableHeader *table;
  int optc;

  set_program_name (argv[0]);

  while ((optc = getopt_long (argc, argv, "hvq", 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 'q':
	quiet_flag = 1;
        break;
      default:
	fprintf (stderr, "Try `%s --help' for more information.\n",
		 program_name);
	exit (EXIT_FAILURE);
        break;
      }

  if (optind != argc - 1)
    {
      /* Print error message and exit.  */
      if (optind < argc - 1)
	fprintf (stderr, "%s: extra operand: %s\n",
		 program_name, argv[optind + 1]);
      else
	fprintf (stderr, "%s: no table specified\n", 
		 program_name);
      fprintf (stderr, "Try `%s --help' for more information.\n",
               program_name);
      exit (EXIT_FAILURE);
    }

  if (!(table = lou_getTable (argv[optind])))
    {
      lou_free ();
      exit (EXIT_FAILURE);
    }
  if (quiet_flag == 0)
    fprintf (stderr, "No errors found.\n");
  lou_free ();
  exit (EXIT_SUCCESS);
}
Exemplo n.º 3
0
int
main(int argc, char **argv)
{

  const char* table = "tests/tables/pass2.ctb";

  int result = 0;

  /* First check a plain word to see if inpos handling generally
     works */
  const char* str1 = "Rene";
  const int expected_inpos1[] = {0,1,2,3,3};

  result |= check(table, str1, "rene", .expected_inputPos=expected_inpos1);

  /* then try a word which uses pass2 and makes the output longer */
  const char* str2 = "Reno";
  const int expected_inpos2[] = {0,1,2,3,3};

  result |= check(table, str2, "ren'o", .expected_inputPos=expected_inpos2);

  /* finally try a word also uses pass2, deletes a char from the
     output and essentially shortens the output */
  const char* str3 = "xRen";
  const int expected_inpos3[] = {1,2,3};

  result |= check(table, str3, "ren", .expected_inputPos=expected_inpos3);

  lou_free();

  return result;

}
int main(int argc, char **argv) {
  int result = 0;

	result |= check(TRANSLATION_TABLE, UNDEFINED_DOTS, "\\\\456/", .direction=1);
	result |= check(TRANSLATION_TABLE, UNDEFINED_DOTS, "", .direction=1, .mode=noUndefinedDots);

  lou_free();
  return result;
}
Exemplo n.º 5
0
int
main (int argc, char **argv)
{
  const char *str1 = "World ";
  const int expected_pos1[]={0,1,2,3,4,3};

  int result = check_cursor_pos(TRANSLATION_TABLE, str1, expected_pos1);

  lou_free();

  return result;
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
  int result = 0;
  const char *text = "---.com";
  const char *expected = "";

  result |= check_translation("UEBC-g2.ctb", text, NULL, expected);

  lou_free();

  return result;
}
Exemplo n.º 7
0
int
main (int argc, char **argv)
{
    const char *str1 = "*****@*****.**";
    const int expected_inpos[] =
    {0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15,15};

    int result = check_inpos(TRANSLATION_TABLE, str1, expected_inpos);

    lou_free();

    return result;
}
Exemplo n.º 8
0
static int
getInput(void) {
	int inputLength;
	inputBuffer[0] = 0;
	if (!fgets(inputBuffer, sizeof(inputBuffer), stdin)) exit(EXIT_FAILURE);
	inputLength = strlen(inputBuffer) - 1;
	if (inputLength < 0) /* EOF on script */
	{
		lou_free();
		exit(EXIT_SUCCESS);
	}
	inputBuffer[inputLength] = 0;
	return inputLength;
}
Exemplo n.º 9
0
int
main(int argc, char **argv)
{
  const char *tableList = "tables/unicode.dis,tables/en-us-comp6.ctb";
  const char *str = "én";
  const char *expected = "⠄⡳⠭⠴⠴⠑⠔⠄⠝";
  int result = 0;

  result |= check(tableList, str, expected, .cursorPos=0);
  result |= check(tableList, str, expected, .cursorPos=1);
  result |= check(tableList, str, expected, .mode=compbrlAtCursor, .cursorPos=0);
  result |= check(tableList, str, expected, .mode=compbrlAtCursor, .cursorPos=1);

  lou_free();
  return result;
}
Exemplo n.º 10
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;
}
Exemplo n.º 11
0
/* Illustrates the same bug as doctests/hyphenate_xxx_test.txt
 * The same bug can be reproduced with only 3 'x'es. */
int main(int argc, char **argv)
{
    int ret = 0;
    char *tables = "tables/cs-g1.ctb,tables/hyph_cs_CZ.dic";
    char *word = "xxx";
    char * hyphens = calloc(5, sizeof(char));

    hyphens[0] = '0';
    hyphens[1] = '0';
    hyphens[2] = '0';

    ret = check_hyphenation(tables, word, hyphens);
    assert(hyphens[3] == '\0');
    assert(hyphens[4] == '\0');
    free(hyphens);
    lou_free();
    return ret;
}
Exemplo n.º 12
0
int
main(int argc, char **argv)
{
    int i;
    int result = 0;

    char* table = "pass0_typebuf.ctb";
    char* text = "foo baz";
    char* expected = "foobar .baz";
    char* typeform = malloc(20 * sizeof(char));
    for (i = 0; i < 7; i++)
      typeform[i] = 0;
    for (i = 4; i < 7; i++)
      typeform[i] = 1;

    result = check_translation(table, text, typeform, expected);

    lou_free();

    return result;
}
Exemplo n.º 13
0
int
main(int argc, char **argv)
{
    int i;
    int result = 0;

    char* table = "tests/tables/pass0_typebuf.ctb";
    char* text = "foo baz";
    char* expected = "foobar .baz";
    formtype* typeform = malloc(20 * sizeof(formtype));
    for (i = 0; i < 7; i++)
      typeform[i] = 0;
    for (i = 4; i < 7; i++)
      typeform[i] = 1;

    result = check(table, text, expected, .typeform=typeform);

    lou_free();

    return result;
}
Exemplo n.º 14
0
int main(int argc, char **argv)
{
  int ret = 0;
  char *tables = "tables/da-dk-g26.ctb";
  char *word = "achena";
  char * hyphens = calloc(8, sizeof(char));

  hyphens[0] = '0';
  hyphens[1] = '1';
  hyphens[2] = '0';
  hyphens[3] = '0';
  hyphens[4] = '1';
  hyphens[5] = '0';

  ret = check_hyphenation(tables, word, hyphens);
  assert(hyphens[6] == '\0');
  assert(hyphens[7] == '\0');
  free(hyphens);
  lou_free();
  return ret;
}
Exemplo n.º 15
0
static void 
translate_input (int forward_translation, char *table_name)
{
  char charbuf[BUFSIZE];
  char *outputbuf;
  widechar inbuf[BUFSIZE];
  widechar transbuf[BUFSIZE];
  int inlen;
  int translen;
  int k;
  int ch = 0;
  int result;
  while (1)
    {
      translen = BUFSIZE;
      k = 0;
      while ((ch = getchar ()) != '\n' && ch != EOF && k < BUFSIZE)
	charbuf[k++] = ch;
      if (ch == EOF && k == 0)
	break;
      charbuf[k] = 0;
      inlen = extParseChars (charbuf, inbuf);
      if (forward_translation) 
	  result = lou_translateString (table_name, inbuf, &inlen,
				      transbuf, &translen, NULL, NULL, 0);
      else 
	result = lou_backTranslateString (table_name, inbuf, &inlen,
					  transbuf, &translen, NULL, NULL, 0);
      if (!result)
	break;
      outputbuf = showString (transbuf, translen);
      k = strlen (outputbuf) - 1;
      outputbuf[k] = 0;
      printf ("%s\n", &outputbuf[1]);
    }
  lou_free ();
}
Exemplo n.º 16
0
int
main(int argc, char **argv)
{

  int result = 0;

  const char *str      = "This is a Test";
  const char *typeform = "00000000000000";
  const char *expected = ",this is a ,test";

  result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);

  str      = "This is a Test in Italic.";
  typeform = "1111111111111111111111111";
  expected = "..,this is a ,test in ,italic4.'";

  result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);

  str      = "This is a Test";
  typeform = "00000111100000";
  expected = ",this .is .a ,test";

  result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);

  /* Test case requested here:
   * http://www.freelists.org/post/liblouis-liblouisxml/Mesar-here-are-some-test-possibilities */

  str      = "time and spirit";
  typeform = "111111111111111";
  expected = ".\"t .& ._s";

  result |= check_translation(TRANSLATION_TABLE, str, convert_typeform(typeform), expected);

  lou_free();
  return result;
}
Exemplo n.º 17
0
int
main(int argc, char **argv)
{

  int result = 0;

  /* First check italics with the English table */
  const char *str      = "He said it wasn't always working as expected.";
  const formtype typeform[] = {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0};
  const char *expected = ".,he sd x wasn't .alw .\"w+ z expect$4";

  result |= check_translation(TRANSLATION_TABLE, str, typeform, expected);

  /* Then check a test table that defines lastworditalafter */
  str      = "Er sagte es funktioniere nicht immer wie erwartet.";
  const formtype typeform2[] = {1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  expected = "_ER SAGTE ES __FUNKTION0RE NI4T', IMMER W0 ERWARTET.";

  result |= check_translation("de-ch-g1.ctb", str, typeform2, expected);

  lou_free();

  return result;
}
Exemplo n.º 18
0
int main(int argc, char **argv)
{

  int i;
  int result = 0;

  const char *tests[] = {
    /* first column is the text, the second is the expected value */
    " ", " ",
    /* the usual case */
    "                                                                                ", " ",
    /* a very long string */
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                ", " ",
    /* an even longer string */
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                ", " ",
    /* a string containing tabs */
    "    \t",     " \t",
    "    \t    ", " \t ",
    "\t    ",     "\t ",
    /* Strings containing newlines */
    "    \n",     " \n",
    "    \n    ", " \n ",
    "\n    ",     "\n "
  };

  /* A number of strings that we want to squash, i.e. they should all
     result in an output of one space */
  const char *strings[] = {
    /* a simple space */
    " ",
    /* a long string */
    "                                                                                ",
    /* a very long string */
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                ",
    /* an even longer string */
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                " \
    "                                                                                ",
    /* a couple of strings containing tabs */
    "    \t",
    "    \t    ",
    "\t    ",
    /* Strings containing newlines */
    "    \n",
    "    \n    ",
    "\n    ",
    /* All mixed */
    "    \n    \t    \n    \t\t    \n\n\n\t\t    ",
  };
  const char *expected = " ";

  int tests_len = sizeof(tests)/sizeof(char*);

  for (i = 0; i < tests_len; i += 2)
    result |= check_translation("tests/tables/squash_space_with_repeated.utb", tests[i], NULL, tests[i+1]);

  tests_len = sizeof(strings)/sizeof(char*);

  for (i = 0; i < tests_len; i++)
    result |= check_translation("tests/tables/squash_space_with_correct.utb", strings[i], NULL, expected);

  for (i = 0; i < tests_len; i++)
    result |= check_translation("tests/tables/squash_space_with_context_1.utb", strings[i], NULL, expected);

  for (i = 0; i < tests_len; i++)
    result |= check_translation("tests/tables/squash_space_with_context_2.utb", strings[i], NULL, expected);

  lou_free();

  return result;
}
Exemplo n.º 19
0
int
main (int argc, char **argv)
{
  char *charbuf;
  widechar inbuf[BUFSIZE];
  widechar transbuf[BUFSIZE];
  widechar outbuf[BUFSIZE];
  int outputPos[BUFSIZE];
  int inputPos[BUFSIZE];
  int inlen;
  int translen;
  int outlen;
  int cursorPos = -1;
  int realInlen = 0;
  int k;
  int optc;

  set_program_name (argv[0]);

  while ((optc = getopt_long (argc, argv, "hv", 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;
      default:
	fprintf (stderr, "Try `%s --help' for more information.\n",
		 program_name);
	exit (EXIT_FAILURE);
        break;
      }

  if (optind < argc)
    {
      /* Print error message and exit.  */
      fprintf (stderr, "%s: extra operand: %s\n",
	       program_name, argv[optind]);
      fprintf (stderr, "Try `%s --help' for more information.\n",
               program_name);
      exit (EXIT_FAILURE);
    }

  validTable = NULL;
  enteredCursorPos = -1;
  mode = 0;
  while (1)
    {
      getCommands ();
      printf ("Type something, press enter, and view the results.\n");
      printf ("A blank line returns to command entry.\n");
      if (minimalist)
	while (1)
	  {
	    translen = outputSize;
	    outlen = outputSize;
	    inlen = getInput ();
	    if (inlen == 0)
	      break;
	    if (!(realInlen = extParseChars (inputBuffer, inbuf)))
	      break;
	    inlen = realInlen;
	    if (!lou_translateString (table, inbuf, &inlen, transbuf,
				      &translen, NULL, NULL, 0))
	      break;
	    transbuf[translen] = 0;
	    printf ("Translation:\n");
	    charbuf = showString (transbuf, translen);
	    k = strlen (charbuf) - 1;
	    charbuf[k] = 0;
	    printf ("%s\n", &charbuf[1]);
	    if (showSizes)
	      printf ("input length = %d; output length = %d\n", inlen,
		      translen);
	    lou_backTranslateString (table, transbuf, &translen, outbuf,
				     &outlen, NULL, NULL, 0);
	    printf ("Back-translation:\n");
	    charbuf = showString (outbuf, outlen);
	    k = strlen (charbuf) - 1;
	    charbuf[k] = 0;
	    printf ("%s\n", &charbuf[1]);
	    if (showSizes)
	      printf ("input length = %d; output length = %d.\n", translen,
		      outlen);
	    if (outlen == realInlen)
	      {
		for (k = 0; k < realInlen; k++)
		  if (inbuf[k] != outbuf[k])
		    break;
		if (k == realInlen)
		  printf ("Perfect roundtrip!\n");
	      }
	  }
      else
	while (1)
	  {
	    for (k = 0; k < strlen (enteredEmphasis); k++)
	      emphasis[k] = (formtype) enteredEmphasis[k];
	    emphasis[k] = 0;
	    strcpy (spacing, enteredSpacing);
	    cursorPos = enteredCursorPos;
	    inlen = getInput ();
	    if (inlen == 0)
	      break;
	    outlen = outputSize;
	    if (backOnly)
	      {
	    if (!(translen = extParseChars (inputBuffer, transbuf)))
	      break;
	    inlen = realInlen;
	      }
	    else
	      {
		translen = outputSize;
	    if (!(realInlen = extParseChars (inputBuffer, inbuf)))
	      break;
	    inlen = realInlen;
		if (!lou_translate (table, inbuf, &inlen, transbuf,
				    &translen, emphasis, spacing,
				    &outputPos[0], &inputPos[0], &cursorPos,
				    mode))
		  break;
		transbuf[translen] = 0;
		if (mode & dotsIO)
		  {
		    printf ("Translation dot patterns:\n");
		    printf ("%s\n", showDots (transbuf, translen));
		  }
		else
		  {
		    printf ("Translation:\n");
		    charbuf = showString (transbuf, translen);
		    k = strlen (charbuf) - 1;
		    charbuf[k] = 0;
		    printf ("%s\n", &charbuf[1]);
		    if (showSizes)
		      printf ("input length = %d; output length = %d\n",
			      inlen, translen);
		  }
	      }
	    if (cursorPos != -1)
	      printf ("Cursor position: %d\n", cursorPos);
	    if (enteredSpacing[0])
	      printf ("Returned spacing: %s\n", spacing);
	    if (showPositions)
	      {
		printf ("Output positions:\n");
		for (k = 0; k < inlen; k++)
		  printf ("%d ", outputPos[k]);
		printf ("\n");
		printf ("Input positions:\n");
		for (k = 0; k < translen; k++)
		  printf ("%d ", inputPos[k]);
		printf ("\n");
	      }
	    if (!forwardOnly)
	      {
		if (!lou_backTranslate (table, transbuf, &translen,
					outbuf, &outlen,
					emphasis, spacing, &outputPos[0],
					&inputPos[0], &cursorPos, mode))
		  break;
		printf ("Back-translation:\n");
		charbuf = showString (outbuf, outlen);		k = 
		strlen (charbuf) - 1;
		charbuf[k] = 0;
		printf ("%s\n", &charbuf[1]);
		if (showSizes)
		  printf ("input length = %d; output length = %d\n",
			  translen, outlen);
		if (cursorPos != -1)
		  printf ("Cursor position: %d\n", cursorPos);
		if (enteredSpacing[0])
		  printf ("Returned spacing: %s\n", spacing);
		if (showPositions)
		  {
		    printf ("Output positions:\n");
		    for (k = 0; k < translen; k++)
		      printf ("%d ", outputPos[k]);
		    printf ("\n");
		    printf ("Input positions:\n");
		    for (k = 0; k < outlen; k++)
		      printf ("%d ", inputPos[k]);
		    printf ("\n");
		  }
	      }
	    if (!(forwardOnly || backOnly))
	      {
		if (outlen == realInlen)
		  {
		    for (k = 0; k < realInlen; k++)
		      if (inbuf[k] != outbuf[k])
			break;
		    if (k == realInlen)
		      printf ("Perfect roundtrip!\n");
		  }
	      }
	  }
    }
  lou_free ();
  exit (EXIT_SUCCESS);
}
Exemplo n.º 20
0
static int
getCommands (void)
{
  paramLetters ();
  do
    {
      printf ("Command: ");
      getInput ();
      switch (inputBuffer[0])
	{
	case 0:
	  break;
	case 't':
	  do
	    {
	      printf ("Enter the name of a table: ");
	      getInput ();
	      strcpy (table, inputBuffer);
	    }
	  while ((validTable = lou_getTable (table)) == NULL);
	  break;
	case 'r':
	  if (validTable == NULL)
	    {
	      printf ("You must enter a valid table name.\n");
	      inputBuffer[0] = 0;
	    }
	  break;
	case 'm':
	  printf ("Reset mode");
	  if (getYN ())
	    mode = 0;
	  printf ("No contractions");
	  mode |= getYN ();
	  printf ("Computer braille at cursor");
	  mode |= 2 * getYN ();
	  printf ("Dots input and output");
	  mode |= 4 * getYN ();
	  printf ("8-dot computer braille");
	  mode |= 8 * getYN ();
	  printf ("Pass1 only");
	  mode |= 16 * getYN ();
	  break;
	case 'l':
	  printf ("Do you want to test input and output lengths");
	  showSizes = getYN ();
	  if (!showSizes)
	    {
	      outputSize = BUFSIZE;
	      break;
	    }
	  printf ("Enter a maximum output size: ");
	  getInput ();
	  outputSize = atoi (inputBuffer);
	  if (outputSize < 0 || outputSize > BUFSIZE)
	    {
	      printf ("Output size must be from 0 tu %d.\n", BUFSIZE);
	      outputSize = BUFSIZE;
	      showSizes = 0;
	    }
	  break;
	case 'c':
	  printf ("Enter a cursor position: ");
	  getInput ();
	  enteredCursorPos = atoi (inputBuffer);
	  if (enteredCursorPos < -1 || enteredCursorPos > outputSize)
	    {
	      printf ("Cursor position must be from -1 to %d.\n", outputSize);
	      enteredCursorPos = -1;
	    }
	  break;
	case 'e':
	  printf ("(Enter an x to cancel emphasis.)\n");
	  printf ("Enter an emphasis string: ");
	  getInput ();
	  strcpy (enteredEmphasis, inputBuffer);
	  break;
	case 's':
	  printf ("(Enter an x to cancel spacing.)\n");
	  printf ("Enter a spacing string: ");
	  getInput ();
	  strcpy (enteredSpacing, inputBuffer);
	  break;
	case 'h':
	  printf ("Commands: action\n");
	  printf ("(t)able: Enter a table name\n");
	  printf ("(r)un: run the translation/back-translation loop\n");
	  printf ("(m)ode: Enter a mode parameter\n");
	  printf ("(c)ursor: Enter a cursor position\n");
	  printf ("(e)mphasis: Enter an emphasis string\n");
	  printf ("(s)pacing: Enter a spacing string\n");
	  printf ("(h)elp: print this page\n");
	  printf ("(q)uit: leave the program\n");
	  printf ("(f)orward-only: do only forward translation\n");
	  printf ("(b)ack-only: do only back-translation\n");
	  printf ("show-(p)ositions: show input and output positions\n");
	  printf
	    ("m(i)nimal: test translator and back-translator with minimal parameters\n");
	  printf ("test-(l)engths: test accuracy of returned lengths\n");
	  printf ("\n");
	  paramLetters ();
	  break;
	case 'q':
	  lou_free();
	  exit (EXIT_SUCCESS);
	case 'f':
	  printf ("Do only forward translation");
	  forwardOnly = getYN ();
	  break;
	case 'b':
	  printf ("Do only backward translation");
	  backOnly = getYN ();
	  break;
	case 'p':
	  printf ("Show input and output positions");
	  showPositions = getYN ();
	  break;
	case 'i':
	  printf
	    ("Test translation/back-translation loop with minimal parameters");
	  minimalist = getYN ();
	  break;
	default:
	  printf ("Bad choice.\n");
	  break;
	}
      if (forwardOnly && backOnly)
	printf
	  ("You cannot specify both forward-only and backward-only translation.\n");
    }
  while (inputBuffer[0] != 'r');
  return 1;
}
Exemplo n.º 21
0
int
main (int argc, char **argv)
{
  widechar inbuf[BUFSIZE];
  char hyphens[BUFSIZE];
  int inlen;
  int k;
  int optc;

  set_program_name (argv[0]);

  while ((optc = getopt_long (argc, argv, "hv", 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;
      default:
	fprintf (stderr, "Try `%s --help' for more information.\n",
		 program_name);
	exit (EXIT_FAILURE);
        break;
      }

  if (optind < argc)
    {
      /* Print error message and exit.  */
      fprintf (stderr, "%s: extra operand: %s\n",
	       program_name, argv[optind]);
      fprintf (stderr, "Try `%s --help' for more information.\n",
               program_name);
      exit (EXIT_FAILURE);
    }

  validTable = NULL;
  mode = 0;

  while (1)
    {
      getCommands ();
      printf ("Type something, press enter, and view the results.\n");
      printf ("A blank line returns to command entry.\n");
      while (1)
	{
	  inlen = getInput ();
	  if (inlen == 0)
	    break;
	  for (k = 0; k < inlen; k++)
	    inbuf[k] = inputBuffer[k];
	  if (!lou_hyphenate (table, inbuf, inlen, hyphens, mode))
	    {
	      printf ("Hyphenation error\n");
	      continue;
	    }
	  printf ("Hyphenation mask: %s\n", hyphens);
	  printf ("Hyphenated word: ");
	  for (k = 0; k < inlen; k++)
	    {
	      if (hyphens[k] == '1')
		printf ("-");
	      printf ("%c", inbuf[k]);
	    }
	  printf ("\n");
	}
    }
  lou_free ();
  return 0;
}