top: utilize getopt and introduce long cmdline options

For quite some time now, top has stood out like a sore
thumb regarding the approach to cmdline options & help
text.  Only short options were used and that same help
text was displayed for '-h' (help) plus 'v' (version).

[ also, top 'rolled his own' when it came to parsing ]
[ options while avoiding that getopt implementation. ]

Well, with this commit all of that has changed and top
now has added a long form of his options. Additionally
he employs getopt_long() for the bulk of that parsing.

[ however, top will still avoid separate fputs calls ]
[ characteristic of other procps-ng programs when it ]
[ comes to help. rather all such text is one string. ]

Along the way, the following major getopt deficiencies
were addressed, assuming the absence of a new #define:

* an equals sign ('=') is allowed on both option forms

* whitespace is allowed before & after the equals sign

* optional arguments needn't abut their related option
for short form nor is an '=' required with either form

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2021-09-04 00:00:00 -05:00
committed by Craig Small
parent b8118b9fee
commit c91b371485
4 changed files with 187 additions and 184 deletions

View File

@@ -29,6 +29,7 @@
//#define CASEUP_HEXES /* show any hex values in upper case */
//#define CASEUP_SUFIX /* show time/mem/cnts suffix in upper case */
//#define EQUCOLHDRYES /* yes, do equalize column header lengths */
//#define GETOPTFIX_NO /* do not address getopt_long deficiencies */
//#define INSP_JUSTNOT /* don't smooth unprintable right margins */
//#define INSP_OFFDEMO /* disable demo screens, issue msg instead */
//#define INSP_SAVEBUF /* preserve 'Insp_buf' contents in a file */
@@ -656,7 +657,7 @@ typedef struct WIN_t {
//atic const char *configs_file (FILE *fp, const char *name, float *delay);
//atic int configs_path (const char *const fmts, ...);
//atic void configs_reads (void);
//atic void parse_args (char **args);
//atic void parse_args (int argc, char **argv);
//atic void whack_terminal (void);
/*------ Windows/Field Groups support ----------------------------------*/
//atic void win_names (WIN_t *q, const char *name);
@@ -699,7 +700,7 @@ typedef struct WIN_t {
/*------ Entry point plus two ------------------------------------------*/
//atic void frame_hlp (int wix, int max);
//atic void frame_make (void);
// int main (int dont_care_argc, char **argv);
// int main (int argc, char *argv[]);
#endif /* _Itop */