HP3000-L Archives

November 1995, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Jim Wowchuk <[log in to unmask]>
Reply To:
Jim Wowchuk <[log in to unmask]>
Date:
Mon, 6 Nov 1995 12:51:44 +1100
Content-Type:
text/plain
Parts/Attachments:
text/plain (128 lines)
I took a moment and wrote the following to copy a file that wouldn't add
extra carriage return/line feeds.
 
----- start snip ------------------------------------------
/*
    bcp - binary copy
 
    copy from input file to $stdlist, suspending carriage control
    between writes.
 
    (C) 95 - Vanguard Computer Services.
    This software may be freely distributed, copied, altered and
    amended provided this acknowledgement of Vanguard's original
    copyright is included.
 
 */
 
#include <stdio.h>
#include <mpe.h>
#define BUFSIZE 256
#define NOSPACE_NORETURN 0320
 
#pragma intrinsic print mpe_print, fcheck, ferrmsg
 
int main(int argc, char *argv[])
{
    FILE *fIn;
    char caBuf[BUFSIZE];
    int cb;
 
    if (argc < 2) {
        fprintf(stderr, "format: %s source_file_name\n", argv[0]);
        exit(1);
        }
 
        /* open the input file */
    fIn = fopen(argv[1], "rb");
    if (fIn == NULL) {
        perror("Unable to open input");
        exit(2);
        }
 
    while ((cb = fread(caBuf, 1, BUFSIZE, fIn)) != 0) {
        mpe_print(caBuf, -cb, NOSPACE_NORETURN);
        if (ccode() != CCE) {
            char caErr[80];
            short nErr, cbErr;
 
            fcheck(2, &nErr);
            ferrmsg(&nErr, caErr, &cbErr);
            caErr[cbErr] = '\0';
            fprintf(stderr, "Error on output: %s\n", caErr);
            exit(3);
            }
        }
 
    if (ferror(fIn)) {
        perror("Error reading input");
        exit(5);
        }
 
    fclose(fIn);
    return 0;
    } /* main */
----- end snip ------------------------------------------
 
If you have a C compiler I presume you'll know how to compile it.
 
To run, issue a file equation of the ilk:
   :FILE OUT;DEV=printer;CCTL
then
   :BCP myfile >*OUT
 
I've tested it with fixed, variable and byte files successfully from the MPE
ci prompt. From Word for Windows on a PC, I printed a test page (with
graphics and fonts) to a file, transported this to the HP3000 and ran BCP to
it.  Same results as printing directly.  It should work from MPE/iX 4.0 too.
 
While I previously said such a program was a no-brainer, it did, in fact,
present some interesting issues which I stimulated some further thinking.
 
1)  It is necessary to add the ;CCTL to the output file equation.  But how
would I do this with my linked device /dev/lp if running under the POSIX
shell?  File equations don't work (do they?).  Shouldn't there be a minor
number on the /mknod/ to support cctl directives?  I could open the device
directly (fopen("/dev/lp", "bC") but will this override this?
 
2)  Using a 'c' fwrite(..., stdout) function (rather than the mpe_fwrite)
causes the data to be inspected for '\n' characters.  So one fwrite()
effectively generates multiple mpe_fwrites() each with standard carriage
control (skip one line).  How can stdout be made to treat the data as
binary? Is there a POSIX equivalent to the PC setmode() function to change
this to binary?
 
3)  I considered how I might 'C'/Posix fopen() or fdopen() the stdout again
to explicitly specify carriage control (and binary mode).  There doesn't
seem to be a way to open or reopen a file without specifying a name, but I'm
concerned that using a name "$STDLIST" would not work under the POSIX shell.
Can anyone confirm?
 
4)  At the moment, errors that occur are sent to stderr, but this of course
is mapped to stdout.  Is there a way from the MPE command line to redirect
stdout, but not stderr?  Is there a programatic way, maybe by determining
the session output device and doing an fdopen() against this -- by name?
 
5)  How does a program running under MPE CI write to a device file like
/dev/lp?  The program runs, but the data seems to disappear into the ether.
Can I not use the mpe_fwrite() intrinsic against /dev/lp?
 
6)  It appears that as I'm using mpe_print(), running under the POSIX shell
does not support the command io redirection ('>/dev/lp').  Is there a fix
for this? (Forgive my laziness in not checking the archives)
 
I've sent the program binary to Moshe, but if anyone else wants it I'll be
glad to post it to opus.
 
/te ne interrogante non discas/ -
If you don't ask questions, you will not learn.
 
Regards.
----
Jim "seMPEr" Wowchuk
Vanguard Computer Services     Internet:    [log in to unmask]
 _--_|\                        Compu$erve:  100036,106
/      \                       Post:        PO Box 18, North Ryde, NSW 2113
\.--.__/ <---Sydney NSW        Phone:       +61 (2) 888-9688
      v      Australia         Fax:         +61 (2) 888-3056

ATOM RSS1 RSS2