home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / modem.madness / SMMNETML / AMAX_230.ZIP / SOURCES.ZIP / AMAXIN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-15  |  7.7 KB  |  288 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /* Module Name:   AMAXIN.C                                                   */
  4. /* Program Name:  AMAX                                                       */
  5. /* Revision:      2.xx                                                       */
  6. /* Purpose:       Input Routines Module                                      */
  7. /* Programmer:    Alan D. Bryant                                             */
  8. /*                                                                           */
  9. /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved.       */
  10. /*                                                                           */
  11. /* NOTICE:  This source code is copyrighted material.  You are granted a     */
  12. /* limited license to use and distribute the code.  The complete text of     */
  13. /* the license can be found in the document LICENSE.DOC which accompanies    */
  14. /* this source code, or can be obtained directly from the author.            */
  15. /*                                                                           */
  16. /* Inquiries regarding this package should be directed to:                   */
  17. /*                                                                           */
  18. /*     AMAX                                                                  */
  19. /*     Alan D. Bryant                                                        */
  20. /*     P. O. Box 101612                                                      */
  21. /*     Denver, CO  80250                                                     */
  22. /*     USA                                                                   */
  23. /*                                                                           */
  24. /*---------------------------------------------------------------------------*/
  25.  
  26. #include <dos.h>
  27. #include <ctype.h>
  28. #include <bios.h>
  29. #include <stdio.h>
  30. #include "amax.h"
  31.  
  32.  
  33. extern char disptime;
  34.  
  35. void getln(char *, unsigned int);
  36. unsigned char menu_select(char *);
  37. unsigned char agetch();
  38. int fgetln(unsigned char *, unsigned int, unsigned char [3], FILE *);
  39.  
  40.  
  41. void getln(char *line, unsigned int length)
  42. {
  43.     int x;
  44.     unsigned int y;
  45.     unsigned char ch;
  46.     unsigned char out[100] = "";
  47.     unsigned char mode = 0;
  48.  
  49.     char exit =  0x00;
  50.  
  51.     if (length >= 500) {
  52.         length -= 500;
  53.         mode = 1;
  54.     }
  55.  
  56.     x = -1;
  57.  
  58.     vreverse();
  59.  
  60.     if (strlen(line) > 0) {
  61.         output(line);
  62.         x = strlen(line) - 1;
  63.         }
  64.  
  65.  
  66.     while (! exit) {
  67.         ch = 0x00;
  68.         while (! ch) {
  69.             ch = agetch();
  70.         }
  71.  
  72.         /*  if an escape, forget it and return  */
  73.  
  74.         if (ch == 0x1B) {
  75.             line[0] = 0x00;
  76.             output("\r\n");
  77.             vnormal();
  78.             return;
  79.         }
  80.  
  81.         /*  if it's a control code, get the next character  */
  82.  
  83.         if (ch < 0x08) continue;
  84.         if (ch > 0x08 && ch < 0x0D) continue;
  85.         if (ch > 0x0D && ch < 0x1B) continue;
  86.  
  87.         /*  not an escape, so go ahead and print the character  */
  88.  
  89.         ++x;
  90.         sprintf(out, "%c", ch);
  91.         output(out);
  92.         line[x] = ch;
  93.  
  94.         /*  if a backspace, handle it (thanks)  */
  95.  
  96.         if (ch == 0x08) {
  97.             if (x == 0) {
  98.                 vnormal();
  99.                 output(" ");
  100.                 vreverse();
  101.             }
  102.             if (x != 0) {
  103.                 --x;
  104.             }
  105.             --x;
  106.             if (! direct) output(" \x08");
  107.             else {
  108.                 output(" ");
  109.                 gotoxy(wherex() - 1, wherey());
  110.             }
  111.         }
  112.  
  113.         /*  if a carriage return, output a linefeed, end in a null, return  */
  114.  
  115.         if (ch == 0x0D) {
  116.             output("\x0A");
  117.             line[x] = 0x00;
  118.             if (mode && x > 0) {
  119.                 line[x] = 0x0D;
  120.                 line[x+1] = 0x0A;
  121.                 line[x+2] = 0x00;
  122.             }
  123.             vnormal();
  124.             return;
  125.         }
  126.  
  127.         /*  if we're at the end of the line, beep like mad and  */
  128.         /*  stop the user from entering anything else but a     */
  129.         /*  backspace or carriage return (thanks)               */
  130.  
  131.         if (x == length) {
  132.             if (! direct) output("\x08 \x08");
  133.             else {
  134.                 gotoxy(wherex() - 1, wherey());
  135.                 output(" ");
  136.                 gotoxy(wherex() - 1, wherey());
  137.             }
  138.             --x;
  139.         }
  140.  
  141.         /*  if space is typed within 10 chars from end, then wrap  */
  142.         /*  but put a null at the end of the line first            */
  143.         /*  do this only if in text mode (mode == 1)               */
  144.  
  145.         if (mode) {
  146.             if (x > (length - 10) && ch == ' ') {
  147.                 line[x] = 0x00;
  148.                 output("\r\n");
  149.                 vnormal();
  150.                 return;
  151.             }
  152.         }
  153.  
  154.         /*  Charlie:  the previous 5 lines are all there is to the  */
  155.         /*  line wrap code...whooppee, huh?  <grin>                 */
  156.  
  157.     }
  158.     line[x] = 0x00;
  159.     vnormal();
  160.     return;
  161. }
  162.  
  163.  
  164.  
  165. unsigned char menu_select(char *possible)
  166. {
  167.     unsigned char ch = 0xFF;
  168.     unsigned char choices[25];
  169.     extern char series[80];
  170.     extern unsigned char series_pos;
  171.  
  172.     if (strlen(series)) {
  173.         if (series_pos <= strlen(series)) {
  174.             ch = series[series_pos];
  175.             ++series_pos;
  176.             if (ch == '=') ch = '\r';
  177.             return ch;
  178.         }
  179.     }
  180.  
  181.     strcpy(choices, possible);
  182.  
  183.     while (! strchr(choices, ch)) {
  184.         if (disptime) display_time(1);
  185.         while (! kbhit()) {
  186.             if (disptime) display_time(0);
  187.         }
  188.         ch = agetch();
  189.         if (ch > 96 && ch < 123) ch -= 32;
  190.     }
  191.     return ch;
  192. }
  193.  
  194.  
  195. unsigned char agetch()
  196. {
  197.     extern char extkey;
  198.     extern char series[80];
  199.     extern unsigned char series_pos;
  200.  
  201.     unsigned int key;
  202.     unsigned char ch;
  203.     char wait = 1;
  204.  
  205.     if (strlen(series)) {
  206.         if (series_pos <= strlen(series)) {
  207.             ch = series[series_pos];
  208.             ++series_pos;
  209.             if (ch == '=') ch = '\r';
  210.             return ch;
  211.         }
  212.     }
  213.  
  214.     if (extkey) {
  215.         while (wait) {
  216.  
  217.             /*  wait for keypress  */
  218.  
  219.             while (bioskey(1) == 0);
  220.  
  221.             /*  get keypress  */
  222.  
  223.             key = bioskey(0);
  224.  
  225.             if (key & 0xFF) {
  226.                 return key;
  227.             }
  228.  
  229.             else {
  230.                 if (key == 0x4800) return 0x18;   /* up arrow */
  231.                 if (key == 0x5000) return 0x19;   /* down arrow */
  232.                 if (key == 0x4900) return 0x1E;   /* page up */
  233.                 if (key == 0x5100) return 0x1F;   /* page down */
  234.             }
  235.         }
  236.     }
  237.     else {
  238.         ch = getch();
  239.         return ch;
  240.     }
  241.     return 0x00;
  242. }
  243.  
  244.  
  245. #define LF      0x0A
  246. #define CR      0x0D
  247. #define EOD     0x1A
  248. #define LFH     0x8A
  249. #define CRH     0x8D
  250.  
  251. int fgetln(unsigned char *buffer, unsigned int limit, unsigned char eolbfr[3], FILE *stream)
  252. {
  253.     unsigned int x;
  254.     unsigned int y = 0;
  255.     int ch;
  256.  
  257.     for (x = 0; x < limit; x++) {
  258.         buffer[x] = 0x00;
  259.     }
  260.  
  261.     strcpy(eolbfr, "\0x00\0x00\0x00");
  262.  
  263.     for (x = 0; x < limit - 1; x++) {
  264.         ch = fgetc(stream);
  265.         if (ch == EOD || ch == EOF) return EOF;
  266.         if (ch == LF || ch == CR || ch == LFH || ch == CRH) {
  267.             eolbfr[y] = ch;
  268.             ++y;
  269.             ch = fgetc(stream);
  270.             if (ch == LF || ch == CR || ch == LFH || ch == CRH) {
  271.                 eolbfr[y] = ch;
  272.                 return 0x01;
  273.             }
  274.             else {
  275.                 ungetc(ch, stream);
  276.                 return 0x01;
  277.             }
  278.         }
  279.     else buffer[x] = ch;
  280.     }
  281.     buffer[limit] = 0x00;
  282.     return 0x01;
  283. }
  284.  
  285.  
  286.  
  287.  
  288.