home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / input.c < prev    next >
Text File  |  1998-08-01  |  10KB  |  388 lines

  1.  
  2. // LoraBBS Version 2.41 Free Edition
  3. // Copyright (C) 1987-98 Marco Maccaferri
  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., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <stdio.h>
  20. #include <conio.h>
  21. #include <ctype.h>
  22. #include <string.h>
  23. #include <dir.h>
  24.  
  25. #include <cxl\cxlwin.h>
  26.  
  27. #include "lsetup.h"
  28. #include "sched.h"
  29. #include "msgapi.h"
  30. #include "externs.h"
  31. #include "prototyp.h"
  32.  
  33. #include <cxl/cxlstr.h>
  34.  
  35. static long online_msg;
  36. static int read_online_message(void);
  37.  
  38. int freeze = 0;
  39. char num_hotkey = 0;
  40.  
  41. void VioUpdate (void);
  42.  
  43. void input(s,width)
  44. char *s;
  45. int width;
  46. {
  47.    chars_input(s,width,0);
  48. }
  49.  
  50. void inpwd(s,width)
  51. char *s;
  52. int width;
  53. {
  54.    chars_input(s,width,INPUT_PWD);
  55. }
  56.  
  57. void cmd_input(s,width)
  58. char *s;
  59. int width;
  60. {
  61.    chars_input(s,width,INPUT_HOT);
  62. }
  63.  
  64. void fancy_input(s,width)
  65. char *s;
  66. int width;
  67. {
  68.    chars_input(s,width,INPUT_FANCY);
  69. }
  70.  
  71. void update_input(s,width)
  72. char *s;
  73. int width;
  74. {
  75.    chars_input(s,width,INPUT_UPDATE);
  76. }
  77.  
  78. void chars_input (char *s, int width, int flag)
  79. {
  80.    char autozm[10];
  81.    unsigned char c;
  82.    int i, upper;
  83.    long inactive, warning, checktime;
  84.  
  85.    upper = 1;
  86.    online_msg = timerset(200);
  87.    cmd_string[0] = '\0';
  88.    if (config->inactivity_timeout) {
  89.       inactive = timerset (0);
  90.       warning = timerset (0);
  91.       inactive += config->inactivity_timeout * 6000L;
  92.       warning += config->inactivity_timeout * 6000L - 2000L;
  93.    }
  94.    else
  95.       warning = inactive = 0L;
  96.  
  97.    if (!local_mode)
  98.       UNBUFFER_BYTES ();
  99.  
  100.    if ((flag & INPUT_FIELD) && usr.color) {
  101.       space (width);
  102.       for (i=0;i<width;i++) {
  103.           if (!local_mode)
  104.              SENDBYTE('\b');
  105.           if (snooping)
  106.              wputs("\b");
  107.       }
  108.    }
  109.  
  110.    if (flag & INPUT_UPDATE) {
  111.       m_print (s);
  112.       i = strlen (s);
  113.    }
  114.    else
  115.       i = 0;
  116.  
  117.    VioUpdate ();
  118.  
  119.    while (CARRIER) {
  120.       if (!local_mode) {
  121.          while (!CHAR_AVAIL ()) {
  122.             if (!CARRIER)
  123.                return;
  124.  
  125.             if (freeze && config->inactivity_timeout) {
  126.                freeze = 0;
  127.  
  128.                inactive = timerset (0);
  129.                warning = timerset (0);
  130.                inactive += config->inactivity_timeout * 6000L;
  131.                warning += config->inactivity_timeout * 6000L - 2000L;
  132.             }
  133.  
  134.             if (inactive && !freeze) {
  135.                if (timeup (inactive)) {
  136.                   m_print (bbstxt[B_INACTIVE_HANG]);
  137.                   terminating_call ();
  138.                   get_down (aftercaller_exit, 2);
  139.                }
  140.                if (warning && timeup (warning)) {
  141.                   m_print (bbstxt[B_INACTIVE_WARN]);
  142.                   warning = 0L;
  143.                }
  144.             }
  145.  
  146.             if (time_remain () <= 0) {
  147.                m_print(bbstxt[B_TIMEOUT]);
  148.                terminating_call ();
  149.                get_down (aftercaller_exit, 2);
  150.             }
  151.  
  152.             if (read_online_message ()) {
  153.                s[0] = '\0';
  154.                return;
  155.             }
  156.  
  157.             if (local_kbd == 0x2E00) {
  158.                sysop_chatting ();
  159.                s[0] = '\0';
  160.                s[1] = 5;
  161.                return;
  162.             }
  163.             else if (local_kbd != -1)
  164.                break;
  165.  
  166.             checktime = time (NULL);
  167.  
  168.             time_release ();
  169.             release_timeslice ();
  170.  
  171.             if (freeze && config->inactivity_timeout) {
  172.                if (time (NULL) - checktime > 10) {
  173.                   freeze = 0;
  174.  
  175.                   inactive = timerset (0);
  176.                   warning = timerset (0);
  177.                   inactive += config->inactivity_timeout * 6000L;
  178.                   warning += config->inactivity_timeout * 6000L - 2000L;
  179.                }
  180.             }
  181.          }
  182.  
  183.          if (local_kbd == -1)
  184.             c = (unsigned char)TIMED_READ(1);
  185.          else {
  186.             c = (unsigned char)local_kbd;
  187.             local_kbd = -1;
  188.          }
  189.       }
  190.       else {
  191.          while (local_kbd == -1) {
  192.             if (!CARRIER)
  193.                return;
  194.  
  195.             if (freeze && config->inactivity_timeout) {
  196.                freeze = 0;
  197.  
  198.                inactive = timerset (0);
  199.                warning = timerset (0);
  200.                inactive += config->inactivity_timeout * 6000L;
  201.                warning += config->inactivity_timeout * 6000L - 2000L;
  202.             }
  203.  
  204.             if (inactive && !freeze) {
  205.                if (timeup (inactive)) {
  206.                   m_print (bbstxt[B_INACTIVE_HANG]);
  207.                   terminating_call ();
  208.                   get_down (aftercaller_exit, 2);
  209.                }
  210.                if (warning && timeup (warning)) {
  211.                   m_print (bbstxt[B_INACTIVE_WARN]);
  212.                   warning = 0L;
  213.                }
  214.             }
  215.  
  216.             if (time_remain() <= 0) {
  217.                change_attr(LRED|_BLACK);
  218.                m_print(bbstxt[B_TIMEOUT]);
  219.                terminating_call ();
  220.                get_down (aftercaller_exit, 2);
  221.             }
  222.  
  223.             if (read_online_message()) {
  224.                s[0] = '\0';
  225.                return;
  226.             }
  227.  
  228.             checktime = time (NULL);
  229.  
  230.             time_release ();
  231.             release_timeslice ();
  232.  
  233.             if (freeze && config->inactivity_timeout) {
  234.                if (time (NULL) - checktime > 10) {
  235.                   freeze = 0;
  236.  
  237.                   inactive = timerset (0);
  238.                   warning = timerset (0);
  239.                   inactive += config->inactivity_timeout * 6000L;
  240.                   warning += config->inactivity_timeout * 6000L - 2000L;
  241.                }
  242.             }
  243.          }
  244.  
  245.          c = (unsigned char)local_kbd;
  246.          local_kbd = -1;
  247.       }
  248.  
  249.       if (config->inactivity_timeout) {
  250.          inactive = timerset (0);
  251.          warning = timerset (0);
  252.          inactive += config->inactivity_timeout * 6000L;
  253.          warning += config->inactivity_timeout * 6000L - 2000L;
  254.       }
  255.       else
  256.          warning = inactive = 0L;
  257.  
  258.       if(c == 0x0D)
  259.          break;
  260.  
  261.       if((c == 0x08 || c == 0x7F) && (i>0)) {
  262.          i--;
  263.          if (i <= 0 || s[i-1] == ' ' || s[i-1] == '_' || s[i-1] == '\'' || s[i-1] == '(' || s[i-1] == '\\')
  264.             upper = 1;
  265.          else
  266.             upper = 0;
  267.          s[i]='\0';
  268.          if (!local_mode) {
  269.             SENDBYTE('\b');
  270.             SENDBYTE(' ');
  271.             SENDBYTE('\b');
  272.          }
  273.          if (snooping)
  274.             wputs("\b \b");
  275.          continue;
  276.       }
  277.  
  278.       if (i >= width)
  279.          continue;
  280.  
  281.       if (c < 0x20 || ((flag & INPUT_FANCY) && c == ' ' && upper) )
  282.          continue;
  283.  
  284.       if (upper && (flag & INPUT_FANCY) && isalpha(c)) {
  285.          c = toupper(c);
  286.          upper = 0;
  287.       }
  288.       else if (flag & INPUT_FANCY)
  289.          c = tolower(c);
  290.  
  291.       s[i++]=c;
  292.  
  293.       if(flag & INPUT_PWD) {
  294.          if (!local_mode)
  295.             SENDBYTE('*');
  296.          if (snooping)
  297.         wputc('*');
  298.         VioUpdate ();
  299.       }
  300.       else {
  301.          if (!local_mode)
  302.             SENDBYTE(c);
  303.          if (snooping)
  304.         wputc(c);
  305.         VioUpdate ();
  306.       }
  307.  
  308.       if(c == ' ' || c == '_' || c == '\'' || c == '(')
  309.          upper = 1;
  310.  
  311.       online_msg = timerset(200);
  312.  
  313.       if ( (flag & INPUT_HOT) ) {
  314.          if ((!isdigit (c) || !num_hotkey) && i == 1)
  315.             break;
  316.       }
  317.    }
  318.  
  319.    if ((flag & INPUT_FIELD) && usr.color)
  320.       change_attr (LGREY|_BLACK);
  321.  
  322.    if (!stricmp (s, "rz")) {
  323.       get_emsi_id (autozm, 8);
  324.       if (!strncmp (autozm, "**B0000", 8)) {
  325.          if (!sys.filepath[0])
  326.             send_can ();
  327.          else
  328.             upload_file (NULL, 3);
  329.       }
  330.       s[0] = '\0';
  331.    }
  332.  
  333.    if(!(flag & INPUT_HOT) && !(flag & INPUT_NOLF)) {
  334.       if (!local_mode) {
  335.          SENDBYTE('\r');
  336.          SENDBYTE('\n');
  337.       }
  338.       if (snooping)
  339.          wputs("\n");
  340.    }
  341.  
  342.    s[i]='\0';
  343.    if (flag & INPUT_FANCY)
  344.       strtrim (s);
  345. }
  346.  
  347. static int read_online_message()
  348. {
  349.    int rc, i, m;
  350.    char filename[80], old_status;
  351.    struct ffblk blk;
  352.  
  353.    if (!timeup(online_msg))
  354.       return (0);
  355.  
  356.    sprintf (filename, "%sLEXIT*.*", config->sys_path);
  357.    if (!findfirst (filename, &blk, 0))
  358.       do {
  359.          i = m = 0;
  360.          sscanf (blk.ff_name, "LEXIT%d.%d", &i, &m);
  361.          if (i == line_offset || i == 0) {
  362.             unlink (blk.ff_name);
  363.             terminating_call ();
  364.             get_down (m, 3);
  365.          }
  366.       } while (!findnext (&blk));
  367.  
  368.    sprintf(filename, ONLINE_MSGNAME, ipc_path, line_offset);
  369.    if (dexists(filename) && user_status == BROWSING) {
  370.       old_status = user_status;
  371.       user_status = 0;
  372.  
  373.       read_file(filename);
  374.       unlink(filename);
  375.  
  376.       user_status = old_status;
  377.       rc = 1;
  378.    }
  379.    else
  380.       rc = 0;
  381.  
  382.    online_msg = timerset(200);
  383.    time_release ();
  384.  
  385.    return (rc);
  386. }
  387.  
  388.