home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / beehive / bbs / rover12a.arc / MUNDANE.INC < prev    next >
Text File  |  1991-08-11  |  11KB  |  482 lines

  1. {** MUNDANE.INC}
  2.  
  3. {--- system routines ---}
  4.  
  5. function bye_present: boolean;
  6. begin
  7.   bye_present:= 77 = bdos(32, 241);
  8. end; {bye_present}
  9.  
  10. function bye_start: boolean;
  11. begin
  12.   bye_start:= mem[$20] = 0;
  13. end; {bye_start}
  14.  
  15. procedure set_user(st: str2);
  16. {set new user area while in program}
  17. var
  18.   number: integer;
  19.   code: integer;
  20. begin
  21.   if length(st) = 0 then exit;
  22.   val(st, number, code);
  23.   if not (code = 0) then exit;
  24.   if (number< 0) or (number > 15) then exit;
  25.   bdos(32, number);
  26. end; {set_user}
  27.  
  28. procedure setupdrive;
  29. var
  30.   drive: string[3];
  31. begin
  32.   drive:= area;
  33.   if length(drive) = 0 then exit;
  34.   bdos(14, ord(drive[1]) - $41);
  35.   if length(drive) < 2 then exit;
  36.   delete(drive,1,1);
  37.   set_user(drive);
  38. end; {setupdrive}
  39.  
  40. function allcaps(st: str30): str30;
  41. var
  42.   I: byte;
  43. begin
  44.   for I:= 1 to length(st) do
  45.     st[I]:= upcase(st[I]);
  46.   allcaps:= st;
  47. end; {allcaps}
  48.  
  49. function lowCase(ch: char): char;
  50. begin
  51.   if (ch in ['A'..'Z']) then
  52.     ch:= chr(ord(ch) + $20);
  53.   lowCase:= ch;
  54. end; {lowCase}
  55.  
  56. function fixcaps(st: str80): str80;
  57. {Adjust start of word to upper case,}
  58. {rest of word to lower case}
  59. var
  60.   flag: boolean;
  61.   I: byte;
  62. begin
  63.   flag:= true;
  64.   for I:= 1 to length(st) do
  65.   begin
  66.     if flag then st[I]:= upCase(st[I])
  67.       else st[I]:= lowCase(st[I]);
  68.     flag:= false;
  69.     if (st[I] in [' ', '-']) then flag:= true;
  70.   end;
  71.   fixcaps:= st;
  72. end; {fixcaps}
  73.  
  74. function byte_to_string(bt: byte): str2;
  75. var
  76.   st: str2;
  77. begin
  78.   str(bt, st);
  79.   if (length(st) < 2) then st:= '0' + st;
  80.   byte_to_string:= st;
  81. end; {byte_to_string}
  82.  
  83. {--- disk file routines ---}
  84.  
  85. function exists(filname: str14): boolean;
  86. begin
  87.   assign(oldfil, filname);
  88.   {$I-}
  89.   reset(oldfil);
  90.   {$I+}
  91.   exists:= (IORESULT = 0);
  92. end; {exists}
  93.  
  94. function existstext(filname: str14): boolean;
  95. begin
  96.   assign(textfil, filname);
  97.   {$I-}
  98.   reset(textfil);
  99.   {$I+}
  100.   existstext:= (IORESULT = 0);
  101. end; {existstext}
  102.  
  103. function opennewtext(filname: str14): boolean;
  104. begin
  105.   assign(textfil, filname);
  106.   {$I-}
  107.   rewrite(textfil);
  108.   {$I+}
  109.   opennewtext:= (IORESULT = 0);
  110. end; {opennewtext}
  111.  
  112. procedure opennew(filname: str14);
  113. begin
  114.   assign(newfil, filname);
  115.   rewrite(newfil);
  116. end; {opennew}
  117.  
  118. procedure openindex;
  119. begin
  120.   assign(ndxfil, 'INDEX.PBS');
  121.   reset(ndxfil);
  122. end; {openindex}
  123.  
  124. function openfiles: boolean;
  125. label abortloc;
  126. var
  127.   OK: boolean;
  128. begin
  129.   assign(ndxfil, 'INDEX.PBS');
  130.   {$I-}
  131.   reset(ndxfil);
  132.   {$I+}
  133.   OK:= (IORESULT = 0 );
  134.   if not OK then goto abortloc;
  135.   assign(msgndxfil, 'MSGINDEX.PBS');
  136.   {$I-}
  137.   reset(msgndxfil);
  138.   {$I+}
  139.   OK:= OK and (IORESULT = 0 );
  140.   if not OK then goto abortloc;
  141.   assign(messagesfil, 'MESSAGES.PBS');
  142.   {$I-}
  143.   reset(messagesfil);
  144.   {$I+}
  145.   OK:= OK and (IORESULT = 0);
  146. ABORTLOC:
  147.   openfiles:= OK;
  148. end; {openfiles}
  149.  
  150. procedure closefiles;
  151. begin
  152.   close(messagesfil);
  153.   close(msgndxfil);
  154.   close(textfil);
  155. end; {closefiles}
  156.  
  157. procedure saveindex;
  158. begin
  159.   writeln('updating INDEX.PBS');
  160.   openindex;
  161.   begin
  162.     {setup buffer}
  163.     with index do
  164.     begin
  165.       {date:   str8;}
  166.       ndxbuffer[4]:= lo(next_messages_rec);
  167.       ndxbuffer[5]:= hi(next_messages_rec);
  168.       ndxbuffer[6]:= lo(next_message_number);
  169.       ndxbuffer[7]:= hi(next_message_number);
  170.       ndxbuffer[8]:= lo(last_msgindex_rec);
  171.       ndxbuffer[9]:= hi(last_msgindex_rec);
  172.     end; {with}
  173.     blockwrite(ndxfil, ndxbuffer, 1);
  174.     close(ndxfil);
  175.   end;
  176. end; {saveindex}
  177.  
  178. function opensnapfile(numb: integer): boolean;
  179. var
  180.   numbstr: string[3];
  181.   newname: string[14];
  182.   result: boolean;
  183. begin
  184.   close(snapfil);
  185.   str(numb, numbstr);
  186.   case length(numbstr) of
  187.     1: numbstr:= '00' + numbstr;
  188.     2: numbstr:= '0'  + numbstr;
  189.   end; {case}
  190.   newname:= snapfilename + '.' + numbstr;
  191.   assign(snapfil, newname);
  192.   {$I-}
  193.   reset(snapfil);
  194.   {$I+}
  195.   result:= (IORESULT = 0);
  196.   if result then writeln('transfering ' + newname);
  197.   opensnapfile:= result;
  198. end; {opensnapfile}
  199.  
  200. {--- more system routines ---}
  201.  
  202. procedure finis(bt: byte);
  203. begin
  204.   case bt of
  205.     0: begin
  206.          writeln('Usage:  ROVER [stm?]');
  207.          writeln('Where:      s = scan/export only (default)');
  208.          writeln('            t = toss/import only');
  209.          writeln('            m = menu (default)');
  210.          writeln('            ? = usage prompt');
  211.          writeln;
  212.          writeln('Defaults to menu and export when command file not present.');
  213.        end;
  214.     3: begin
  215.          writeln;
  216.          writeln;
  217.          writeln('Session terminated by user');
  218.        end;
  219.   end; {case}
  220.   if bt in [0, 3] then halt;
  221.  
  222.   closefiles;
  223.   case bt of
  224.     1: writeln('Done');
  225.     2: writeln('++ Cannot open files, aborting ++', ^G);
  226.   end; {case}
  227.   halt;
  228. end; {finis}
  229.  
  230. function readKey: char;
  231. var
  232.   ch: char;
  233. begin
  234.   read(kbd, ch);
  235.   readKey:= ch;
  236. end; {readKey}
  237.  
  238. function readKeyETX: char;
  239. var
  240.   ch: char;
  241. begin
  242.   ch:= readKey;
  243.   if (ch= ETX) then finis(3);
  244.   readKeyETX:= ch;
  245. end; {readkeyetx}
  246.  
  247. (*
  248. procedure load(fname: str14);
  249. begin
  250.   if open(fname) then begin mem[0]:= $C3; execute(fil); end
  251.     else writeln('++ file BBS.COM not found ++');
  252. end; {load}
  253. *)
  254.  
  255. {--- buffering routines ---}
  256.  
  257. function buffertostring(buffer: bufftype; pos, numb: byte): str30;
  258. label endbuf;
  259. var
  260.   I, v : byte;
  261.   st: str30;
  262. begin
  263.   st:= '';
  264.   for I:= (pos) to (pos + numb - 1) do
  265.   begin
  266.     v:= buffer[I];
  267.     if (v = 0) then goto endbuf;
  268.     st:= st + chr(v);
  269.   end;
  270. ENDBUF:
  271.   buffertostring:= st;
  272. end; {buffertostring}
  273.  
  274. function padstr0(st: str30; numb: byte): str30;
  275. var
  276.   I, len: byte;
  277. begin
  278.   len:= length(st);
  279.   if (numb > 30) then numb:= 30;
  280.   if len < 30 then
  281.     for I:= len + 1 to numb
  282.       do st:= st + NUL;
  283.   padstr0:= st;
  284. end; {padstr0}
  285.  
  286. function fillstr16(ch: str2): str16;
  287. {fill 16 char string with single char}
  288. var
  289.   a: byte;
  290.   st: str16;
  291. begin
  292.   st:= '';
  293.   for a:= 1 to 16 do
  294.     st:= st + ch;
  295.   fillstr16:= st;
  296. end; {fillstr16}
  297.  
  298. procedure transfertobuffer;
  299. {transfer string array to byte array}
  300. var
  301.   b, j, p: byte;
  302.   st: str16;
  303. begin
  304.   for b:= 1 to 8 do
  305.   begin
  306.     st:= line1[b];
  307.     p:= (b-1) * 16;
  308.     for j:= 1 to 16 do
  309.       filebuffer[j + p]:= ord(st[j]);
  310.    end;
  311. end; {filebuffer}
  312.  
  313. {--- record routines ---}
  314.  
  315. procedure update_msgindexrec;
  316. begin
  317.   msgindex.receiver:= receiver;
  318.   msgindex.date:= date;
  319.   msgindex.time:= time;
  320.   msgindex.subject:= subject;
  321.   msgindex.sender:= sender;
  322.   with msgindex do
  323.   begin
  324.     msg_no:= index.next_message_number;
  325.     start_rec_no:= index.next_messages_rec;
  326.     nextrecord:= start_rec_no + num_of_recs;
  327.     msgindex_rec_no:= index.last_msgindex_rec + 1;
  328.     mirecord:= msgindex_rec_no;
  329.     msgindexrec:= mirecord;
  330.    { public:= 0; }
  331.    { folder:= 4; }
  332.     deleted:= 0;
  333.     null:= 0;
  334.   end; {with}
  335. end; {update_msgindexrec}
  336.  
  337. procedure update_indexrec;
  338. begin
  339.   with index do
  340.   begin
  341.     date:= msgindex.date;
  342.     next_messages_rec:= next_messages_rec + msgindex.num_of_recs;
  343.     next_message_number:= next_message_number + 1;
  344.     last_msgindex_rec:= msgindex.msgindex_rec_no;
  345.   end; {with}
  346. end; {update_indexrec}
  347.  
  348. {--- read/write routines ---}
  349.  
  350. procedure readindex;
  351.  
  352. procedure set_index_record;
  353. begin
  354.   with index do
  355.   begin
  356.     {date:   str8;}
  357.     next_messages_rec:= ndxbuffer[4] + ndxbuffer[5]*256;
  358.     next_message_number:= ndxbuffer[6] + ndxbuffer[7]*256;
  359.     last_msgindex_rec:= ndxbuffer[8] + ndxbuffer[9]*256;
  360.   end; {with}
  361.   close(ndxfil);
  362. end; {set_index_record}
  363.  
  364. begin;
  365.   blockread(ndxfil, ndxbuffer, 1);
  366.   set_index_record;
  367. end; {readindex}
  368.  
  369. procedure wrtmsg(msgline: msgtype; numb: integer);
  370. var
  371.   I: byte;
  372.   more: boolean;
  373.   msgbuffer: bufftype;
  374.   dummy: msgtype;
  375. begin
  376.   more:= {not} odd(numb);
  377.   numb:= trunc(numb / 2); {round}
  378.  
  379.   if more then
  380.   begin
  381.   seek(messagesfil, numb);
  382.   blockread(messagesfil, msgbuffer, 1);
  383.   for I:= 1 to 64 do
  384.     msgbuffer[I + 64]:= msgline[I];
  385.   end
  386.   else
  387.   begin
  388.     for I:= 1 to 64 do
  389.       msgbuffer[I]:= msgline[I];
  390.     for I:= 1 to 64 do
  391.       msgbuffer[I + 64]:= 1;
  392.   end;
  393.  
  394.   seek(messagesfil, numb);
  395.   blockwrite(messagesfil, msgbuffer, 1);
  396. end; {wrtmsg}
  397.  
  398. procedure writemsgindex;
  399. var
  400.   physicalrecord: integer;
  401.   mioffset: byte;
  402.   I, newoffset: byte;
  403.   buf: array[1..100] of byte;
  404.  
  405. procedure build_buffer;
  406. var
  407.   k, c: byte;
  408.   int, int1: integer;
  409. begin
  410.   with msgindex do
  411.   begin
  412.     for k:= 1 to 100 do
  413.       buf[k]:= 5;
  414.     receiver:= padstr0(receiver, 30);
  415.     for k:= 1 to 30 do
  416.       buf[k]:= ord(receiver[k]);
  417.     buf[31]:= lo(msg_no); buf[32]:= hi(msg_no);
  418.  
  419.     {date}
  420.     val(copy(date,1,2),int,int1);
  421.     if (int1 > 0) then int:= int1;
  422.     buf[33]:= int;
  423.     val(copy(date,4,2),int,int1);
  424.     if (int1 > 0) then int:= int1;
  425.     buf[34]:= int;
  426.     val(copy(date,7,2),int,int1);
  427.     if (int1 > 0) then int:= int1;
  428.     buf[35]:= int;
  429.     buf[36]:= num_of_recs;
  430.     buf[37]:= lo(start_rec_no); buf[38]:= hi(start_rec_no);
  431.     buf[39]:= lo(msgindex_rec_no); buf[40]:= hi(msgindex_rec_no);
  432.     subject:= padstr0(subject, 26);
  433.     for k:= 41 to 66 do
  434.       buf[k]:= ord(subject[k - 40]);
  435.     sender:=  padstr0(sender, 30);
  436.     for k:= 67 to 96 do
  437.        buf[k]:= ord(sender[k-66]);
  438.     buf[97]:= public;
  439.     buf[98]:= folder;
  440.     buf[99]:= deleted;
  441.     buf[100]:= null;
  442.   end; {with}
  443. end; {build_buffer}
  444.  
  445. begin
  446.   physicalrecord:= trunc((100/128) * mirecord);
  447.   mioffset:= round(frac((100/128) * mirecord) * 128) + 1;
  448.   writeln('writing  MSGINDEX.PBS');
  449.   build_buffer;
  450.  
  451.   if (mioffset> 1) then
  452.   begin
  453.     seek(msgndxfil, physicalrecord);
  454.     blockread(msgndxfil, msgindexbuffer, 1);
  455.   end;
  456.  
  457.   if (mioffset < 30) then
  458.   for I:= mioffset to 99 + mioffset do
  459.     msgindexbuffer[I]:= buf[I - mioffset + 1];
  460.   {** else **}
  461.   if (mioffset > 29) then
  462.   begin
  463.     for I:= mioffset to 128 do
  464.       msgindexbuffer[I]:= buf[I - mioffset + 1];
  465.   end;
  466.  
  467.   seek(msgndxfil, physicalrecord);
  468.   blockwrite(msgndxfil, msgindexbuffer, 1);
  469.  
  470.  { mioffset:= mioffset - 28;} {next physcial record}
  471.   if (mioffset > 29) then
  472.   begin
  473.     physicalrecord:= physicalrecord + 1;
  474.     for I:= 1 to (mioffset - 29) do
  475.       msgindexbuffer[I]:= buf[I + 129 - mioffset];
  476.     for I:= (mioffset - 28) to 128 do {fill extra space}
  477.       msgindexbuffer[I]:= 0;
  478.     seek(msgndxfil, physicalrecord);
  479.     blockwrite(msgndxfil, msgindexbuffer, 1);
  480.   end;
  481. end; {writemsgindex}
  482.