home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
forum4.lzh
/
SPRACHEN
/
C
/
LP
/
lp.c
next >
Wrap
C/C++ Source or Header
|
1988-02-14
|
3KB
|
130 lines
/* lp fuer os-9/68k Uwe Simon 4.9.1987 */
#include <stdio.h>
#include <module.h>
#include <pwd.h>
#include "lp.h"
FILE *f;
char s[300],titel[100],filename[100],dev[32],r_mesg[20];
mod_exec *module;
int ev;
error()
{
fprintf(stderr,"Syntax: lp [<opts>] {<path>}\n");
fprintf(stderr,"Options:\n");
fprintf(stderr," -z get file names from standard input\n");
fprintf(stderr," -w message on terminal when ready\n");
fprintf(stderr," -m mail to user when ready\n");
fprintf(stderr," -n=xx make xx copies (default 1)\n");
fprintf(stderr," -d=ptr output on device ptr\n");
fprintf(stderr," -s silentmode\n");
_ev_unlink(ev);
munlink(module);
}
copy_file()
{
while(fgets(s,256,stdin)) fputs(s,f);
}
main(argc,argv)
int argc;
char **argv;
{
int copies,mesg,h,files=0,idmesg=1;
struct passwd *pwd;
if(strcmp(argv[1],"-?")==0) {
error();
exit(0);
}
module=(mod_exec *)modlink("spoolqueue",0x400);
if((int)module==-1) { exit(_errmsg(1,"Spooler not installed\n")); }
queue=(struct spoolqueue *)((long)module+module->_mexec);
if(!queue->active) fprintf(stderr,"WARNING: Spooler not active\n");
ev=_ev_link("spoolqueue");
filename[0]='\0'; titel[0]='\0'; dev[0]='\0';
copies=1; mesg=0; r_mesg[0]='\0';
if((pwd=getpwuid(getuid()&0xffff))!=NULL) strcat(spooltmp,pwd->pw_name);
strcat(spooltmp,".XXXXXX");
f=fopen(strcpy(filename,mktemp(spooltmp)),"w");
while (--argc) {
if(**++argv=='-') {
switch(toupper(*++*argv)) {
case '?':
error();
exit(0);
break;
case 'Z':
break;
case 'M':
mesg=mesg | MAILMODE;
break;
case 'N':
copies=atoi(*argv+(long)2);
break;
case 'D':
strcpy(dev,*argv+(long)2);
break;
case 'S':
idmesg=0;
break;
case 'W':
strcpy(r_mesg,getenv("PORT"));
break;
default:
error();
exit(1);
break;
}
}
else {
files++;
if(freopen(*argv,"r",stdin)) {
if(titel[0]!='\0') { /* schon ein File */
if(strlen(titel)+strlen(*argv)<90) {
strcat(titel,", ");
strcat(titel,*argv);
}
else strcat(titel,", ...");
putc(0x0c,f);
}
else strcpy(titel,*argv);
copy_file();
}
else fprintf(stderr,"can't open %s\n",*argv);
}
}
if((files==0) && (titel[0]=='\0')) { /* kein File (also stdin !) */
strcpy(titel,"/stdin/");
copy_file();
}
fflush(f);
h=_gs_size(fileno(f));
fclose(f);
if(h>0) {
if((h=ins_job(ev,queue,dev,filename,titel,copies,r_mesg,mesg,h))== -1) {
fprintf(stderr,"Spoolqueue is full or unknown printer\n");
_ev_unlink(ev);
munlink(module);
exit(1);
}
if(idmesg) printf("Spoolid : %d\n",h);
}
else {
unlink(filename);
printf("empty input\n");
}
_ev_unlink(ev);
munlink(module);
}