// PRINT.VDM -- Basic print formatting macro. // // Originally by: Theodore Green, Greenview Data, Inc. // Last change: 03/16/99 // // Modified by // Christian Ziemski 02/08/2000 (Indention for wrapped lines) // (Ruler dependent on printer right margin) // 02/11/2000 (european date format option added) // 02/12/2000 (more formatting options added) // 10/04/2000 (some bug fixes and enhancements) // Known problem: printing very long lines // in landscape format doesn't work o.k. // reason: "Bug" in VEDIT: Switching portrait/landscape for // the printer from within VEDIT doesn't switch // all internal values! (e.g. Printer_LPP) // Requires: VEDIT 5.03 or later. // // From VEDIT: Select {FILE, Print}. In dialog box select "( ) PRINT.VDM". // // From OS: vedit -x print filename (Where 'filename' is your file.) // // Description: Prints the current highlighted block, if any, with the // filename on the top of each page. If there is no currently // highlighted block, prints the entire file with filename and // page numbers. Starts a new page if a (Ctrl-L) is // in the first column. // // Options: Print with optional line number and/or file offset. // Num_Push(92,99) // save used normal registers ////////////////// // configuration / ////////////////// //------------------------------------------------------------- #121=0 // Set to "1" to print full pathname on separate line // Prints page #, date and time on next line // #96=1 // Set to "1" to use dd.mm.yyyy instead of mm-dd-yyyy // in the heading line //------------------------------------------------------------- #95=1 // Set to "1" to add a dash line below the heading line //------------------------------------------------------------- #118=0 // Set to "1" to add a column ruler at top and bottom // #118 is here now a flag only, the exact value is // calculated below (dependent on Config(P_Right_Marg)) // #92=0 // Set to "1" to add an additional ruler line to show the ten's // #94=1 // Set to "1" to add an empty line below the top column ruler // and above the bottom ruler (only valid if ruler is activated) //------------------------------------------------------------- #116=0 // Set to "1" to add line numbers #117=0 // Set to "1" to add file offset; or "HEX" to print in hex // #93=0 // Set to "1" to add an additional line between the text lines // //////////////////------------------------------------------------------------- #99=Config(P_RIGHT_MARG) // get right print margin #98=#116*7 + #117*11 + (#116 && #117) // get indention through line number and position if(#99>0 && #99>=#98){ // calculate print width #97=#99-#98 } else { #97=0 } if(#118){ #118=#97 // calculate ruler length if(#118==0){ #118=80 // hard coded default } // (not optimal but o.k., I think) } // :AGAIN: #103 = Config(P_TOP_MARG,0) //Disable page formatting (save old values) #104 = Config(P_BOT_MARG,0) //allows macro to control entire page #106 = 1 //Set page counter to 1 #107 = Block_Begin //Save current block begin marker #108 = Block_End //Save current block end marker //#109 = working block begin //#110 = working block end #120 = 0 //#120 = temp #122 = Cur_Pos //#122 = save current position in file Out_Print() //Re-route output to the printer if ((#109=Block_Begin) < 0) { BOF() //Print from the beginning of file #109 = 0 #110 = File_Size } else { if ((#110=Block_End) < 0) { #110 = Cur_Pos } if (#110<#109) { //Ensure that #109 <= #110 Num_Push(110,110) //Tricky way to exchange #109 & #110 #110 = #109 // without using another register Num_Pop(109,109) } Goto_Pos(#109) Line(0) } Repeat(ALL) { //Print loop for entire file/block Type_Newline(2) //Print 2 blank lines Message("File: ") //Start heading line if (#121) { //If full pathname on separate line... Name_Write(NOMSG+EXTRA) //Print full pathname; start new line //Name_Write(NOMSG) //Alternate for just very long filenames Message("Page ") //Heading Num_Type(#106,LEFT+NOCR) //Print page number, left justified Tab_Out(20) //Tab-out to column 20 if(#96){ #99=Buf_Num // Print the date as dd.mm.yyyy Out_Reg(104) Date(BEGIN+NOCR) Out_Reg(CLEAR) Buf_Switch(34) Buf_Empty(OK) Reg_Ins(104) BOF Replace("-",".",ALL) Reg_Copy_Block(104,0,EoL_Pos) Buf_Switch(#99) Reg_Type(104) } else { Date(NOCR) //Print the date as mm-dd-yyyy } Message(" ") //And a space Time(NOMSG) //Print the time; start a new line } else { Name_Write(NOMSG+NOCR) //Print filename if(Config(P_RIGHT_MARG)){ Tab_Out(Config(P_RIGHT_MARG)-Config(P_LEFT_MARG) - 40) } else { Tab_Out(30) } if(#96){ #99=Buf_Num // Print the date as dd.mm.yyyy Out_Reg(104) Date(BEGIN+NOCR) Out_Reg(CLEAR) Buf_Switch(34) Buf_Empty(OK) Reg_Ins(104) BOF Replace("-",".",ALL) Reg_Copy_Block(104,0,EoL_Pos) Buf_Switch(#99) Reg_Type(104) } else { Date(NOCR) //Print the date as mm-dd-yyyy } if(Config(P_RIGHT_MARG)){ Tab_Out(Config(P_RIGHT_MARG)-Config(P_LEFT_MARG) - 10) } else { Tab_Out(60) } // if (#107<0) { //Only print "PAGE" if printing entire file Message("Page ") //Heading Num_Type(#106,LEFT+NOCR) //Print page number, left justified // } Type_Newline(1) //Start a new line } if(#95){ // if dash line if(Config(P_RIGHT_MARG)){ Type_Char('-',COUNT,Config(P_RIGHT_MARG)-Config(P_LEFT_MARG)) } else { Type_Char('-',COUNT,70) // hard codes default if no right margin configured } Type_Newline(1) //Start a new line } if (#118) { //If ruler desired... if(#92){ // if ruler should show ten's Type_Char(' ',COUNT,#116*7 + #117*11 + (#116 && #117)) #120=#118/10 for(#99=1;#99<=#120;#99++) { Message(" ") if(#99<10){ Message(" ") } Num_Type(#99,LEFT+NOCR) } Type_Newline(1) //Start a new line } Type_Char(' ',COUNT,#116*7 + #117*11 + (#116 && #117)) #120=#118/10 Repeat(#120) { Message("123456789+") } for(#120=1;#120<=(#118-#118/10*10);#120++){ Num_Type(#120,LEFT+NOCR) } // Type_Newline(1) // not necessary because of Print_Right_Margin's auto LF if (#94){ Type_Newline(1) //additional empty line } } Type_Newline(1) // empty line before the text Repeat(ALL) { //Print loop for one page // Print until Printer_Line past bottom of page. // Account for dashes, 2 blank lines at bottom, and ruler if (Printer_Line > Printer_LPP-2-(#118!=0)*(1+#94+#92)-#95) { //If past bottom of page... Break //Break out of loop to start new page } if (Config(P_RIGHT_MARG)){ // check if multi-line line would fit onto current page #99 = (EoL_Pos-Bol_Pos)/(Config(P_RIGHT_MARG)-#98) + 1 if (Printer_Line > Printer_LPP-2-(#118!=0)*(1+#94+#92)-#95- #99-1 ) { Break //Break out of loop to start new page } } if (Cur_Char==^L) { //If in 1st column... Char() //Skip char Break //Break out of loop to start new page } if (At_EOF || (Cur_Pos >= #110)) { Goto END //Branch when done } if (#116) { //If optional line number desired... Num_Type(Cur_Line,NOCR) Tab_Out(8) } if (#117) { //If optional file position desired... if (#117==HEX) { Num_Type(Cur_Pos,HEX+NOCR) } else { Num_Type(Cur_Pos,NOCR) } if (#116) { Tab_Out(12+8) } else { Tab_Out(12) } } if(#116||#117){ // if indention required because of line number or file pos. Out_Reg(104) Type(1) // Print one text line, file buffering if needed Out_Reg(Clear) // no longer to printer, but into TReg.104 #99=Buf_Num // remember current buffer Buf_Switch(34) // switch to temp. buffer Buf_Empty(OK) Reg_Ins(104) // and insert that line here BoF if(#97 && (EoL_Pos > #97)){ // if print width is known and line longer than it Type_Block(0,#97,NORESTORE) // type it in separate lines with indention Type_Newline Del_Line(0) while(EoL_Pos >= #97){ Type_Space(#116*7 + #117*11 + (#116 && #117)) Type_Block(0,#97,NORESTORE) Type_Newline Del_Line(0) } Type_Space(#116*7 + #117*11 + (#116 && #117)) Type(1) } else { // else type it in one line Type(1) } Buf_Switch(#99) } else { Type(1) //Print one text line, file buffering if needed } if (#93){ Type_Newline // additional empty line between text lines } Line(1,NOERR) //Advance by 1 line } //End of loop for one page if (#118) { // If ruler desired... if (#94){ Type_Newline(1) // additional empty line } if(#92){ // if ruler should show ten's Type_Char(' ',COUNT,#116*7 + #117*11 + (#116 && #117)) #120=#118/10 for(#99=1;#99<=#120;#99++) { Message(" ") if(#99<10){ Message(" ") } Num_Type(#99,LEFT+NOCR) } Type_Newline(1) //Start a new line } Type_Char(' ',COUNT,#116*7 + #117*11 + (#116 && #117)) #120=#118/10 Repeat(#120) { Message("123456789+") } for(#120=1;#120<=(#118-#118/10*10);#120++){ Num_Type(#120,LEFT+NOCR) } // Type_Newline(1) } Print_Eject() //Page-eject, start new page if (Cur_Char==^L) { Char() } //Ignore next char if it's ; //prevents printing blank pages #106++ //Advance page counter } //END of main print loop :END: Num_Pop(92,99) // restore temp. used registers Out_Print(0) //Turn off printer re-routing Print_Finish() //Finish print job //DOS: just a page eject (same as PE) //UNIX: flush and close the print job Block_End(#108) //Restore original block end marker Block_Begin(#107) //Restore original block begin marker Goto_Pos(#122) //Restore original file position Config(P_TOP_MARG,#103) //Restore original print config values... Config(P_BOT_MARG,#104) if (Macro_Num<>100) { //If macro not running in T-Reg 100... Return //Exit macro } :PROMPT: Repeat(ALL){ //Loop until valid reply #104 = Get_Key('Press "P" to print another file or to exit to OS: ',STATLINE) if (#104=='E'+'S'*256) { Exit() } //Back to OS on [ESCAPE] (e.g. ) if ((#104&95)=='P') { Break } //Break out if "p" or "P" Alert() } Get_Input(103,"Enter name of file to print: ",STATLINE+NOCR) if (File_Exist(@103)==0) { Get_Key("File does not exist. Press any key to continue ") Goto PROMPT } File_Close(NOMSG) //Close old file File_Open(@103) //Open new file Goto AGAIN //Start over