[comp.sys.ibm.pc] Sticky Problems with C on IBM-compatibles

alex@bilver.UUCP (Alex Matulich) (02/16/90)

For the past couple of years I have been writing C programs for IBM
compatibles using either Microsoft C or Turbo C.  I try to make my software
look and feel as professional as possible, but during my endeavors I have
run into some programming problems that I can't figure out, and none of
the IBM-specific C programming books I have read are any help.  Commercial
programs do these things, so why can't I?

Specifically:

1) Is there a faster way to display character strings than using puts()
   or printf() without resorting to assembly language?

2) If I have a text screen set up like I want it, is it possible to save
   it away somehow so I can display it anytime later by dumping it back
   into the video memory?  If so, how do I find the address and length 
   of a video text display?

3) How do I display inverse, boldface, or multicolored text without
   resorting to using ANSI.SYS?

4) The critical error handler gets invoked when the printer needs more
   paper.  How do I tell if the printer is offline?  The computer hung up
   last time I tried using fopen() to get a file handle to a printer that
   was powered off.

5) If a user of my software has a serial printer, how do I set up the
   serial port parameters (baud rate, xon/xoff, databits, stopbits, etc)?

6) I expected to find a function somewhere in the standard library that
   would read the contents of a disk directory into a string array.  Did
   I miss it?  I have heard the Lattice compiler has such a function, but
   I don't have that compiler.  If no such function exists, how is it done?

7) If my PATH environment variable is set up so that I can run one of my
   programs from a directory different than the one containing my program,
   how it possible for my program to determine the directory IT started
   from?  Or does that information have to be hard-coded in my program?

If you know the answers to at least one of the above questions, or if you
know the title of a helpful book I can look up, PLEASE e-mail me a reply.
Especially if you have examples of code that you use, I'd like to hear from
you.  I'll summarize the replies I receive.  Thanks...

-- 
     ///  Alex Matulich
    ///  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
\\\///  alex@bilver.UUCP    ...uunet!tarpit!bilver!alex
 \XX/  From BitNet use: bilver!alex@uunet.uu.net

psrc@pegasus.ATT.COM (Paul S. R. Chisholm) (02/18/90)

< Krasny Oktyabr:  the hunt is on, March 2, 1990 >

In article <492@bilver.UUCP>, alex@bilver.UUCP (Alex Matulich) writes:
> 1) Is there a faster way to display character strings than using puts()
>    or printf() without resorting to assembly language?

Have you tried the console video functions described in the first part
of chapter 8 of the (TC 2.0) User's Guide?

> 2) If I have a text screen set up like I want it, is it possible to save
>    it away somehow so I can display it anytime later by dumping it back
>    into the video memory?

Try gettext().

> 3) How do I display inverse, boldface, or multicolored text without
>    resorting to using ANSI.SYS?

Use the functions I've already mentioned, with textattr(), textcolor(),
and textbackground(), as appropriate.

> 4) The critical error handler gets invoked when the printer needs more
>    paper.  How do I tell if the printer is offline?  The computer hung up
>    last time I tried using fopen() to get a file handle to a printer that
>    was powered off.

I don't think it'll really hang; it *will* wait for many seconds,
giving the printer a chance to get on-line.  You'll need to replace the
critical error handler (using the setvect() function) with your own.
It should check everything you're interested in, and the rest should be
ignored or passed to the original handler.  Be sure to replace the
original when you're done!  Check the Norton or Duncan books for
details.

> 5) If a user of my software has a serial printer, how do I set up the
>    serial port parameters (baud rate, xon/xoff, databits, stopbits, etc)?

I think you're going to have to invoke interrupt 20, service 0 "by
hand".  (You can do this with the intr() functions, or one of the other
int*() functions.)  Norton and Duncan have the details.

> 6) I expected to find a function somewhere in the standard library that
>    would read the contents of a disk directory into a string array.

Try findfirst() and findnext().  They're not quite what you asked for,
but they provide the basics.

> 7) If my PATH environment variable is set up so that I can run one of my
>    programs from a directory different than the one containing my program,
>    how it possible for my program to determine the directory IT started
>    from?  Or does that information have to be hard-coded in my program?

DOS 3.0 and later generate enough information for the TC start-up code
to put the path name in argv[0].  In version 1.x and 2.x, your best bet
is to (yuchh) search the current directory, and then the path,
yourself.

> If you know the answers to at least one of the above questions, or if you
> know the title of a helpful book I can look up, PLEASE e-mail me a reply.

Try the second editions of either of these:  THE PETER NORTON
PROGRAMMER'S GUIDE TO THE IBM PC by (surprise) Peter Norton, or Ray
Duncan's ADVANCED MS-DOS.

>      ///  Alex Matulich
>     ///  Unicorn Research Corp, 4621 N Landmark Dr, Orlando, FL 32817
> \\\///  alex@bilver.UUCP    ...uunet!tarpit!bilver!alex
>  \XX/  From BitNet use: bilver!alex@uunet.uu.net

Paul S. R. Chisholm, AT&T Bell Laboratories
att!pegasus!psrc, psrc@pegasus.att.com, AT&T Mail !psrchisholm
I'm not speaking for the company, I'm just speaking my mind.