home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / microcrn / issue_33.arc / ROS-PCB.ARC / TROSKOV.INC < prev   
Text File  |  1986-10-23  |  15KB  |  483 lines

  1. { ROSKOV.INC - Remote Operating System Kernel Overlayed Routines }
  2.  
  3. { THIS FILE HAS BEEN ALTERED TO TRANSFER ROS DATA TO PCBOARD FORMAT.
  4.   Mesg_Header_List IS THE ALTERED PROCEDURE. }
  5.  
  6. overlay procedure list(ch: char);
  7. { List a portion of the system message file }
  8.   var
  9.     line_count: integer;
  10.     this: SysmPtr;
  11.   begin
  12.     this := SysmBase;
  13.     while (this <> nil) and (this^.key <> ch) do
  14.       this := this^.next;
  15.     if this^.key = ch
  16.       then
  17.         begin
  18.           writeln(USR);
  19.           seek(sysm_file, succ(this^.loc));
  20.           read(sysm_file, sysm_rec);
  21.           line_count := 0;
  22.           while (not brk) and (not EOF(sysm_file)) and (sysm_rec[1] <> ':') do
  23.             begin
  24.               writeln(USR, sysm_rec);
  25.               read(sysm_file, sysm_rec);
  26.               if user_rec.lines <> 99
  27.                 then
  28.                   begin
  29.                     line_count := succ(line_count);
  30.                     if line_count mod user_rec.lines = 0
  31.                       then pause
  32.                   end
  33.             end
  34.         end
  35.   end;
  36.  
  37. overlay function correct_fn(strn: FileName): FileName;
  38. { Correct possible errors in file name }
  39.   var
  40.     i, j: integer;
  41.   begin
  42.     i := 1;                                 { Remove blanks and invalid characters }
  43.     while i <= length(strn) do
  44.       if strn[i] in [' ', '*', ',', ':', ';', '=', '?', '_']
  45.         then delete(strn, i, 1)
  46.         else i := succ(i);
  47.     while (strn <> '') and (strn[1] = '.') do { Remove leading '.' }
  48.       delete(strn, 1, 1);
  49.     i := pos('.', strn);                     { Remove redundant '.' }
  50.     j := 1;
  51.     while j <= length(strn) do
  52.       if (strn[j] = '.') and (j > i)
  53.         then delete(strn, j, 1)
  54.         else j := succ(j);
  55.     i := pos('.', strn);
  56.     if i = 0                                { Ensure name has '.' }
  57.       then
  58.         begin
  59.           strn := copy(strn, 1, 8);           { Ensure file name <= 8 characters }
  60.           if length(strn) > 0
  61.             then strn := strn + '.'
  62.         end
  63.       else strn := copy(strn, 1, min(8, pred(i))) + '.' +
  64.                   copy(strn, succ(i), min(3, length(strn) - i));
  65.     correct_fn := strn
  66.   end;
  67.  
  68. overlay function compress_fn(name: FileName): FileName;
  69. { Strip hi bits and remove all blanks from file name }
  70.   var
  71.     i: integer;
  72.   begin
  73.     for i := 1 to length(name) do
  74.       name[i] := chr($7F and ord(name[i]));
  75.     i := pos(' ', name);
  76.     while i > 0 do
  77.       begin
  78.         delete(name, i, 1);
  79.         i := pos(' ', name)
  80.       end;
  81.     compress_fn := name
  82.   end;
  83.  
  84. overlay procedure get_name(var fn: firstname; var ln: lastname);
  85. { Get user name }
  86.   begin
  87.     writeln(USR);
  88.     repeat
  89.       fn := trim(prompt('FIRST name', len_fn, 'ES'))
  90.     until (not online) or (fn <> '');
  91.     if fn = 'SYSOP'
  92.       then ln := ''
  93.       else
  94.         repeat
  95.           ln := trim(prompt(' LAST name', len_ln, 'ES'))
  96.         until (not online) or (ln <> '')
  97.   end;
  98.  
  99. overlay procedure get_old_password(pr: StrPr; var valid: boolean);
  100. { Accept and validate old password.  Only 'Max_Tries' will be allowed. }
  101.   var
  102.     tries: integer;
  103.   begin
  104.     tries := 1;
  105.     repeat
  106.       valid := (user_rec.pw = prompt(pr, len_pw, 'S'));
  107.       tries := succ(tries)
  108.     until (not online) or valid or (tries > Max_Tries);
  109.     if not valid
  110.       then writeln(USR, 'Only ', Max_Tries, ' tries allowed.')
  111.   end;
  112.  
  113. overlay procedure get_new_password;
  114. { Accept and validate new password. }
  115.   var
  116.     i: integer;
  117.     trial_pw: password;
  118.   begin
  119.     writeln(USR);
  120.     writeln(USR, 'Please select and enter a password of 4-', len_pw, ' characters');
  121.     writeln(USR, 'to ensure that no one else uses your name on the system.');
  122.     writeln(USR);
  123.     repeat
  124.       repeat
  125.         trial_pw := prompt('Password (will NOT display as you type)', len_pw, 'S');
  126.         i := length(trial_pw);
  127.         if (i < 4) or (i > len_pw)
  128.           then writeln(USR, 'Length must be 4-', len_pw, ' characters.');
  129.       until (not online) or ((4 <= i) and (i <= len_pw));
  130.       user_rec.pw := prompt(' Please enter it again for verification', len_pw, 'S');
  131.       if user_rec.pw <> trial_pw
  132.         then writeln(USR, 'No match.  Try again.')
  133.     until (not online) or (user_rec.pw = trial_pw);
  134.     writeln(USR);
  135.     writeln(USR, 'Please remember your password.');
  136.     writeln(USR, 'It will be required for all future calls.')
  137.   end;
  138.  
  139. overlay procedure get_case;
  140. { Get case switch from user }
  141.   begin
  142.     user_rec.shift_lock := not ask('Can your terminal display lower case')
  143.   end;
  144.  
  145. overlay procedure get_nulls;
  146. { Get nulls from user }
  147.   begin
  148.     user_rec.nulls := strint(prompt('How many nulls do you need [0-9]?', 1, 'AES'))
  149.   end;
  150.  
  151. overlay function mesg_start(pr: StrPr): integer;
  152. { Get starting message number from user }
  153.   var
  154.     i, lo, hi: integer;
  155.   begin
  156.     if MesgBase = nil
  157.       then
  158.         begin
  159.           lo := 0;
  160.           hi := 0
  161.         end
  162.       else
  163.         begin
  164.           lo := MesgBase^.MesgNo;
  165.           hi := MesgLast^.MesgNo
  166.         end;
  167.     i := strint(prompt(pr + ' [' + intstr(lo, 1) + '-' + intstr(hi, 1) + ']?', 5, 'E'));
  168.     if (i < 1) or (i > hi)
  169.       then
  170.         begin
  171.           i := succ(user_rec.lasthi);
  172.           writeln(USR, 'Starting after last high message (# ', user_rec.lasthi, ')...')
  173.         end;
  174.     mesg_start := i
  175.   end;
  176.  
  177. overlay procedure mesg_header_list(loc: integer; var first_line, last_line: integer);
  178. { send message header info to PCBoard's MSGS }
  179.   const
  180.     minus : char = '-';
  181.     blank : char = ' ';
  182.   var
  183.     J: Integer;
  184.     to_fn, fr_fn: firstname;
  185.     to_ln, fr_ln: lastname;
  186.     strn: StrTAD;
  187.     temp_user_rec: user_list;
  188.     num_str: String [6];
  189.   begin
  190.     seek(summ_file, loc);
  191.     read(summ_file, summ_rec);
  192.     with summ_rec do
  193.       begin
  194.         if user_to = 0
  195.           then
  196.             begin
  197.               to_fn := 'ALL';
  198.               to_ln := ''
  199.             end
  200.         else if user_to = user_loc
  201.           then
  202.             begin
  203.               to_fn := user_rec.fn;
  204.               to_ln := user_rec.ln
  205.             end
  206.           else
  207.             begin
  208.               GetRec(DatF, user_to, temp_user_rec);
  209.               to_fn := temp_user_rec.fn;
  210.               to_ln := temp_user_rec.ln
  211.             end;
  212.         if user_from = user_loc
  213.           then
  214.             begin
  215.               fr_fn := user_rec.fn;
  216.               fr_ln := user_rec.ln
  217.             end
  218.           else
  219.             begin
  220.               GetRec(DatF, user_from, temp_user_rec);
  221.               fr_fn := temp_user_rec.fn;
  222.               fr_ln := temp_user_rec.ln
  223.             end;
  224.         strn := FormTAD(date);
  225.         write(num);
  226.         case status of
  227.           deleted: writeln( Chr(7), Chr(7), 'Deleted message found ...');
  228.           read:    begin write(OutF, minus); writeln ('  read'); end;
  229.           private: begin write(OutF, blank); writeln ('  private'); end;
  230.           public:  begin write(OutF, blank); writeln ('  public'); end;
  231.         end;
  232.         Str (num, num_str);
  233.         ConvertStr (num_str, 7);
  234.         Write (OutF, Copy (strn, 6, 8));
  235.         Write (OutF, Copy (strn, 1, 5));
  236.         ConvertStr (to_fn + ' ' + to_ln, 25);
  237.         ConvertStr (fr_fn + ' ' + fr_ln, 25);
  238.         ConvertStr (subject, 25);
  239.         for J := 1 to 20 do
  240.           Write (OutF, blank);
  241.  
  242.         first_line := st_rec;
  243.         last_line := size
  244.       end
  245.   end;
  246.  
  247. overlay procedure mesg_delete;
  248. { Delete the current message }
  249.   var
  250.     this: MesgPtr;
  251.   begin
  252.     summ_rec.status := deleted;
  253.     seek(summ_file, pred(FilePos(summ_file)));
  254.     write(summ_file, summ_rec);
  255.     this := MesgCurr;
  256.     if MesgCurr = MesgBase
  257.       then
  258.         begin
  259.           MesgCurr := MesgBase^.next;
  260.           MesgBase := MesgBase^.next;
  261.           dispose(this)
  262.         end
  263.     else if MesgCurr <> nil
  264.       then
  265.         begin
  266.           MesgCurr := MesgBase;             { Find previous record }
  267.           while MesgCurr^.next <> this do
  268.             MesgCurr := MesgCurr^.next;
  269.           MesgCurr^.next := this^.next;     { Make it point to next record }
  270.           if MesgLast = this
  271.             then MesgLast := MesgCurr;
  272.           MesgCurr := MesgCurr^.next;
  273.           dispose(this)
  274.         end;
  275.     writeln(USR, 'Message #', summ_rec.num, ' deleted.')
  276.   end;
  277.  
  278. overlay procedure mesg_build_index(mesg_area: byte);
  279. { Scan summary file and build message index list.  Public messages are tied
  280.   to the current message area.  Private and authored messages are independent
  281.   of area.  All messages are accessible in mesg_area #0 (SYSTEM). }
  282.   var
  283.     this: MesgPtr;
  284.   begin
  285.     while MesgBase <> nil do                { Delete old messages }
  286.       begin
  287.         this := MesgBase;
  288.         MesgBase := MesgBase^.next;         { Go to next on list }
  289.         dispose(this)                       { Reclaim space }
  290.       end;
  291.     msg_all := 0;
  292.     msg_ind := 0;
  293.     msg_aut := 0;
  294.     msg_sys := 0;
  295.     seek(summ_file, 1);
  296.     while not EOF(summ_file) do
  297.       with summ_rec do
  298.         begin
  299.           read(summ_file, summ_rec);
  300.           if (status = public) and (area = mesg_area)
  301.             then
  302.               begin                         { Public message }
  303.                 msg_all := succ(msg_all);
  304.                 mesg_insert(0)
  305.               end
  306.           else if (status <> deleted) and (user_loc = user_to)
  307.             then
  308.               begin                         { Private message }
  309.                 msg_ind := succ(msg_ind);
  310.                 mesg_insert(1)
  311.               end
  312.           else if (status <> deleted) and (user_loc = user_from)
  313.             then
  314.               begin                         { Author of message }
  315.                 msg_aut := succ(msg_aut);
  316.                 mesg_insert(2)
  317.               end
  318.           else if mesg_area = 0
  319.             then
  320.               begin                         { Sysop can view all messages }
  321.                 msg_sys := succ(msg_sys);
  322.                 mesg_insert(3)
  323.               end
  324.         end;
  325.     summ_rec.user_from := 0
  326.   end;
  327.  
  328. overlay procedure mesg_directory;
  329. { Display directory of messages }
  330.   const
  331.     col_width = 6;
  332.   var
  333.     hi, col_count, col_limit: integer;
  334.   begin
  335.     col_limit := max(1, user_rec.columns div col_width);
  336.     if MesgBase = nil
  337.       then hi := 0
  338.       else hi := MesgLast^.MesgNo;
  339.     writeln(USR, 'High message now  : ', hi);
  340.     writeln(USR, 'Public messages   : ', msg_all);
  341.     writeln(USR);
  342.     if msg_ind = 0
  343.       then writeln(USR, user_rec.fn, ', no messages for you at this time.')
  344.       else
  345.         begin
  346.           writeln(USR, user_rec.fn, ', the following messages are addressed to you:');
  347.           col_count := 0;
  348.           MesgCurr := MesgBase;
  349.           while (not brk) and (MesgCurr <> nil) do
  350.             begin
  351.               if MesgCurr^.TypMsg = 1
  352.                 then
  353.                   begin
  354.                     write(USR, MesgCurr^.MesgNo:col_width);
  355.                     col_count := succ(col_count);
  356.                     if (0 = col_count mod col_limit)
  357.                       then writeln(USR)
  358.                   end;
  359.               MesgCurr := MesgCurr^.next
  360.             end;
  361.           writeln(USR)
  362.         end;
  363.     if msg_aut > 0
  364.       then
  365.         begin
  366.           writeln(USR, user_rec.fn, ', the following messages were sent by you:');
  367.           col_count := 0;
  368.           MesgCurr := MesgBase;
  369.           while (not brk) and (MesgCurr <> nil) do
  370.             begin
  371.               if MesgCurr^.TypMsg = 2
  372.                 then
  373.                   begin
  374.                     write(USR, MesgCurr^.MesgNo:col_width);
  375.                     col_count := succ(col_count);
  376.                     if (0 = col_count mod col_limit)
  377.                       then writeln(USR)
  378.                   end;
  379.               MesgCurr := MesgCurr^.next
  380.             end;
  381.           writeln(USR)
  382.         end
  383.   end;
  384.  
  385. overlay procedure ReadDir(var entries, space_used: integer; var first: FilePtr);
  386. { Create an alphabetized list of files in the current file area }
  387.   var
  388.     i, j, off: integer;
  389.     this: FilePtr;
  390.     searchblk: FileBlock;                 { Buffer to define search params }
  391.     answerblk: array[0..3] of FileBlock;  { Buffer to receive file names }
  392.   begin
  393.     new_dir := TRUE;
  394.     space_used := 0;
  395.     while first <> nil do                 { Clean out any old directory list }
  396.       begin
  397.         this := first;
  398.         first := first^.Next;             { Go to next on chain }
  399.         dispose(this)                     { Reclaim space }
  400.       end;
  401.     DirEntries := 0;
  402.     with searchblk do
  403.       begin
  404.         drive := 0;
  405.         for i := 1 to 11 do
  406.           fname[i] := ord('?');
  407.         extent := ord('?');
  408.         s1     := ord('?');
  409.         s2     := ord('?');
  410.         reccount := 0;
  411.         for i := 16 to 31 do
  412.           map[i] := 0
  413.       end;
  414.     SetSect(SetDrv, SetUsr);
  415.     BDOS(setdma, addr(answerblk));
  416.     off := BDOS(findfirst, addr(searchblk));
  417.     while off <> 255 do
  418.       begin
  419.         with answerblk[off] do
  420.           { Non-system or sysop and not creating system directory? }
  421.           if (($80 and ord(fname[10])) = 0) or
  422.              ((user_rec.access >= 250) and (mode <> sysop_mode))
  423.             then InsertFile(fname, 0, reccount + (extent + (s2 shl 5)) shl 7,
  424.                             entries, space_used, first);
  425.         off := BDOS(findnext, addr(searchblk))
  426.       end;
  427.     BDOS(setdma, fcb);                    { Restore DMA buffer }
  428.     if user_rec.access >= 250
  429.       then free_space := diskfree;
  430.     SetSect(HomDrv, HomUsr)
  431.   end;
  432.  
  433. overlay procedure LibReadDir(var entries, space_used: integer; var first: FilePtr);
  434. { Read library directory }
  435.   var
  436.     i, off: integer;
  437.     LibBlock: array[0..3] of EntryBlock;
  438.   begin
  439.     SetSect(SetDrv, SetUsr);
  440.     Assign(libr_file, LibReq);
  441.     {$I-} Reset(libr_file) {$I+};
  442.     if IOresult = 0
  443.       then
  444.         begin
  445.           {$I-} blockread(libr_file, LibBlock, 1) {$I+};
  446.           in_library := (IOresult = 0);
  447.           i := 1;
  448.           while in_library and (i < 11) do
  449.             if LibBlock[0].fname[i] = $20
  450.               then i := succ(i)
  451.               else in_library := FALSE;
  452.           in_library := in_library and (LibBlock[0].status = 0);
  453.           if in_library
  454.             then
  455.               begin
  456.                 new_dir := TRUE;
  457.                 space_used := 0;
  458.                 LibEntries := 0;
  459.                 for i := 1 to pred(LibBlock[0].fsize shl 2) do
  460.                   begin
  461.                     off := i mod 4;
  462.                     if off = 0
  463.                       then blockread(libr_file, LibBlock, 1);
  464.                     with LibBlock[off] do
  465.                       if status < $FE
  466.                         then InsertFile(fname, index, fsize, entries, space_used, first)
  467.                   end
  468.               end
  469.         end;
  470.     SetSect(HomDrv, HomUsr)
  471.   end;
  472.  
  473. overlay function greg_to_jul(day, mon, yr: integer): real;
  474. { Convert from Gregorian date to Julian }
  475.   var
  476.     i: integer;
  477.   begin
  478.     i := (mon - 14) div 12;
  479.     greg_to_jul := day - 32075 + 367 * (mon - 2 - 12 * i) div 12 -
  480.                    3 * (yr + 6800 + i) div 400 + 365.25 * (yr + 6700 + i)
  481.   end;
  482.  
  483.