From d3f644a37f28c1ad5e9e0d9b342cfc28fdd5692c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 26 Jul 2008 14:58:44 -0400 Subject: [PATCH] New get_planes(), factored out of plane flying commands No functional change. --- include/prototypes.h | 2 ++ src/lib/commands/bomb.c | 5 +---- src/lib/commands/drop.c | 5 +---- src/lib/commands/fly.c | 5 +---- src/lib/commands/para.c | 5 +---- src/lib/commands/reco.c | 5 +---- src/lib/subs/plnsub.c | 23 +++++++++++++++++++++++ 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index 8c7791e8c..4c10f0f34 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -535,6 +535,8 @@ extern int pln_postread(int, void *); extern int pln_prewrite(int, void *); /* plnsub.c */ extern void count_planes(struct shpstr *); +extern int get_planes(struct nstr_item *, struct nstr_item *, + char *, char *); extern struct sctstr *get_assembly_point(char *, struct sctstr *, char *); extern int pln_onewaymission(struct sctstr *, int *, int *); extern int pln_oneway_to_carrier_ok(struct emp_qelem *, diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 1445b3f8a..871335676 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -99,11 +99,8 @@ bomb(void) char buf[1024]; wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0) return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, - getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf); if (!p || !*p) return RET_SYN; diff --git a/src/lib/commands/drop.c b/src/lib/commands/drop.c index a3317af5e..e33bb086f 100644 --- a/src/lib/commands/drop.c +++ b/src/lib/commands/drop.c @@ -58,11 +58,8 @@ drop(void) char buf[1024]; wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0) return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, - getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); if (!get_assembly_point(player->argp[3], &ap_sect, buf)) return RET_SYN; ax = ap_sect.sct_x; diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index 97304f7dc..b0095b762 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -60,11 +60,8 @@ fly(void) char buf[1024]; wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0) return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, - getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); if (!get_assembly_point(player->argp[3], &ap_sect, buf)) return RET_SYN; ax = ap_sect.sct_x; diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index 9c976b2b2..620fc4578 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -63,11 +63,8 @@ para(void) char buf[1024]; wantflags = P_P; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0) return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, - getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); if (!get_assembly_point(player->argp[3], &ap_sect, buf)) return RET_SYN; ax = ap_sect.sct_x; diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index fcd4d1359..a28387fb7 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -57,11 +57,8 @@ reco(void) char buf[1024]; wantflags = 0; - if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1])) + if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0) return RET_SYN; - if (!snxtitem(&ni_esc, EF_PLANE, - getstarg(player->argp[2], "escort(s)? ", buf))) - pr("No escorts...\n"); if (!get_assembly_point(player->argp[3], &ap_sect, buf)) return RET_SYN; ax = ap_sect.sct_x; diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 73f2d7973..ae9afdfda 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -57,6 +57,29 @@ static int pln_equip(struct plist *, struct ichrstr *, int, char); static int fit_plane_on_ship(struct plnstr *, struct shpstr *); +/* + * Get planes and escorts argument. + * Read planes into *NI_BOMB, and (optional) escorts into *NI_ESC. + * If INPUT_BOMB is not empty, use it, else prompt for more input. + * Same for INPUT_ESC. + * If we got a plane argument, initialize *NI_BOMB and *NI_ESC, and + * return 0. + * Else return -1 (*NI_BOMB and *NI_ESC may be modified). + */ +int +get_planes(struct nstr_item *ni_bomb, struct nstr_item *ni_esc, + char *input_bomb, char *input_esc) +{ + char buf[1024]; + + if (!snxtitem(ni_bomb, EF_PLANE, input_bomb)) + return -1; + if (!snxtitem(ni_esc, EF_PLANE, + getstarg(input_esc, "escort(s)? ", buf))) + pr("No escorts...\n"); + return 0; +} + /* * Get assembly point argument. * If INPUT is not empty, use it, else prompt for more input using PROMPT. -- 2.43.0