Exemple #1
0
SaneWinMain( argc, argv )
{
	FILE *input;
	if( argc > 2 )
	{
		input = sack_fopen( 0, argv[2], WIDE("rb+") );
		if( input )
		{
			if( StrCaseCmpEx( argv[1], WIDE( "u" ), 1 ) == 0 )
			{
				read_ascii( input );
				ascii_to_unicode();
				write_unicode( input );
			}
			else
			{
				read_unicode( input );
				unicode_to_ascii();
				write_ascii( input );
			}
			fclose( input );
		}
		else
			printf( WIDE( "Failed to open %s" ), argv[2] );
	}
	else
	{
		printf( WIDE("Usage: %s [u/a] [filename]\n"), argv[0] );
		printf( WIDE("  u or a is unicode or ascii mode; unicode translates from ascii to unicode\n") );
		printf( WIDE("  ascii translates from unicode to ascii\n") );
		printf( WIDE("  file will be written back in-place\n") );
	}
	return 0;
}
Exemple #2
0
/* Read input from the text client and populate the spool with it.
 */
static void
fill_targets (ModeInfo *mi)
{
  splitflap_configuration *bp = &bps[MI_SCREEN(mi)];
  int x, y;
  Bool cls_p = False;

  if (bp->clock_p)
    {
      char buf[80];
      time_t now = time ((time_t *) 0);
        struct tm *tm = localtime (&now);
      const char *fmt = (bp->clock_p == 24
                         ? "%H%M%S"
                         : "%I%M%S%p");
      int i;
      strftime (buf, sizeof(buf)-1, fmt, tm);
      if (bp->clock_p == 12 && buf[0] == '0')
        buf[0] = ' ';

      for (i = 0; i < strlen(buf); i++)
        {
          flapper *f = &bp->flappers[i];
          f->target_index = find_index (mi, f, buf[i]);
        }
      for (; i < grid_width * grid_height; i++)
        {
          flapper *f = &bp->flappers[i];
          f->target_index = find_index (mi, f, ' ');
        }
      return;
    }

  for (y = 0; y < grid_height; y++)
    {
      Bool nl_p = False;
      for (x = 0; x < grid_width; x++)
        {
          int i = y * grid_width + x;
          flapper *f = &bp->flappers[i];
          unsigned long uc = ((nl_p || cls_p) ? ' ' : read_unicode (mi));
          if (uc == '\r' || uc == '\n')
            nl_p = True;
          else if (uc == 12)  /* ^L */
            cls_p = True;

          /* Convert Unicode to the closest Latin1 equivalent. */
          if (uc > 127)
            {
              Bool ascii_p = (f->spool != latin1_spool);
              unsigned char s[5], *s2;
              int L = utf8_encode (uc, (char *) s, sizeof(s));
              s[L] = 0;
              s2 = (unsigned char *) utf8_to_latin1 ((char *) s, ascii_p);
              
              if (s2[0] < 128)	/* ASCII */
                uc = s2[0];
              else		/* Latin1 -> UTF8 -> Unicode */
                {
                  s[0] = (s2[0] > 0xBF ? 0xC3 : 0xC2);
                  s[1] = s2[0] & (s2[0] > 0xBF ? 0xBF : 0xFF);
                  s[2] = 0;
                  utf8_decode (s, 2, &uc);
                }

              free (s2);
            }

          /* Upcase ASCII. Upcasing Unicrud would be rocket surgery. */
          if (uc >= 'a' && uc <= 'z') uc += ('A'-'a');

          f->target_index = find_index (mi, f, uc);

          f->sticky = (((random() % 20) == 0)
                       ? 0.05 + frand(0.1) + frand(0.1)
                       : 0);
        }
    }

# if 0
  for (y = 0; y < grid_height; y++)
    {
      fprintf (stderr, "# ");
      for (x = 0; x < grid_width; x++)
        {
          int i = y * grid_width + x;
          flapper *f = &bp->flappers[i];
          fprintf(stderr, "%s", bp->spool[f->target_index]);
        }
      fprintf (stderr, " #\n");
    }
  fprintf (stderr, "\n");
# endif
}