Page eject when printing source code

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When viewing a C/C++ source file within Atmel Studio you can press CTRL-P to print it.

 

I would like to insert form feeds (page ejects) such that a new print page is started at those points in the code listing.

 

No method I have tried (inserting \f, etc.) has worked.  Every web search I have done turns up the (much more common) case of inserting form feeds in output generated by the program (I know how to do that), not a program listing.

 

Can this be done?  Perhaps a "#" command I'm unaware of? 

 

It needs to be something that the compiler either considers valid (i.e.: a recognized page eject command) or something it considers "White Space" (I tried \f and 0x0C without success) and causes the "print" function to pass through to the printed output as a page eject.

 

Regards,

 

Chuck Hackett

This topic has a solution.
Last Edited: Tue. Aug 28, 2018 - 12:08 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can just embed a formfeed character (ctl-L) anywhere in your source code.    The C compiler will treat it as whitespace.   I would expect any print function to respect it.

It is probably easiest to put it inside a comment.    Then you can copy-paste the comment wherever you like.

 

Personally,   I wrote a command line program to create PostScript / PDF files many years ago.

It gives me nicely paginated output for A4 paper.     I can view / print it via a PDF reader.

 

I avoid the "usual" print from an IDE.

 

YMMV.

 

David.

Last Edited: Mon. Aug 27, 2018 - 01:27 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChuckH wrote:
I tried \f and 0x0C without success

Well \f is just something that the 'C' compiler interprets within string & character constants - so that won't work.

 

How, exactly, did you insert "0x0C" ?

 

If would need to be an actual Form-Feed character - not some sort of 'C' escape sequence.

 

This would (almost?) certainly be an area where the functionality is inherited from standard MS Visual Studio - so try searching there, too ...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
I would expect any print function to respect it

In my experience, that is not something that can be relied upon.

 

frown

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah-ha.   I can not see how to insert a "special character" in Notepad++.

So I inserted a ctl-L into the CodeVision Editor.    Then copy-pasted into Notepad++.     (Where is shows up as a green FF like FF )

 

I am sure that there are more official ways of doing this.

As I said.  You only need to do it once.   Then copy-paste forever.

 

David.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Just in case you need some Green Bar paper for that:  https://www.appleforms.com/8-1-2...

 

indecision  Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

In the dim and distant past a compiler I used to use had the '$eject' directive. Very useful. Put one just above every functions header comment block.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

$PAGE was another directive some of our assemblers used.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Old school, use nroff (groff) after editing the listing to add a line with .bp where you want page breaks!

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:

Just in case you need some Green Bar paper for that:  https://www.appleforms.com/8-1-2...

 

indecision  Jim

 

 

 

Wow, haven't seen "Green Bar" in a looong time ... but I think I have a box from the old days kicking around here somewhere :-)

Last Edited: Tue. Aug 28, 2018 - 04:40 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

