The C.A.T.S Newsletter

See all articles from Update July 1990
Author(s): Timothy Swenson; Herb Schaaf; Mark Fisher
Publication: Update Magazine
Pub Details: Update July 1990
Date: July 1990
Pages: 10-12

The following three articles are re-printed from the CATS NEWSLETTER. To Join CATS and receive this nice newsletter, send $15.00 US Check or MO to: CATS Newsletter, PO Box 11017, Takoma Park, MD 20913. There are other benefits. _BJ-

The C Column

By Tim Swenson

As promised last month, I’ll talk about how C accesses files.

The simplest way to discuss how C handles files is to take a look at a C program that uses it. Look at program number 5. This program asks the user for a file name. It then opens the file, reads in a character and prints it out the screen. This goes on for the entire file.

The program declares a character array of size 20 to be hold the file name. It then declares the integer fd to hold the file ID. When a file is opened, C assigns a number to it. This number is returned from the fopen command to the variable fd.

Note the syntax of the fopen command. The file name is sent into the function along with a string that specifies if the file is for reading or writing. If we wanted to open a file to write to, we would have used “w” instead of “r”.

The next couple of lines checks to see if the file was opened sucessfully. If the file was not opened (there was some error like a bad file name) fd will be returned as NULL (a predefined constant).

Instead of using getch the function getc is used. Where getch defaults to the keyboard, getc needs a file ID to know where to get it’s input. In our case we use fd.

We exit the while loop when the program reaches the end of the file (EOF). After the program exits the while loop, we use the fclose function to close the file. We must tell fclose which file to close. If we do not close the file, we may loose the file.

/* prog 5 */
#include <stdio_h>

main() {
char file[20];
int c, fd;

printf("Enter file: ");
gets(file);

fd=fopen(file,"r");
if (fd == NULL) {
printf("File open Error");
abort(1);
}
while ((c=getc(fd))!=EOF) {
putchar(c);
}
fclose(fd);
}

QL Small-C Companion

By Tim Swenson

I have been using the Small-C compiler on the QL for some time now. I have found the documentation severly lacking. Knowing that other users are probably having the same problem, I decided to document the solutions to some of the problems I ran across. I also looked into other versions of Small-C for other computers. A copy of this document is available from the QL library. The library has a hard copy of the document and a Quill file. The hard copy was printed out using a laser printer and looks good. I’ve utilized multiple fonts to enchance it’s looks.

When looking at the CP/M version of Small-C, I found that the QL version did not come with all of the functions found in most Small-C compilers. I typed in the functions that I could convert and created a new library. I tested the library generator with this new library. The library is also available from the QL library. The functions are documented in the Companion documentation.


I’m all for computer dating, But I wouldn’t want one to marry my sister.

Additions to the QL Library

By Tim Swenson

Over the years I have written a number of usefull programs for the QL. Some of them I have used in articles for numerous newsletters. I have donated them to the club’s QL library. I thought I would let users know about the more interesting and usefull.

Lister – This program reads in a SuperBasic, Pascal, or C program (actually any text file will work). It prints the program to the printer with page breaks and the file name at the top of each page. It even has options for NLQ, bold, etc, type print. It is set up for an Epson compatable printer.

QLcryptII – This programs reads in any file and encrypts it. The user enters a password that controls how the file is encrypted and decrypted. The output file may look like garbage, but when decrypted the original file is returned. Even works on executable files. It is very secure.

Calc – This is a small calculator program that works in decimal, hexidecimal, and binary. Lets you add any of the three bases and convert between them. Easy way to convert between bases. If compiled, it can be a nice pop up type calculator.

Maillist – A menu driven Archive program for maintaining a mailing list. User can add, edit, delete, and print entries. Has a nice data entry screen.

All of the programs have a Quill file that describes the programs fully. All of the documentation is 1 to 5 pages long. Maillist has longer documentation. Be aware that the software has my old address in California. I’ve been too lazy to update them.

See Tom Robbins for getting copies of the QL Public Domain library.

More On Benchmarks

By Herb Schaaf

Duane Parker had the time down to 23 seconds using Forth in his January classic on benchmarking with Pascal, QL-SuperBasic, etc.

The Small-C QL combo does it in 16 seconds( 14 with Lightning installed). An IBM PS/2-30 and the same (well, nearly the same) source code using Turbo-C took 6 seconds. Mix-C & IBM did it in 5. A Toshiba T5200/100 & Turbo-C took 2 seconds.

When ported over to the VAX-3650 and timed it came back as 0.0 seconds, so I extended the run down to 1; then it took 0.2 seconds. Times to go down to 1 are:

Turbo-C & T5200        22 secs.
Mix-C & IBM            42
Turbo-C & IBM          55
Small-C & QL          155
with QL &
   Conqueror Mix-C   1390
   Turbo-C           2070

Now as to costs:

Hardware----
  QL systems $$ hundreds
  IBM systems $ thousands
  T5200 $ ten thousand
  VAX $$hundreds of Thousands

