473,770 Members | 1,644 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wrap thoughts

Well, I've reached a milestone: Here I have an adequately functional
application I can't use without some preliminary stuff. If I'm going to
assign dynamic memory, I need to know the file length, or undergo some sort
of guess routine. And other things as well. It's now immediately evident
that some non-portable code must be written to make this useful.

What to do?

At the moment, I'm inclined to wrap the 'wrap' code (heh...) in a shell
script which can supply all the parameters handily. Such a script can be
written for any operating system, of course, and that would leave the code
portable in its own right. Another approach would be to do the same with a
GUI routine (I like GTK+), and put all the non-portable code in at that level.

The last choice would be to lard the code with system calls to supply the
added functionality, or so I think.

I guess the point is to keep the portable code separate and intact. It's
easy to provide all the necessary arguments at command line for the script
to address, and that way, the app itself could be used manually if the
required information were at hand. Also, any added functionality to the
code itself could be handled the same way, as CL arguments, and the wrapper
script modified accordingly.

I guess my question here is: What *do* you guys do about this, and given
options, what order of preference thereof is most common?

Thanks for reading!
--
Email is wtallman at olypen dot com
Nov 14 '05 #1
10 1248
"name" <us**@host.doma in> wrote

Well, I've reached a milestone: Here I have an adequately functional
application I can't use without some preliminary stuff. If I'm going to
assign dynamic memory, I need to know the file length, or undergo some sort of guess routine. And other things as well. It's now immediately evident
that some non-portable code must be written to make this useful.

What to do?

Normally you can use "portable enough" code. If you want to know the length
of a file, open it, fseek() to the end, ftell() the location, and add a few
hundred bytes for luck. In strict ANSI terms this can fail, but practically
it is unlikely that your code will ever have to run on a pathological
platform.
Nov 14 '05 #2
On 2004-08-28, Malcolm <ma*****@55bank .freeserve.co.u k> wrote:
"name" <us**@host.doma in> wrote

Well, I've reached a milestone: Here I have an adequately functional
application I can't use without some preliminary stuff. If I'm going to
assign dynamic memory, I need to know the file length, or undergo some

sort
of guess routine. And other things as well. It's now immediately evident
that some non-portable code must be written to make this useful.

What to do?

Normally you can use "portable enough" code. If you want to know the length
of a file, open it, fseek() to the end, ftell() the location, and add a few
hundred bytes for luck. In strict ANSI terms this can fail, but practically
it is unlikely that your code will ever have to run on a pathological
platform.


Aha. I had gathered elsewhere that this actually didn't work, but can't now
remember exactly why. I do recall it wasn't considered portably (I
think...), but you raise an interesting and apparently practical approach.
There is excellent theoretical justification for the general "good enough"
approach, of course; the problem might be in identifying what that turns out
to be in any particular case. Seems to me the real issue is the skill and
knowledge of the programmer. But is it not always thus!

Normally, I wouldn't even raise this issue, and probably would not have
posted here in the first place. I can generally get something to work with
a bit of effort, but that's not what this particular project is about. I
want to understand what I can about programming in general, as seen from the
C programmer's point of view. And so these issues thus become relevant.

So I'll take your recommendation and see what I can make of it. I'll also
be interested in the general range of opinions regarding the "good enough"
approach.

Thanks for your response!
--
Email is wtallman at olypen dot com
Nov 14 '05 #3

On Sat, 28 Aug 2004, Malcolm wrote:

"name" <us**@host.doma in> wrote
Well, I've reached a milestone: Here I have an adequately functional
application I can't use without some preliminary stuff. If I'm going to
assign dynamic memory, I need to know the file length, or undergo some
sort of guess routine. And other things as well. It's now immediately
evident that some non-portable code must be written to make this useful.

What to do?


Normally you can use "portable enough" code. If you want to know the length
of a file, open it, fseek() to the end, ftell() the location, and add a few
hundred bytes for luck. In strict ANSI terms this can fail, but practically
it is unlikely that your code will ever have to run on a pathological
platform.


True enough---sometimes you do really need to write non-portable
or "portable enough" code. But lest the OP get the wrong idea:
His program does /not/ require implementation-defined behavior.
Unless he's changed the specs again, it requires O(k) memory where
k is the number entered at the command line. And that's something
you can get without knowing anything about file lengths.

