From E.Barbaini.cons@it12.bull.it  Fri Oct  8 18:36:37 1993
Received-Date: Fri, 8 Oct 93 18:34:33 +0100
From: Emiliano Barbaini <E.Barbaini.cons@it12.bull.it>
Message-Id: <9310081342.AA17665@qateam.it12.bull.it>
Subject: QUILL READER
To: sinf7@imovx2.unimo.it (Omar Valenti), beppe@maya.dei.unipd.it (G.Zanetti)
Date: Fri, 8 Oct 1993 14:41:46 +0100 (MET)
Return-Receipt-To: E.Barbaini.cons@it12.bull.it
Reply-To: E.Barbaini.cons@it12.bull.it
X-Mailer: ELM [version 2.4 PL13]
Content-Type: text
Content-Length: 3649      


Ciao. vi invio un piccolo programmino in C, che serve a trasformare
un file _doc in ASCII txt. Non ci sono molti fronzoli, ma funziona
praticamente su tutte le macchine che dispongono di un compilatore
C : io ad es. lo uso sul mio sistema, dove scarico i files in formato
QL con QLTOOLS, li filtro e poi li formatto e li stampo in postscript.
L' idea e' nata dal fatto che Quill non puo' esportare in ascii.

Se lo ritenete utile, scaricatelo sulla rete. L' ho inviato anche
a Tim Swenson.


			Ciao, a presto
			Emiliano Barbaini

----------------- CUT HERE -----------------------------------

/******************************************************/
/********** quill reader : a simple filter ************/
/********** vs 1.08 08 Oct. 1993           ************/
/********** Emiliano Barbaini              ************/
/********** E-mail  E.Barbaini.cons@it12.bull.it  *****/
/******************************************************/
#include <stdio.h>
#include <string.h>

void right_justify();
void End_of_Document();
void Newpage();
void Newparagraph();
void Htab();
void Check_Nlines();

#define WIDTH    70        /** width of a line           **/
#define MAXLINE  60        /** Nr of lines for page      **/
#define HTAB      5        /** tab length                **/

char Paragraph[32768];
int Page=1;                /** Start printing at page =1 **/
int Nlines=1;              /** number of lines, max 60   **/
int count;

main()
{
register int ch;

    while( (ch=getchar()) != EOF )
    {
        if (ch==14)              End_of_Document();
        if (ch==12)              Newpage();
        if (ch==0)               Newparagraph();
        if (ch==9)               Htab();
        if (ch>=32 && ch<=127)   Paragraph[count++]=ch;
    }
}
void
Htab()
{
register int blank,j;

    blank=count % 5;
    for (j=0;j<blank;j++)
        Paragraph[count++]=' ';
    return;
}
void
End_of_Document()
{
    Paragraph[count]='\0';
    right_justify(Paragraph);
    printf("\n ----- End of Document -----\n");
    exit(0);
}
void
Newpage()
{
    Paragraph[count]='\0';
    right_justify(Paragraph);
    printf("\n ----- End of Page  %2d -----\n",Page++);
    Paragraph[0]='\0';
    count=0;
    Nlines=1;
    return;
}
void
Newparagraph()
{
    Paragraph[count]='\0';
    right_justify(Paragraph);
    Paragraph[0]='\0';
    count=0;
    return;
}

void
Check_Nlines()
{
    if ( Nlines++ > MAXLINE )
    {
        Nlines=1;
        printf("\n ----- End of Page  %2d -----\n",Page++);
    }
    return;
}
/**/

void
right_justify(register char *stringa)
{
register int j,k;            /** 'for' variables **/
int pos = 0;
int start_pos = 0;
int len;

    len=strlen(stringa);
    if (len<=WIDTH)
    {
        printf ("%s\n",stringa);
        Check_Nlines();
        return;
    }
    pos=WIDTH;
    while(start_pos<len)
    {
        if ( pos > len )
        {
            for (j=start_pos;j<=len;j++)
                putchar(stringa[j]);
            putchar('\n');
            Check_Nlines();
            return;
        }
        if ( stringa[pos] != ' ' )
            pos--;
        else {
            for (j=start_pos,k=0;j<=pos;j++,k++)
                putchar(stringa[j]);
            putchar('\n');
            Check_Nlines();
            start_pos+=k ;
            pos=start_pos + k;
        }
    }
    return;
}
/****************************************************************/
-- 
 Emiliano Barbaini               |   Email : E.Barbaini.cons@it12.bull.it
 BULL HN                         |   tel   : 39-2-6779-8362
 Via Lab. Olivetti               |   fax   : 39-2-6779-8222
 I-20010 Pregnana Milanese       |   telex : 33 25 22 


                                            Giuseppe Zanetti


