2 Copyright © 2013, The AROS Development Team. All rights reserved.
6 /******************************************************************************
22 Shows help information for commands and system applications.
23 The help files are stored in HELP:English with a sub-directory
24 for each section. The utility "Multiview" is used to show the
25 guide files. If neither NAME nor SECTION are given an index page
30 NAME -- the name of the command or application whose help
31 you want to view. The name is case-insensitive.
32 SECTION -- the section where the help document will be searched.
33 Currently available are "commands" and "system". If you
34 don't specify the section all available sections will
35 be searched. The section is case-insensitive.
53 ******************************************************************************/
55 #include <proto/dos.h>
62 #include <aros/debug.h>
64 #define ARG_TEMPLATE "NAME,SECTION"
66 const char *ver
= "$VER: Help 1.1 (09.03.2013)";
77 static STRPTR section
;
78 static TEXT docpath
[100];
79 static TEXT viewpath
[256];
81 static CONST_STRPTR section_arr
[] = {"Commands", "System", NULL
};
84 static void clean_exit(CONST_STRPTR s
)
87 if (rda
) FreeArgs(rda
);
92 static LONG
show_file(STRPTR buffer
, ULONG buflen
, CONST_STRPTR path
)
94 strlcpy(buffer
, "SYS:Utilities/Multiview ", buflen
);
95 strlcat(buffer
, path
, buflen
);
96 D(bug("[Help/show_file] SystemTags path %s\n", buffer
));
97 // FIXME: running asynchron?
98 LONG error
= SystemTags
107 static STRPTR find_file
109 STRPTR buffer
, ULONG buflen
,
110 CONST_STRPTR name
, CONST_STRPTR section
113 // TODO: support different suffixes
115 STRPTR retval
= NULL
;
116 struct FileInfoBlock
*fib
= AllocDosObjectTagList(DOS_FIB
, NULL
);
119 snprintf(buffer
, buflen
, "HELP:English/%s/%s.guide", section
, name
);
120 D(bug("[Help/find_file] search for %s\n", buffer
));
121 BPTR lock
= Lock(buffer
, ACCESS_READ
);
124 BOOL success
= Examine(lock
, fib
);
127 if (fib
->fib_DirEntryType
< 0) // is file?
134 FreeDosObject(DOS_FIB
, fib
);
140 int main(int argc
, char **argv
)
142 if (argc
) // started from Shell
144 IPTR args
[ARG_COUNT
] = {0};
146 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
149 PrintFault(IoErr(), argv
[0]);
150 clean_exit("ReadArgs() failed.\n");
155 name
= (STRPTR
)args
[ARG_NAME
];
156 if (strpbrk(name
, ":/()#?~"))
158 clean_exit("Illegal characters in argument 'name'.\n");
162 if (args
[ARG_SECTION
])
164 section
= (STRPTR
)args
[ARG_SECTION
];
165 if (strpbrk(section
, ":/()#?~"))
167 clean_exit("Illegal characters in argument 'section'.\n");
171 D(bug("[Help] name %s section %s\n", name
, section
));
173 if (name
== NULL
&& section
== NULL
)
175 strcpy(docpath
, "HELP:English/Index.guide");
176 show_file(viewpath
, sizeof(viewpath
), docpath
);
178 else if (section
== NULL
|| *section
== '\0')
182 for (sect
= section_arr
; (found
== FALSE
) && (*sect
) ; sect
++)
184 if (find_file(docpath
, sizeof(docpath
), name
, *sect
))
186 show_file(viewpath
, sizeof(viewpath
), docpath
);
192 clean_exit("Can't find help document.\n");
197 if (find_file(docpath
, sizeof(docpath
), name
, section
))
199 show_file(viewpath
, sizeof(viewpath
), docpath
);
203 clean_exit("Can't find help document.\n");
207 else // started from Wanderer
209 strcpy(docpath
, "HELP:English/Index.guide");
210 show_file(viewpath
, sizeof(viewpath
), docpath
);