Path: utzoo!utgpu!jarvis.csri.toronto.edu!clyde.concordia.ca!uunet!snorkelwacker!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!mcnc!xanth!cs.odu.edu!Amiga-Request From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator) Newsgroups: comp.sources.amiga Subject: v90i098: Wrap 1.00 - word-wrap text files, Part01/01 Message-ID: <11624@xanth.cs.odu.edu> Date: 4 Mar 90 03:26:17 GMT Sender: news@cs.odu.edu Reply-To: davids@ucscb.UCSC.EDU (60116000) Lines: 702 Approved: tadguy@cs.odu.edu (Tad Guy) X-Mail-Submissions-To: Amiga@cs.odu.edu X-Post-Discussions-To: comp.sys.amiga Submitted-by: davids@ucscb.UCSC.EDU (60116000) Posting-number: Volume 90, Issue 098 Archive-name: util/wrap-1.00 [ uuencoded executable included. ...tad ] [ the sample unformatted file has been uuencoded since some news transport agents croak on long lines... ] Wrap is a simple text formatter designed to word-wrap text files that have no carriage returns in paragraphs. I wrote it because my word processor, Write & File (never heard of it? Imagine a scaled down version of Pen Pal, written by Pen Pal's author), when it saves a document as straight ASCII, only has carriage returns at the end of paragraphs. This is nice when I import something into a desktop publishing program, but not when I use Write & File to write program documentation such as the documentation you're reading now. I could insert carriage returns manually, but that's a lot of work for 3 page docs, and if I make one change in the documentation, I have to reformat the whole thing over again. #!/bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'Wrap.c' <<'END_OF_FILE' X#include X#include X#include X#include X#include X#define CR 0x0D X#define LF 0x0A X XUBYTE GetWord(); Xvoid SetVariables(); X XBYTE DoubleSpacing = FALSE; XUSHORT RightMargin = 0; XUSHORT LeftMargin = 0; XUSHORT TopMargin = 0; XUSHORT BottomMargin = 0; XSHORT PageSize = 66; XUSHORT TabSpaces = 5; XUSHORT ParaIndent = 0; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X struct FileHandle *infile,*outfile; /*pointers to files*/ X char chip outbuf[256]; X UBYTE EOP=FALSE; /*End of paragraph flag*/ X UBYTE EOF=FALSE; /*End of file flag*/ X UBYTE wordcount,linecount; X ULONG Line; X char chip LeftSpaces[80]; X char chip TopReturns[80]; X char chip IndentSpaces[80]; X char chip BottomReturns[80]; X X LeftSpaces[0]=0x0a; X LeftSpaces[1]=NULL; X TopReturns[0]=BottomReturns[0]=NULL; X X if(argv[1][0]=='?') /*Print the instructions*/ X { X puts("Wrap V1.0 (c)1989, 1990 by Dave Schreiber. All rights reserved."); X puts("Written by Dave Schreiber."); X puts("Format:"); X puts(" 1> wrap [options] Infile Outfile"); X puts(" Infile-text file to be processed"); X puts(" Outfile-filename that the formatted text is to be written to"); X puts(" Options (in upper- or lowercase"); X puts(" -a# -- number of spaces to expand tabs out to (default 5)"); X puts(" -b# -- bottom margin (default 0)"); X puts(" -t# -- top margin (default 0)"); X puts(" -r# -- right margin (default 0)"); X puts(" -l# -- left margin (default 0)"); X puts(" -i# -- number of spaces to indent each paragraph (default 0)"); X puts(" -p# -- page size (with no margin, default 66)"); X puts(" -d -- double spaced (default is single spaced)"); X exit(0); X } X X if((argv[argc-1][0]=='-') || (argc == 2)) /*Check for output filename*/ X { X puts("No output file specified!!!\n"); X exit(100); X } X X if((argv[argc-2][0]=='-') || (argc == 1)) /*Check for input filename*/ X { X puts("No input file specified!!!\n"); X exit(200); X } X X /*Get the command line switches, etc.*/ X SetVariables(argc,argv,LeftSpaces,TopReturns,BottomReturns,IndentSpaces); X if(79-RightMargin-LeftMargin < 1) X { X puts("The left/right margins are too large!\n"); X exit(300); X } X X /*Get the true page size (after the margins are taken out)*/ X PageSize = PageSize - (TopMargin + BottomMargin); X if(PageSize < 1) X { X puts("The top/bottom margins are too large!"); X exit(400); X } X X /*Open read file*/ X if((infile=(struct FileHandle *)Open(argv[argc-2],MODE_OLDFILE))==NULL) X { X puts("Couldn't open the read file!"); X exit(500); X } X X /*Now go for write file*/ X if((outfile=(struct FileHandle *)Open(argv[argc-1],MODE_NEWFILE))==NULL) X { X puts("Couldn't open the write file!"); X Close(infile); /*Clean up*/ X exit(600); X } X X /*Write the first top margin padding*/ X Write(outfile,&TopReturns,TopMargin); X X /*Get the first word*/ X linecount=wordcount=GetWord(outbuf,&EOP,&EOF,infile); X X /*Write out the left margin*/ X Write(outfile,&LeftSpaces[1],LeftMargin); X X /*Write out the paragraph indent*/ X Write(outfile,IndentSpaces,ParaIndent); X linecount+=ParaIndent; X X /*Write the first word*/ X Write(outfile,outbuf,wordcount); X wordcount=(linecount+=LeftMargin); X X /*First line of the page...*/ X Line = 0; X X while(!EOF) /*While there's still stuff to be processed...*/ X { X outbuf[1]=NULL; X wordcount=GetWord(&outbuf[1],&EOP,&EOF,infile)+1; /*Get a word*/ X X if((linecount+=wordcount) > 79-RightMargin) /*End of line*/ X { X X if(DoubleSpacing) X { X Line++; X outbuf[0]=0x0a; /*If double spaced, write out an*/ X Write(outfile,outbuf,1); /*extra line*/ X } X X if(++Line == PageSize) /*If we're at the end of a page...*/ X { X Write(outfile,BottomReturns,BottomMargin); /*Write out the margins*/ X Write(outfile,TopReturns,TopMargin); X Line = 0; /*And start a new page*/ X } X X Write(outfile,LeftSpaces,LeftMargin+1); /*Left margin*/ X Write(outfile,&outbuf[1],wordcount-1); /*Write the word*/ X linecount=wordcount+LeftMargin; X } X else /*If we're not at the end of a line*/ X { X if(linecount != (wordcount+LeftMargin)) /*If were not at the start*/ X { /*of a line...*/ X outbuf[0]=0x20; /*Tack on a space*/ X Write(outfile,outbuf,wordcount); X } X else /*Don't tack on a space (insures new paragraphs are*/ X Write(outfile,&outbuf[1],wordcount-1); /*formatted properly)*/ X } X X if(EOP) /*If we're at the end of a paragraph*/ X { X outbuf[0]=0x0a; /*Start a new line*/ X Write(outfile,outbuf,1); X if(!EOF) /*Do this only if we're not at the end of the text*/ X { X if(DoubleSpacing) /*Another line if double spaced*/ X { X Line++; X Write(outfile,outbuf,1); X } X X if(++Line == PageSize) /*If at the end of a page?*/ X { /*Write the margins, etc.*/ X Write(outfile,BottomReturns,BottomMargin); X Write(outfile,TopReturns,TopMargin); X Line = 0; X } X if(LeftMargin>0) /*Write out a margin if it exists*/ X Write(outfile,&LeftSpaces[1],LeftMargin-1); X linecount=LeftMargin; X if(ParaIndent>0) /*Write out the indent for the start*/ X Write(outfile,IndentSpaces,ParaIndent-1); /*of the*/ X /*next paragraph*/ X linecount+=ParaIndent; X } X } X X } X X Close(outfile); /*Done*/ X Close(infile); X exit(0); X} X XUBYTE GetWord(buffer,EOP,EOF,in) Xchar *buffer; XUBYTE *EOP,*EOF; Xstruct FileHandle *in; X{ X char chip inbuf[8]; X UBYTE c,wordcount=0; X X *EOP=FALSE; X *EOF=GetByte(inbuf,in); X while ( ( !(*EOF) ) && (inbuf[0] != 0x0a) && (inbuf[0] != 0x20) ) X { X if(inbuf[0]=='\t') /*Expand tab out to spaces*/ X for(c=0;c'Wrap.doc' <<'END_OF_FILE' X Wrap V1.00 is Copyright (c)1990 by Dave Schreiber. All rights reserved. XThis program is freely distributable, and may not be sold. Money may be Xcharged for copying, media, shipping/handling, labels, taxes, and related Xcosts. X X Wrap is a simple text formatter designed to word-wrap text files that Xhave no carriage returns in paragraphs. I wrote it because my word Xprocessor, Write & File (never heard of it? Imagine a scaled down version Xof Pen Pal, written by Pen Pal's author), when it saves a document as Xstraight ASCII, only has carriage returns at the end of paragraphs. This is Xnice when I import something into a desktop publishing program, but not when XI use Write & File to write program documentation such as the documentation Xyou're reading now. I could insert carriage returns manually, but that's a Xlot of work for 3 page docs, and if I make one change in the documentation, XI have to reformat the whole thing over again. X X But enough of justifying Wrap's existence. Wrap's command line should Xlook like this: X X 1> Wrap [options] X X is the name of the unformatted text and is the filename Xyou want the formatted text saved under. The options are: X X -a# -- expand TABs out # spaces (default: 5 spaces) X -b# -- set a bottom margin of # (default: 0) X -t# -- set a top margin of # (default: 0) X -r# -- set a right margin of # (default: 0) X -l# -- set a left margin of # (default: 0) X -i# -- number of spaces to indent each paragraph X (default: 0) X -p# -- number of lines in a page (default: 66) X -d -- use double spacing (single spacing is the X default) X XThe line width is set at 79 characters. To format a text file to fit into a XCLI window, I'd recommend a right margin of two. If you want to send the Xfile to a printer, set the bottom and top margins to suit the printer. If Xthe printer supports less or more than 66 lines per page, -p lets you set Xthat. If you forgot to indent your paragraphs, -i will let you set that. XIf you indent them with TABs, -a will let you control how many spaces are Xinserted in place of a TAB. X X That's it. Any questions, comments, praise, etc. should be sent to the Xe-mail address(es) below. Enjoy. X X-Dave Schreiber Xdavids@slugmail.ucsc.edu (prefered, but flakey. If it doesn't work, try: Xdavids@ucscb.ucsc.edu (school year) Xdavids@cup.portal.com (summer, vacations, etc.)) X XP.S. Just to give you something to experiment with, I've included the Xunformatted version of this documentation under the name "Wrap.unfmt". X X END_OF_FILE if test 2623 -ne `wc -c <'Wrap.doc'`; then echo shar: \"'Wrap.doc'\" unpacked with wrong size! fi # end of 'Wrap.doc' fi if test -f 'Wrap.unfmt.uu' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'Wrap.unfmt.uu'\" else echo shar: Extracting \"'Wrap.unfmt.uu'\" \(3625 characters\) sed "s/^X//" >'Wrap.unfmt.uu' <<'END_OF_FILE' Xbegin 664 Wrap.unfmt XM"5=R87`@5C$N,#`@:7,@0V]P>7)I9VAT("AC*3$Y.3`@8GD@1&%V92!38VAR? XM96EB97(N("!!;&P@2!D:7-T2!096X@4&%L)W,@875T:&]R*2P@=VAE;B!I="!S5 XM879E6]U)W)E(')E861I;F<@;F]W+B`@1 XM22!C;W5L9"!I;G-E2P@8G5T@ XM('1H870G&ES=&5N8V4N("!7S XM'0@86YD(#QOC XM=71F:6QE/B!I6]U('=A;G0@=&AE(&9O2X@($EF(&ET(&1O97-N)W0@=V]R:RP@=')Y.@ID879I9'-`B XM=6-S8V(N=6-S8RYE9'4@*'-C:&]O;"!Y96%R*0ID879I9'-`8W5P+G!O'Wrap.uu' <<'END_OF_FILE' Xbegin 664 Wrap XM```#\P`````````%``````````0```0W```"&T```"````&X````&@```^D`V XM``0W)$@D`$GY`````$?Y```$>'(`(#P```":8`(FP5'(__PL>``$*4X$L"E/9 XM!+A"K`2T)FX!%'``(CP``#``3J[^SBEK`)@$K$JK`*QG``!P(`^0KP`$!H``= XM``"`*4`$?&$``2X@:P"LT$ZZI XM`.!P`&`$("\`!"\`("P$I&<$($!.D$ZZ#NPL>``$(FP&T$ZN_F).N@!.2JP$- XMM&<:(BP$O&<$3J[_W"QX``1.KO]\(FP$M$ZN_H8@'RYL!+A.=7!D8+1#^@`0W XM<`!.KOW8*4`&T&?L3G5D;W,N;&EB0!.=4YU2.<',"XO`!@F;P`<+"\`L XM("\'3KH-6%A/)$`@"F8$``"( XM0J XM3KK[,$_O``PJ`&`">@!P_[J`9@@(ZP`%`!M@#+JM__!G!@CK``0`&TH&9PXB5 XM*P`4)`%$@B="``Q@&`@K``(`&V<(<@`G00`,8`@B*P`4)T$`#"!K`!`G2``$' XMOH!G+E.K``QM%B!K``1#Z``!)TD`!"`'$(!R`!(`8!(@!W(`$@`O"R\!80#]O XMD%!/(@!P,,"K`!AG!'#_8`QP_[B`9@1P`&`"(`1,WPCT3EU.=0T*`````"YL' XM!+A.N@4B2'D````43KH#D```````````<&%.5?_X2.<#,"9O`"`D;P`D+B\`Q XM*"!*2AAF_%.(D*TO_]"MM_^S_Z"938`#_Z XM;B!M__0@BD*2)4<`!'``3-],@$Y=3G4``````````'!A2.<',"XO`!@F;P`<. XM+"\`("\'3KH&(%A/)$`@"F8$<`H0@'(`$@!@$$AL`YI(>``*3KKZ_%!/(@`@`4S?"(!.=0``, XM2.(@``43KH#("QM_ZQ.74YUL XM*BH@4W1A8VL@3W9E1(!*@6H```Q$@6$``"!$@4YU80``&$2`1(%.=4J!:@``#$2!80``1 XM!D2`3G4O`DA!-`%F```B2$!(04A"-`!G```&A,$P`DA`-`"$P3`"2$(R`B0?K XM3G4O`W80#$$`@&0```;AF5%##$$(`&0```;IF5E##$$@`&0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y```),$[Y```'I$[Y````'$[Y````3$[Y```*T$[Y````,```W XM`^P````$````````"%````AB```(2@``"#X````"`````@``!8X```5Z````C XM!`````0```AH```(7```"%8```A$`````````_)```/J````(```````````( XM````````````````````````````````````````````````````````````` XM````````````````````````````````````````````````````````````` XM```````````````````````````````````````````#\@```^H```$>````! XM``````````!"``4``%=R87`@5C$N,""I,3DX.2P@,3DY,"!B>2!$879E(%-C: XM:')E:6)E'0@:7,@=&\@8F4@=W)I='1E;B!T;P``("!/<'1I;VYS("AI;B!U<'!E'!A;F0@=&%B XM:"`H9&5F875L="`P*0``("`@("UP(R`M+2!P86=E('-I>F4@*'=I=&@@;F\@! XM;6%R9VEN+"!D969A=6QT(#8V*0`@("`@+60@("TM(&1O=6)L92!S<&%C960@: XM*&1E9F%U;'0@:7,@0``!M!,[P`&``Q.KO_B3-]`!$YU```O#BQY```&T"(O``A.KO_<+%].Z XM=4CG,`(L>0``!M!,[P`.`!!.KO_63-]`#$YU``!(YS`"+'D```;03.\`#@`0J XM3J[_T$S?0`Q.=0`````#[`````0````#````4@```#8````@````!@``````I XM``/P`````E]7```````<`````E]/<&5N``````````````````/R$ X`` Xend Xsize 8220 END_OF_FILE if test 11541 -ne `wc -c <'Wrap.uu'`; then echo shar: \"'Wrap.uu'\" unpacked with wrong size! fi # end of 'Wrap.uu' fi echo shar: End of archive 1 \(of 1\). cp /dev/null ark1isdone MISSING="" for I in 1 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have the archive. rm -f ark[1-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exit 0 -- Mail submissions (sources or binaries) to . Mail comments to the moderator at . Post requests for sources, and general discussion to comp.sys.amiga.