home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / UTIL / WWIVE / SHRINK.C < prev    next >
C/C++ Source or Header  |  1991-04-06  |  5KB  |  249 lines

  1. /*****************************************************************************
  2.  
  3.                                 WWIV Version 4
  4.                     Copyright (C) 1988-1991 by Wayne Bell
  5.  
  6. Distribution of the source code for WWIV, in any form, modified or unmodified,
  7. without PRIOR, WRITTEN APPROVAL by the author, is expressly prohibited.
  8. Distribution of compiled versions of WWIV is limited to copies compiled BY
  9. THE AUTHOR.  Distribution of any copies of WWIV not compiled by the author
  10. is expressly prohibited.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15.  
  16.  
  17. #include "vars.h"
  18.  
  19. #pragma hdrstop
  20.  
  21. #include <process.h>
  22. #include <dir.h>
  23.  
  24.  
  25.  
  26. #define READ(x) read(f,&(x),sizeof(x))
  27.  
  28. #define WRITE(x) write(f,&(x),sizeof(x))
  29.  
  30.  
  31. /****************************************************************************/
  32.  
  33. int restore_data(char *s)
  34. {
  35.   int f,stat;
  36.  
  37.   f=open(s,O_RDONLY | O_BINARY);
  38.   if (f<0)
  39.     return(-1);
  40.  
  41.   READ(stat);
  42.   READ(oklevel);
  43.   READ(noklevel);
  44.   READ(ooneuser);
  45.   READ(no_hangup);
  46.   READ(ok_modem_stuff);
  47.   READ(topdata);
  48.   READ(last_time_c);
  49.   READ(sysop_alert);
  50.   READ(do_event);
  51.  
  52.   if (stat) {
  53.     READ(andwith);
  54.     READ(usernum);
  55.     READ(chatcall);
  56.     READ(chatreason);
  57.     READ(timeon);
  58.     READ(extratimecall);
  59.     READ(curspeed);
  60.     READ(modem_speed);
  61.     READ(com_speed);
  62.     READ(cursub);
  63.     READ(curdir);
  64.     READ(curdloads);
  65.     READ(msgreadlogon);
  66.     READ(nscandate);
  67.     READ(mailcheck);
  68.     READ(smwcheck);
  69.     READ(use_workspace);
  70.     READ(using_modem);
  71.     READ(last_time);
  72.     READ(fsenttoday);
  73.     READ(global_xx);
  74.     READ(xtime);
  75.     READ(xdate);
  76.     READ(incom);
  77.     READ(outcom);
  78.     READ(global_handle);
  79.     READ(actsl);
  80.  
  81.     if (global_handle) {
  82.       global_handle=0;
  83.       set_global_handle(1);
  84.     }
  85.  
  86.     read_user(usernum,&thisuser);
  87.     useron=1;
  88.     changedsl();
  89.     topscreen();
  90.     set_baud(com_speed);
  91.   }
  92.  
  93.   close(f);
  94.   unlink(s);
  95.   unlink("stat.wwv");
  96.   return(stat);
  97. }
  98.  
  99. /****************************************************************************/
  100.  
  101. void save_state(char *s, int state,int ctc)
  102. {
  103.   int f;
  104.  
  105.   save_status();
  106.  
  107.   f=open(s,O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  108.   if (f<0)
  109.     return;
  110.  
  111.   WRITE(state);
  112.   WRITE(oklevel);
  113.   WRITE(noklevel);
  114.   WRITE(ooneuser);
  115.   WRITE(no_hangup);
  116.   WRITE(ok_modem_stuff);
  117.   WRITE(topdata);
  118.   WRITE(last_time_c);
  119.   WRITE(sysop_alert);
  120.   WRITE(do_event);
  121.  
  122.   if (state) {
  123.     WRITE(andwith);
  124.     WRITE(usernum);
  125.     WRITE(chatcall);
  126.     WRITE(chatreason);
  127.     WRITE(timeon);
  128.     WRITE(extratimecall);
  129.     WRITE(curspeed);
  130.     WRITE(modem_speed);
  131.     WRITE(com_speed);
  132.     WRITE(cursub);
  133.     WRITE(curdir);
  134.     WRITE(curdloads);
  135.     WRITE(msgreadlogon);
  136.     WRITE(nscandate);
  137.     WRITE(mailcheck);
  138.     WRITE(smwcheck);
  139.     WRITE(use_workspace);
  140.     WRITE(using_modem);
  141.     WRITE(last_time);
  142.     WRITE(fsenttoday);
  143.     WRITE(global_xx);
  144.     WRITE(xtime);
  145.     WRITE(xdate);
  146.     WRITE(incom);
  147.     WRITE(outcom);
  148.     WRITE(global_handle);
  149.     WRITE(actsl);
  150.  
  151.     set_global_handle(0);
  152.   }
  153.  
  154.   close(f);
  155.  
  156.   if (state) {
  157.     f=open("stat.wwv",O_RDWR | O_BINARY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
  158.     if (f<0)
  159.       return;
  160.  
  161.     WRITE(incom);
  162.     WRITE(outcom);
  163.     WRITE(thisuser);
  164.     WRITE(flow_control);
  165.     WRITE(async_irq);
  166.     WRITE(com_speed);
  167.     WRITE(base);
  168.     WRITE(andwith);
  169.     WRITE(ctc);
  170.     WRITE(defscreenbottom);
  171.     WRITE(ok_modem_stuff);
  172.  
  173.     close(f);
  174.   }
  175.  
  176.  
  177. }
  178.  
  179. /****************************************************************************/
  180.  
  181. void do_it_1(char *cl)
  182. {
  183.   int i,i1,l;
  184.   char *ss,*ss1;
  185.   char t[81];
  186.  
  187.   sl1(1,"");
  188.   ss=cl;
  189.   while ((*ss) && (*ss!=' '))
  190.     ++ss;
  191.   if (*ss==' ') {
  192.     *ss=0;
  193.     ss++;
  194.   }
  195.   ss1=(char far *) getvect(INT_SHRINK);
  196.   if (ok_modem_stuff)
  197.     closeport();
  198.   close_user();
  199.   *ss1=1;
  200.   ss1++;
  201.   strcpy(ss1,searchpath(cl));
  202.   ss1=MK_FP(FP_SEG(ss1),0x0080);
  203.   strcpy(t," ");
  204.   strcat(t,ss);
  205.   strcat(t,"\r");
  206.   *ss1=strlen(t)-1;
  207.   ++ss1;
  208.   strcpy(ss1,t);
  209.   exit(0);
  210. }
  211.  
  212. /****************************************************************************/
  213.  
  214. void shrink_out(char *command, int state, int intercept,int ctc,int ccc)
  215. {
  216.   char s[81],s1[10],*ss1;
  217.   int ok_shrink;
  218.  
  219.   ok_shrink=1;
  220.   ss1=(char far *) getvect(INT_SHRINK);
  221.   if (*ss1) {
  222.     ok_shrink=0;
  223.     nl();
  224.     pl("Can't shrink: No BBS.COM");
  225.     nl();
  226.   }
  227.   if (!searchpath("RETURN.EXE")) {
  228.     ok_shrink=0;
  229.     nl();
  230.     pl("Can't shrink: No RETURN.EXE");
  231.     nl();
  232.   }
  233.  
  234.   if (ok_shrink) {
  235.     if (state) {
  236.       write_user(usernum,&thisuser);
  237.     }
  238.     save_state("restore.wwv",state,ctc);
  239.     sprintf(s,"RETURN.EXE %d %d %s",intercept,ccc,command);
  240.     set_protect(0);
  241.     do_it_1(s);
  242.   } else {
  243.     if (intercept)
  244.       full_external(command,ctc,ccc);
  245.     else
  246.       do_remote(command,ccc);
  247.   }
  248. }
  249.