473,809 Members | 2,891 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 2863
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
2234
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
2162
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
2503
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
6906
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
1571
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
2982
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
2056
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
1798
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
2434
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
10633
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...
0
10114
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...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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
6880
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
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3860
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.