home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / HSRC_117.ZIP / EXPORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-25  |  12.8 KB  |  520 lines

  1. #include "msgg.h"
  2. #include "twindow.h"
  3. #include "keys.h"
  4. #include "headedit.h"
  5.  
  6.  
  7. /* Export messages */
  8.  
  9. void pascal make_file (void) {
  10.  
  11.     char xport[6];
  12.     char s[30];
  13.     word temp;
  14.     int returncode;
  15.     word tempmess;
  16.     struct ffblk f;
  17.     WINDOW *wnd;
  18.     FIELD *fld;
  19.  
  20. ReStart:
  21.         wnd=establish_window(1,maxy-7,6,80);
  22.         set_border(wnd,3);
  23.         set_title(wnd," Export message ");
  24.         set_colors(wnd,BORDER,7,0,0);
  25.         display_window(wnd);
  26.         wcursor(wnd,0,0);
  27.         wprintf(wnd," F10 to export or ESC to abort");
  28.         sprintf(xport,"%u",messno);
  29.         sprintf(s,"Export #(1-%u):",nomess);
  30.         wprompt(wnd,1,2,s);
  31.         wprompt(wnd,1,3,"Filename:");
  32.         fld=establish_field(wnd,21,2,msk5,xport,'N');
  33.         field_window(fld,"export#   ",40,6);
  34.         fld=establish_field(wnd,11,3,msk65,filenamer,'A');
  35.         field_window(fld,"exportname",40,7);
  36. Over:
  37.         prep_template(wnd);
  38.         returncode=data_entry(wnd);
  39.         if (returncode==ESC) {
  40.             delete_window(wnd);
  41.             return;
  42.         }
  43.         if (returncode!=F10) goto Over;
  44.         returncode=0;
  45.         rstrip(filenamer);
  46.         temp=(word)atol(xport);
  47.         if (!strlen(filenamer) || temp<1 || temp>nomess) {
  48.             error_message(" Invalid parameter ");
  49.             pause();
  50.             goto Over;
  51.         }
  52.         if (!findfirst(filenamer,&f,0)) {
  53.             any_message(" Exists...[O]verwrite [A]ppend [R]eEnter? [A] ");
  54. ReInput:
  55.             returncode=toupper(get_char());
  56.             if (returncode=='R' || returncode==ESC) {
  57.                 clear_message();
  58.                 goto Over;
  59.             }
  60.             if (returncode=='O') unlink(filenamer);
  61.             else if (returncode!='\r' && returncode!='A') {
  62.                 bell();
  63.                 goto ReInput;
  64.             }
  65.         }
  66.         clear_message();
  67.         tempmess=messno;
  68.         messno=temp;
  69.         get_mess(0);
  70.         delete_window(wnd);
  71.         wnd=establish_window(0,maxy-7,19,maxx);
  72.         set_border(wnd,3);
  73.         set_title(wnd," Exporting message ");
  74.         set_colors(wnd,BORDER,7,0,0);
  75.         display_window(wnd);
  76.         wcursor(wnd,0,0);
  77.         if (!export(filenamer,((currarea->attr & NET) || (currarea->attr & ALTERNATE)),TEXTFILE,"","",wnd)) {
  78.             delete_window(wnd);
  79.             goto ReStart;
  80.         }
  81.         clear_message();
  82.         delete_window(wnd);
  83.         messno=tempmess;
  84.         get_mess(0);
  85. }
  86.  
  87.  
  88. int pascal export (file,net,type,olddate,oldfrom,wndd)
  89.  
  90.  char *file;
  91.  char net;
  92.  char type;
  93.  char *olddate;
  94.  char *oldfrom;
  95.  void *wndd;
  96.  
  97. {
  98.  
  99.  static char text[124];
  100.  static char lines=0;
  101.  WINDOW *wnd;
  102.  register word x;
  103.  int pp;
  104.  char message[82];
  105.  char far *hold;
  106.  char *tempo;
  107.  char *p;
  108.  char width;
  109.  char noquote=0;
  110.  
  111.  wnd=(WINDOW *)wndd;
  112.  if(!strnicmp(file,"MSGTMP",6)) get_rid();
  113.  if(type != EDITIT) strcpy(to_domain,curaddress.domain);
  114.  *replyid=0;
  115.  if (type==TEXTFILE) width=78;
  116.  else if (type==PRINTIT) {
  117.     width=textwidth;
  118.     if (*olddate) lines=0;
  119.  }
  120.  else if (type==QUOTE || type==ECHO2NET) width=65;
  121.  else if (type==EDITIT) width=71;
  122.  
  123.  if(type!=NOQUOTE) {
  124.      if((pp=(_open(file,O_WRONLY | O_BINARY | O_DENYWRITE)))==-1)
  125.        if((pp=(creat(file,S_IWRITE)))==-1) {
  126.          sprintf(text,"Cannot open %s",file);
  127.          error_message(text);
  128.          pause();
  129.          return(0);
  130.      }
  131.  }
  132.  lseek(pp,0L,SEEK_END);
  133.  if (type==TEXTFILE || type==PRINTIT) {
  134.      if (type==PRINTIT) {
  135.         for (x=0;x<strlen(beforeheader);x++) {
  136.             if (beforeheader[x]=='\n') {
  137.                 lines++;
  138.                 ffprintf(pp,"\r\n");
  139.                 if(wnd)wprintf(wnd,"\n");
  140.             }
  141.             else {
  142.                 ffprintf(pp,"%c",beforeheader[x]);
  143.                 if(wnd)wprintf(wnd,"\n");
  144.             }
  145.             if(beforeheader[x]=='\xc') lines=0;
  146.         }
  147.      }
  148.      if (type==PRINTIT) if((lines+8)>(pagelength-bottommargin)) {
  149.         ffprintf(pp,"\xc\r\n");
  150.         if(wnd)wprintf(wnd,"\n <=-Page Break-=>\n\n");
  151.         lines=1;
  152.      }
  153.      if (type==PRINTIT) if (lines<topmargin) {
  154.         for (x=lines;x<topmargin;x++) {
  155.             ffprintf(pp,"\r\n");
  156.             if(wnd)wprintf(wnd,"\n");
  157.         }
  158.         lines=topmargin;
  159.      }
  160.      if (type==PRINTIT) {
  161.         for (x=0;x<(word)leftmargin;x++) {
  162.             ffprintf(pp," ");
  163.             if(wnd)wprintf(wnd," ");
  164.         }
  165.      }
  166.      lines+=7;
  167.      ffprintf(pp,"Board #%u  *  Message #%u: ",areano,messno);
  168.      if(wnd)wprintf(wnd,"Board #%u  *  Message #%u: ",areano,messno);
  169.      if ((msg.attr & MSGPRIVATE)!=0) {
  170.         if(wnd)wprintf(wnd,"(Priv)");
  171.         ffprintf(pp,"(Priv)");
  172.      }
  173.      if ((msg.m_attr & MSGDELETED)!=0) {
  174.         ffprintf(pp,"(Del)");
  175.         if(wnd)wprintf(wnd,"(Del)");
  176.      }
  177.      if ((msg.attr & MSGCRASH)!=0) {
  178.         ffprintf(pp,"(CRASH)");
  179.         if(wnd)wprintf(wnd,"(CRASH");
  180.      }
  181.      if ((msg.attr & MSGKILL)!=0) {
  182.         ffprintf(pp,"(Kill)");
  183.         if(wnd)wprintf(wnd,"(Kill)");
  184.      }
  185.      if ((msg.attr & MSGSENT)!=0) {
  186.         ffprintf(pp,"(Sent)");
  187.         if(wnd)wprintf(wnd,"(Sent)");
  188.      }
  189.      if ((msg.attr & MSGFWD)!=0) {
  190.         ffprintf(pp,"(Fwd)");
  191.         if(wnd)wprintf(wnd,"(Fwd)");
  192.      }
  193.      if ((msg.attr & MSGREAD)!=0) {
  194.         ffprintf(pp,"(Recd)");
  195.         if(wnd)wprintf(wnd,"(Recd)");
  196.      }
  197.      if ((msg.attr & MSGRRQ)!=0) {
  198.         ffprintf(pp,"(Rec.Req)");
  199.         if(wnd)wprintf(wnd,"(Rec.Req)");
  200.      }
  201.      if ((msg.attr & MSGCPT)!=0) {
  202.         ffprintf(pp,"(Recpt)");
  203.         if(wnd)wprintf(wnd,"(Recpt)");
  204.      }
  205.      if ((msg.attr & MSGARQ)!=0) {
  206.         ffprintf(pp,"(Aud.Req)");
  207.         if(wnd)wprintf(wnd,"(Aud.Req)");
  208.      }
  209.      if ((msg.attr & MSGURQ)!=0) {
  210.         ffprintf(pp,"(Up.Req)");
  211.         if(wnd)wprintf(wnd,"(Up.Req)");
  212.      }
  213.      ffprintf(pp,"(Read %u times)\r\n",msg.times);
  214.      if(wnd)wprintf(wnd,"(Read %u times)\n",msg.times);
  215.  
  216.      if (type==PRINTIT) {
  217.         for (x=0;x<(word)leftmargin;x++) {
  218.             ffprintf(pp," ");
  219.             if(wnd)wprintf(wnd," ");
  220.          }
  221.      }
  222.      ffprintf(pp,"To:   %s",msg.to);
  223.      if(wnd)wprintfraw(wnd,"To:   %s",msg.to);
  224.      if ((net)!=0) {
  225.         ffprintf(pp," (%u/%u)",msg.dest_net,msg.dest);
  226.         if(wnd)wprintf(wnd," (%u/%u)",msg.dest_net,msg.dest);
  227.      }
  228.      ffprintf(pp,"\r\n");
  229.      if(wnd)wprintf(wnd,"\n");
  230.      if (type==PRINTIT) {
  231.         for (x=0;x<(word)leftmargin;x++) {
  232.             ffprintf(pp," ");
  233.             if(wnd)wprintf(wnd," ");
  234.         }
  235.      }
  236.      ffprintf(pp,"From: ");
  237.      if(wnd)wprintf(wnd,"From: ");
  238.      if ((msg.m_attr & MSGANON)!=0) {
  239.        ffprintf(pp,"*Anonymous* (%s)",msg.from);
  240.        if(wnd)wprintfraw(wnd,"*Anonymous* (%s)",msg.from);
  241.      }
  242.      else {
  243.         ffprintf(pp,"%s",msg.from);
  244.         if(wnd)wprintfraw(wnd,"%s",msg.from);
  245.      }
  246.      if (net) {
  247.         ffprintf(pp," (%u/%u)",msg.orig_net,msg.orig);
  248.         if(wnd)wprintf(wnd,"(%u/%u)",msg.orig_net,msg.orig);
  249.      }
  250.      ffprintf(pp,"\r\n");
  251.      if(wnd)wprintf(wnd,"\n");
  252.      if (type==PRINTIT) {
  253.         for (x=0;x<(word)leftmargin;x++) {
  254.             ffprintf(pp," ");
  255.             if(wnd)wprintf(wnd," ");
  256.         }
  257.      }
  258.      ffprintf(pp,"On:   ");
  259.      if(wnd)wprintf(wnd,"On:   ");
  260.  
  261.      if ((msg.m_attr & MSGANON)!=0) {
  262.        ffprintf(pp,"%9.9s",msg.date);
  263.        if(wnd)wprintfraw(wnd,"%9.9s",msg.date);
  264.      }
  265.      else {
  266.         ffprintf(pp,"%s",msg.date);
  267.         if(wnd)wprintfraw(wnd,"%s",msg.date);
  268.      }
  269.      ffprintf(pp,"\r\n");
  270.      if(wnd)wprintf(wnd,"\n");
  271.      if (type==PRINTIT) {
  272.         for (x=0;x<(word)leftmargin;x++) {
  273.             ffprintf(pp," ");
  274.             if(wnd)wprintf(wnd," ");
  275.         }
  276.      }
  277.  
  278.      if ((msg.attr & MSGFILE)!=0) {
  279.         ffprintf(pp,"File: ");
  280.         if(wnd)wprintf(wnd,"File: ");
  281.      }
  282.      else if ((msg.attr & MSGFRQ)!=0) {
  283.         ffprintf(pp,"FReq: ");
  284.         if(wnd)wprintf(wnd,"FReq: ");
  285.      }
  286.      else if ((msg.attr & MSGURQ)!=0) {
  287.         ffprintf(pp,"UReq: ");
  288.         if(wnd)wprintf(wnd,"UReq: ");
  289.      }
  290.      else {
  291.         ffprintf(pp,"Subj: ");
  292.         if(wnd)wprintf(wnd,"Subj: ");
  293.      }
  294.      ffprintf(pp,"%s\r\n\r\n",msg.subj);
  295.      if(wnd)wprintfraw(wnd,"%s\n\n",msg.subj);
  296.      if (type==PRINTIT) {
  297.         for (x=0;x<strlen(afterheader);x++) {
  298.             if (afterheader[x]=='\n') {
  299.                 lines++;
  300.                 ffprintf(pp,"\r\n");
  301.                 if(wnd)wprintf(wnd,"\n");
  302.             }
  303.             else {
  304.                 ffprintf(pp,"%c",afterheader[x]);
  305.                 if(wnd)wprintfraw(wnd,"%c",afterheader[x]);
  306.             }
  307.         }
  308.      }
  309.  }
  310.  
  311.  if (type==QUOTE || type==ECHO2NET) {
  312.  
  313.     if(editor) {
  314.         if (get_qstring(quotestring)==NULL) {
  315.             _close(pp);
  316.             get_rid();
  317.             return 0;
  318.         }
  319.     }
  320.     else *quotestring=0;
  321.  
  322.     if(!strcmp(quotestring,"NOQUOTE")) {
  323.         *quotestring=0;
  324.         noquote=1;
  325.     }
  326.     if(type==ECHO2NET) {
  327.         ffprintf(pp,"  *Replying to msg in %s\r\n",currarea->name);
  328.         if(*quotestring || noquote) ffprintf(pp,"\r\n");
  329.     }
  330.     if(noquote && msg.o_zone) {
  331.         _close(pp);
  332.         return 1;
  333.     }
  334.     if (!*quotestring && !noquote) {
  335.         if(before_quote) {
  336.             ffprintf(pp,"\r\n");
  337.             ffprintf(pp,before_quote,olddate,msg.from,oldfrom,msg.subj);
  338.         }
  339.         if(after_before) {
  340.             ffprintf(pp,"\r\n");
  341.             ffprintf(pp,after_before,olddate,msg.from,oldfrom,msg.subj);
  342.             ffprintf(pp,"\r\n\r\n");
  343.         }
  344.     }
  345.  }
  346.  
  347.  hold=get_text();
  348.  if(hold==NULL) return 0;
  349.  if(!ctla) strip_seenbys(hold);
  350.  strip_blanklines(hold);
  351.  if (!*hold) {
  352.     _close(pp);
  353.     free(hold);
  354.     return 0;
  355.  }
  356.  p=hold;
  357.  
  358.       while (*p) {
  359.           if (type==QUOTE || type==ECHO2NET || type==NOQUOTE) {
  360.             if (strcspn(p,">")<6) width=80-(strlen(quotestring) * (strcspn(p,">")<3));
  361.             if(*p=='\01') width=80;
  362.             else width=67;
  363.           }
  364.           strcpy(message,write_line(&p,width,1));
  365.  
  366.           if (type==ECHO2NET) {
  367.             if(!strncmp(message,PATHSTRING,6)) {
  368.                 memmove(&message[2],&message[1],strlen(&message[2]));
  369.                 message[1]='R';
  370.                 ffprintf(pp,"%s\r\n",message);
  371.                 continue;
  372.             }
  373.           }
  374.           if (type==QUOTE || type==NOQUOTE || type==ECHO2NET) {
  375.            if (!strncmp(message,PATHSTRING,6) && !ctla) break;
  376.            if(msg.o_zone==0) {
  377.             if (!strncmp(message,FMPTSTRING,5)) {
  378.                 msg.o_point=(char)atoi(&message[5]);
  379.                 continue;
  380.             }
  381.             else if (!strncmp(message,"\01INTL",5)) {
  382.                 strtok(message," :");
  383.                 strtok(0," ");
  384.                 tempo=strtok(0,":");
  385.                 if(tempo) if ((word)atoi(tempo)) msg.o_zone=(word)atol(tempo);
  386.                 continue;
  387.             }
  388.             if (!strncmp(message,"\01DOMAIN",7)) {
  389.                 strtok(message," ");
  390.                 tempo=strtok(0,"\r\n");
  391.                 if(tempo) {
  392.                     strncpy(to_domain,tempo,37);
  393.                     to_domain[36]=0;
  394.                 }
  395.                 continue;
  396.             }
  397.            }
  398.            if (!strncmp(message,"\01MSGID",6)) {
  399.  
  400.                 char *p;
  401.                 char *ispoint;
  402.                 char *isdomain;
  403.                 char *isnumsign;
  404.                 char *mss;
  405.  
  406.                 strncpy(replyid,&message[7],80);
  407.                 replyid[79]=0;
  408.                 lstrip(replyid);
  409.                 rstrip(replyid);
  410.                 mss=message;
  411.                 ispoint=strchr(mss,'.');
  412.                 isdomain=strchr(mss,'@');
  413.                 isnumsign=strchr(mss,'#');
  414.                 if(isnumsign) {        /* For [user@]domain#z:n/n.p */
  415.                     if(isdomain) {
  416.                         if(isnumsign<isdomain) {
  417.                             strtok(mss,"@");
  418.                             strncpy(msg.to,mss,36);
  419.                             msg.to[35]=0;
  420.                             mss=strtok(0,"\n");
  421.                             isdomain=NULL;    /* Was username */
  422.                         }
  423.                     }
  424.                     strtok(mss,"#");
  425.                     strncpy(to_domain,mss,37);
  426.                     to_domain[36]=0;
  427.                     mss=strtok(0,"\n");
  428.                 }
  429.                 strtok(mss," :");
  430.                 p=strtok(0,":");
  431.                 if(p)msg.o_zone=(word)atol(p);
  432.                 p=strtok(0,"/");
  433.                 msg.orig_net=(word)atol(p);
  434.                 if(ispoint) p=strtok(0,".");
  435.                 else if (isdomain) p=strtok(0,"@");
  436.                 else p=strtok(0," ");
  437.                 if(p)msg.orig=(word)atol(p);
  438.                 if(ispoint) {
  439.                     p=strtok(0,"@ ");
  440.                     if(p && (word)atol(p) && atol(p)<65536L)
  441.                         msg.o_point=(word)atol(p);
  442.                 }
  443.                 if(isdomain) {
  444.                     p=strtok(0," \r");
  445.                     if(p) strncpy(to_domain,p,37);
  446.                     to_domain[36]=0;
  447.                 }
  448.                 continue;
  449.            }
  450.            if (*message=='\x1' && !ctla) continue;
  451.            if(type==NOQUOTE) continue;
  452.            if (!*message || !strcmp(message," ") || !*quotestring) ffprintf(pp,"%s\r\n",message);
  453.            else if (strcspn(message,">")>3) ffprintf(pp,"%s%s\r\n",quotestring,message);
  454.            else ffprintf(pp," >%s\r\n",message);
  455.           }
  456.           else {
  457.             if (type==EDITIT) {
  458.                 if(!strncmp(message," * Origin: ",11)) continue;
  459.                 if(!strncmp(message,"--- ",4)) continue;
  460.                 if(!strncmp(message,"\01REPLY: ",8)) {
  461.                     strncpy(replyid,&message[7],80);
  462.                     replyid[79]=0;
  463.                     lstrip(replyid);
  464.                     rstrip(replyid);
  465.                     continue;
  466.                 }
  467.                 if (*message=='\01') continue;
  468.             }
  469.             if (type==PRINTIT) {
  470.                 if((lines)>(pagelength-bottommargin)) {
  471.                     ffprintf(pp,"\xc");
  472.                     if(wnd)wprintf(wnd,"\n<=-Page Break-=>\n");
  473.                     for (x=0;x<topmargin;x++) {
  474.                         ffprintf(pp,"\r\n");
  475.                         if(wnd)wprintf(wnd,"\n");
  476.                     }
  477.                     lines=topmargin;
  478.                 }
  479.             }
  480.             if (type==PRINTIT) {
  481.                 for (x=0;x<(word)leftmargin;x++) {
  482.                     ffprintf(pp," ");
  483.                     if(wnd)wprintf(wnd," ");
  484.                 }
  485.             }
  486.             if(!ctla && *message=='\01');
  487.             else {
  488.                 ffprintf(pp,"%s\r\n",message);
  489.                 if(wnd)wprintfraw(wnd,"%s\n",message);
  490.                 lines++;
  491.             }
  492.           }
  493.        }
  494.        if(hold)free(hold);
  495.        if (type==QUOTE && !*quotestring && !noquote) {
  496.             if(after_quote) {
  497.                 ffprintf(pp,after_quote);
  498.                 ffprintf(pp,"\r\n\r\n");
  499.             }
  500.        }
  501.        if (type==PRINTIT) {
  502.             for (x=0;x<strlen(aftertext);x++) {
  503.                 if (aftertext[x]=='\n') {
  504.                     lines++;
  505.                     ffprintf(pp,"\r\n");
  506.                     if(wnd)wprintf(wnd,"\n");
  507.                 }
  508.                 else {
  509.                     ffprintf(pp,"%c",aftertext[x]);
  510.                     if(wnd)wprintfraw(wnd,"%c",aftertext[x]);
  511.                 }
  512.                 if(aftertext[x]=='\xc') lines=0;
  513.             }
  514.        }
  515.        if(type!=NOQUOTE)_close(pp);
  516.  
  517.     return 1;
  518. }
  519.  
  520.