home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / XSRC_117.ZIP / XMSGINL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-16  |  15.2 KB  |  511 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*   XBBS SOURCE CODE copyright (c) 1990 by M. Kimes                        */
  4. /*   All Rights Reserved                                                    */
  5. /*                                                                          */
  6. /*    For complete details of the licensing restrictions, please refer      */
  7. /*    to the License agreement, which is published in its entirety in       */
  8. /*    the in the file LICENSE.XBS.                                          */
  9. /*                                                                          */
  10. /*    USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE      */
  11. /*    XBBS LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF            */
  12. /*    THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO       */
  13. /*    NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT M. KIMES         */
  14. /*    AT THE ADDRESS LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO USE   */
  15. /*    THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE XBBS LICENSING     */
  16. /*    AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU ARE ABLE TO REACH WITH      */
  17. /*    M. KIMES                                                              */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /* You can contact M. Kimes at the following address:                       */
  21. /*                                                                          */
  22. /* M. Kimes                         1:380/16.0@FidoNet                      */
  23. /* 542 Merrick                      (318)222-3455 data                      */
  24. /* Shreveport, LA  71104                                                    */
  25. /*                                                                          */
  26. /*                                                                          */
  27. /* Please feel free to contact me at any time to share your comments about  */
  28. /* my software and/or licensing policies.                                   */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31. /*======================================================================*/
  32. /*  XBBS Bulletin Board System.....Msg reading low-level functions      */
  33. /*======================================================================*/
  34.  
  35. #include "msg.h"
  36. #include "xext.h"
  37.  
  38. extern struct _mboard far *marea;
  39. extern struct _fboard holdboard;
  40. extern struct _mboard holdmboard;
  41. extern char exporting;
  42. extern word maxareas;
  43. extern word higharea;
  44.  
  45.  
  46. int pascal get_mess (word messno) {
  47.  
  48.  int handle;
  49.  register word x=0;
  50.  
  51.  sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
  52.  
  53.  while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  54.      if (errno==EACCES) {
  55.         x++;
  56.         if(x>2) {
  57.             say_prompt(418);
  58.             return -1;
  59.         }
  60.         say_prompt(57);
  61.         sleep(1);
  62.      }
  63.      else  {
  64.         say_prompt(59);
  65.         return -1;
  66.      }
  67.  }
  68.  if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || (_read(handle,&msg,sizeof(struct _xmsg))<1)) {
  69.     if (eof(handle)==(-1)) lprint("\n\04Seek error\n");
  70.     cclose(handle);
  71.     return -1;
  72.  }
  73.  cclose(handle);
  74.  return 0;
  75. }
  76.  
  77.  
  78.  
  79.  
  80. int pascal put_mess (word messno) {
  81.  
  82.  int handle;
  83.  register word x=0;
  84.  
  85.  sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
  86.  
  87.  while ((handle=oopen(buffer,O_RDWR | O_BINARY | O_DENYNONE))==-1) {
  88.      if (errno==EACCES) {
  89.         x++;
  90.         if(x>2) {
  91.             say_prompt(50);
  92.             return -1;
  93.         }
  94.         say_prompt(57);
  95.         sleep(1);
  96.      }
  97.      else {
  98.         if((handle=ccreat(buffer,S_IWRITE))==-1) {
  99.             say_prompt(59);
  100.             return -1;
  101.         }
  102.         break;
  103.      }
  104.  }
  105.  if (conf.share) {
  106.      x=0;
  107.      while (lock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg))){
  108.         x++;
  109.         if(x>2) {
  110.             say_prompt(50);
  111.             return -1;
  112.         }
  113.         say_prompt(57);
  114.         sleep(1);
  115.      }
  116.  }
  117.  if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || (_write(handle,&msg,sizeof(struct _xmsg))<1)) {
  118.     if (eof(handle)==(-1))  {
  119.         lprint(" SEEK ERROR ");
  120.         if(conf.share)unlock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg));
  121.         cclose(handle);
  122.         return -1;
  123.     }
  124.  }
  125.  if (conf.share)unlock(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),(long)sizeof(struct _xmsg));
  126.   cclose(handle);
  127.  return 0;
  128. }
  129.  
  130.  
  131.  
  132. char far * pascal get_text (word messno) {
  133.  
  134.  char once;
  135.  char reduced=0;
  136.  char *hold;
  137.  char *tempo;
  138.  word temp=0;
  139.  int  handle;
  140.  
  141.  sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
  142.  while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  143.      if (errno==EACCES) {
  144.         temp++;
  145.         if (temp>2) {
  146.             say_prompt(50);
  147.             return NULL;
  148.         }
  149.         say_prompt(57);
  150.         sleep(1);
  151.      }
  152.      else {
  153.         say_prompt(58);
  154.         return NULL;
  155.      }
  156.  }
  157.  once=0;
  158. TryThatAgain:
  159.  if (lseek(handle,msg.start,SEEK_SET)) {
  160.      if (eof(handle)) {
  161.         if (!once) {
  162.             once++;
  163.             goto TryThatAgain;
  164.         }
  165.         else lprint("\n\04Text Seek error\n");
  166.         cclose(handle);
  167.         return NULL;
  168.      }
  169.  }
  170.  temp=msg.length;
  171. ReTry:
  172.   hold=(char far*)mmalloc(msg.length+1);
  173.   if (hold==NULL) {
  174.     if (msg.length>1024 && !(msg.m_attr & MSGPACKED)) {
  175.         msg.length-=256;
  176.         reduced=1;
  177.         goto ReTry;
  178.     }
  179.     else {
  180.         say_prompt(41);
  181.         msg.length=temp;
  182.         cclose(handle);
  183.         return NULL;
  184.     }
  185.   }
  186.   memset(hold,0,msg.length);
  187.   if(_read(handle,hold,msg.length)<msg.length)reduced=1;
  188.   cclose(handle);
  189.   hold[msg.length-1]=0;
  190.   hold[msg.length]=0;
  191.   tempo=hold;
  192.  if(!(msg.m_attr & MSGTREATED) && !(mboard.attr & ANSI) && !(msg.m_attr & MSGPACKED)) {
  193.       while (*tempo) {
  194.         if(*tempo=='\x8d' || *tempo=='\n') {
  195.             if(*tempo=='\n') memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
  196.             else {
  197.                 if(*(tempo-1)==' ' && tempo>hold) memmove(tempo,&tempo[1],msg.length-((word)tempo-(word)hold));
  198.                 else {
  199.                     *tempo=' ';
  200.                     tempo++;
  201.                 }
  202.             }
  203.         }
  204.         else tempo++;
  205.       }
  206.       if(*(tempo-1)!='\r' && tempo>hold) {
  207.         *tempo='\r';
  208.         tempo[1]=0;
  209.       }
  210.       if(!reduced && temp>(word)strlen(hold)+1) {
  211.         msg.length=(word)strlen(hold)+1;
  212.         sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
  213.         if ((handle=oopen(buffer,O_RDWR | O_BINARY | O_DENYWRITE))==-1) goto OkayThenDont;
  214.         once=0;
  215. TryThatAgain2:
  216.         if (lseek(handle,msg.start,SEEK_SET)==-1) {
  217.          if (eof(handle)==-1) {
  218.             if (!once) {
  219.                 once++;
  220.                 goto TryThatAgain;
  221.             }
  222.             else {
  223.                 cclose(handle);
  224.                 goto OkayThenDont;
  225.             }
  226.          }
  227.         }
  228.         if(_write(handle,hold,(word)strlen(hold))==strlen(hold)) {
  229.             _write(handle,"\0",1);
  230.             if(eof(handle)==-1) {
  231.                 cclose(handle);
  232.                 goto OkayThenDont;
  233.             }
  234.             cclose(handle);
  235.             msg.m_attr=(msg.m_attr | MSGTREATED);
  236.             if(messno)put_mess(messno);
  237.             temp=msg.length;
  238.         }
  239.     }
  240.   }
  241.   if(msg.m_attr & MSGPACKED) {
  242.         if(unpack_msg(&hold)==NULL) {
  243. /* gprintf(LOCALONLY,"\nCame back null: Hold=%p\n",hold); */
  244.             if(hold)ffree(hold);
  245.             msg.length=0;
  246.             return NULL;
  247.         }
  248. /* gprintf(LOCALONLY,"\nCame back ok: Hold=%p\n",hold); */
  249.   }
  250.  
  251. OkayThenDont:
  252.   msg.length=temp;
  253.   return hold;
  254. }
  255.  
  256.  
  257. word pascal get_abunch (word messno,char type,int direction,char *str) {
  258.  
  259.  register word x=0;
  260.  register int y;
  261.  int handle;
  262.  int handle2;
  263.  char finished=0;
  264.  word temp;
  265.  static struct _xmsg msgs[5];
  266.  char once;
  267.  
  268.   if(type==1) {
  269.     rstrip(str);
  270.     if(!strnicmp(str,"RE: ",4)) memmove(str,&str[4],strlen(&str[4])+1);
  271.     if(!*str || !str) return 0;
  272.  }
  273.  if(direction>=0) {
  274.     messno++;
  275.     direction=1;
  276.  }
  277.  else direction=(-1);
  278.  sprintf(buffer,"%sXDATA.%03x",messpath,mboard.number);
  279.  while ((handle=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  280.      if (errno==EACCES) {
  281.         x++;
  282.         if(x>2) {
  283.             say_prompt(418);
  284.             return 0;
  285.         }
  286.         say_prompt(57);
  287.         sleep(1);
  288.      }
  289.      else  {
  290.         say_prompt(59);
  291.         return 0;
  292.      }
  293.  }
  294.  if(direction<0) {
  295.     if(messno>6){
  296.         x=5;
  297.         messno-=5;
  298.     }
  299.     else {
  300.         x=messno-1;
  301.         messno=1;
  302.     }
  303.  }
  304. Loop:
  305.  if(toupper(inkey())=='S') {
  306.     cclose(handle);
  307.     return 0;
  308.  }
  309.  if(direction>0) {
  310.     x=(word)(filelength(handle)/(long)sizeof(struct _xmsg));
  311.     if(messno>x || finished) {
  312.         cclose(handle);
  313.         return 0;
  314.      }
  315.      if((x-messno)<6)x-=(messno-1);
  316.      else x=5;
  317.  }
  318. Skip:
  319.  if ((lseek(handle,(long)((long)(messno-1)*(long)sizeof(struct _xmsg)),SEEK_SET)==(-1)) || ((temp=(_read(handle,&msgs,(int)(x * sizeof(struct _xmsg)))))<1)) {
  320.     if (eof(handle)==(-1)) lprint("\n\04Seek or Read error\n");
  321.     cclose(handle);
  322.     return 0;
  323.  }
  324.  if((temp/sizeof(struct _xmsg))<x)x=temp/sizeof(struct _xmsg);
  325.  if(direction<0)y=x-1;
  326.  else y=0;
  327.  if(type==0) {  /* Personal mail check */
  328.     while(1) {
  329.         if ((msgs[y].attr & MSGREAD) || (msgs[y].m_attr & MSGDELETED)) goto NotGot;
  330.         if((stricmp(msgs[y].to,user.name)==0) || (stricmp(msgs[y].to,user.handle)==0)) {
  331.                 cclose(handle);
  332.                 return (messno+y);
  333.         }
  334.         if(userno==1) {
  335.             if (!stricmp(msgs[y].to,"SYSOP")) {
  336.                     cclose(handle);
  337.                     return (messno+y);
  338.                 }
  339.         }
  340. NotGot:
  341.         y+=(direction);
  342.         if(direction<0) {
  343.             if(y<0) break;
  344.         }
  345.         else if(y>=x) break;
  346.     }
  347.  }
  348.  else if (type==1) { /* Subject check */
  349.    temp=(word)strlen(str);
  350.    while(1) {
  351.         if (msgs[y].m_attr & MSGDELETED) goto NoGot;
  352.         rstrip(msgs[y].subj);
  353.         if(!strnicmp(msgs[y].subj,"RE: ",4)) memmove(msgs[y].subj,&msgs[y].subj[4],strlen(&msgs[y].subj[4])+1);
  354.         handle2=(int)temp;
  355.         if(temp>24) {
  356.             if(strlen(msgs[y].subj)<(int)temp) handle2=strlen(msgs[y].subj);
  357.             if(handle2<24) handle2=temp;
  358.         }
  359.         if(!strnicmp(msgs[y].subj,str,handle2)) {
  360.  
  361.             cclose(handle);
  362.             return (messno+y);
  363.         }
  364. NoGot:
  365.         y+=(direction);
  366.         if(direction<0) {
  367.             if(y<0) break;
  368.         }
  369.         else if(y>=x) break;
  370.         }
  371.  }
  372.  else if (type==2) { /* Body check */
  373.      sprintf(buffer,"%sXTEXT.%03x",messpath,mboard.number);
  374.      temp=0;
  375.      while ((handle2=oopen(buffer,O_RDONLY | O_BINARY | O_DENYNONE))==-1) {
  376.          if (errno==EACCES) {
  377.             temp++;
  378.             if (temp>2) {
  379.                 say_prompt(50);
  380.                 cclose(handle);
  381.                 return 0;
  382.             }
  383.             say_prompt(57);
  384.             sleep(1);
  385.          }
  386.          else {
  387.             say_prompt(58);
  388.             cclose(handle);
  389.             return 0;
  390.          }
  391.      }
  392.     while(1) {
  393.      if(!msgs[y].length) goto NoGot2;
  394.      if ((msgs[y].m_attr & MSGDELETED)) goto NoGot2;
  395.      once=0;
  396. TryThatAgain:
  397.      if (lseek(handle2,msgs[y].start,SEEK_SET)) {
  398.          if (eof(handle2)) {
  399.             if (once<2) {
  400.                 once++;
  401.                 goto TryThatAgain;
  402.             }
  403.             lprint("\nText Seek error\n");
  404.             goto NoGot2;
  405.          }
  406.      }
  407.      *buffer=0;
  408.      temp=510;
  409.      if(temp>(msgs[y].length-1)) temp=msgs[y].length-1;
  410.      temp=_read(handle2,buffer,temp);
  411.      buffer[temp+1]=0;
  412.      if(stristr(buffer,str)) {
  413.         cclose(handle);
  414.         cclose(handle2);
  415.         return (messno+y);
  416.      }
  417. NoGot2:
  418.         y+=(direction);
  419.         if(direction<0) {
  420.             if(y<0) break;
  421.         }
  422.         else if(y>=x) break;
  423. }
  424.     cclose(handle2);
  425.  }
  426.  if(direction>0) {
  427.     if((long)(messno+x)>65535L) finished++;
  428.     else messno+=x;
  429.  }
  430.  else {
  431.     if((long)(messno-x)<=0L) {
  432.         cclose(handle);
  433.         return 0;
  434.     }
  435.     else messno-=x;
  436.     if (messno>5) x=5;
  437.  }
  438.  goto Loop;
  439. }
  440.  
  441.  
  442. int pascal do_all_msg_areas (char *msgareas,char type,char newonly,char abortok,word startat) {
  443.  
  444.     register word x;
  445.     char temp=0;
  446.     struct ffblk f;
  447.     char filename[133];
  448.  
  449. /* gprintf(LOCALONLY,"\nMA: %s\ntype: %hu\nnew: %hu\nabort: %hu\nstart: %u\n",msgareas,type,newonly,abortok,startat); */
  450.  
  451.     load_areas(msgareas);
  452.     if (!maxareas) {
  453.         if(marea)ffree(marea);
  454.         return 1;
  455.     }
  456.     memcpy(&holdboard,&fboard,sizeof(struct _fboard));
  457.     memcpy(&holdmboard,&mboard,sizeof(struct _mboard));
  458.     for (x=startat;x<(higharea+1);x++) {
  459.         if (find_area(x,1+(type & 2))) {
  460.             if(newonly) {
  461.                 if(x<(conf.nolmrs+1)) {
  462.                     if(temp && abortok) {
  463.                         sprintf(filename,"%sXDATA.%03x",messpath,x);
  464.                         if (findfirst(filename,&f,0)) f.ff_fsize=0;
  465.                         if (!f.ff_fsize) continue;
  466.                         say_prompt(292);
  467.                         temp=*genin(1,0,1,1,ALPHA);
  468.                         printm("\n");
  469.                         switch((int)temp) {
  470.                             case 'S': goto Loop;
  471.                             case 'I': if(x<(conf.nolmrs+1)) lastread[x-1]=(word)(f.ff_fsize/(long)sizeof(struct _xmsg));
  472.                                       goto Loop;
  473.                             case 'A': goto BreakOut;
  474.                             default:  temp='R';
  475.                         }
  476.                     }
  477.                     readamessage(type,lastread[x-1]+1);
  478.                     temp=1;
  479.                 }
  480.             }
  481.             else {
  482.                 if(temp && abortok) {
  483.                     sprintf(filename,"%sXDATA.%03x",messpath,x);
  484.                     if (findfirst(filename,&f,0)) f.ff_fsize=0;
  485.                     if (!f.ff_fsize) continue;
  486.                     say_prompt(292);
  487.                     temp=*genin(1,0,1,1,ALPHA);
  488.                     printm("\n");
  489.                     switch((int)temp) {
  490.                         case 'S': goto Loop;
  491.                         case 'I': if(x<(conf.nolmrs+1)) lastread[x-1]=(word)(f.ff_fsize/(long)sizeof(struct _xmsg));
  492.                                   goto Loop;
  493.                         case 'A': goto BreakOut;
  494.                         default:  temp='R';
  495.                     }
  496.                 }
  497.                 readamessage(type,0);
  498.                 temp=1;
  499.             }
  500.         }
  501. Loop:
  502. ;
  503.     }
  504. BreakOut:
  505.     if (marea) ffree(marea);
  506.     maxareas=0;
  507.     memcpy(&fboard,&holdboard,sizeof(struct _fboard));
  508.     memcpy(&mboard,&holdmboard,sizeof(struct _mboard));
  509.     return 0;
  510. }
  511.