// PRINT.VDM -- Basic print formatting macro. // // Originally by: Theodore Green, Greenview Data, Inc. // Last change: 03/16/99 // // Modified by Christian Ziemski 02/07/2000 (Indention for wrapped lines) // (Ruler dependent on printer right margin) // // 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. // ////////////////// #116=1 // Set to "1" to add line numbers #117=1 // Set to "1" to add file offset; or "HEX" to print in hex // CZ begin #118=1 // 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 // CZ end #121=0 // Set to "1" to print full pathname on separate line // Prints page #, date and time on next line ////////////////// // CZ begin Num_Push(97,99) // save used normal registers Out_Reg(104) // get right print margin (how easier??) .Config(P_RIGHT_MARG) Out_Reg(CLEAR) #98=Buf_Num Buf_Switch(34) Buf_Empty(OK) Reg_Ins(104,BEGIN) #99=Num_Eval() Buf_Quit(OK) Buf_Switch(#98) #98=#116*7 + #117*11 + (#116 && #117) // get indention through line number and position #97=0 if(#99>0){ // calculate print width if(#99>=#98){ #97=#99-#98 } } if(#118){ #118=#97 // calculate ruler length if(#118==0){ #118=80 } } // CZ end // :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 Date(NOMSG+NOCR) //Print the date Message(" ") //And a space Time(NOMSG) //Print the time } else { Name_Write(NOMSG+NOCR) //Print filename Tab_Out(30) //Tab-out to column 30 Date(NOCR) //Print the date Tab_Out(60) //Tab-out to column 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 (#118) { //If ruler desired... // CZ begin Type_Char(45,COUNT,#116*7 + #117*11 + (#116 && #117)) // or so: // if (#116) { Message(" ") } // if (#117) { Message(" ") } // if (#116 && #117) { Message(" ") } // CZ end #120=#118/10 Repeat(#120) { Message("123456789+") } // CZ begin for(#120=1;#120<=(#118-#118/10*10);#120++){ Num_Type(#120,LEFT+NOCR) } // CZ end } Type_Newline(1) //Start a new line Repeat(ALL) { //Print loop for one page // Print until Printer_Line past bottom of page. // Account for 2 blank lines at bottom, if (Printer_Line > Printer_LPP-2) { //If past bottom of page... 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) } } // CZ begin if(#116||#117){ // indention required Out_Reg(104) Type(1) // Print one text line, file buffering if needed Out_Reg(Clear) // but no longer to printer, but into TReg.99 #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 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 } // CZ end Line(1,NOERR) //Advance by 1 line } //End of loop for one page if (#118) { //If ruler desired... // CZ begin Type_Char(45,COUNT,#116*7 + #117*11 + (#116 && #117)) // or so: // if (#116) { Message(" ") } // if (#117) { Message(" ") } // if (#116 && #117) { Message(" ") } // CZ end #120=#118/10 Repeat(#120) { Message("123456789+") } // CZ begin for(#120=1;#120<=(#118-#118/10*10);#120++){ Num_Type(#120,LEFT+NOCR) } // CZ end } 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: // CZ begin Num_Pop(97,99) // CZ end 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