From 739a8290a8b05645a2d055aed8e5eb76ba2e24e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Fri, 28 Aug 2015 17:55:26 +0000 Subject: one-true indentation svn path=/trunk/externals/zexy/; revision=17537 --- src/lpt.c | 107 +++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 60 insertions(+), 47 deletions(-) (limited to 'src/lpt.c') diff --git a/src/lpt.c b/src/lpt.c index 270aead..26f4468 100644 --- a/src/lpt.c +++ b/src/lpt.c @@ -1,4 +1,4 @@ -/* +/* * lpt: read/write the parallel port * * (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem) @@ -7,18 +7,18 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ -/* +/* (c) 2000:forum::für::umläute:2005 write to the parallel port @@ -68,7 +68,9 @@ extern int open_port(int port); static int ioperm(int port, int a, int b) { - if(open_port(port) == -1)return(1); + if(open_port(port) == -1) { + return(1); + } return(0); } @@ -104,8 +106,7 @@ static int sys_inb(int port) static int count_iopl = 0; static t_class *lpt_class; -typedef struct _lpt -{ +typedef struct _lpt { t_object x_obj; unsigned long port; @@ -119,13 +120,13 @@ static void lpt_float(t_lpt *x, t_floatarg f) #ifdef Z_WANT_LPT unsigned char b = f; # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPWDATA, &b); } else # endif - if (x->port) { - sys_outb(b, x->port+0); - } + if (x->port) { + sys_outb(b, x->port+0); + } #endif /* Z_WANT_LPT */ } @@ -134,13 +135,13 @@ static void lpt_control(t_lpt *x, t_floatarg f) #ifdef Z_WANT_LPT unsigned char b = f; # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPWCONTROL, &b); } else # endif - if (x->port) { - sys_outb(b, x->port+2); - } + if (x->port) { + sys_outb(b, x->port+2); + } #endif /* Z_WANT_LPT */ } @@ -148,15 +149,15 @@ static void lpt_bang(t_lpt *x) { #ifdef Z_WANT_LPT # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { unsigned char b=0; ioctl (x->device, PPRCONTROL, &b); - outlet_float(x->x_obj.ob_outlet, (t_float)b); + outlet_float(x->x_obj.ob_outlet, (t_float)b); } else # endif - if (x->port) { - outlet_float(x->x_obj.ob_outlet, (t_float)sys_inb(x->port+1)); - } + if (x->port) { + outlet_float(x->x_obj.ob_outlet, (t_float)sys_inb(x->port+1)); + } #endif /* Z_WANT_LPT */ } @@ -165,8 +166,9 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) { t_lpt *x = (t_lpt *)pd_new(lpt_class); char*devname=atom_getsymbol(argv)->s_name; - if(s==gensym("lp")) + if(s==gensym("lp")) { error("lpt: the use of 'lp' has been deprecated; use 'lpt' instead"); + } inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("control")); @@ -184,7 +186,7 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) break; case 1: x->port = BASE1; - break; + break; case 2: x->port = BASE2; break; @@ -193,17 +195,17 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) x->port = 0; return (x); } - } else { + } else { /* SYMBOL might be a file or a hex port-number; we ignore the file (device) case by now; LATER think about this */ x->device=-1; x->port=strtol(devname, 0, 16); - if(0==x->port){ + if(0==x->port) { #ifdef HAVE_LINUX_PPDEV_H x->device = open(devname, O_RDWR); - if(x->device<=0){ + if(x->device<=0) { error("lpt: bad device %s", devname); return(x); } else { @@ -217,12 +219,12 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) } } - if ((x->device<0) && (!x->port || x->port>65535)){ + if ((x->device<0) && (!x->port || x->port>65535)) { error("lpt : bad port %x", x->port); x->port = 0; return (x); } - if (x->device<0){ + if (x->device<0) { /* this is ugly: when using a named device, * we are currently assuming that we have read/write-access * of course, this is not necessary true @@ -231,29 +233,37 @@ static void *lpt_new(t_symbol *s, int argc, t_atom *argv) * withOUT write permissions * (just reading the parport) */ - if (x->port && x->port < 0x400){ + if (x->port && x->port < 0x400) { if (ioperm(x->port, 8, 1)) { x->mode=MODE_NONE; - } else x->mode = MODE_IOPERM; + } else { + x->mode = MODE_IOPERM; + } } - if(x->mode==MODE_NONE){ - if (iopl(3)){ + if(x->mode==MODE_NONE) { + if (iopl(3)) { x->mode=MODE_NONE; - } else x->mode=MODE_IOPL; + } else { + x->mode=MODE_IOPL; + } count_iopl++; } - - if(x->mode==MODE_NONE){ + + if(x->mode==MODE_NONE) { error("lpt : couldn't get write permissions"); x->port = 0; return (x); } } - if(x->device>0) + if(x->device>0) { post("lpt: connected to device %s", devname); - else - post("lpt: connected to port %x in mode '%s'", x->port, (x->mode==MODE_IOPL)?"iopl":"ioperm"); - if (x->mode==MODE_IOPL)post("lpt-warning: this might seriously damage your pc..."); + } else { + post("lpt: connected to port %x in mode '%s'", x->port, + (x->mode==MODE_IOPL)?"iopl":"ioperm"); + } + if (x->mode==MODE_IOPL) { + post("lpt-warning: this might seriously damage your pc..."); + } #else error("zexy has been compiled without [lpt]!"); count_iopl=0; @@ -268,17 +278,19 @@ static void lpt_free(t_lpt *x) { #ifdef Z_WANT_LPT # ifdef HAVE_LINUX_PPDEV_H - if (x->device>0){ + if (x->device>0) { ioctl (x->device, PPRELEASE); close(x->device); x->device=0; } else # endif - if (x->port) { - if (x->mode==MODE_IOPERM && ioperm(x->port, 8, 0)) error("lpt: couldn't clean up device"); - else if (x->mode==MODE_IOPL && (!--count_iopl) && iopl(0)) - error("lpt: couldn't clean up device"); - } + if (x->port) { + if (x->mode==MODE_IOPERM && ioperm(x->port, 8, 0)) { + error("lpt: couldn't clean up device"); + } else if (x->mode==MODE_IOPL && (!--count_iopl) && iopl(0)) { + error("lpt: couldn't clean up device"); + } + } #endif /* Z_WANT_LPT */ } @@ -294,12 +306,13 @@ static void lpt_helper(t_lpt*UNUSED(x)) void lpt_setup(void) { lpt_class = class_new(gensym("lpt"), - (t_newmethod)lpt_new, (t_method)lpt_free, - sizeof(t_lpt), 0, A_GIMME, 0); + (t_newmethod)lpt_new, (t_method)lpt_free, + sizeof(t_lpt), 0, A_GIMME, 0); class_addcreator((t_newmethod)lpt_new, gensym("lp"), A_GIMME, 0); class_addfloat(lpt_class, (t_method)lpt_float); - class_addmethod(lpt_class, (t_method)lpt_control, gensym("control"), A_FLOAT, 0); + class_addmethod(lpt_class, (t_method)lpt_control, gensym("control"), + A_FLOAT, 0); class_addbang(lpt_class, (t_method)lpt_bang); class_addmethod(lpt_class, (t_method)lpt_helper, gensym("help"), 0); -- cgit v1.2.1