Software----
  Small-C $ 1 (cost of disk)
  Mix-C  $ 20 (BEST BUY!!)
  Turbo-C $ 100 (discount)
  UNIX C $ a lot more
/*  dpbench7_c      May 13 1990  10:30am
** Small-C benchmark program by Duane H. Parker
** Ref: CATS Newsletter Jan 1990 pages 6-8.
*/

#include <stdio_h> /* standard input/output header */
#define MAX 32767 /* limit of signed integers */

main()
{
char c, string[20]; /* characters and/or strings */
int start, stop, index, i, j; /* handy integer values */
int testfactor, tfsq; /* testfactor and its square */
int secs, d1[2], d2[2]; /* used in timing */
int minval, pos; /* more integers */
minval = 0;
pos = (MAX/100);
testfactor = 181; /* int(sqrt(MAX)) */
tfsq = 32761;
while( ((minval>0) + (minval<MAX) + (index == 1)) != 3)
{
stop = 0; /* initializing for clean start */
index = 1;
start = 1;
cls(2);
printf("This is a Small-C programn");
printf("of a benchmark test by DH Parkern");
printf("see CATS Newsletter of January 1990n");
printf("nStop calculation at what value less than %d ?n",MAX);
gets(string); /* when to stop ? */
j = strlen(string);
strncpy(c,string,1);
start = atoi(c); /* makes string into integer */
for(i=0 ; i<j; i++) /* checks for correct input */
{
c = string[i];
stop = isdigit(string[i]); /* is it a digit ? */
index = stop * index;
}
minval = atoi(string);
if( j>5 ) /* are there too many digits ? */
{
index = 0;
}
if((j == 5) && (index == 1) && (start>3) )
{
index = 0;
}
if((minval>=MAX) || (minval<1) || (index == 0))
{
printf("nnI N V A L I D ! !"); /* error trapping */
printf("nnany key to try againn q to quit");
c = getchar();
switch (c)
{
case 'q' : xcit(); /* 'fancy' exit */
}
}
}
cls(stdout); /* clear screen */
printf("Ready to find primes from 32767 to %dn",minval);
printf("any key to beginn"); /* inform and wait for */
getchar(); /* trigger */
{
/* start clock */
*d1 = date(); /* starting time */

for(index = MAX; index >= minval ; index -= 2)
{
while ((pos*100)> index) /* make newline to */
{ /* group by 100's */
--pos;
printf("n");
}
while( index < tfsq ) /* reduce tfsq and */
{ /* testfactor when */

for( j = 0; j < 4 ; j++) /* possible */
{
tfsq -= testfactor;
tfsq++;
}
testfactor -= 2;
}
if(testfactor == 1 && index != 1 )
{ /* small primes */
printf("%6d",index);
}
for( j=3; ( j <= testfactor ); j += 2 )
{
if((index % j)==0) /* not prime */
break;
if(j >= testfactor) /* is prime */
printf("%6d",index);
}
}
if(minval < 3) /* to catch 2, */
{ /* the even prime */
printf("%6d",2);
}
}
*d2 = date(); /* checks time of finish */
secs = d2[1] -d1[1]; /* simple difference */
printf("nRuntime = %d seconds in Small-Cn",secs);
printf("nany key to exit");
getchar();
xcit();
}
xcit() /* a fancy (?) way to exit */
{ /* a function is like a defined procedure */
mode(8);
cls(2);
at(stdout,1,3);
ink(stdout,1);
printf("It's been good to");
csize(stdout,3,1);
at(stdout,3,11);
ink(stdout,2);
flash(stdout,1);
printf("'C'");
flash(stdout,0);
csize(stdout,0,0);
at(stdout,12,15);
ink(stdout,4);
printf("you");
at (stdout,17,5);
flash(stdout,1);
ink(stdout,6);
printf("any key to exit . . ._");
getchar();
mode(4);
flash(stdout,0);
exit(2);
}
/* The end of the small-c source code for dpbench7_c May 13, 1990 11am */

Dealing With The BBS

By Mark Fisher

GETTING ON THE AIR

What you’ll need:

This will take your computer, a terminal program, and a MODEM. For the 2068, the most common setup is the 2050 (Anchor) MODEM, along with SmartTerm II. For the QL, the horizon is wider – any “external” MODEM will work at 1200 BAUD. For terminal programs, again, the choice is wider, with QL Term, QLink, QL-52 being the main contenders. (If you want 300 BAUD compatibility, you’ll have to do more work; i.e. the Modaptor and QCode software)

Now you’ll have to connect the pieces:

2068 — Plug the 2050 into the expansion bus in the back of the computer, and plug its adapter into the wall.

QL — Get a connecting cable to bridge the gap between the DB9 connector on the QL and the DB25 on the MODEM.

Using the software:

Load the software. If you have the SmartTerm II cartridge, that’s already happened by the time you see the first screen. QL programs are nearly that simple.

