Changes in uspace/app/taskbar/tbsmenu.c [d92b8e8f:e63e74a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskbar/tbsmenu.c
rd92b8e8f re63e74a 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 *);67 66 68 67 /** Create taskbar start menu. … … 70 69 * @param window Containing window 71 70 * @param fixed Fixed layout to which start button will be added 72 * @param dspec Display specification (for passing to applications)73 71 * @param rtbsmenu Place to store pointer to new start menu 74 72 * @return @c EOK on success or an error code 75 73 */ 76 74 errno_t tbsmenu_create(ui_window_t *window, ui_fixed_t *fixed, 77 const char *dspec,tbsmenu_t **rtbsmenu)75 tbsmenu_t **rtbsmenu) 78 76 { 79 77 ui_resource_t *res = ui_window_get_res(window); … … 87 85 } 88 86 89 tbsmenu->display_spec = str_dup(dspec);90 if (tbsmenu->display_spec == NULL) {91 rc = ENOMEM;92 goto error;93 }94 95 87 rc = ui_pbutton_create(res, "Start", &tbsmenu->sbutton); 96 88 if (rc != EOK) … … 119 111 return EOK; 120 112 error: 121 if (tbsmenu != NULL && tbsmenu->display_spec != NULL)122 free(tbsmenu->display_spec);123 113 if (tbsmenu != NULL) 124 114 ui_pbutton_destroy(tbsmenu->sbutton); … … 144 134 bool terminal; 145 135 errno_t rc; 146 147 if (tbsmenu->repopath != NULL)148 free(tbsmenu->repopath);149 150 tbsmenu->repopath = str_dup(repopath);151 if (tbsmenu->repopath == NULL)152 return ENOMEM;153 154 /* Remove existing entries */155 tentry = tbsmenu_first(tbsmenu);156 while (tentry != NULL) {157 tbsmenu_remove(tbsmenu, tentry, false);158 tentry = tbsmenu_first(tbsmenu);159 }160 136 161 137 rc = tbarcfg_open(repopath, &tbcfg); … … 194 170 } 195 171 196 /** Reload start menu from repository (or schedule reload).197 *198 * @param tbsmenu Start menu199 */200 void tbsmenu_reload(tbsmenu_t *tbsmenu)201 {202 if (!tbsmenu_is_open(tbsmenu))203 (void) tbsmenu_load(tbsmenu, tbsmenu->repopath);204 else205 tbsmenu->needs_reload = true;206 }207 208 172 /** Set start menu rectangle. 209 173 * … … 234 198 { 235 199 ui_menu_close(tbsmenu->smenu); 236 237 if (tbsmenu->needs_reload)238 (void) tbsmenu_load(tbsmenu, tbsmenu->repopath);239 200 } 240 201 … … 486 447 static errno_t tbsmenu_cmd_split(const char *str, tbsmenu_cmd_t *cmd) 487 448 { 488 char *buf;489 449 char *arg; 490 450 char *next; 491 451 size_t cnt; 492 452 493 buf = str_dup(str);494 if ( buf == NULL)453 cmd->buf = str_dup(str); 454 if (cmd->buf == NULL) 495 455 return ENOMEM; 496 456 497 457 /* Count the entries */ 498 458 cnt = 0; 499 arg = str_tok( buf, " ", &next);459 arg = str_tok(cmd->buf, " ", &next); 500 460 while (arg != NULL) { 501 461 ++cnt; … … 504 464 505 465 /* Need to copy again as buf was mangled */ 506 free( buf);507 buf = str_dup(str);508 if ( buf == NULL)466 free(cmd->buf); 467 cmd->buf = str_dup(str); 468 if (cmd->buf == NULL) 509 469 return ENOMEM; 510 470 511 471 cmd->argv = calloc(cnt + 1, sizeof(char *)); 512 472 if (cmd->argv == NULL) { 513 free( buf);473 free(cmd->buf); 514 474 return ENOMEM; 515 475 } 516 476 517 /* Copy individual arguments */477 /* Fill in pointers */ 518 478 cnt = 0; 519 arg = str_tok( buf, " ", &next);479 arg = str_tok(cmd->buf, " ", &next); 520 480 while (arg != NULL) { 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 481 cmd->argv[cnt++] = arg; 528 482 arg = str_tok(next, " ", &next); 529 483 } … … 540 494 static void tbsmenu_cmd_fini(tbsmenu_cmd_t *cmd) 541 495 { 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 */552 496 free(cmd->argv); 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; 497 free(cmd->buf); 583 498 } 584 499 … … 601 516 char **cp; 602 517 const char **targv = NULL; 603 char *dspec = NULL;604 sysarg_t idev_id;605 int rv;606 518 errno_t rc; 607 519 ui_t *ui; … … 610 522 suspended = false; 611 523 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 */620 524 rc = tbsmenu_cmd_split(entry->cmd, &cmd); 621 if (rc != EOK) { 622 free(dspec); 525 if (rc != EOK) 623 526 return rc; 624 }625 626 /* Substitute metacharacters in command */627 rc = tbsmenu_cmd_subst(&cmd, entry, dspec);628 if (rc != EOK)629 goto error;630 527 631 528 /* Free up and clean console for the child task. */ … … 645 542 } 646 543 647 targv = calloc(cnt + 5, sizeof(char **));544 targv = calloc(cnt + 3, sizeof(char **)); 648 545 if (targv == NULL) 649 546 goto error; 650 547 651 548 targv[0] = "/app/terminal"; 652 targv[1] = "-d"; 653 targv[2] = dspec; 654 targv[3] = "-c"; 549 targv[1] = "-c"; 655 550 656 551 for (i = 0; i <= cnt; i++) { 657 targv[ 4+ i] = cmd.argv[i];552 targv[2 + i] = cmd.argv[i]; 658 553 } 659 554 … … 683 578 return EOK; 684 579 error: 685 free(dspec);686 580 if (targv != NULL) 687 581 free(targv);
Note:
See TracChangeset
for help on using the changeset viewer.