home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
bbs
/
alib
/
d5xx
/
d583
/
aroff.lha
/
ARoff
/
Sources
/
ajuste.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-04
|
3KB
|
165 lines
/*
* Ajustement des lignes
* (c)1991 par Denis GOUNELLE
*/
#include "aroff.h"
#include "pile.h"
extern unsigned char OutputBuf[] ;
extern long OutputLen, TmpLineLen, AdjustMode, Flg, TmpCenter ;
static unsigned char tmp[LGMAXBUF+1] ;
/***********************************************************************/
long adjust_b()
{
long nbr, inc ;
register unsigned char *p ;
register long k, l, j, NbInt ;
if ( Flg & F_BREAKED ) return( 0 ) ;
/* calcule le nombre d'intervalles et la taille de la ligne */
j = NbInt = 0 ;
p = OutputBuf ;
for ( k = 0 ; k < OutputLen ; k++ )
{
if ( isspace( *p ) )
{
if ( j ) NbInt++ ;
j = 0 ;
}
else j = 1 ;
p++ ;
}
/* calcule le nombre d'espaces a inserer */
if (! NbInt) return( 0 ) ;
k = TmpLineLen - OutputLen ;
nbr = k / NbInt ;
inc = NbInt - (k % NbInt) ;
/* effectue l'insertion */
p = tmp ;
j = l = 0 ;
for ( k = 0 ; k < OutputLen ; k++ )
{
if ( isspace( OutputBuf[k] ) )
{
if ( j )
{
for ( j = 0 ; j < nbr ; j++ , p++ ) *p = ' ' ;
l++ ;
if ( l == inc ) nbr++ ;
}
j = 0 ;
}
else j = 1 ;
*p = OutputBuf[k] ;
p++ ;
}
*p = '\0' ;
return( 1 ) ;
}
/***********************************************************************/
long adjust_c()
{
register long k, l ;
register unsigned char *p ;
p = OutputBuf ;
for ( k = 0 ; k < OutputLen ; k++ , p++ ) if (! isspace( *p )) break ;
l = (TmpLineLen - OutputLen + k) >> 1 ;
for ( p = tmp ; l > 0 ; l-- , p++ ) *p = ' ' ;
for ( ; k < OutputLen ; k++ , p++ ) *p = OutputBuf[k] ;
*p = '\0' ;
return( 1 ) ;
}
/***********************************************************************/
long adjust_r()
{
register long k ;
register unsigned char *p ;
k = TmpLineLen - OutputLen ;
for ( p = tmp ; k > 0 ; k-- , p++ ) *p = ' ' ;
for ( k = 0 ; k < OutputLen ; k++ , p++ ) *p = OutputBuf[k] ;
*p = '\0' ;
return( 1 ) ;
}
/***********************************************************************/
void AdjustLine()
{
register long c, l ;
/* verifie qu'on ne coupe pas un mot */
if ( OutputLen >= TmpLineLen )
{
SauveContexte( 1 ) ;
c = GetChar() ;
if ( c == EOF ) return ;
l = OutputLen-1 ;
while ( (! isspace( c )) && (! isspace( OutputBuf[l] )) )
{
RestoreContexte( 0 ) ;
l = OutputLen-1 ;
SauveContexte( 1 ) ;
c = GetChar() ;
}
RestoreContexte( 1 ) ;
}
/* enleve les espaces en fin de ligne */
l = OutputLen - 1 ;
while ( (l > 0) && isspace( OutputBuf[l] ) )
{
OutputLen-- ;
l-- ;
}
if (! OutputLen ) return ;
/* cadre/centre/justifie */
*tmp = '\0' ;
l = ( TmpCenter ) ? AM_CENTER : AdjustMode ;
switch ( l )
{
case AM_BOTH : c = adjust_b() ; break ;
case AM_LEFT : c = 0 ; break ;
case AM_RIGHT : c = adjust_r() ; break ;
case AM_CENTER : c = adjust_c() ; break ;
}
if ( c )
{
l = strlen( tmp ) ;
strncpy( OutputBuf , tmp , l ) ;
OutputLen = l ;
}
}