bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-indent] Patch for handling comments


From: Roger Flores
Subject: [Bug-indent] Patch for handling comments
Date: Fri, 23 Jan 2004 21:47:41 -0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5b) Gecko/20030723 Thunderbird/0.1


Hello. I've made a number of changes for comment handling. I've used them for a while and am happy with them, so it's time to pass them on. A brief summary of changes are:

- Added limited support of Splint, PC-Lint, and Doxygen. Indent used to force a space after a comment start, breaking these..

- Add new commands to change comments to only C, only C++ and mix modes (C++ for single line comments and C for block comments). The commands are -comc, -comcpp -commix, and the default -com to not change comments. The option -comc is great to keep C code using only C comments. And -comcpp or -commix are great when migrating code to C++!

- List items are now recognized as starting a new line instead of getting word wrapped. The pattern ^[a-z]*: also starts a new line.

- Even when -fc1 is on, first column comments within functions are no longer formatted. This keeps commented out code from being word wrapped. Of course using a #if 0 ... #endif equivalent is preferable but...

- Some comments have "lines" in them. A line is essentially a very repeated single character sequence intended to stretch across the screen. These are now stretched or shrunk to the right margin. These differ from block comments by expecting a space after the comment start.

The patch to indent 2.2.9 is attached. I'm appending some examples too. Comments and bug reports are welcome.


-Roger Flores



First, here's some source:

/* first comment. */
/* second  comment. */


/*

This is a list of items.

 1. The first one.
 2. The second one.
       - another one
 4) the fourth one.
 */

/*! \fn int open(const char *pathname,int flags)
   \brief Opens a file descriptor.

   \param pathname The name of the descriptor.
   \param flags Opening flags.
*/

/*@ NULL @*/
/*lint OK */

static void

  record_setName (/address@hidden@*/ record r, /address@hidden@*/ char *name)

  /address@hidden r->address@hidden/

{

 r->name = name;

}



//!< some comments

// Random number settings

/* --------------------------------------------------------------------
       UNIT ADJACENT
  Purpose: Are there any units next to the position x,y?
  Description: This simply looks in all the squares around x, y.
------------------------------------------------------------------------- */






Here is some sample output, first from C++ conversions.  Both -bcp
and -sc are on, because they're were more challenging to get working.
The output is as expected when they're off.

//
// first comment.
//

//
// second comment.
//

//
// This is a list of items.
//
// 1. The first one.
// 2. The second one.
// - another one
// 4) the fourth one.
//

//!
// \fn int open(const char *pathname,int flags)
// \brief Opens a file descriptor.
//
// \param pathname The name of the descriptor.
// \param flags Opening flags.
//

/*@ NULL @*/
//lint OK

static void
record_setName( /address@hidden@*/ record r,   /address@hidden@*/
  char *name)
  /address@hidden r->address@hidden/
{

  r->name = name;

}



//!<
// some comments
//

//
// Random number settings
//


//
// -------------------------------------------------------------------------
// UNIT ADJACENT
//
// Purpose: Are there any units next to the position x,y?
//
// Description: This simply looks in all the squares around x, y.
// -------------------------------------------------------------------------
//



Here's the output of C comments.

/*
* first comment.
*/
/*
* second comment.
*/


/*
* This is a list of items.
*
* 1. The first one.
* 2. The second one.
* - another one
* 4) the fourth one.
*/

/*!
* \fn int open(const char *pathname,int flags)
* \brief Opens a file descriptor.
*
* \param pathname The name of the descriptor.
* \param flags Opening flags.
*/

/*@ NULL @*/
/*lint OK */

static void
record_setName( /address@hidden@*/ record r,   /address@hidden@*/
  char *name)
  /address@hidden r->address@hidden/
{

  r->name = name;

}



/*!<
* some comments
*/

/*
* Random number settings
*/


/*
* -------------------------------------------------------------------------
* UNIT ADJACENT
*
* Purpose: Are there any units next to the position x,y?
*
* Description: This simply looks in all the squares around x, y.
* -------------------------------------------------------------------------
*/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]