hardie@sask.UUCP (Peter Hardie ) (02/18/86)
Here's the C (Lattice 3.02) source for a program that prints files. It's better than using the copy command but it does not work under Workbench. It's not a spooler but at least you can start it up in a CLI and forget about it until it's done. Pete ihnp4!sask!hardie /************************** CUT HERE *********************************/ /* print .... print files to the printer.device. print [-r | -nN] file [file [ file .....] ] The -r option causes print to write the files using raw I/O which means that all characters go through exactly as in the file. (i.e. escape sequences are not translated etc.) If -r is not specified then the normal device is used and any escape sequences are assumed to be the standard ISO ones used by the driver (see include/devices/printer.h for a list of codes) The program adds a formfeed at the end of each file. If the -nN option is used then only one file should be specified and that file will be printed N times without the formfeed between each one. This is useful for printing an address label umpty times. BUGS: Yep. It does not look for a cancel signal so once started it goes until it's done or until a reboot, whichever occurs first. PUBLIC DOMAIN FREEBIE ..... just don't sell it turkey! Peter Hardie ihnp4!sask!hardie Saskatoon, Sask, Canada. */ #include <libraries/dos.h> #include <exec/io.h> #include <devices/printer.h> #include <devices/inputevent.h> #include <lattice/fcntl.h> struct IOStdReq *iorb,iob; struct InputEvent *event,ev; char buf[512]; char formfeed = '\014'; main(argc,argv) char *argv[]; int argc; { int ifd,rawwrite; int num; int repeat, count; event = &ev; iorb = &iob; OpenDevice("printer.device",1,iorb,0); if(iorb->io_Error) { printf("can't open printer.device\n"); exit(); } iorb->io_Message.mn_ReplyPort = CreatePort("printer_reply",0L); if(iorb->io_Message.mn_ReplyPort == NULL) { CloseDevice(iorb); printf("can't get a reply port\n"); exit(); } rawwrite = CMD_WRITE; repeat = 1; if(argc > 1) { while(argv[1][0] == '-') { argv++; argc--; switch(argv[0][1]) { case 'r': rawwrite = PRD_RAWWRITE; break; case 'n': repeat = atoi(&argv[0][2]); break; default: printf("unknown argument '%s'\n",argv[0]); usage(); goto finish; } } } if((repeat > 1) && (argc != 2)) { printf("arg count: only one file can be repeated\n"); goto finish; } while(argc > 1) { if((ifd = open(argv[1],O_RDONLY)) == 0) { printf("can't open %s\n",argv[1]); argc--; argv++; continue; } for(count = 0; count < repeat; count++) { while((num = read(ifd,&buf[0],512)) > 0) { iorb->io_Command = rawwrite; iorb->io_Length = num; iorb->io_Data = &buf[0]; DoIO(iorb); } if(repeat > 1)lseek(ifd,0L,0); } iorb->io_Command = rawwrite; iorb->io_Length = 1; iorb->io_Data = &formfeed; DoIO(iorb); close(ifd); argc--; argv++; } finish: CloseDevice(iorb); } usage() { printf("Usage: print [-r | -nN] file [file .....]\n"); printf("If -nN is specified then only one file should be given\n"); }
andy@amiga.UUCP (Andy Finkel) (02/19/86)
In article <332@sask.UUCP> hardie@sask.UUCP (Peter Hardie ) writes: >Here's the C (Lattice 3.02) source for a program that prints files. >It's better than using the copy command but it does not work under >Workbench. It's not a spooler but at least you can start it up in >a CLI and forget about it until it's done. >Pete >ihnp4!sask!hardie Not to take anything away from Pete, since its useful to try these things, but here's another way to to it: (from a CLI window) run copy filename1 to prt: + copy filename2 to prt: + . . . copy filenamen to prt: ---------------------------- If you want formfeeds between files, put in an echo statement between files, like: echo > prt: "^L" (control L is the formfeed) to get the full, raw effect, copy to par: instead of prt: You could also make it into a DOS execute file, with parameters. andy finkel Commodore(Amiga)
bruceb@amiga.UUCP (Bruce Barrett) (02/20/86)
In article <707@amiga.amiga.UUCP> andy@skipper.UUCP (Andy Finkel) writes: >In article <332@sask.UUCP> hardie@sask.UUCP (Peter Hardie ) writes: >>Here's the C (Lattice 3.02) source for a program that prints files. >>It's better than using the copy command... >>Pete >>ihnp4!sask!hardie > >Not to take anything away from Pete, since its useful to try these things, >but here's another way to to it: > >(from a CLI window) > >run copy filename1 to prt: + >copy filename2 to prt: + > : >copy filenamen to prt: optional: >echo > prt: "^L" >(control L is the formfeed) > >to get the full, raw effect, copy to par: instead of prt: > >You could also make it into a DOS execute file, with parameters. > > andy finkel > Commodore(Amiga) Or........ even better(???) [different, at least] than Andy's solution... You can use the "Join" command. This makes handling multiple files even easier (for the batch file). Something like: 1) echo > :t/ff "^L" run join file1 :t/ff file2 :t/ff ... filen as prt: delete :t/ff or 2) run join file1 file2 ... filen as prt: or 3) and 4) use par: (or ser:) instead for "RawWrite". ==========PROBLEMS============= You will please note the following problems with both Andy and my "solutions": 1) No provision for the -nN option is made 2) We assume (*Very* foolish us) that your printer is parallel. OK so you can copy to SER: instead but this would require knowlege on the part of the person running/installing the execute file. Not user friendly if you have 2 systems with 2 different types of printers (like I do). 3) Join will only handle 10 files (in this case that might be 5 files and 5 form-feeds) a definite limitation. 4) Do NOT try using: run copy .... par: run copy .... par: run copy .... par: as the 2nd and third copies may try to print before the first frees the printer. They will just give up on the PRT: open error. All and all I think Peter's program (although I have yet to use it) is quite useful in some cases. Thanks Peter. --Bruce Barrett (Commodore-Amiga)
hardie@sask.UUCP (Peter Hardie ) (02/22/86)
> In article <707@amiga.amiga.UUCP> andy@skipper.UUCP (Andy Finkel) writes: a way of printing with CLI commands. And Bruce Barrett shows another way and adds: > All and all I think Peter's program (although I have yet to use it) is > quite useful in some cases. Thanks Peter. > --Bruce Barrett (Commodore-Amiga) Thanks guys. As I commented to another Commodore-Amiga person, by mail, the program isn't exactly a spooler and you can certainly do the same thing with lots of command lines. But in my startup-sequence I open a newcli with newcli con:400/10/240/50/cli that hangs up in the top right corner of my screen. If I want to print something I open that window and type, for example, print mand.h mand.c mand1.c mand2.c mand3.c mand4.c and then go back to the previous window wherein I am typing a reply to some mail or reading this news over the phone line with my hacked up version of the amigaterm program that was posted a while ago. And I can forget about the printer until it's done. Actually, the program started as an exercise in opening, using and closing a device and then evolved to the print program. It'll probably get worse as time goes by and I try to fiddle with the text justification and plotting features on my printer. Ciao Pete Hardie ihnp4!sask!hardie