home *** CD-ROM | disk | FTP | other *** search
- PROGRAM what;
-
- (* Compiles a list of functions and procedures in a file *)
- (* that is generated from your TURBO PASCAL programs. *)
- (* Useful to help remember what procedures and functions *)
- (* You have in a particular file. Would be nice to have *)
- (* it automatically include TURBO PASCALS include files *)
- (* will get to that one of these days. *)
- (* Puts in the appropriate characters so the list can *)
- (* be used as comments in your main program. *)
- (* Released to Public Domain for any use whatsoever. *)
- (* William L. Mabee, CRNA *)
-
- LABEL start,escape;
-
- TYPE
- charset = SET OF CHAR;
- fieldtype = (alpha,dollar,numeric,yesno);
- anystr = STRING[128];
- str80 = STRING[80];
- str2 = STRING[2];
- str14 = STRING[14];
- STR = STRING[128];
- name = STRING[14];
- prtype = (cpi10,cpi12,cpi17,wide,RESET,correspond,dp,
- enhanced,emphacized,normal,form,superon,
- superoff,subon,suboff,underon,underoff);
-
-
- CONST
-
- dash = '(*--------------------------------------------------------------------------*)';
- open ='(* *)';
- okidata = TRUE;
- cr = ^m; { Keyboard constants }
- lf = ^j;
- crlf = ^m^j;
- bell = ^g;
- bs = ^h;
- esc = ^[;
- null = ''; { Concatenation constants }
- space = ' ';
- digits:charset = ['.', '-', '0'..'9', 'e', 'E'];
- alphaset:charset = [' '..'}']; { Printable characters }
-
-
- VAR
- prompt : STRING[80];
- ch : CHAR;
- julian,year,month,day : INTEGER;
- dummy : STRING[1];
- outfilename,filename : STRING[14];
- filvar,word : TEXT;
- i : BYTE;
- stuff,data : STRING[128];
- result,page,count : INTEGER;
-
- PROCEDURE printer(which: prtype);
-
- {------------------------------------------------------------------}
- { }
- { this procedure allows for easy control of the major functions of }
- { the Okidata 92 printer. It is written in Turbo Pascal and should }
- { be included in your source program. The following type }
- { declaration must appear in your main program: }
- { }
- { type }
- { }
- { prtype = (Cpi10,Cpi12,Cpi17,Wide,Reset,Correspond,DP, }
- { Enhanced,Emphacized,Normal,Form,SuperOn, }
- { SuperOff,SubOn,SubOff,UnderOn,UnderOff); }
- { Const OKIDATA = TRUE; }
- { }
- {------------------------------------------------------------------}
-
- VAR
- c: STRING[2];
-
- BEGIN
- CASE which OF
- cpi10 : c:= CHR(30); { 10 char/inch 80/line }
- cpi12 : c:= CHR(28); { 12 char/inch 96/line }
- cpi17 : c:= CHR(29); { 17.1 char/inch 132/line}
- wide : c:= CHR(31); { double wide characters }
- RESET : c:= CHR(24); { reset to poweron values}
- correspond : c:= CHR(27)+CHR(49); { correspondence quality }
- dp : c:= CHR(27)+CHR(48); { data processing qual. }
- enhanced : c:= CHR(27)+CHR(72); { enhanced printing }
- emphacized : c:= CHR(27)+CHR(84); { emphacized printing }
- normal : c:= CHR(27)+CHR(73); { no enhanced/emphacized }
- form : c:= CHR(12); { form feed }
- superon : c:= CHR(27)+CHR(74); { superscripting on }
- superoff : c:= CHR(27)+CHR(75); { superscripting off }
- subon : c:= CHR(27)+CHR(76); { subscripting on }
- suboff : c:= CHR(27)+CHR(77); { subscripting off }
- underon : c:= CHR(27)+CHR(67); { underlining on }
- underoff : c:= CHR(27)+CHR(68); { underlining off }
- END; { case }
- IF ((okidata) OR (which = form)) THEN
- WRITE(LST,c); { write command to printer}
- END;
-
- PROCEDURE CLEARFRAME;
- VAR
- i : INTEGER;
- BEGIN
- FOR i := 20 DOWNTO 3 DO
- BEGIN
- GOTOXY(1,i + 1); CLREOL ;
- END;
- END;
-
- PROCEDURE upper_case(VAR strg : STR);
- {A+}
- BEGIN
- INLINE ($2a/strg/$46/$04/$05/$ca/*+20/$23/$7e/$fe/$61/$da/*-9/
- $fe/$7b/$d2/*-14/$d6/$20/$77/$c3/*-20);
- {A-}
- END;
-
- PROCEDURE select( prompt : str80;
- term : charset;
- VAR tc : CHAR );
- VAR
- ch : CHAR;
- BEGIN
- GOTOXY(1,23); WRITE(prompt); CLREOL;
- REPEAT
- READ(KBD,ch);
- tc := UPCASE(ch);
- IF NOT (tc IN term) THEN
- WRITE(^g);
- UNTIL tc IN term;
- WRITE(ch);
- END;
-
- PROCEDURE help;
- BEGIN
- GOTOXY(1,8);
- WRITELN('Selecting ''1'' will process a Turbo Pascal program you have written.');
- WRITELN('It will write the procedures and functions contained in that program');
- WRITELN('to a file.');
- WRITELN('Selecting ''2'' will allow you to list a file to the printer.');
- WRITELN('Selecting ''3'' displays this file.');
- WRITELN('Selecting ''4'' exits this program.');
- select('Press <RETURN> to continue. ',[^m],ch);
- CLEARFRAME;
- END;
-
- PROCEDURE getln(VAR s:str80; okset:charset; maxlen:INTEGER);
- VAR ch: CHAR;
- stemp: str80;
- len: INTEGER;
- first,
- last: BOOLEAN;
- getset:charset;
-
- FUNCTION getchar(okset:charset):CHAR;
- VAR OK:BOOLEAN; ch:CHAR;
- BEGIN
- REPEAT
- READ(KBD,ch);
- IF EOLN(KBD) THEN ch:=cr;
- OK:=ch IN okset;
- IF NOT OK
- THEN WRITE(CON,bell)
- ELSE IF ch IN alphaset THEN WRITE(CON,ch)
- UNTIL OK;
- getchar:=ch
- END; {getchar}
-
- BEGIN
- stemp:=null;
- ch:=space;
- REPEAT
- len:=LENGTH(stemp);
- first:=len=0;
- last:=len=maxlen;
- IF first THEN getset:=okset+[cr]
- ELSE IF last THEN getset:=[cr,bs]
- ELSE getset:=okset+[cr,bs];
- ch:=getchar(getset);
- IF ch=bs THEN
- BEGIN
- WRITE(bs,space,bs);
- DELETE(stemp,len,1)
- END
- ELSE IF ch IN okset-[cr] THEN stemp:=stemp+ch
- UNTIL ch=cr;
- s:=stemp
- END; {getln}
-
- FUNCTION ival(VAR s:str80):INTEGER;
- VAR go: BOOLEAN; n:INTEGER;
- BEGIN
- n:=0; go:=TRUE;
- WHILE (s<>null) AND go DO
- BEGIN
- IF s[1] IN ['0'..'9'] THEN
- n:=( n*10 + ORD(s[1])-ORD('0') ) MOD 3000
- ELSE go:=FALSE;
- DELETE(s,1,1)
- END;
- ival:=n
- END; {ival}
-
- PROCEDURE dtoj(day,month,year: INTEGER;VAR julian: INTEGER);
- { Convert from a date to a Julian number -- January 1, 1900 = -32767 }
- { Note that much care is taken to avoid problems with inaccurate bit representations inherent in the binary fractions
- of the real numbers used as temporary variables. Thus the seemingly unnecessary use of small fractional offsets
- and int() functions }
- BEGIN
- IF (year=1900) AND (month<3) { Handle the first two months as a special case since the general }
- THEN { algorithm used doesn't start until March 1, 1900 }
- IF month=1
- THEN
- julian := day-$8000 { Compiler won't accept -32768 as a valid integer, so use the hex form }
- ELSE
- julian := day-32737
- ELSE
- BEGIN
- IF month>2
- THEN
- month := month-3
- ELSE
- BEGIN
- month := month+9;
- year := year-1
- END;
- year := year-1900;
- julian := ROUND(-32709.0+day+INT(0.125+INT(1461.0*year+0.5)/4.0))+((153*month+2) DIV 5)
- END
- END;
-
- PROCEDURE jtod(julian: INTEGER;VAR day,month,year: INTEGER);
- { Convert from a Julian date to a calendar date }
- { Note that much care is taken to avoid problems with inaccurate bit representations inherent in the binary fractions
- of the real numbers used as temporary variables. Thus the seemingly unnecessary use of small fractional offsets
- and int() functions }
- VAR temp: REAL;
- BEGIN
- temp := INT(32767.5+julian); { Convert 16 bit quantity into a real number }
- IF temp<58.5
- THEN
- BEGIN { The first two months of the twentieth century are handled as a special }
- year := 1900; { case of the general algorithm used which handles all of the rest }
- IF temp<30.5
- THEN
- BEGIN
- month := 1;
- day := ROUND(temp+1.0)
- END
- ELSE
- BEGIN
- month := 2;
- day := ROUND(temp-30.0)
- END
- END
- ELSE
- BEGIN
- temp := INT(4.0*(temp-59.0)+3.5);
- year := TRUNC(temp/1461.0+0.00034223); { 0.00034223 is about one half of the reciprocal of 1461.0 }
- day := SUCC(ROUND(temp-year*1461.0) DIV 4);
- month := (5*day-3) DIV 153;
- day := SUCC((5*day-3) MOD 153 DIV 5);
- year := year+1900;
- IF month<10
- THEN
- month := month+3
- ELSE
- BEGIN
- month := month-9;
- year := SUCC(year)
- END
- END
- END;
-
- FUNCTION dayofweek(julian: INTEGER): INTEGER;
- { Return an integer representing the day of week for the date }
- { Sunday = 0, etc. }
- VAR temp: REAL;
- BEGIN
- temp := julian+32767.0; { Convert into a real temporary variable }
- dayofweek := ROUND(FRAC((temp+1.0)/7.0)*7.0) { Essentially this is a real number version of Julian mod 7 with }
- END; { an offset to make Sunday = 0 }
-
- PROCEDURE writedate(julian: INTEGER);
- { Write the date out to the console in long form , e.g. "Monday, September 10, 1984" }
- CONST days: ARRAY[0..6] OF STRING[9]=('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
- months: ARRAY[1..12] OF STRING[9] = ('January','February','March','April','May','June',
- 'July','August','September','October','November','December');
- VAR day,month,year: INTEGER;
- BEGIN
- jtod(julian,day,month,year); { Convert into date form }
- WRITELN(days[dayofweek(julian)],' ',months[month],' ',day,', ',year);
- END;
-
- PROCEDURE writedateprinter(julian: INTEGER);
- { Write the date out to the printer in long form , e.g. "Monday, September 10, 1984" }
- CONST days: ARRAY[0..6] OF STRING[9]=('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
- months: ARRAY[1..12] OF STRING[9] = ('January','February','March','April','May','June',
- 'July','August','September','October','November','December');
- VAR day,month,year: INTEGER;
- BEGIN
- jtod(julian,day,month,year); { Convert into date form }
- WRITELN(LST,days[dayofweek(julian)],' ',months[month],' ',day,', ',year);
- END;
-
- FUNCTION tab(spaces : INTEGER) : str80;
- VAR
- column : INTEGER;
- temp : str80;
- BEGIN
- temp :='';
- FOR column := 1 TO spaces DO
- BEGIN
- temp := temp + ' ';
- tab := temp;
- END;
- END;
-
- FUNCTION file_exists(fname : name) : BOOLEAN;
- VAR
- ffile : FILE;
- BEGIN
- ASSIGN(ffile,fname);
- {$I-}
- RESET(ffile);
- {$I+}
- file_exists := (IORESULT = 0)
- END;
-
- PROCEDURE blast; (* CLEARSCREEN *)
- BEGIN
- {A+}
- INLINE ($0e/$02/$1e/$1a/$c3/$05/$00/$00);
- {A-}
- END;
-
- PROCEDURE put_up_message;
-
- BEGIN
- GOTOXY(1,4); WRITELN('Procedure & Function Lister By : William L. Mabee, CRNA');
- WRITELN('This program will create a file containing a list of procedures');
- WRITELN('and functions from TURBO PASCAL programs you have written. Your');
- WRITELN('first prompt will be for the name of the file you want these');
- WRITELN('procedures and functions written to.');
- WRITELN('Your second prompt will be for the name of the program you');
- WRITELN('have written and wish to obtain a list of procedures and');
- WRITELN('functions.');
- WRITELN('You may continue to read in programs you wish to obtain a');
- WRITELN('listing of functions and procedures from until you enter');
- WRITELN('a carriage return when prompted for the name of the file to');
- WRITELN('process.');
- select('Press <RETURN> to continue. ',[^m],ch);
- CLEARFRAME;
- END;
-
- PROCEDURE getoutfilename(VAR outfilename : str14);
- LABEL done;
- BEGIN
- REPEAT
- GOTOXY(1,10); WRITE('Enter a carriage return to exit this procedure.');
- GOTOXY(1,12); WRITE('This file will contain a list of the procedures and functions.');
- GOTOXY(1,14); WRITE('Enter Name of file to Create : '); READ(outfilename);
- IF outfilename = '' THEN GOTO done;
- IF file_exists(outfilename) = TRUE THEN
- BEGIN
- WRITE(^g);
- GOTOXY(1,18); WRITE('File Exists');
- DELAY(2000); GOTOXY(1,18); CLREOL;
- GOTOXY(32,14); CLREOL;
- END;
- UNTIL file_exists(outfilename) = FALSE;
- ASSIGN(word,outfilename);
- REWRITE(word);
- done :
- CLEARFRAME;
- END;
-
- PROCEDURE getfilename(VAR filename : str14);
- LABEL done;
- BEGIN
- count := 1;
- REPEAT
- CLEARFRAME;
- GOTOXY(1,10); WRITE('Enter a carriage return to exit this procedure.');
- GOTOXY(1,12); WRITE('Enter Name of File to Process : ');
- REPEAT
- READ(filename);
- IF filename = '' THEN GOTO done;
- IF file_exists(filename)= FALSE THEN
- BEGIN
- GOTOXY(33,12);
- CLREOL;
- WRITE(^g);
- END;
- UNTIL file_exists(filename) = TRUE;
- ASSIGN(filvar,filename);
- RESET(filvar);
- IF count = 1 THEN WRITELN(word,dash);
- BEGIN
- WRITELN(word,'(* The file ',filename,' contains the following : ',tab(38-LENGTH(filename)),'*)');
- CLEARFRAME;
- GOTOXY(1,10); WRITE('Reading from file : ',filename);
- GOTOXY(1,12); WRITE('Writing to file : ',outfilename);
- WRITELN(word,open);
- WHILE NOT EOF(filvar) DO
- BEGIN
- READLN(filvar,data);
- upper_case(data);
- IF (COPY(data,1,9) = 'PROCEDURE') OR (COPY(data,1,8) = 'FUNCTION') OR
- (COPY(data,1,7) = 'OVERLAY') OR (COPY(data,1,7) = 'PROGRAM') OR
- (COPY(data,1,8) = 'EXTERNAL') THEN
- WRITELN(word,'(* ',data,tab(72-LENGTH(data)),' *)');
- END;
- WRITELN(word,open);
- WRITELN(word,dash);
- count := count + 1;
- IF NOT EOF(filvar) THEN WRITELN(word,open);
- END;
- UNTIL filename = '';
- done :
- CLOSE(word);
- CLEARFRAME;
- IF count > 1 THEN CLOSE(filvar);
- IF count < 2 THEN ERASE(word);
- END;
-
- PROCEDURE print_it_out;
-
- LABEL done;
- BEGIN
- CLEARFRAME;
- page := 1;
- count := 1;
- REPEAT
- GOTOXY(1,12); WRITE('What is the name of the file you wish to print ');
- READ(filename);
- IF filename = '' THEN GOTO done;
- UNTIL file_exists(filename) = TRUE;
- BEGIN
- REPEAT
- CLEARFRAME;
- GOTOXY(1,6); WRITE('Enter numeric values for the date prompts.');
- GOTOXY(1,8); WRITE('Day : '); getln(prompt,digits,2);
- VAL(prompt,day,result);
- GOTOXY(1,10); WRITE('Month : '); getln(prompt,digits,2);
- VAL(prompt,month,result);
- GOTOXY(1,12); WRITE('Year : 19'); getln(prompt,digits,2);
- VAL(prompt,year,result);
- year := year + 1900;
- dtoj(day,month,year,julian);
- GOTOXY(1,14);
- writedate(julian);
- select('Is this the current date (Y/N) ',['Y','N'],ch);
- UNTIL ch = 'Y';
- ASSIGN(filvar,filename);
- RESET(filvar);
- printer(cpi17);
- WHILE NOT EOF(filvar) DO
- BEGIN
- IF count = 1 THEN
- BEGIN
- WRITELN(LST,'');
- WRITE(LST,'Listing of file ',outfilename,' Page # ',page,' ');
- writedateprinter(julian);
- WRITELN(LST,'');
- END;
- READLN(filvar,data);
- WRITELN(LST,data);
- count := count + 1;
- IF count = 50 THEN
- BEGIN
- page := page + 1;
- count := 1;
- printer(form);
- END;
- END;
- IF count <> 1 THEN printer(form);
- END;
- done :
- CLOSE(filvar);
- printer(RESET);
- CLEARFRAME;
- END;
-
- BEGIN (* Main *)
- blast;
- GOTOXY(18,1); WRITE('TURBO PASCAL UTILITY : W. MABEE Ver 2.0');
- put_up_message;
- outfilename := '';
- count := 1;
- REPEAT
- start :
- select('1.) Process New File, 2.) Print existing file, 3.) Help, 4.) Quit ',['1','2','3','4'],ch);
- CASE ch OF
- '1' : BEGIN
- getoutfilename(outfilename);
- IF outfilename = '' THEN GOTO start;
- getfilename(filename);
- END;
- '2' : print_it_out;
- '3' : help;
- '4' : GOTO escape;
- END; (* Case *)
- UNTIL ch = '3';
- escape :
- CLOSE(word);
- CLOSE(filvar);
- blast;
- END.