Wicri:Dilib source, module CharSet, CharSetTr

De Wicri Outils
Révision datée du 9 septembre 2013 à 09:31 par imported>Jacques Ducloy

Cette page introduit les sources relatifs à la commande CharSetTr du module Dilib, module CharSet.

Fichier CharSetTr.c

/***********************************************************************
*
*               Projet   : DilibPro
*               Module   : CharSet
*               Fichier  : CharSetTr.c
*               Auteur   : J. DUCLOY
*               Date     : Aout 93
*     $Id: CharSetTr.c,v 1.2 2003/07/11 13:39:36 parmentf Exp $
*
************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include "CharSetTabO.h"
#include "CharSetEbcdic.h"
#include <string.h>
void usage ()

{
printf ("Usage : CharSetTr -OtoA | -AtoO | -XtoA  | -AtoX | -AtoXX | -toLower | -toUpper < file name\n");
printf ("Usage : CharSetTr o2a | u2d | a2o | a2x | a2xx | -od | l | u < file name\n");
exit (1);
}

/*-----------------------------------------------------------------*/

void CharSetTrToLower()
{
int c;
while((c=getchar())!=EOF)
  {
    putchar(tolower(c));
  };
}

/*-----------------------------------------------------------------*/

void CharSetTrToUpper()
{
int c;
while((c=getchar())!=EOF)
  {
    putchar(toupper(c));
  };
}

/*-----------------------------------------------------------------*/

void CharSetTrAtoO()
{
int c;
while((c=getchar())!=EOF)
  {
    if (CharSetTabO[c]=='#')
      {
	printf("\\%d%d%d",(c&0300)>>6,(c&070)>>3,c&7);
      }
    else putchar(c);
  };
}

/*-----------------------------------------------------------------*/

void CharSetTrAtoOO()
{
int c;
while((c=getchar())!=EOF)
  {
    if ((c=='\n'))putchar ('\n');
    else printf("\\%d%d%d",(c&0300)>>6,(c&070)>>3,c&7);
  }
}


/*-----------------------------------------------------------------*/

void CharSetTrAtoX()
{
int c;
static char *hexa="0123456789ABCDEF";
while((c=getchar())!=EOF)
  {
    if (CharSetTabO[c]=='#')
      {
	printf("#%c%c",hexa[(c&0360)>>4],hexa[c&0017]);
      }
    else putchar(c);
  };
}

void CharSetTrAtoXX()
{
int c;
static char *hexa="0123456789ABCDEF";
while((c=getchar())!=EOF)
  {
    if (CharSetTabOctalXml[c]=='#')
      {
	printf("#%c%c",hexa[(c&0360)>>4],hexa[c&0017]);
      }
    else putchar(c);
  };
}

/*-----------------------------------------------------------------*/

void CharSetTrEtoX()
{
int c;
static char *hexa="0123456789ABCDEF";
while((c=getchar())!=EOF)
  {
    int c1;
    c1=CharSetEbcdicTab[c];
    if (c1=='#')
      {
	printf("#%c%c",hexa[(c&0360)>>4],hexa[c&0017]);
      }
    else putchar(c1);
  };
}

/*-----------------------------------------------------------------*/
void CharSetTrOtoA()
{
  int c;  /* char c;  */
  int c1; /* char c1; */
  int c2; /* char c2; */
  int c3; /* char c3; */

  while((c=getchar())!=EOF)
    {
      if(c== '\\')
	{
	  c1=getchar();
	  c2=getchar();
	  c3=getchar();
	  putchar((c3&7)+((c2&7)<<3)+((c1&7)<<6));
	}
      else
	{
	  putchar(c);
	};
    };
}

/*-----------------------------------------------------------------*/
void CharSetTrXAtoA()
{
  int c;  /* char c;  */
  int c1; /* char c1; */
  int c2; /* char c2; */

  while((c=getchar())!=EOF)
    {
      if(c== '#')
	{
	  c1=getchar();
	  c2=getchar();
	  if (isdigit(c1)) c=(c1&'\017')<<4;
	  else c=((c1&'\017')+9)<<4;
	  if (isdigit(c2)) c+=c2 & '\017';
	  else c+=(c2 & '\017')+9;
	  putchar(c);
	}
      else
	{
	  putchar(c);
	};
    };
}


int main(argc,argv)
     int argc;
     char **argv;
{
  char *option;

  if (argc!=2)usage();
  option=argv[1];
  if      (strcmp(option, "-OtoA")==0)   CharSetTrOtoA();
  else if (strcmp(option, "-AtoX")==0)   CharSetTrAtoX();
  else if (strcmp(option, "-od")==0)     CharSetTrAtoOO();
  else if (strcmp(option, "-AtoXX")==0)  CharSetTrAtoXX();
  else if (strcmp(option, "a2xx")==0)    CharSetTrAtoXX();
  else if (strcmp(option, "o2a")==0)     CharSetTrOtoA();
  else if (strcmp(option, "d2u")==0)     CharSetTrOtoA();
  else if (strcmp(option, "-XAtoA")==0)  CharSetTrXAtoA();
  else if (strcmp(option, "-XtoA")==0)   CharSetTrXAtoA();
  else if (strcmp(option, "-XA1toA")==0) CharSetTrXAtoA();
  else if (strcmp(option, "-O1toA")==0)  CharSetTrOtoA();
  else if (strcmp(option, "-AtoO")==0)   CharSetTrAtoO();
  else if (strcmp(option, "a2o")==0)     CharSetTrAtoO();
  else if (strcmp(option, "u2d")==0)     CharSetTrAtoO();
  else if (strcmp(option, "e2x")==0)     CharSetTrEtoX();
  else if (strcmp(option, "-toLower")==0)CharSetTrToLower();
  else if (strcmp(option, "l")==0)	 CharSetTrToLower();
  else if (strcmp(option, "-toUpper")==0)CharSetTrToUpper();
  else if (strcmp(option, "u")==0)	 CharSetTrToUpper();
  else usage();

  return (0);
}

La documentation par man

\" This file is managed on Wicri (Wicri:Dilib source, module CharSet, CharSetTr) "
.TH CharSetTr 1 "11 Jul 2003"
.SH NAME
CharSetTr \- transcode character sets.
.SH SYNOPSIS
.B CharSetTr
.I option
\<
.I file_name
.SH DESCRIPTION
.LP
.B CharSetTr
converts file
.I file_name
acccording to option.
.SH OPTION
.TP
.B \-OtoA
.PD
CharSetO (octal) to ASCII.
.
.TP
.B \-OtoA
.PD
CharSetO1 (restricted octal) to ASCII.
.
.TP
.B \-XAtoA
.PD
CharSetO (hexadecimal ASCII based) to ASCII.
.
.TP
.B \-XA1toA
.PD
CharSetXA1 (restricted hexadecimal ASCII base) to ASCII.
.
.TP
.B \-AtoO
.PD
ASCII toCharSetO (octal).
.
.TP
.B \-AtoX
.PD
ASCII toCharSetX (hexadecimal).
.
.TP
.B \-AtoXX
.PD
ASCII toCharSetXX (hexadecimal Xml compatible).
.
.TP
.B \-toLower
.PD
apply the
.BR tolower (3C)
C function to each character
.
.TP
.B \-toUpper
.PD
apply the
.BR toupper (3C)
C function to each character
.
.SH "SEE ALSO"
.BR CharSet (5),
.BR ctype (3C).

.SH AUTHORS
(c) 1993-2003 INIST-CNRS

Jacques DUCLOY,
Francois PARMENTIER