K&R2 Ex 5-11 : What is it asking for?

D

Deniz Bahar

Hi,
My english is not top notch and I am trying to understand what K&R2 Ex
5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed from
chapter 1 and have on hand) to accept a list of tab stops as arguments.
Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root "help").
 
J

Jens.Toerring

Deniz Bahar said:
My english is not top notch and I am trying to understand what K&R2 Ex
5-11 is asking for (pg 118).
It says: Modify the programs entab and detab (which I completed from
chapter 1 and have on hand) to accept a list of tab stops as arguments.
Use the default tab settings if there are no arguments.
I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root "help").

As far as I can tell it means to change the program so that tab
stops (i.e. the places where the cursor ends up when you press
the tab key) aren't always e.g. 4 spaces appart (so that tab
stops are at positions 4, 8, 12, ...) but that you can tell it
that tab stops are e.g. at arbitrary position like 5, 7, 14, 23,
etc. So, when you call the modified program like this
detab 5 7 14 23 25 27 33 39 42

it puts in as many space characters that you end up in column 5 after
the first tab character, in column 7 after the second, in column 14
after the third etc.

If you ever get hold of a mechanical typewriter you will find that
it also has a tab key, but that you have to set "tab stops" at the
positions you want it to stop (it has an extra key for setting and
unsetting them). That was used e.g. for filling in forms and proba-
bly is what tabs where invented for in the first place.

Regards, Jens
 
C

CBFalconer

Deniz said:
My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").

Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>detab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed
If tablist has only one number, then that is the tab interval
If tablist contains multiple numbers, separated by spaces,
then they are assumed to be the tab points. The leftmost
column is numbered 0.
If tablist is a single 0, then tabs are not expanded
Backspaces in a line shut off tab expansion until cr

Any isolated lf's are converted into cr/lf pairs (Unix files)
Omitting the "<infile" causes this help screen
 
D

Deniz Bahar

CBFalconer said:
Deniz said:
My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").

Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>detab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed

Is this an unspoken standard?
If tablist has only one number, then that is the tab interval

If tablist contains multiple numbers, separated by spaces,
then they are assumed to be the tab points. The leftmost
column is numbered 0.

Do programs like notepad, vi also consider the first column 0, instead
of 1?

How many arguments do you expect the user to enter in this mode? What
if he/she only give 2 arguments, but a line of inputs has > 2 tabs? Do
you ignore the rest of the tabs?

Also, do you limit the maximum size of a tabpoint to 80 or some other
value?
If tablist is a single 0, then tabs are not expanded
Backspaces in a line shut off tab expansion until cr
How do you detect backspaces? Aren't backspaces taken care of by
hardware/tty drivers or some other layer of the OS?
Any isolated lf's are converted into cr/lf pairs (Unix files)
Omitting the "<infile" causes this help screen

Isn't a UNIX text file ending with LF and Windows CRLF?


Thank you for your help.
 
D

Deniz Bahar

"help").

As far as I can tell it means to change the program so that tab
stops (i.e. the places where the cursor ends up when you press
the tab key) aren't always e.g. 4 spaces appart (so that tab
stops are at positions 4, 8, 12, ...) but that you can tell it
that tab stops are e.g. at arbitrary position like 5, 7, 14, 23,
etc. So, when you call the modified program like this


it puts in as many space characters that you end up in column 5 after
the first tab character, in column 7 after the second, in column 14
after the third etc.

Thank you for clearing that up. Do you think there should be a limit
on the number of tabpositions given by the user, or the size of the
positions? What if the user gives me 3 positions, but some of his/her
lines has >3 tabs? I am really not sure how to organize the parameters
for input and operation. What type of error checking do you think is
valid here? Posibble checking the each number is larger than the
previous, and is not less than 1 or greater than some max value (like
80)?
If you ever get hold of a mechanical typewriter you will find that
it also has a tab key, but that you have to set "tab stops" at the
positions you want it to stop (it has an extra key for setting and
unsetting them). That was used e.g. for filling in forms and proba-
bly is what tabs where invented for in the first place.

Last time I saw a mechanical typewriter, I was too young to even know
what the thing was :) But I get what you're saying, there are
physical stops in these machines, much like the software stops that
programs like vi/notepad have for the TAB character.
Regards, Jens

Thank you for your help
 
M

Michael Mair

Deniz said:
CBFalconer said:
Deniz said:
My english is not top notch and I am trying to understand what K&R2
Ex 5-11 is asking for (pg 118).

It says: Modify the programs entab and detab (which I completed
from chapter 1 and have on hand) to accept a list of tab stops as
arguments. Use the default tab settings if there are no arguments.

I am having difficulty understanding the question (not asking for
answer to it). Any help would be helpful (thus the common root
"help").

Here is the help screen from my own version, which I have been
using for a while. Maybe it will clarify what is wanted.

[1] c:\c\hshftst>detab
DETAB copyright (c) 1989 by C.B. Falconer. Ver 1.0

usage: DETAB [tablist] <infile >outfile
If tablist is omitted a tab interval of 8 is assumed

Is this an unspoken standard?

<OT>
AFAIK, yes. I could not turn up anything official on this.
However, for many editors, the standard tabstops are at 8.
Do programs like notepad, vi also consider the first column 0, instead
of 1?

<OT>
Usually, editors see the position before the first character as
column 0 and after the first character as column 1.
How many arguments do you expect the user to enter in this mode? What
if he/she only give 2 arguments, but a line of inputs has > 2 tabs? Do
you ignore the rest of the tabs?

Also, do you limit the maximum size of a tabpoint to 80 or some other
value?



How do you detect backspaces? Aren't backspaces taken care of by
hardware/tty drivers or some other layer of the OS?

'\b' is the backspace character. How you get this character
into the input, is your problem and may be not possible on
stdin for your implementation (redirected input from a file
should do, however; if you need a '\b' in your file, there
are always the C file output functions...).
Isn't a UNIX text file ending with LF and Windows CRLF?

If you mean "newline is encoded as ...": yep.
The help is ambiguous here; I understand "(Unix files)"
as "this happens for Unix files". This is only an issue if you
consider files with different encodings which also means that you
have to access the files in binary mode.


Cheers
Michael
 
J

Jens.Toerring

Deniz Bahar said:
Thank you for clearing that up. Do you think there should be a limit
on the number of tabpositions given by the user, or the size of the
positions? What if the user gives me 3 positions, but some of his/her
lines has >3 tabs? I am really not sure how to organize the parameters
for input and operation. What type of error checking do you think is
valid here? Posibble checking the each number is larger than the
previous, and is not less than 1 or greater than some max value (like
80)?

Difficult to say since K&R doesn't say. Putting in unnecessary limits
(like a maximum number of tab positions) doesn't sound like a very
good idea to me. About the rest you probably will have to figure out
something that seems to be reasonable (like if there are more tab
characters in a line than the user supplied tab positions reverting to
a default of e.g. tab stops at multiples of 8). Checking that the
tab stop positions the user defines are increasing sounds reasonable,
but you could also assume that too small a value is meant as an in-
crement instead of an absolute position. Of course, all values need
to be larger than 0. If you want a restriction of 80 chars max as tab
stop positions it's up to you, but I wouldn't know why you would want
to do that.
Regards, Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top