/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.90 by masse, Thu Mar 7 01:21:07 2002 UTC revision 1.91 by teddy, Thu Mar 7 03:28:29 2002 UTC
# Line 1  Line 1 
1    /*
2        stack - an interactive interpreter for a stack-based language
3        Copyright (C) 2002  Mats Alritzson and Teddy Hogeborn
4    
5        This program is free software; you can redistribute it and/or modify
6        it under the terms of the GNU General Public License as published by
7        the Free Software Foundation; either version 2 of the License, or
8        (at your option) any later version.
9    
10        This program is distributed in the hope that it will be useful,
11        but WITHOUT ANY WARRANTY; without even the implied warranty of
12        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13        GNU General Public License for more details.
14    
15        You should have received a copy of the GNU General Public License
16        along with this program; if not, write to the Free Software
17        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18    
19        Authors: Mats Alritzson <masse@fukt.bth.se>
20                 Teddy Hogeborn <teddy@fukt.bth.se>
21    */
22    
23  /* printf, sscanf, fgets, fprintf, fopen, perror */  /* printf, sscanf, fgets, fprintf, fopen, perror */
24  #include <stdio.h>  #include <stdio.h>
25  /* exit, EXIT_SUCCESS, malloc, free */  /* exit, EXIT_SUCCESS, malloc, free */
# Line 8  Line 30 
30  #include <dlfcn.h>  #include <dlfcn.h>
31  /* strcmp, strcpy, strlen, strcat, strdup */  /* strcmp, strcpy, strlen, strcat, strdup */
32  #include <string.h>  #include <string.h>
33  /* getopt, STDIN_FILENO, STDOUT_FILENO */  /* getopt, STDIN_FILENO, STDOUT_FILENO, usleep */
34  #include <unistd.h>  #include <unistd.h>
35  /* EX_NOINPUT, EX_USAGE */  /* EX_NOINPUT, EX_USAGE */
36  #include <sysexits.h>  #include <sysexits.h>
37  /* mtrace, muntrace */  /* mtrace, muntrace */
38  #include <mcheck.h>  #include <mcheck.h>
39    /* ioctl */
40    #include <sys/ioctl.h>
41    /* KDMKTONE */
42    #include <linux/kd.h>
43    
44  #include "stack.h"  #include "stack.h"
45    
# Line 903  int main(int argc, char **argv) Line 929  int main(int argc, char **argv)
929      }      }
930    }    }
931    
932      if(myenv.interactive) {
933        printf("Stack version $Revision$\n\
934    Copyright (C) 2002  Mats Alritzson and Teddy Hogeborn\n\
935    Stack comes with ABSOLUTELY NO WARRANTY; for details type `warranty;'.\n\
936    This is free software, and you are welcome to redistribute it\n\
937    under certain conditions; type `copying;' for details.\n");
938      }
939    
940    while(1) {    while(1) {
941      if(myenv.in_string==NULL) {      if(myenv.in_string==NULL) {
942        if (myenv.interactive) {        if (myenv.interactive) {
# Line 917  int main(int argc, char **argv) Line 951  int main(int argc, char **argv)
951      }      }
952      sx_72656164(&myenv);      sx_72656164(&myenv);
953      if (myenv.err==4) {      if (myenv.err==4) {
954        return EX_NOINPUT;        return EXIT_SUCCESS;      /* EOF */
955      } else if(myenv.head!=NULL      } else if(myenv.head!=NULL
956                && myenv.head->item->type==symb                && myenv.head->item->type==symb
957                && ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') {                && ((symbol*)(myenv.head->item->content.ptr))->id[0]==';') {
# Line 1399  extern void sx_72656164(environment *env Line 1433  extern void sx_72656164(environment *env
1433    if(depth)    if(depth)
1434      return sx_72656164(env);      return sx_72656164(env);
1435  }  }
1436    
1437    extern void beep(environment *env) {
1438    
1439      int freq, dur, period, ticks;
1440    
1441      if((env->head)==NULL || env->head->next==NULL) {
1442        printerr("Too Few Arguments");
1443        env->err=1;
1444        return;
1445      }
1446    
1447      if(env->head->item->type!=integer
1448         || env->head->next->item->type!=integer) {
1449        printerr("Bad Argument Type");
1450        env->err=2;
1451        return;
1452      }
1453    
1454      dur=env->head->item->content.val;
1455      toss(env);
1456      freq=env->head->item->content.val;
1457      toss(env);
1458    
1459      period=1193180/freq;          /* convert freq from Hz to period
1460                                       length */
1461      ticks=dur*.001193180;         /* convert duration from µseconds to
1462                                       timer ticks */
1463    
1464    /*    ticks=dur/1000; */
1465    
1466      /*  if (ioctl(STDOUT_FILENO, KDMKTONE, (125<<16) + 0x637)==0) */
1467      switch (ioctl(STDOUT_FILENO, KDMKTONE, (ticks<<16) | period)){
1468      case 0:
1469        usleep(dur);
1470        return;
1471      case -1:
1472        perror("beep");
1473        env->err=5;
1474        return;
1475      default:
1476        abort();
1477      }
1478    };
1479    
1480    /* "wait" */
1481    extern void sx_77616974(environment *env) {
1482    
1483      int dur;
1484    
1485      if((env->head)==NULL) {
1486        printerr("Too Few Arguments");
1487        env->err=1;
1488        return;
1489      }
1490    
1491      if(env->head->item->type!=integer) {
1492        printerr("Bad Argument Type");
1493        env->err=2;
1494        return;
1495      }
1496    
1497      dur=env->head->item->content.val;
1498      toss(env);
1499    
1500      usleep(dur);
1501    };
1502    
1503    extern void copying(environment *env){
1504      printf("GNU GENERAL PUBLIC LICENSE\n\
1505                           Version 2, June 1991\n\
1506    \n\
1507     Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n\
1508         59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\
1509     Everyone is permitted to copy and distribute verbatim copies\n\
1510     of this license document, but changing it is not allowed.\n\
1511    \n\
1512                                Preamble\n\
1513    \n\
1514      The licenses for most software are designed to take away your\n\
1515    freedom to share and change it.  By contrast, the GNU General Public\n\
1516    License is intended to guarantee your freedom to share and change free\n\
1517    software--to make sure the software is free for all its users.  This\n\
1518    General Public License applies to most of the Free Software\n\
1519    Foundation's software and to any other program whose authors commit to\n\
1520    using it.  (Some other Free Software Foundation software is covered by\n\
1521    the GNU Library General Public License instead.)  You can apply it to\n\
1522    your programs, too.\n\
1523    \n\
1524      When we speak of free software, we are referring to freedom, not\n\
1525    price.  Our General Public Licenses are designed to make sure that you\n\
1526    have the freedom to distribute copies of free software (and charge for\n\
1527    this service if you wish), that you receive source code or can get it\n\
1528    if you want it, that you can change the software or use pieces of it\n\
1529    in new free programs; and that you know you can do these things.\n\
1530    \n\
1531      To protect your rights, we need to make restrictions that forbid\n\
1532    anyone to deny you these rights or to ask you to surrender the rights.\n\
1533    These restrictions translate to certain responsibilities for you if you\n\
1534    distribute copies of the software, or if you modify it.\n\
1535    \n\
1536      For example, if you distribute copies of such a program, whether\n\
1537    gratis or for a fee, you must give the recipients all the rights that\n\
1538    you have.  You must make sure that they, too, receive or can get the\n\
1539    source code.  And you must show them these terms so they know their\n\
1540    rights.\n\
1541    \n\
1542      We protect your rights with two steps: (1) copyright the software, and\n\
1543    (2) offer you this license which gives you legal permission to copy,\n\
1544    distribute and/or modify the software.\n\
1545    \n\
1546      Also, for each author's protection and ours, we want to make certain\n\
1547    that everyone understands that there is no warranty for this free\n\
1548    software.  If the software is modified by someone else and passed on, we\n\
1549    want its recipients to know that what they have is not the original, so\n\
1550    that any problems introduced by others will not reflect on the original\n\
1551    authors' reputations.\n\
1552    \n\
1553      Finally, any free program is threatened constantly by software\n\
1554    patents.  We wish to avoid the danger that redistributors of a free\n\
1555    program will individually obtain patent licenses, in effect making the\n\
1556    program proprietary.  To prevent this, we have made it clear that any\n\
1557    patent must be licensed for everyone's free use or not licensed at all.\n\
1558    \n\
1559      The precise terms and conditions for copying, distribution and\n\
1560    modification follow.\n\
1561    \n\
1562                        GNU GENERAL PUBLIC LICENSE\n\
1563       TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\
1564    \n\
1565      0. This License applies to any program or other work which contains\n\
1566    a notice placed by the copyright holder saying it may be distributed\n\
1567    under the terms of this General Public License.  The \"Program\", below,\n\
1568    refers to any such program or work, and a \"work based on the Program\"\n\
1569    means either the Program or any derivative work under copyright law:\n\
1570    that is to say, a work containing the Program or a portion of it,\n\
1571    either verbatim or with modifications and/or translated into another\n\
1572    language.  (Hereinafter, translation is included without limitation in\n\
1573    the term \"modification\".)  Each licensee is addressed as \"you\".\n\
1574    \n\
1575    Activities other than copying, distribution and modification are not\n\
1576    covered by this License; they are outside its scope.  The act of\n\
1577    running the Program is not restricted, and the output from the Program\n\
1578    is covered only if its contents constitute a work based on the\n\
1579    Program (independent of having been made by running the Program).\n\
1580    Whether that is true depends on what the Program does.\n\
1581    \n\
1582      1. You may copy and distribute verbatim copies of the Program's\n\
1583    source code as you receive it, in any medium, provided that you\n\
1584    conspicuously and appropriately publish on each copy an appropriate\n\
1585    copyright notice and disclaimer of warranty; keep intact all the\n\
1586    notices that refer to this License and to the absence of any warranty;\n\
1587    and give any other recipients of the Program a copy of this License\n\
1588    along with the Program.\n\
1589    \n\
1590    You may charge a fee for the physical act of transferring a copy, and\n\
1591    you may at your option offer warranty protection in exchange for a fee.\n\
1592    \n\
1593      2. You may modify your copy or copies of the Program or any portion\n\
1594    of it, thus forming a work based on the Program, and copy and\n\
1595    distribute such modifications or work under the terms of Section 1\n\
1596    above, provided that you also meet all of these conditions:\n\
1597    \n\
1598        a) You must cause the modified files to carry prominent notices\n\
1599        stating that you changed the files and the date of any change.\n\
1600    \n\
1601        b) You must cause any work that you distribute or publish, that in\n\
1602        whole or in part contains or is derived from the Program or any\n\
1603        part thereof, to be licensed as a whole at no charge to all third\n\
1604        parties under the terms of this License.\n\
1605    \n\
1606        c) If the modified program normally reads commands interactively\n\
1607        when run, you must cause it, when started running for such\n\
1608        interactive use in the most ordinary way, to print or display an\n\
1609        announcement including an appropriate copyright notice and a\n\
1610        notice that there is no warranty (or else, saying that you provide\n\
1611        a warranty) and that users may redistribute the program under\n\
1612        these conditions, and telling the user how to view a copy of this\n\
1613        License.  (Exception: if the Program itself is interactive but\n\
1614        does not normally print such an announcement, your work based on\n\
1615        the Program is not required to print an announcement.)\n\
1616    \n\
1617    These requirements apply to the modified work as a whole.  If\n\
1618    identifiable sections of that work are not derived from the Program,\n\
1619    and can be reasonably considered independent and separate works in\n\
1620    themselves, then this License, and its terms, do not apply to those\n\
1621    sections when you distribute them as separate works.  But when you\n\
1622    distribute the same sections as part of a whole which is a work based\n\
1623    on the Program, the distribution of the whole must be on the terms of\n\
1624    this License, whose permissions for other licensees extend to the\n\
1625    entire whole, and thus to each and every part regardless of who wrote it.\n\
1626    \n\
1627    Thus, it is not the intent of this section to claim rights or contest\n\
1628    your rights to work written entirely by you; rather, the intent is to\n\
1629    exercise the right to control the distribution of derivative or\n\
1630    collective works based on the Program.\n\
1631    \n\
1632    In addition, mere aggregation of another work not based on the Program\n\
1633    with the Program (or with a work based on the Program) on a volume of\n\
1634    a storage or distribution medium does not bring the other work under\n\
1635    the scope of this License.\n\
1636    \n\
1637      3. You may copy and distribute the Program (or a work based on it,\n\
1638    under Section 2) in object code or executable form under the terms of\n\
1639    Sections 1 and 2 above provided that you also do one of the following:\n\
1640    \n\
1641        a) Accompany it with the complete corresponding machine-readable\n\
1642        source code, which must be distributed under the terms of Sections\n\
1643        1 and 2 above on a medium customarily used for software interchange; or,\n\
1644    \n\
1645        b) Accompany it with a written offer, valid for at least three\n\
1646        years, to give any third party, for a charge no more than your\n\
1647        cost of physically performing source distribution, a complete\n\
1648        machine-readable copy of the corresponding source code, to be\n\
1649        distributed under the terms of Sections 1 and 2 above on a medium\n\
1650        customarily used for software interchange; or,\n\
1651    \n\
1652        c) Accompany it with the information you received as to the offer\n\
1653        to distribute corresponding source code.  (This alternative is\n\
1654        allowed only for noncommercial distribution and only if you\n\
1655        received the program in object code or executable form with such\n\
1656        an offer, in accord with Subsection b above.)\n\
1657    \n\
1658    The source code for a work means the preferred form of the work for\n\
1659    making modifications to it.  For an executable work, complete source\n\
1660    code means all the source code for all modules it contains, plus any\n\
1661    associated interface definition files, plus the scripts used to\n\
1662    control compilation and installation of the executable.  However, as a\n\
1663    special exception, the source code distributed need not include\n\
1664    anything that is normally distributed (in either source or binary\n\
1665    form) with the major components (compiler, kernel, and so on) of the\n\
1666    operating system on which the executable runs, unless that component\n\
1667    itself accompanies the executable.\n\
1668    \n\
1669    If distribution of executable or object code is made by offering\n\
1670    access to copy from a designated place, then offering equivalent\n\
1671    access to copy the source code from the same place counts as\n\
1672    distribution of the source code, even though third parties are not\n\
1673    compelled to copy the source along with the object code.\n\
1674    \n\
1675      4. You may not copy, modify, sublicense, or distribute the Program\n\
1676    except as expressly provided under this License.  Any attempt\n\
1677    otherwise to copy, modify, sublicense or distribute the Program is\n\
1678    void, and will automatically terminate your rights under this License.\n\
1679    However, parties who have received copies, or rights, from you under\n\
1680    this License will not have their licenses terminated so long as such\n\
1681    parties remain in full compliance.\n\
1682    \n\
1683      5. You are not required to accept this License, since you have not\n\
1684    signed it.  However, nothing else grants you permission to modify or\n\
1685    distribute the Program or its derivative works.  These actions are\n\
1686    prohibited by law if you do not accept this License.  Therefore, by\n\
1687    modifying or distributing the Program (or any work based on the\n\
1688    Program), you indicate your acceptance of this License to do so, and\n\
1689    all its terms and conditions for copying, distributing or modifying\n\
1690    the Program or works based on it.\n\
1691    \n\
1692      6. Each time you redistribute the Program (or any work based on the\n\
1693    Program), the recipient automatically receives a license from the\n\
1694    original licensor to copy, distribute or modify the Program subject to\n\
1695    these terms and conditions.  You may not impose any further\n\
1696    restrictions on the recipients' exercise of the rights granted herein.\n\
1697    You are not responsible for enforcing compliance by third parties to\n\
1698    this License.\n\
1699    \n\
1700      7. If, as a consequence of a court judgment or allegation of patent\n\
1701    infringement or for any other reason (not limited to patent issues),\n\
1702    conditions are imposed on you (whether by court order, agreement or\n\
1703    otherwise) that contradict the conditions of this License, they do not\n\
1704    excuse you from the conditions of this License.  If you cannot\n\
1705    distribute so as to satisfy simultaneously your obligations under this\n\
1706    License and any other pertinent obligations, then as a consequence you\n\
1707    may not distribute the Program at all.  For example, if a patent\n\
1708    license would not permit royalty-free redistribution of the Program by\n\
1709    all those who receive copies directly or indirectly through you, then\n\
1710    the only way you could satisfy both it and this License would be to\n\
1711    refrain entirely from distribution of the Program.\n\
1712    \n\
1713    If any portion of this section is held invalid or unenforceable under\n\
1714    any particular circumstance, the balance of the section is intended to\n\
1715    apply and the section as a whole is intended to apply in other\n\
1716    circumstances.\n\
1717    \n\
1718    It is not the purpose of this section to induce you to infringe any\n\
1719    patents or other property right claims or to contest validity of any\n\
1720    such claims; this section has the sole purpose of protecting the\n\
1721    integrity of the free software distribution system, which is\n\
1722    implemented by public license practices.  Many people have made\n\
1723    generous contributions to the wide range of software distributed\n\
1724    through that system in reliance on consistent application of that\n\
1725    system; it is up to the author/donor to decide if he or she is willing\n\
1726    to distribute software through any other system and a licensee cannot\n\
1727    impose that choice.\n\
1728    \n\
1729    This section is intended to make thoroughly clear what is believed to\n\
1730    be a consequence of the rest of this License.\n\
1731    \n\
1732      8. If the distribution and/or use of the Program is restricted in\n\
1733    certain countries either by patents or by copyrighted interfaces, the\n\
1734    original copyright holder who places the Program under this License\n\
1735    may add an explicit geographical distribution limitation excluding\n\
1736    those countries, so that distribution is permitted only in or among\n\
1737    countries not thus excluded.  In such case, this License incorporates\n\
1738    the limitation as if written in the body of this License.\n\
1739    \n\
1740      9. The Free Software Foundation may publish revised and/or new versions\n\
1741    of the General Public License from time to time.  Such new versions will\n\
1742    be similar in spirit to the present version, but may differ in detail to\n\
1743    address new problems or concerns.\n\
1744    \n\
1745    Each version is given a distinguishing version number.  If the Program\n\
1746    specifies a version number of this License which applies to it and \"any\n\
1747    later version\", you have the option of following the terms and conditions\n\
1748    either of that version or of any later version published by the Free\n\
1749    Software Foundation.  If the Program does not specify a version number of\n\
1750    this License, you may choose any version ever published by the Free Software\n\
1751    Foundation.\n\
1752    \n\
1753      10. If you wish to incorporate parts of the Program into other free\n\
1754    programs whose distribution conditions are different, write to the author\n\
1755    to ask for permission.  For software which is copyrighted by the Free\n\
1756    Software Foundation, write to the Free Software Foundation; we sometimes\n\
1757    make exceptions for this.  Our decision will be guided by the two goals\n\
1758    of preserving the free status of all derivatives of our free software and\n\
1759    of promoting the sharing and reuse of software generally.\n");
1760    }
1761    
1762    extern void warranty(environment *env){
1763      printf("                          NO WARRANTY\n\
1764    \n\
1765      11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n\
1766    FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\n\
1767    OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n\
1768    PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n\
1769    OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n\
1770    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\n\
1771    TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\n\
1772    PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n\
1773    REPAIR OR CORRECTION.\n\
1774    \n\
1775      12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n\
1776    WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n\
1777    REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n\
1778    INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n\
1779    OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n\
1780    TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n\
1781    YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n\
1782    PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n\
1783    POSSIBILITY OF SUCH DAMAGES.\n");
1784    }

Legend:
Removed from v.1.90  
changed lines
  Added in v.1.91

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26