I am asking for some homework help. I am not asking for the answer,I just wanted to be pointed in the right direction.
I have a program in C which I am new to. I have to recreate a Unix tool using vi. Its job will be to read input and “neaten” it up. It reads in paragraphs of words and rearranges them such that they fit nicely onto a line of specified width, inserting line breaks as needed. A paragraph is separated from other paragraphs by one or more empty lines than changing the width with -w and changing to right alignment using -r.
Next would be to justify the text using -j so that every line with more than one word extends from the left to the right with max width. I need to apply integer division to calculate the total number of spaces that should have been seen by the time you finish a gap using Kevin Woods Si = i*S/G where S is the total number of spaces needed in the line, G is the number of gaps between words in the line and Si is the number of spaces that should have appeared by the end of the i'th gap. Lastly suppress line spacing from lines entered with more than a double line back into a double line.
The options should be cumulative—I can specify width, alignment, and skipping of blank lines together. The -r and -j flags should not be used together.
first step: metacode
main(arguments)
analyse arguments f.e. with getopt() for correctness and validity
read the original text
break the text into virtual paragraphs (identified by a double LineBreak)
for each paragraph
break it into lines of less than allowed (-w, default 80) characters
for each line that is not the last line of a paragraph
fill with spaces according to your algorithm and command line spezification
print out all lines
second step: coding
this is your task. Please come back, when you have code, that shows us, where you are stuck.
Related
Write a program for word-wrap which should work on any screen size?
Given a sequence of words, and a limit on the number of characters that can be put in one line (line width). Put line breaks in the given sequence such that the lines are printed neatly. Assume that the length of each word is smaller than the line width.
The word processors like MS Word do task of placing line breaks. The idea is to have balanced lines. In other words, not have few lines with lots of extra spaces and some lines with small amount of extra spaces.
I made a .txt file (UTF-8) and put the following text in it:
123
456
789
I then tried to find out the position of the character '4' by using the InStr() function. Surprisingly, the result was 6. I tried with the character '3', and the result was 3. So, there must be two characters in between the 3 and the 4.
I then tried InStr(TextBox1.Text, Chr(13)) and the result was 4.
Ok. The "New Line" has a character located in the 4th position. If so, then what is 5th character in there?
The actual character(s) used for new-line are different from one platform to the next. Some systems use character 13 to mean a new-line, some use 10, and some, like Windows, use both.
Technically, character 13 is supposed to mean a carriage return (return the print head of the printer to the left side of the page), that's why it's often referred to as CR. Remember, in the early days of computing, printers were used as terminals rather than video screens. So, the closest equivalent of CR on a video terminal is for the cursor to return to the beginning of the current line, but not advance to the next line.
Character 10 means line-feed (LF), which means to advance (i.e. feed) the paper by one line so that the print head is ready to print on the next line. The closest equivalent to a line-feed on a video terminal is to move the cursor down to the next line, but keep it at the same x-position.
So, with those two-things in mind, if you wanted to begin typing at the beginning of the next line, you would need to do both things. You need to advance to the next line on the page AND return to the beginning of the line, hence CRLF, two characters.
Presumably, some system designers thought it was too wasteful to use two characters for each new-line, when the added nuance was rarely needed for computers with video displays, so they opted to only use either CR or LF. Since the correct encoding to use changes from one platform to another, it's best to use Environment.NewLine in .NET to get whichever is appropriate for the current system.
Consider, for example, when you run this console app on windows:
Public Sub Main()
Console.Write("123" & vbCr)
Console.Write("4" & vbCr)
End Sub
The output is:
423
The carriage-return only caused the cursor to go back to the beginning of the line. It didn't cause it to move down to the next line, so the 4, when it's printed, overwrites the 1.
I am stuck.
At my organization, we need to check if line numbers are active for a given paragraph. We are attempting to do this but are running into an issue with suppressed line numbers.
We have tried:
Selection.Information(wdFirstCharacterLineNumber)
and
Paragraph.Range.PageSetup.LineNumbers.Active = True
However, the paragraph(s) we are trying to avoid have suppressed line numbers. We are trying to determine whether or not the current paragraph has line numbers.
If line numbers are suppressed LineNumbers.Active returns True for the current paragraph. In addition, if line numbers are suppressed then wdFirstCharacterLineNumber returns 1 for the first paragraph even though it is obviously not 1 as I see 1 in a lower paragraph.
I have not found a function that returns a bool or an integer if line numbers are suppressed for a given paragraph.
I welcome any suggestions. Thank you.
Line numbers are valid for the entire document, which is why what you've tried is returning the information it is.
Line number suppression is direct formatting applied to individual paragraphs, so you need to query the paragraph properties. For example:
If Selection.Paragraphs(1).NoLineNumber Then
'True (-1) means the line numbers are suppressed
Else
'Flase (0) means the line numbers are visible
End If
I have a Multi Line Label and I want it to truncate only the last line tail. In the Attribute Inspector I set the options like the screenshot:
But it truncates always the first line.
This topic is a duplicate of this:
How to make a Multi-line (2 lines) label truncate the last line (OS X)
But I have had to open another one, because I don't have enough reputation to comment other people's topic.
Thanks for the replies!
Change "Layout" to Wraps, which will change "Line Break" to Word Wrap, too. So long as "Truncates Last Visible Line" remains checked, you should get the result you want.
In other words, a Multi-Line Label just as it's dragged out from the Object library, tweaked by checking "Truncates Last Visible Line", does what you want.
I would like to develop a selection-tool for Screen which ignores the leading spaces and numbers in selection.
Problems
What is the code which affects selection-tool C-a Esc in Screen?
To make an algorithm which ignores the linenumbers and the space at the beginning from the selection:
alt text http://files.getdropbox.com/u/175564/%20selection-less.png
The following Perl-regex seems to match the beginning of the line
{5}[1-9]{1-4} {8} # not tested
The selection tool apparently works by concatenating an increase in selection to the current selection. For instance, one line is selected. I select another one: a new line is added to the selection queue. The reverse is true also for a decrease in selection.
I want to put the Perl regex on when the selection obverses \n such that the ignorance of the line is considered.
I think you want to select columns. That'd be much easier than a regex.
From the screen manpage:
c or C to set the left or right margin respectively. If no
repeat count is given, both default to the current
cursor position.
Example: Try this on a rather full text screen: "C-a [
M 20 l SPACE c 10 l 5 j C SPACE".
This moves one to the middle line of the screen, moves
in 20 columns left, marks the beginning of the paste
buffer, sets the left column, moves 5 columns down, sets
the right column, and then marks the end of the paste
buffer. Now try:
"C-a [ M 20 l SPACE 10 l 5 j SPACE"
and notice the difference in the amount of text copied.
So, in your screenshot, press C-a [, move the cursor to the beginning of your text, press SPACE and then press c. Move to the end of your selection and then press SPACE again. Now you have the text you want.
Hope this wasn't too much info. You tagged it with beginner so I wasn't sure if you were a perl or screen beginner.