home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / sltpu70a.zip / SAMPLE2.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-11  |  3KB  |  100 lines

  1.  
  2. Program Sample2;
  3.  
  4.   { Sample program to save a message to a subboard }
  5.  
  6.  
  7. Uses General,Filedef,SubList,Message,Users,Post;
  8.  
  9. var msg: msgptr;
  10.     s,subboard,filename: string;
  11.     valid: boolean;
  12.     header: headertype;
  13.     inputfile: text;
  14.     p: SubListPtr;
  15.     result: longint;
  16.  
  17.  
  18. Begin
  19.  
  20.   { Open CONFIG, NODES and USER files }
  21.   { It is recommended to open the user file if saving messages }
  22.  
  23.   if OpenFiles([CONFIGF,NODESF]) and OpenUserFile then begin
  24.  
  25.     { Initialize subboard list }
  26.     SubListInit(Subboards);
  27.  
  28.     { Prompt user to enter a subboard name }
  29.     repeat
  30.       writeln('Enter Subboard Name: ');
  31.       readln(subboard);
  32.       upstr(subboard);          { make all uppercase }
  33.       stripspaces(subboard);    { strip spaces }
  34.  
  35.       p:=ListIndex(subboard);   { get list index, if valid subboard name }
  36.       if (p=Nil) or (p^.fname<>subboard) then begin
  37.         writeln('Invalid subboard. Try again.');
  38.         valid:=false;
  39.       end else valid:=true;
  40.  
  41.     until valid;
  42.  
  43.     if OpenSub(subboard,Mainsub,Allfiles) then begin     { Open subboard }
  44.  
  45.       { initialize message pointer }
  46.       new(msg);
  47.       clearmsg(msg);
  48.  
  49.       { input text file name and open text file }
  50.       writeln;
  51.       repeat
  52.         writeln('Enter Textfile Name: ');
  53.         readln(filename);
  54.         assign(inputfile,filename);
  55.         {$I-} reset(inputfile); {$I+}
  56.  
  57.         if IOResult=0 then valid:=true
  58.         else begin
  59.           writeln('Could not open file. Try again.');
  60.           valid:=false;
  61.         end;
  62.       until valid;
  63.  
  64.       { read text from file into memory }
  65.       while (not eof(inputfile)) and (msg^.msglen<=MaxLines) do begin
  66.         readln(inputfile,s);
  67.         if length(s)>MaxLinlen
  68.           then s:=copy(s,1,maxlinlen);    { truncate if necessary }
  69.         AddLine(msg,s);
  70.       end;
  71.       close(inputfile);
  72.  
  73.       { create a header }
  74.       fillchar(header,sizeof(header),0);
  75.       with header do begin
  76.         from:='GUEST';
  77.         touser:='SYSOP';
  78.         subj:='Text of file '+filename;
  79.         dosdate(date);
  80.         dostime(time);
  81.       end;
  82.  
  83.       { post the message }
  84.       result:=MsgPost(msg,header,0,true,true);
  85.  
  86.       { discard the text in memory }
  87.       DisposeMsg(msg);
  88.  
  89.       { close the subboard }
  90.       CloseSub(Mainsub);
  91.  
  92.     end
  93.     else writeln('Error opening subboard!');
  94.  
  95.     CloseUserFile;
  96.     CloseAllFiles;
  97.   end
  98.   else writeln('Could not open CONFIG File!');
  99.  
  100. end.