comparison src/variables.cc @ 668:d63a1354f319

[project @ 1994-09-07 14:39:43 by jwe]
author jwe
date Wed, 07 Sep 1994 14:39:43 +0000
parents fb4f6556b443
children 0faebdd7df57
comparison
equal deleted inserted replaced
667:b19a14bbd862 668:d63a1354f319
1511 } 1511 }
1512 1512
1513 // Deleting names from the symbol tables. 1513 // Deleting names from the symbol tables.
1514 1514
1515 DEFUN_TEXT ("clear", Fclear, Sclear, -1, 1, 1515 DEFUN_TEXT ("clear", Fclear, Sclear, -1, 1,
1516 "clear [name ...]\n\ 1516 "clear [-x] [name ...]\n\
1517 \n\ 1517 \n\
1518 clear symbol(s) matching a list of globbing patterns\n\ 1518 Clear symbol(s) matching a list of globbing patterns.\n\
1519 if no arguments are given, clear all user-defined variables and functions") 1519 \n\
1520 If no arguments are given, clear all user-defined variables and
1521 functions.\n\
1522 \n\
1523 With -x, exclude the named variables")
1520 { 1524 {
1521 Octave_object retval; 1525 Octave_object retval;
1522 1526
1523 DEFINE_ARGV("clear"); 1527 DEFINE_ARGV("clear");
1528
1529 argc--;
1530 argv++;
1524 1531
1525 // Always clear the local table, but don't clear currently compiled 1532 // Always clear the local table, but don't clear currently compiled
1526 // functions unless we are at the top level. (Allowing that to happen 1533 // functions unless we are at the top level. (Allowing that to happen
1527 // inside functions would result in pretty odd behavior...) 1534 // inside functions would result in pretty odd behavior...)
1528 1535
1529 int clear_user_functions = (curr_sym_tab == top_level_sym_tab); 1536 int clear_user_functions = (curr_sym_tab == top_level_sym_tab);
1530 1537
1531 if (argc == 1) 1538 if (argc == 0)
1532 { 1539 {
1533 curr_sym_tab->clear (); 1540 curr_sym_tab->clear ();
1534 global_sym_tab->clear (clear_user_functions); 1541 global_sym_tab->clear (clear_user_functions);
1535 } 1542 }
1536 else 1543 else
1537 { 1544 {
1538 int lcount; 1545 int exclusive = 0;
1539 char **lvars = curr_sym_tab->list (lcount, 0, 1546
1540 symbol_def::USER_VARIABLE, 1547 if (argc > 0)
1541 SYMTAB_LOCAL_SCOPE); 1548 {
1542 int gcount; 1549 if (strcmp (*argv, "-x") == 0)
1543 char **gvars = curr_sym_tab->list (gcount, 0, 1550 {
1544 symbol_def::USER_VARIABLE, 1551 exclusive = 1;
1545 SYMTAB_GLOBAL_SCOPE); 1552 argv++;
1546 int fcount; 1553 argc--;
1547 char **fcns = curr_sym_tab->list (fcount, 0, 1554 }
1548 symbol_def::USER_FUNCTION, 1555 }
1549 SYMTAB_ALL_SCOPES); 1556
1550 1557 int lcount = 0;
1551 while (--argc > 0) 1558 int gcount = 0;
1552 { 1559 int fcount = 0;
1553 argv++; 1560
1554 if (*argv) 1561 char **lvars = 0;
1562 char **gvars = 0;
1563 char **fcns = 0;
1564
1565 if (argc > 0)
1566 {
1567 lvars = curr_sym_tab->list (lcount, 0, symbol_def::USER_VARIABLE,
1568 SYMTAB_LOCAL_SCOPE);
1569
1570 gvars = curr_sym_tab->list (gcount, 0, symbol_def::USER_VARIABLE,
1571 SYMTAB_GLOBAL_SCOPE);
1572
1573 fcns = curr_sym_tab->list (fcount, 0, symbol_def::USER_FUNCTION,
1574 SYMTAB_ALL_SCOPES);
1575 }
1576
1577 while (argc > 0)
1578 {
1579 char *pat = *argv;
1580
1581 if (pat)
1555 { 1582 {
1556 int i; 1583 int i;
1557 for (i = 0; i < lcount; i++) 1584 for (i = 0; i < lcount; i++)
1558 { 1585 {
1559 if (fnmatch (*argv, lvars[i], __FNM_FLAGS) == 0) 1586 char *nm = lvars[i];
1560 curr_sym_tab->clear (lvars[i]); 1587 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0);
1588 if ((exclusive && ! match) || (! exclusive && match))
1589 curr_sym_tab->clear (nm);
1561 } 1590 }
1562 1591
1563 int count; 1592 int count;
1564 for (i = 0; i < gcount; i++) 1593 for (i = 0; i < gcount; i++)
1565 { 1594 {
1566 if (fnmatch (*argv, gvars[i], __FNM_FLAGS) == 0) 1595 char *nm = gvars[i];
1596 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0);
1597 if ((exclusive && ! match) || (! exclusive && match))
1567 { 1598 {
1568 count = curr_sym_tab->clear (gvars[i]); 1599 count = curr_sym_tab->clear (nm);
1569 if (count > 0) 1600 if (count > 0)
1570 global_sym_tab->clear (gvars[i], clear_user_functions); 1601 global_sym_tab->clear (nm, clear_user_functions);
1571 } 1602 }
1572 } 1603 }
1573 1604
1574 for (i = 0; i < fcount; i++) 1605 for (i = 0; i < fcount; i++)
1575 { 1606 {
1576 if (fnmatch (*argv, fcns[i], __FNM_FLAGS) == 0) 1607 char *nm = fcns[i];
1608 int match = (fnmatch (pat, nm, __FNM_FLAGS) == 0);
1609 if ((exclusive && ! match) || (! exclusive && match))
1577 { 1610 {
1578 count = curr_sym_tab->clear (fcns[i]); 1611 count = curr_sym_tab->clear (nm);
1579 if (count > 0) 1612 if (count > 0)
1580 global_sym_tab->clear (fcns[i], clear_user_functions); 1613 global_sym_tab->clear (nm, clear_user_functions);
1581 } 1614 }
1582 } 1615 }
1583 } 1616 }
1617
1618 argc--;
1619 argv++;
1584 } 1620 }
1585 1621
1586 delete [] lvars; 1622 delete [] lvars;
1587 delete [] gvars; 1623 delete [] gvars;
1588 delete [] fcns; 1624 delete [] fcns;