Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) ===============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) Linux USB Printer Gadget Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) ===============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) 06/04/2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) Copyright (C) 2007 Craig W. Nadler <craig@nadler.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) General
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) This driver may be used if you are writing printer firmware using Linux as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) the embedded OS. This driver has nothing to do with using a printer with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) your Linux host system.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) You will need a USB device controller and a Linux driver for it that accepts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) a gadget / "device class" driver using the Linux USB Gadget API. After the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) USB device controller driver is loaded then load the printer gadget driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) This will present a printer interface to the USB Host that your USB Device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) port is connected to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) This driver is structured for printer firmware that runs in user mode. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) user mode printer firmware will read and write data from the kernel mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) printer gadget driver using a device file. The printer returns a printer status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) byte when the USB HOST sends a device request to get the printer status.  The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) user space firmware can read or write this status byte using a device file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) /dev/g_printer . Both blocking and non-blocking read/write calls are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) Howto Use This Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) =====================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) To load the USB device controller driver and the printer gadget driver. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) following example uses the Netchip 2280 USB device controller driver::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	modprobe net2280
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	modprobe g_printer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) The follow command line parameter can be used when loading the printer gadget
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) (ex: modprobe g_printer idVendor=0x0525 idProduct=0xa4a8 ):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) idVendor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	This is the Vendor ID used in the device descriptor. The default is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	the Netchip vendor id 0x0525. YOU MUST CHANGE TO YOUR OWN VENDOR ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	BEFORE RELEASING A PRODUCT. If you plan to release a product and don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	already have a Vendor ID please see www.usb.org for details on how to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	get one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) idProduct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	This is the Product ID used in the device descriptor. The default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	is 0xa4a8, you should change this to an ID that's not used by any of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	your other USB products if you have any. It would be a good idea to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	start numbering your products starting with say 0x0001.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) bcdDevice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	This is the version number of your product. It would be a good idea
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	to put your firmware version here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) iManufacturer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	A string containing the name of the Vendor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) iProduct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	A string containing the Product Name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) iSerialNum
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	A string containing the Serial Number. This should be changed for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	each unit of your product.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) iPNPstring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	The PNP ID string used for this printer. You will want to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	either on the command line or hard code the PNP ID string used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	your printer product.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) qlen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	The number of 8k buffers to use per endpoint. The default is 10, you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	should tune this for your product. You may also want to tune the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	size of each buffer for your product.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) Using The Example Code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) ======================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) This example code talks to stdout, instead of a print engine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) To compile the test code below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 1) save it to a file called prn_example.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 2) compile the code with the follow command::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 gcc prn_example.c -o prn_example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) To read printer data from the host to stdout::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	# prn_example -read_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) To write printer data from a file (data_file) to the host::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	# cat data_file | prn_example -write_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) To get the current printer status for the gadget driver:::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	# prn_example -get_status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	Printer status is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	     Printer is NOT Selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	     Paper is Out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	     Printer OK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) To set printer to Selected/On-line::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	# prn_example -selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) To set printer to Not Selected/Off-line::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	# prn_example -not_selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) To set paper status to paper out::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	# prn_example -paper_out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) To set paper status to paper loaded::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	# prn_example -paper_loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) To set error status to printer OK::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	# prn_example -no_error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) To set error status to ERROR::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	# prn_example -error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) Example Code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)   #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)   #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)   #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)   #include <linux/poll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)   #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)   #include <linux/usb/g_printer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)   #define PRINTER_FILE			"/dev/g_printer"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)   #define BUF_SIZE			512
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)   /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)    * 'usage()' - Show program usage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)   static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)   usage(const char *option)		/* I - Option string or NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (option) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		fprintf(stderr,"prn_example: Unknown option \"%s\"!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				option);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	fputs("\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	fputs("Usage: prn_example -[options]\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	fputs("Options:\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	fputs("\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	fputs("-get_status    Get the current printer status.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	fputs("-selected      Set the selected status to selected.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	fputs("-not_selected  Set the selected status to NOT selected.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	fputs("-error         Set the error status to error.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	fputs("-no_error      Set the error status to NO error.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	fputs("-paper_out     Set the paper status to paper out.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	fputs("-paper_loaded  Set the paper status to paper loaded.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	fputs("-read_data     Read printer data from driver.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	fputs("-write_data    Write printer sata to driver.\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	fputs("-NB_read_data  (Non-Blocking) Read printer data from driver.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	fputs("\n\n", stderr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)   read_printer_data()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	struct pollfd	fd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	/* Open device file for printer gadget. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	fd[0].fd = open(PRINTER_FILE, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (fd[0].fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	fd[0].events = POLLIN | POLLRDNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		static char buf[BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		int bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		/* Wait for up to 1 second for data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		retval = poll(fd, 1, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (retval && (fd[0].revents & POLLRDNORM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			/* Read data from printer gadget driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			bytes_read = read(fd[0].fd, buf, BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 			if (bytes_read < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 				printf("Error %d reading from %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 						fd[0].fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 				close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 				return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			} else if (bytes_read > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 				/* Write data to standard OUTPUT (stdout). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 				fwrite(buf, 1, bytes_read, stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 				fflush(stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	/* Close the device file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)   write_printer_data()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct pollfd	fd[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	/* Open device file for printer gadget. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	fd[0].fd = open (PRINTER_FILE, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (fd[0].fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		printf("Error %d opening %s\n", fd[0].fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	fd[0].events = POLLOUT | POLLWRNORM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		static char buf[BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		/* Read data from standard INPUT (stdin). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		int bytes_read = fread(buf, 1, BUF_SIZE, stdin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		if (!bytes_read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		while (bytes_read) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			/* Wait for up to 1 second to sent data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			retval = poll(fd, 1, 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			/* Write data to printer gadget driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			if (retval && (fd[0].revents & POLLWRNORM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 				retval = write(fd[0].fd, buf, bytes_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 				if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 					printf("Error %d writing to %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 							fd[0].fd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 							PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 					close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 					return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 					bytes_read -= retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/* Wait until the data has been sent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	fsync(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* Close the device file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	close(fd[0].fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)   read_NB_printer_data()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	int		fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	static char	buf[BUF_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	int		bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	/* Open device file for printer gadget. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	fd = open(PRINTER_FILE, O_RDWR|O_NONBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		printf("Error %d opening %s\n", fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		/* Read data from printer gadget driver. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		bytes_read = read(fd, buf, BUF_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		if (bytes_read <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		/* Write data to standard OUTPUT (stdout). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		fwrite(buf, 1, bytes_read, stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		fflush(stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	/* Close the device file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)   get_printer_status()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	int	retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	int	fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	/* Open device file for printer gadget. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	fd = open(PRINTER_FILE, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		printf("Error %d opening %s\n", fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	/* Make the IOCTL call. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	retval = ioctl(fd, GADGET_GET_PRINTER_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		fprintf(stderr, "ERROR: Failed to set printer status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	/* Close the device file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	return(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)   set_printer_status(unsigned char buf, int clear_printer_status_bit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	int	retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	int	fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	retval = get_printer_status();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		fprintf(stderr, "ERROR: Failed to get printer status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	/* Open device file for printer gadget. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	fd = open(PRINTER_FILE, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (fd < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		printf("Error %d opening %s\n", fd, PRINTER_FILE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (clear_printer_status_bit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		retval &= ~buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		retval |= buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	/* Make the IOCTL call. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	if (ioctl(fd, GADGET_SET_PRINTER_STATUS, (unsigned char)retval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		fprintf(stderr, "ERROR: Failed to set printer status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	/* Close the device file. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)   static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)   display_printer_status()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	char	printer_status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	printer_status = get_printer_status();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	if (printer_status < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 		fprintf(stderr, "ERROR: Failed to get printer status\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		return(-1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	printf("Printer status is:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (printer_status & PRINTER_SELECTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		printf("     Printer is Selected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		printf("     Printer is NOT Selected\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	if (printer_status & PRINTER_PAPER_EMPTY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		printf("     Paper is Out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		printf("     Paper is Loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	if (printer_status & PRINTER_NOT_ERROR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		printf("     Printer OK\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		printf("     Printer ERROR\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	return(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)   }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)   int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)   main(int  argc, char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)   {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	int	i;		/* Looping var */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	int	retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	/* No Args */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (argc == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		usage(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	for (i = 1; i < argc && !retval; i ++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		if (argv[i][0] != '-') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		if (!strcmp(argv[i], "-get_status")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			if (display_printer_status()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		} else if (!strcmp(argv[i], "-paper_loaded")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			if (set_printer_status(PRINTER_PAPER_EMPTY, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		} else if (!strcmp(argv[i], "-paper_out")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 			if (set_printer_status(PRINTER_PAPER_EMPTY, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		} else if (!strcmp(argv[i], "-selected")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 			if (set_printer_status(PRINTER_SELECTED, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		} else if (!strcmp(argv[i], "-not_selected")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			if (set_printer_status(PRINTER_SELECTED, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		} else if (!strcmp(argv[i], "-error")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 			if (set_printer_status(PRINTER_NOT_ERROR, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		} else if (!strcmp(argv[i], "-no_error")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 			if (set_printer_status(PRINTER_NOT_ERROR, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 		} else if (!strcmp(argv[i], "-read_data")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 			if (read_printer_data()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 		} else if (!strcmp(argv[i], "-write_data")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 			if (write_printer_data()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 		} else if (!strcmp(argv[i], "-NB_read_data")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 			if (read_NB_printer_data()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 				retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			usage(argv[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 			retval = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	exit(retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)   }