In article <hf*******************@fe2.texas.rr.com>,
Jerry Gaspard <jg********@hotmail.com> wrote:
I'd like to know how to open a document in a default app. like for example
if I wanted to open a .txt document I'd like my program open notepad if it
is the default for a windows machine text files or open openoffice if it is
the default application for linux.
is there a portable way to do this?
There is no such a thing as a "default app" associated with a
file in a UNIX system. You may build such an association
into your C program. Here's something to get you started with.
It will require quite a bit of enhancements to become something
workable.
enum filetypes { unknown, text, html, jpeg, gif };
char *default_apps[100];
default_apps[text] = "cat";
default_apps[html] = "w3m";
default_apps[jpeg] = "xv";
default_apps[gif] = "xv";
....
default_apps[unknown] = (you decide)
To determine the file type of a file, see the man page for the "file"
command on Linux and the references in its "See Also" section.
---------- WARNING! WARNING! -----------------------------------
Having said that, I urge you strongly to resist the temptation of
giving a "default app" functionality in your program. In general
such functionality opens a slew of possibilities for security breaches.
It's sufficient for one file to masquerade as something other than
what it is and have your program gullibly run an unexpected program.
DON'T DO IT!
--
rr