473,848 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: reformat to tool/editor-compliant C style?

On 4 Jul, 15:26, Hallvard B Furuseth <h.b.furus...@u sit.uio.nowrote :
I'd like to reformat an open source package (OpenLDAP) to a new C style.
8M code, 0.3M lines. With some currently hopeless formatting rules like
tab-width=4.
what's wrong with that?!

I'm sure that made sense once to save disk space for the
source code, or something:-(
wouldn't replacing spaces with tabs do that? Were disks ever
*that* small? I've worked on old mini-computers and even
then we didn't try to save space at the *source* level.
The project's normal rule is "don't
reformat unnecessarily" since it makes source control merge/diff
difficult.
use a decent configuration control system and make sure
you don't mix source code changes with reformats. Clearly label
the reformat versions.

can't help you with indent

<snip>

--
Nick Keighley
Jul 4 '08
18 2870
Mark McIntyre wrote:
>
>I should have clarified: The code was _originally_ written with
tab width 4. But by now it's sprinkled with quite a bit written
with tab widht 8. Open-source project, several authors... So
it gets wrong either way.

That doesn't make sense to me. A Tab is a tab - your editor should
convert 0x09 into whatever tabspace you've defined in your editor.

Presumably you mean that some moron has tab-to-spaced your code
twice, once at 4s/t and once at 8s/t.

In which case why not just run it through indent, setting
appropriate tabs (not spaces)?
Your software seems to be absorbing the message attributions.
Please fix.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Jul 6 '08 #11
Mark McIntyre writes:
>I should have clarified: The code was _originally_ written with tab
width 4. But by now it's sprinkled with quite a bit written with tab
widht 8. Open-source project, several authors... So it gets wrong
either way.

That doesn't make sense to me. A Tab is a tab - your editor should
convert 0x09 into whatever tabspace you've defined in your editor.
Yes, and either way existing code gets displayed misaligned.
Presumably you mean that some moron has tab-to-spaced your code twice,
once at 4s/t and once at 8s/t.
Maybe some places, but mostly "some moron" has written code which looks
fine with tab-width 8 but not 4. Maybe because it wasn't documented
anywhere that the code was written with tab-width 4.

If someone writes this with tab-width = indentation = 4, it gets aligned
fine:
int foo; /* ... */
struct Bar bar[256]; /* ... */
And if someone else writes this with tab-width = indentation = 8, it
gets aligned fine:
int baz; /* ... */
struct Bar quux[256]; /* ... */
but when you have both variants mixed up in the code base, there is no
tab-width which will align all of the code fine. With tab-width 8, the
first example looks like
int foo; /* ... */
struct Bar bar[256]; /* ... */
With tab-width 4, the 2nd example looks like
int baz; /* ... */
struct Bar quux[256]; /* ... */

Also, of course, occasional lines are indented with tabs+spaces
(tab-width 8, indentation 4).
In which case why not just run it through indent, setting appropriate
tabs (not spaces)?
First, I don't know how other people _write_ code, in particular with
non-Emacs. Thus the question of what kind of style is easy to produce
with other editors.

Second, because indent isn't smart enough. With macro magic, multiline
macros, too creative formatting and macros etc. So I'll have to walk
through the result and clean up. Like this piece of formatting which
is just semantically wrong:

/* try foo */
if (foo) {
handle foo;

/* otherwise try bar */
} else if (bar) {
handle bar;

/* oh dear */
} else {
error();
}

Also indent doesn't really understand C, so I suppose it could make
semantic changes. Not sure that's worth worrying about though.
Probably more likely that I'd make a typo when cleaning up.

--
Hallvard
Jul 6 '08 #12
[Argh, forgot to untabify an example. Superseding article...]

Mark McIntyre writes:
>I should have clarified: The code was _originally_ written with tab
width 4. But by now it's sprinkled with quite a bit written with tab
widht 8. Open-source project, several authors... So it gets wrong
either way.

That doesn't make sense to me. A Tab is a tab - your editor should
convert 0x09 into whatever tabspace you've defined in your editor.
Yes, and either way existing code gets displayed misaligned.
Presumably you mean that some moron has tab-to-spaced your code twice,
once at 4s/t and once at 8s/t.
Maybe some places, but mostly "some moron" has written code which looks
fine with tab-width 8 but not 4. Maybe because it wasn't documented
anywhere that the code was written with tab-width 4.

If someone writes this with tab-width = indentation = 4, it gets aligned
fine:
int foo; /* ... */
struct Bar bar[256]; /* ... */
And if someone else writes this with tab-width = indentation = 8, it
gets aligned fine:
int baz; /* ... */
struct Bar quux[256]; /* ... */
but when you have both variants mixed up in the code base, there is no
tab-width which will align all of the code fine. With tab-width 8, the
first example looks like
int foo; /* ... */
struct Bar bar[256]; /* ... */
With tab-width 4, the 2nd example looks like
int baz; /* ... */
struct Bar quux[256]; /* ... */

Also, of course, occasional lines are indented with tabs+spaces
(tab-width 8, indentation 4).
In which case why not just run it through indent, setting appropriate
tabs (not spaces)?
First, I don't know how other people _write_ code, in particular with
non-Emacs. Thus the question of what kind of style is easy to produce
with other editors.

Second, because indent isn't smart enough. With macro magic, multiline
macros, too creative formatting and macros etc. So I'll have to walk
through the result and clean up. Like this piece of formatting which
is just semantically wrong:

/* try foo */
if (foo) {
handle foo;

/* otherwise try bar */
} else if (bar) {
handle bar;

/* oh dear */
} else {
error();
}

Also indent doesn't really understand C, so I suppose it could make
semantic changes. Not sure that's worth worrying about though.
Probably more likely that I'd make a typo when cleaning up.

--
Hallvard
Jul 6 '08 #13
On 6 Jul, 17:52, Hallvard B Furuseth <h.b.furus...@u sit.uio.nowrote :
Mark McIntyre writes:
I should have clarified: *The code was _originally_ written with tab
width 4. *But by now it's sprinkled with quite a bit written with tab
widht 8. *Open-source project, several authors... *So it gets wrong
either way.
That doesn't make sense to me. A Tab is a tab - your editor should
convert 0x09 into whatever tabspace you've defined in your editor.

Yes, and either way existing code gets displayed misaligned.
Presumably you mean that some moron has tab-to-spaced your code twice,
once at 4s/t and once at 8s/t.

Maybe some places, but mostly "some moron" has written code which looks
fine with tab-width 8 but not 4. *Maybe because it wasn't documented
anywhere that the code was written with tab-width 4.

If someone writes this with tab-width = indentation = 4, it gets aligned
fine:
* * * * int * * * * * * * * * * foo; * * * * * * * * * */* ... */
* * * * struct Bar * * *bar[256]; * * * * * * * /* ... */
And if someone else writes this with tab-width = indentation = 8, it
gets aligned fine:
* * * * int * * * * * * baz; * * * * * */* ... */
* * * * struct Bar * * *quux[256]; * * */* ... */
but when you have both variants mixed up in the code base, there is no
tab-width which will align all of the code fine. *With tab-width 8, the
first example looks like
* * * * int * * * * * * * * * * foo; * * * * * * * * * */* ... */
* * * * struct Bar * * *bar[256]; * * * * * * * /* ... */
I think I could live with that...
With tab-width 4, the 2nd example looks like
* * * * int * * * * * * baz; * * * * * */* ... */
* * * * struct Bar * * *quux[256]; * * */* ... */

Also, of course, occasional lines are indented with tabs+spaces
(tab-width 8, indentation 4).
In which case why not just run it through indent, setting appropriate
tabs (not spaces)?
no. *remove* all the tabs. Its the tabs that cause the problem.

First, I don't know how other people _write_ code, in particular with
non-Emacs. *Thus the question of what kind of style is easy to produce
with other editors.
Does emacs format your code that much? The editor I use fiddles
with the indentation a bit but otherwise leaves things alone
(if it tried to do anything else the feature would be rapidly
disabled- or the editoe dumped).

Second, because indent isn't smart enough. *With macro magic, multiline
macros, too creative formatting and macros etc. *So I'll have to walk
through the result and clean up.
I havn't used indent for a while but generally I thought it was pretty
good.
It tended to messs up some of my comment blocks.

>*Like this piece of formatting which
is just semantically wrong:
*semantically* wrong? Why? I hate K&R style { on the same
line as the code and comments outside the block. But the semantics
seem
plain enough.

* * * * /* try foo */
* * * * if (foo) {
* * * * * * * * handle foo;

* * * * /* otherwise try bar */
* * * * } else if (bar) {
* * * * * * * * handle bar;

* * * * /* oh dear */
* * * * } else {
* * * * * * * * error();
* * * * }
with my layout this would look like this.

if (foo)
{
handle foo;
}
else if (bar)
{
handle bar;
}
else
{
error();
}

or even

if (foo)
handle foo;
else if (bar)
handle bar;
else
error();

is *that* "semantical ly* wrong? I'm beginning to wonder
if one of us has a non-standard meaning for "semantic". ..

Also indent doesn't really understand C,
ok...
so I suppose it could make
semantic changes. *
not by *my* definition of "semantic". I've never seen
indent screw up a correct peoce of code. The layout may
be strange but in my experience the code did the same thing
before and after.
Not sure that's worth worrying about though.
it would sure worry me if it was happening!

Probably more likely that I'd make a typo when cleaning up.
yes
--
Nick Keighley

"To every complex problem there is a simple solution... and it is
wrong."
-- Turski

Jul 7 '08 #14
Nick Keighley writes:
>On 6 Jul, 17:52, Hallvard B Furuseth <h.b.furus...@u sit.uio.nowrote :
(...)
>With tab-width 8, the
first example looks like
* * * * int * * * * * * * * * * foo; * * * * * * * * * */* ... */
* * * * struct Bar * * *bar[256]; * * * * * * * /* ... */

I think I could live with that...
Well, two lines are hardly a problem. 20 gets a bit more annoying.
>>Mark McIntyre writes:
>>In which case why not just run it through indent, setting appropriate
tabs (not spaces)?

no. *remove* all the tabs. Its the tabs that cause the problem.
Well, that's one option.
If people refrain from re-inserting tabs...
>First, I don't know how other people _write_ code, in particular with
non-Emacs. *Thus the question of what kind of style is easy to produce
with other editors.

Does emacs format your code that much? The editor I use fiddles
with the indentation a bit but otherwise leaves things alone
(if it tried to do anything else the feature would be rapidly
disabled- or the editoe dumped).
Emacs is programmable and very (too?) configurable, there is e.g. a
key binding to re-indent a block of code according to my chosen style.
In C files, the Tab key by default re-indents the line. It can be
configured to not do that, or to only do it when there is only
whitespace to the left of the cursor. Or I could write a function
which inserts spaces following non-tab characters but tab otherwise.
There is a key which inserts /* */ at the configured comment column
or moves an existing comment to that column. Etc.

I've hardly used other editors for C files, so I don't know how much
help they give and what kind of styles are natural to produce with
those. (E.g. if "indent with tab, align to a configured comment column
with spaces" is easy.)
>>*Like this piece of formatting which is just semantically wrong:

*semantically* wrong? Why? I hate K&R style { on the same line as the
code and comments outside the block. But the semantics seem plain
enough.
I meant the comment for one if-test is inside the previous {}, so there
little reason to expect any program to be able to indent it right.
Indentation gives (editing the quoted text a bit):

/* try foo */
if (foo) {
handle foo;

/* otherwise try bar */ <<< whoops <<<
} else if (bar) {
handle bar;
(...)

Yet it would have been so easy to write it "indent-friendly":

/* try foo */
if (foo) {
handle foo;
}

/* otherwise try bar */
else if (bar) {
handle bar;
(...)
>
>Also indent doesn't really understand C,

ok...
>so I suppose it could make semantic changes. *

not by *my* definition of "semantic". I've never seen
indent screw up a correct peoce of code. The layout may
be strange but in my experience the code did the same thing
before and after.
I've seen old documentation that warned that it could happen.
Getting confused and inserting/removing whitespace in strings or macro
arguments, or something. However I expect the keyword here is "old".
>Probably more likely that I'd make a typo when cleaning up.

yes
--
Hallvard
Jul 7 '08 #15
Hallvard B Furuseth wrote:
[Argh, forgot to untabify an example. Superseding article...]
its ok, I realised what you meant and in fact it worked on my display.
Also indent doesn't really understand C, so I suppose it could make
semantic changes.
I've /never/ heard of it doing that. It also understands C fine, afaik.

--
Mark McIntyre

CLC FAQ <http://c-faq.com/>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >
Jul 7 '08 #16
Johannes Bauer wrote:
Hallvard B Furuseth schrieb:
>Who knows. If the point was not to save space, I have no idea at all
what the point was.

The point of using tabs is that everyone can easily convert to something
convenient. I find a value of 4 spaces perfect, some prefer 2, some
prefer 8. I've also seen 3.

You suggest that you switch to 8 spaces (i.e. no tabs) which seems to me
like a really not that good idea. After all everyone should be able to
display it the way he/she wants - not the way the programmer liked it.
Code indented by spaces is an annoying pest, IMHO.
I agree wholeheartedly. It is more flexible to use logical indentation
steps (tabs). Moreover, tabs are easier to edit than sequences of spaces
when you do not rely on automatic indentation. To make editing with a
simple editor easier I also never insert newlines in comment paragraphs
but use line wrapping instead.
August
Jul 8 '08 #17
August Karlstrom wrote:
>
.... snip ...
>
I agree wholeheartedly. It is more flexible to use logical indentation
steps (tabs). Moreover, tabs are easier to edit than sequences of spaces
when you do not rely on automatic indentation. To make editing with a
simple editor easier I also never insert newlines in comment paragraphs
but use line wrapping instead.
Ugh.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Jul 8 '08 #18
August Karlstrom <fu********@com hem.sewrites:
Johannes Bauer wrote:
>Hallvard B Furuseth schrieb:
>>Who knows. If the point was not to save space, I have no idea at all
what the point was.

The point of using tabs is that everyone can easily convert to
something convenient. I find a value of 4 spaces perfect, some
prefer 2, some prefer 8. I've also seen 3.

You suggest that you switch to 8 spaces (i.e. no tabs) which seems
to me like a really not that good idea. After all everyone should be
able to display it the way he/she wants - not the way the programmer
liked it. Code indented by spaces is an annoying pest, IMHO.

I agree wholeheartedly. It is more flexible to use logical indentation
steps (tabs). Moreover, tabs are easier to edit than sequences of
spaces when you do not rely on automatic indentation. To make editing
with a simple editor easier I also never insert newlines in comment
paragraphs but use line wrapping instead.
August
Absolute and total nonsense. This might have been true when working in
the stone age. No decent editor worth its salt cant not "mimic" tabs
indenting or outdenting using spaces.
Jul 8 '08 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2237
by: Paul Kooistra | last post by:
I need a tool to browse text files with a size of 10-20 Mb. These files have a fixed record length of 800 bytes (CR/LF), and containt records used to create printed pages by an external company. Each line (record) contains an 2-character identifier, like 'A0' or 'C1'. The identifier identifies the record format for the line, thereby allowing different record formats to be used in a textfile. For example: An A0 record may consist of:
3
2164
by: Just Curious | last post by:
Hello, I am doing some XSLT tranformations. I have a pretty complicated XML document with high level of nesting. I am looking for a tool that gives me the "hierarchial path" to the element I select for example if in the xml below - I select <City>XY</City> - I want to get "Address/Address/City" <Addresses> <Address>
11
2507
by: Shiperton Henethe | last post by:
Dreamweaver 4 Hi Can anyone recommend a decent utility for compressing HTML that is safe - i.e. that *definitely* doesn't mess with the appearance in any browsers. I run a growing website whose pages are inexorably getting too "heavy".
14
6912
by: Akseli Mäki | last post by:
Hi, Hopefully this is not too much offtopic. I'm working on a FAQ. I want to make two versions of it, plain text and HTML. I'm looking for a tool that will make a plain text doc out of the HTML doc. The HTML version doesn't have anything fancy, just internal links. So the tool must be able to delete internal links and anchors from the HTML version, but leave external links in simplified form. That is, the HTML version would say <a...
3
1573
by: Xiaopeng Xiong | last post by:
If there is any command for formatting all files under a directory, that would be best. But currently, formatting a single file is enough for me. I just can not type TAB at each line. Thanks a lot! -- Xiaopeng Xiong
32
2985
by: Roman | last post by:
Hello group, I'm wondering which authoring tool would be most flexible and useful for large websites using only html, css and javascrip. So far I've tried Dreamweaver MX, but have heard BBEdit is also good. What do you think?
14
2060
by: Rajnish | last post by:
Hi C experts, Please suggest me best c programming language tool, which is like Jbuilder (for java) which suggest all avilable methods etc on typing the object. Best regards, Rajnish
3
1800
by: Tina | last post by:
Does anyone know of an asp.net general purpose table editing tool that will allow users to add modify and delete data? Thanks, T
2
1412
by: BigDave | last post by:
For a previous employer, I did a lot of BizTalk 2004 development, but am no longer doing so, and do not even have BizTalk installed. One of the things I miss is the BizTalk Scheme Editor, and how it displayed elements in a vertical tree. (Visual Studio 2005 Schema Editor and XMLSpy seem to want to display elements in a horizontal tree, and to me, not as elegantly). Does anyone know if the BizTalk Schema Editor can be obtained and used
13
2437
by: dmarrese | last post by:
I am a parent volunteer for a swim team website (makoswim.org) and am looking for a recommendation for a new web authoring tool . While I am technically oriented and have somehave some knowledge of HTML but not a deep techie. I want to give this site an extreme makeover. The tool I've been using has probably outlived it's usefulness (IBM Websphere Home Page Builder - out of support). I need something easy to use. I'd like to add...
0
9892
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9735
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10997
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10718
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10347
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.