{ NULL, 0, NULL, 0 },
};
struct image *image;
- const char *name;
+ const char *name = NULL;
int c;
int rc;
}
}
- /* Need exactly one image name */
- if ( optind != ( argc - 1 ) ) {
+ /* Need no more than one image name */
+ if ( optind != argc )
+ name = argv[optind++];
+ if ( optind != argc ) {
imgexec_syntax ( argv );
return 1;
}
- name = argv[optind];
/* Execute specified image */
- image = find_image ( name );
- if ( ! image ) {
- printf ( "No such image: %s\n", name );
- return 1;
+ if ( name ) {
+ image = find_image ( name );
+ if ( ! image ) {
+ printf ( "No such image: %s\n", name );
+ return 1;
+ }
+ } else {
+ image = imgautoselect();
+ if ( ! image ) {
+ printf ( "No loaded images\n" );
+ return 1;
+ }
}
+
if ( ( rc = imgexec ( image ) ) != 0 ) {
printf ( "Could not execute %s: %s\n", name, strerror ( rc ) );
return 1;
return 0;
}
-
/** Image management commands */
struct command image_commands[] __command = {
{
struct image **new_image );
extern int imgload ( struct image *image );
extern int imgexec ( struct image *image );
+extern struct image * imgautoselect ( void );
extern void imgstat ( struct image *image );
extern void imgfree ( struct image *image );
return image_exec ( image );
}
+/**
+ * Identify the first loaded image
+ *
+ * @ret image Image, or NULL
+ */
+struct image * imgautoselect ( void ) {
+ struct image *image;
+
+ for_each_image ( image ) {
+ if ( image->flags & IMAGE_LOADED )
+ return image;
+ }
+
+ return NULL;
+}
+
/**
* Display status of an image
*