home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-04 | 86.5 KB | 2,235 lines |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Welcome to
- A D A - T U T R
- The Interactive Ada Tutor
- by John J. Herro, Ph.D.
- Software Innovations Technology
-
- These are the printed course notes.
-
- Ver. 2.02, 4 Sep. 1992
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Copyright 1988-1992 John J. Herro
-
- Software Innovations Technology
- 1083 Mandarin Dr. NE, Palm Bay, FL 32905-4706
- (407)951-0233
-
-
- You may make copies of these notes,
- in printed or machine-readable form.
-
- You may also copy the computer program.
- Please see page 1 for details.
-
-
- Page i
-
- TABLE OF CONTENTS
-
-
- Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
- Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . ii
- Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
- Registration and Licenses - What is Shareware? . . . . . . . . . . 2
- Special Offer to Companies, Schools, Etc. . . . . . . . . . . . . 3
- Note to Compiler Companies . . . . . . . . . . . . . . . . . . . . 5
- Does Your Screen Show Strange Characters Like Arrows and Brackets? 6
- The Ada Reserved Words . . . . . . . . . . . . . . . . . . . . . . 7
- Steps for Outside Assignment 1, Preparing to Run Ada . . . . . . . 8
- Listings of HELLO.ADA and ADD.ADA . . . . . . . . . . . . . . . . 9
- Listing of TRITEST.ADA . . . . . . . . . . . . . . . . . . . . . . 10
- Steps for Outside Assignment 2, Exercise in Enumeration Types . . 12
- Listing of NEXTDATE.ADA . . . . . . . . . . . . . . . . . . . . . 13
- Steps for Outside Assignment 3, Exercise in Records . . . . . . . 14
- Listing of FIBTEST.ADA . . . . . . . . . . . . . . . . . . . . . . 15
- Steps for Outside Assignment 4, Exercise in Recursion . . . . . . 16
- Simplified Specification for TEXT_IO . . . . . . . . . . . . . . . 17
- Listings of Procedure FILECOPY and Function EXISTS . . . . . . . . 19
- Requirements for the Program LEDIT . . . . . . . . . . . . . . . . 20
- Steps for Outside Assignment 5, Writing a Simple Line Editor . . . 25
- How to Test LEDIT . . . . . . . . . . . . . . . . . . . . . . . . 26
- Listing of LEDIT.ANS . . . . . . . . . . . . . . . . . . . . . . . 29
- Listing of TASKING.DUM . . . . . . . . . . . . . . . . . . . . . . 33
- Steps for Outside Assignment 6, Exercise in Tasking . . . . . . . 34
- Output from TASKING.EXE After Modification of TASKING.ADA . . . . 35
- Listing of TASKING.ANS . . . . . . . . . . . . . . . . . . . . . . 36
-
- Appendix A: Would You Like a Textbook to Use Along with ADA-TUTR? 37
- Appendix B: Running BOOK to Print All the Screens . . . . . . . . 38
- Appendix C: Some Ada Compilers Available for the PC . . . . . . . 39
- Appendix D: Sample Multi-User Software License . . . . . . . . . 40
- Appendix E: Do You Need a Screen Editor / Word Processor? . . . . 42
- Appendix F: Installing ADA-TUTR on Other Computers . . . . . . . 43
- Appendix G: We Listen! New Features of ADA-TUTR . . . . . . . . 48
- Appendix H: Disclaimer of Warranty . . . . . . . . . . . . . . . 50
-
- Page ii
-
- ACKNOWLEDGMENTS
-
- The following trademarks are used in these notes and in the
- accompanying files:
-
- FirstAda Alsys, Inc.
- IBM International Business Machines Corp.
- IntegrAda Aetech, Inc.
- Janus/Ada R R Software, Inc.
- Meridian Ada Meridian Software Systems, Inc.
- Open Ada Meridian Software Systems, Inc.
- PC-Write Quicksoft
- TeleGen Telesoft Corporation
- Turbo Pascal Borland International
- UNIX AT & T
- VAX Digital Equipment Corporation
- VMS Digital Equipment Corporation
-
- The file ONECHAR.C was sent to us by Mr. David Hill, 7549 Wynford
- Street, Salt Lake City, UT 84121, and the file ALTCHAR.C was sent to
- us by Mr. Richard Conn, 2700 Bowline Court, Maineville, OH 45039.
- We're very grateful to Mr. Hill and to Mr. Conn for giving us
- permission to include these files in ADA-TUTR. When used with
- UNIX.ADA, these files provide two ways to run the Tutor on UNIX based
- machines without having to strike ENTER after each response. See
- pages 43-47.
-
- The programs in this version of ADA-TUTR were compiled with the
- Meridian Ada Compiler, v4.1, and optimized with the Meridian IFORM
- Optimizer, v1.0. The .EXE files contain Meridian's runtime, and were
- further compressed with the public domain program LZEXE, v0.91, by
- Fabrice Bellard of Grabels, France.
-
- Page 1
-
- INTRODUCTION
-
- ADA-TUTR, the Interactive Ada Tutor, will make you an excellent Ada
- programmer in minimum time. You'll learn good Ada program design
- techniques, not just Ada syntax. ADA-TUTR runs on PCs as well as
- workstations and mainframes. On PCs an Ada compiler is helpful, but
- not required. The PC can have a monochrome or a color monitor.
-
- These printed notes aren't meant to be a complete course, or even a
- summary, of Ada. They merely accompany the program ADA-TUTR, which is
- a complete course. You can't "study" these printed notes alone. For
- now, just read pages 1, 2, and 6.
-
- ADA-TUTR lets you learn at your own pace. So that you don't feel
- pressured, ADA-TUTR doesn't keep track of the number of right and
- wrong answers. It simply tells you whether your answers are correct,
- and why. Also, there's no time limit for answering the questions or
- completing the Outside Assignments.
-
- Because I want every programmer to have a chance to learn the best
- programming language, I made ADA-TUTR available very inexpensively as
- Shareware. Shareware isn't the same as public domain, and ADA-TUTR
- isn't free. But you may TRY it for free, and register or buy a
- license only if you use it. Please see pages 2-3 for details.
-
- Whether or not you use ADA-TUTR and register (or buy a license),
- you're encouraged to make unmodified copies of the program and
- distribute them. Please put ADA-TUTR on computer bulletin boards,
- distribute copies at club meetings, give them to companies, etc. You
- may charge a small fee to copy the program, provided you make it clear
- that the fee is only for the copy, and doesn't pay for the Shareware.
- (Companies that copy Shareware usually charge about $2 to $10 per
- diskette.) Bulletin boards may carry ADA-TUTR even if they charge for
- access. Please contact us for permission to include ADA-TUTR with
- commercial products, such as Ada compilers (see page 5). You may use
- file compression, library, and archive programs on ADA-TUTR; we won't
- interpret that as "modifying" the program. You may also add your own
- files. (The files included with ADA-TUTR are briefly described in
- ED.DIR.) If you register, you can earn substantial money distributing
- ADA-TUTR; please see page 2 for details.
-
- Ada will become more and more important, since the Department of
- Defense mandated its use in defense software, and is now making it
- very hard to obtain waivers. Although learning Ada takes real effort,
- you'll be able to write software that's more reliable and easier to
- modify a month or a year later.
-
- New features of this version of ADA-TUTR are described on pages 48-49.
- Please send me your comments and suggestions. I wish you success
- using ADA-TUTR!
-
- John J. Herro, Ph.D., Software Innovations Technology
- 1083 Mandarin Drive NE, Palm Bay, FL 32905-4706 (407)951-0233
-
- Page 2
-
- REGISTRATION AND LICENSES - WHAT IS SHAREWARE?
-
- Shareware is a way of marketing a program. It lets you try the
- program before spending money for it. If you decide to use the
- program, you send a small payment to register your copy or buy a
- license. We give you several incentives to do so, explained below.
- You're on your honor; you know whether you're "using" ADA-TUTR or
- only "trying" it.
-
- To use ADA-TUTR, individuals register as described below. Companies,
- schools, and other organizations can register each individual who
- uses the program, or buy a Multi-User License as described on the next
- page.
-
- INDIVIDUALS: Register your copy for only $25. When you register,
- please give us the serial number from the ADA-TUTR opening screen.
- We'll assign you a new serial number. Then run CHANGESN to put your
- new number into the program, and give copies to individuals, schools,
- companies, clubs, computer bulletin boards, etc.
-
- We'll send you a commission of $5 for each individual who registers
- from one of your copies, and TEN PERCENT for each Multi-User License
- sold from one of your copies! As you can see from the next page, you
- can earn up to $240 per license sold! Commissions are paid quarterly.
- If you like, print the file AD.TXT and use copies as an advertisement.
-
- Registration includes the right to use ADA-TUTR as long as you like,
- and it includes technical support for one year. While you have
- technical support, we'll inform you of any important updates to
- ADA-TUTR, and send you updated copies for only $5 each ($10 if you
- prefer a 3.5" diskette, free if you send us a blank, formatted,
- diskette with a stamped, addressed diskette mailer). We're planning a
- major update of ADA-TUTR with the next revision (9X) of the Ada
- language. You can renew technical support for only $10 a year. Even
- if you don't renew, you'll continue to receive commissions.
-
- When you register, you may order a copy of the current version of
- ADA-TUTR, with your serial number. The price is $5 for a 5.25"
- diskette, $10 for a 3.5" diskette, or free with your formatted
- diskette and a stamped, addressed diskette mailer. If you would like
- an order form or a price list, please print the file INVOICE.TXT.
-
- We offer a Customization Kit that lets you edit, add, and delete
- ADA-TUTR screens, questions, etc. (even whole topics), producing a new
- ADA_TUTR.DAT file. See the last paragraph on page 4. Note that the
- Customization Kit is not Shareware.
-
- We sell anywhere in the Free World. We're sorry, but we don't yet
- accept credit cards. Outside the U.S., please remit in U.S. funds and
- contact us about extra postal charges on diskettes.
-
-
- COMPANIES, SCHOOLS, AND OTHER ORGANIZATIONS: Please see our special
- offer for Multi-User Licenses on the next page.
-
- Page 3
-
- SPECIAL OFFER TO COMPANIES, SCHOOLS, ETC.
-
- ADA-TUTR can be of great benefit to your company, school, or other
- organization. We encourage you to try ADA-TUTR before paying for it,
- and you may install ADA-TUTR on your workstations and mainframes as
- well as your PCs! Instructions for installing ADA-TUTR on other
- computers are on page 43.
-
- If you decide to use ADA-TUTR, you could register each individual
- user, as described on page 2. But if you have more than 18 users, you
- can save money by buying a Multi-User License, as described here.
- You're on your honor; you know whether you're "using" ADA-TUTR or only
- "trying" it. Multi-User Licenses are very reasonably priced, as
- follows:
-
- Number of Users: Price of License: Note:
-
- Up to 100 only $450 Send $5 extra for a copy of the
- Up to 500 only $725 latest version of ADA-TUTR on a
- Up to 2000 only $950 5.25" diskette, $10 extra for a
- Unlimited only $2400 copy on a 3.5" diskette.
-
- A license may always be upgraded for only the difference in price.
-
- A sample Multi-User license appears on pages 40-41. A Multi-User
- License gives the specified number of people the right to use ADA-TUTR
- as long as you like, on all your computers (from small PCs to large
- mainframes), at all your locations. We use the term Multi-User
- License rather than Site License because there are no geographic
- restrictions. (Note: If 100 people use ADA-TUTR now and 100 others
- use it later, that counts as 200 users, not 100.) Sales commissions
- are NOT paid to Multi-User Licensees.
-
- A Multi-User License includes one year of technical support, which can
- be renewed for only 10% of the price of the license per year. While
- you have technical support, we'll inform you of any important updates
- to ADA-TUTR, and send you an updated copy on a 5.25" diskette for only
- $5 ($10 for a 3.5" diskette). The update is free if you send your own
- blank, formatted diskette and a stamped, addressed diskette mailer.
- We're planning a major update of ADA-TUTR with the next revision (9X)
- of the Ada language.
-
- Even if you don't renew your Technical Support, you'll still have the
- right to use ADA-TUTR as long as you like.
-
- Please print the file INVOICE.TXT, or use your own form. (When
- ordering, please give us the serial number from the opening screen of
- your copy of ADA-TUTR, if you have one.)
-
- We accept Purchase Orders. Our Federal tax ID number is 360-40-8382,
- and we qualify as a Small Business. We sell anywhere in the Free
- World. We're sorry, but we don't yet accept credit cards. Outside
- the U.S., please remit in U.S. funds and contact us about extra postal
- charges on diskettes.
-
- Page 4
-
- With Shareware, you never have to worry about software piracy, because
- your people are ENCOURAGED to copy and distribute the program! If you
- prefer, however, a conventional (non-Shareware) version of ADA-TUTR is
- available at the same prices.
-
- If you buy a license, we'll be happy to do minor customization of
- ADA-TUTR for you at no charge. For example, we can add your company
- name to the opening screen. If you'd like major customization,
- contact us for terms, or buy our Customization Kit for $195. Using
- any text editor on a PC or mainframe, the Customization Kit lets you
- edit, add, and delete screens, questions, etc. (even whole topics),
- producing a new ADA_TUTR.DAT file. The Customization Kit isn't
- Shareware, but you may copy it for use throughout your organization as
- required.
-
- Page 5
-
- NOTE TO COMPILER COMPANIES
-
- A Commercial version of ADA-TUTR is available, without the Shareware
- notices and without the list of Ada compilers. It can be customized
- for your company, and can run on almost any Ada platform, including
- workstations and mainframes, because Ada source code is included.
- ADA-TUTR can greatly increase the sales appeal of your compilers and
- your Ada tools, whether you sell it separately or include it with your
- products. Please contact us.
-
- If you're a prospective contractor or subcontractor, the Commercial or
- Shareware version of ADA-TUTR may be the best and most economical way
- for you to supply your customer's Ada educational needs. Please
- contact us before writing your proposal.
-
- Page 6
-
- DOES YOUR SCREEN SHOW STRANGE CHARACTERS LIKE ARROWS AND BRACKETS?
-
- Give the command TYPE READ.ME on your PC. If one word appears
- brighter than the rest, you can skip this page. However, if your
- screen shows strange characters like "[1m" when you TYPE READ.ME or
- run ADA_TUTR, you need to read this.
-
- ADA-TUTR uses ANSI (American National Standards Institute) escape
- sequences for highlighting, cursor positioning, reverse video, etc.
- Before ADA-TUTR will work correctly on a PC, you must install the
- device driver ANSI.SYS, which came with your copy of DOS. To install
- ANSI.SYS, do the following:
-
- 1. If there's a file CONFIG.SYS in the root directory of the disk
- from which you boot, type it and look for a line saying
- "DEVICE=ANSI.SYS" (without the quotes), in either upper or lower
- case. If that line is not present, add it to CONFIG.SYS anywhere
- in the file, using an ordinary text editor or word processor in
- the non-document mode. If there's no CONFIG.SYS file, create one
- containing the single line "DEVICE=ANSI.SYS" (without the quotes).
-
- 2. If there's no file ANSI.SYS in your root directory, copy ANSI.SYS
- from your DOS distribution diskette to the root directory of the
- disk from which you boot.
-
- 3. Reboot the computer. ADA-TUTR should then work correctly.
-
- Page 7
-
- THE ADA RESERVED WORDS
-
- The 63 reserved words are listed in the Language Reference Manual in
- section 2.9, and are repeated here for convenience.
-
- abort declare generic of select
- abs delay goto or separate
- accept delta others subtype
- access digits if out
- all do in task
- and is package terminate
- array pragma then
- at else private type
- elsif limited procedure
- end loop
- begin entry raise use
- body exception range
- exit mod record when
- rem while
- new renames with
- case for not return
- constant function null reverse xor
-
- Page 8
-
- STEPS FOR OUTSIDE ASSIGNMENT 1, PREPARING TO RUN ADA
-
- For the first Outside Assignment, learn enough about your Ada compiler
- to compile and run the two simple programs HELLO.ADA and ADD.ADA.
- Obviously, you have to do this before you can do the remaining Outside
- Assignments.
-
- 1. Compile HELLO.ADA. On most systems, after the Ada compiler is
- installed and your library is created, this only involves typing
- ADA HELLO or ADA HELLO.ADA. On some systems, the compiler is invoked
- from a menu or "APSE" (Ada Programming Support Environment).
-
- 2. Link, giving the name of the main program, HELLO. This usually
- involves typing LINK HELLO or BIND HELLO, perhaps with some options.
- On one system, the command is BAMP HELLO, for Build Ada Main Program!
-
- 3. Run the program. If your Ada compiler produces native code on a
- PC, it created a file HELLO.EXE, and this step simply involves typing
- HELLO. On other systems, the command RUN HELLO is appropriate. On
- some systems, you have to invoke an interpreter to run the program.
-
- 4. Now compile, link, and run ADD.ADA.
-
- If your compiler implements a subset of Ada, you may have to modify
- the programs in this and later Outside Assignments to get them to
- compile. Some subset Ada compilers don't allow "separate" compilation
- (used in later assignments), and you'll have to include the "separate"
- subprograms inside the main program and compile them as one. Some
- subset compilers don't allow generic instantiation, and have another
- way of displaying integers. In that case, you'll have to modify
- ADD.ADA. If you're using a validated compiler, you won't have to
- worry about any of this, because all of the Outside Assignments are
- written in standard Ada.
-
- Page 9
-
- HELLO.ADA
- ---------
-
- with TEXT_IO; use TEXT_IO;
- procedure HELLO is
- begin
- PUT_LINE("Hello!");
- end HELLO;
-
-
-
- ADD.ADA
- -------
-
- with TEXT_IO; use TEXT_IO;
- procedure ADD is
- package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
- begin
- PUT(2 + 2);
- NEW_LINE;
- end ADD;
-
- Page 10
-
- TRITEST.ADA
- -----------
-
- with TEXT_IO; use TEXT_IO;
- procedure TRITEST is
- PASSED : BOOLEAN := TRUE;
- type TRIANGLE is (EQUILATERAL, ISOSCELES, SCALENE, NOT_A_TRIANGLE);
- function TRITYPE(LEN1, LEN2, LEN3 : in INTEGER) return TRIANGLE
- is separate;
- procedure COMPARE(A, B, C: in INTEGER; RIGHT_ANSWER : in TRIANGLE)
- is separate;
- begin
- COMPARE( 3, 4, 5, SCALENE);
- COMPARE( 6, 3, 4, SCALENE);
- COMPARE( 4, 3, 6, SCALENE);
- COMPARE( 3, 3, 3, EQUILATERAL);
- COMPARE( 3, 3, 4, ISOSCELES);
- COMPARE( 3, 4, 3, ISOSCELES);
- COMPARE( 4, 3, 3, ISOSCELES);
- COMPARE( 7, 7, 4, ISOSCELES);
- COMPARE( 7, 4, 7, ISOSCELES);
- COMPARE( 4, 7, 7, ISOSCELES);
- COMPARE( 1, 1, 1, EQUILATERAL);
- COMPARE( 0, 4, 4, NOT_A_TRIANGLE);
- COMPARE( 4, 0, 4, NOT_A_TRIANGLE);
- COMPARE( 4, 4, 0, NOT_A_TRIANGLE);
- COMPARE( 0, 4, 3, NOT_A_TRIANGLE);
- COMPARE( 3, 0, 4, NOT_A_TRIANGLE);
- COMPARE( 4, 3, 0, NOT_A_TRIANGLE);
- COMPARE(-1, 4, 4, NOT_A_TRIANGLE);
- COMPARE( 4, -1, 4, NOT_A_TRIANGLE);
- COMPARE( 4, 4, -1, NOT_A_TRIANGLE);
- COMPARE(-1, 4, 3, NOT_A_TRIANGLE);
- COMPARE( 3, -1, 4, NOT_A_TRIANGLE);
- COMPARE( 4, 3, -1, NOT_A_TRIANGLE);
- COMPARE( 2, 4, 6, NOT_A_TRIANGLE);
- COMPARE( 1, 3, 2, NOT_A_TRIANGLE);
- COMPARE( 3, 1, 2, NOT_A_TRIANGLE);
- COMPARE( 1, 2, 4, NOT_A_TRIANGLE);
- COMPARE( 1, 4, 2, NOT_A_TRIANGLE);
- COMPARE( 4, 1, 2, NOT_A_TRIANGLE);
- COMPARE( 0, 0, 0, NOT_A_TRIANGLE);
- COMPARE( 0, 0, 4, NOT_A_TRIANGLE);
- COMPARE( 0, 4, 0, NOT_A_TRIANGLE);
- COMPARE( 4, 0, 0, NOT_A_TRIANGLE);
- COMPARE( 3, 3, 7, NOT_A_TRIANGLE);
- COMPARE( 3, 7, 3, NOT_A_TRIANGLE);
- COMPARE( 6, 3, 3, NOT_A_TRIANGLE);
- COMPARE(-3, -4, -5, NOT_A_TRIANGLE);
- if PASSED then
- PUT_LINE("Congratulations, you completed the assignment!");
- end if;
- end TRITEST;
- -- continued --
-
- Page 11
-
- separate (TRITEST)
- procedure COMPARE(A, B, C: in INTEGER; RIGHT_ANSWER : in TRIANGLE) is
- package INT_IO is new INTEGER_IO(INTEGER); use INT_IO;
- package TRI_IO is new ENUMERATION_IO(TRIANGLE); use TRI_IO;
- MY_ANSWER : TRIANGLE := TRITYPE(A, B, C);
- begin
- if MY_ANSWER /= RIGHT_ANSWER then
- PUT("Sides:");
- PUT(A, WIDTH => 3);
- PUT(B, WIDTH => 3);
- PUT(C, WIDTH => 3);
- PUT(" My answer: ");
- PUT(MY_ANSWER, WIDTH => 14);
- PUT(" Right answer: ");
- PUT(RIGHT_ANSWER);
- NEW_LINE;
- PASSED := FALSE;
- end if;
- end COMPARE;
-
- Page 12
-
- STEPS FOR OUTSIDE ASSIGNMENT 2, EXERCISE IN ENUMERATION TYPES
-
- 1. Compile the test driver TRITEST.ADA. Also, make a copy of the
- dummy solution by typing COPY TRITYPE.DUM TRITYPE.ADA. You need
- do this step only once.
-
- 2. Edit TRITYPE.ADA to become your real solution. You can skip this
- step the first time through, to see error messages from the test
- driver.
-
- 3. Compile your solution TRITYPE.ADA. If the compiler finds errors,
- go back to step 2.
-
- 4. Link with the name of the main program TRITEST. Then execute. If
- the test driver displays error messages, go back to step 2.
-
- 5. When the message "Congratulations, you completed the assignment!"
- is displayed, you'll have a chance to compare your solution with
- ours.
-
- Page 13
-
- NEXTDATE.ADA
- ------------
-
- with TEXT_IO; use TEXT_IO;
- procedure NEXTDATE is
- type MONTH_TYPE is
- (JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC);
- subtype DAY_SUBTYPE is INTEGER range 1 .. 31;
- type DATE is
- record
- DAY : DAY_SUBTYPE;
- MONTH : MONTH_TYPE;
- YEAR : POSITIVE;
- end record;
- PASSED : BOOLEAN := TRUE;
- function TOMORROW(TODAY : in DATE) return DATE is separate;
-
- procedure DISPLAY (S : in STRING; D : in DATE) is
- package INT_IO is new INTEGER_IO(INTEGER); use INT_IO;
- begin
- PUT(S);
- PUT(D.DAY, WIDTH => 3);
- PUT(" " & MONTH_TYPE'IMAGE(D.MONTH));
- PUT(D.YEAR, WIDTH => 5);
- NEW_LINE;
- end DISPLAY;
- procedure COMPARE(TODAY, RIGHT_ANSWER : in DATE) is
- MY_ANSWER : DATE := TOMORROW(TODAY);
- begin
- if MY_ANSWER /= RIGHT_ANSWER then
- DISPLAY("Today: ", TODAY);
- DISPLAY("My answer: ", MY_ANSWER);
- DISPLAY("Right answer:", RIGHT_ANSWER);
- NEW_LINE;
- PASSED := FALSE;
- end if;
- end COMPARE;
- begin
- COMPARE((12,DEC,1815), (13,DEC,1815)); -- ordinary date
- COMPARE(( 3,FEB,1986), ( 4,FEB,1986)); -- ordinary date in Feb.
- COMPARE((30,JUN,1981), ( 1,JUL,1981)); -- last day of 30-day month
- COMPARE((30,SEP,3999), ( 1,OCT,3999)); -- last day of 30-day month
- COMPARE((31,MAR,1876), ( 1,APR,1876)); -- last day of 31-day month
- COMPARE((31,AUG,1984), ( 1,SEP,1984)); -- last day of 31-day month
- COMPARE((31,DEC,1966), ( 1,JAN,1967)); -- last day of year
- COMPARE((28,FEB,1980), (29,FEB,1980)); -- leap year
- COMPARE((28,FEB,1600), (29,FEB,1600)); -- century leap year
- COMPARE((28,FEB,2200), ( 1,MAR,2200)); -- century non-leap year
- COMPARE((28,FEB,1982), ( 1,MAR,1982)); -- non-leap year
- COMPARE((29,FEB,1980), ( 1,MAR,1980)); -- leap day in leap year
- if PASSED then
- PUT_LINE("Congratulations, you completed the assignment!");
- end if;
- end NEXTDATE;
-
- Page 14
-
- STEPS FOR OUTSIDE ASSIGNMENT 3, EXERCISE IN RECORDS
-
- 1. Compile the test driver NEXTDATE.ADA. Also, make a copy of the
- dummy solution by typing COPY TOMORROW.DUM TOMORROW.ADA. You need
- do this step only once.
-
- 2. Edit TOMORROW.ADA to become your real solution. You can skip this
- step the first time through, to see error messages from the test
- driver.
-
- 3. Compile TOMORROW.ADA. If the compiler finds errors, go back to
- step 2.
-
- 4. Link with the name of the main program NEXTDATE. Then execute.
- If the test driver displays error messages, go back to step 2.
-
- 5. When the message "Congratulations, you completed the assignment!"
- is displayed, you'll have a chance to compare your solution with
- ours.
-
- Page 15
-
- FIBTEST.ADA
- -----------
-
- with TEXT_IO; use TEXT_IO;
- procedure FIBTEST is
- PASSED : BOOLEAN := TRUE;
- function FIB(N : in POSITIVE) return POSITIVE is separate;
- procedure COMPARE (N : in POSITIVE; RIGHT_ANSWER : in POSITIVE) is
- package INT_IO is new INTEGER_IO(INTEGER); use INT_IO;
- MY_ANSWER : POSITIVE := FIB(N);
- begin
- if MY_ANSWER /= RIGHT_ANSWER then
- PUT("N:"); PUT(N);
- PUT(" My answer:"); PUT(MY_ANSWER);
- PUT(" Right answer:"); PUT(RIGHT_ANSWER);
- NEW_LINE;
- PASSED := FALSE;
- end if;
- end COMPARE;
- begin
- COMPARE(1, 1);
- COMPARE(2, 1);
- COMPARE(3, 2);
- COMPARE(4, 3);
- COMPARE(5, 5);
- COMPARE(6, 8);
- COMPARE(7, 13);
- COMPARE(10, 55);
- COMPARE(15, 610);
- COMPARE(20, 6765);
- if PASSED then
- PUT_LINE("Congratulations, you completed the assignment!");
- end if;
- end FIBTEST;
-
- Page 16
-
- STEPS FOR OUTSIDE ASSIGNMENT 4, EXERCISE IN RECURSION
-
- 1. Compile the test driver FIBTEST.ADA. Also, make a copy of the
- dummy solution by typing COPY FIB.DUM FIB.ADA. You need do this
- step only once.
-
- 2. Edit FIB.ADA to become your real solution. You can skip this step
- the first time through, to see error messages from the test
- driver.
-
- 3. Compile FIB.ADA. If the compiler finds errors, go back to step 2.
-
- 4. Link with the name of the main program FIBTEST. Then execute. If
- the test driver displays error messages, go back to step 2.
-
- 5. When the message "Congratulations, you completed the assignment!"
- is displayed, you'll have a chance to compare your solution with
- ours.
-
- Page 17
-
- SIMPLIFIED SPECIFICATION FOR TEXT_IO
- ------------------------------------
-
- package TEXT_IO is
- type FILE_TYPE is limited private;
-
- type FILE_MODE is (IN_FILE, OUT_FILE);
- type COUNT is ... (a user-defined type similar to INTEGER);
- STATUS_ERROR, MODE_ERROR, NAME_ERROR, END_ERROR : exception;
-
- procedure CREATE (FILE : in out FILE_TYPE;
- MODE : in FILE_MODE := OUT_FILE;
- NAME : in STRING);
-
- procedure OPEN (FILE : in out FILE_TYPE;
- MODE : in FILE_MODE;
- NAME : in STRING);
-
- procedure CLOSE (FILE : in out FILE_TYPE);
- procedure DELETE (FILE : in out FILE_TYPE);
- procedure NEW_LINE (SPACING : in COUNT := 1);
- procedure NEW_LINE (FILE : in FILE_TYPE;
- SPACING : in COUNT := 1);
- procedure SKIP_LINE (SPACING : in COUNT := 1);
- procedure SKIP_LINE (FILE : in FILE_TYPE;
- SPACING : in COUNT := 1);
- function END_OF_FILE (FILE : in FILE_TYPE) return BOOLEAN;
- procedure PUT (ITEM : in CHARACTER);
- procedure PUT (FILE : in FILE_TYPE; ITEM : in CHARACTER);
- procedure GET (ITEM : out CHARACTER);
- procedure GET (FILE : in FILE_TYPE; ITEM : out CHARACTER);
- procedure PUT (ITEM : in STRING);
- procedure PUT (FILE : in FILE_TYPE; ITEM : in STRING);
- procedure PUT_LINE (ITEM : in STRING);
- procedure PUT_LINE (FILE : in FILE_TYPE; ITEM : in STRING);
- procedure GET_LINE (ITEM : out STRING; LAST : out NATURAL);
- procedure GET_LINE (FILE : in FILE_TYPE;
- ITEM : out STRING;
- LAST : out NATURAL);
- generic
- type NUM is range <>;
- package INTEGER_IO is
- procedure GET (ITEM : out NUM);
- procedure GET (FILE : in FILE_TYPE; ITEM : out NUM);
- procedure PUT (ITEM : in NUM;
- WIDTH : in INTEGER := ...;
- BASE : in INTEGER := 10);
- procedure PUT (FILE : in FILE_TYPE;
- ITEM : in NUM;
- WIDTH : in INTEGER := ...;
- BASE : in INTEGER := 10);
- end INTEGER_IO;
-
- -- continued --
-
- Page 18
-
- generic
- type NUM is digits <>;
- package FLOAT_IO is
- procedure GET (ITEM : out NUM);
- procedure GET (FILE : in FILE_TYPE; ITEM : out NUM);
- procedure PUT (ITEM : in NUM;
- FORE : in INTEGER := 2;
- AFT : in INTEGER := ...;
- EXP : in INTEGER := 3);
- procedure PUT (FILE : in FILE_TYPE;
- ITEM : in NUM;
- FORE : in INTEGER := 2;
- AFT : in INTEGER := ...;
- EXP : in INTEGER := 3);
- end FLOAT_IO;
-
- generic
- type ENUM is (<>);
- package ENUMERATION_IO is
- procedure GET (ITEM : out ENUM);
- procedure GET (FILE : in FILE_TYPE; ITEM : out ENUM);
- procedure PUT (ITEM : in ENUM; WIDTH : in INTEGER := 0);
- procedure PUT (FILE : in FILE_TYPE;
- ITEM : in ENUM; WIDTH : in INTEGER := 0);
- end ENUMERATION_IO;
-
- private
-
- type FILE_TYPE is ... (implementation dependent);
-
- end TEXT_IO;
-
- Page 19
-
- Program to copy a simple text file:
- -----------------------------------
-
- with TEXT_IO; use TEXT_IO;
- procedure FILECOPY is
- F1, F2 : FILE_TYPE;
- S : STRING(1 .. 80);
- LEN : INTEGER;
- begin
- PUT("Input file: "); GET_LINE(S, LEN);
- OPEN(FILE => F1, MODE => IN_FILE, NAME => S(1 .. LEN));
- PUT("Output file: "); GET_LINE(S, LEN);
- CREATE(FILE => F2, MODE => OUT_FILE, NAME => S(1 .. LEN));
- while not END_OF_FILE(F1) loop
- GET_LINE(F1, S, LEN);
- PUT_LINE(F2, S(1 .. LEN));
- end loop;
- CLOSE(F1);
- CLOSE(F2);
- end FILECOPY;
-
-
-
- Function to test if a text file exists:
- ---------------------------------------
-
- with TEXT_IO; use TEXT_IO;
- function EXISTS(FILE_NAME : in STRING) return BOOLEAN is
- F : FILE_TYPE;
- ANSWER : BOOLEAN := TRUE;
- begin
- begin
- OPEN(F, IN_FILE, FILE_NAME);
- CLOSE(F);
- exception
- when NAME_ERROR => ANSWER := FALSE;
- end;
- return ANSWER;
- end EXISTS;
-
- Page 20
-
- REQUIREMENTS FOR THE PROGRAM LEDIT
-
- This assignment will give you practice in writing a program of greater
- complexity than the previous programs you've written. Imagine that
- your screen editor is unavailable to a particular user, perhaps
- because he's dialing your computer from a remote location, and your
- screen editor writes directly to the screen. You want to write a very
- simple line editor, LEDIT, that could be used in such circumstances.
- While your computer already has a line editor called EDLIN, it's
- difficult to learn to use. LEDIT will take almost no effort to learn.
- The only commands are LIST and EXIT! The line editor edits by means
- of line numbers, similar to the Basic language.
-
- The user begins each line of text that he types with a line number
- from 1 to 29999. Line numbers must be integers. The upper limit
- 29999 was chosen so that the simple type INTEGER could be used - in
- any implementation of Ada. Regardless of the order in which lines
- are typed, LEDIT maintains a linked list of lines in order by number.
- Also, line numbers may be preceded by any number of spaces. For
- example, if the user types
-
- 40 -- This is a comment.
- 20 begin
- 10 with TEXT_IO; use TEXT_IO;
- 30 end ADD;
-
- and then types LIST, the editor will type
-
- 10 with TEXT_IO; use TEXT_IO;
- 20 begin
- 30 end ADD;
- 40 -- This is a comment.
-
- To INSERT lines, the user merely types lines with intermediate line
- numbers. For example, if he types
-
- 15 procedure HELLO is
-
- and then types LIST, LEDIT will type
-
- 10 with TEXT_IO; use TEXT_IO;
- 15 procedure HELLO is
- 20 begin
- 30 end ADD;
- 40 -- This is a comment.
-
- To REPLACE an existing line, the user merely types a line with the
- same line number as the line to be replaced. For example, if he typed
-
- 15 procedure ADD is
- LIST
-
-
- -- continued --
-
- Page 21
-
- LEDIT would then show
-
- 10 with TEXT_IO; use TEXT_IO;
- 15 procedure ADD is
- 20 begin
- 30 end ADD;
- 40 -- This is a comment.
-
- Finally, to DELETE a line, the user merely types the number of the
- line to be deleted, followed immediately by a carriage return. Typing
-
- 40
- LIST
-
- would then produce
-
- 10 with TEXT_IO; use TEXT_IO;
- 15 procedure ADD is
- 20 begin
- 30 end ADD;
-
- Thus the user can INSERT, REPLACE, and DELETE lines, all by line
- numbers, without learning any commands. Note that in this simple
- editor there is no "cursor" and no "current line."
-
- The space is not required after the line number. These two lines have
- exactly the same effect:
-
- 20 begin
- 20begin
-
- Of course, if the text of the line begins with a digit, a space will
- be required to separate it from the line number. In any event, LEDIT
- always leaves one blank space after the line number when LISTing, for
- readability. It always allows exactly five spaces for the line number
- itself.
-
- However, any EXTRA spaces typed after the line number are significant.
- The three lines below each contain three EXTRA spaces after the line
- number, for a total of four spaces.
-
- 24 PUT(2 + 2);
- 26 NEW_LINE;
- 18 package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
-
- They have the effect of indenting the text three spaces. LIST now
- shows
-
-
- -- continued --
-
- Page 22
-
- 10 with TEXT_IO; use TEXT_IO;
- 15 procedure ADD is
- 18 package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
- 20 begin
- 24 PUT(2 + 2);
- 26 NEW_LINE;
- 30 end ADD;
-
- Although typing a line number followed immediately by a carriage
- return deletes a line (if there is a line by that number), typing a
- line number followed by a single space causes an empty line to be
- introduced into the file. For example, typing 12 followed by a single
- space and a carriage return would then cause LIST to type
-
- 10 with TEXT_IO; use TEXT_IO;
- 12
- 15 procedure ADD is
- 18 package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
- 20 begin
- 24 PUT(2 + 2);
- 26 NEW_LINE;
- 30 end ADD;
-
- When LEDIT is run, it prompts for the names of the input and output
- files. If the input file exists, LEDIT displays "File found" and
- reads the file into its linked list, assigning line numbers starting
- with 10 and incrementing by 10. If the file does not exist, LEDIT
- displays "File not found," and the linked list is initially empty. In
- any event, LEDIT creates an output file. When the EXIT command is
- given, LEDIT writes the contents of the linked list to the output
- file. In doing so, LEDIT removes the line numbers and the first blank
- after each line number.
-
- In the example above, let us assume that the user typed ADD.ADA for an
- output file name. When he types EXIT, the new file ADD.ADA created by
- LEDIT will contain:
-
- with TEXT_IO; use TEXT_IO;
-
- procedure ADD is
- package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
- begin
- PUT(2 + 2);
- NEW_LINE;
- end ADD;
-
- (Note that the file contains one empty line.) Your program is not
- allowed to add any trailing blanks of its own in the output file. If
- the user again runs LEDIT and specifies ADD.ADA as an input file, the
- editor will type "File found" and read the file. LIST will then show
-
-
- -- continued --
-
- Page 23
-
- 10 with TEXT_IO; use TEXT_IO;
- 20
- 30 procedure ADD is
- 40 package MY_INT_IO is new INTEGER_IO(INTEGER); use MY_INT_IO;
- 50 begin
- 60 PUT(2 + 2);
- 70 NEW_LINE;
- 80 end ADD;
-
- When he EXITs, the new file will contain modified text. The old file
- will still be present until it is deleted.
-
- The two commands LIST and EXIT must be accepted in either upper or
- lower case, but for simplicity, they need not be accepted in a mixture
- of cases. They may be preceded by any number of spaces. The LIST
- command must be accepted in any of the following forms:
-
- LIST (Lists all lines, if any, otherwise does nothing.)
- list 30 (Lists line 30, if it exists.)
- list 25 - 35 (Lists all lines between 25 and 35 inclusive, if any.)
- LIST - 35 (Lists all lines numbered 35 or less, if any.)
- list 25 - (Lists all lines numbered 25 or more, if any.)
-
- Furthermore, all spaces are optional in the LIST command provided that
- LIST is written solid, so that LIST25-35 is equivalent to the third
- example above. Any other forms of LIST should be flagged as an error.
- In particular, all of these should give error messages:
-
- LIST -
- list 2A
- LIST 30 - 50 -
- list 30 - -50
- list 30-A
- LIST XYZ
-
- The EXIT command must stand alone; unlike LIST, EXIT is never followed
- by anything. Except for the LIST and EXIT commands, every line typed
- must begin with a number between 1 and 29999. (Of course, the user
- should be able to type just a carriage return with no effect.) LEDIT
- should check that line numbers are in range when adding or replacing
- lines. The LIST command need not check the range of the line numbers,
- because it should be impossible to create lines with improper numbers.
- Your program need not handle input files so long that 29999 would be
- exceeded when it assigns line numbers starting at 10 with an increment
- of 10.
-
- Your LEDIT must prompt for input and output file names at the start,
- and it may display a prompt for each line that the user types. You
- may assume some maximum length for an input line (e.g., 80), and
- assume that no file will have lines longer than the maximum. You may
- also assume that no file will have special characters like form feeds.
-
-
- -- continued --
-
- Page 24
-
- For simplicity, there's no way to edit a line except by retyping it.
- Also, there's no way to copy or move a line or a block of lines, and
- no way to delete a block of lines except one line at a time. There's
- no RENUMBER command. The user can renumber the entire file starting
- at 10 with an increment of 10 by EXITing and then rerunning LEDIT.
- There's no AUTO command to make the editor type the line numbers
- automatically while text is being typed by the user, and there's no
- means of recovering from a system crash that occurs during an edit.
- Additionally, there's no way to search for a string, or replace one
- string with another. These features would all be desirable, but we
- feel that Outside Assignment 5 is challenging as it stands.
-
- You're encouraged to use Ada's "separate" compilation feature, so that
- you don't have to recompile the entire program when developing a
- module.
-
- As a point of reference, our solution to this assignment consists of
- about 180 lines of code on four pages. If you have any questions
- about what LEDIT should do, you can compile and run our solution,
- which is in LEDIT.ANS.
-
- The following declarations are offered by way of suggestion only, and
- you should use them only if you feel comfortable with them:
-
- MAX_LENGTH : constant INTEGER := 80;
- type TEXT is
- record
- LEN : INTEGER range 0 .. MAX_LENGTH;
- VAL : STRING(1 .. MAX_LENGTH);
- end record;
-
- type LINK;
- type P is access LINK;
- type LINK is
- record
- NUM : POSITIVE;
- LINE : TEXT;
- NEXT : P;
- end record;
-
- function STR(T : in TEXT) return STRING;
-
- In our solution, we used type TEXT as above. However, we didn't write
- a TEXT_HANDLER package, because it didn't seem to be needed. We used
- a one-page main program with several "separate" subprograms.
-
- Page 25
-
- STEPS FOR OUTSIDE ASSIGNMENT 5, WRITING A SIMPLE LINE EDITOR
-
- 1. Carefully read the requirements starting on page 20 of these
- notes. Take your time.
-
- 2. Write the Ada code, compile, and link. Call the main program
- LEDIT. If you have any questions about what LEDIT should do, you
- can compile and run our solution, which is in LEDIT.ANS.
-
- 3. Refer to pages 26-28 of these notes for instructions on testing
- your line editor. If any tests are failed, go back to step 2.
-
- 4. When all the tests are passed, you've completed the assignment and
- will have a chance to compare your solution with ours.
-
- Page 26
-
- HOW TO TEST LEDIT
-
- 1. Run LEDIT and give the name of an input file that doesn't exist.
- LEDIT should say "File not found." Give another name of a file that
- doesn't exist for an output file.
-
- 2. Type "LIST" (without the quotes) to make sure that LEDIT can
- handle the LIST command when no text has been entered.
-
- 3. Type "EXI". The program should NOT exit. If it exits, it's
- probably because the "T" was left in the input buffer from the LIST
- command. Your program is checking the first four characters of the
- input buffer without checking the length of the typed command.
-
- 4. Type "ABC". The program should display a message about an illegal
- or unrecognized command, or syntax error.
-
- 5. Type "0X" (zero followed by X). The program should reject this
- line, displaying a message about an invalid line number. Type "0 X".
- The same thing should happen. Try "30000X", then "30000 X", and then
- "3000000000 X". The program should reject these, as well.
-
- 6. Type "-1 X" and "-1X". The program should reject these lines,
- displaying a message either about an unrecognized command (or syntax
- error), or an invalid line number.
-
- 7. Type a simple carriage return. There should be no effect, except
- for any prompt being repeated.
-
- 8. Type the following exactly as shown. Note that lines 1000 and 100
- each contain four spaces:
-
- 30 X
- 1 The
- 29999 ZZZZZZZZ
- 1000 used
- 100 is
- 10000 to test
- 30file --
- 1 This
- 29999 LEDIT.
-
- 9. Type "list". You should see the following, lined up exactly as
- shown. There should be exactly five spaces for the line numbers.
-
- 1 This
- 30 file --
- 100 is
- 1000 used
- 10000 to test
- 29999 LEDIT.
-
-
- -- continued --
-
- Page 27
-
- 10. Try a line of text beginning with a number: "20000 123 45". Then
- type " LIST" with three leading spaces. You should see
-
- 1 This
- 30 file --
- 100 is
- 1000 used
- 10000 to test
- 20000 123 45
- 29999 LEDIT.
-
- 11. Insert an empty line by typing "15000 ". Then type "LIST". You
- should see
-
- 1 This
- 30 file --
- 100 is
- 1000 used
- 10000 to test
- 15000
- 20000 123 45
- 29999 LEDIT.
-
- 12. Type "EXIT ABC". LEDIT should display a error message and NOT
- exit. The requirements say that the EXIT command must stand alone.
-
- 13. Type " exit". LEDIT should exit, and you should have a new
- file with the output file name you gave in step 1. Type the file with
- the TYPE command. You should see exactly this, starting in column 1:
-
- This
- file --
- is
- used
- to test
-
- 123 45
- LEDIT.
-
- 14. Run LEDIT again, using for an input file the name of the OUTPUT
- file you specified in step 1. This time the program should say "File
- found." Choose yet another name for an output file for this step.
- Type "list". You should see the following, exactly as shown:
-
- 10 This
- 20 file --
- 30 is
- 40 used
- 50 to test
- 60
- 70 123 45
- 80 LEDIT.
-
- -- continued --
-
- Page 28
-
- 15. Type " LIST 30". You should see only line 30. Type
- "list25-45". You should see only lines 30 and 40. Type "LIST - 40".
- You should see lines 10 through 40. Type "list35 -". You should see
- lines 40 through 80. Type "list 15". The program should either do
- nothing or display a message that line 15 doesn't exist. Try
- "list 30000" and "list 3000000000". Again, the program should either
- do nothing or display an error message. Now type "list" and check
- that the result is the same as in step 14.
-
- 16. Try each of the following. In each case, LEDIT should display an
- error message:
-
- LIST -
- list 2A
- list 30 - 50 -
- list 30 - -50
- list 30-A
- LIST XYZ
-
- 17. Type "70" to delete line 70. Type "LIST". You should see
-
- 10 This
- 20 file --
- 30 is
- 40 used
- 50 to test
- 60
- 80 LEDIT.
-
- 18. Delete line 60. Do not list. Now delete line 80 and list. You
- should see
-
- 10 This
- 20 file --
- 30 is
- 40 used
- 50 to test
-
- 19. Delete line 10 and list. You should see lines 20 through 50
- above. Delete line 50 and list. You should see lines 20 through 40.
- Delete line 30 and list. You should see lines 20 and 40. Delete line
- 40 and list. You should see only line 20. Delete line 20 and list.
- The result should be the same as in step 2. Type "EXIT".
-
- 20. If your program passed all these tests, sincere congratulations!
- You've completed a difficult assignment. We hope that you feel
- comfortable with Ada now. If you like, you can compare your solution
- with ours, starting on page 29 of these notes. When you go back to
- ADA-TUTR, you'll learn to write your own generic packages, procedures,
- and functions.
-
- Page 29
-
- LEDIT.ANS
- ---------
-
- -- Our solution to Outside Assignment 5:
- with TEXT_IO; use TEXT_IO;
- procedure LEDIT is
- MAX_LENGTH : constant := 80;
- MAX_LINE_NUMBER : constant := 29_999;
- type TEXT is
- record
- LEN : INTEGER range 0 .. MAX_LENGTH := 0;
- VAL : STRING(1 .. MAX_LENGTH);
- end record;
- type LINK;
- type P is access LINK;
- type LINK is
- record
- NUM : POSITIVE;
- LINE : TEXT;
- NEXT : P;
- end record;
- HEAD : P := new LINK;
- TEMP : P;
- INPUT_FILE : FILE_TYPE;
- OUTPUT_FILE : FILE_TYPE;
- INPUT : TEXT;
- FINISHED : BOOLEAN := FALSE;
- LINE_NUM : NATURAL := 10;
-
- function STR(T : in TEXT) return STRING is separate;
- procedure READ_INPUT_FILE is separate;
- procedure DO_COMMAND is separate;
- begin
- PUT("Input file: "); GET_LINE(INPUT.VAL, INPUT.LEN);
- READ_INPUT_FILE;
- PUT("Output file: "); GET_LINE(INPUT.VAL, INPUT.LEN);
- CREATE(OUTPUT_FILE, NAME => STR(INPUT));
-
- -- Get and process commands.
- while not FINISHED loop
- PUT("> "); GET_LINE(INPUT.VAL, INPUT.LEN);
- DO_COMMAND;
- end loop;
-
- -- Write the output file.
- TEMP := HEAD.NEXT; -- Skip unused link at start of linked list.
- while TEMP /= null loop
- PUT_LINE(OUTPUT_FILE, STR(TEMP.LINE)); -- Write line of text.
- TEMP := TEMP.NEXT; -- Get next link.
- end loop;
- CLOSE(OUTPUT_FILE);
- end LEDIT;
-
- -- continued --
-
- Page 30
-
- separate (LEDIT)
- function STR(T : in TEXT) return STRING is
- begin
- return T.VAL(1 .. T.LEN);
- end STR;
-
- separate (LEDIT)
- procedure READ_INPUT_FILE is
- begin -- If the input file exists, display a message and read it in.
- OPEN(INPUT_FILE, IN_FILE, STR(INPUT));
- PUT_LINE("File found.");
- TEMP := HEAD;
- while not END_OF_FILE(INPUT_FILE) loop
- GET_LINE(INPUT_FILE, INPUT.VAL, INPUT.LEN); -- Read a line.
- TEMP.NEXT := new LINK'(LINE_NUM, INPUT, null); -- Add to list.
- TEMP := TEMP.NEXT; -- Advance pointer to next link.
- LINE_NUM := LINE_NUM + 10;
- end loop;
- CLOSE(INPUT_FILE);
- exception -- If the input file doesn't exist, just display a message.
- when NAME_ERROR => PUT_LINE("File not found.");
- end READ_INPUT_FILE;
-
- separate (LEDIT)
- procedure DO_COMMAND is
- procedure DELETE_FIRST_CHARACTER(T : in out TEXT) is separate;
- procedure GET_LEADING_INTEGER(N : out NATURAL) is separate;
- procedure STRIP_LEADING_SPACES_FROM_INPUT is separate;
- procedure ADD_DELETE_REPLACE_LINE is separate;
- procedure LIST is separate;
- begin
- STRIP_LEADING_SPACES_FROM_INPUT;
- if STR(INPUT) = "exit" or STR(INPUT) = "EXIT" then
- FINISHED := TRUE;
- elsif INPUT.LEN >= 4 and (INPUT.VAL(1 .. 4) = "list" or
- INPUT.VAL(1 .. 4) = "LIST") then
- LIST;
- elsif INPUT.LEN > 0 and INPUT.VAL(1) not in '0' .. '9' then
- PUT_LINE("Unrecognized command.");
- elsif INPUT.LEN > 0 then
- GET_LEADING_INTEGER(LINE_NUM);
- if LINE_NUM not in 1 .. MAX_LINE_NUMBER then
- PUT_LINE("Illegal line number.");
- else
- ADD_DELETE_REPLACE_LINE;
- end if;
- end if;
- exception
- when NUMERIC_ERROR | CONSTRAINT_ERROR =>
- PUT_LINE("Line number too large.");
- end DO_COMMAND;
-
-
- -- continued --
-
- Page 31
-
- separate (LEDIT.DO_COMMAND)
- procedure ADD_DELETE_REPLACE_LINE is
- INP : TEXT := INPUT;
- begin
- if INP.LEN > 0 and INP.VAL(1) = ' ' then -- Treat "9x" like "9 x".
- DELETE_FIRST_CHARACTER(INP);
- end if;
- TEMP := HEAD; -- Find where this number belongs in linked list.
- while TEMP /= null and then TEMP.NEXT /= null and then
- TEMP.NEXT.NUM <= LINE_NUM loop
- if TEMP.NEXT.NUM = LINE_NUM then
- TEMP.NEXT := TEMP.NEXT.NEXT; -- Delete line.
- else
- TEMP := TEMP.NEXT; -- Advance to next link in list.
- end if;
- end loop;
- if INPUT.LEN > 0 then -- Add line.
- TEMP.NEXT := new LINK'(LINE_NUM, INP, TEMP.NEXT);
- end if;
- end ADD_DELETE_REPLACE_LINE;
-
- separate (LEDIT.DO_COMMAND)
- procedure DELETE_FIRST_CHARACTER(T : in out TEXT) is
- begin
- T.VAL(1 .. T.LEN - 1) := T.VAL(2 .. T.LEN);
- T.LEN := T.LEN - 1;
- end DELETE_FIRST_CHARACTER;
-
- separate (LEDIT.DO_COMMAND)
- procedure GET_LEADING_INTEGER(N : out NATURAL) is
- ANS: INTEGER := 0;
- begin
- while INPUT.LEN > 0 and INPUT.VAL(1) in '0' .. '9' loop
- ANS := ANS*10 + CHARACTER'POS(INPUT.VAL(1)) -CHARACTER'POS('0');
- DELETE_FIRST_CHARACTER(INPUT);
- end loop;
- N := ANS;
- end GET_LEADING_INTEGER;
-
- separate (LEDIT.DO_COMMAND)
- procedure STRIP_LEADING_SPACES_FROM_INPUT is
- begin
- while INPUT.LEN > 0 and INPUT.VAL(1) = ' ' loop
- DELETE_FIRST_CHARACTER(INPUT);
- end loop;
- end STRIP_LEADING_SPACES_FROM_INPUT;
-
-
- -- continued --
-
- Page 32
-
- separate (LEDIT.DO_COMMAND)
- procedure LIST is
- package IIO is new INTEGER_IO(INTEGER); use IIO;
- START, FINISH : NATURAL;
- VALID : BOOLEAN := TRUE;
- begin
- INPUT.LEN := INPUT.LEN - 4; -- Delete the name of the command.
- INPUT.VAL(1 .. INPUT.LEN) := INPUT.VAL(5 .. INPUT.LEN + 4);
- STRIP_LEADING_SPACES_FROM_INPUT;
- if INPUT.LEN = 0 then -- For "LIST" alone, list all lines.
- START := 0;
- FINISH := MAX_LINE_NUMBER + 1;
- else
- GET_LEADING_INTEGER(START); -- Get number after "LIST".
- STRIP_LEADING_SPACES_FROM_INPUT;
- if INPUT.LEN = 0 then -- For "LIST n", list only line n.
- FINISH := START;
- elsif INPUT.VAL(1) /= '-' then -- Else "-" must follow n.
- VALID := FALSE;
- else
- DELETE_FIRST_CHARACTER(INPUT); -- Delete the "-".
- STRIP_LEADING_SPACES_FROM_INPUT;
- GET_LEADING_INTEGER(FINISH); -- Get number after "-".
- STRIP_LEADING_SPACES_FROM_INPUT;
- if FINISH = 0 and START = 0 then -- "LIST -" isn't valid.
- VALID := FALSE;
- elsif FINISH = 0 then -- For "LIST n -", list n through end.
- FINISH := MAX_LINE_NUMBER + 1;
- end if;
- VALID := VALID and INPUT.LEN = 0; -- No trailing garbage.
- end if;
- end if;
- if not VALID then
- PUT_LINE("Illegal syntax for LIST.");
- else
- TEMP := HEAD.NEXT; -- Skip unused link at start of linked list.
- while TEMP /= null and then TEMP.NUM <= FINISH loop
- if TEMP.NUM >= START then
- PUT(TEMP.NUM, WIDTH => 5); -- Display line #, width 5.
- PUT_LINE(' ' & STR(TEMP.LINE)); -- Display text of line.
- end if;
- TEMP := TEMP.NEXT; -- Get next link.
- end loop;
- end if;
- exception
- when NUMERIC_ERROR | CONSTRAINT_ERROR =>
- PUT_LINE("Line number too large in LIST.");
- end LIST;
-
- Page 33
-
- TASKING.DUM
- -----------
-
- with text_io, calendar; use text_io, calendar;
- procedure tasking is
- interval : constant duration := 5.0;
- total_intervals : constant positive := 9;
- start_time : constant time := clock;
- quitting_time : constant time := start_time +
- total_intervals*interval;
- next_time : time := start_time;
- task type tick is
- entry make_noise;
- entry shutdown;
- end tick;
- t : tick;
- task body tick is
- quit : boolean := false;
- begin
- while not quit loop
- select
- accept make_noise do
- put_line("Tick!");
- end make_noise;
- or
- accept shutdown;
- quit := true;
- end select;
- end loop;
- end tick;
- begin
- while next_time < quitting_time loop
- t.make_noise;
- next_time := next_time + interval;
- put_line("(5-second delay)"); delay next_time - clock;
- end loop;
- t.shutdown;
- end tasking;
-
- Page 34
-
- STEPS FOR OUTSIDE ASSIGNMENT 6, EXERCISE IN TASKING
-
- 1. Make a copy of TASKING.DUM by typing COPY TASKING.DUM TASKING.ADA.
- Compile, link, and execute the program to make sure it displays
- "Tick!" nine times, with a 5-second delay after each "Tick."
-
- 2. Edit TASKING.ADA to become your solution. Make your changes in
- upper case.
-
- 3. Compile TASKING.ADA, link, and execute.
-
- 4. Compare your output with page 35 of these notes. If there are any
- errors, go back to step 2.
-
- 5. When your output agrees with these notes, you've finished the
- assignment and will have a chance to compare your solution with
- ours.
-
- Page 35
-
- OUTPUT FROM TASKING.EXE AFTER MODIFICATION OF TASKING.ADA
-
- C>tasking
- Task number 1 is starting.
- Task number 2 is starting.
- Task number 3 is starting.
- (5-second delay)
- (5-second delay)
- Task number 1 is starting.
- (5-second delay)
- Task number 2 is starting.
- (5-second delay)
- Task number 1 is starting.
- Task number 3 is starting.
- (5-second delay)
- (5-second delay)
- Task number 1 is starting.
- Task number 2 is starting.
- (5-second delay)
- (5-second delay)
- Task number 1 is starting.
- Task number 3 is starting.
- (5-second delay)
-
- C>
-
- Page 36
-
- TASKING.ANS
- -----------
-
- -- Our solution to Outside Assignment 6:
- with text_io, calendar; use text_io, calendar;
- procedure tasking is
- interval : constant duration := 5.0;
- total_intervals : constant positive := 9;
- start_time : constant time := clock;
- quitting_time : constant time := start_time +
- total_intervals*interval;
- next_time : time := start_time;
- task type tick is
- ENTRY IDENTIFY(TASK_NUMBER : IN NATURAL);
- entry shutdown;
- end tick;
- T : ARRAY(1 .. 3) OF TICK;
- PERIOD : CONSTANT ARRAY(T'RANGE) OF POSITIVE := (2, 3, 4);
- TIMER : ARRAY(T'RANGE) OF NATURAL := (OTHERS => 0);
- task body tick is
- quit : boolean := false;
- begin
- while not quit loop
- select
- ACCEPT IDENTIFY(TASK_NUMBER : IN NATURAL) DO
- PUT_LINE("Task number" & INTEGER'IMAGE(TASK_NUMBER) &
- " is starting.");
- END IDENTIFY;
- or
- accept shutdown;
- quit := true;
- end select;
- end loop;
- end tick;
- begin
- while next_time < quitting_time loop
- FOR I IN T'RANGE LOOP
- IF TIMER(I) = 0 THEN
- T(I).IDENTIFY(I);
- TIMER(I) := PERIOD(I);
- END IF;
- TIMER(I) := TIMER(I) - 1;
- END LOOP;
- next_time := next_time + interval;
- put_line("(5-second delay)"); delay next_time - clock;
- end loop;
- FOR I IN T'RANGE LOOP
- T(I).SHUTDOWN;
- END LOOP;
- end tasking;
-
- Page 37
-
- APPENDIX A: WOULD YOU LIKE A TEXTBOOK TO USE ALONG WITH ADA-TUTR?
-
- ADA-TUTR doesn't require a textbook, but a number of users have asked
- us to recommend a book that would go well with this course. We made a
- special arrangement with John Wiley and Sons so that you can buy the
- excellent textbook RENDEZVOUS WITH ADA by David Naiditch for only
- $42.95 plus sales tax. Simply print the file COUPON.TXT, or copy the
- coupon below. Please send it to the address on the coupon, not to
- Software Innovations Technology.
-
- +--------------------------------------------------------------------+
- | |
- | If you would like to have a textbook to go along with ADA-TUTR, |
- | send this coupon to |
- | |
- | Attn.: Diane Dooley, 4th floor |
- | Wiley - Training Sales |
- | John Wiley and Sons |
- | 605 Third Avenue |
- | New York, NY 10158 |
- | |
- | Please send me ______ copy(ies) of RENDEZVOUS WITH ADA by David |
- | Naiditch, to examine for 15 days. |
- | |
- | Order #: 1-61654-0. Price: $42.95 plus local sales tax, postage |
- | and handling. |
- | |
- | [ ] Bill me. |
- | |
- | [ ] Payment enclosed. (Orders accompanied by payment will be |
- | sent postpaid.) |
- | |
- | [ ] Charge my ___ VISA ___ MasterCard ___ American Express |
- | (Note: Credit card orders are not considered prepayment.) |
- | |
- | Account #: ________________________________ |
- | |
- | Expiration Date: __________________________ |
- | |
- | NAME:____________________________ AFFILIATION:____________________ |
- | |
- | ADDRESS:__________________________________________________________ |
- | |
- | CITY/STATE/ZIP:_____________________ SIGNATURE:___________________ |
- | (Offer invalid without signature) |
- | |
- | (Prices subject to change without notice and higher outside the |
- | U.S.A.) |
- | |
- +--------------------------------------------------------------------+
-
- Page 38
-
- APPENDIX B: RUNNING BOOK TO PRINT ALL THE SCREENS
-
- If you're running ADA-TUTR on a PC, you can always print the screen
- that's currently being displayed by holding a Shift key while pressing
- the PrtSc key.
-
- However, several users wanted to be able to print ALL the screens in
- the entire course, as one large book. So, starting with version 2.0
- of ADA-TUTR, we added the program BOOK. This program reads the file
- ADA_TUTR.DAT and produces two large output files, which can then be
- printed. Be prepared to print almost 500 pages!
-
- Simply type BOOK to run the program. BOOK first asks you if you'll be
- using PC-Write to print the files. (See page 42 for information about
- PC-Write.)
-
- If you answer Y, BOOK will put PC-Write "boldface" commands in the
- output files. Thus the text will print in boldface wherever you see
- emphasized text on the screen.
-
-
- However, if you answer N, BOOK will create plain ASCII files, double
- ------
- spaced the way this paragraph is double spaced. It will emphasize
- ------ ------------- ---------
- text by placing hyphens below the lines like this.
- ------- ---------
-
- Next, BOOK will ask you for the name of the output file for the first
- half of the tutorial. After that file is written, BOOK will ask for
- the name of the output file for the second half of the tutorial. You
- can then print the output files.
-
- If you're not using PC-Write, you can optionally specify the name PRN
- for both output files, and the output of BOOK will go directly to the
- printer.
-
- Begin reading your printed output with Screen 104. Note that, at the
- bottom of each page, there's a list of possible user responses with
- screen numbers. For example, at the bottom of Screen 104 you will see
-
- 'Y' 107 'N' 120
-
- This means that, if the user presses Y, he will next see Screen 107,
- and if the user presses N, he will next see Screen 120. Pressing X
- always takes the user to Screen 103. The special "screen numbers" 098
- through 100 appearing at the bottom of Screens 107 and 108 are
- explained in the introductory comments in ADA_TUTR.ADA.
-
- BOOK, like ADA-TUTR, will run on a PC or on any Ada-speaking computer.
-
- Page 39
-
- APPENDIX C: SOME ADA COMPILERS AVAILABLE FOR THE PC
-
- Here's a brief list of Ada compilers available for the IBM PC and
- compatibles. For this course, an Ada compiler is helpful, but not
- required. There are six Outside Assignments; most of them ask you to
- write and compile a short Ada program. If you don't have access to an
- Ada compiler, just skip the Outside Assignments.
-
- Although we may now have a small financial interest in some of the
- companies mentioned here (see page 5), we try to keep this list
- unbiased. If you know of an Ada compiler for the PC that should be on
- this list, or if you have any updated information or corrections,
- please contact us.
-
- 1. At the low end of the scale is Augusta. This compiler is in the
- public domain, and can be found on many computer bulletin boards.
- It's a very small subset of Ada with no packages. It translates
- Ada to a P-code, and then interprets the P-code. Some of the
- syntax is non-standard, such as "elseif" where Ada uses "elsif."
- Older versions of Augusta require Turbo Pascal. Augusta isn't
- really adequate for most of the Outside Assignments of ADA-TUTR.
-
- 2. Janus/Ada is sold by R R Software, Inc., Box 1512, Madison, WI
- 53701, phone 800-722-3248, starting at $129. Educational
- discounts are available. A complete development system with tools
- (such as a debugger) and utility packages is available for $500,
- but it requires an 80386 computer. Janus/Ada is validated and
- produces native PC code; no interpreter is required.
-
- 3. Open Ada is sold by Meridian Software Systems, Inc., 10 Pasteur
- St., Irvine, CA 92718, phone 800-221-2522 (in CA, 714-727-0700),
- for $199 ($99 for students). Open Ada includes tools (such as a
- debugger) and utility packages. It's validated and produces
- native PC code; no interpreter is required.
-
- 4. IntegrAda is sold by Aetech, Inc., 5841 Edison Place, Suite 110,
- Carlsbad, CA 92008, phone 619-431-7714, for $395. Students can
- obtain the IntegrAda Student Package, which includes IntegrAda and
- learning tools, for $149. IntegrAda includes CASE (Computer-Aided
- Software Engineering) tools and utility packages. It's validated
- and produces native PC code; no interpreter is required.
-
- 5. At the high end of the scale is FirstAda, sold by Alsys, Inc., 67
- South Bedford St., Burlington, MA 01803-9748, phone 617-270-0030.
- The price is $595. FirstAda is validated and requires a PC/AT (or
- compatible) with at least 2 MB of extended memory. However, it
- can produce native code for the PC/XT; no interpreter is required.
-
- Page 40
-
- APPENDIX D: SAMPLE MULTI-USER SOFTWARE LICENSE
-
- Software Innovations Technology believes in a plain-English software
- license that people can understand. A sample license appears on the
- next page. However, if your company's lawyers would prefer a
- differently worded license, simply contact us. We'll be happy to
- accommodate you.
-
- As you can see, the terms of our license are very generous. We allow
- you to make as many copies of ADA-TUTR as you like, and to install it
- on as many computers as you like, regardless of the computer type
- (laptop, desktop, workstation, mainframe, etc.) Also, you may use
- ADA-TUTR at all your geographical locations, which is why we use the
- term Multi-User License rather than Site License. The only thing we
- limit is the total number of people who may use ADA-TUTR (except in
- the case of an unlimited license). Please remember that if 100 people
- use ADA-TUTR now and 100 others use it later, that counts as 200
- users, not 100.
-
- In the sample license on the next page, comments appear in brackets.
- These comments are not part of the actual license.
-
- Page 41
-
- [SAMPLE] MULTI-USER SOFTWARE LICENSE
-
- Software Innovations Technology
- 1083 Mandarin Drive NE
- Palm Bay, FL 32905-4706
- (407) 951-0233
-
-
- This license conveys to XYZ Company the right to use the comput-
- er program ADA-TUTR, the Interactive Ada Tutor, under the fol-
- lowing conditions:
-
- 1. The program shall remain the property of Software Innova-
- tions Technology.
-
- 2. The program may be freely copied and installed on any or all
- computers of XYZ Company, regardless of geographical location.
- Copies of the program may be distributed outside XYZ Company for
- others to evaluate on a trial basis.
-
- 3. This license is perpetual.
-
- 4. The number of XYZ Company personnel [or "students and per-
- sonnel of XYZ University"] who may use the program is unlimited.
- [*** OR ***]
- 4. The total number of XYZ Company personnel [or "students and
- personnel of XYZ University"] who use the program, excluding
- those who only briefly evaluate it, shall not exceed two thou-
- sand (2000) [or "five hundred (500)" or "one hundred (100)"].
- In calculating the number of users, XYZ Company must always add
- the number of people currently using the program to the number
- who have used it in the past.
-
- 5. [This paragraph is omitted in unlimited licenses.] Software
- Innovations Technology sells licenses for larger numbers of
- users. XYZ Company may, at any time, upgrade this license for a
- larger number of users by paying, to Software Innovations Tech-
- nology, the difference in price between the two licenses.
-
- 6. This license is not transferable.
-
- 7. The Disclaimer of Warranty, included in the program documen-
- tation, applies as if included in this license.
-
- 8. [This paragraph is omitted if the order is prepaid.] This
- license shall be void if the invoice is not paid within thirty
- (30) days of the date of this license.
-
-
- (Signed)________________________________ Date _________________
-
- John J. Herro, President
- Software Innovations Technology
-
- Page 42
-
- APPENDIX E: DO YOU NEED A SCREEN EDITOR / WORD PROCESSOR?
-
- The Outside Assignments will be much easier if you have a good screen
- editor. We've looked at many, and found PC-Write Advanced Level, a
- Shareware program by Quicksoft of Seattle, WA to be the best screen
- editor as well as word processor. There's lots of on-line help, and
- the 50000-word spelling checker can be turned on for editing letters
- and documents, and off for editing source code. We liked the idea of
- having to learn only ONE program for both kinds of editing! Unlike
- ADA-TUTR, PC-Write Advanced Level runs only on PCs and compatibles,
- not on mainframes, etc.
-
- We have no connection with Quicksoft, except for being a registered
- user of PC-Write Advanced Level. However, we'll be happy to send you
- a free copy of the latest version of that excellent program, if you
- send us four blank, formatted, 360K 5.25" diskettes or two 720K 3.5"
- diskettes, and a stamped, addressed diskette mailer. Or send us $20
- for four 5.25" diskettes or two 3.5" diskettes. The diskettes or fee
- covers only our expenses; you must register your copy of PC-Write with
- Quicksoft if you use it after a free trial. We're sorry, but we're
- allowed to send copies of PC-Write only to the U.S., Canada, the
- United Kingdom, Australia, and New Zealand.
-
- If you use PC-Write Advanced Level to edit Ada programs, you may find
- the file ED.ADA, included with ADA-TUTR, to be helpful. It allows
- typing many Ada reserved words with a single keystroke. For example,
- you can type "procedure" by striking Ctrl-P. See the file ED.ADA for
- more details. PC-Write Advanced Level will automatically invoke
- ED.ADA whenever you edit a file with the extension .ADA.
-
- Page 43
-
- APPENDIX F: INSTALLING ADA-TUTR ON OTHER COMPUTERS
-
- Because source code is included with ADA-TUTR, you can install
- ADA-TUTR on almost any computer that has an Ada compiler - from
- compact units to large mainframes. ADA-TUTR is written in Ada (of
- course!), and Ada programs tend to be very portable.
-
- The screen should have at least 24 rows of 80 characters each, and
- should support the ANSI escape sequences for highlighting, reverse
- video, cursor positioning, etc. Almost all computers qualify.
-
- You need a way to send text files from your PC to the other computer.
- Files are usually sent to large mainframes with the program KERMIT,
- which is in the public domain. One version of KERMIT runs on the PC,
- another on the mainframe. The two communicate with each other.
- Sometimes XMODEM or another protocol is used instead of KERMIT.
-
- If a communications program is available on the PC but not on the
- other computer, you can still send text files, but not as efficiently.
- Connect your PC as a terminal and tell the other computer to copy the
- keyboard to a new file. For example, on a VAX computer running VMS,
- the command is "COPY TT: filename.ext" (without the quotes). Then
- tell your communications program to send (or "upload") the file, using
- ASCII protocol, and stripping line feeds. After the file is sent,
- type the appropriate end-of-file character for the other computer. On
- a VAX running VMS, you would type Control-Z. Since this method of
- file transfer doesn't do error checking, you may have to send each
- file twice using two different names, and compare the two files with
- each other on the other computer. It's far better to use a
- communications program on the other computer, if one is available.
-
- OK, you have some means of sending text files. You won't have to send
- other kinds of files. To install ADA-TUTR on the other computer, just
- follow these steps:
-
- 1. Type DAT2TXT on the PC. This will read the file ADA_TUTR.DAT,
- which is not a text file, and create a new text file TUTOR.TXT, which
- can be sent to the other computer. DAT2TXT will probably take several
- minutes to run. Don't try to bypass this step even if you're able to
- send non-text files. It's important that you send TUTOR.TXT and not
- ADA_TUTR.DAT, because the PC version of ADA_TUTR.DAT doesn't work on
- some systems.
-
- 2. Decide where ADA-TUTR will reside on the other computer, so that
- it will be available to all users. For example, on a VAX computer
- running VMS, the tutor is usually placed in SYS$INSTRUCTION. It could
- also be placed in SYS$MANAGER, etc.
-
- -- continued --
-
- Page 44
-
- 3. Send to the other computer all the files that come with ADA-TUTR,
- except ADA_TUTR.DAT and the files ending in .EXE. Be sure to send
- TUTOR.TXT, created in step 1. Don't try to send ADA_TUTR.DAT and the
- .EXE files, because they're not text files. Also note that ADA-TUTR
- creates a file ADA_TUTR.USR the first time it's run. Do NOT send that
- file, because it also is not a text file. If our file names are
- illegal on the other system, you'll have to rename them as they're
- sent. (We haven't seen a system where our file names are illegal.)
-
- 4. If any of the file names ADA_TUTR.DAT, ADA_TUTR.USR, or TUTOR.TXT
- are illegal on your system, edit the files ADA_TUTR.ADA, BOOK.ADA,
- CHANGESN.ADA, and TXT2DAT.ADA to show new, legal file names. Search
- for the old file names and replace them with the new ones.
-
- 5. Note that each user will probably run ADA-TUTR from his own file
- directory. There will be a file ADA_TUTR.USR in each user's
- directory, but all the other files will reside in a common area, such
- as SYS$INSTRUCTION, etc. Therefore, edit the files ADA_TUTR.ADA,
- BOOK.ADA, CHANGESN.ADA, and TXT2DAT.ADA to show the full path name of
- the file ADA_TUTR.DAT. On a VAX system, for example, you might search
- for the name ADA_TUTR.DAT and replace it with
- SYS$INSTRUCTION:ADA_TUTR.DAT.
-
- 6. On one system we encountered, Ada source file names must end in .a
- rather than .ADA. If that's the case on your system, rename all the
- .ADA files.
-
- 7. On the other computer, compile, link, and run TXT2DAT.ADA. Some
- systems call the linking step "binding." This program will read
- TUTOR.TXT and create ADA_TUTR.DAT on the other system. If you wish,
- you may then delete TUTOR.TXT.
-
- 8. If you're using VAX Ada, skip to page 46. If you're using a UNIX
- based system that has a C compiler with the ability to link into Ada
- programs, skip to page 47. Otherwise, continue with the next page.
- If you're not certain, continue with the next page.
-
- -- continued --
-
- Page 45
-
-
- 9. Compile VANILLA.ADA, but don't try to link or run it. This "plain
- vanilla" file will work with any standard Ada compiler.
-
- 10. Compile ADA_TUTR.ADA.
-
- 11. Link, giving the name of the main program, ADA_TUTR. This will
- produce an executable file, which on most systems will be called
- ADA_TUTR.EXE. However, on a few systems the executable file will have
- a strange name, so rename the executable file if necessary.
-
- 12. Run ADA-TUTR. The command is usually ADA_TUTR or RUN ADA_TUTR.
- Note that, on some systems, you'll have to strike ENTER (or RETURN or
- NEW-LINE) after each response, even though the program says, "You need
- not hit ENTER." The reason is that some systems require you to strike
- ENTER when they read the keyboard through TEXT_IO. However, with
- recent versions of TeleGen Ada, you don't have to hit ENTER. Also
- note that some of the tutorial text refers to commands that are meant
- for a PC, such as COPY and PRINT. These commands may have to be
- varied slightly to work on your system.
-
- 13. Define a command so that each user will be able to run ADA-TUTR
- easily.
-
-
- We'll be happy to help you install ADA-TUTR and get it running, even
- if you haven't registered or bought a license. We want you to try
- ADA-TUTR before paying for it.
-
- Page 46
-
- SPECIAL INSTRUCTIONS FOR VAX ADA
-
- 9. If you're using VAX Ada, compile VAX.ADA, but don't try to link or
- run it. The file VANILLA.ADA would work, but VAX.ADA makes it
- unnecessary to strike RETURN after each response. The reason is that
- VAX.ADA gets characters from the keyboard by calling the System
- Service routines, without going through TEXT_IO.
-
- 10. Compile ADA_TUTR.ADA.
-
- 11. Link, giving the name of the main program, ADA_TUTR. The command
- is ACS LINK ADA_TUTR. This will produce an executable file,
- ADA_TUTR.EXE.
-
- 12. Run ADA-TUTR by typing RUN ADA_TUTR. Note that some of the
- tutorial text refers to commands that are meant for a PC, such as COPY
- and PRINT. These commands may have to be varied slightly to work on
- your system. For example, when the text says to type
- COPY TRITYPE.DUM TRITYPE.ADA, your users might have to type
- COPY SYS$INSTRUCTION:TRITYPE.DUM TRITYPE.ADA.
-
- 13. Define a command so that each user will be able to run ADA-TUTR
- easily. For example, you might add the following line to SYLOGIN.COM:
-
- $ TEACHADA :== "RUN SYS$INSTRUCTION:ADA_TUTR"
-
-
- We'll be happy to help you install ADA-TUTR and get it running, even
- if you haven't registered or bought a license. We want you to try
- ADA-TUTR before paying for it.
-
- Page 47
-
- SPECIAL INSTRUCTIONS FOR UNIX BASED SYSTEMS
-
- 9. If you're using a UNIX based system with a C compiler, and your
- Ada compiler can link with modules produced by C, compile ONECHAR.C
- with the C compiler. If you can't compile ONECHAR.C because your
- system doesn't have the include file TERMIO.H, then compile ALTCHAR.C
- instead. However, if you compile ALTCHAR.C, you'll have to invoke
- ADA-TUTR between two calls to stty, in a script file. For example:
- stty raw
- /usr/local/ada-tutr/ada_tutr
- stty -raw
-
- 10. Compile UNIX.ADA, but don't try to link or run it. The file
- VANILLA.ADA would work, but UNIX.ADA, when used with ONECHAR.C or
- ALTCHAR.C, makes it unnecessary to strike RETURN after each response.
- The reason is that ONECHAR.C and ALTCHAR.C get characters directly
- from the keyboard, without going through TEXT_IO.
-
- 11. Compile ADA_TUTR.ADA.
-
- 12. Link, giving the name of the main program, ADA_TUTR. Include the
- object file from the C compiler in the link. This will create an
- executable file, called ADA_TUTR on most systems. (On one system we
- encountered, the file created was named a.out.) If necessary, rename
- the executable file to an appropriate name, such as ada_tutr or
- ADA_TUTR or ADA_TUTR.EXE.
-
-
- Here are sample steps 9 through 12 for two UNIX based systems:
-
- ON A UNISYS 5000/80: ON A HARRIS HCX:
-
- cc -c onechar.c cc -c onechar.c
- ada unix.ada ada_tutr.ada ada unix.a ada_tutr.a
- ald -p'onechar' ada_tutr a.ld ada_tutr onechar.o
- mv a.out ada_tutr
-
-
- 13. Run ADA-TUTR. Usually this is done by typing ada_tutr. Note
- that some of the tutorial text refers to commands that are meant for a
- PC, such as COPY and PRINT. These commands may have to be varied
- slightly to work on your system.
-
- 14. Define a command so that each user will be able to run ADA-TUTR
- easily.
-
-
- We'll be happy to help you install ADA-TUTR and get it running, even
- if you haven't registered or bought a license. We want you to try
- ADA-TUTR before paying for it.
-
- Page 48
-
- APPENDIX G: WE LISTEN! NEW FEATURES OF ADA-TUTR
-
- Almost all of the features added to ADA-TUTR were done as a result of
- your comments and suggestions. Thank you very much, and please
- continue to send them! We want to produce the very best Ada Tutor
- possible. Here's a history of revisions to ADA-TUTR. In addition to
- the changes shown here, we're constantly making minor improvements in
- the tutorial text and updating the list of Ada compilers available for
- the PC (page 39).
-
-
- VERSION 2.02:
-
- Added the files DESC.SDI and FILE_ID.DIZ, briefly describing ADA-TUTR.
-
- Improved ED.ADA to take advantage of the newest version PC-Write,
- called PC-Write Advanced Level.
-
-
- VERSION 2.01:
-
- Added the file JANUS.ADA.
-
-
- VERSION 2.00:
-
- Changed the ADA_TUTR.DAT file to a more compact format, so that
- ADA-TUTR would take less room on a hard disk and be able to run from a
- floppy diskette.
-
- Added the BOOK program to print all of the tutorial screens as a large
- book (page 38).
-
- Updated Outside Assignment 6 to make it easier to see where the
- 5-second intervals occur.
-
- Updated the list of Ada compilers available for the PC (page 39).
-
- Added the sample Multi-User License (pages 40-41).
-
- Added the special offer for a textbook (page 37).
-
-
- VERSION 1.22:
-
- Added ALTCHAR.C for UNIX based systems that don't have the file
- TERMIO.H. (Thank you, Mr. Richard Conn, 2700 Bowline Court,
- Maineville, OH 45039.)
-
- Page 49
-
- VERSION 1.21:
-
- Added ONECHAR.C so users of UNIX based systems wouldn't have to strike
- ENTER after each response. (Thank you, Mr. David Hill, 7549 Wynford
- Street, Salt Lake City, UT 84121.)
-
- Changed all hyphens in file names to underlines, at the request of
- PC-SIG, so that ADA-TUTR would be compatible with High Sierra Format
- CD-ROMs.
-
-
- VERSION 1.20:
-
- Added the ability to select background, foreground, and border colors
- on a PC without sacrificing compatibility with mainframe computers and
- monochrome PCs.
-
- Made ADA-TUTR automatically remember where you leave off when you exit
- the program, so that you don't have to write down the screen number.
- Also made ADA-TUTR remember your color choices.
-
- Made ADA-TUTR tell you the current screen number and the approximate
- percentage through the course when you strike X, and added the ability
- to go back to the last question or to the last Outside Assignment.
-
- Added a special screen at the start of each major section, showing an
- outline of the course.
-
- Updated the tutorial text to reflect the government's new policy
- regarding expiration of Validation Certificates.
-
- Updated the tutorial text to show that the newest Ada compilers now
- raise CONSTRAINT_ERROR where NUMERIC_ERROR was once raised.
-
- Added the offer for customized versions of ADA-TUTR, and for the
- Customization Kit (page 4).
-
- Recompiled ADA-TUTR using a validated compiler from Meridian Software
- Systems, Inc., instead of an older unvalidated compiler from Artek,
- Inc.
-
- Made ADA-TUTR available on 3.5" as well as 5.25" diskettes.
-
-
- VERSION 1.01:
-
- Fixed minor typographical errors in Version 1.00.
-
- Page 50
-
- APPENDIX H: DISCLAIMER OF WARRANTY
-
- We hate legal mumbo jumbo, but we have to say the following to protect
- ourselves:
-
- Software Innovations Technology makes no warranty of any kind,
- expressed or implied, including any warranties of merchantability or
- fitness for a particular purpose. We shall not be liable for any
- damages, whether direct, indirect, incidental, special, or
- consequential, arising from a failure of this program to operate in a
- manner desired by the user. We shall not be liable for any damage to
- data or property which may be caused directly or indirectly by use of
- this program. IN NO EVENT SHALL SOFTWARE INNOVATIONS TECHNOLOGY BE
- LIABLE FOR ANY DAMAGES, INCLUDING ANY LOST PROFITS, LOST SAVINGS, OR
- OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
- INABILITY TO USE THIS PROGRAM, OR FOR ANY CLAIM BY ANY OTHER PARTY.
-