Terminal programs must make a distinction between input that controls the operation of the program, and input that is intended to be sent out the port of your computer. The usual way to describe these choices is the term “mode”. “Command mode” controls the operation of the terminal program itself, while “terminal mode” sends your input out the serial port. When you first get on, make sure your terminal program is saving everything to its buffer. This will let you review what happened after you disconnect. You may want to save the (I)nformation files as permanent references.

Depending on your particular setup, you may dial the BBS via your phone, or through the auto-dial option of your terminal program. Many external MODEM’s can be dialed by typing ATDP5880579 from terminal mode.

When you connect with the BBS, you will see a prompt to set the date (this is an addition I’ve made to get around the lack of a clock on our machine). If you get something wrong, you’ll be prompted again. Don’t worry; the computer has plenty of time, and you can go around as much as you like. Next, you will be asked for your name. If I’ve guessed the spelling of your name correctly, you’ll be asked for the password. The default password is VERNON, but you should change that as soon as possible. (To encourage you to do so, I’ve also set your message reading width to 20. You can change both preset values from the (U)pdate record menu choice.)

EXPLORING

Once you get past this, you’ll be IN the CATS BBS. There are no time limits here. The BBS will not penalize you for making a mistake. The worst thing that can happen is that you’ll have to ‘unplug’ your computer. The BBS will detect this, and re-set itself for the next caller.

If you think of the BBS as a house, there are three main wings. They are the Main menu, the Mail menu, and the files system. Entry into each is heralded by a specific phrase. You can think of each phrase as being carved over the entrance to the wing (one of the weaknesses of this metaphor is that the actual location of the phrase will be in the bottom left corner of your screen, not top center).

The Main Menu Wing:

“Over the Door”, you’ll see:

PBBS Menu, Commands are ….

This is the general purpose section of the BBS. Here, you’ll find out about general (I)nformation, recent uploads, other users, and your personal customization values. You can also do some basic chores, such as toggling the full display of the menu or the [more] prompt, (Y)akking with me, (J)umping to CPM, switching to the (M)ail menu, or saying (G)oodbye.

The Mail Menu Wing:

Over the door of this wing is :

Folder: General
MAIL Menu: Commands are ….

This wing offers ways to delve through the message base. The most basic are (E)nter a message and (R)ead one. In addition, you can scan the headers, either for a given subject, or a list of all subjects. As the message base grows, it will get harder to scan everything. To deal with this, the message base is divided into 9 FOLDERS. By switching between the folders, you can view all “FOR SALE” messages, all 2068 messages, etc.

There are sub-menus that appear as you go through the more complex operatons: for (E)nter, there is a menu that appears when you press <ENTER> twice. It offers you the option to (L)ist, (E)dit, or C)ontinue entering the message, or (S)ave the message as public or (P)rivate.

The CPM Attic:

Over the door is:

B3>

The last wing of the “PBBS house” is the files area. The rules here are different. You can think of it as the “attic” of the system, storing all those things you MIGHT use. There are no menus here – instead there are a number of discrete commands you can invoke. CPM interprets the word following the B3> prompt as the file name of a machine code program. There is room after the name for further data – see the examples below. When you are adding that extra data, separate it from the command with ONE SPACE. The most basic are:

“BYE” Hangs up the phone and resets the BBS for the next caller.

“PBBS” Returns to the Bulletin board program, so you can leave a message about what you found up in the CP M attic.

“D” This is the Directory command – producing an alpha sorted list of files.

“USER xx” This changes the user area (C PM’s sub-directory method)

“TYPE-DN (your filename here)” This will type to the screen the contents of the file you specify. If you have cleared your capture buffer and opened it, you will end up with a copy of the file you requested. If you use TYPE-DN on COM or DOC files you will see some interesting screen art, and possibly hang up your computer, but it won’t hurt the BBS.

“TYPE-UP (your filename here)” This program will create a new file on the BBS computer, and store whatever you send to it there. You can use your terminal program’s ASCII file transfer routines to send your ASCII files to the BBS. It will be closed when you send a control-Z, and after a few seconds, you’ll see the B3> again.

“XMODEM (your filename here)” The is the big gun of the files area. This program can work with the Xmodem part of your terminal program to transport ANY file to or from the BBS. Typing XMODEM alone will give you a short list of your options. To use it, type “XMODEM (your filename here)” at the B3> prompt. You will then enter command mode of your terminal program, and start up its xmodem file transfer procedure. The two programs will work together to shift the file between the machines. XMODEM knows that you will take a while to get your end going – there’s a delay built in. If you take too long it will abort the transfer, but you can always try again. The transfer may also be aborted if there are too many transmission errors – often a second try will work fine.

“DEMO CPM” To see several of these commands in action, type DEMO CPM. There is an automated demo of the basics (I’ve put in a place for your input – don’t just sit back!).

T R Y U S O U T !


These articles from the CATS Newsletter were photo reduced in order to get as much of a sample of the depth of articles given in each NL issue.

The Newsletter is printed in a nice size readable print.

All QL and TS-2068 users would do themselves a favor by subscribing to the CATS Newsletter.