I'll write the program tonight, and maybe post some more thoughts
then. In the meantime, I encourage the OP to examine 'usenetify',
'usenetify2', and Leor Zolman's 'pf', links to all of which can be
found in the Google Groups archive; search for "usenetify wrapping",
I would think. All three programs were written with portability
in mind, and they all do basically the same thing the OP is trying
to do, albeit with more bells and whistles.

-Arthur
Nov 14 '05 #4
On 2004-08-28, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:

On Sat, 28 Aug 2004, Malcolm wrote:
<snip>
Normally you can use "portable enough" code. If you want to know the length
of a file, open it, fseek() to the end, ftell() the location, and add a few
hundred bytes for luck. In strict ANSI terms this can fail, but practically
it is unlikely that your code will ever have to run on a pathological
platform.


True enough---sometimes you do really need to write non-portable
or "portable enough" code. But lest the OP get the wrong idea:
His program does /not/ require implementation-defined behavior.
Unless he's changed the specs again, it requires O(k) memory where
k is the number entered at the command line. And that's something
you can get without knowing anything about file lengths.


I don't understand the '0(k)' concept. Would that not simply make any
number entered a zero? Clearly, I'm missing something (probably a lot!) here.
I'll write the program tonight, and maybe post some more thoughts
then. In the meantime, I encourage the OP to examine 'usenetify',
'usenetify2', and Leor Zolman's 'pf', links to all of which can be
found in the Google Groups archive; search for "usenetify wrapping",
I would think. All three programs were written with portability
in mind, and they all do basically the same thing the OP is trying
to do, albeit with more bells and whistles.

-Arthur


Wow!!

These, I gather, are what would be required to write the application in
"full generality"? It's immediately obvious that I'm very far behind the
curve here. I had figured that I could keep it really simple and still make
this code useful. I'm not surprised that I was wrong, though. There's
always a lot more that is required from an app than is initially envisioned,
I suspect.

And I'm not surprised that what I trying to do has already been done with a
good deal more... well, a good deal of most everything, I guess! So what I
think I'll do is study these three programs and learn from them. At this
point, I'm not sure that continuing to work on 'wrap' has any merit, except
as a platform for experimentation .

Thanks a lot for sharing, and I appreciate the help, Arthur!
--
Email is wtallman at olypen dot com
Nov 14 '05 #5

On Sun, 29 Aug 2004, name wrote:

On 2004-08-28, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:
Unless he's changed the specs again, it requires O(k) memory where
k is the number entered at the command line. And that's something
you can get without knowing anything about file lengths.
I don't understand the '0(k)' concept. Would that not simply make any
number entered a zero? Clearly, I'm missing something (probably a lot!)
here.


Yup; for one thing, you're missing a computer font that lets you
tell the difference between '0' and 'O'. I suggest Courier, although
ISTR there was a thread in comp.programmin g a month ago with some
"alternativ e" fixed-width font suggestions. :)
Google "Big-O notation", and ask comp.programmin g or comp.theory
if you still don't get it.

In the meantime, I encourage the OP to examine 'usenetify',
'usenetify2', and Leor Zolman's 'pf', links to all of which can be
found in the Google Groups archive; search for "usenetify wrapping",
I would think. All three programs were written with portability
in mind, and they all do basically the same thing the OP is trying
to do, albeit with more bells and whistles.


Wow!!

These, I gather, are what would be required to write the application in
"full generality"? It's immediately obvious that I'm very far behind the
curve here.


