home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume32 / xbbs / part03 / bbscfile.c < prev    next >
C/C++ Source or Header  |  1992-09-08  |  16KB  |  633 lines

  1. /*
  2.     bbscfile.c
  3.  
  4. */
  5.  
  6. /* #define DEBUG 1 */
  7.  
  8. #include "bbscdef.h"
  9. #include <string.h>
  10. #include <sys/types.h>     /* For compatibility */
  11. #include <sys/locking.h>
  12.  
  13. #define LASTDATE  " 04/21/90 "
  14.  
  15. #define PGMNAME "BBSCFILE "
  16. #define VERSION " 7.92 "
  17. extern int user_priv;
  18.  
  19.     static    char    bufmsg0[MSG1MAX+1],
  20.         buftmp[MSGSECT+256],
  21.         this1[11],
  22.         next1[11];
  23. hdrwrt()        /* write the header from memory variables */
  24.     {        /* header is a 1 record file */
  25.     int    fd;
  26.     int    fd1;
  27.  
  28.     strcpy(who_am_i, m_pathname);
  29.     strcat(who_am_i, HEADER);
  30.     if ((fd = open(who_am_i,WRITE,0666)) < 0)    /* open i/o */
  31.         {
  32.         portsout("Can't open header-file, will create it!") ;
  33.         portsout(CRLF) ;
  34.         if ((fd = creat(who_am_i,0666)) < 0)
  35.             {
  36.             portsout("Can't create header-file, aborting!") ;
  37.             portsout(CRLF) ;
  38.             return(ERROR) ;
  39.             }
  40.         }
  41.     lseek(fd, 0L, 0);
  42.     locking(fd, LK_LOCK, 0L);
  43.     strcpy(who_am_i, m_pathname);
  44.     strcat(who_am_i, CROSSREF);
  45.     if ((fd1 = open(who_am_i,WRITE,0666)) < 0)
  46.         {
  47.         portsout("Can't open xref file, will create it!");
  48.         portsout(CRLF) ;
  49.         if ((fd1 = creat(who_am_i,0666)) < 0)
  50.             {
  51.             portsout(" XREF creation error! -- abort!");
  52.             portsout(CRLF);
  53.             return(ERROR) ;
  54.             }
  55.         }
  56.     lseek(fd1, 0L, 0);
  57.     locking(fd1, LK_LOCK, 0L);
  58.     itoa(h_next_msg,h_next) ;    /* convert int to char */
  59.     itoa(h_act_msg,h_act) ;
  60.     strfill(buf128,26,MSGSECT) ;    /* init buf128 to all hex 1a */
  61.     sprintf(buf128,"%s~%s~%s~",    /* build record */
  62.         h_next_msg,
  63.         h_act_msg,
  64.         h_date) ;
  65.     write(fd,buf128,MSGSECT) ;    /* write it */
  66.     lseek(fd, 0L, 0);
  67.     locking(fd, LK_UNLCK, 0L);
  68.     close(fd) ;            /* no need to leave it open */
  69.     write(fd1,xtable,4000);
  70.     lseek(fd1, 0L, 0);
  71.     locking(fd1, LK_UNLCK, 0L);
  72.     close(fd1) ;
  73.     return(OK) ;
  74.     }
  75.  
  76. hdrread()        /* read the header file into memory */
  77.     {
  78.     int    fd,
  79.         i,
  80.         cnt1,
  81.         cnt;
  82.  
  83.     strcpy(who_am_i, m_pathname);
  84.     strcat(who_am_i, HEADER);
  85.     if ((fd = open(who_am_i,READ,0666)) < 0)    /* open input */
  86.         {
  87.         portsout("Can't open header-file, using inital values!") ;
  88.         portsout(CRLF) ;
  89.         h_next = 1 ;
  90.         h_next_msg[0] = '1' ; h_next_msg[1] = 0 ;
  91.         h_act = 1 ;
  92.         h_act_msg[0] = '1' ; h_act_msg[1] = 0 ;
  93.         h_date[0] = '0' ; h_date[1] = 0 ;
  94.         hdrwrt() ; goto next;
  95.         }
  96.     lseek(fd, 0L, 0);
  97.     locking(fd, LK_LOCK, 0L);
  98.     if((cnt=read(fd,buf128,MSGSECT)) != MSGSECT)
  99.         {
  100.         portsout(CRLF) ;
  101.             portsout("<<< header read error >>>") ;
  102.         portsout(CRLF) ;
  103.         return(ERROR) ;
  104.         }
  105.     cnt = sscanf(buf128,"%[^~]~%[^~]~%[^~]~", 
  106.             h_next_msg,
  107.             h_act_msg,
  108.             h_date) ;
  109. next:
  110.     lseek(fd, 0L, 0);
  111.     locking(fd, LK_UNLCK, 0L);
  112.     close(fd) ;        /* no need to leave it open */
  113.     strcpy(who_am_i, m_pathname);
  114.     strcat(who_am_i, CROSSREF);
  115.     if ((fd = open(who_am_i,READ,0666)) < 0)
  116.         {
  117.         portsout("Can't open xref file --- setting values!");
  118.         portsout(CRLF);
  119.         xtable[0] = 1L;
  120.         for (i = 1; i <= 999; i++)
  121.             xtable[i] = 0L;
  122.         return ;
  123.         }
  124.     lseek(fd, 0L, 0);
  125.     locking(fd, LK_LOCK, 0L);
  126.     if ((cnt1=read(fd, xtable, 4000)) != 4000)
  127.         {
  128.         portsout(CRLF) ;
  129.         portsout("<<< xref read error >>>");
  130.         portsout(CRLF);
  131.         return(ERROR);
  132.         }
  133.     lseek(fd, 0L, 0);
  134.     locking(fd, LK_UNLCK, 0L);
  135.     close (fd);
  136. /*
  137.  
  138.     if (cnt != 2)
  139.         {
  140.         return(ERROR) ;
  141.         }
  142. */
  143.     h_next = atoi(h_next_msg) ;
  144.     h_act = atoi(h_act_msg) ;
  145.     return(OK) ;
  146.     }
  147.  
  148. msgopen(how)
  149. int    how ;        /* how to open 0=input, 1=output, 2=i/o */
  150.     {
  151.     int    fd ;
  152.  
  153.     strcpy(who_am_i, m_pathname);
  154.     strcat(who_am_i, MESSAGES);
  155.     if ((fd = open(who_am_i,how,0666)) < 0)    /* open i/o */
  156.         {
  157.         portsout("can't open message-file, will create it!") ;
  158.         portsout(CRLF) ;
  159.         if ((fd = creat(who_am_i,0666)) < 0)
  160.             {
  161.             portsout("can't create message-file, aborting!") ;
  162.             portsout(CRLF) ;
  163.             return(ERROR) ;
  164.             }
  165.         }
  166.     lseek(fd, 0L, 0);
  167.     locking(fd, LK_RLCK, 0L);
  168.     return(fd) ;
  169.     }
  170.  
  171. msgclose(fd)
  172. int    fd ;
  173.     {
  174.     lseek(fd, 0L, 0);
  175.     locking(fd, LK_UNLCK, 0L);
  176.     return(close(fd)) ;
  177.     }
  178.  
  179. msgwrt(fd)        /* write the message file from memory variables */
  180. int    fd;        /* writes a message starting with the h_next msg # */
  181.     {
  182.     int    rc,            /* return code */
  183.         cnt1,
  184.         cnt2,
  185.         len;
  186.  
  187.     rc = cnt1 = len = cnt2 = 0 ;
  188.     itoa(this1,h_next) ;                /* convert int to char */
  189.     xtable[h_act - 1] = h_next;
  190.     for( len=h_act; len < 1000; len++)
  191.         xtable[len] = 0L;        /* guarantee clean table */
  192.     h_act++;
  193.     rc = seek(fd,h_next - 1,0) ;        /* seek next available sector */
  194.     h_next++ ;
  195.     itoa(next1,h_next) ;
  196.     strfill(buf128,0,MSGSECT) ;        /* init buf128 to all hex 00 */
  197. /*
  198. *            build first piece of msg record
  199. */
  200.     sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  201.         this1,                    /* this rcd # */
  202.         next1,                    /*  points next rcd # */
  203.         msg_delete,                /* delete byte */
  204.         msg_date,
  205.         msg_time,
  206.         msg_to,
  207.         msg_from,
  208.         msg_pass,
  209.         msg_subject);
  210.     rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  211.                     /*  for a message record */
  212. /*
  213. *            build the n+1 piece of msg record
  214. */
  215.  
  216.     len = (strlen(msg_text) / MSG1MAX) + 1; /* calc how many more 128 */
  217.                         /*  byte records to write */
  218.     cnt2 = 1 ;                /* init for substr */
  219.     while (len--)
  220.         {
  221.         itoa(this1,h_next);        /* calc/convert record #'s */
  222.         h_next++;                      
  223.         if (len == 0)
  224.             {
  225.             strcpy(next1,"0");    /* marks last 128 byte piece */
  226.             }            /*  of a msg */
  227.         else
  228.             {
  229.             itoa(next1,h_next);
  230.             }
  231.         strfill(bufmsg0,0,MSG1MAX);
  232.         substr(msg_text,bufmsg0,cnt2,MSG1MAX); /* mv MSG1MAX to buff */
  233.         cnt2 += MSG1MAX;        /* up cnt2 by MSG1MAX */
  234.         strfill(buf128,0,MSGSECT);    /* init buf128 to all hex 00 */
  235.         sprintf(buf128,"%-10s~%-10s~%-2s~%-102s~",
  236.             this1,            /* this rcd # */
  237.             next1,            /* point to next rcd # */
  238.             msg_delete,        /* delete byte */
  239.             bufmsg0);        /* piece of msg */
  240.         rc = write(fd,buf128,MSGSECT);    /* write n+1 128 byte record */
  241.         }
  242.  
  243.     strfill(buf128,26,MSGSECT);        /* fill with all hex 1a */
  244.     rc = write(fd,buf128,MSGSECT);    /* write all hex 1a 128 byte record */
  245.     return(OK);
  246.     }
  247.  
  248. msgrewrt(fd,r_msg)    /* re-write the message file from memory variables */
  249. int    fd,        /* re-writes only the 1st part of a message */
  250.     r_msg;        /* used to update the delete byte */
  251.     {
  252.     int    rc,            /* return code */
  253.         cnt1,
  254.         file_size;
  255.  
  256.     rc = cnt1 = 0;
  257.     if (r_msg > h_next)    /* don't try to seek past end of file */
  258.         {
  259.         return(ERROR);
  260.         }
  261.     if ((rc = seek(fd,r_msg-1,0)) == ERROR)    /* seek to requested sector */
  262.         {
  263.         return(ERROR);
  264.         }
  265.     itoa(this1,r_msg);        /* convert int to char */
  266.     r_msg++;
  267.     itoa(next1,r_msg);
  268.     strfill(buf128,0,MSGSECT);        /* init buf128 to all hex 00 */
  269. /*
  270. *            build first piece of msg record
  271. */
  272.     sprintf(buf128,"%-10s~%-10s~%-2s~%-9s~%-15s~%-21s~%-21s~%-11s~%-21s~",
  273.         this1,                    /* this rcd # */
  274.         next1,                    /* points next rcd # */
  275.         msg_delete,                /* delete byte */
  276.         msg_date,
  277.         msg_time,
  278.         msg_to,
  279.         msg_from,
  280.         msg_pass,
  281.         msg_subject);
  282.     rc = write(fd,buf128,MSGSECT);    /* write the first 128 byte record */
  283.                     /*  for a message record */
  284.     return(OK);
  285.     }
  286.  
  287.  
  288. msgread(fd,msgno)        /* read message number requested */
  289. int    fd,            /* returns ERROR if msg past eof */
  290.     msgno;            /* returns 0 if msg is not 1st piece */
  291.                 /*   of a message */
  292.                 /* returns 0 if msg is deleted */
  293.                 /* returns msg # if successful */
  294.     {
  295.     int    rc,            /* return code */
  296.         msgac,
  297.         cnt1,
  298.         cnt2,
  299.         len,
  300.         next,
  301.         ret_this,
  302.         file_size;
  303.     char     act[11];
  304.  
  305.     msgac = xtable[msgno - 1];
  306.     if (msgac > h_next)        /* don't try to seek past end of file */
  307.         {
  308.         return(ERROR);
  309.         }
  310.     if (msgac == 0)
  311.         {
  312.         return(ERROR);
  313.         }
  314.     if ((rc = seek(fd,msgac-1,0)) == ERROR)
  315.         {
  316.         portsout(CRLF) ;
  317.         portsout("Can't seek on message-file!") ;
  318.         portsout(CRLF) ;
  319.         return(ERROR);        /* when cant find it */
  320.         }
  321.     if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  322.         {
  323.         portsout(CRLF) ;
  324.         portsout("Can't read in message-file!") ;
  325.         portsout(CRLF) ;
  326.         return(ERROR);
  327.         }
  328. /*
  329. *            get first piece of msg record
  330. */
  331. /* do trial read, since if not first record, fields might overflow */
  332. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  333.     buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  334.     if (rc != 9)        /* makes sure we read the 1st piece */
  335.         {        /*  of a message and not in the middle */
  336.         return(0);    /* 0 when is not the msg header */
  337.         }
  338. /* now do the real read since looks like is a good record */
  339. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  340.         this1,                /* this rcd # */
  341.         next1,                /*  points to next rcd # */
  342.         msg_delete,            /* delete byte */
  343.         msg_date,
  344.         msg_time,
  345.         msg_to,
  346.         msg_from,
  347.         msg_pass,
  348.         msg_subject);
  349.     if (rc != 9)        /* makes sure we read the 1st piece */
  350.         {        /*  of a message and not in the middle */
  351.         return(0);    /* 0 when is not the msg header */
  352.         }
  353.  
  354.     if (msg_delete[0] == '9')    /* check for deleted messages */
  355.         {            /*  if so, return as if not found */
  356.         return(0);
  357.         }
  358.  
  359.     ret_this = atoi(this1);    /* return this msg no. */
  360.     next = atoi(next1);
  361.     itoa(act,msgno);
  362.     strcpy(msg_no,act);
  363.     if(msg_delete[0] == '5')
  364.         {
  365.         strcat(msg_no,"*");
  366.         strcpy(msg_subject,"< Private Msg >");
  367.         }
  368.     msg_text[0] = '\0';
  369.     while (next)            /* read until no more pieces for */
  370.         {            /*  this message */
  371.         if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  372.             {
  373.             portsout(CRLF) ;
  374.             portsout("Can't read in message-file(2)!") ;
  375.             portsout(CRLF) ;
  376.             return(ERROR);
  377.             }
  378.         strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  379.         rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  380.             this1,            /* this rcd # */
  381.             next1,            /* point to next rcd # */
  382.             msg_delete,        /* delete byte */
  383.             bufmsg0);        /* piece of msg */
  384.         next = atoi(next1);
  385.         strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  386.                         /*  whole msg array */
  387.         }
  388.     return(ret_this);    /* if all ok, return the msg no. found */
  389.     }
  390.  
  391. msgreadx(fd,msgno)        /* read message number requested */
  392. int    fd,            /* returns ERROR if msg past eof */
  393.     msgno;            /* returns 0 if msg is not 1st piece */
  394.                 /*   of a message */
  395.                 /* returns 0 if msg is deleted */
  396.                 /* returns msg # if successful */
  397.     {
  398.     int    rc,            /* return code */
  399.         msgac,
  400.         cnt1,
  401.         cnt2,
  402.         len,
  403.         next,
  404.         ret_this,
  405.         t1,
  406.         t2,
  407.         t3,
  408.         file_size;
  409.     char    who_am_i[99],
  410.         who_am_I[99],
  411.         sysop[99],
  412.         Sysop[99],
  413.         act[11];
  414.  
  415.     msgac = xtable[msgno - 1];
  416.     if (msgac > h_next)        /* don't try to seek past end of file */
  417.         {
  418.         return(ERROR);
  419.         }
  420.     if (msgac == 0)
  421.         {
  422.         return(ERROR);
  423.         }
  424.     if ((rc = seek(fd,msgac-1,0)) == ERROR)
  425.         {
  426.         portsout(CRLF) ;
  427.         portsout("Can't seek on message-file!") ;
  428.         portsout(CRLF) ;
  429.         return(ERROR);        /* when cant find it */
  430.         }
  431.     if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  432.         {
  433.         portsout(CRLF) ;
  434.         portsout("Can't read in message-file!") ;
  435.         portsout(CRLF) ;
  436.         return(ERROR);
  437.         }
  438. /*
  439. *            get first piece of msg record
  440. */
  441. /* do trial read, since if not first record, fields might overflow */
  442. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  443.     buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  444.     if (rc != 9)        /* makes sure we read the 1st piece */
  445.         {        /*  of a message and not in the middle */
  446.         return(0);    /* 0 when is not the msg header */
  447.         }
  448. /* now do the real read since looks like is a good record */
  449. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  450.         this1,
  451.         next1,                /*  points to next rcd # */
  452.         msg_delete,            /* delete byte */
  453.         msg_date,
  454.         msg_time,
  455.         msg_to,
  456.         msg_from,
  457.         msg_pass,
  458.         msg_subject);
  459.     if (rc != 9)        /* makes sure we read the 1st piece */
  460.         {        /*  of a message and not in the middle */
  461.         return(0);    /* 0 when is not the msg header */
  462.         }
  463.  
  464.     if (msg_delete[0] == '9')    /* check for deleted messages */
  465.         {            /*  if so, return as if not found */
  466.         return(0);
  467.         }
  468.     if (msg_delete[0] == '5')    /* protected msg */
  469.         {
  470.         strcpy(who_am_i,w_fname);
  471.         strcat(who_am_i," ");
  472.         strcat(who_am_i,w_lname);
  473.         strcpy(Sysop,SYSOP);
  474.         sprintf(sysop,"%-21s",Sysop);
  475.         sprintf(who_am_I,"%-21s",who_am_i);
  476.         t1=strcmp(who_am_I,sysop);
  477.         t2=strcmp(who_am_I,msg_to);
  478.         t3=strcmp(who_am_I,msg_from);
  479.         if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  480.             {
  481.             goto zzzz;
  482.             }
  483.         return(-10);
  484.         }
  485. zzzz:
  486.  
  487.     ret_this = atoi(this1);    /* return this msg no. */
  488.     next = atoi(next1);
  489.     itoa(act,msgno);
  490.     strcpy(msg_no,act);
  491.     msg_text[0] = '\0';
  492.     while (next)            /* read until no more pieces for */
  493.         {            /*  this message */
  494.         if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  495.             {
  496.             portsout(CRLF) ;
  497.             portsout("Can't read in message-file(2)!") ;
  498.             portsout(CRLF) ;
  499.             return(ERROR);
  500.             }
  501.         strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  502.         rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  503.             this1,            /* this rcd # */
  504.             next1,            /* point to next rcd # */
  505.             msg_delete,        /* delete byte */
  506.             bufmsg0);        /* piece of msg */
  507.         next = atoi(next1);
  508.         strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  509.                         /*  whole msg array */
  510.         }
  511.     return(ret_this);    /* if all ok, return the msg no. found */
  512.     }
  513. msgreadk(fd,msgno)        /* read message number requested */
  514. int    fd,            /* returns ERROR if msg past eof */
  515.     msgno;            /* returns 0 if msg is not 1st piece */
  516.                 /*   of a message */
  517.                 /* returns 0 if msg is deleted */
  518.                 /* returns msg # if successful */
  519.     {
  520.     int    rc,            /* return code */
  521.         msgac,
  522.         cnt1,
  523.         cnt2,
  524.         len,
  525.         next,
  526.         ret_this,
  527.         t1,
  528.         t2,
  529.         t3,
  530.         file_size;
  531.     char    who_am_i[99],
  532.         who_am_I[99],
  533.         sysop[99],
  534.         Sysop[99],
  535.         act[11];
  536.  
  537.     msgac = xtable[msgno - 1];
  538.     if (msgac > h_next)        /* don't try to seek past end of file */
  539.         {
  540.         return(ERROR);
  541.         }
  542.     if (msgac == 0)
  543.         {
  544.         return(ERROR);
  545.         }
  546.     if ((rc = seek(fd,msgac-1,0)) == ERROR)
  547.         {
  548.         portsout(CRLF) ;
  549.         portsout("Can't seek on message-file!") ;
  550.         portsout(CRLF) ;
  551.         return(ERROR);        /* when cant find it */
  552.         }
  553.     if (read(fd,buf128,MSGSECT) != MSGSECT) /* read 128 byte sector */
  554.         {
  555.         portsout(CRLF) ;
  556.         portsout("Can't read in message-file!") ;
  557.         portsout(CRLF) ;
  558.         return(ERROR);
  559.         }
  560. /*
  561. *            get first piece of msg record
  562. */
  563. /* do trial read, since if not first record, fields might overflow */
  564. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  565.     buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp,buftmp) ;
  566.     if (rc != 9)        /* makes sure we read the 1st piece */
  567.         {        /*  of a message and not in the middle */
  568.         return(0);    /* 0 when is not the msg header */
  569.         }
  570. /* now do the real read since looks like is a good record */
  571. rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~%[^~]~",
  572.         this1,
  573.         next1,                /*  points to next rcd # */
  574.         msg_delete,            /* delete byte */
  575.         msg_date,
  576.         msg_time,
  577.         msg_to,
  578.         msg_from,
  579.         msg_pass,
  580.         msg_subject);
  581.     if (rc != 9)        /* makes sure we read the 1st piece */
  582.         {        /*  of a message and not in the middle */
  583.         return(0);    /* 0 when is not the msg header */
  584.         }
  585.  
  586.     if (msg_delete[0] == '9')    /* check for deleted messages */
  587.         {            /*  if so, return as if not found */
  588.         return(0);
  589.         }
  590.     strcpy(who_am_i,w_fname);
  591.     strcat(who_am_i," ");
  592.     strcat(who_am_i,w_lname);
  593.     strcpy(Sysop,SYSOP);
  594.     sprintf(sysop,"%-21s",Sysop);
  595.     sprintf(who_am_I,"%-21s",who_am_i);
  596.     t1=strcmp(who_am_I,sysop);
  597.     t2=strcmp(who_am_I,msg_to);
  598.     t3=strcmp(who_am_I,msg_from);
  599.     if (t1 == 0 || t2 == 0 || t3 == 0 || user_priv == 32767)
  600.         {
  601.         goto yyyy;
  602.         }
  603.     return(-10);
  604. yyyy:
  605.  
  606.     ret_this = atoi(this1);    /* return this msg no. */
  607.     next = atoi(next1);
  608.     itoa(act,msgno);
  609.     strcpy(msg_no,act);
  610.     msg_text[0] = '\0';
  611.     while (next)            /* read until no more pieces for */
  612.         {            /*  this message */
  613.         if (read(fd,buf128,MSGSECT) != MSGSECT) /* read next sector */
  614.             {
  615.             portsout(CRLF) ;
  616.             portsout("Can't read in message-file(2)!") ;
  617.             portsout(CRLF) ;
  618.             return(ERROR);
  619.             }
  620.         strfill(bufmsg0,0,MSG1MAX);    /* init bufmsg0 to all hex 00 */
  621.         rc = sscanf(buf128,"%[^~]~%[^~]~%[^~]~%[^~]~",
  622.             this1,            /* this rcd # */
  623.             next1,            /* point to next rcd # */
  624.             msg_delete,        /* delete byte */
  625.             bufmsg0);        /* piece of msg */
  626.         next = atoi(next1);
  627.         strcat(msg_text,bufmsg0);    /* tag piece of msg to */
  628.                         /*  whole msg array */
  629.         }
  630.     return(ret_this);    /* if all ok, return the msg no. found */
  631.     }
  632. /*    end of program      */
  633.