home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / W / WWIVSOR.ZIP / BBSUTL1.C < prev    next >
C/C++ Source or Header  |  1995-05-12  |  20KB  |  857 lines

  1. /*****************************************************************************
  2.  
  3.                 WWIV Version 4
  4.                     Copyright (C) 1988-1995 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. #include "vars.h"
  16.  
  17. #pragma hdrstop
  18.  
  19. /****************************************************************************/
  20.  
  21. /*
  22.  * Returns 1 if local sysop functions accessible, else returns 0.
  23.  */
  24.  
  25. int ok_local(void)
  26. {
  27.   if (syscfg.sysconfig & sysconfig_no_local)
  28.     return(0);
  29.   else
  30.     return(1);
  31. }
  32.  
  33. /****************************************************************************/
  34.  
  35. /*
  36.  * Takes user name/handle as parameter, and returns user number, if found,
  37.  * else returns 0.
  38.  */
  39.  
  40. int finduser1(unsigned char *sx)
  41. {
  42.   int i,i1,i2;
  43.   unsigned char s[81],s1[81],ch;
  44.   userrec u;
  45.  
  46.   if (sx[0]==0)
  47.     return(0);
  48.   i=finduser(sx);
  49.   if (i>0)
  50.     return(i);
  51.   strcpy(s,sx);
  52.   for (i=0; s[i]!=0; i++)
  53.     s[i]=upcase(s[i]);
  54.   i2=0;
  55.   read_status();
  56.   for (i=0; (i<status.users) && (i2==0); i++) {
  57.     if (strstr(smallist[i].name,s)!=NULL) {
  58.       i1=smallist[i].number;
  59.       read_user(i1,&u);
  60.       sprintf(s1,"%s %s %s ? ",get_string(618), nam(&u,i1), get_string(619));
  61.       prt(5,s1);
  62.       ch=ynq();
  63.       if (ch=='Y')
  64.         i2=i1;
  65.       if (ch=='Q')
  66.         i=status.users;
  67.     }
  68.   }
  69.   return(i2);
  70. }
  71.  
  72. /****************************************************************************/
  73.  
  74. /*
  75.  * Creates sysoplog filename in s, from datestring.
  76.  */
  77.  
  78. void slname(char *d, char *s)
  79. {
  80.   sprintf(s,"%c%c%c%c%c%c.LOG",
  81.     d[6],d[7],d[0],d[1],d[3],d[4]);
  82. }
  83.  
  84. /****************************************************************************/
  85.  
  86. /*
  87.  * Returns instance (temporary) sysoplog filename in s.
  88.  */
  89.  
  90. void islname(char *s)
  91. {
  92.   sprintf(s,"INST-%3.3d.LOG",instance);
  93. }
  94.  
  95. /****************************************************************************/
  96.  
  97. #define CAT_BUFSIZE 8192
  98.  
  99. /*
  100.  * Copies temporary/instance sysoplog to primary sysoplog file.
  101.  */
  102.  
  103. void catsl(void)
  104. {
  105.   char s[81], s1[81], instname[81], wholename[81];
  106.   int fi, fo, i;
  107.   char *buf;
  108.  
  109.   islname(s1);
  110.   sprintf(instname,"%s%s",syscfg.gfilesdir, s1);
  111.  
  112.   if (exist(instname)) {
  113.     slname(date(), s);
  114.     sprintf(wholename, "%s%s",syscfg.gfilesdir, s);
  115.  
  116.     buf=malloca(CAT_BUFSIZE);
  117.     if (buf) {
  118.       fo=sh_open(wholename, O_RDWR|O_BINARY|O_CREAT, S_IREAD|S_IWRITE);
  119.       if (fo>0) {
  120.         sh_lseek(fo, 0L, SEEK_END);
  121.  
  122.         fi=sh_open1(instname, O_RDONLY|O_BINARY);
  123.         if (fi>0) {
  124.           do {
  125.             i=sh_read(fi, buf, CAT_BUFSIZE);
  126.             if (i>0)
  127.               sh_write(fo, buf, i);
  128.           } while (i==CAT_BUFSIZE);
  129.  
  130.           sh_close(fi);
  131.           unlink(instname);
  132.         }
  133.         sh_close(fo);
  134.       }
  135.       bbsfree(buf);
  136.     }
  137.   }
  138. }
  139.  
  140. /****************************************************************************/
  141.  
  142. /*
  143.  * Writes a line to the sysoplog.
  144.  */
  145.  
  146. void sl1(int cmd, char *s)
  147. {
  148.   static int midline=0;
  149.   static char slfn[81];
  150.   char l[180],ch1;
  151.   int i,f=-1;
  152.  
  153.   if (!slfn[0]) {
  154.     strcpy(slfn, syscfg.gfilesdir);
  155.     islname(slfn+strlen(slfn));
  156.   }
  157.  
  158.   switch(cmd) {
  159.     case 0: /* Write line to sysop's log */
  160.       f=sh_open(slfn,O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  161.       if (f<0) {
  162.         /* sysop log ? */
  163.         return;
  164.       }
  165.       if (filelength(f)) {
  166.         sh_lseek(f,-1L,SEEK_END);
  167.         sh_read(f,((void *)&ch1),1);
  168.         if (ch1==26)
  169.           sh_lseek(f,-1L,SEEK_END);
  170.       }
  171.  
  172.       if (midline) {
  173.         sprintf(l,"\r\n%s",s);
  174.         midline = 0;
  175.       } else {
  176.         sprintf(l,"%s",s);
  177.       }
  178.       if (syscfg.sysconfig & sysconfig_printer)
  179.         fprintf(stdprn,"%s\r\n",l);
  180.       i=strlen(l);
  181.       l[i++]='\r';
  182.       l[i++]='\n';
  183.       l[i]=0;
  184.       sh_write(f,(void *)l,i);
  185.       f=sh_close(f);
  186.     break;
  187.     case 4:
  188.       f = sh_open(slfn, O_RDWR | O_CREAT | O_BINARY, S_IREAD | S_IWRITE);
  189.       if (f<0) {
  190.         /* sysop log ? */
  191.         return;
  192.       }
  193.       if (filelength(f)) {
  194.         sh_lseek(f, -1L, SEEK_END);
  195.         sh_read(f, ((void *)&ch1), 1);
  196.         if (ch1 == 26)
  197.           sh_lseek(f, -1L, SEEK_END);
  198.      }
  199.      if (!midline || ((midline + 2 + strlen(s)) > 78)) {
  200.        strcpy(l, midline ? "\r\n   " : "   ");
  201.        strcat(l, s);
  202.        midline = 3 + strlen(s);
  203.      } else {
  204.        strcpy(l, ", ");
  205.        strcat(l, s);
  206.        midline += (2 + strlen(s));
  207.      }
  208.      if (syscfg.sysconfig & sysconfig_printer)
  209.        fprintf(stdprn, "%s", l);
  210.      i = strlen(l);
  211.      sh_write(f, (void *)l, i);
  212.      f=sh_close(f);
  213.      break;
  214.   }
  215. }
  216.  
  217. /****************************************************************************/
  218.  
  219. /*
  220.  * Writes a string to the sysoplog, if user online and actsl < 255.
  221.  */
  222.  
  223. void sysopchar(char *s)
  224. {
  225.   if ((incom || (actsl != 255)) && (s[0]))
  226.     sl1(4, s);
  227. }
  228.  
  229. /****************************************************************************/
  230.  
  231. /*
  232.  * Writes a string to the sysoplog, if actsl < 255 and user online,
  233.  * indented a few spaces.
  234.  */
  235.  
  236. void sysoplog(char *s)
  237. {
  238.   char s1[180];
  239.  
  240.   if ((incom) || (actsl!=255)) {
  241.     sprintf(s1,"   %s",s);
  242.     sl1(0,s1);
  243.   }
  244. }
  245.  
  246. /****************************************************************************/
  247.  
  248. /*
  249.  * Sends a short message to a user. Takes user number and system number
  250.  * and short message as params. Network number should be set before calling
  251.  * this function.
  252.  */
  253.  
  254. void ssm(unsigned int un, unsigned int sy, char *s)
  255. {
  256.   int  f,i,i1;
  257.   userrec u;
  258.   char s1[161];
  259.   shortmsgrec sm;
  260.   net_header_rec nh;
  261.  
  262.   if ((un==65535) || (un==0))
  263.     return;
  264.   if (sy==0) {
  265.     read_user(un,&u);
  266.     if (!(u.inact & inact_deleted)) {
  267.       sprintf(s1,"%sSMW.DAT",syscfg.datadir);
  268.       f=sh_open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  269.       if (f<0)
  270.         return;
  271.       i=(int) (filelength(f) / sizeof(shortmsgrec));
  272.       i1=i-1;
  273.       if (i1>=0) {
  274.         sh_lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  275.         sh_read(f,(void *)&sm,sizeof(shortmsgrec));
  276.         while ((sm.tosys==0) && (sm.touser==0) && (i1>0)) {
  277.           --i1;
  278.           sh_lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  279.           sh_read(f,(void *)&sm,sizeof(shortmsgrec));
  280.         }
  281.         if ((sm.tosys) || (sm.touser))
  282.           ++i1;
  283.       } else
  284.         i1=0;
  285.       sm.tosys=sy;
  286.       sm.touser=un;
  287.       strncpy(sm.message,s,80);
  288.       sm.message[80]=0;
  289.       sh_lseek(f,((long) (i1)) * sizeof(shortmsgrec), SEEK_SET);
  290.       sh_write(f,(void *)&sm,sizeof(shortmsgrec));
  291.       sh_close(f);
  292.       u.sysstatus |= sysstatus_smw;
  293.       write_user(un,&u);
  294.     }
  295.   } else if (net_sysnum && valid_system(sy)) {
  296.     nh.tosys=sy;
  297.     nh.touser=un;
  298.     nh.fromsys=net_sysnum;
  299.     nh.fromuser=usernum;
  300.     nh.main_type = main_type_ssm;
  301.     nh.minor_type=0;
  302.     nh.list_len=0;
  303.     time((long *)&nh.daten);
  304.     if (strlen(s)>80)
  305.       s[80]=0;
  306.     nh.length=strlen(s);
  307.     nh.method=0;
  308.     sprintf(s1,"%sP0%s",net_data,nete);
  309.     f=sh_open(s1,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  310.     sh_lseek(f,0L,SEEK_END);
  311.     sh_write(f,(void *)&nh,sizeof(net_header_rec));
  312.     sh_write(f,(void *)s,nh.length);
  313.     sh_close(f);
  314.   }
  315. }
  316.  
  317.  
  318. /****************************************************************************/
  319.  
  320. /*
  321.  * Writes BBS location data to instance.dat, so other instances can see
  322.  * some info about this instance.
  323.  */
  324.  
  325. void write_inst(unsigned short loc, unsigned short subloc, unsigned short flags)
  326. {
  327.   char s[81];
  328.   int f,re_write;
  329.   unsigned short cf, ms;
  330.   static instancerec ti;
  331.   instancerec ir;
  332.  
  333.   if (ti.user==0) {
  334.     if (get_inst_info(instance,&ir))
  335.       ti.user=ir.user;
  336.     else
  337.       ti.user=1;
  338.   }
  339.  
  340.   re_write=0;
  341.   curloc=loc;
  342.  
  343.  
  344.   cf=ti.flags & (~(INST_FLAGS_ONLINE | INST_FLAGS_MSG_AVAIL));
  345.   if (useron) {
  346.     cf |= INST_FLAGS_ONLINE;
  347.     if (!(thisuser.sysstatus & sysstatus_no_msgs)) {
  348.       switch (loc) {
  349.         case INST_LOC_MAIN:
  350.         case INST_LOC_XFER:
  351.         case INST_LOC_SUBS:
  352.         case INST_LOC_EMAIL:
  353.         case INST_LOC_CHATROOM:
  354.         case INST_LOC_RMAIL:
  355.           cf |= INST_FLAGS_MSG_AVAIL;
  356.           break;
  357.       }
  358.     } else if (loc == INST_LOC_CHATROOM) {
  359.       cf |= INST_FLAGS_MSG_AVAIL;
  360.     }
  361.     if (using_modem)
  362.       ms=modem_speed;
  363.     else
  364.       ms=0;
  365.     if (ti.modem_speed != ms) {
  366.       ti.modem_speed = ms;
  367.       re_write=1;
  368.     }
  369.   }
  370.  
  371.   if (flags != INST_FLAGS_NONE) {
  372.     if (flags & 0x8000) {
  373.       /* reset an option */
  374.       ti.flags &= flags;
  375.     } else {
  376.       /* set an option */
  377.       ti.flags |= flags;
  378.     }
  379.   }
  380.  
  381.   if (cf!=ti.flags) {
  382.     re_write=1;
  383.     ti.flags=cf;
  384.   }
  385.  
  386.   if (ti.number!=instance) {
  387.     re_write=1;
  388.     ti.number=instance;
  389.   }
  390.  
  391.   if (loc==INST_LOC_DOWN)
  392.     re_write=1;
  393.   else {
  394.     if (useron) {
  395.       if (ti.user!=usernum) {
  396.         re_write=1;
  397.         if ((usernum>0) && (usernum<=syscfg.maxusers))
  398.           ti.user=usernum;
  399.       }
  400.     }
  401.   }
  402.  
  403.   if (ti.subloc!=subloc) {
  404.     re_write=1;
  405.     ti.subloc=subloc;
  406.   }
  407.  
  408.   if (ti.loc!=loc) {
  409.     re_write=1;
  410.     ti.loc=loc;
  411.   }
  412.  
  413.   if (re_write) {
  414.     time((long *)&ti.last_update);
  415.     sprintf(s,"%sINSTANCE.DAT",syscfg.datadir);
  416.     f=sh_open(s,O_RDWR | O_BINARY | O_CREAT, S_IREAD | S_IWRITE);
  417.     if (f>0) {
  418.       lseek(f,(long) (instance * sizeof(instancerec)),SEEK_SET);
  419.       write(f,(void *)&ti,sizeof(instancerec));
  420.       sh_close(f);
  421.     }
  422.   }
  423. }
  424. /****************************************************************************/
  425.  
  426. /*
  427.  * Finds usernum and system number from char *s, sets network number as
  428.  * appropriate.
  429.  */
  430.  
  431. void parse_email_info(char *s, unsigned short *un1, unsigned short *sy1)
  432. {
  433.   char *ss,*ss1,onx[20],ch,*mmk;
  434.   unsigned un, sy;
  435.   int i,nv,on,xx,onxi,odci;
  436.   net_system_list_rec *csne;
  437.  
  438.   *un1=0;
  439.   *sy1=0;
  440.   ss=strrchr(s,'@');
  441.   if (ss==NULL) {
  442.     un=finduser1(s);
  443.     if (un>0)
  444.       *un1=un;
  445.     else
  446.       pl(get_string(8));
  447.   } else if (atoi(ss+1)==0) {
  448.     for (i=0; i<net_num_max; i++) {
  449.       set_net_num(i);
  450.       if (strnicmp("internet",net_name,8)==0) {
  451.         strcpy(net_email_name,s);
  452.         *sy1=1;
  453.       }
  454.     }
  455.     if (i>=net_num_max)
  456.       pl(get_string(8));
  457.   } else {
  458.     ss[0]=0;
  459.     ss=&(ss[1]);
  460.     i=strlen(s);
  461.     while ((i>0) && (s[i-1]==' '))
  462.       --i;
  463.     s[i]=0;
  464.     un=atoi(s);
  465.     sy=atoi(ss);
  466.     ss1=strchr(ss,'.');
  467.     if (ss1)
  468.       ss1++;
  469.     if (un==0) {
  470.       strcpy(net_email_name,s);
  471.       i=strlen(net_email_name);
  472.       while ((i>0) && (net_email_name[i-1]==' '))
  473.         --i;
  474.       net_email_name[i]=0;
  475.       if (net_email_name[0])
  476.         *sy1=sy;
  477.       else
  478.         pl(get_string(8));
  479.     } else {
  480.       *un1=un;
  481.       *sy1=sy;
  482.     }
  483.     if (*sy1 && ss1) {
  484.       for (i=0; i<net_num_max; i++) {
  485.         set_net_num(i);
  486.         if (stricmp(ss1,net_name)==0) {
  487.           if (!valid_system(*sy1)) {
  488.             nl();
  489.             outstr(get_string(9));
  490.             npr("%s @%u.\r\n",ss1,*sy1);
  491.             nl();
  492.             *sy1=*un1=0;
  493.           } else {
  494.             if (*sy1==net_sysnum) {
  495.               *sy1=0;
  496.               if (*un1==0)
  497.                 *un1=finduser(net_email_name);
  498.               if ((*un1==0) || (*un1>32767)) {
  499.                 *un1=0;
  500.                 pl(get_string(8));
  501.               }
  502.             }
  503.           }
  504.           break;
  505.         }
  506.       }
  507.       if (i>=net_num_max) {
  508.         nl();
  509.         outstr(get_string(10));
  510.         outstr(ss1);
  511.         nl();
  512.         *sy1=*un1=0;
  513.       }
  514.     } else if (*sy1 && (net_num_max>1)) {
  515.       odc[0]=0;
  516.       odci=0;
  517.       onx[0]='Q';
  518.       onx[1]=0;
  519.       onxi=1;
  520.       nv=0;
  521.       on=net_num;
  522.       ss=malloca(net_num_max);
  523.       xx=-1;
  524.       for (i=0; i<net_num_max; i++) {
  525.         set_net_num(i);
  526.         if (net_sysnum==*sy1) {
  527.           xx=i;
  528.         } else if (valid_system(*sy1)) {
  529.           ss[nv++]=i;
  530.         }
  531.       }
  532.       set_net_num(on);
  533.       if (nv==0) {
  534.         if (xx!=-1) {
  535.           set_net_num(xx);
  536.           *sy1=0;
  537.           if (*un1==0) {
  538.             *un1=finduser(net_email_name);
  539.             if ((*un1==0) || (*un1>32767)) {
  540.               *un1=0;
  541.               pl(get_string(8));
  542.             }
  543.           }
  544.         } else {
  545.           nl();
  546.           pl(get_string(11));
  547.           *sy1=*un1=0;
  548.         }
  549.       } else if (nv==1) {
  550.         set_net_num(ss[0]);
  551.       } else {
  552.         nl();
  553.         for (i=0; i<nv; i++) {
  554.           set_net_num(ss[i]);
  555.           csne=next_system(*sy1);
  556.           if (csne) {
  557.             if (i<9) {
  558.               onx[onxi++]=i+'1';
  559.               onx[onxi]=0;
  560.             } else {
  561.               odci=(i+1)/10;
  562.               odc[odci-1]=odci+'0';
  563.               odc[odci]=0;
  564.             }
  565.             npr("%d. %s (%s)\r\n",i+1,net_name,csne->name);
  566.           }
  567.         }
  568.         pl(get_string(12));
  569.         nl();
  570.         prt(2,get_string(13));
  571.         if (nv<9) {
  572.           ch=onek(onx);
  573.           if (ch=='Q')
  574.             i=-1;
  575.           else
  576.             i=ch-'1';
  577.         } else {
  578.           mmk=mmkey(2);
  579.           if (*mmk=='Q')
  580.             i=-1;
  581.           else
  582.             i=atoi(mmk)-1;
  583.         }
  584.         if ((i>=0) && (i<nv)) {
  585.           set_net_num(ss[i]);
  586.         } else {
  587.           nl();
  588.           pl(get_string(14));
  589.           nl();
  590.           *un1=*sy1=0;
  591.         }
  592.       }
  593.       bbsfree(ss);
  594.     } else {
  595.       if (*sy1==net_sysnum) {
  596.         *sy1=0;
  597.         if (*un1==0)
  598.           *un1=finduser(net_email_name);
  599.         if ((*un1==0) || (*un1>32767)) {
  600.           *un1=0;
  601.           pl(get_string(8));
  602.         }
  603.       } else if (!valid_system(*sy1)) {
  604.         nl();
  605.         pl(get_string(11));
  606.         *sy1=*un1=0;
  607.       }
  608.     }
  609.   }
  610. }
  611.  
  612. /****************************************************************************/
  613.  
  614. /*
  615.  * Checks system password, returns 1 if pw entered is valid, else returns 0.
  616.  */
  617.  
  618. int checkpw(void)
  619. {
  620.   char s[81];
  621.  
  622.   nl();
  623.   prt(2,get_string(616));
  624.   echo=0;
  625.   input(s,20);
  626.   echo=1;
  627.   if (strcmp(s,(syscfg.systempw))==0)
  628.     return(1);
  629.   else
  630.     return(0);
  631. }
  632.  
  633. /****************************************************************************/
  634.  
  635. /*
  636.  * Ends BBS execution with errorlevel of lev set. Closes stringfiles and
  637.  * restores all interrupts to previous state.
  638.  */
  639.  
  640. void end_bbs(int lev)
  641. {
  642.   char s[81];
  643.  
  644.   sprintf(s,get_stringx(1,131), wwiv_version,
  645.           instance, times(), date());
  646.   sl1(0,"");
  647.   sl1(0, s);
  648.   sl1(0,"");
  649.   sl1(1,"");
  650.   catsl();
  651.   close_strfiles();
  652. #ifdef __OS2__
  653.   if (stdprn != NULL)
  654.     fclose(stdprn);
  655. #endif
  656.   write_inst(INST_LOC_DOWN,0,INST_FLAGS_NONE);
  657.   if (ok_modem_stuff)
  658.     closeport();
  659.   outs(wwiv_version);
  660.   outs(" run complete.\r\n\r\n");
  661. #ifndef __OS2__
  662.   setvect(save_dos,NULL);
  663. #endif
  664.   exit(lev);
  665. }
  666.  
  667. /****************************************************************************/
  668.  
  669. /*
  670.  * Returns 1 if date has changed, else returns 0.
  671.  */
  672.  
  673. int date_changed(void)
  674. {
  675.   struct date today,today1;
  676.  
  677.   getdate(&today);
  678.   getdate(&today1);
  679.   if (today.da_day==today1.da_day)
  680.     return(0);
  681.   else
  682.     return(1);
  683. }
  684.  
  685. /****************************************************************************/
  686.  
  687. /*
  688.  * Displays a file locally, using LIST util if so defined in INIT, else
  689.  * uses normal TTY output.
  690.  */
  691.  
  692. void print_local_file(char *ss, char *ss1)
  693. {
  694.   char s[81];
  695.   char s1[81];
  696.   char *bs;
  697.  
  698.   bs=strchr(ss,'\\');
  699.   if ((syscfg.sysconfig & sysconfig_list) && (!incom)) {
  700.     if (!bs) {
  701.       sprintf(s,"%s %s%s",get_string(1041),syscfg.gfilesdir,ss);
  702.       if (ss1[0]) {
  703.         bs=strchr(ss1,'\\');
  704.         if (!bs)
  705.           sprintf(s1,"%s %s%s",s,syscfg.gfilesdir,ss1);
  706.         else
  707.           sprintf(s1,"%s %s",s,ss1);
  708.         strcpy(s,s1);
  709.       }
  710.     } else {
  711.       sprintf(s,"%s %s",get_string(1041),ss);
  712.       if (ss1[0]) {
  713.         bs=strchr(ss1,'\\');
  714.         if (!bs)
  715.           sprintf(s1,"%s %s%s",s,syscfg.gfilesdir,ss1);
  716.         else
  717.           sprintf(s1,"%s %s",s,ss1);
  718.         strcpy(s,s1);
  719.       }
  720.     }
  721.     extern_prog(s, 0);
  722.     if (useron) {
  723.       clrscrb();
  724.       topscreen();
  725.     }
  726.   } else {
  727.     printfile(ss);
  728.     nln(2);
  729.     pausescr();
  730.   }
  731. }
  732.  
  733. /****************************************************************************/
  734.  
  735. /*
  736.  * Hangs up the modem if user online. Whether using modem or not, sets
  737.  * hangup to 1.
  738.  */
  739.  
  740. void hang_it_up(void)
  741. {
  742.   int i;
  743.  
  744.   hangup=1;
  745.  
  746.   if (!ok_modem_stuff)
  747.     return;
  748.  
  749.   dtr(0);
  750.   if (cdet()) {
  751.     wait1(9);
  752.     if (cdet()) {
  753.       wait1(9);
  754.       if (cdet()) {
  755.         i=0;
  756.         dtr(1);
  757.         while ((i++<2) && (cdet())) {
  758.           wait1(27);
  759.           pr1("\x1\x1\x1");
  760.           wait1(54);
  761.           if (modem_i->hang[0])
  762.             pr1(modem_i->hang);
  763.           else
  764.             pr1("ATH\r");
  765.           wait1(6);
  766.         }
  767.       }
  768.     }
  769.   }
  770.   dtr(1);
  771. }
  772.  
  773. /****************************************************************************/
  774.  
  775. /*
  776.  * Plays a sound definition file (*.SDF) through PC speaker. SDF files
  777.  * should reside in the gfiles dir. The only params passed to function are
  778.  * filename and 0 if playback is unabortable, 1 if it is abortable. If no
  779.  * extension then .SDF is appended. A full path to file may be specified to
  780.  * override gfiles dir. Format of file is:
  781.  *
  782.  * <freq> <duration in ms> [pause_delay in ms]
  783.  * 1000 1000 50
  784.  *
  785.  * Returns 1 if sucessful, else returns 0. The pause_delay is optional and
  786.  * is used to insert silences between tones.
  787.  */
  788.  
  789. #ifdef __OS2__
  790. #define sound(freq) setbeep(freq)
  791. #define nosound() setbeep(0)
  792. #endif
  793.  
  794.  
  795. int play_sdf(unsigned char *sdfn, int abortable)
  796. {
  797.   FILE *f;
  798.   unsigned char soundline[81], tempstring[81], fname[81];
  799.   int freq, dur, pausedelay, nw;
  800.  
  801.   /* append gfilesdir if no path specified */
  802.   if (strchr(sdfn,'\\')==NULL) {
  803.     strncpy(fname, syscfg.gfilesdir, sizeof(fname));
  804.     strncat(fname, sdfn, sizeof(fname));
  805.   } else
  806.     strncpy(fname, sdfn, sizeof(fname));
  807.  
  808.   /* append .SDF if no extension specified */
  809.   if (strchr(fname,'.')==NULL)
  810.     strncat(fname, ".SDF", sizeof(fname));
  811.  
  812.   /* must exist */
  813.   if (!exist(fname))
  814.     return(0);
  815.  
  816.   /* must be able to open read-only */
  817.   f=fsh_open(fname,"rt");
  818.   if (!f)
  819.     return(0);
  820.  
  821.   /* scan each line, ignore lines with words<2 */
  822.   while (fgets(soundline, sizeof(soundline), f) != NULL) {
  823.     if ((abortable) && (!empty()))
  824.       break;
  825.     freq=dur=pausedelay=0;
  826.     nw=wordcount(soundline, DELIMS_WHITE);
  827.     if (nw>=2) {
  828.       strncpy(tempstring,extractword(1,soundline,DELIMS_WHITE),sizeof(tempstring));
  829.       freq=atoi(tempstring);
  830.       strncpy(tempstring,extractword(2,soundline,DELIMS_WHITE),sizeof(tempstring));
  831.       dur=atoi(tempstring);
  832.  
  833.       /* only play if freq and duration > 0 */
  834.       if ((freq>0) && (dur>0)) {
  835.         if (nw>2) {
  836.           strncpy(tempstring,extractword(3,soundline,DELIMS_WHITE),sizeof(tempstring));
  837.           pausedelay=atoi(tempstring);
  838.         }
  839.         sound(freq);
  840.         delay(dur);
  841.         nosound();
  842.         if (pausedelay>0)
  843.           delay(pausedelay);
  844.       }
  845.     }
  846.   }
  847.  
  848.   /* close and return success */
  849.   fsh_close(f);
  850.   return(1);
  851. }
  852.  
  853. /****************************************************************************/
  854.  
  855.  
  856.  
  857.