home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / ECO30603.ZIP / ECO30603.LZH / ECOLIBBS / eco_fido.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-03-21  |  14.3 KB  |  487 lines

  1. (*
  2.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  3.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  4.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  5.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  6.     ▓▓▓▓▓▓▓▓·──                                              ──·▓▓▓▓▓▓▓▓▓▓▓
  7.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  8.     ▓▓▓▓▓▓▓▓   Unit was conceived, designed and written         ░░▓▓▓▓▓▓▓▓▓
  9.     ▓▓▓▓▓▓▓▓   by Floor A.C. Naaijkens for                      ░░▓▓▓▓▓▓▓▓▓
  10.     ▓▓▓▓▓▓▓▓   UltiHouse Software / The ECO Group.              ░░▓▓▓▓▓▓▓▓▓
  11.     ▓▓▓▓▓▓▓▓                                                    ░░▓▓▓▓▓▓▓▓▓
  12.     ▓▓▓▓▓▓▓▓   (C) MCMXCII by EUROCON PANATIONAL CORPORATION.   ░░▓▓▓▓▓▓▓▓▓
  13.     ▓▓▓▓▓▓▓▓   All Rights Reserved for The ECO Group.           ░░▓▓▓▓▓▓▓▓▓
  14.     ▓▓▓▓▓▓▓▓│                                                  │░░▓▓▓▓▓▓▓▓▓
  15.     ▓▓▓▓▓▓▓▓·──                                              ──·░░▓▓▓▓▓▓▓▓▓
  16.     ▓▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▓▓▓▓▓▓▓▓▓
  17.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  18.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  19.     ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
  20. *)
  21. unit eco_fido;
  22. interface
  23. uses
  24.   eco_lib, dos
  25.  
  26.   ;
  27.  
  28. type
  29.   netmsg = record        { netmessage record structure }
  30.     from, 
  31.     too        : string[35];
  32.     subject    : string[71];
  33.     date       : string[19];
  34.     timesread, 
  35.     destnode, 
  36.     orignode, 
  37.     cost, 
  38.     orignet, 
  39.     destnet, 
  40.     replyto, 
  41.     attr, 
  42.     nextreply  :       word;
  43.     areaname   : string[20];
  44.   end;
  45.  
  46.   pkthdr = record        { packet hdr of packet }
  47.     orignode, 
  48.     destnode, 
  49.     year, 
  50.     month, 
  51.     day, 
  52.     hour, 
  53.     minute, 
  54.     second, 
  55.     baud, 
  56.     orignet, 
  57.     destnet  : word;
  58.   end;
  59.  
  60.   pktmessage = record        { packet hdr of each individual message }
  61.     orignode, 
  62.     destnode, 
  63.     orignet, 
  64.     destnet, 
  65.     attr, 
  66.     cost        :       word;
  67.     date        : string[19];
  68.     too         : string[35];
  69.     from        : string[35];
  70.     subject     : string[71];
  71.     areaname    : string[20];
  72.   end;
  73.  
  74.   archivename = record        { internal record structure used for     }
  75.     mynet,                    { determining the name of of an echomail }
  76.     mynode,                   { archive. i.e. 00fa1fd3.mo1             }
  77.     hisnet, 
  78.     hisnode     : word;
  79.   end;
  80.  
  81.  
  82. const                        { attribute flags }
  83.   _private  = $0001;
  84.   _crash    = $0002;
  85.   _recvd    = $0004;
  86.   _sent     = $0008;
  87.   _file     = $0010;
  88.   _forward  = $0020;     { also know as in-transit }
  89.   _orphan   = $0040;
  90.   _killsent = $0080;
  91.   _local    = $0100;
  92.   _hold     = $0200;
  93.   _freq     = $0800;
  94.  
  95.   months    : array[1..12] of string[3] = (
  96.     'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  97.     'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
  98.   );
  99.  
  100.  
  101. var
  102.   net    :      netmsg;
  103.   ph     :      pkthdr;
  104.   pm     :  pktmessage;
  105.   arcn   : archivename;
  106.  
  107.  
  108.   function  __fpktname                                      :  string;
  109.   function  __fpktmsg                                       :  string;
  110.   function  __fpkthdr                                       :  string;
  111.   function  __fnetmsg                                       :  string;
  112.   function  __fgetnet(gn: string)                           :  string;
  113.   function  __fgetnode(gn: string)                          :  string;
  114.   function  __fmsgdatestamp                                 :  string;
  115.   function  __flastmsgnum(_netpath: string)                 : integer;
  116.   function  __fhex(n : word)                                :  string;
  117.   function  __farcname                                      :  string;
  118.   procedure __fexpnodenum(var list: string; var totalnumber: integer);
  119.   procedure __fcvtnetnode(netnode: string; var net, node: word);
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. implementation
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.   function last(n: byte; str: string): string;
  135.   var temp: string;
  136.   begin
  137.     if (
  138.       n > length(str)
  139.     ) then temp := str else temp := copy(str, succ(length(str) - n), n);
  140.     last := temp;
  141.   end;  {func last}
  142.  
  143.  
  144.  
  145.  
  146.   function wordcnt(str: string): byte;
  147.   var
  148.     w, i       : integer;
  149.     spacebefore: boolean;
  150.   begin
  151.     if str = '' then begin wordcnt := 0; exit end;
  152.     spacebefore := true; w := 0;
  153.     for  i :=  1 to length(str) do begin
  154.       if spacebefore and (str[i] <> ' ') then begin
  155.         w := succ(w); spacebefore := false;
  156.       end else if (
  157.         spacebefore = false) and (str[i] = ' '
  158.       ) then spacebefore := true;
  159.     end;
  160.     wordcnt := w;
  161.   end;
  162.  
  163.  
  164.  
  165.   function locword(startat, wordno: byte;str: string): byte;
  166.   {local proc used by posword and extract word}
  167.   var
  168.     w, l        : integer;
  169.     spacebefore: boolean;
  170.  
  171.   begin
  172.     if (str = '') or (wordno < 1) or (startat > length(str)) then begin
  173.       locword := 0; exit
  174.     end;
  175.     spacebefore := true;
  176.     w := 0; l := length(str);
  177.     startat := pred(startat);
  178.     while (w < wordno) and (startat <= length(str)) do begin
  179.       startat := succ(startat);
  180.       if spacebefore and (str[startat] <> ' ') then begin
  181.         w := succ(w); spacebefore := false;
  182.       end else if (
  183.         (spacebefore = false) and (str[startat] = ' ')
  184.       ) then spacebefore := true;
  185.     end;
  186.     if w = wordno then locword := startat else locword := 0;
  187.   end;
  188.  
  189.  
  190.  
  191.   function extractwords(startword, nowords: byte; st: string): string;
  192.   var start, finish: integer;
  193.   begin
  194.     if st = '' then begin extractwords := ''; exit end;
  195.     start := locword(1, startword, st);
  196.     if start <> 0 then finish := locword(start, succ(nowords), st) else begin
  197.       extractwords := ''; exit
  198.     end;
  199.     if finish <> 0 then repeat
  200.       finish := pred(finish);
  201.     until st[finish] <> ' ' else finish := length(st);
  202.     extractwords := copy(st, start, succ(finish-start));
  203.   end; {func extractwords}
  204.  
  205.  
  206.  
  207.   function __fpktname: string; { creates and returns a unique packet name }
  208.   var
  209.     h, m, s, hs    :   word;
  210.     yr, mo, da, dow:   word;
  211.     wrkstr      : string;
  212.  
  213.   begin
  214.     wrkstr := ''; gettime(h, m, s, hs); getdate(yr, mo, da, dow);
  215.     wrkstr := __juststr(__num(da), '0', 2, _right_just_str) +
  216.       __juststr(__num(h), '0', 2, _right_just_str) +
  217.       __juststr(__num(m), '0', 2, _right_just_str) +
  218.       __juststr(__num(s), '0', 2, _right_just_str
  219.     );
  220.     __fpktname := wrkstr + '.PKT';
  221.   end;
  222.  
  223.  
  224.  
  225.   
  226.   function __fpktmsg: string;       { returns a packet msg hdr }
  227.   var hdr: string;
  228.   begin
  229.     hdr := ''; { type #2 packets... type #1 is obsolete }
  230.     with pm do hdr := #2#0  +
  231.       chr(lo(orignode)) + chr(hi(orignode)) +
  232.       chr(lo(destnode)) + chr(hi(destnode)) +
  233.       chr(lo(orignet))  + chr(hi(orignet)) +
  234.       chr(lo(destnet))  + chr(hi(destnet)) +
  235.       chr(lo(attr))     + chr(hi(attr)) +
  236.       chr(lo(cost))     + chr(hi(cost)) +
  237.       date+#0 + too+#0 + from+#0 + subject+#0 +
  238.       __cvtstr(pm.areaname, _to_upcase_str);
  239.     __fpktmsg := hdr;
  240.   end;
  241.  
  242.  
  243.  
  244.   function __fpkthdr: string;         { returns a packet hdr string }
  245.   var hdr: string;
  246.   begin
  247.     hdr := '';
  248.     with ph do hdr :=
  249.       chr(lo(orignode)) + chr(hi(orignode)) +
  250.       chr(lo(destnode)) + chr(hi(destnode)) +
  251.       chr(lo(year))     + chr(hi(year)) +
  252.       chr(lo(month))    + chr(hi(month)) +
  253.       chr(lo(day))      + chr(hi(day)) +
  254.       chr(lo(hour))     + chr(hi(hour)) +
  255.       chr(lo(minute))   + chr(hi(minute)) +
  256.       chr(lo(second))   + chr(hi(second)) +
  257.       chr(lo(baud))     + chr(hi(baud)) +
  258.       #2#0+
  259.       chr(lo(orignet))  + chr(hi(orignet)) +
  260.       chr(lo(destnet))  + chr(hi(destnet)) +
  261.       #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0#0+
  262.       #0#0#0#0#0#0#0#0#0#0#0#0#0#0#0;  { null field fill space }
  263.     __fpkthdr := hdr;
  264.   end;
  265.  
  266.  
  267.   function __fnetmsg: string; { returns a __fnetmsg hdr string }
  268.   var hdr: string;
  269.   begin
  270.     hdr := ''; hdr := __juststr(net.from, #0, 36, _left_just_str);
  271.     with net do hdr := hdr +
  272.       __juststr(too, #0, 36, _left_just_str) +
  273.       __juststr(subject, #0, 72, _left_just_str) +
  274.       __juststr(date, ' ', 19, _right_just_str) + #0 +
  275.       chr(lo(timesread)) + chr(hi(timesread)) +
  276.       chr(lo(destnode))  + chr(hi(destnode)) +
  277.       chr(lo(orignode))  + chr(hi(orignode)) +
  278.       chr(lo(cost))      + chr(hi(cost)) +
  279.       chr(lo(orignet))   + chr(hi(orignet)) +
  280.       chr(lo(destnet))   + chr(hi(destnet)) +
  281.       #0#0#0#0#0#0#0#0 +
  282.       chr(lo(replyto))   + chr(hi(replyto)) +
  283.       chr(lo(attr))      + chr(hi(attr)) +
  284.       chr(lo(nextreply)) + chr(hi(nextreply)) +
  285.       __cvtstr(areaname, _to_upcase_str);
  286.     __fnetmsg := hdr;
  287.   end;
  288.   
  289.  
  290.  
  291.   function __fmsgdatestamp: string; { creates fido std- 01 jan 89 21: 05: 18 }
  292.   var
  293.     h, m, s, hs         :   word;    { standard msg hdr time/date stamp   }
  294.     y, mo, d, dow       :   word;
  295.     tmp, 
  296.     o1, o2, o3         : string;
  297.  
  298.   begin
  299.     o1 := '';  o2 := '';  o3 := '';  tmp := '';
  300.     getdate(y, mo, d, dow);  gettime(h, m, s, hs);
  301.     o1 := __juststr(__num(d), '0', 2, _right_just_str);
  302.     o2 := months[mo];
  303.     o3 := last(2, __num(y));
  304.     tmp := concat( o1, ' ', o2, ' ', o3, '  ');
  305.     o1 := __juststr(__num(h), '0', 2, _right_just_str);
  306.     o2 := __juststr(__num(m), '0', 2, _right_just_str);
  307.     o3 := __juststr(__num(s), '0', 2, _right_just_str);
  308.     tmp := tmp + concat(o1, ': ', o2, ': ', o3);
  309.     __fmsgdatestamp := tmp;
  310.   end;
  311.  
  312.  
  313.  
  314.   function first(n: byte; st: string): string;
  315.   var temp: string;
  316.   begin
  317.     if n > length(st) then temp := st else temp := copy(st, 1, n);
  318.     first := temp;
  319.   end;  {func first}
  320.  
  321.  
  322.  
  323.   function msgtonum(fnm: string): integer; { used internally by __flastmsgnum }
  324.   var p: byte;
  325.   begin
  326.     p := pos('.', fnm); fnm := first(p-1, fnm); msgtonum := __str(fnm);
  327.   end;
  328.  
  329.  
  330.  
  331.   function __flastmsgnum(_netpath: string): integer;
  332.   { returns the highest numbered xxx.msg in netpath directory }
  333.   var
  334.     _path  :    string;
  335.     temp1, 
  336.     temp2  :    string;
  337.     len    :      byte;
  338.     dxirinf: searchrec;
  339.     num, 
  340.     num1   :   integer;
  341.   
  342.   begin
  343.     num := 0; num1 := 0; temp1 := ''; temp2 := ''; _path := '';
  344.     _path := __backapp(_netpath) + '*.MSG';
  345.     findfirst(_path, archive, dxirinf);
  346.     while doserror=0 do begin
  347.       temp1 := dxirinf.name; num1 := msgtonum(temp1);
  348.       if num1 > num then num := num1; findnext(dxirinf);
  349.     end;
  350.     if num = 0 then num := 1;
  351.     __flastmsgnum := num;
  352.   end;
  353.   
  354.   
  355.  
  356.   
  357.   function __fhex(n: word): string;
  358.   { converts an integer or word to it's __fhex equivelent }
  359.   var
  360.     l        : string[16];
  361.     bhi, blo :       byte;
  362.   
  363.   begin
  364.     l := '0123456789ABCDEF'; bhi := hi(n); blo := lo(n);
  365.     __fhex := (
  366.       copy(l, succ(bhi shr 04), 1) +
  367.       copy(l, succ(bhi and 15), 1) +
  368.       copy(l, succ(blo shr 04), 1) +
  369.       copy(l, succ(blo and 15), 1)
  370.     );
  371.   end;
  372.  
  373.  
  374. {@}
  375.   function __farcname: string;
  376.   { returns the proper name of an echomail archive }
  377.   var c1, c2: longint;
  378.   begin
  379.     c1 := 0; c2 := 0;
  380.     c1 := arcn.mynet - arcn.hisnet;
  381.     c2 := arcn.mynode - arcn.hisnode;
  382.     if c1 < 0 then c1 := 65535 + c1;
  383.     if c2 < 0 then c2 := 65535 + c2;
  384.     __farcname := __fhex(c1) + __fhex(c2);
  385.   end;
  386.   
  387.  
  388.  
  389.   function __fgetnet(gn: string): string;
  390.   { returns the net portion of a net/node string }
  391.   var p: byte;
  392.   begin
  393.     p := pos('/', gn); __fgetnet := first(p-1, gn);
  394.   end;
  395.  
  396.  
  397.  
  398.   function __fgetnode( gn: string ): string;
  399.   { returns the node portion of a net/node string }
  400.   var p: byte;
  401.   begin
  402.     p := pos('/', gn); __fgetnode := last(length(gn)-p, gn);
  403.   end;
  404.  
  405.  
  406.  
  407.   function strip(l, c: char; st: string): string;
  408.   {l is left, center, right, all, ends}
  409.   var i:  byte;
  410.   begin
  411.     case upcase(l) of
  412.       'L': begin       {left}
  413.         while (st[1] = c) and (length(st) > 0) do delete(st, 1, 1);
  414.       end;
  415.       'R': begin       {right}
  416.         while (st[length(st)]=c) and (length(st)>0) do delete(st,length(st),1);
  417.       end;
  418.       'B': begin       {both left and right}
  419.         while (st[1]=c) and (length(st) > 0) do delete(st, 1, 1);
  420.         while (st[length(st)]=c) and (length(st)>0) do delete(st,length(st),1);
  421.       end;
  422.       'A': begin       {all}
  423.         i := 1;
  424.         repeat
  425.           if (st[i]=c) and (length(st)>0) then delete(st, i, 1) else inc(i);
  426.         until (i > length(st)) or (st = '');
  427.       end;
  428.     end; { case }
  429.     strip := st;
  430.   end;  { func }
  431.  
  432.  
  433.  
  434.   procedure __fexpnodenum(var list: string; var totalnumber: integer );
  435.   { expands a list of short form node numbers to their proper       }
  436.   { net/node representations. example:                              }
  437.   { the string: 170/100 101 102 5 114/12 15 17 166/225 226          }
  438.   { would return: 170/100 170/101 170/102 170/5 114/12 114/15 etc.. }
  439.   var
  440.     net, netnode : string[10];
  441.     holdstr, 
  442.     ws1         :     string;
  443.     n1          :    integer;
  444.   begin
  445.     net := ''; netnode := ''; holdstr := ''; ws1 := ''; n1 := 0;
  446.     totalnumber := 0; totalnumber := wordcnt(list);
  447.     for n1 := 1 to totalnumber do begin
  448.       ws1 := extractwords(n1, 1, list);
  449.       if pos('/', ws1) <> 0 then begin
  450.         net := __fgetnet(ws1)+'/'; netnode := ws1;
  451.       end else netnode := net+ws1;
  452.       holdstr := holdstr + ' ' + strip('A', ' ', netnode);
  453.     end;
  454.   end;
  455.  
  456.  
  457.  
  458.  
  459.   procedure __fcvtnetnode(netnode: string; var net, node: word);
  460.   { returns net and node as words from a net/node string }
  461.   var wstr: string[6];
  462.   begin
  463.     wstr := __fgetnet(netnode);  net  := __str(wstr);
  464.     wstr := __fgetnode(netnode); node := __str(wstr);
  465.   end;
  466.  
  467.  
  468.  
  469.  
  470.  
  471. begin
  472.   { initialize the data structures }
  473.   fillchar(net, sizeof(net), #0); fillchar(pm, sizeof(pm), #0);
  474.   fillchar(ph, sizeof(ph), #0); fillchar(arcn, sizeof(arcn), #0);
  475. end. { unit }
  476.  
  477.  
  478.  
  479.     { FIDONET UNIT by Kelly Drown, Copyright (C)1988, 89-LCP  }
  480.     {                                   All rights reserved  }
  481.     { If you use this unit in your own programming, I ask    }
  482.     { only that you give me credit in your documentation.    }
  483.     { I ask this instead of money. All of the following code }
  484.     { is covered under the copyright of Laser Computing Co.  }
  485.     { and may be used in your own programming provided the   }
  486.     { terms above have been satisfactorily met.              }
  487.