None of the suggestions offered helped.  Could not get Atmel Studio (or Programmer's Notepad, or Notepad) to let me put in a ctrl-L. 

 

I was able to get one in by right-clicking the file and selecting "Open With", selecting the binary editor and entering "0C" at the proper location.

 

Atmel Studio displays it as a single blank.  Programmer's Workbench displays it as "FF" with a background.

 

When printing (CTRL-P) to the Microsoft PDF driver it is treated as white space (no new page).  Same operation with Programmer's Notepad prints the "FF"s.  Same operation with Notepad prints an arrow pointing up for each CTRL-L.

 

So, looks like I'm out of luck unless I want to write my own utility or using something like nroff(groff)

 

crying

 

Chuck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChuckH wrote:
When printing (CTRL-P) to the Microsoft PDF driver it is treated as white space (no new page).  Same operation with Programmer's Notepad prints the "FF"s.  Same operation with Notepad prints an arrow pointing up for each CTRL-L.

See #4.

 

As others have noted, many old systems used to have a facility to do this. I guess the thing is that people just don't print code onto paper these days!

I rarely do, and then it's just selections - so pagination isn't an issue.

 

You could load the source text into a word processor, and have it do the printing & pagination ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I often print source code. But I tend to print 2 pages per A4 sheet. Print double sided means 4 x 66 line pages to a sheet of paper.
I am happier reading paper. Especially when there is a problem.
.
You can do anything with a command line program. IDEs tend to obscure control. Legacy MSDOS programs should print listings ok.
I am happy with a PDF file being created. The original text is unchanged i.e. embedded ctrl-L does not affect C compiler.
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

I guess the thing is that people just don't print code onto paper these days!

 

And some of the newer text/code editors (like Sublime) don't even have a print facility.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
Print double sided

I generally don't like code printed double-sided - as it's then hard to cross-reference stuff on the front & back of the sheet!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Aug 28, 2018 - 08:50 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Google just suggested this:

 Visual Studio  Marketplace wrote:
VScodePrint2017 - Print Source Code In Color

 

VScodePrint is a Microsoft® Visual Studio Extension that enables you to print professional style printouts of Visual Studio source code directly from the Visual Studio Editor. The generated output is fully customizable that can be printed or to exported to secure PDF.

"Key Features" include

Quote:

  • Output C#, C++. Basic, HTML, XML,XAML etc and much more source code with syntax highlighted style
  • You can customise page layout

 

I am just passing this on - have not used it myself.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I usually don't print source code either. 

 

In this case the thing I'm printing is actually a source code file that just consists of a bunch of macro invocations that, in turn, generate an EEPROM image that is loaded into an ATMega1284p as configuration data.  We reference this file in the field (the one I have in front of me consists of 1,300 lines).  It is broken into sections where each section applies to a given processor node.

 

//#############################################################################
//	Node 2 - Lenard
//
//			Critical	NonCritical	Statistics
//			Msg Report	Msg Report	Report
//		NodeID, Interval	Interval	Interval
Config_Node( 	2,  	CMRI,		NCMRI,		SRI		);
Common_CAN_Bus_Timing;
//
//-----------------------------------------------------------------------------
//	Define locally connected track inputs
//						Voltage
//						Report
//	    	ID	ADCChannel	Options	Interval
Config_TrackIn(	16007, 	0,	        SwP, 	VRI		);	//	Temp switch point input for Blanton switch
Config_TrackIn(	2001, 	1,		2, 	VRI		);	//	Approach to west Lenard signal (2100)
Config_TrackIn(	2002, 	2,		2, 	VRI		);	//	Lenard to Blanton main
Config_TrackIn(	2003, 	3,		2, 	VRI		);	//	East end of North siding
Config_TrackIn(	2004, 	4,		2, 	VRI		);	//	Approach to east Lenard signal (103)
Config_TrackIn(	2005, 	5,		2, 	VRI		);	//	East end of south leg of wye
Config_TrackIn(	2006, 	6,		2, 	VRI		);	//	South end of east leg of wye
Config_TrackIn(	2007, 	7,		SwP, 	VRI		);	//	Blanton (wye, southeast) switch motor position sense
//
//-----------------------------------------------------------------------------
//	Define the locally connected signal heads
//
//			ID	G_Chan	G_Dim	G_Bright	Y_Chan	Y_Dim	Y_Bright	R_Chan	R_Dim	R_Bright
Config_SignalHead(	2100, 	0,	Dim, 	Brt, 		1,	Dim, 	Brt, 		2, 	Dim, 	Brt 		);	//	West Lenard (toward Pasco)
Config_SignalHead(	103, 	3,	Dim, 	Brt, 		4,	Dim, 	Brt, 		15, 	Dim, 	Brt 		);	//	East Lenard
Config_SignalHead(	2106, 	6,	Dim, 	Brt, 		7,	Dim, 	Brt, 		8, 	Dim, 	Brt 		);	//	Blanton (from Chipco)
Config_SignalHead(	2109, 	9,	Dim, 	Brt, 		10,	Dim, 	Brt, 		11,	Dim, 	Brt 		);	//	Blanton (from San Antonio)
Config_SignalHead(	2112, 	12,	Dim, 	Brt, 		13,	Dim, 	Brt, 		14,	Dim, 	Brt 		);	//	West Lenard (toward Chipco)

//
//
//-----------------------------------------------------------------------------
//	Define Lenard to Macon block
//
//  		BlockID	   Block Tracks
Config_Block(	2,	   4001, 0, 0, 0, 0 );
//
//																		Track
//																Switch		to be		Entry
//			ID	BlockID		Enable-App	Approach	Priority	Destination	Opposing	Hardover	Reserved	Delay
Config_BlockSignal( 	103,  	2,		0,		2004,		1,		20,		4000,		0,		0,		HalloweenDelay	); // East Lenard to Macon
Config_BlockSignal( 	104,	2,		0,		4000,		1,		2003,		2004,		0,		0,		HalloweenDelay	); // West Macon to Lenard
//
Config_Node_End( );
//
//#############################################################################

 

If embedding CTRL-L had worked that would have been fine but it's not worth the effort to run extra programs or jump through hoops. 

 

Looks like I'll just continue to use blank lines and block comments at the start of each node section.

 

Thanks for the comments.

 

Chuck Hackett

Last Edited: Tue. Aug 28, 2018 - 11:30 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ChuckH wrote:
We reference this file in the field

Sounds like what you really need is Doxygen ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

ChuckH wrote:

We reference this file in the field

 

Sounds like what you really need is Doxygen ... ?

 

Now why didn't I think of that!  (see, that's why this list is so great!)

 

