home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / src / runtime / keyword.r < prev    next >
Text File  |  2002-01-18  |  18KB  |  753 lines

  1. /*
  2.  * File: keyword.r
  3.  *  Contents: all keywords
  4.  *
  5.  *  After adding keywords, be sure to rerun ../icont/mkkwd.
  6.  */
  7.  
  8. #define KDef(p,n) int Cat(K,p) (dptr cargp);
  9. #include "../h/kdefs.h"
  10. #undef KDef
  11.  
  12. "&allocated - the space used in the storage regions:"
  13. " total, static, string, and block"
  14. keyword{4} allocated
  15.    abstract {
  16.       return integer
  17.       }
  18.    inline {
  19.       suspend C_integer stattotal + strtotal + blktotal;
  20.       suspend C_integer stattotal;
  21.       suspend C_integer strtotal;
  22.       return  C_integer blktotal;
  23.       }
  24. end
  25.  
  26. "&clock - a string consisting of the current time of day"
  27. keyword{1} clock
  28.    abstract {
  29.       return string
  30.       }
  31.    inline {
  32.       time_t t;
  33.       struct tm *ct;
  34.       char sbuf[9], *tmp;
  35.  
  36.       time(&t);
  37.       ct = localtime(&t);
  38.       sprintf(sbuf,"%02d:%02d:%02d", ct->tm_hour, ct->tm_min, ct->tm_sec);
  39.       Protect(tmp = alcstr(sbuf,(word)8), runerr(0));
  40.       return string(8, tmp);
  41.       }
  42. end
  43.  
  44. "&collections - the number of collections: total, triggered by static requests"
  45. " triggered by string requests, and triggered by block requests"
  46. keyword{4} collections
  47.    abstract {
  48.       return integer
  49.       }
  50.    inline {
  51.       suspend C_integer coll_tot;
  52.       suspend C_integer coll_stat;
  53.       suspend C_integer coll_str;
  54.       return  C_integer coll_blk;
  55.       }
  56. end
  57.  
  58. #if !COMPILER
  59. "&column - source column number of current execution point"
  60. keyword{1} column
  61.    abstract {
  62.       return integer;
  63.       }
  64.    inline {
  65. #ifdef MultiThread
  66. #ifdef EventMon
  67.       return C_integer findcol(ipc.opnd);
  68. #else                    /* EventMon */
  69.       fail;
  70. #endif                    /* EventMon */
  71. #else
  72.       fail;
  73. #endif                    /* MultiThread */
  74.       }
  75. end
  76. #endif                    /* !COMPILER */
  77.  
  78. "¤t - the currently active co-expression"
  79. keyword{1} current
  80.    abstract {
  81.       return coexpr
  82.       }
  83.    inline {
  84.       return k_current;
  85.       }
  86. end
  87.  
  88. "&date - the current date"
  89. keyword{1} date
  90.    abstract {
  91.       return string
  92.       }
  93.    inline {
  94.       time_t t;
  95.       struct tm *ct;
  96.       char sbuf[11], *tmp;
  97.  
  98.       time(&t);
  99.       ct = localtime(&t);
  100.       sprintf(sbuf, "%04d/%02d/%02d",
  101.          1900 + ct->tm_year, ct->tm_mon + 1, ct->tm_mday);
  102.       Protect(tmp = alcstr(sbuf,(word)10), runerr(0));
  103.       return string(10, tmp);
  104.       }
  105. end
  106.  
  107. "&dateline - current date and time"
  108. keyword{1} dateline
  109.    abstract {
  110.       return string
  111.       }
  112.    body {
  113.       static char *day[] = {
  114.          "Sunday", "Monday", "Tuesday", "Wednesday",
  115.          "Thursday", "Friday", "Saturday"
  116.          };
  117.       static char *month[] = {
  118.          "January", "February", "March", "April", "May", "June",
  119.          "July", "August", "September", "October", "November", "December"
  120.          };
  121.       time_t t;
  122.       struct tm *ct;
  123.       char sbuf[MaxCvtLen];
  124.       int hour;
  125.       char *merid, *tmp;
  126.       int i;
  127.  
  128.       time(&t);
  129.       ct = localtime(&t);
  130.       if ((hour = ct->tm_hour) >= 12) {
  131.          merid = "pm";
  132.          if (hour > 12)
  133.             hour -= 12;
  134.          }
  135.       else {
  136.          merid = "am";
  137.          if (hour < 1)
  138.             hour += 12;
  139.          }
  140.       sprintf(sbuf, "%s, %s %d, %d  %d:%02d %s", day[ct->tm_wday],
  141.          month[ct->tm_mon], ct->tm_mday, 1900 + ct->tm_year, hour,
  142.      ct->tm_min, merid);
  143.        i = strlen(sbuf);
  144.        Protect(tmp = alcstr(sbuf, i), runerr(0));
  145.        return string(i, tmp);
  146.        }
  147. end
  148.  
  149. "&digits - a cset consisting of the 10 decimal digits"
  150. keyword{1} digits
  151.    constant '0123456789'
  152. end
  153.  
  154. "&e - the base of the natural logarithms"
  155. keyword{1} e
  156.    constant 2.71828182845904523536028747135266249775724709369996
  157. end
  158.  
  159. "&error - enable/disable error conversion"
  160. keyword{1} error
  161.    abstract {
  162.       return kywdint
  163.       }
  164.    inline {
  165.       return kywdint(&kywd_err);
  166.       }
  167. end
  168.  
  169. "&errornumber - error number of last error converted to failure"
  170. keyword{0,1} errornumber
  171.    abstract {
  172.       return integer
  173.       }
  174.    inline {
  175.       if (k_errornumber == 0)
  176.          fail;
  177.       return C_integer k_errornumber;
  178.       }
  179. end
  180.  
  181. "&errortext - error message of last error converted to failure"
  182. keyword{0,1} errortext
  183.    abstract {
  184.       return string
  185.       }
  186.    inline {
  187.       if (k_errornumber == 0)
  188.          fail;
  189.       return C_string k_errortext;
  190.       }
  191. end
  192.  
  193. "&errorvalue - erroneous value of last error converted to failure"
  194. keyword{0,1} errorvalue
  195.    abstract {
  196.       return any_value
  197.       }
  198.    inline {
  199.       if (have_errval)
  200.          return k_errorvalue;
  201.       else
  202.          fail;
  203.       }
  204. end
  205.  
  206. "&errout - standard error output."
  207. keyword{1} errout
  208.     abstract {
  209.        return file
  210.        }
  211.     inline {
  212.        return file(&k_errout);
  213.        }
  214. end
  215.  
  216. "&fail - just fail"
  217. keyword{0} fail
  218.    abstract {
  219.       return empty_type
  220.       }
  221.    inline {
  222.       fail;
  223.       }
  224. end
  225.  
  226. "&eventcode - event in monitored program"
  227. keyword{0,1} eventcode
  228.    abstract {
  229.       return kywdevent
  230.       }
  231.    inline {
  232.       return kywdevent(&k_eventcode);
  233.       }
  234. end
  235.  
  236. "&eventsource - source of events in monitoring program"
  237. keyword{0,1} eventsource
  238.    abstract {
  239.       return kywdevent
  240.       }
  241.    inline {
  242.       return kywdevent(&k_eventsource);
  243.       }
  244. end
  245.  
  246. "&eventvalue - value from event in monitored program"
  247. keyword{0,1} eventvalue
  248.    abstract {
  249.       return kywdevent
  250.       }
  251.    inline {
  252.       return kywdevent(&k_eventvalue);
  253.       }
  254. end
  255.  
  256. "&features - generate strings identifying features in this version of Icon"
  257. keyword{1,*} features
  258.    abstract {
  259.       return string
  260.       }
  261.    body {
  262. #if COMPILER
  263. #define Feature(guard,sym,kwval) if ((guard) && (kwval)) suspend C_string kwval;
  264. #else                    /* COMPILER */
  265. #define Feature(guard,sym,kwval) if (kwval) suspend C_string kwval;
  266. #endif                    /* COMPILER */
  267. #include "../h/features.h"
  268.       fail;
  269.       }
  270. end
  271.  
  272. "&file - name of the source file for the current execution point"
  273. keyword{1} file
  274.    abstract {
  275.       return string
  276.       }
  277.    inline {
  278. #if COMPILER
  279.       if (line_info)
  280.          return C_string file_name;
  281.       else
  282.          runerr(402);
  283. #else                    /* COMPILER */
  284.       char *s;
  285.       s = findfile(ipc.opnd);
  286.       if (!strcmp(s,"?")) fail;
  287.       return C_string s;
  288. #endif                    /* COMPILER */
  289.       }
  290. end
  291.  
  292. "&host - a string that identifies the host computer Icon is running on."
  293. keyword{1} host
  294.    abstract {
  295.      return string
  296.      }
  297.    inline {
  298.       char sbuf[MaxCvtLen], *tmp;
  299.       int i;
  300.  
  301.       iconhost(sbuf);
  302.       i = strlen(sbuf);
  303.       Protect(tmp = alcstr(sbuf, i), runerr(0));
  304.       return string(i, tmp);
  305.       }
  306. end
  307.  
  308. "&input - the standard input file"
  309. keyword{1} input
  310.    abstract {
  311.       return file
  312.       }
  313.    inline {
  314.       return file(&k_input);
  315.       }
  316. end
  317.  
  318. "&lcase - a cset consisting of the 26 lower case letters"
  319. keyword{1} lcase
  320.    constant 'abcdefghijklmnopqrstuvwxyz'
  321. end
  322.  
  323. "&letters - a cset consisting of the 52 letters"
  324. keyword{1} letters
  325.    constant 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  326. end
  327.  
  328. "&level - level of procedure call."
  329. keyword{1} level
  330.    abstract {
  331.       return integer
  332.       }
  333.  
  334.    inline {
  335. #if COMPILER
  336.       if (!debug_info)
  337.          runerr(402);
  338. #endif                    /* COMPILER */
  339.       return C_integer k_level;
  340.       }
  341. end
  342.  
  343. "&line - source line number of current execution point"
  344. keyword{1} line
  345.    abstract {
  346.       return integer;
  347.       }
  348.    inline {
  349. #if COMPILER
  350.       if (line_info)
  351.          return C_integer line_num;
  352.       else
  353.          runerr(402);
  354. #else                    /* COMPILER */
  355.       return C_integer findline(ipc.opnd);
  356. #endif                    /* COMPILER */
  357.       }
  358. end
  359.  
  360. "&main - the main co-expression."
  361. keyword{1} main
  362.    abstract {
  363.       return coexpr
  364.       }
  365.    inline {
  366.       return k_main;
  367.       }
  368. end
  369.  
  370. "&null - the null value."
  371. keyword{1} null
  372.    abstract {
  373.       return null
  374.       }
  375.    inline {
  376.       return nulldesc;
  377.       }
  378. end
  379.  
  380. "&output - the standard output file."
  381. keyword{1} output
  382.    abstract {
  383.       return file
  384.       }
  385.    inline {
  386.       return file(&k_output);
  387.       }
  388. end
  389.  
  390. "&phi - the golden ratio"
  391. keyword{1} phi
  392.    constant 1.618033988749894848204586834365638117720309180
  393. end
  394.  
  395. "&pi - the ratio of circumference to diameter"
  396. keyword{1} pi
  397.    constant 3.14159265358979323846264338327950288419716939937511
  398. end
  399.  
  400. "&pos - a variable containing the current focus in string scanning."
  401. keyword{1} pos
  402.    abstract {
  403.       return kywdpos
  404.       }
  405.     inline {
  406.       return kywdpos(&kywd_pos);
  407.       }
  408. end
  409.  
  410. "&progname - a variable containing the program name."
  411. keyword{1} progname
  412.    abstract {
  413.       return kywdstr
  414.       }
  415.     inline {
  416.       return kywdstr(&kywd_prog);
  417.       }
  418. end
  419.  
  420. "&random - a variable containing the current seed for random operations."
  421. keyword{1} random
  422.    abstract {
  423.       return kywdint
  424.       }
  425.    inline {
  426.       return kywdint(&kywd_ran);
  427.       }
  428. end
  429.  
  430. "®ions - generates regions sizes"
  431. keyword{3} regions
  432.    abstract {
  433.       return integer
  434.       }
  435.    inline {
  436.       word allRegions = 0;
  437.       struct region *rp;
  438.  
  439.       suspend C_integer 0;        /* static region */
  440.  
  441.       allRegions = DiffPtrs(strend,strbase);
  442.       for (rp = curstring->next; rp; rp = rp->next)
  443.      allRegions += DiffPtrs(rp->end,rp->base);
  444.       for (rp = curstring->prev; rp; rp = rp->prev)
  445.      allRegions += DiffPtrs(rp->end,rp->base);
  446.       suspend C_integer allRegions;    /* string region */
  447.  
  448.       allRegions = DiffPtrs(blkend,blkbase);
  449.       for (rp = curblock->next; rp; rp = rp->next)
  450.      allRegions += DiffPtrs(rp->end,rp->base);
  451.       for (rp = curblock->prev; rp; rp = rp->prev)
  452.      allRegions += DiffPtrs(rp->end,rp->base);
  453.       return C_integer allRegions;    /* block region */
  454.       }
  455. end
  456.  
  457. "&source - the co-expression that invoked the current co-expression."
  458. keyword{1} source
  459.    abstract {
  460.        return coexpr
  461.        }
  462.    inline {
  463. #ifndef Coexpr
  464.          return k_main;
  465. #else                    /* Coexpr */
  466.          return coexpr(topact((struct b_coexpr *)BlkLoc(k_current)));
  467. #endif                    /* Coexpr */
  468.          }
  469. end
  470.  
  471. "&storage - generate the amount of storage used for each region."
  472. keyword{3} storage
  473.    abstract {
  474.       return integer
  475.       }
  476.    inline {
  477.       word allRegions = 0;
  478.       struct region *rp;
  479.  
  480.       suspend C_integer 0;        /* static region */
  481.  
  482.       allRegions = DiffPtrs(strfree,strbase);
  483.       for (rp = curstring->next; rp; rp = rp->next)
  484.      allRegions += DiffPtrs(rp->free,rp->base);
  485.       for (rp = curstring->prev; rp; rp = rp->prev)
  486.      allRegions += DiffPtrs(rp->free,rp->base);
  487.       suspend C_integer allRegions;    /* string region */
  488.  
  489.       allRegions = DiffPtrs(blkfree,blkbase);
  490.       for (rp = curblock->next; rp; rp = rp->next)
  491.      allRegions += DiffPtrs(rp->free,rp->base);
  492.       for (rp = curblock->prev; rp; rp = rp->prev)
  493.      allRegions += DiffPtrs(rp->free,rp->base);
  494.       return C_integer allRegions;    /* block region */
  495.       }
  496. end
  497.  
  498. "&subject - variable containing the current subject of string scanning."
  499. keyword{1} subject
  500.    abstract {
  501.       return kywdsubj
  502.       }
  503.    inline {
  504.       return kywdsubj(&k_subject);
  505.       }
  506. end
  507.  
  508. "&time - the elapsed execution time in milliseconds."
  509. keyword{1} time
  510.    abstract {
  511.       return integer
  512.       }
  513.    inline {
  514.       return C_integer millisec();
  515.       }
  516. end
  517.  
  518. "&trace - variable that controls procedure tracing."
  519. keyword{1} trace
  520.    abstract {
  521.       return kywdint
  522.       }
  523.    inline {
  524.       return kywdint(&kywd_trc);
  525.       }
  526. end
  527.  
  528. "&dump - variable that controls termination dump."
  529. keyword{1} dump
  530.    abstract {
  531.       return kywdint
  532.       }
  533.    inline {
  534.       return kywdint(&kywd_dmp);
  535.       }
  536. end
  537.  
  538. "&ucase - a cset consisting of the 26 uppercase characters."
  539. keyword{1} ucase
  540.    constant 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  541. end
  542.  
  543. "&version - a string indentifying this version of Icon."
  544. keyword{1} version
  545.    constant Version
  546. end
  547.  
  548. #ifndef MultiThread
  549. struct descrip kywd_xwin[2] = {{D_Null}};
  550. #endif                    /* MultiThread */
  551.  
  552. "&window - variable containing the current graphics rendering context."
  553. #ifdef Graphics
  554. keyword{1} window
  555.    abstract {
  556.       return kywdwin
  557.       }
  558.    inline {
  559.       return kywdwin(kywd_xwin + XKey_Window);
  560.       }
  561. end
  562. #else                    /* Graphics */
  563. keyword{0} window
  564.    abstract {
  565.       return empty_type
  566.       }
  567.    inline {
  568.       fail;
  569.       }
  570. end
  571. #endif                    /* Graphics */
  572.  
  573. #ifdef Graphics
  574. "&col - mouse horizontal position in text columns."
  575. keyword{1} col
  576.    abstract { return kywdint }
  577.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  578.         else return kywdint(&erCol); }
  579. end
  580.  
  581. "&row - mouse vertical position in text rows."
  582. keyword{1} row
  583.    abstract { return kywdint }
  584.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  585.         else return kywdint(&erRow); }
  586. end
  587.  
  588. "&x - mouse horizontal position."
  589. keyword{1} x
  590.    abstract { return kywdint }
  591.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  592.         else return kywdint(&erX); }
  593. end
  594.  
  595. "&y - mouse vertical position."
  596. keyword{1} y
  597.    abstract { return kywdint }
  598.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  599.         else return kywdint(&erY); }
  600. end
  601.  
  602. "&interval - milliseconds since previous event."
  603. keyword{1} interval
  604.    abstract { return kywdint }
  605.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  606.         else return kywdint(&erInterval); }
  607. end
  608.  
  609. "&control - null if control key was down on last X event, else failure"
  610. keyword{0,1} control
  611.    abstract { return null }
  612.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  613.         else if (xmod_control) return nulldesc; else fail; }
  614. end
  615.  
  616. "&shift - null if shift key was down on last X event, else failure"
  617. keyword{0,1} shift
  618.    abstract { return null }
  619.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  620.         else if (xmod_shift) return nulldesc; else fail; }
  621. end
  622.  
  623. "&meta - null if meta key was down on last X event, else failure"
  624. keyword{0,1} meta
  625.    abstract { return null }
  626.    inline { if (is:null(lastEventWin)) runerr(140, lastEventWin);
  627.         else if (xmod_meta) return nulldesc; else fail; }
  628. end
  629. #else                    /* Graphics */
  630. "&col - mouse horizontal position in text columns."
  631. keyword{0} col
  632.    abstract { return empty_type }
  633.    inline { fail; }
  634. end
  635.  
  636. "&row - mouse vertical position in text rows."
  637. keyword{0} row
  638.    abstract { return empty_type }
  639.    inline { fail; }
  640. end
  641.  
  642. "&x - mouse horizontal position."
  643. keyword{0} x
  644.    abstract { return empty_type }
  645.    inline { fail; }
  646. end
  647.  
  648. "&y - mouse vertical position."
  649. keyword{0} y
  650.    abstract { return empty_type }
  651.    inline { fail; }
  652. end
  653.  
  654. "&interval - milliseconds since previous event."
  655. keyword{0} interval
  656.    abstract { return empty_type }
  657.    inline { fail; }
  658. end
  659.  
  660. "&control - null if control key was down on last X event, else failure"
  661. keyword{0} control
  662.    abstract { return empty_type}
  663.    inline { fail; }
  664. end
  665.  
  666. "&shift - null if shift key was down on last X event, else failure"
  667. keyword{0} shift
  668.    abstract { return empty_type }
  669.    inline { fail; }
  670. end
  671.  
  672. "&meta - null if meta key was down on last X event, else failure"
  673. keyword{0} meta
  674.    abstract { return empty_type }
  675.    inline { fail; }
  676. end
  677. #endif                    /* Graphics */
  678.  
  679. "&lpress - left button press."
  680. keyword{1} lpress
  681.    abstract { return integer} inline { return C_integer MOUSELEFT; }
  682. end
  683. "&mpress - middle button press."
  684. keyword{1} mpress
  685.    abstract { return integer} inline { return C_integer MOUSEMID; }
  686. end
  687. "&rpress - right button press."
  688. keyword{1} rpress
  689.    abstract { return integer} inline { return C_integer MOUSERIGHT; }
  690. end
  691. "&lrelease - left button release."
  692. keyword{1} lrelease
  693.    abstract { return integer} inline { return C_integer MOUSELEFTUP; }
  694. end
  695. "&mrelease - middle button release."
  696. keyword{1} mrelease
  697.    abstract { return integer} inline { return C_integer MOUSEMIDUP; }
  698. end
  699. "&rrelease - right button release."
  700. keyword{1} rrelease
  701.    abstract { return integer} inline { return C_integer MOUSERIGHTUP; }
  702. end
  703. "&ldrag - left button drag."
  704. keyword{1} ldrag
  705.    abstract { return integer} inline { return C_integer MOUSELEFTDRAG; }
  706. end
  707. "&mdrag - middle button drag."
  708. keyword{1} mdrag
  709.    abstract { return integer} inline { return C_integer MOUSEMIDDRAG; }
  710. end
  711. "&rdrag - right button drag."
  712. keyword{1} rdrag
  713.    abstract { return integer} inline { return C_integer MOUSERIGHTDRAG; }
  714. end
  715. "&resize - window resize."
  716. keyword{1} resize
  717.    abstract { return integer} inline { return C_integer RESIZED; }
  718. end
  719.  
  720. "&ascii - a cset consisting of the 128 ascii characters"
  721. keyword{1} ascii
  722. constant '\
  723. \000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\
  724. \020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037\
  725. \040\041\042\043\044\045\046\047\050\051\052\053\054\055\056\057\
  726. \060\061\062\063\064\065\066\067\070\071\072\073\074\075\076\077\
  727. \100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\
  728. \120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\
  729. \140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\
  730. \160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177'
  731. end
  732.  
  733. "&cset - a cset consisting of all the 256 characters."
  734. keyword{1} cset
  735. constant '\
  736. \0\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17\
  737. \20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37\
  738. \40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\
  739. \60\61\62\63\64\65\66\67\70\71\72\73\74\75\76\77\
  740. \100\101\102\103\104\105\106\107\110\111\112\113\114\115\116\117\
  741. \120\121\122\123\124\125\126\127\130\131\132\133\134\135\136\137\
  742. \140\141\142\143\144\145\146\147\150\151\152\153\154\155\156\157\
  743. \160\161\162\163\164\165\166\167\170\171\172\173\174\175\176\177\
  744. \200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\
  745. \220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\
  746. \240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\
  747. \260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\
  748. \300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\
  749. \320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\
  750. \340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\
  751. \360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
  752. end
  753.