diff --git a/LICENSE.p9p b/LICENSE.p9p deleted file mode 100644 index 996e6a2b..00000000 --- a/LICENSE.p9p +++ /dev/null @@ -1,251 +0,0 @@ -The bulk of this software is derived from Plan 9 and is thus distributed -under the Lucent Public License, Version 1.02, reproduced below. - -There are a few exceptions: libutf, libfmt, and libregexp are distributed -under simpler BSD-like boilerplates. See the LICENSE files in those -directories. There are other exceptions, also marked with LICENSE files -in their directories. - -The bitmap fonts in the font/luc, font/lucm, font/lucsans, and font/pelm -directory are copyright B&H Inc. and distributed under more restricted -terms under agreement with B&H. See the NOTICE file in those directories. - -=================================================================== - -Lucent Public License Version 1.02 - -THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS PUBLIC -LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE -PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. - -1. DEFINITIONS - -"Contribution" means: - - a. in the case of Lucent Technologies Inc. ("LUCENT"), the Original - Program, and - b. in the case of each Contributor, - - i. changes to the Program, and - ii. additions to the Program; - - where such changes and/or additions to the Program were added to the - Program by such Contributor itself or anyone acting on such - Contributor's behalf, and the Contributor explicitly consents, in - accordance with Section 3C, to characterization of the changes and/or - additions as Contributions. - -"Contributor" means LUCENT and any other entity that has Contributed a -Contribution to the Program. - -"Distributor" means a Recipient that distributes the Program, -modifications to the Program, or any part thereof. - -"Licensed Patents" mean patent claims licensable by a Contributor -which are necessarily infringed by the use or sale of its Contribution -alone or when combined with the Program. - -"Original Program" means the original version of the software -accompanying this Agreement as released by LUCENT, including source -code, object code and documentation, if any. - -"Program" means the Original Program and Contributions or any part -thereof - -"Recipient" means anyone who receives the Program under this -Agreement, including all Contributors. - -2. GRANT OF RIGHTS - - a. Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free copyright - license to reproduce, prepare derivative works of, publicly display, - publicly perform, distribute and sublicense the Contribution of such - Contributor, if any, and such derivative works, in source code and - object code form. - - b. Subject to the terms of this Agreement, each Contributor hereby - grants Recipient a non-exclusive, worldwide, royalty-free patent - license under Licensed Patents to make, use, sell, offer to sell, - import and otherwise transfer the Contribution of such Contributor, if - any, in source code and object code form. The patent license granted - by a Contributor shall also apply to the combination of the - Contribution of that Contributor and the Program if, at the time the - Contribution is added by the Contributor, such addition of the - Contribution causes such combination to be covered by the Licensed - Patents. The patent license granted by a Contributor shall not apply - to (i) any other combinations which include the Contribution, nor to - (ii) Contributions of other Contributors. No hardware per se is - licensed hereunder. - - c. Recipient understands that although each Contributor grants the - licenses to its Contributions set forth herein, no assurances are - provided by any Contributor that the Program does not infringe the - patent or other intellectual property rights of any other entity. Each - Contributor disclaims any liability to Recipient for claims brought by - any other entity based on infringement of intellectual property rights - or otherwise. As a condition to exercising the rights and licenses - granted hereunder, each Recipient hereby assumes sole responsibility - to secure any other intellectual property rights needed, if any. For - example, if a third party patent license is required to allow - Recipient to distribute the Program, it is Recipient's responsibility - to acquire that license before distributing the Program. - - d. Each Contributor represents that to its knowledge it has sufficient - copyright rights in its Contribution, if any, to grant the copyright - license set forth in this Agreement. - -3. REQUIREMENTS - -A. Distributor may choose to distribute the Program in any form under -this Agreement or under its own license agreement, provided that: - - a. it complies with the terms and conditions of this Agreement; - - b. if the Program is distributed in source code or other tangible - form, a copy of this Agreement or Distributor's own license agreement - is included with each copy of the Program; and - - c. if distributed under Distributor's own license agreement, such - license agreement: - - i. effectively disclaims on behalf of all Contributors all warranties - and conditions, express and implied, including warranties or - conditions of title and non-infringement, and implied warranties or - conditions of merchantability and fitness for a particular purpose; - ii. effectively excludes on behalf of all Contributors all liability - for damages, including direct, indirect, special, incidental and - consequential damages, such as lost profits; and - iii. states that any provisions which differ from this Agreement are - offered by that Contributor alone and not by any other party. - -B. Each Distributor must include the following in a conspicuous - location in the Program: - - Copyright (C) 2003, Lucent Technologies Inc. and others. All Rights - Reserved. - -C. In addition, each Contributor must identify itself as the -originator of its Contribution in a manner that reasonably allows -subsequent Recipients to identify the originator of the Contribution. -Also, each Contributor must agree that the additions and/or changes -are intended to be a Contribution. Once a Contribution is contributed, -it may not thereafter be revoked. - -4. COMMERCIAL DISTRIBUTION - -Commercial distributors of software may accept certain -responsibilities with respect to end users, business partners and the -like. While this license is intended to facilitate the commercial use -of the Program, the Distributor who includes the Program in a -commercial product offering should do so in a manner which does not -create potential liability for Contributors. Therefore, if a -Distributor includes the Program in a commercial product offering, -such Distributor ("Commercial Distributor") hereby agrees to defend -and indemnify every Contributor ("Indemnified Contributor") against -any losses, damages and costs (collectively"Losses") arising from -claims, lawsuits and other legal actions brought by a third party -against the Indemnified Contributor to the extent caused by the acts -or omissions of such Commercial Distributor in connection with its -distribution of the Program in a commercial product offering. The -obligations in this section do not apply to any claims or Losses -relating to any actual or alleged intellectual property infringement. -In order to qualify, an Indemnified Contributor must: a) promptly -notify the Commercial Distributor in writing of such claim, and b) -allow the Commercial Distributor to control, and cooperate with the -Commercial Distributor in, the defense and any related settlement -negotiations. The Indemnified Contributor may participate in any such -claim at its own expense. - -For example, a Distributor might include the Program in a commercial -product offering, Product X. That Distributor is then a Commercial -Distributor. If that Commercial Distributor then makes performance -claims, or offers warranties related to Product X, those performance -claims and warranties are such Commercial Distributor's responsibility -alone. Under this section, the Commercial Distributor would have to -defend claims against the Contributors related to those performance -claims and warranties, and if a court requires any Contributor to pay -any damages as a result, the Commercial Distributor must pay those -damages. - -5. NO WARRANTY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS -PROVIDED ON AN"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY -WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY -OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely -responsible for determining the appropriateness of using and -distributing the Program and assumes all risks associated with its -exercise of rights under this Agreement, including but not limited to -the risks and costs of program errors, compliance with applicable -laws, damage to or loss of data, programs or equipment, and -unavailability or interruption of operations. - -6. DISCLAIMER OF LIABILITY - -EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR -ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING -WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR -DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED -HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -7. EXPORT CONTROL - -Recipient agrees that Recipient alone is responsible for compliance -with the United States export administration regulations (and the -export control laws and regulation of any other countries). - -8. GENERAL - -If any provision of this Agreement is invalid or unenforceable under -applicable law, it shall not affect the validity or enforceability of -the remainder of the terms of this Agreement, and without further -action by the parties hereto, such provision shall be reformed to the -minimum extent necessary to make such provision valid and enforceable. - -If Recipient institutes patent litigation against a Contributor with -respect to a patent applicable to software (including a cross-claim or -counterclaim in a lawsuit), then any patent licenses granted by that -Contributor to such Recipient under this Agreement shall terminate as -of the date such litigation is filed. In addition, if Recipient -institutes patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Program -itself (excluding combinations of the Program with other software or -hardware) infringes such Recipient's patent(s), then such Recipient's -rights granted under Section 2(b) shall terminate as of the date such -litigation is filed. - -All Recipient's rights under this Agreement shall terminate if it -fails to comply with any of the material terms or conditions of this -Agreement and does not cure such failure in a reasonable period of -time after becoming aware of such noncompliance. If all Recipient's -rights under this Agreement terminate, Recipient agrees to cease use -and distribution of the Program as soon as reasonably practicable. -However, Recipient's obligations under this Agreement and any licenses -granted by Recipient relating to the Program shall continue and -survive. - -LUCENT may publish new versions (including revisions) of this -Agreement from time to time. Each new version of the Agreement will be -given a distinguishing version number. The Program (including -Contributions) may always be distributed subject to the version of the -Agreement under which it was received. In addition, after a new -version of the Agreement is published, Contributor may elect to -distribute the Program (including its Contributions) under the new -version. No one other than LUCENT has the right to modify this -Agreement. Except as expressly stated in Sections 2(a) and 2(b) above, -Recipient receives no rights or licenses to the intellectual property -of any Contributor under this Agreement, whether expressly, by -implication, estoppel or otherwise. All rights in the Program not -expressly granted under this Agreement are reserved. - -This Agreement is governed by the laws of the State of New York and -the intellectual property laws of the United States of America. No -party to this Agreement will bring a legal action under this Agreement -more than one year after the cause of action arose. Each party waives -its rights to a jury trial in any resulting litigation. - diff --git a/Makefile b/Makefile index 146af2bd..488536c9 100644 --- a/Makefile +++ b/Makefile @@ -1,101 +1,8 @@ -# window manager improved 2 - window manager improved 2 -# © 2006 Anselm R. Garbe -# © 2006-2007 Kris Maglione -.POSIX: +ROOT=. +include ${ROOT}/mk/hdr.mk -include config.mk +DIRS = libixp \ + cmd \ + man -SRC = area.c bar.c client.c column.c draw.c event.c frame.c fs.c \ - geom.c key.c main.c mouse.c rule.c printevent.c util.c view.c -OBJ = ${SRC:.c=.o} -MAN1 = wmii wmiir wmiiwm wmiiloop -SCRIPTS = wmiistartrc wmiir wmiiloop wmii9rc -BIN = wmii wmii9menu - -all: options ${BIN} - -options: - @echo wmii build options: - @echo "CFLAGS = ${CFLAGS}" - @echo "LDFLAGS = ${LDFLAGS}" - @echo "CC = ${CC}" - -.c.o: - @echo CC $< - @${CC} -c ${CFLAGS} $< - -# In case this isn't from hg -.hg/00changelog.i: - @mkdir .hg - @touch .hg/00changelog.i -# VERSION must be updated on every commit/pull -config.mk: .hg/00changelog.i - -${OBJ}: wmii.h config.mk - -9menu.o: config.mk - -wmii: ${OBJ} - @echo LD $@ - @${CC} -o $@ ${OBJ} ${LDFLAGS} ${LIBIXP} - -wmii9menu: 9menu.o - @echo LD $@ - @${CC} -o $@ 9menu.o ${LDFLAGS} - -clean: - @echo cleaning - @rm -f ${BIN} ${OBJ} 9menu.o wmii-${VERSION}.tar.gz - -dist: clean - @echo creating dist tarball - @mkdir -p wmii-${VERSION} - @ln LICENSE Makefile config.mk README rc/ \ - wmii.eps wmii.mp \ - ${MAN1:=.1} ${SRC} ${SCRIPTS} wmii.h 9menu.c \ - wmii-${VERSION}/ - @tar -zcf wmii-${VERSION}.tgz wmii-${VERSION} - @rm -rf wmii-${VERSION} - -install: all - @echo installing executable files to ${DESTDIR}${PREFIX}/bin - @mkdir -p -m 0755 ${DESTDIR}${PREFIX}/bin - @for i in ${SCRIPTS}; do \ - sed "s|CONFPREFIX|${CONFPREFIX}|g; \ - s|CONFVERSION|${CONFVERSION}|g; \ - s|P9PATHS|${P9PATHS}|g; \ - s|AWKPATH|${AWKPATH}|g" \ - $$i \ - >${DESTDIR}${PREFIX}/bin/$$i; \ - chmod 755 ${DESTDIR}${PREFIX}/bin/$$i; \ - done - @for i in ${BIN}; do\ - cp -f $$i ${DESTDIR}${PREFIX}/bin; \ - chmod 755 ${DESTDIR}${PREFIX}/bin/$$i; \ - done - @echo installing scripts to ${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION} - @mkdir -p -m 0755 ${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION} - @cd rc; for i in *; do \ - sed "s|CONFPREFIX|${CONFPREFIX}|g" $$i \ - >${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION}/$$i; \ - chmod 755 ${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION}/$$i; \ - done - @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 - @mkdir -p -m 0755 ${DESTDIR}${MANPREFIX}/man1 - @for i in ${MAN1:=.1}; do \ - sed "s/VERSION/${VERSION}/g; \ - s|CONFPREFIX|${CONFPREFIX}|g" \ - $$i \ - >${DESTDIR}${MANPREFIX}/man1/$$i; \ - chmod 644 ${DESTDIR}${MANPREFIX}/man1/$$i; \ - done - -uninstall: - @echo removing executable files from ${DESTDIR}${PREFIX}/bin - @cd ${DESTDIR}${PREFIX}/bin && rm -f ${SCRIPTS} ${BIN} - @echo removing scripts from ${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION} - @rm -rf ${DESTDIR}${CONFPREFIX}/wmii-${CONFVERSION} - @echo removing manual page from ${DESTDIR}${MANPREFIX}/man1 - @cd ${DESTDIR}${MANPREFIX}/man1 && rm -f ${MAN1:=.1} - -.PHONY: all options clean dist install uninstall +include ${ROOT}/mk/dir.mk diff --git a/cmd/Makefile b/cmd/Makefile new file mode 100644 index 00000000..d0847597 --- /dev/null +++ b/cmd/Makefile @@ -0,0 +1,26 @@ +ROOT=.. +include ${ROOT}/mk/hdr.mk + +DIRS = wmii +TARG = wmii9menu \ + wmii9rc \ + wmiiloop \ + wmiir \ + wmiistartrc + +OFILES = util.o +FILTER = sed "s|CONFPREFIX|${CONFPREFIX}|g; \ + s|CONFVERSION|${CONFVERSION}|g; \ + s|P9PATHS|${P9PATHS}|g; \ + s|AWKPATH|${AWKPATH}|g" + +include ${ROOT}/mk/many.mk +include ${ROOT}/mk/dir.mk + +OWMIIR=${OFILES} ${LIBIXP} +wmiir.O: ${OWMIIR} + ${LINK} $@ $*.o ${OWMIIR} + +EXCFLAGS=${INCX11} +wmii9menu.O: + ${LINK} $@ $*.o ${LIBX11} diff --git a/util.c b/cmd/util.c similarity index 93% rename from util.c rename to cmd/util.c index 402310ca..c0b328f5 100644 --- a/util.c +++ b/cmd/util.c @@ -3,9 +3,10 @@ #include #include #include +#include #include #include -#include "wmii.h" +#include void fatal(const char *fmt, ...) { @@ -13,7 +14,7 @@ fatal(const char *fmt, ...) { int err; err = errno; - fprintf(stderr, "wmii: fatal: "); + fprintf(stderr, "%s: fatal: ", argv0); va_start(ap, fmt); vfprintf(stderr, fmt, ap); @@ -31,7 +32,7 @@ fatal(const char *fmt, ...) { void mfatal(char *name, uint size) { const char - couldnot[] = "wmii: fatal: Could not ", + couldnot[] = ": fatal: Could not ", paren[] = "() ", bytes[] = " bytes\n"; char sizestr[8]; @@ -43,6 +44,7 @@ mfatal(char *name, uint size) { size /= 10; } while(size > 0); + write(1, argv0, strlen(argv0)-1); write(1, couldnot, sizeof(couldnot)-1); write(1, name, strlen(name)); write(1, paren, sizeof(paren)-1); diff --git a/cmd/wmii/Makefile b/cmd/wmii/Makefile new file mode 100644 index 00000000..2d3747fc --- /dev/null +++ b/cmd/wmii/Makefile @@ -0,0 +1,26 @@ +ROOT= ../.. +include ${ROOT}/mk/hdr.mk + +TARG = wmii + +LIB = ${LIBIXP} +EXLDFLAGS = -lm ${LIBX11} +EXCFLAGS = ${INCX11} +OBJ = area \ + bar \ + client \ + column \ + draw \ + event \ + frame \ + fs \ + geom \ + key \ + main \ + mouse \ + rule \ + printevent\ + view \ + ../util + +include ${ROOT}/mk/one.mk diff --git a/area.c b/cmd/wmii/area.c similarity index 100% rename from area.c rename to cmd/wmii/area.c diff --git a/bar.c b/cmd/wmii/bar.c similarity index 100% rename from bar.c rename to cmd/wmii/bar.c diff --git a/client.c b/cmd/wmii/client.c similarity index 100% rename from client.c rename to cmd/wmii/client.c diff --git a/column.c b/cmd/wmii/column.c similarity index 100% rename from column.c rename to cmd/wmii/column.c diff --git a/draw.c b/cmd/wmii/draw.c similarity index 100% rename from draw.c rename to cmd/wmii/draw.c diff --git a/event.c b/cmd/wmii/event.c similarity index 99% rename from event.c rename to cmd/wmii/event.c index ea00fe0e..59ba455b 100644 --- a/event.c +++ b/cmd/wmii/event.c @@ -436,7 +436,7 @@ void (*handler[LASTEvent]) (XEvent *) = { }; void -check_x_event(IXPConn *c) { +check_x_event(IxpConn *c) { XEvent ev; while(XPending(blz.dpy)) { XNextEvent(blz.dpy, &ev); diff --git a/frame.c b/cmd/wmii/frame.c similarity index 100% rename from frame.c rename to cmd/wmii/frame.c diff --git a/fs.c b/cmd/wmii/fs.c similarity index 89% rename from fs.c rename to cmd/wmii/fs.c index 8c5cce22..212aa499 100644 --- a/fs.c +++ b/cmd/wmii/fs.c @@ -70,10 +70,10 @@ static char /* Global Vars */ /***************/ FileId *free_fileid; -P9Req *pending_event_reads; -P9Req *outgoing_event_reads; +Ixp9Req *pending_event_reads; +Ixp9Req *outgoing_event_reads; FidLink *pending_event_fids; -P9Srv p9srv = { +Ixp9Srv p9srv = { .open= fs_open, .walk= fs_walk, .read= fs_read, @@ -90,34 +90,34 @@ P9Srv p9srv = { /* ad-hoc file tree. Empty names ("") indicate dynamic entries to be filled * in by lookup_file */ static Dirtab -dirtab_root[]= {{".", P9QTDIR, FsRoot, 0500|P9DMDIR }, - {"rbar", P9QTDIR, FsDBars, 0700|P9DMDIR }, - {"lbar", P9QTDIR, FsDBars, 0700|P9DMDIR }, - {"client", P9QTDIR, FsDClients, 0500|P9DMDIR }, - {"tag", P9QTDIR, FsDTags, 0500|P9DMDIR }, - {"ctl", P9QTAPPEND, FsFRctl, 0600|P9DMAPPEND }, - {"colrules", P9QTFILE, FsFColRules, 0600 }, - {"event", P9QTFILE, FsFEvent, 0600 }, - {"keys", P9QTFILE, FsFKeys, 0600 }, - {"tagrules", P9QTFILE, FsFTagRules, 0600 }, +dirtab_root[]= {{".", QTDIR, FsRoot, 0500|P9_DMDIR }, + {"rbar", QTDIR, FsDBars, 0700|P9_DMDIR }, + {"lbar", QTDIR, FsDBars, 0700|P9_DMDIR }, + {"client", QTDIR, FsDClients, 0500|P9_DMDIR }, + {"tag", QTDIR, FsDTags, 0500|P9_DMDIR }, + {"ctl", QTAPPEND, FsFRctl, 0600|P9_DMAPPEND }, + {"colrules", QTFILE, FsFColRules, 0600 }, + {"event", QTFILE, FsFEvent, 0600 }, + {"keys", QTFILE, FsFKeys, 0600 }, + {"tagrules", QTFILE, FsFTagRules, 0600 }, {nil}}, -dirtab_clients[]={{".", P9QTDIR, FsDClients, 0500|P9DMDIR }, - {"", P9QTDIR, FsDClient, 0500|P9DMDIR }, +dirtab_clients[]={{".", QTDIR, FsDClients, 0500|P9_DMDIR }, + {"", QTDIR, FsDClient, 0500|P9_DMDIR }, {nil}}, -dirtab_client[]= {{".", P9QTDIR, FsDClient, 0500|P9DMDIR }, - {"ctl", P9QTAPPEND, FsFCctl, 0600|P9DMAPPEND }, - {"tags", P9QTFILE, FsFCtags, 0600 }, - {"props", P9QTFILE, FsFprops, 0400 }, +dirtab_client[]= {{".", QTDIR, FsDClient, 0500|P9_DMDIR }, + {"ctl", QTAPPEND, FsFCctl, 0600|P9_DMAPPEND }, + {"tags", QTFILE, FsFCtags, 0600 }, + {"props", QTFILE, FsFprops, 0400 }, {nil}}, -dirtab_bars[]= {{".", P9QTDIR, FsDBars, 0700|P9DMDIR }, - {"", P9QTFILE, FsFBar, 0600 }, +dirtab_bars[]= {{".", QTDIR, FsDBars, 0700|P9_DMDIR }, + {"", QTFILE, FsFBar, 0600 }, {nil}}, -dirtab_tags[]= {{".", P9QTDIR, FsDTags, 0500|P9DMDIR }, - {"", P9QTDIR, FsDTag, 0500|P9DMDIR }, +dirtab_tags[]= {{".", QTDIR, FsDTags, 0500|P9_DMDIR }, + {"", QTDIR, FsDTag, 0500|P9_DMDIR }, {nil}}, -dirtab_tag[]= {{".", P9QTDIR, FsDTag, 0500|P9DMDIR }, - {"ctl", P9QTAPPEND, FsFTctl, 0600|P9DMAPPEND }, - {"index", P9QTFILE, FsFTindex, 0400 }, +dirtab_tag[]= {{".", QTDIR, FsDTag, 0500|P9_DMDIR }, + {"ctl", QTAPPEND, FsFTctl, 0600|P9_DMAPPEND }, + {"index", QTFILE, FsFTindex, 0400 }, {nil}}; /* Writing the lists separately and using an array of their references * removes the need for casting and allows for C90 conformance, @@ -174,7 +174,7 @@ clone_files(FileId *f) { /* This should be moved to libixp */ static void -write_buf(P9Req *r, char *buf, uint len) { +write_buf(Ixp9Req *r, char *buf, uint len) { if(r->ifcall.offset >= len) return; @@ -188,10 +188,10 @@ write_buf(P9Req *r, char *buf, uint len) { /* This should be moved to libixp */ void -write_to_buf(P9Req *r, void *buf, uint *len, uint max) { +write_to_buf(Ixp9Req *r, void *buf, uint *len, uint max) { uint offset, count; - offset = (r->fid->omode&P9OAPPEND) ? *len : r->ifcall.offset; + offset = (r->fid->omode&P9_OAPPEND) ? *len : r->ifcall.offset; if(offset > *len || r->ifcall.count == 0) { r->ofcall.count = 0; return; @@ -215,7 +215,7 @@ write_to_buf(P9Req *r, void *buf, uint *len, uint max) { /* This should be moved to libixp */ void -data_to_cstring(P9Req *r) { +data_to_cstring(Ixp9Req *r) { uint i; i = r->ifcall.count; if(!i || r->ifcall.data[i - 1] != '\n') @@ -301,7 +301,7 @@ read_root_ctl() { void -respond_event(P9Req *r) { +respond_event(Ixp9Req *r) { FileId *f = r->fid->aux; if(f->content.buf) { r->ofcall.data = (void *)f->content.buf; @@ -320,7 +320,7 @@ write_event(char *format, ...) { va_list ap; FidLink *f; FileId *fi; - P9Req *req; + Ixp9Req *req; va_start(ap, format); vsnprintf(buffer, BUFFER_SIZE, format, ap); @@ -373,7 +373,7 @@ lookup_file(FileId *parent, char *name) Bar *b; uint id; - if(!(parent->tab.perm & P9DMDIR)) + if(!(parent->tab.perm & P9_DMDIR)) return nil; dir = dirtab[parent->tab.type]; last = &ret; @@ -508,7 +508,7 @@ verify_file(FileId *f) { /* Service Functions */ /*********************/ void -fs_attach(P9Req *r) { +fs_attach(Ixp9Req *r) { FileId *f = get_file(); f->tab = dirtab[FsRoot][0]; f->tab.name = estrdup("/"); @@ -521,7 +521,7 @@ fs_attach(P9Req *r) { } void -fs_walk(P9Req *r) { +fs_walk(Ixp9Req *r) { FileId *f, *nf; int i; @@ -588,7 +588,8 @@ fs_size(FileId *f) { } void -fs_stat(P9Req *r) { +fs_stat(Ixp9Req *r) { + Message m; Stat s; int size; uchar *buf; @@ -602,13 +603,16 @@ fs_stat(P9Req *r) { dostat(&s, fs_size(f), f); r->ofcall.nstat = size = ixp_sizeof_stat(&s); buf = emallocz(size); - r->ofcall.stat = buf; - ixp_pack_stat(&buf, &size, &s); + + m = ixp_message(buf, size, MsgPack); + ixp_pstat(&m, &s); + + r->ofcall.stat = m.data; respond(r, nil); } void -fs_read(P9Req *r) { +fs_read(Ixp9Req *r) { char *buf; FileId *f, *tf; int n, offset; @@ -622,12 +626,15 @@ fs_read(P9Req *r) { return; } - if(f->tab.perm & P9DMDIR && f->tab.perm & 0400) { + if(f->tab.perm & P9_DMDIR && f->tab.perm & 0400) { Stat s; + Message m; + offset = 0; size = r->ifcall.count; buf = emallocz(size); - r->ofcall.data = buf; + m = ixp_message(buf, size, MsgPack); + tf = f = lookup_file(f, nil); /* Note: f->tab.name == "." so we skip it */ for(f=f->next; f; f=f->next) { @@ -636,7 +643,7 @@ fs_read(P9Req *r) { if(offset >= r->ifcall.offset) { if(size < n) break; - ixp_pack_stat((uchar **)&buf, &size, &s); + ixp_pstat(&m, &s); } offset += n; } @@ -645,6 +652,7 @@ fs_read(P9Req *r) { free_file(f); } r->ofcall.count = r->ifcall.count - size; + r->ofcall.data = m.data; respond(r, nil); return; } @@ -709,7 +717,7 @@ fs_read(P9Req *r) { /* This function needs to be seriously cleaned up */ void -fs_write(P9Req *r) { +fs_write(Ixp9Req *r) { FileId *f; char *errstr = nil; uint i; @@ -802,7 +810,7 @@ fs_write(P9Req *r) { } void -fs_open(P9Req *r) { +fs_open(Ixp9Req *r) { FidLink *fl; FileId *f = r->fid->aux; @@ -819,19 +827,19 @@ fs_open(P9Req *r) { pending_event_fids = fl; break; } - if((r->ifcall.mode&3) == P9OEXEC) { + if((r->ifcall.mode&3) == P9_OEXEC) { respond(r, Enoperm); return; } - if((r->ifcall.mode&3) != P9OREAD && !(f->tab.perm & 0200)) { + if((r->ifcall.mode&3) != P9_OREAD && !(f->tab.perm & 0200)) { respond(r, Enoperm); return; } - if((r->ifcall.mode&3) != P9OWRITE && !(f->tab.perm & 0400)) { + if((r->ifcall.mode&3) != P9_OWRITE && !(f->tab.perm & 0400)) { respond(r, Enoperm); return; } - if((r->ifcall.mode&~(3|P9OAPPEND|P9OTRUNC))) { + if((r->ifcall.mode&~(3|P9_OAPPEND|P9_OTRUNC))) { respond(r, Enoperm); return; } @@ -839,7 +847,7 @@ fs_open(P9Req *r) { } void -fs_create(P9Req *r) { +fs_create(Ixp9Req *r) { FileId *f = r->fid->aux; switch(f->tab.type) { @@ -868,7 +876,7 @@ fs_create(P9Req *r) { } void -fs_remove(P9Req *r) { +fs_remove(Ixp9Req *r) { FileId *f = r->fid->aux; if(!verify_file(f)) { @@ -891,7 +899,7 @@ fs_remove(P9Req *r) { } void -fs_clunk(P9Req *r) { +fs_clunk(Ixp9Req *r) { Client *c; FidLink **fl, *ft; char *buf; @@ -941,11 +949,11 @@ fs_clunk(P9Req *r) { } void -fs_flush(P9Req *r) { - P9Req **i, **j; +fs_flush(Ixp9Req *r) { + Ixp9Req **i, **j; for(i=&pending_event_reads; i != &outgoing_event_reads; i=&outgoing_event_reads) - for(j=i; *j; j=(P9Req **)&(*j)->aux) + for(j=i; *j; j=(Ixp9Req **)&(*j)->aux) if(*j == r->oldreq) { *j = (*j)->aux; respond(r->oldreq, Einterrupted); diff --git a/geom.c b/cmd/wmii/geom.c similarity index 100% rename from geom.c rename to cmd/wmii/geom.c diff --git a/key.c b/cmd/wmii/key.c similarity index 100% rename from key.c rename to cmd/wmii/key.c diff --git a/main.c b/cmd/wmii/main.c similarity index 94% rename from main.c rename to cmd/wmii/main.c index f902473e..61ed9570 100644 --- a/main.c +++ b/cmd/wmii/main.c @@ -412,7 +412,7 @@ spawn_command(const char *cmd) { } void -check_9pcon(IXPConn *c) { +check_9pcon(IxpConn *c) { serve_9pcon(c); check_x_event(nil); } @@ -429,36 +429,23 @@ main(int argc, char *argv[]) { wmiirc = "wmiistartrc"; /* command line args */ - for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { - switch (argv[i][1]) { - case 'v': - printf("%s", version); - exit(0); - break; - case 'V': - verbose = True; - break; - case 'a': - if(argv[i][2] != '\0') - address = &argv[i][2]; - else if(++i < argc) - address = argv[i]; - else - usage(); - break; - case 'r': - if(argv[i][2] != '\0') - wmiirc = &argv[i][2]; - else if(++i < argc) - wmiirc = argv[i]; - else - usage(); - break; - default: - usage(); - break; - } - } + ARGBEGIN{ + case 'v': + printf("%s", version); + exit(0); + case 'V': + verbose = True; + break; + case 'a': + address = EARGF(usage()); + break; + case 'r': + wmiirc = EARGF(usage()); + break; + default: + usage(); + break; + }ARGEND; setlocale(LC_CTYPE, ""); starting = True; @@ -479,15 +466,15 @@ main(int argc, char *argv[]) { init_traps(); errstr = nil; - sock = ixp_create_sock(address, &errstr); + sock = ixp_dial(address); if(sock < 0) fatal("Can't create socket '%s': %s", address, errstr); if(wmiirc) spawn_command(wmiirc); - ixp_server_open_conn(&srv, sock, &p9srv, check_9pcon, nil); - ixp_server_open_conn(&srv, ConnectionNumber(blz.dpy), nil, check_x_event, nil); + ixp_listen(&srv, sock, &p9srv, check_9pcon, nil); + ixp_listen(&srv, ConnectionNumber(blz.dpy), nil, check_x_event, nil); view = nil; client = nil; @@ -579,7 +566,7 @@ main(int argc, char *argv[]) { write_event("FocusTag %s\n", screen->sel->name); check_x_event(nil); - errstr = ixp_server_loop(&srv); + errstr = ixp_serverloop(&srv); if(errstr) cleanup(); diff --git a/mouse.c b/cmd/wmii/mouse.c similarity index 100% rename from mouse.c rename to cmd/wmii/mouse.c diff --git a/printevent.c b/cmd/wmii/printevent.c similarity index 100% rename from printevent.c rename to cmd/wmii/printevent.c diff --git a/printevent.h b/cmd/wmii/printevent.h similarity index 100% rename from printevent.h rename to cmd/wmii/printevent.h diff --git a/rule.c b/cmd/wmii/rule.c similarity index 100% rename from rule.c rename to cmd/wmii/rule.c diff --git a/view.c b/cmd/wmii/view.c similarity index 100% rename from view.c rename to cmd/wmii/view.c diff --git a/wmii.h b/cmd/wmii/wmii.h similarity index 93% rename from wmii.h rename to cmd/wmii/wmii.h index f455e6df..3a1d42ca 100644 --- a/wmii.h +++ b/cmd/wmii/wmii.h @@ -9,6 +9,7 @@ #include #include +#include #define nil ((void*)0) #define nelem(ary) (sizeof(ary) / sizeof(*ary)) @@ -256,8 +257,8 @@ enum { BUFFER_SIZE = 8092 }; char buffer[BUFFER_SIZE]; /* IXP */ -IXPServer srv; -P9Srv p9srv; +IxpServer srv; +Ixp9Srv p9srv; /* X11 */ uint num_screens; @@ -354,7 +355,7 @@ char *parse_colors(char **buf, int *buflen, BlitzColor *col); /* event.c */ void dispatch_event(XEvent *e); -void check_x_event(IXPConn *c); +void check_x_event(IxpConn *c); uint flushevents(long even_mask, Bool dispatch); /* frame.c */ @@ -374,17 +375,17 @@ void update_frame_widget_colors(Frame *f); void check_frame_constraints(XRectangle *rect); /* fs.c */ -void fs_attach(P9Req *r); -void fs_clunk(P9Req *r); -void fs_create(P9Req *r); -void fs_flush(P9Req *r); +void fs_attach(Ixp9Req *r); +void fs_clunk(Ixp9Req *r); +void fs_create(Ixp9Req *r); +void fs_flush(Ixp9Req *r); void fs_freefid(Fid *f); -void fs_open(P9Req *r); -void fs_read(P9Req *r); -void fs_remove(P9Req *r); -void fs_stat(P9Req *r); -void fs_walk(P9Req *r); -void fs_write(P9Req *r); +void fs_open(Ixp9Req *r); +void fs_read(Ixp9Req *r); +void fs_remove(Ixp9Req *r); +void fs_stat(Ixp9Req *r); +void fs_walk(Ixp9Req *r); +void fs_write(Ixp9Req *r); void write_event(char *format, ...); /* geom.c */ @@ -414,19 +415,6 @@ void grab_button(Window w, uint button, ulong mod); void update_rules(Rule **rule, const char *data); void trim(char *str, const char *chars); -#define strlcat wmii_strlcat -/* util.c */ -uint tokenize(char *res[], uint reslen, char *str, char delim); -char *estrdup(const char *str); -void *erealloc(void *ptr, uint size); -void *emallocz(uint size); -void *emalloc(uint size); -void fatal(const char *fmt, ...); -int max(int a, int b); -int min(int a, int b); -char *str_nil(char *s); -uint strlcat(char *dst, const char *src, unsigned int siz); - /* view.c */ void arrange_view(View *v); void scale_view(View *v, float w); diff --git a/9menu.c b/cmd/wmii9menu.c similarity index 100% rename from 9menu.c rename to cmd/wmii9menu.c diff --git a/wmii9rc b/cmd/wmii9rc.sh similarity index 100% rename from wmii9rc rename to cmd/wmii9rc.sh diff --git a/wmiiloop b/cmd/wmiiloop.awk similarity index 100% rename from wmiiloop rename to cmd/wmiiloop.awk diff --git a/cmd/wmiir.c b/cmd/wmiir.c new file mode 100644 index 00000000..11030770 --- /dev/null +++ b/cmd/wmiir.c @@ -0,0 +1,321 @@ +/* Copyright ©2007 Kris Maglione + * See LICENSE file for license details. + */ +#include +#include +#include +#include +#include +#include +#include + +static IxpClient *client; + +static void +usage() { + fprintf(stderr, + "usage: %1$s [-a
] {create | read | ls [-ld] | remove | write} \n" + " %1$s [-a
] xwrite \n" + " %1$s -v\n", argv0); + exit(1); +} + +/* Utility Functions */ +static void +write_data(IxpCFid *fid) { + void *buf; + uint len; + + buf = ixp_emalloc(fid->iounit);; + while((len = read(0, buf, fid->iounit)) > 0) + if(ixp_write(fid, buf, len) != len) + fatal("cannot write file: %s\n", errstr); + /* do an explicit empty write when no writing has been done yet */ + if(fid->offset == 0) + if(ixp_write(fid, buf, 0) != 0) + fatal("cannot write file: %s\n", errstr); + free(buf); +} + +static int +comp_stat(const void *s1, const void *s2) { + Stat *st1, *st2; + + st1 = (Stat*)s1; + st2 = (Stat*)s2; + return strcmp(st1->name, st2->name); +} + +static void +setrwx(long m, char *s) { + static char *modes[] = { + "---", "--x", "-w-", + "-wx", "r--", "r-x", + "rw-", "rwx", + }; + strncpy(s, modes[m], 3); +} + +static char * +str_of_mode(uint mode) { + static char buf[16]; + + buf[0]='-'; + if(mode & P9_DMDIR) + buf[0]='d'; + buf[1]='-'; + setrwx((mode >> 6) & 7, &buf[2]); + setrwx((mode >> 3) & 7, &buf[5]); + setrwx((mode >> 0) & 7, &buf[8]); + buf[11] = 0; + return buf; +} + +static char * +str_of_time(uint val) { + static char buf[32]; + + ctime_r((time_t*)&val, buf); + buf[strlen(buf) - 1] = '\0'; + return buf; +} + +static void +print_stat(Stat *s, int details) { + if(details) + fprintf(stdout, "%s %s %s %5llu %s %s\n", str_of_mode(s->mode), + s->uid, s->gid, s->length, str_of_time(s->mtime), s->name); + else { + if((s->mode&P9_DMDIR) && strcmp(s->name, "/")) + fprintf(stdout, "%s/\n", s->name); + else + fprintf(stdout, "%s\n", s->name); + } +} + +/* Service Functions */ +static int +xwrite(int argc, char *argv[]) { + IxpCFid *fid; + char *file; + + ARGBEGIN{ + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + fid = ixp_open(client, file, P9_OWRITE); + if(fid == nil) + fatal("Can't open file '%s': %s\n", file, errstr); + + write_data(fid); + return 0; +} + +static int +xawrite(int argc, char *argv[]) { + IxpCFid *fid; + char *file, *buf, *arg; + int nbuf, mbuf, len; + + ARGBEGIN{ + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + fid = ixp_open(client, file, P9_OWRITE); + if(fid == nil) + fatal("Can't open file '%s': %s\n", file, errstr); + + nbuf = 0; + mbuf = 128; + buf = ixp_emalloc(mbuf); + while(argc) { + arg = ARGF(); + len = strlen(arg); + if(nbuf + len > mbuf) { + mbuf <<= 1; + buf = ixp_erealloc(buf, mbuf); + } + memcpy(buf+nbuf, arg, len); + nbuf += len; + if(argc) + buf[nbuf++] = ' '; + } + + if(ixp_write(fid, buf, nbuf) == -1) + fatal("cannot write file '%s': %s\n", file, errstr); + return 0; +} + +static int +xcreate(int argc, char *argv[]) { + IxpCFid *fid; + char *file; + + ARGBEGIN{ + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + fid = ixp_create(client, file, 0777, P9_OREAD); + if(fid == nil) + fatal("Can't create file '%s': %s\n", file, errstr); + + if((fid->qid.type&P9_DMDIR) == 0) + write_data(fid); + + return 0; +} + +static int +xremove(int argc, char *argv[]) { + char *file; + + ARGBEGIN{ + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + if(ixp_remove(client, file) == 0) + fatal("Can't remove file '%s': %s\n", file, errstr); + return 0; +} + +static int +xread(int argc, char *argv[]) { + IxpCFid *fid; + char *file, *buf; + int count; + + ARGBEGIN{ + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + fid = ixp_open(client, file, P9_OREAD); + if(fid == nil) + fatal("Can't open file '%s': %s\n", file, errstr); + + buf = ixp_emalloc(fid->iounit); + while((count = ixp_read(fid, buf, fid->iounit)) > 0) + write(1, buf, count); + + if(count == -1) + fatal("cannot read file/directory '%s': %s\n", file, errstr); + + return 0; +} + +static int +xls(int argc, char *argv[]) { + Message m; + Stat *stat; + IxpCFid *fid; + char *file, *buf; + int lflag, dflag, count, nstat, mstat, i; + + lflag = dflag = 0; + + ARGBEGIN{ + case 'l': + lflag++; + break; + case 'd': + dflag++; + break; + default: + usage(); + }ARGEND; + + file = EARGF(usage()); + + stat = ixp_stat(client, file); + if(stat == nil) + fatal("cannot stat file '%s': %s\n", file, errstr); + + if(dflag || (stat->mode&P9_DMDIR) == 0) { + print_stat(stat, lflag); + ixp_freestat(stat); + return 0; + } + ixp_freestat(stat); + + fid = ixp_open(client, file, P9_OREAD); + if(fid == nil) + fatal("Can't open file '%s': %s\n", file, errstr); + + nstat = 0; + mstat = 16; + stat = ixp_emalloc(sizeof(*stat) * mstat); + buf = ixp_emalloc(fid->iounit); + while((count = ixp_read(fid, buf, fid->iounit)) > 0) { + m = ixp_message(buf, count, MsgUnpack); + while(m.pos < m.end) { + if(nstat == mstat) { + mstat <<= 1; + stat = ixp_erealloc(stat, mstat); + } + ixp_pstat(&m, &stat[nstat++]); + } + } + + qsort(stat, nstat, sizeof(*stat), comp_stat); + for(i = 0; i < nstat; i++) { + print_stat(&stat[i], lflag); + ixp_freestat(&stat[i]); + } + free(stat); + + if(count == -1) + fatal("cannot read directory '%s': %s\n", file, errstr); + return 0; +} + +int +main(int argc, char *argv[]) { + int ret; + char *cmd, *address; + + address = getenv("WMII_ADDRESS"); + + ARGBEGIN{ + case 'v': + puts("ixpc-" VERSION ", ©2007 Kris Maglione\n"); + exit(0); + case 'a': + address = EARGF(usage()); + }ARGEND; + + cmd = EARGF(usage()); + + if(!address) + fatal("$WMII_ADDRESS not set\n"); + + client = ixp_mount(address); + if(client == nil) + fatal("%s\n", errstr); + + if(!strcmp(cmd, "create")) + ret = xcreate(argc, argv); + else if(!strcmp(cmd, "ls")) + ret = xls(argc, argv); + else if(!strcmp(cmd, "read")) + ret = xread(argc, argv); + else if(!strcmp(cmd, "remove")) + ret = xremove(argc, argv); + else if(!strcmp(cmd, "write")) + ret = xwrite(argc, argv); + else if(!strcmp(cmd, "xwrite")) + ret = xawrite(argc, argv); + else + usage(); + + ixp_unmount(client); + return ret; +} diff --git a/wmiistartrc b/cmd/wmiistartrc.sh similarity index 100% rename from wmiistartrc rename to cmd/wmiistartrc.sh diff --git a/config.mk b/config.mk index 9ad4dcc7..a3b04b15 100644 --- a/config.mk +++ b/config.mk @@ -1,35 +1,38 @@ -# wmii version -VERSION = $$(hg tip --template 'hg{rev}' 2>/dev/null) -CONFVERSION = 3.5 - # Customize below to fit your system # paths PREFIX = /usr/local -CONFPREFIX = ${PREFIX}/etc -MANPREFIX = ${PREFIX}/share/man +BIN = ${PREFIX}/bin +MAN = ${PREFIX}/share/man +ETC = ${PREFIX}/etc +LIBDIR = ${PREFIX}/lib +INCLUDE = ${PREFIX}/include + +# Includes and libs +INCS = -I. -I${ROOT}/include -I${INCLUDE} -I/usr/include +LIBS = -L/usr/lib -lc + +# Flags +CFLAGS = -g -Wall ${INCS} -DVERSION=\"${VERSION}\" +LDFLAGS = -g ${LIBS} + +# Compiler +CC = cc -c +# Linker (Under normal circumstances, this should *not* be 'ld') +LD = cc +# Other +AR = ar cr +RANLIB = ranlib + AWKPATH = /usr/bin/awk P9PATHS = /usr/local/plan9 /usr/local/9 /opt/plan9 /opt/9 /usr/plan9 /usr/9 -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib - -# includes and libs -INCS = -I. -I${PREFIX}/include -I/usr/include -I${X11INC} -LIBS = -L/usr/lib -lc -lm -L${X11LIB} -lX11 -LIBIXP = -L${PREFIX}/lib -lixp - -# flags -#CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -#LDFLAGS = ${LIBS} -CFLAGS = -g -Wall ${INCS} -DVERSION=\"${VERSION}\" -LDFLAGS = -g ${LIBS} +INCX11 = -I/usr/X11R6/include +LIBX11 = -L/usr/X11R6/lib -lX11 +LIBIXP = ${ROOT}/libixp/libixp.a # Solaris #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" #LDFLAGS = ${LIBS} -R${PREFIX}/lib #LDFLAGS += -lsocket -lnsl #CFLAGS += -xtarget=ultra - -# compiler and linker -CC = cc diff --git a/wmii.eps b/img/wmii.eps similarity index 100% rename from wmii.eps rename to img/wmii.eps diff --git a/wmii.mp b/img/wmii.mp similarity index 100% rename from wmii.mp rename to img/wmii.mp diff --git a/include/Makefile b/include/Makefile new file mode 100644 index 00000000..1362284b --- /dev/null +++ b/include/Makefile @@ -0,0 +1,6 @@ +ROOT= .. +include ${ROOT}/mk/hdr.mk + +HFILES = ixp.h ixp_fcall.h + +include ${ROOT}/mk/common.mk diff --git a/include/util.h b/include/util.h new file mode 100644 index 00000000..89eb5026 --- /dev/null +++ b/include/util.h @@ -0,0 +1,36 @@ +#define strlcat wmii_strlcat +/* util.c */ +uint tokenize(char *res[], uint reslen, char *str, char delim); +char *estrdup(const char *str); +void *erealloc(void *ptr, uint size); +void *emallocz(uint size); +void *emalloc(uint size); +void fatal(const char *fmt, ...); +int max(int a, int b); +int min(int a, int b); +char *str_nil(char *s); +uint strlcat(char *dst, const char *src, unsigned int siz); + +char *argv0; +#undef ARGBEGIN +#undef ARGEND +#undef ARGF +#undef EARGF +#define ARGBEGIN int _argi, _argtmp, _inargv=0; char *_argv; \ + if(!argv0)argv0=ARGF(); _inargv=1; \ + while(argc && argv[0][0] == '-') { \ + _argi=1; _argv=*argv++; argc++; \ + while(_argv[_argi]) switch(_argv[_argi++]) +#define ARGEND }_inargv=0;USED(_argtmp);USED(_argv);USED(_argi) +#define ARGF() ((_inargv && _argv[_argi]) ? \ + (_argtmp=_argi, _argi=strlen(_argv), _argv+_argtmp) \ + : ((argc > 0) ? (argc--, *argv++) : ((char*)0))) +#define EARGF(f) ((_inargv && _argv[_argi]) ? \ + (_argtmp=_argi, _argi=strlen(_argv), _argv+_argtmp) \ + : ((argc > 0) ? (argc--, *argv++) : ((f), (char*)0))) + +#undef USED +#undef SET +#define USED(x) if(x){}else +#define SET(x) ((x)=0) + diff --git a/man/Makefile b/man/Makefile new file mode 100644 index 00000000..c23ab7ad --- /dev/null +++ b/man/Makefile @@ -0,0 +1,14 @@ +ROOT=.. +include ${ROOT}/mk/hdr.mk + +TARG = wmii.1 \ + wmiiloop.1 \ + wmiir.1 \ + wmiiwm.1 + +FILTER = sed "s|CONFPREFIX|${CONFPREFIX}|g; \ + s|CONFVERSION|${CONFVERSION}|g; \ + s|P9PATHS|${P9PATHS}|g; \ + s|AWKPATH|${AWKPATH}|g" + +include ${ROOT}/mk/man.mk diff --git a/wmii.1 b/man/wmii.1 similarity index 100% rename from wmii.1 rename to man/wmii.1 diff --git a/wmiiloop.1 b/man/wmiiloop.1 similarity index 100% rename from wmiiloop.1 rename to man/wmiiloop.1 diff --git a/wmiir.1 b/man/wmiir.1 similarity index 100% rename from wmiir.1 rename to man/wmiir.1 diff --git a/wmiiwm.1 b/man/wmiiwm.1 similarity index 100% rename from wmiiwm.1 rename to man/wmiiwm.1 diff --git a/mk/common.mk b/mk/common.mk new file mode 100644 index 00000000..908f4456 --- /dev/null +++ b/mk/common.mk @@ -0,0 +1,18 @@ +all: + +install: all +depend: cleandep + +MANDIRS=${MAN}/man1 +mkdirs: + for i in ${BIN} ${ETC} ${MANDIRS} ${DIRS}; do \ + test -d $$i || echo MKDIR $$i; \ + mkdir -pm 0755 $$i; \ + done + +install: ${HFILES:.h=.install} + +cleandep: + rm .depend 2>/dev/null || true + +.PHONY: all options clean dist install uninstall depend cleandep diff --git a/mk/dir.mk b/mk/dir.mk new file mode 100644 index 00000000..2f238fdf --- /dev/null +++ b/mk/dir.mk @@ -0,0 +1,29 @@ +dall: + for i in ${DIRS}; do \ + if [ ! -d $$i ]; then echo Skipping nonexistent directory: $$i 1>&2; continue; fi; \ + echo MAKE all ${BASE}$$i/; \ + (cd $$i && ${MAKE} BASE="${BASE}$$i/" all) || exit $?; \ + done +dclean: + for i in ${DIRS}; do \ + if [ ! -d $$i ]; then echo Skipping nonexistent directory: $$i 1>&2; continue; fi; \ + echo MAKE clean ${BASE}$$i/; \ + (cd $$i && ${MAKE} BASE="${BASE}$$i/" clean) || exit $?; \ + done +dinstall: + for i in ${DIRS}; do \ + if [ ! -d $$i ]; then echo Skipping nonexistent directory: $$i 1>&2; continue; fi; \ + echo MAKE install ${BASE}$$i/; \ + (cd $$i && ${MAKE} BASE="${BASE}$$i/" install) || exit $?; \ + done +ddepend: + for i in ${DIRS}; do \ + if [ ! -d $$i ]; then echo Skipping nonexistent directory: $$i 1>&2; continue; fi; \ + echo MAKE depend ${BASE}$$i/; \ + (cd $$i && ${MAKE} BASE="${BASE}$$i/" depend) || exit $?; \ + done + +all: dall +clean: dclean +install: dinstall +depend: ddepend diff --git a/mk/hdr.mk b/mk/hdr.mk new file mode 100644 index 00000000..aeea7d4f --- /dev/null +++ b/mk/hdr.mk @@ -0,0 +1,60 @@ +.SILENT: +.SUFFIXES: .O .o .c .sh .rc .awk .1 .depend .install .clean +all: + +.c.o: + ${COMPILE} $@ $< + +.c.depend: + ${DEPEND} $< >>.depend + +.o.O: + ${LINK} $@ $< + +.awk.O: + echo FILTER ${BASE}$< + ${FILTER} $< >$@ + +.rc.O: + echo FILTER ${BASE}$< + ${FILTER} $< >$@ + +.sh.O: + echo FILTER ${BASE}$< + ${FILTER} $< >$@ + +.O.install: + echo INSTALL $* + cp -f $< ${BIN}/$* + chmod 0755 ${BIN}/$* + +.a.install: + echo INSTALL $< + cp -f $< ${LIBDIR}/$< + chmod 0644 ${LIBDIR}/$< + +.h.install: + echo INSTALL $< + cp -f $< ${INCLUDE}/$< + chmod 0644 ${INCLUDE}/$< + +.1.install: + echo INSTALL man $*'(1)' + ${FILTER} $< >${MAN}/man1/$< + chmod 0644 ${MAN}/man1/$< + +.O.clean: + rm $< || true 2>/dev/null + rm $*.o || true 2>/dev/null +.o.clean: + rm $< || true 2>/dev/null + +printinstall: +mkdirs: +clean: +install: printinstall mkdirs + +COMPILE= CC="${CC}" CFLAGS="${CFLAGS} ${EXCFLAGS}" ${ROOT}/util/compile +LINK= LD="${LD}" LDFLAGS="${LDFLAGS} ${EXLDFLAGS}" ${ROOT}/util/link + +include ${ROOT}/config.mk diff --git a/mk/lib.mk b/mk/lib.mk new file mode 100644 index 00000000..4bb7675d --- /dev/null +++ b/mk/lib.mk @@ -0,0 +1,24 @@ +LIB = ${TARG}.a +OFILES = ${OBJ:=.o} + +all: ${HFILES} ${LIB} + +install: ${TARG}.install +clean: libclean +depend: ${OBJ:=.depend} + +libclean: + for i in ${LIB} ${OFILES}; do \ + rm $$i; \ + done 2>/dev/null || true + +printinstall: + echo 'Install directories:' + echo ' Lib: ${LIBDIR}' + +${LIB}: ${OFILES} + @echo AR $@ + @${AR} $@ ${OFILES} + @${RANLIB} $@ + +include ${ROOT}/mk/common.mk diff --git a/mk/man.mk b/mk/man.mk new file mode 100644 index 00000000..a1a5de11 --- /dev/null +++ b/mk/man.mk @@ -0,0 +1,7 @@ +install: ${TARG:.1=.install} + +printinstall: + echo 'Install directories:' + echo ' Man: ${MAN}' + +include ${ROOT}/mk/common.mk diff --git a/mk/many.mk b/mk/many.mk new file mode 100644 index 00000000..48471a01 --- /dev/null +++ b/mk/many.mk @@ -0,0 +1,18 @@ +PROGS = ${TARG:=.O} + +all: ${PROGS} + +install: ${TARG:=.install} +clean: manyclean + +printinstall: + echo 'Install directories:' + echo ' Bin: ${BIN}' + +manyclean: + for i in ${TARG}; do \ + rm $$i.o; rm $$i.O; \ + done 2>/dev/null || true + +include ${ROOT}/mk/common.mk + diff --git a/mk/one.mk b/mk/one.mk new file mode 100644 index 00000000..17895a3c --- /dev/null +++ b/mk/one.mk @@ -0,0 +1,22 @@ +PROG = ${TARG}.O +OFILES = ${OBJ:=.o} + +all: ${PROG} + +install: ${TARG}.install +clean: oneclean +depend: ${OBJ:=.depend} + +printinstall: + echo 'Install directories:' + echo ' Bin: ${BIN}' + +oneclean: + for i in ${PROG} ${OFILES}; do \ + rm $$i; \ + done 2>/dev/null || true + +${PROG}: ${OFILES} ${LIB} + ${LINK} $@ ${OFILES} ${LIB} + +include ${ROOT}/mk/common.mk diff --git a/mk/wmii.mk b/mk/wmii.mk new file mode 100644 index 00000000..9fef6a46 --- /dev/null +++ b/mk/wmii.mk @@ -0,0 +1,2 @@ +VERSION = $$(hg tip --template 'hg{rev}' 2>/dev/null) +CONFVERSION = 3.5 diff --git a/util/compile b/util/compile new file mode 100755 index 00000000..00790d9e --- /dev/null +++ b/util/compile @@ -0,0 +1,20 @@ +#!/bin/sh -f + +outfile="$1"; shift + +# Derived from Russ Cox's 9c in plan9port. + +xtmp=/tmp/cc.$$.$USER.out + +echo CC ${BASE}$outfile +$CC -o $outfile $CFLAGS $@ 2>$xtmp +status=$? + +cat $xtmp \ +| egrep -v ': error: .Each undeclared identifier|: error: for each function it appears|is dangerous, better use|is almost always misused|: In function |: At top level:|support .long long.|In file included from| from|use of C99 long long|ISO C forbids conversion' \ +| sed 's/ .first use in this function.$//; s/\"\([^\"][^\"]*\)\", line \([0-9][0-9]*\)/\1:\2/g' \ +| uniq 1>&2 + +rm -f $xtmp $xtmp.status +exit $status + diff --git a/util/link b/util/link new file mode 100755 index 00000000..ace54069 --- /dev/null +++ b/util/link @@ -0,0 +1,31 @@ +#!/bin/sh -f + +outfile="$1"; shift + +# Derived from Russ Cox's 9l in plan9port. +ofiles="" +args="" +for i +do + case "$i" in + *.[ao]) + ofiles="$ofiles $i" + ;; + *) + args="$args $i" + ;; + esac +done + +xtmp=/tmp/ld.$$.$USER.out + +echo LD ${BASE}$outfile +$LD -o $outfile $ofiles $LDFLAGS $args >$xtmp 2>&1 +status=$? + +sed 's/.*: In function `[^:]*: *//' $xtmp | egrep . | +egrep -v 'is almost always misused|is dangerous, better use' +rm -f $xtmp + +exit $status + diff --git a/wmiir b/wmiir deleted file mode 100644 index b0071c26..00000000 --- a/wmiir +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -f -exec ixpc -a "$WMII_ADDRESS" $@