aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2020-02-15 18:56:18 +0100
committerHarald Welte <laforge@osmocom.org>2020-02-15 18:59:19 +0100
commit3a1a3bb8879141fb2b6f7e97278c5903b0c651d4 (patch)
treeb32c36d3dcf88a24953106a3a19f3468fd6c798b /utils
parent4c9a36cb40b93a5dc61d9ee2935ea64d18f2e495 (diff)
osmo-sim-test: Recurse through subdirectories
Don't just iterate over all files in the current working directory (cwd), but also recurse through all sub-directories. Change-Id: I737b01d9a845e37d8be9d4709ef0de04e749daec
Diffstat (limited to 'utils')
-rw-r--r--utils/osmo-sim-test.c52
1 files changed, 39 insertions, 13 deletions
diff --git a/utils/osmo-sim-test.c b/utils/osmo-sim-test.c
index cd983975..ea3ce2a6 100644
--- a/utils/osmo-sim-test.c
+++ b/utils/osmo-sim-test.c
@@ -374,6 +374,44 @@ static void handle_options(int argc, char **argv)
}
}
+
+static void iterate_fs(struct osim_chan_hdl *chan)
+{
+ const struct osim_file_desc *prev_cwd;
+ struct osim_file_desc *ofd;
+
+ /* iterate over all files in current working directory */
+ llist_for_each_entry(ofd, &chan->cwd->child_list, list) {
+ struct msgb *m;
+ printf("\n\n================ %s (%s) ==================\n",
+ ofd->short_name, ofd->long_name);
+
+ m = select_file(chan, ofd->fid);
+ if (msgb_apdu_sw(m) != 0x9000) {
+ msgb_free(m);
+ continue;
+ }
+ dump_fcp_template_msg(m);
+ msgb_free(m);
+
+ /* If this is a DF, recurse into it */
+ switch (ofd->type) {
+ case TYPE_DF:
+ /* the select above has just changed into this directory */
+ prev_cwd = chan->cwd;
+ chan->cwd = ofd;
+ iterate_fs(chan);
+ /* "pop" the directory from the stack */
+ chan->cwd = prev_cwd;
+ break;
+ default:
+ dump_file(chan, ofd->fid);
+ break;
+ }
+ }
+}
+
+
int main(int argc, char **argv)
{
struct osim_reader_hdl *reader;
@@ -410,19 +448,7 @@ int main(int argc, char **argv)
dump_fcp_template_msg(msg);
msgb_free(msg);
- {
- struct osim_file_desc *ofd;
- llist_for_each_entry(ofd, &chan->cwd->child_list, list) {
- struct msgb *m;
- printf("\n\n================ %s (%s) ==================\n",
- ofd->short_name, ofd->long_name);
-
- m = select_file(chan, ofd->fid);
- dump_fcp_template_msg(m);
- msgb_free(m);
- dump_file(chan, ofd->fid);
- }
- }
+ iterate_fs(chan);
exit(0);
}