Well, no. It depends what you're trying to do. Those three programs
are all specifically targeted at correctly wrapping /C code/ (and/or
C++ code) to Usenet standards, which requires not only detabbing (which
I suggest you try) but also preserving the semantics of C code (which I
suggest you don't try yet). Consider wrapping the line

puts ("places on the table")

For your purposes, it suffices to wrap the line at word breaks, as

puts ("places on
the table")

But Leor and I were trying to preserve the C semantics of the wrapped
text---so it would wrap as one of

puts ("places on\
the table")

puts ("places on"
" the table")

So those programs aren't doing exactly the same thing that you're
trying to do; but they /are/ doing something similar (if more
complicated.) Looking at their basic structure and I/O routines may
help you get a better perspective on your own task.
And I'm not surprised that what I trying to do has already been done with a
good deal more... well, a good deal of most everything, I guess! So what I
think I'll do is study these three programs and learn from them. At this
point, I'm not sure that continuing to work on 'wrap' has any merit, except
as a platform for experimentation .


Well, wasn't that always the case? ;)

-Arthur
hasn't gotten back to coding yet, but will try later tonight
Nov 14 '05 #6
On 2004-08-29, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:

On Sun, 29 Aug 2004, name wrote:

On 2004-08-28, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:
Unless he's changed the specs again, it requires O(k) memory where
k is the number entered at the command line. And that's something
you can get without knowing anything about file lengths.
I don't understand the '0(k)' concept. Would that not simply make any
number entered a zero? Clearly, I'm missing something (probably a lot!)
here.


Yup; for one thing, you're missing a computer font that lets you
tell the difference between '0' and 'O'. I suggest Courier, although
ISTR there was a thread in comp.programmin g a month ago with some
"alternativ e" fixed-width font suggestions. :)
Google "Big-O notation", and ask comp.programmin g or comp.theory
if you still don't get it.


OMG! I clearly got that one completely wrong! Yes, I can see the
difference with the font I use (Courier of some brand or other), and this is
another example of seeing what one expects instead of what is actually there!

Big O notation, eh. Asymptotics and infinites and infinitesmals and such.
And yeah I do remember that it can be useful for assessing algorithms. I'll
have to go back and look at all this; I do remember being fascinated by the
behavior of asymptotes but that was a very long time ago, and one quickly
loses what one does not use.
In the meantime, I encourage the OP to examine 'usenetify',
'usenetify2', and Leor Zolman's 'pf', links to all of which can be
found in the Google Groups archive; search for "usenetify wrapping",
I would think. All three programs were written with portability
in mind, and they all do basically the same thing the OP is trying
to do, albeit with more bells and whistles.


Wow!!

These, I gather, are what would be required to write the application in
"full generality"? It's immediately obvious that I'm very far behind the
curve here.


Well, no. It depends what you're trying to do. Those three programs
are all specifically targeted at correctly wrapping /C code/ (and/or
C++ code) to Usenet standards, which requires not only detabbing (which
I suggest you try) but also preserving the semantics of C code (which I
suggest you don't try yet). Consider wrapping the line

puts ("places on the table")

For your purposes, it suffices to wrap the line at word breaks, as

puts ("places on
the table")

But Leor and I were trying to preserve the C semantics of the wrapped
text---so it would wrap as one of

puts ("places on\
the table")

puts ("places on"
" the table")

So those programs aren't doing exactly the same thing that you're
trying to do; but they /are/ doing something similar (if more
complicated.) Looking at their basic structure and I/O routines may
help you get a better perspective on your own task.


Aha. Yes, I did get that after a closer look. And yes, this is very much
more complex, of course.

But the basic problem remains: I've not got a clear idea of what this code
should and should not be expected to do, which is a matter of not having
made some design decisions at the beginning. As it stands, the code does
pretty much what I expect it to do with a minimum of fuss. But if I want it
to do large files, there will undoubtedly be other (more) format
considerations that it will need to handle. Etc.

Fact is, I can declare it done as it is, but that's no fun... <grin> So I
guess I should stop and think about these design decisions, and then work
toward implementing them; I fancy that is what professional programmers do,
indeed, what they have to do!

In any case, looking at the code you guys wrote makes it very clear that
having an original purpose that's well defined is a Good Thing, and that in
itself informs my view of your code; it's intended to do specific things
with specific parameters provided. Absent those, one really can't tell
whether the code is appropriate and effective: What, exactly, is it
supposed to DO?!?
And I'm not surprised that what I trying to do has already been done with a
good deal more... well, a good deal of most everything, I guess! So what I
think I'll do is study these three programs and learn from them. At this
point, I'm not sure that continuing to work on 'wrap' has any merit, except
as a platform for experimentation .


Well, wasn't that always the case? ;)


Well, I thought I'd like to see what it would take to create a finished
product. Problem is, as I said, I have to be able to recognize when it
is one, and that takes deciding just what that should be. OTOH, changing
the intent to experimentation is worth considering.
-Arthur
hasn't gotten back to coding yet, but will try later tonight


Okay, I'll keep watch, and thanks again!
--
Email is wtallman at olypen dot com
Nov 14 '05 #7
name <us**@host.doma in> scribbled the following:
On 2004-08-29, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:
On Sun, 29 Aug 2004, name wrote:
On 2004-08-28, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:
Unless he's changed the specs again, it requires O(k) memory where
k is the number entered at the command line. And that's something
you can get without knowing anything about file lengths.

I don't understand the '0(k)' concept. Would that not simply make any
number entered a zero? Clearly, I'm missing something (probably a lot!)
here.
Yup; for one thing, you're missing a computer font that lets you
tell the difference between '0' and 'O'. I suggest Courier, although
ISTR there was a thread in comp.programmin g a month ago with some
"alternativ e" fixed-width font suggestions. :)
Google "Big-O notation", and ask comp.programmin g or comp.theory
if you still don't get it.

OMG! I clearly got that one completely wrong! Yes, I can see the
difference with the font I use (Courier of some brand or other), and this is
another example of seeing what one expects instead of what is actually there! Big O notation, eh. Asymptotics and infinites and infinitesmals and such.
And yeah I do remember that it can be useful for assessing algorithms. I'll
have to go back and look at all this; I do remember being fascinated by the
behavior of asymptotes but that was a very long time ago, and one quickly
loses what one does not use.


Kids these days think "Big O" is a Japanese cartoon series. It felt odd
going to a cartoon collectors' shop and seeing a series with a name I
had seen before but in a different context.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"That's no raisin - it's an ALIEN!"
- Tourist in MTV's Oddities
Nov 14 '05 #8

On Sun, 29 Aug 2004, name wrote:

But the basic problem remains: I've not got a clear idea of what this code
should and should not be expected to do, which is a matter of not having
made some design decisions at the beginning. [...] In any case, looking at the code you guys wrote makes it very clear that
having an original purpose that's well defined is a Good Thing, and that in
itself informs my view of your code; it's intended to do specific things
with specific parameters provided. Absent those, one really can't tell
whether the code is appropriate and effective: What, exactly, is it
supposed to DO?!?


Exactly. Of course, sometimes you can fail to anticipate all of the
corner cases that will come up. And sometimes, especially with tasks
like this line-wrapping project, you have to make decisions that are
based less on "what is right" and more on "what looks right." I found
a couple of those cases and documented them in my 'wrap.c' program
(see below). Consider, for example, wrapping the line

[23456789-123456789-1]
abc def

at a line length of 10 characters. The simplest thing to do is
replace spaces by newlines at positions 11 and 19, which yields
a result that looks like this on the screen:

abc

def

There's a blank line between the two parts of the input line. Is
that really "what looks right" in this case? Or should we try to
insert some ad-hoc code to deal with this special case?: say, don't
print any line if it's composed entirely of blanks.

Unfortunately, no textbook is going to give you the answers to
questions like that. You've just got to figure out what approach
will give you the "nicest-looking" results, and then code it.
Where "nicest-looking" is pretty much subjective, unless you have
the luxury of a whole bunch of beta-testers. :)
Anyway, I did finally code a simple 'wrap' program. It was harder
than I thought at first---lots of opportunities for off-by-one
errors! The finished product is on the web at
http://www.contrib.andrew.cmu.edu/~a...eminate/wrap.c

HTH,
-Arthur
Nov 14 '05 #9
On 2004-08-29, Arthur J. O'Dwyer <aj*@nospam.and rew.cmu.edu> wrote:

On Sun, 29 Aug 2004, name wrote:

But the basic problem remains: I've not got a clear idea of what this code
should and should not be expected to do, which is a matter of not having
made some design decisions at the beginning. [...]
In any case, looking at the code you guys wrote makes it very clear that
having an original purpose that's well defined is a Good Thing, and that in
itself informs my view of your code; it's intended to do specific things
with specific parameters provided. Absent those, one really can't tell
whether the code is appropriate and effective: What, exactly, is it
supposed to DO?!?


Exactly. Of course, sometimes you can fail to anticipate all of the
corner cases that will come up. And sometimes, especially with tasks
like this line-wrapping project, you have to make decisions that are
based less on "what is right" and more on "what looks right." I found
a couple of those cases and documented them in my 'wrap.c' program
(see below). Consider, for example, wrapping the line

[23456789-123456789-1]
abc def

at a line length of 10 characters. The simplest thing to do is
replace spaces by newlines at positions 11 and 19, which yields
a result that looks like this on the screen:

abc

def

There's a blank line between the two parts of the input line. Is
that really "what looks right" in this case? Or should we try to
insert some ad-hoc code to deal with this special case?: say, don't
print any line if it's composed entirely of blanks.


I guess what I get from this is that one really has to be creative in one's
search for the oddball cases. That's probably a matter of experience as
much as anything else. I would not have thought of most of these, and would
have had to figure out what to do with them when I ran across them.

But then, you've already written a program like this, and so you've already
seen many of these exceptions. I shall be satisfied if I can address them
successful when I do run across them... <grin>
Unfortunately, no textbook is going to give you the answers to
questions like that. You've just got to figure out what approach
will give you the "nicest-looking" results, and then code it.
Where "nicest-looking" is pretty much subjective, unless you have
the luxury of a whole bunch of beta-testers. :)
As I suggested to someone else who emphasized the planning as necessary,
sometimes one simply has to tinker a while to discover what it is that one
really does want the app to do. This follows the "Be prepared to throw the
first one away" dicta. Nevertheless, at some point one really does have to
firm up the specifications and simply work to fill them, otherwise it can
never be judged as finished.

