473,734 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nice way to do help screen output?

To create help output (the response to "myprog --help", for example) I
currently create a big .h file, which includes a single string, such
as:

static char *help_text = "\
myprog: my program\n\
loads and\n\
loads of\n\
painfully manually\n\
formatted and\n\
justified text\n"

There's got to be a better way to do this - any ideas? Ideally, I
would like to write the help as a plain text file. Of course, I don't
want to distribute this file with the program, so it needs some
preprocessing. I'm on Linux.

Cheers

Richard
Jul 22 '05 #1
4 2702
Richard Tierney <no****@nospam. com> scribbled the following
on comp.lang.c:
To create help output (the response to "myprog --help", for example) I
currently create a big .h file, which includes a single string, such
as: static char *help_text = "\
myprog: my program\n\
loads and\n\
loads of\n\
painfully manually\n\
formatted and\n\
justified text\n" There's got to be a better way to do this - any ideas? Ideally, I
would like to write the help as a plain text file. Of course, I don't
want to distribute this file with the program, so it needs some
preprocessing. I'm on Linux.


You're going to have to type the text in manually anyway, so what does
it matter whether it's going in your C source or a text file? If you
can use an external text file in your program, you can use the normal
C stream IO functions to display its contents, which will give you the
benefit of not having to type the \n\ bits after every line.
But since you said you don't want to use an external text file,
writing the text in your source code is really the only option. Or you
could just write a mass of whitespace there and write the text directly
into the compiled object file using a hex editor. This gives you the
rather minuscule benefit of being able to write only one character (the
newline) instead of three for \n\.

--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You will be given the plague."
- Montgomery Burns
Jul 22 '05 #2
Richard Tierney wrote:

To create help output (the response to "myprog --help", for example) I
currently create a big .h file, which includes a single string, such
as:

static char *help_text = "\
myprog: my program\n\
loads and\n\
loads of\n\
painfully manually\n\
formatted and\n\
justified text\n"

There's got to be a better way to do this - any ideas? Ideally, I
would like to write the help as a plain text file.


What is hindering you?

Writing tools is something a programmer is always aware of.
In your case a tool would be simple. Write a program which generates
the header file from a text file:

open help text file for input
open header file for output

output "static char *help_text = \"\\" to header file

as long as a line could be read from the help text file
output that line to the header file
output "\n\\" to the header file

output "\";" to the header file

close header file
close text file

That's your tool.
You edit your plain vanilla help text file. When you are finished
you let the tool generate the header file and use that in the
compilation as usual.

--
Karl Heinz Buchegger
kb******@gascad .at
Jul 22 '05 #3
How much time need you to format the text in your editor?
How much time will it need to create a tool?
How much time you will need to search this tool?

The normal help-screen message should fit into one screen page.
Write the text.
Insert " at the start of each line.
Append \n" at the end of each line.
Use the search-and-replace feature of your favourite editor for this.

char const helpmsg[] =
"this\n"
" is\n"
" the\n"
" easy\n"
" way"
;

std::cout << helpmsg << std::endl;

Done.

-mb
Jul 22 '05 #4

"Richard Tierney" <no****@nospam. com> wrote
To create help output (the response to "myprog --help", for example) I
currently create a big .h file

There's got to be a better way to do this - any ideas? Ideally, I
would like to write the help as a plain text file.

There's no one easy answer. Many C compilers will allow you to embed data
such as strings, images, sound files and so on into the program. However
this means that the listing is no longer portable.
Another way is to write a function that wraps and left-justifies your
string. This is probably the best solution, so long as you have a monospaced
font. With a variable pitched font, the function is still possible to write,
but much more difficult, much less generally useful, and probably more
trouble than it is worth.

The third approach is to write your own utility program to convert a text
file into C source (C data, not executable code). The problem with this is
that the utility program becomes part of you developement environment, may
have to be documented and so on, and the program becomes much more difficult
to maintain.
Jul 22 '05 #5

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

Similar topics

7
4789
by: Alex Hunsley | last post by:
I'm making a web site that does login authentication. It all works fine, but I have a question about 'correctness'... Certain php scripts on the site should only run in the user has logged on. So, the 'private' scripts in question all includes the following php script: <? // has user authenticated? if (! $logged_in) {
31
14333
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? Basically: "Press any key to continue..." I beleive that I am looking for is something along the lines of a....
1
2158
by: dan | last post by:
I need help in figuring out what to do for this program, it is a program that reads book id, unit price, book purchased, book sold, book returned, and city(respectively). It is a control break program that prints a report for each city on a separate screen with a total, then at the end it has a grand total. It prints to the screen and an output file. Input file looks like (the char is the city) 200 1.40 30 13 1 B 201 7.50 13 ...
4
519
by: Richard Tierney | last post by:
To create help output (the response to "myprog --help", for example) I currently create a big .h file, which includes a single string, such as: static char *help_text = "\ myprog: my program\n\ loads and\n\ loads of\n\ painfully manually\n\ formatted and\n\
0
1422
by: Ian Ceicys | last post by:
I’ve been tasked with doing documentation on the project I’ve recently joined. Here’s what I’m looking for in terms of documentation. I want to generate a diagram from a huge .net 1.1 Winforms application that relates every form with the corresponding button/command that invokes that form. In other words I want to output a diagram that traces the flow (workflow is the right term?) of what happens when every single button/command is...
1
6095
by: al2004 | last post by:
Write a program that reads information about youth soccer teams from a file, calculates the average score for each team and prints the averages in a neatly formatted table along with the team name. Please follow the specifications for assignment 3 as described below otherwise points will be taken off. Input from a file Please create an input file named input.txt using a text editor like notepad or the Visual C++ editor and put the following...
0
2688
jeffbroodwar
by: jeffbroodwar | last post by:
Hi, I'm tying to develop a program that uses a radio button wherein if this radio button is clicked, it'll do a loop at screen block to display the select option controls that i have. i used : SELECT-OPTIONS: s_SO FOR vbak-vkorg MODIF ID ONE, s_DC FOR vbak-vtweg MODIF ID ONE. now, when i execute this program. I'm encountering a problem with the output of the select-options. the two text boxes outputed...
4
1814
by: Steve | last post by:
Can someone help me with this code - I'm trying to retrieve updated product information by pulling 3 fields and inserting values into my MYSQL db. In my code below I'm getting the page but I can't get the date inserted into the DB what am I doing wrong. Second Can I suppress output to screen. I'm planning on running this in cron if I'm inserting into db do I have to output to screen This is the method my host company told me to use. they...
0
8946
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...
1
9236
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
9182
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
6735
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
6031
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.