Now I have to learn (a little) Doxygen (but I should have already anyway ...)

 

Regards,

 

Chuck Hackett

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What's more. If you use Doxygen you can generate straight to HTML or PDF and save some of the trees ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is that Amy with her PhD thesis ... ?

Image result for amy farrah fowler

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How many times are you going to process the files, and how many files?

 

Although reading the file into a Word Processor will place nice Headers, (file name, page number), it won't format the output, so the pages will break where ever they break.

 

If Doxygen works for you that's great, but I'm not sure what the learning curve will be.

 

It would seem to me that one could write their own text file processor without too much difficulty, if you use some PC languages, (VB, Visual Studio, Python, etc.).

 

Way back, a "few" years ago, I had a need for a formatted hardcopy output for a few PC programs that were several thousand lines long.

The IDE, such as it was back then, didn't provide a list of the subroutines, functions, etc.

I wrote a simple program to read in the file, parse the line, and generate a temporary output file.

As it parsed the lines it generated a table of contents type listing for all of the labels, subroutines, and functions and their page number.

It also wouldn't start a new subroutine with less than X lines left on the page, as it was frustrating to have a section label or a sub start very near the bottom of the page and have the core of the routine on the next page (s).

It would also print the labels, etc., in bold, making them stand out within the listings.

The small amount of time I spent writing that program saved me tons of time while debugging code, and documenting it.

 

JC

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
reading the file into a Word Processor will place nice Headers, (file name, page number)

Good point - although that's not what I was thinking of

 

 it won't format the output, so the pages will break where ever they break.

But it will allow you to specify where the breaks go - which was the original question.

 

You could either do this manually each time you print (ie, each time you load into the WP), or embed some "magic marker" text in the source file - and have a WP macro insert the page breaks at those points.

 

Another advantage of a WP here is that you get a print preview

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is that Amy with her PhD thesis ... ?

;-)

 

Margaret Hamilton, next to a printout of her baby.

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

How many times are you going to process the files, and how many files?

....

JC

 

Maybe 6-8 files for different systems and they get changed whenever a configuration change is made for that system. 

 

These changes usually come in bursts every couple of months so a automated/semi-automated requiring minimal extra file manipulation is best.

 

Yes, I'm perfectly capable of writing a program to do it but I would much rather use an available tool rather than write one even if it requires some learning (especially if it's a tool I should use more anyway) because I have lots of other pressing projects to complete.

 

Regards,

 

Chuck Hackett

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there a source code pretty-printer as a separate app? Handling page breaks, using nice fonts, and doing something intellible with long lines would be a start; ultimately it ought to do customizable smart coloration and font selection.