![]() |
|
ADSP 21xx
Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now? Please make a donation to help with maintenance. |
Objective Real-Time Software on the ADSP21XXPretty Printers.1. IntroductionA pretty printer is a source code formatting utility and as such is a major time saver. Most corporations have elaborate coding standards which can be very difficult to adhere to, especially if your favourite editor doesn't support some of the more esoteric block formatting methods. Fear no more. Now you can hack with (almost) wild abandon in your own style and use the pretty printer to reformat the text to the satisfaction of the SW QA freaks. Any programmer that spent hours (and who hasn't?) alligning comments in nice columns, will appreciate the power of these programs to do away with this senseless drudgery. 2. What it doesBoth what it does and what it doesn't are equally important. Firstly, we have two separate pretty printers. One for C and the other for Assembler. The C formatter is the well known(?) indent.exe, which came to life about 25 years ago in a moment of utter despair and frustration. This program is public domain and has a lot of switches to satisfy the most weird and wonderful coding styles. The Assembler formatter is my own little hack called pretty.exe, which came into this world recently in a moment of utter despair and frustration... These pretty printers will NOT change the code syntax. They will NOT fix your coding errors, although they may identify some errors, especially accute attacks of bracketitice. They will warn you about errors, but won't try to fix them. They will NOT delete your original files. The originals are preserved with the .BAK extention. Indent will parse the C language and will intelligently indent code blocks, add/remove white space between tokens, reformat function argument lists and line up inline comments. Everything in this program is adjustable to satisfy the most officious SW QA officials. Indent will happily convert block structures from K&R style to Pascal style etc. Pretty will parse the Assembler code and will line up opcodes, add/remove white space between tokens and line up inline comments. Nothing in this program is adjustable. If you use it, your code will look exactly like mine. This is not really a drawback, since the structure of assembler code is very simple indeed, so there isn't much scope for weird formats. Both programs will leave text inside comments alone and all comments that are alligned against the left margin will stay there and will not be indented, which is usually the intention of a programmer. For instance blocks at the file header will not be moved if they are against the left margin. 3. ExamplesIndent will take some garbage code that looks like this: /*
* procedure do something
*/
void proc(int one,int two ){
int var1;
int var2 ;
if(one == two){ /* do something */
var1 = one; /* do something else */
}
}
and turn it into this: /*
* procedure do something
*/
void proc ( int one, int two )
{
int var1;
int var2;
if ( one == two )
{ /* do something */
var1 = one; /* do something else */
}
}
Pretty will take some garbage code that looks like this: /*
* Procedure do something
*/
proc:
ar=1 ; /* init */
ay0= dm(variable) ;/* get a value */
ar = ar+ay0; /* add */
rts;
and turn it into something like this: /* * Procedure do something */ proc: ar = 1; /* init */ ay0 = dm ( variable ); /* get a value */ ar = ar + ay0; /* add */ rts; which looks a lot better. 4. UsageIndent has an extensive manual. In practice, you define a profile file for your coding standard and after that all you do is type indent filename.c and Bob's your uncle. Indent works on C, C++ and header files. Pretty does not have a manual. In practice, you simply type pretty filename and Bob's your uncle. Pretty works ONLY on .dsp files and the .dsp extention is assumed, don't type it. As a final note: Pretty will remove tabs from the source and perform its magic using spaces, but it will leave tabs in comment blocks. It is best not to use tabs in your source files. The best way to see what these programs do and how they can save you from Karpal Tunnel Syndrome, is to try them. Most people think they are a gift from the gods! Have Fun! |
|
Copyright © 1996-2008, Aerospace Software Ltd., GPL. |