Changeset fd11144 in mainline for uspace/app/gfxdemo/gfxdemo.c


Ignore:
Timestamp:
2020-07-04T21:52:35Z (4 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fc4abca
Parents:
e79a025
Message:

Make display service argument optional

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/gfxdemo/gfxdemo.c

    re79a025 rfd11144  
    11/*
    2  * Copyright (c) 2019 Jiri Svoboda
     2 * Copyright (c) 2020 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    487487
    488488/** Run demo on canvas. */
    489 static errno_t demo_canvas(void)
     489static errno_t demo_canvas(const char *display_svc)
    490490{
    491491        canvas_gc_t *cgc = NULL;
     
    500500        printf("Init canvas..\n");
    501501
    502         window = window_open(DISPLAY_DEFAULT, NULL,
     502        window = window_open(display_svc, NULL,
    503503            WINDOW_MAIN | WINDOW_DECORATED, "GFX Demo");
    504504        if (window == NULL) {
     
    553553
    554554/** Run demo on display server. */
    555 static errno_t demo_display(void)
     555static errno_t demo_display(const char *display_svc)
    556556{
    557557        display_t *display = NULL;
     
    563563        printf("Init display..\n");
    564564
    565         rc = display_open(DISPLAY_DEFAULT, &display);
     565        rc = display_open(display_svc, &display);
    566566        if (rc != EOK) {
    567567                printf("Error opening display.\n");
     
    618618static void print_syntax(void)
    619619{
    620         printf("syntax: gfxdemo {canvas|console|display}\n");
     620        printf("Syntax: gfxdemo [-d <display>] {canvas|console|display}\n");
    621621}
    622622
     
    624624{
    625625        errno_t rc;
    626 
    627         if (argc < 2 || str_cmp(argv[1], "display") == 0) {
    628                 rc = demo_display();
    629                 if (rc != EOK)
     626        const char *display_svc = DISPLAY_DEFAULT;
     627        int i;
     628
     629        i = 1;
     630        while (i < argc && argv[i][0] == '-') {
     631                if (str_cmp(argv[i], "-d") == 0) {
     632                        ++i;
     633                        if (i >= argc) {
     634                                printf("Argument missing.\n");
     635                                print_syntax();
     636                                return 1;
     637                        }
     638
     639                        display_svc = argv[i++];
     640                } else {
     641                        printf("Invalid option '%s'.\n", argv[i]);
     642                        print_syntax();
    630643                        return 1;
    631         } else if (str_cmp(argv[1], "console") == 0) {
     644                }
     645        }
     646
     647        if (i >= argc || str_cmp(argv[i], "display") == 0) {
     648                rc = demo_display(display_svc);
     649                if (rc != EOK)
     650                        return 1;
     651        } else if (str_cmp(argv[i], "console") == 0) {
    632652                rc = demo_console();
    633653                if (rc != EOK)
    634654                        return 1;
    635         } else if (str_cmp(argv[1], "canvas") == 0) {
    636                 rc = demo_canvas();
     655        } else if (str_cmp(argv[i], "canvas") == 0) {
     656                rc = demo_canvas(display_svc);
    637657                if (rc != EOK)
    638658                        return 1;
Note: See TracChangeset for help on using the changeset viewer.