1 /* cmd-library-versions.c
2  *
3  ****************************************************************
4  * Copyright (C) 2003 Tom Lord
5  *
6  * See the file "COPYING" for further information about
7  * the copyright and warranty status of this work.
8  */
9 
10 
11 #include "config-options.h"
12 #include "hackerlab/cmd/main.h"
13 #include "tla/libarch/namespace.h"
14 #include "tla/libarch/project-tree.h"
15 #include "tla/libarch/my.h"
16 #include "tla/libarch/libraries.h"
17 #include "tla/libarch/cmd-library-versions.h"
18 
19 
20 
21 static t_uchar * usage = "[options] [branch]";
22 static t_uchar * version_string = (cfg__std__package " from regexps.com\n"
23                                    "\n"
24                                    "Copyright 2003 Tom Lord\n"
25                                    "\n"
26                                    "This is free software; see the source for copying conditions.\n"
27                                    "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n"
28                                    "PARTICULAR PURPOSE.\n"
29                                    "\n"
30                                    "Report bugs to " cfg__tla_bug_mail ".\n"
31                                    "\n"
32                                    cfg__std__release_id_string
33                                    "\n");
34 
35 #define OPTS(OP) \
36   OP (opt_help_msg, "h", "help", 0, \
37       "Display a help message and exit.") \
38   OP (opt_long_help, "H", 0, 0, \
39       "Display a verbose help message and exit.") \
40   OP (opt_version, "V", "version", 0, \
41       "Display a release identifier string\n" \
42       "and exit.") \
43   OP (opt_archive, "A", "archive", 1, \
44       "Override `my-default-archive'") \
45   OP (opt_reverse, "r", "reverse", 0, \
46       "sort from newest to oldest")
47 
48 
49 t_uchar arch_cmd_library_versions_help[] = ("list the versions in a library branch\n"
50                                             "List all versions within a particular archive/branch with\n"
51                                             "records in the revision library.\n");
52 
53 enum options
54 {
55   OPTS (OPT_ENUM)
56 };
57 
58 static struct opt_desc opts[] =
59 {
60   OPTS (OPT_DESC)
61     {-1, 0, 0, 0, 0}
62 };
63 
64 
65 
66 int
arch_cmd_library_versions(t_uchar * program_name,int argc,char * argv[])67 arch_cmd_library_versions (t_uchar * program_name, int argc, char * argv[])
68 {
69   int o;
70   struct opt_parsed * option;
71   t_uchar * default_archive;
72   int reverse;
73 
74 
75   default_archive = 0;
76   reverse = 0;
77 
78   safe_buffer_fd (1, 0, O_WRONLY, 0);
79 
80   option = 0;
81 
82   while (1)
83     {
84       o = opt_standard (lim_use_must_malloc, &option, opts, &argc, argv, program_name, usage, version_string, arch_cmd_library_versions_help, opt_help_msg, opt_long_help, opt_version);
85       if (o == opt_none)
86         break;
87       switch (o)
88         {
89         default:
90           safe_printfmt (2, "unhandled option `%s'\n", option->opt_string);
91           panic ("internal error parsing arguments");
92 
93         usage_error:
94           opt_usage (2, argv[0], program_name, usage, 1);
95           exit (1);
96 
97           /* bogus_arg: */
98           safe_printfmt (2, "ill-formed argument for `%s' (`%s')\n", option->opt_string, option->arg_string);
99           goto usage_error;
100 
101         case opt_archive:
102           {
103             default_archive = str_save (0, option->arg_string);
104             break;
105           }
106 
107         case opt_reverse:
108           {
109             reverse = 1;
110             break;
111           }
112         }
113     }
114 
115   if (argc > 2)
116     goto usage_error;
117 
118   default_archive = arch_my_default_archive (default_archive);
119 
120   {
121     t_uchar * branch_spec = 0;
122     t_uchar * archive = 0;
123     t_uchar * branch = 0;
124     rel_table versions = rel_table_nil;
125 
126     if (argc == 2)
127       {
128         branch_spec = str_save (0, argv[1]);
129 
130         if (!arch_valid_package_name (branch_spec, arch_maybe_archive, arch_req_package, 0))
131           {
132             safe_printfmt (2, "%s: invalid branch name (%s)\n",
133                            argv[0], branch_spec);
134             exit (2);
135           }
136       }
137     else
138       branch_spec = arch_try_tree_version (program_name);
139 
140     archive = arch_parse_package_name (arch_ret_archive, default_archive, branch_spec);
141     branch = arch_parse_package_name (arch_ret_package, 0, branch_spec);
142 
143     versions = arch_library_versions (archive, branch);
144 
145     if (reverse)
146       arch_sort_table_by_name_field (1, versions, 0);
147 
148     rel_print_table (1, versions);
149 
150     lim_free (0, branch_spec);
151   }
152 
153   return 0;
154 }
155 
156 
157 
158 
159 /* tag: Tom Lord Wed May 21 14:51:35 2003 (library-versions.c)
160  */
161