LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Generating list of options of a command using script (https://www.linuxquestions.org/questions/programming-9/generating-list-of-options-of-a-command-using-script-904411/)

backdoor 09-22-2011 07:25 AM

Generating list of options of a command using script
 
Hi,

I am looking to write a script which could generate list of all the options available for a command. Problems i am facing are
1) I have to generate the options list for all available commands in man1 to start. Ex for ls command (I want to generate -l, -d, -b, -c, etc etc)
2) Formats of the man pages vary for different commands. (Even the roff formats are different).
3) On later stages I will have to extract arguments in system calls, function calls etc.

is there a easy way to accomplish this.
Thank you !!

David the H. 09-22-2011 09:20 AM

No, I can see no easy way to do this. You'd need some uniform way to locate the data you need, and as you said yourself, program documentation isn't uniform. Neither are programs, for that matter. Just try looking at all the options mplayer has, for example, and ps can accept options in three different formats.

With a bit of work you might be able to get something that works in the majority of cases, but there will likely be many exceptions that can't be easily handled.

It might help a bit if you told us why you want to do this--a bit of context. Perhaps there's some other way of satisfying your real goal.

archtoad6 09-22-2011 07:21 PM

Moderation
1st, this doesn't belong in Kernel & I need some feedback from about your goals in order to decide where to move it.
Are you focussed on one particular Linux distro or version. of *nix, or is this primarily a more general scripting question?


Attempt to actually help
From 1) above I see you know where to go to find them (on my system /usr/share/man/man1 containing 1,446 files & soft links.)

2) tells me you have a good idea of the contents, & the problems their lack of uniformity causes.

I do have one off-the-wall, but possibly good, suggestion: Use the KDE "man:" kioslave, possibly working together w/ wget or cURL, to do the basic work for you.

The man kioslave allows you to put "man:<command>" into Konqueror's location bar & get the man page displayed in HTML. (It even turns the "SEE ALSO" entries into clickable links.)

Both wget & cURL can be called from a script, but I don't know if there is is any URL on localhost for them to reference.

I also have never played w/ trying to operate Konqueror under the control of a script, so I have no idea how easy, or even possible that would be.

I do know that Konqueror's HTML display of man pages looks pretty uniform to me. I suspect that if you produce & save the .html files, you can probably grep, sed, awk the info. you need out of them. As a last resort, you could even use perl. ;)

It all depends on the ease of automatically producing the .html man pages -- I doubt you want to individually "Save As" them. :)

backdoor 09-23-2011 02:02 AM

Hi all,

Thanks for the reply..

I am trying to document list of arguments which are different in two different Unix versions (That is the main objective). I would even have to do that for system calls arguments and function calls. Accuracy is very crucial in my case and therefore some formating differences can cause lot of problem.

Converting things to html might or might not work because the basic files of the documents itself are pretty varying.
I am little dissapointed that no one has attempted this before :( ..
Anyways thanks for the help. I will try the solutions and let you guys know. !!

Thhnkas again

archtoad6 09-23-2011 08:10 AM

Quote:

Originally Posted by backdoor (Post 4479898)
Thanks for the reply..

You're welcome.

Quote:

Originally Posted by backdoor (Post 4479898)
I am trying to document list of arguments which are different in two different Unix versions (That is the main objective). I would even have to do that for system calls arguments and function calls. Accuracy is very crucial in my case and therefore some formating differences can cause lot of problem.

Which 2 Unix versions? NB: The answer to this is crucial in deciding where to move this.

Quote:

Originally Posted by backdoor (Post 4479898)
Converting things to html might or might not work because the basic files of the documents itself are pretty varying.

Do you have KDE & Konqueror available for both target Unices? Even if you do, the HTML conversion idea may not help; still, I have to ask. :)

Quote:

Originally Posted by backdoor (Post 4479898)
I am little dissapointed that no one has attempted this before :( ..

That is probably due to the nature of Free Software. Implicit in the license is freedom to do what you want, & conversely to not do what you don't want to do.
Are you familiar w/ The Cathedral and the Bazaar? From its WikipediaŽ article:
Quote:

Guidelines for creating good open source software
There are 19 guidelines for creating good open source software listed in his essay:
1. Every good work of software starts by scratching a developer's personal itch.
It seems you are the 1st one (that you know of) to have this itch.

Quote:

Originally Posted by backdoor (Post 4479898)
I will try the solutions and let you guys know. !!

Please do, posting your results adds to the LQ archive & will help others in the future.

Quote:

Originally Posted by backdoor (Post 4479898)
Thhnkas again

You're welcome again. :D

backdoor 09-24-2011 06:24 AM

I am trying to document stuff to make ppl using solaris to move to linux

Thanks for the comments and help !!

backdoor 09-26-2011 06:39 AM

Hi again..

I am trying to convert the file into html and then finding the right tags. Though again its not exhaustive but better than other ways.

Right now I am trying to figure out if there is a way to check whether a given option exists or not without running the command.

For example when I do "ls -wrong_argument" it gives an error message. But if the command is right it obv runs it. I dont want to run it, just check if the argument is there or not.

Thanks again.

David the H. 10-02-2011 05:04 AM

I don't know if it will help you, but I just stumbled across this project. It looks like it might help you to get man pages into a more parseable format.

http://www.catb.org/~esr/doclifter/


All times are GMT -5. The time now is 05:18 PM.