home *** CD-ROM | disk | FTP | other *** search
- /*
- PAGEIT.E
-
- PAGEIT scans the current file and inserts page numbers and ejects
- where they are needed. PAGEIT will also insert print control for
- single or double spacing if desired (of course, the page numbering
- is done taking single and double spacing into consideration). Two
- blank lines are inserted at the start of each new page.
-
- The routine will remove extra blank lines between paragraphs. It
- will recognize the page numbering so that if it is run more then
- once, maybe changes were made to the file, the ejects and page
- numbers will be repositioned correctly.
-
- SETUP:
- Compile PAGEIT.E with the EPM compiler. For example:
- ETPM PAGEIT.E
-
- Link the .EX file in MYSTUFF.E or MYMAIN.E
-
- Now it is ready to use. Edit your ASCII file, and enter the command
- PAGEIT.
-
- Try it. I hope you like it.
- Jeff Grantz
- */
-
- defc pageit=
- ind = ''
- TRUE = 0
- FALSE = 1
- top_of_page = TRUE
- pageline = ' Page '
- count = 0 ; blankline = 0
- eject = \12 -- put eject here so the macro can be printed without breaks
- psave_pos(save_pos) -- save starting point
- .col = 1 ; .line = 1
-
- ccmenu = '#Single spaced.'
- ccmenu = ccmenu||'#Single spaced. Insert print control characters.'
- ccmenu = ccmenu||'#Double spaced.'
- ccmenu = ccmenu||'#Double spaced. Insert print control characters.'
-
- cc2 = listbox('Is this document single or double spaced?',
- ccmenu, '' ,0 ,0 ,5,30);
-
- if (cc2 = '') then
- stop -- cancel indicates stop processing
- elseif (cc2 = 'Single spaced.' or
- cc2 = 'Single spaced. Insert print control characters.') then
- maxlines = 60
- range = 6
- spacing = \27\65\12\27\50
- wrong_spacing = \27\65\24\27\50
- else
- maxlines = 30
- range = 3
- spacing = \27\65\24\27\50
- wrong_spacing = \27\65\12\27\50
- endif
-
- if (cc2 = 'Single spaced. Insert print control characters.' or
- cc2 = 'Double spaced. Insert print control characters.') then
- getline line, 1
- line = strip(line, 'B')
-
- if line = '' then
- -- put the proper spacing into the document
- insertline spacing, 1
- elseif line = spacing then
- -- Current control is correct, don't do anything
- elseif line = wrong_spacing then
- replaceline spacing, 1
- else
- -- Insert the line before whatever is there
- insertline spacing, 1
- endif
- if (line = spacing or line = wrong_spacing) then
- .line = 2
- endif
- endif
-
- /*
- -- if .line < 2 then
- -- page = 0 -- set up to skip the leading blank lines without deleting
- -- else
- -- page = 1
- -- endif
- */
- page = 0
- -----------------------------------------------------------------------
- curline = .line
- do forever -- don't use for loop because the to value is evaluated once ONLY
- -- for curline = .line to .last
- if page = 0 then
- -- Don't delete leading blank lines
- for startline = curline to .last
-
- count = count + 1
- getline line, startline
- line = strip(line, 'B')
-
- if line <> '' then
- -- were done skipping, so get out of loop
- curline = startline
- startline = .last
- count = count - 1
- endif
- endfor
- page = 1
- endif
- count = count + 1
- if curline > .last then
- sayerror 'CURLINE > .LINE - - ERROR!! ind='ind
- if askyesno("Type ""N"" to stop",1)="N" then stop endif
- endif
- getline rawline, curline
- line = strip(rawline, 'B')
-
- if line = '' then
- -- Keep track of the last blank line found
- if curline - 1 = blankline then
- -- We have 2 blank lines in a row delete this one
- ind='removed blank line'
- deleteline curline
- curline = curline - 1
- count = count - 1
- else
- blankline = curline -- save location of blank line
- ind='saved blank line'
- endif
-
- elseif substr(rawline, 1, length(pageline)) = pageline then
- -- This is a page line so delete it
- ind='deleted pageline'
- deleteline curline
- curline = curline - 1
- count = count - 1
-
- elseif line = eject then
- -- Delete the old ejects
- ind='deleted eject'
- deleteline curline
- curline = curline - 1
- count = count - 1
- else
- -- found a real line, indicate not top of a page ant more
- top_of_page = FALSE
- endif
-
- if count > maxlines then
- if page < 10 then
- pagenum = ' '|| page
- else
- pagenum = page
- endif
- page = page + 1
- -- DO THE EJECT!!!!!!!!!!!!!!!!!!!!!
- -- Find a place to put the eject
- -- Put the page numbering in
- -- Then fix the count
- count = 3
- top_of_page = TRUE
- ind='do eject'
-
- if curline - range > blankline then
- -- put the eject here, the last blank line is to far back
- insertline ' ', curline
- -- Put a blank line in so reflow won't
- -- take the eject in
- else
- -- skip down lines so pageline comes out in same place as the other ch
- -- put the eject at the last blank line
- -- IE front of the next paragraph
- for i = blankline to curline
- insertline ' ', i
- endfor
- endif
- -- Common code------------------------------------------
- if (cc2 = 'Single spaced.' or
- cc2 = 'Single spaced. Insert print control characters.') then
- -- If the doc is single spaced, add a second trailer blank line
- insertline ' ', curline
- curline = curline + 1
- endif
- insertline pageline || pagenum, curline + 1
- insertline eject, curline + 2
- insertline ' ', curline + 3
- if cc2 = 'Single spaced.' then
- -- If the doc is single spaced, add a second header blank line
- insertline ' ', curline + 4
- curline = curline + 4
- else
- curline = curline + 3
- endif
- sayerror 'One moment while I work. I am at line ' curline
- endif
-
- curline = curline + 1 -- EXIT LOOP CODE !!!!!!!!!
- if curline > .last then -- EXIT LOOP CODE !!!!!!!!!
- leave -- EXIT LOOP CODE !!!!!!!!!
- endif -- EXIT LOOP CODE !!!!!!!!!
-
- enddo -- end of do forever
-
- if top_of_page = FALSE then
- for i = count to maxlines + 1
- insertline ' ', .last + 1
- endfor
- if page < 10 then
- pagenum = ' '|| page
- else
- pagenum = page
- endif
- insertline pageline || pagenum, .last + 1 -- put page number on last pag
- endif
-
- prestore_pos(save_pos)
- sayerror 'Pagination done.'
-
-