Changeset d92b8e8f in mainline for uspace/app/taskbar/tbsmenu.c
- Timestamp:
- 2024-03-04T14:12:26Z (11 months ago)
- Branches:
- master
- Children:
- e229148
- Parents:
- ee3b28a9
- git-author:
- Jiri Svoboda <jiri@…> (2024-03-03 18:12:02)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-03-04 14:12:26)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/tbsmenu.c
ree3b28a9 rd92b8e8f 64 64 static void tbsmenu_smenu_entry_cb(ui_menu_entry_t *, void *); 65 65 static errno_t tbsmenu_entry_start(tbsmenu_entry_t *); 66 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *); 66 67 67 68 /** Create taskbar start menu. … … 69 70 * @param window Containing window 70 71 * @param fixed Fixed layout to which start button will be added 72 * @param dspec Display specification (for passing to applications) 71 73 * @param rtbsmenu Place to store pointer to new start menu 72 74 * @return @c EOK on success or an error code 73 75 */ 74 76 errno_t tbsmenu_create(ui_window_t *window, ui_fixed_t *fixed, 75 tbsmenu_t **rtbsmenu)77 const char *dspec, tbsmenu_t **rtbsmenu) 76 78 { 77 79 ui_resource_t *res = ui_window_get_res(window); … … 85 87 } 86 88 89 tbsmenu->display_spec = str_dup(dspec); 90 if (tbsmenu->display_spec == NULL) { 91 rc = ENOMEM; 92 goto error; 93 } 94 87 95 rc = ui_pbutton_create(res, "Start", &tbsmenu->sbutton); 88 96 if (rc != EOK) … … 111 119 return EOK; 112 120 error: 121 if (tbsmenu != NULL && tbsmenu->display_spec != NULL) 122 free(tbsmenu->display_spec); 113 123 if (tbsmenu != NULL) 114 124 ui_pbutton_destroy(tbsmenu->sbutton); … … 476 486 static errno_t tbsmenu_cmd_split(const char *str, tbsmenu_cmd_t *cmd) 477 487 { 488 char *buf; 478 489 char *arg; 479 490 char *next; 480 491 size_t cnt; 481 492 482 cmd->buf = str_dup(str);483 if ( cmd->buf == NULL)493 buf = str_dup(str); 494 if (buf == NULL) 484 495 return ENOMEM; 485 496 486 497 /* Count the entries */ 487 498 cnt = 0; 488 arg = str_tok( cmd->buf, " ", &next);499 arg = str_tok(buf, " ", &next); 489 500 while (arg != NULL) { 490 501 ++cnt; … … 493 504 494 505 /* Need to copy again as buf was mangled */ 495 free( cmd->buf);496 cmd->buf = str_dup(str);497 if ( cmd->buf == NULL)506 free(buf); 507 buf = str_dup(str); 508 if (buf == NULL) 498 509 return ENOMEM; 499 510 500 511 cmd->argv = calloc(cnt + 1, sizeof(char *)); 501 512 if (cmd->argv == NULL) { 502 free( cmd->buf);513 free(buf); 503 514 return ENOMEM; 504 515 } 505 516 506 /* Fill in pointers */517 /* Copy individual arguments */ 507 518 cnt = 0; 508 arg = str_tok( cmd->buf, " ", &next);519 arg = str_tok(buf, " ", &next); 509 520 while (arg != NULL) { 510 cmd->argv[cnt++] = arg; 521 cmd->argv[cnt] = str_dup(arg); 522 if (cmd->argv[cnt] == NULL) { 523 tbsmenu_cmd_fini(cmd); 524 return ENOMEM; 525 } 526 ++cnt; 527 511 528 arg = str_tok(next, " ", &next); 512 529 } … … 523 540 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *cmd) 524 541 { 542 char **cp; 543 544 /* Free all pointers in NULL-terminated list */ 545 cp = cmd->argv; 546 while (*cp != NULL) { 547 free(*cp); 548 ++cp; 549 } 550 551 /* Free the array of pointers */ 525 552 free(cmd->argv); 526 free(cmd->buf); 553 } 554 555 /** Free command structure. 556 * 557 * @param cmd Command 558 * @param entry Start menu entry 559 * @param dspec Display specification 560 * @return EOK on success or an error code 561 */ 562 static errno_t tbsmenu_cmd_subst(tbsmenu_cmd_t *cmd, tbsmenu_entry_t *entry, 563 const char *dspec) 564 { 565 char **cp; 566 567 (void)entry; 568 569 /* Walk NULL-terminated list of arguments */ 570 cp = cmd->argv; 571 while (*cp != NULL) { 572 if (str_cmp(*cp, "%d") == 0) { 573 /* Display specification */ 574 free(*cp); 575 *cp = str_dup(dspec); 576 if (*cp == NULL) 577 return ENOMEM; 578 } 579 ++cp; 580 } 581 582 return EOK; 527 583 } 528 584 … … 545 601 char **cp; 546 602 const char **targv = NULL; 603 char *dspec = NULL; 604 sysarg_t idev_id; 605 int rv; 547 606 errno_t rc; 548 607 ui_t *ui; … … 551 610 suspended = false; 552 611 612 idev_id = ui_menu_get_idev_id(entry->tbsmenu->smenu); 613 614 rv = asprintf(&dspec, "%s?idev=%zu", 615 entry->tbsmenu->display_spec, (size_t)idev_id); 616 if (rv < 0) 617 return ENOMEM; 618 619 /* Split command string into individual arguments */ 553 620 rc = tbsmenu_cmd_split(entry->cmd, &cmd); 554 if (rc != EOK) 621 if (rc != EOK) { 622 free(dspec); 555 623 return rc; 624 } 625 626 /* Substitute metacharacters in command */ 627 rc = tbsmenu_cmd_subst(&cmd, entry, dspec); 628 if (rc != EOK) 629 goto error; 556 630 557 631 /* Free up and clean console for the child task. */ … … 571 645 } 572 646 573 targv = calloc(cnt + 3, sizeof(char **));647 targv = calloc(cnt + 5, sizeof(char **)); 574 648 if (targv == NULL) 575 649 goto error; 576 650 577 651 targv[0] = "/app/terminal"; 578 targv[1] = "-c"; 652 targv[1] = "-d"; 653 targv[2] = dspec; 654 targv[3] = "-c"; 579 655 580 656 for (i = 0; i <= cnt; i++) { 581 targv[ 2+ i] = cmd.argv[i];657 targv[4 + i] = cmd.argv[i]; 582 658 } 583 659 … … 607 683 return EOK; 608 684 error: 685 free(dspec); 609 686 if (targv != NULL) 610 687 free(targv);
Note:
See TracChangeset
for help on using the changeset viewer.