Anyway, I did finally code a simple 'wrap' program. It was harder
than I thought at first---lots of opportunities for off-by-one
errors!
Indeed! lol!!!
The finished product is on the web at
http://www.contrib.andrew.cmu.edu/~a...eminate/wrap.c


Ah yes. Got it and will study it as well. Wow, I've gotten a lot of code
to study from several people now! I expect this will take a while now, but
I'll be back... <grin>

And thanks to all others as well as Arthur!
--
Email is wtallman at olypen dot com
Nov 14 '05 #10

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

Similar topics

2
1816
by: cppaddict | last post by:
Hi, I'm writing a windows application in C++. However, much of the application's logic is already written in Java. I'd like to be able to make use of that code from within my C++ code. How can this be accomplished? I'd appreciated any thoughts or good internet reference material on the subject. Thanks, cpp
3
6776
by: Fluffy Convict | last post by:
I am trying to write a script that changes a textarea wrap realtime, basically like you can switch to and from "wordwrap" in Microsofts Notepad. Because of a bug (https://bugzilla.mozilla.org/show_bug.cgi?id=302710), FireFox does not listen to the textarea.wrap = 'soft' command. Because I want the script to be cross-browser compatible, someone suggested to remove and immediately add a node to the DOM, so I now have: ...
8
2173
by: name | last post by:
Back again for more critique... <grin> ------------------------------------------------ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #define MAX 10000
8
53023
by: Mark D. Smith | last post by:
Hi I have googled but not found a solution to wordwrap in a textarea using firefox/netscape. is there a style sheet solution or am i stuck with not being able to force wrapping in a textarea Mark
0
1888
by: GregG | last post by:
Greetings, I have been fighting with the new GridView control, and while figuring out most of it's idiosyncrasies on my own, have stumbled upon a problem I cannot seem to resolve. We have table displayed in a GV control. It allows for editing and selecting, etc. Some of the fields are 60 characters long, but only the first 20 or so are relevant, and all of them have to fit on one line within the row -
2
5796
by: Mark Rae | last post by:
Hi, Is there a bug in the GridView control specifically related to wrapping of header text...? E.g. the following tag <asp:GridView HeaderStyle-Wrap="false" ID=gvListUsers runat=server ... etc .... > does not prevent the header text from wrapping.
3
14588
by: Jason | last post by:
Anyone know how to make the text wrap in a text box of a DetailsView?
0
991
by: glenn | last post by:
Hi folks, I have a DataGrid control and I have all of the columns wrapping their text except for one column which insists on placing the text all in one line without wrapping. All columns in my HTML are the same but obviously something is different. Thanks for any thoughts on this.
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
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
9873
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
8891
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
7420
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
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3578
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2822
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.