home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newlibs / rawil110.lha / RawIN.doc next >
Text File  |  1992-08-04  |  21KB  |  715 lines

  1.  
  2.                         ===================
  3.                           RawIN.lib V1.10
  4.                            Documentation
  5.                          - August 4, 1992 -
  6.                         ===================
  7.  
  8.  
  9.         Copyright (c) 1992 by Sam Yee.  All rights reserved.
  10.  
  11.  
  12.  
  13. =====================================================================
  14. COPYRIGHT
  15. =========
  16.  
  17. The link-time library RawIN.lib and its documentation are written and
  18. copyrighted by Sam Yee.  They may be distributed freely providing the
  19. following restrictions are satisfied:
  20.  
  21. o Distributors  may  not charge more than the cost of a diskette used
  22.   for the distribution of this library.
  23.  
  24. o Distributors  may  only  distribute  the  unmodified  copy  of  the
  25.   original  library,  along  with  its  documentation,  and copyright
  26.   notices intact.
  27.  
  28.  
  29. =====================================================================
  30. DISCLAIMER
  31. ==========
  32.  
  33. This  library  and the test program and its documentation is provided
  34. "as  is".   No  warranties  are  made  with  respect to the accuracy,
  35. reliability,   performance   or   operation   of  this  software  and
  36. information.   You  are  using  this  program  at your own risk.  The
  37. author  is  not  liable  for any damages that may have been caused by
  38. using this software.
  39.  
  40.  
  41. =====================================================================
  42. INTRODUCTION
  43. ============
  44.  
  45. Have  you ever wanted to write a program that runs in the CLI, taking
  46. input  from  the user and at the same time checking for other things,
  47. like  signals  and messages from other processes?  You found out that
  48. you  couldn't  use  AmigaDOS's  Read() function or C's built-in input
  49. functions,  like  scanf(), or getchar() to get the job done.  Some of
  50. you  may  have  tried using the WaitForChar() function in conjunction
  51. with  the  Read()  function,  but  reading a line cannot be completed
  52. until  the  user presses the carriage return.  I have writen numerous
  53. utilities for bulletin board systems (BBSs) and have found that using
  54. Read()  or  other  synchronous  input functions are inappropriate for
  55. such  applications.   These synchronous functions do not return until
  56. they accomplish their tasks.  For example, if you send a break signal
  57. to  a  process to tell it to abort, and this process is getting input
  58. from  the user, the program would not exit until the user has pressed
  59. a carriage return.  This is a big problem if the BBS is attempting to
  60. terminate  a  user  who  is  running  this program and whose time has
  61. expired.   This  is  where  RawIN.lib comes in.  It allows you to get
  62. input  from  the  user  and  at the same time check for other special
  63. events  (such as an abort signal).  It also provides a set of command
  64. history routines.
  65.  
  66. =====================================================================
  67. USER MANUAL
  68. ===========
  69.  
  70. Read  the  RawINTest.c  file  to get a better idea of how most of the
  71. following functions work together.  You should put RawIN.lib into the
  72. directory where your other link-time libraries are.  If you are using
  73. SAS/C,  you  can  link  the  library  with the following command line
  74. arguments:
  75.  
  76. blink lib:c.o,prg.o to prg lib lib:RawIN.lib,lib:lc.lib,lib:amiga.lib
  77.  
  78. To  make  your program systems friendly they should exit when a break
  79. signal (C) has been received or the end-of-file of standard input has
  80. been  reached.  You can check for the break signal by calling Wait(),
  81. SetSignal()  or  CheckSignal  (OS  2.04).   Note that only if you use
  82. RawIN.lib's  functions  will  the  LNF_BREAKC flag be set in the Line
  83. struture.  For end-of-file of standard input, check the LNF_EOF flag.
  84.  
  85. The autodocs are as follows.
  86. ---------------------------------------------------------------------
  87.  
  88. NAME
  89.     AllocLine -- Allocate a line structure to be used for raw input.
  90.  
  91. SYNOPSIS
  92.     line = AllocLine(buf_size,hist_size)
  93.  
  94.     struct Line *line;
  95.     unsigned long buf_size;
  96.     unsigned long hist_size;
  97.  
  98. FUNCTIONS
  99.     Allocate  and  prepare  a line structure.  Allocate all necessary
  100.     buffers.   Initialize  all  variables, etc.  This routine must be
  101.     the  first  one  to  be  called  before  you  can  call any other
  102.     RawIN.lib routines.
  103.  
  104. EXAMPLE
  105.     struct Line *line;
  106.  
  107.     if (!(line = AllocLine(512,100)))   /* 512 char buffer,
  108.                                            10 history lines */
  109.     {
  110.         printf("AllocLine() fails. :-(\n");
  111.         exit(10);
  112.     }
  113.     ...
  114.     FreeLine(line);
  115.  
  116. INPUT
  117.     buf_size = Size to allocate for command buffer.
  118.     hist_size = Number of history lines.  The history buffers are not
  119.                 allocated at this point.
  120.  
  121. RESULT
  122.     line = Allocated Line structure.  NULL if unsuccessful.
  123.  
  124. SEE ALSO
  125.     FreeLine
  126.  
  127. ---------------------------------------------------------------------
  128.  
  129. NAME
  130.     BuildLine -- Inserts  a  character  into  the  command  buffer if
  131.                  applicable.   Some  control  codes  will  change the
  132.                  state of the buffer.
  133.  
  134. SYNOPSIS
  135.     eol = BuildLine(line,max_chars,echo)
  136.  
  137.     BOOL eol;
  138.     struct Line *line;
  139.     long max_chars;
  140.     BOOL echo
  141.  
  142. FUNCTION
  143.     This  routine  takes  the  input character in line->InputChar and
  144.     stores  it  into the buffer and echoes it back onto the screen if
  145.     the  buffer  is non-full.  Control codes such as cursor movements
  146.     will  alter  the  state  of  the  buffer.  Read the "COMMAND LINE
  147.     EDITING FEATURES" section for these codes.
  148.  
  149. EXAMPLE
  150.     struct Line *line;
  151.  
  152.     ...
  153.     if (BuildLine(Output(),line,-1L))
  154.         printf("You've typed %s\n",line->buf);
  155.  
  156. INPUTS
  157.     line = The line structure in which the character is to affect.
  158.     max_chars  = The maximum number of characters the current command
  159.                  line can allow.  If -1L, use the default.
  160.     echo = If TRUE, output changes to the command line.
  161.  
  162. RESULT
  163.     eol = If  TRUE,  user  has  pressed  a  carriage return, and thus
  164.           ending the command line.
  165.  
  166. SEE ALSO
  167.     ResetLine
  168.  
  169. ---------------------------------------------------------------------
  170.  
  171. NAME
  172.     DeleteHistory -- Delete the specified history line.
  173.  
  174. SYNOPSIS
  175.     void DeleteHistory(line,num)
  176.  
  177.     struct Line *line;
  178.     long num;
  179.  
  180. FUNCTIONS
  181.     Remove the specified history node from the history list.
  182.  
  183. INPUT
  184.     line = Line structure where the history list is found.
  185.     num = History number to remove.  The first one is 1, and the last
  186.           one is -1L.
  187.  
  188. RESULT
  189.     none
  190.  
  191. EXAMPLE
  192.     struct Line *line;
  193.  
  194.     ...
  195.     while(line->hist_linecount)        /* delete all history lines */
  196.         DeleteHistory(line,1);
  197.  
  198. SEE ALSO
  199.     MakeHistory
  200.     ShowHistory
  201.     GetHistory
  202.  
  203. ---------------------------------------------------------------------
  204.  
  205. NAME
  206.     FreeLine -- Deallocate all the buffers allocated by a Line
  207.                 structure.
  208.  
  209. SYNOPSIS
  210.     void FreeLine(line)
  211.  
  212.     struct Line *line;
  213.  
  214. FUNCTIONS
  215.     Simply  free  all  the  memory  associated with a Line structure,
  216.     including  itself.   If  there  is a read pending, wait for it to
  217.     complete.
  218.  
  219. INPUT
  220.     line = Line structure whose contents to be freed.
  221.  
  222. RESULT
  223.     none
  224.  
  225. SEE ALSO
  226.     AllocLine
  227.  
  228. ---------------------------------------------------------------------
  229.  
  230. NAME
  231.     GetHistory  --  Travers  the  history  list to find the specified
  232.                     history buffer.
  233.  
  234. SYNOPSIS
  235.     history = GetHistory(line,num)
  236.  
  237.     struct History *history;
  238.     struct Line *line;
  239.     long num;
  240.  
  241. FUNCTIONS
  242.     This  routine  will  find  the  numbered  history line buffer you
  243.     specify.  It will search through the whole history list.
  244.  
  245. EXAMPLE
  246.     struct Line *line;
  247.     struct History *hist;
  248.  
  249.     ...
  250.     if (hist = GetHistory(line,1L))
  251.         printf("The first history line is '%s'\n",hist->buf);
  252.     else
  253.         printf("No history.\n");
  254.  
  255. INPUTS
  256.     line = The line structure to search for the specified history.
  257.     num = The history number to search (starting from 1).
  258.  
  259. RESULT
  260.     history  =  Pointer  to the history structure node if found, else
  261.                 NULL.
  262.  
  263. EXAMPLE
  264.     struct Line *line;
  265.     struct History *history;
  266.     ...
  267.  
  268.     history = GetHistory(line,1);
  269.     if (history)
  270.         printf("%s\n",history->buf);
  271.  
  272. SEE ALSO
  273.     MakeHistory
  274.     ShowHistory
  275.     DeleteHistory
  276.  
  277. ---------------------------------------------------------------------
  278.  
  279. NAME
  280.     GetKey  --  Get  a  character from the standard input if there is
  281.                 one, else return immediately.
  282.  
  283. SYNOPSIS
  284.     key = GetKey(line,caps,echo)
  285.  
  286.     char key;
  287.     struct Line *line;
  288.     BOOL caps;
  289.     BOOL echo;
  290.  
  291. FUNCTION
  292.     Read a character from the standard input if possible, else return
  293.     immediately.  This is particular useful for "hot-keys" in menuing
  294.     systems.
  295.  
  296. INPUTS
  297.     line = line structure
  298.     caps = if TRUE capitalize the character typed.
  299.     echo = if TRUE echo the character typed.
  300.  
  301. RESULT
  302.     key = if non-zero this is the character typed.
  303.  
  304. SEE ALSO
  305.     WaitKey
  306.  
  307. ---------------------------------------------------------------------
  308.  
  309. NAME
  310.     KeyPressed -- Check if the user has pressed a key.
  311.  
  312.  
  313. SYNOPSIS
  314.     pressed = KeyPressed(line);
  315.  
  316.     BOOL pressed;
  317.     struct Line *line;
  318.  
  319. FUNCTION
  320.     After  StartAsyncRead() has been called use this routine to check
  321.     if  any key has been pressed or end-of-file has been reached.  If
  322.     line->flag  has  LNF_EOF  set  then  the file has reached end, in
  323.     which case your program should exit.  If a key is pressed it will
  324.     be    stored    in   line->InputChar.    You   should   not   use
  325.     GetMsg(line->ReadReplyPort)    or   WaitPort(line->ReadReplyPort)
  326.     because  this  routine  does  more  than  that, it sets important
  327.     variables.   After  a  key has been pressed call StartAsyncRead()
  328.     for the next character to be read.
  329.  
  330. INPUT
  331.     line = line structure to check of any key presses.
  332.  
  333. RESULT
  334.     pressed = if TRUE a key has been pressed.  Read line->InputChar
  335.               for the character.
  336.  
  337. SEE ALSO
  338.     StartAsyncRead
  339.  
  340. ---------------------------------------------------------------------
  341.  
  342. NAME
  343.     MakeHistory -- Add a buffer to the history list.
  344.  
  345. SYNOPSIS
  346.     void MakeHistory(line,buf,len)
  347.  
  348.     struct Line *line;
  349.     char *buf;
  350.     long len;
  351.  
  352. FUNCTIONS
  353.     This  routine  will add a new history line into history list.  If
  354.     the  current  number  of  history lines is at maximum, the oldest
  355.     history  line  will be deleted, and the new one added.  After the
  356.     user  enters  a  command line buffer, it automatically adds it to
  357.     the history list, so you need not call this routine yourself.
  358.  
  359. INPUT
  360.     line = Line structure in which to put the new history.
  361.     buf = Buffer to add to history list.
  362.     len = Length of buffer, if -1L it'll use strlen(buf).
  363.           If len == 0, buf is not added to the history list.
  364.  
  365. RESULT
  366.     none
  367.    
  368. EXAMPLE
  369.     struct Line *line;
  370.  
  371.     ...
  372.     MakeHistory(line,"New history line coming in...",-1L);
  373.  
  374. SEE ALSO
  375.     DeleteHistory
  376.     GetHistory
  377.     ShowHistory
  378.  
  379. ---------------------------------------------------------------------
  380.  
  381. NAME
  382.     PauseKey -- Check  to  see if the user has typed a character that
  383.                 should cause the standard output to pause.
  384.  
  385. SYNOPSIS
  386.     key = PauseKey(line,pause_key,unpause_key,pause_text)
  387.  
  388.     char key;
  389.     struct Line *line;
  390.     char pause_key;
  391.     char unpause_key;
  392.     char *pause_text;
  393.  
  394. FUNCTION
  395.     This  routine  is  particular useful for checking if the user has
  396.     pressed  a  key  to  pause of the output on the screen.  When the
  397.     user  has  pressed  the  pause  key, this routine will not return
  398.     until  either  the  unpause  key  is  pressed,  a break signal is
  399.     received,  or  the  end-of-life  is  reached.   If any exceptions
  400.     occured, you should read line->flag.
  401.  
  402. EXAMPLE
  403.  
  404.     int i;
  405.     struct Line *line;
  406.  
  407.     ...
  408.     printf("Press ^S to pause output, ^Q to resume.\n");
  409.     for (i = 0; i < 100; ++i)
  410.     {
  411.         printf("%ld\n",i);
  412.         PauseKey(line,0x13,0x11,"[PAUSED]");
  413.     }
  414.  
  415. INPUTS
  416.     line = line structure.
  417.     pause_key  = the key the user needs to press to cause the routine
  418.                  to block until the unpause character is pressed.  -1
  419.                  if any key can be used to cause outputting to pause.
  420.     unpause_key  =  the  key  the  user needs to press to unblock the
  421.                     program  when  he/she has pressed the paused key.
  422.                     -1 if any key can be used to cause outputting to
  423.                     be unpaused.
  424.     pause_text  = text to display when the user has pressed the pause
  425.                   key.   NULL if such output is not wanted.  The text
  426.                   will be erased when the unpause key is pressed.
  427.  
  428. RESULT
  429.     key  =  if  non-zero, the key the user typed when this routine is
  430.             called.    Generally,  this  character  is  the  same  as
  431.             unpause_key, unless no pause key is pressed.
  432.  
  433. SEE ALSO
  434.     WaitKey
  435.     GetKey
  436.  
  437. ---------------------------------------------------------------------
  438.  
  439. NAME
  440.     RawGets  --  Synchronously get a command buffer from the standard
  441.                  input handler.
  442.  
  443. SYNOPSIS
  444.     count = RawGets(line,buf,buflen,defsize,hotkey,caps,echo)
  445.  
  446.     long count;
  447.     struct Line *line;
  448.     char *buf;
  449.     unsigned long buflen;
  450.     unsigned long defsize;
  451.     BOOL hotkey;
  452.     BOOL caps;
  453.     BOOL echo;
  454.  
  455. FUNCTION
  456.     Get  a line of input from the user.  This routine will not return
  457.     until either the user has pressed a carriage return, the break
  458.     signal is received, or end of file is reached.
  459.  
  460. EXAMPLE
  461.     void main(void)
  462.     {
  463.         char    name[30],
  464.                 pass[30],
  465.                 comp[30],
  466.                 key[2];
  467.  
  468.         printf("Enter your name => ");
  469.         RawGets(name,30,0,FALSE,FALSE,TRUE);
  470.         printf("Enter your password => ");
  471.         RawGets(pass,30,0,FALSE,FALSE,FALSE);
  472.         printf("Enter your computer type => ");
  473.         strcpy(comp,"Amiga!");    /* if user just presses return,
  474.                "Amiga!" is accepted */
  475.         RawGets(comp,30,strlen(comp),FALSE,FALSE,TRUE);
  476.         printf("Press any key to continue...");
  477.         RawGets(key,2,0,TRUE,FALSE,FALSE);
  478.     }
  479.  
  480. INPUT
  481.     buflen = Length of buffer, including the null-termination char.
  482.     line = Line structure allocated by AllocLine().
  483.     defsize = The default size of the buffer to display.
  484.     hotkey = If TRUE return when the user has typed one character.
  485.     caps = If TRUE capitalizes everything the users types.
  486.     echo = If TRUE echo back what the user typed.
  487.  
  488. RESULT
  489.     count = Number of characters entered by the user.
  490.             0 if the user pressed return on a blank line.
  491.             -1 if failure, either due to EOF or signal break.
  492.  
  493. ---------------------------------------------------------------------
  494.  
  495. NAME
  496.     RawMode -- Turn the standard input file handle into raw mode.
  497.  
  498. SYNOPSIS
  499.     void RawMode(line,raw)
  500.  
  501.     struct Line *line;
  502.     BOOL raw;
  503.  
  504. FUNCTION
  505.     This  routine  sends  a ACTION_SCREEN_MODE packet to the standard
  506.     input  file  handle  to  tell  it to go into raw mode if it's not
  507.     already  in raw mode.  In raw mode, characters can be read one at
  508.     a  time,  without making the user press return for the line to be
  509.     accepted.   You  normally  would  not  need  to call this routine
  510.     yourself as all of RawIN.lib's routines call it for you.
  511.  
  512. EXAMPLE
  513.     RawMode(line,FALSE);
  514.     system("list c:");
  515.  
  516. INPUTS
  517.     line = line structure.
  518.     raw = if TRUE to go into raw mode, FALSE to go into cooked mode.
  519.  
  520. RESULT
  521.     none
  522.  
  523. ---------------------------------------------------------------------
  524.  
  525. NAME
  526.     ResetLine -- Prepare a Line structure for the next use.
  527.  
  528. SYNOPSIS
  529.     void ResetLine(line)
  530.  
  531.     struct Line *line;
  532.  
  533. FUNCTIONS
  534.     Reset all indices, etc. so that Line structure can be used again.
  535.  
  536. INPUT
  537.     line = Line to reset.
  538.  
  539. RESULT
  540.     none
  541.  
  542. ---------------------------------------------------------------------
  543.  
  544. NAME
  545.     ShowHistory  --  Display any number of history lines in any range
  546.                      or order.
  547.  
  548. SYNOPSIS
  549.     void ShowHistory(line,hist_start,hist_lines,reverse)
  550.  
  551.     struct Line *line;
  552.     long hist_start;
  553.     long hist_lines;
  554.     BOOL reverse;
  555.  
  556. FUNCTIONS
  557.     Display  the  numbered  history  lines  in  the  order  and range
  558.     specified.   If  the  order  is  reverse,  the  last line will be
  559.     displayed first, and the first displayed last.
  560.  
  561. INPUT
  562.     line = Line structure where the history lines are found.
  563.     hist_start  =  The location where history lines start to display.
  564.                    1 is first, -1 is last.
  565.     hist_lines  =  The  number  of  history lines to display.  If -1,
  566.                    display all.
  567.     reverse  =  If  TRUE  then  display  in  descending  order,  else
  568.                 otherwise.
  569.  
  570. RESULT
  571.     none
  572.  
  573. SEE ALSO
  574.     MakeHistory
  575.     GetHistory
  576.     DeleteHistory
  577.  
  578. ---------------------------------------------------------------------
  579.  
  580. NAME
  581.     StartAsyncRead  --  Start  an asynchronous read from the standard
  582.                         input.
  583.  
  584. SYNOPSIS
  585.     void StartAsyncRead(line)
  586.  
  587.     struct Line *line;
  588.  
  589. FUNCTION
  590.     A  ACTION_READ  packet is sent to the input handler to tell it we
  591.     want  to  get a character.  Use KeyPressed() to check if the user
  592.     has  typed something or there is an EOF.  Look at line->InputChar
  593.     for the character returned.
  594.  
  595. INPUTS
  596.     line = line structure.
  597.  
  598. RESULT
  599.     none
  600.  
  601. SEE ALSO
  602.     KeyPressed
  603.  
  604. ---------------------------------------------------------------------
  605.  
  606. NAME
  607.     WaitKey -- Get a character from the standard input.
  608.  
  609. SYNOPSIS
  610.     key = WaitKey(line,caps,echo)
  611.  
  612.     char key;
  613.     struct Line *line;
  614.     BOOL caps;
  615.     BOOL echo;
  616.  
  617. FUNCTION
  618.     This  routine  will attempt to read a character from the standard
  619.     input.   Your program will be blocked until either a character is
  620.     typed,  a break signal is received, or end of file.  This routine
  621.     is particular useful for single character respones from the user.
  622.  
  623. EXAMPLE
  624.     struct Line *line;
  625.     char key;
  626.  
  627.     ...
  628.     printf("Press any key to continue...");
  629.     key = WaitKey(line,FALSE,FALSE);
  630.     
  631. INPUTS
  632.     line = line structure.
  633.     caps = capitalizes the character typed.
  634.     echo = if TRUE echo the character back, else don't echo.
  635.  
  636. RESULT
  637.     key = A non-zero ASCII character if successful.
  638.           Otherwise, read line->flag for reason.
  639.  
  640. SEE ALSO
  641.     GetKey
  642.  
  643. ---------------------------------------------------------------------
  644.  
  645. =====================================================================
  646. COMMAND LINE EDITING FEATURES
  647. =============================
  648.  
  649. Key                ANSI     Effect
  650. ---------------------------------------------------------------------
  651. Cursor-left        ^[[D     move one character to the left
  652. Cursor-right       ^[[C     move one character to the right
  653. Shift-cursor-left  ^[[ A,^A move to the beginning of the line
  654. Shift-cursor-right ^[[ @,^Z move to the end of the line
  655. Backspace          ^H       delete last character
  656. Del                127      delete the character under the cursor
  657. Return/Enter       ^M       process command line
  658.                    ^W       move cursor one tab stop to the right
  659.                    ^X       delete current line
  660.                    ^K       delete everything from the cursor forward
  661.                             to the end of the line
  662.                    ^U       delete everything from the cursor
  663.                             backward to the start of the line
  664. Cursor-up          ^[[A     move backward in the history buffer
  665.                             (earlier lines)
  666. Cursor-down        ^[[B     move forward in the history buffer
  667.                             (latter lines)
  668. Shift-cursor-up    ^[[T,^R  search backward through history buffer
  669.                             for given command line or fragment
  670. Shift-cursor-down  ^[[S     move to the bottom of the history buffer,
  671.                             with cusor on blank line
  672.                    ^F       move to last word
  673.                    ^G       move to next word
  674.                    ^V       move halfway backward toward the start of
  675.                             the line
  676.                    ^B       move halfway forward toward the end of
  677.                             the line
  678.                    ^E       delete the word under the cursor
  679. ---------------------------------------------------------------------
  680. NOTE: 1. ^x is Ctrl-x (Hold down the control "Ctrl" key and type x)
  681.       2. Some terminal programs do not support shifted cursor keys.
  682.  
  683.  
  684. =====================================================================
  685. REQUIREMENTS
  686. ============
  687.  
  688. The  test  program  and  the library runs on any Amiga with OS 1.2 or
  689. higher.
  690.  
  691.  
  692. =====================================================================
  693. LAST WORDS
  694. ==========
  695.  
  696. No  fee  is required for usage of this program, but I will accept any
  697. donations  of  money.   If  you donate over $5 and request it, I will
  698. send  you the latest version of RawIN.lib, including the source code.
  699. Please let me know if you find this library useful, so that will give
  700. me incentive to write other similiar libraries.
  701.  
  702. Donations, comments, and bug reports should be sent to:
  703.  
  704. Home Address: Sam Yee
  705.               c/o Utilities
  706.               4595 Nanaimo St.
  707.               Vancouver, B.C.
  708.               Canada  V5N-5J5
  709.  
  710.     Internet: samy@sfu.ca (starting September '92)
  711.               flui@sfu.ca (before September '92)
  712.  
  713.      FidoNet: 1:153/765 (Terra Firma BBS 604-434-3665)
  714.  
  715.