Changeset a33f0a6 in mainline for uspace/app
- Timestamp:
- 2011-08-03T17:34:57Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1940326
- Parents:
- 52a79081 (diff), 3fab770 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/app
- Files:
-
- 45 added
- 5 deleted
- 78 edited
- 3 moved
-
bdsh/Makefile (modified) (1 diff)
-
bdsh/cmds/builtin_cmds.c (modified) (3 diffs)
-
bdsh/cmds/builtins/cd/cd.c (modified) (1 diff)
-
bdsh/cmds/builtins/exit/exit.c (modified) (1 diff)
-
bdsh/cmds/cmds.h (modified) (3 diffs)
-
bdsh/cmds/mod_cmds.c (modified) (2 diffs)
-
bdsh/cmds/modules/bdd/bdd.c (modified) (1 diff)
-
bdsh/cmds/modules/cat/cat.c (modified) (6 diffs)
-
bdsh/cmds/modules/cp/cp.c (modified) (3 diffs)
-
bdsh/cmds/modules/help/help.c (modified) (1 diff)
-
bdsh/cmds/modules/kcon/kcon.c (modified) (4 diffs)
-
bdsh/cmds/modules/ls/ls.c (modified) (2 diffs)
-
bdsh/cmds/modules/mkdir/mkdir.c (modified) (1 diff)
-
bdsh/cmds/modules/mkfile/mkfile.c (modified) (1 diff)
-
bdsh/cmds/modules/module_aliases.h (modified) (1 diff)
-
bdsh/cmds/modules/modules.h (modified) (1 diff)
-
bdsh/cmds/modules/mount/mount.c (modified) (3 diffs)
-
bdsh/cmds/modules/pwd/pwd.c (modified) (1 diff)
-
bdsh/cmds/modules/rm/rm.c (modified) (1 diff)
-
bdsh/cmds/modules/sleep/sleep.c (modified) (1 diff)
-
bdsh/cmds/modules/touch/touch.c (modified) (1 diff)
-
bdsh/compl.c (added)
-
bdsh/compl.h (moved) (moved from kernel/test/fpu/sse1_skip.c ) (2 diffs)
-
bdsh/config.h (modified) (2 diffs)
-
bdsh/errors.c (modified) (2 diffs)
-
bdsh/errors.h (modified) (1 diff)
-
bdsh/errstr.h (modified) (1 diff)
-
bdsh/exec.c (modified) (5 diffs)
-
bdsh/exec.h (modified) (1 diff)
-
bdsh/input.c (modified) (7 diffs)
-
bdsh/input.h (modified) (2 diffs)
-
bdsh/scli.c (modified) (4 diffs)
-
bdsh/scli.h (modified) (3 diffs)
-
bdsh/tok.c (added)
-
bdsh/tok.h (added)
-
bdsh/util.c (modified) (2 diffs)
-
bdsh/util.h (modified) (1 diff)
-
blkdump/Makefile (moved) (moved from uspace/srv/hid/char_mouse/Makefile ) (1 diff)
-
blkdump/blkdump.c (added)
-
bnchmark/Makefile (moved) (moved from uspace/srv/hw/irc/fhc/Makefile ) (2 diffs)
-
bnchmark/bnchmark.c (added)
-
edit/edit.c (modified) (19 diffs)
-
edit/sheet.c (modified) (8 diffs)
-
edit/sheet.h (modified) (2 diffs)
-
ext2info/Makefile (added)
-
ext2info/ext2info.c (added)
-
getterm/version.c (modified) (1 diff)
-
init/Makefile (modified) (1 diff)
-
init/init.c (modified) (3 diffs)
-
klog/klog.c (modified) (4 diffs)
-
lsusb/Makefile (added)
-
lsusb/main.c (added)
-
mkbd/Makefile (added)
-
mkbd/main.c (added)
-
mkfat/mkfat.c (modified) (1 diff)
-
ping/ping.c (modified) (4 diffs)
-
redir/redir.c (modified) (3 diffs)
-
sbi/src/compat.h (modified) (2 diffs)
-
sbi/src/input.c (modified) (2 diffs)
-
sbi/src/list_t.h (modified) (1 diff)
-
sbi/src/os/helenos.c (modified) (2 diffs)
-
sbi/src/os/os.h (modified) (1 diff)
-
sbi/src/os/posix.c (modified) (1 diff)
-
taskdump/elf_core.c (modified) (15 diffs)
-
taskdump/include/elf.h (deleted)
-
taskdump/include/elf_core.h (modified) (1 diff)
-
taskdump/include/symtab.h (modified) (1 diff)
-
taskdump/symtab.c (modified) (8 diffs)
-
taskdump/taskdump.c (modified) (15 diffs)
-
tester/Makefile (modified) (2 diffs)
-
tester/console/console1.c (modified) (4 diffs)
-
tester/devs/devman2.c (added)
-
tester/devs/devman2.def (added)
-
tester/hw/misc/virtchar1.c (modified) (3 diffs)
-
tester/hw/serial/serial1.c (modified) (5 diffs)
-
tester/ipc/ping_pong.c (modified) (2 diffs)
-
tester/libext2/libext2_1.c (added)
-
tester/libext2/libext2_1.def (added)
-
tester/mm/common.c (added)
-
tester/mm/common.h (added)
-
tester/mm/malloc1.c (modified) (13 diffs)
-
tester/mm/malloc3.c (added)
-
tester/mm/malloc3.def (added)
-
tester/mm/mapping1.c (added)
-
tester/mm/mapping1.def (added)
-
tester/tester.c (modified) (1 diff)
-
tester/tester.h (modified) (3 diffs)
-
tester/util.c (added)
-
tester/util.h (added)
-
tester/util_functions.def (added)
-
testread/Makefile (added)
-
testread/testread.c (added)
-
tetris/Makefile (modified) (1 diff)
-
tetris/input.c (deleted)
-
tetris/input.h (deleted)
-
tetris/scores.c (modified) (4 diffs)
-
tetris/scores.h (modified) (2 diffs)
-
tetris/screen.c (modified) (12 diffs)
-
tetris/screen.h (modified) (5 diffs)
-
tetris/shapes.c (modified) (1 diff)
-
tetris/tetris.c (modified) (4 diffs)
-
tetris/tetris.h (modified) (1 diff)
-
top/Makefile (modified) (1 diff)
-
top/input.c (deleted)
-
top/input.h (deleted)
-
top/screen.c (modified) (6 diffs)
-
top/screen.h (modified) (2 diffs)
-
top/top.c (modified) (1 diff)
-
trace/ipc_desc.c (modified) (2 diffs)
-
trace/ipcp.c (modified) (7 diffs)
-
trace/syscalls.c (modified) (2 diffs)
-
trace/trace.c (modified) (23 diffs)
-
usbinfo/Makefile (added)
-
usbinfo/desctree.c (added)
-
usbinfo/dev.c (added)
-
usbinfo/dump.c (added)
-
usbinfo/hid.c (added)
-
usbinfo/info.c (added)
-
usbinfo/main.c (added)
-
usbinfo/usbinfo.h (added)
-
vuhid/Makefile (added)
-
vuhid/device.c (added)
-
vuhid/hids/bootkbd.c (added)
-
vuhid/ifaces.c (added)
-
vuhid/ifaces.h (added)
-
vuhid/items.h (added)
-
vuhid/main.c (added)
-
vuhid/report.h (added)
-
vuhid/stdreq.c (added)
-
vuhid/stdreq.h (added)
-
vuhid/virthid.h (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/Makefile
r52a79081 ra33f0a6 54 54 cmds/mod_cmds.c \ 55 55 cmds/builtin_cmds.c \ 56 compl.c \ 56 57 errors.c \ 57 58 input.c \ 58 59 util.c \ 59 60 exec.c \ 60 scli.c 61 scli.c \ 62 tok.c 61 63 62 64 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/bdsh/cmds/builtin_cmds.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 38 36 #include "cmds.h" 39 37 #include "builtin_aliases.h" 38 #include "scli.h" 40 39 41 40 extern volatile unsigned int cli_interactive; … … 97 96 cmd->help(extended); 98 97 return CL_EOK; 99 } else 98 } else { 100 99 return CL_ENOENT; 100 } 101 101 } 102 102 103 int run_builtin(int builtin, char *argv[], cliuser_t *usr )103 int run_builtin(int builtin, char *argv[], cliuser_t *usr, iostate_t *new_iostate) 104 104 { 105 int rc; 105 106 builtin_t *cmd = builtins; 106 107 107 108 cmd += builtin; 109 110 iostate_t *old_iostate = get_iostate(); 111 set_iostate(new_iostate); 112 113 if (NULL != cmd->entry) { 114 rc = ((int)cmd->entry(argv, usr)); 115 } else { 116 rc = CL_ENOENT; 117 } 118 119 set_iostate(old_iostate); 108 120 109 if (NULL != cmd->entry) 110 return((int)cmd->entry(argv, usr)); 111 112 return CL_ENOENT; 121 return rc; 113 122 } -
uspace/app/bdsh/cmds/builtins/cd/cd.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/builtins/exit/exit.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/cmds.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef CMDS_H 2 30 #define CMDS_H … … 59 87 extern char *alias_for_module(const char *); 60 88 extern int help_module(int, unsigned int); 61 extern int run_module(int, char *[] );89 extern int run_module(int, char *[], iostate_t *); 62 90 63 91 /* Prototypes for builtin launchers */ … … 67 95 extern char *alias_for_builtin(const char *); 68 96 extern int help_builtin(int, unsigned int); 69 extern int run_builtin(int, char *[], cliuser_t * );97 extern int run_builtin(int, char *[], cliuser_t *, iostate_t *); 70 98 71 99 #endif -
uspace/app/bdsh/cmds/mod_cmds.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 118 116 mod->help(extended); 119 117 return CL_EOK; 120 } else 118 } else { 121 119 return CL_ENOENT; 120 } 122 121 } 123 122 124 123 /* Invokes the module entry point modules[module], passing argv[] as an argument 125 124 * stack. */ 126 int run_module(int module, char *argv[] )125 int run_module(int module, char *argv[], iostate_t *new_iostate) 127 126 { 127 int rc; 128 128 module_t *mod = modules; 129 129 130 130 mod += module; 131 132 iostate_t *old_iostate = get_iostate(); 133 set_iostate(new_iostate); 131 134 132 if (NULL != mod->entry) 133 return ((int)mod->entry(argv)); 135 if (NULL != mod->entry) { 136 rc = ((int)mod->entry(argv)); 137 } else { 138 rc = CL_ENOENT; 139 } 140 141 set_iostate(old_iostate); 134 142 135 return CL_ENOENT;143 return rc; 136 144 } -
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r52a79081 ra33f0a6 102 102 } 103 103 104 rc = block_init( handle, 2048);104 rc = block_init(EXCHANGE_SERIALIZE, handle, 2048); 105 105 if (rc != EOK) { 106 106 printf("%s: Error initializing libblock.\n", cmdname); -
uspace/app/bdsh/cmds/modules/cat/cat.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * Copyright (c) 2011, Martin Sucha 3 4 * All rights reserved. 4 5 * 5 6 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions 8 * are met: 7 9 * 8 * Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * - Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * - The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 10 17 * 11 * Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * Neither the name of the original program's authors nor the names of its 16 * contributors may be used to endorse or promote products derived from this 17 * software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 28 */ 31 29 … … 64 62 static sysarg_t console_rows = 0; 65 63 static bool should_quit = false; 64 65 static console_ctrl_t *console = NULL; 66 66 67 67 static struct option const long_options[] = { … … 102 102 static void waitprompt() 103 103 { 104 console_set_pos(fphone(stdout), 0, console_rows-1); 105 console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0); 104 console_set_pos(console, 0, console_rows-1); 105 console_set_color(console, COLOR_BLUE, COLOR_WHITE, 0); 106 106 107 printf("ENTER/SPACE/PAGE DOWN - next page, " 107 108 "ESC/Q - quit, C - continue unpaged"); 108 109 fflush(stdout); 109 console_set_style(fphone(stdout), STYLE_NORMAL); 110 111 console_set_style(console, STYLE_NORMAL); 110 112 } 111 113 112 114 static void waitkey() 113 115 { 114 console_event_t ev;116 kbd_event_t ev; 115 117 116 118 while (true) { 117 if (!console_get_ event(fphone(stdin), &ev)) {119 if (!console_get_kbd_event(console, &ev)) { 118 120 return; 119 121 } … … 138 140 static void newpage() 139 141 { 140 console_clear( fphone(stdout));142 console_clear(console); 141 143 chars_remaining = console_cols; 142 lines_remaining = console_rows -1;144 lines_remaining = console_rows - 1; 143 145 } 144 146 … … 238 240 console_rows = 0; 239 241 should_quit = false; 242 console = console_init(stdin, stdout); 240 243 241 244 argc = cli_count_args(argv); … … 280 283 281 284 if (more) { 282 rc = console_get_size( fphone(stdout), &cols, &rows);285 rc = console_get_size(console, &cols, &rows); 283 286 if (rc != EOK) { 284 287 printf("%s - cannot get console size\n", cmdname); -
uspace/app/bdsh/cmds/modules/cp/cp.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 73 71 size_t blen, int vb) 74 72 { 75 int fd1, fd2, bytes = 0;76 off64_t total = 0;73 int fd1, fd2, bytes; 74 off64_t total; 77 75 int64_t copied = 0; 78 76 char *buff = NULL; … … 106 104 } 107 105 108 for (;;) { 109 ssize_t res; 110 size_t written = 0; 111 112 bytes = read(fd1, buff, blen); 113 if (bytes <= 0) 106 while ((bytes = read_all(fd1, buff, blen)) > 0) { 107 if ((bytes = write_all(fd2, buff, bytes)) < 0) 114 108 break; 115 109 copied += bytes; 116 res = bytes;117 do {118 /*119 * Theoretically, it may not be enough to call write()120 * only once. Also the previous read() may have121 * returned less data than requested.122 */123 bytes = write(fd2, buff + written, res);124 if (bytes < 0)125 goto err;126 written += bytes;127 res -= bytes;128 } while (res > 0);129 130 /* TODO: re-insert assert() once this is stand alone,131 * removed as abort() exits the entire shell132 */133 if (res != 0) {134 printf("\n%zd more bytes than actually exist were copied\n", res);135 goto err;136 }137 110 } 138 111 139 112 if (bytes < 0) { 140 err:141 113 printf("\nError copying %s, (%d)\n", src, bytes); 142 114 copied = bytes; -
uspace/app/bdsh/cmds/modules/help/help.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/modules/kcon/kcon.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 32 30 #include <stdlib.h> 33 31 #include <io/console.h> 34 #include <vfs/vfs.h>35 32 #include "config.h" 36 33 #include "util.h" … … 42 39 static const char *cmdname = "kcon"; 43 40 44 /* Disp ayshelp for kcon in various levels */41 /* Display help for kcon in various levels */ 45 42 void help_cmd_kcon(unsigned int level) 46 43 { 47 44 printf("`kcon' switches to the kernel debug console.\n"); 48 49 if (level != HELP_SHORT) { 50 printf("Usage: %s\n", cmdname); 51 } 52 45 46 if (level != HELP_SHORT) 47 printf("Usage: %s\n", cmdname); 48 53 49 return; 54 50 } … … 57 53 int cmd_kcon(char **argv) 58 54 { 59 unsigned int argc; 60 61 argc = cli_count_args(argv); 62 55 unsigned int argc = cli_count_args(argv); 56 63 57 if (argc != 1) { 64 58 printf("%s - incorrect number of arguments. Try `%s --help'\n", 65 cmdname, cmdname);59 cmdname, cmdname); 66 60 return CMD_FAILURE; 67 61 } 68 69 console_kcon_enable(fphone(stdout)); 70 71 return CMD_SUCCESS; 62 63 if (console_kcon()) 64 return CMD_SUCCESS; 65 else 66 return CMD_FAILURE; 72 67 } 73 -
uspace/app/bdsh/cmds/modules/ls/ls.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 171 169 172 170 /* fill the name field */ 173 tosort[nbdirs].name = (char *) malloc(str_ length(dp->d_name) + 1);171 tosort[nbdirs].name = (char *) malloc(str_size(dp->d_name) + 1); 174 172 if (!tosort[nbdirs].name) { 175 173 cli_error(CL_ENOMEM, "ls: failed to scan %s", d); 176 174 goto out; 177 175 } 178 179 str_cpy(tosort[nbdirs].name, str_ length(dp->d_name) + 1, dp->d_name);176 177 str_cpy(tosort[nbdirs].name, str_size(dp->d_name) + 1, dp->d_name); 180 178 len = snprintf(buff, PATH_MAX - 1, "%s/%s", d, tosort[nbdirs].name); 181 179 buff[len] = '\0'; -
uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 31 28 32 29 #include <stdio.h> -
uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
r52a79081 ra33f0a6 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 29 28 30 29 #include <stdio.h> -
uspace/app/bdsh/cmds/modules/module_aliases.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef MODULE_ALIASES_H 2 30 #define MODULE_ALIASES_H -
uspace/app/bdsh/cmds/modules/modules.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef MODULES_H 2 30 #define MODULES_H -
uspace/app/bdsh/cmds/modules/mount/mount.c
r52a79081 ra33f0a6 51 51 { 52 52 static char helpfmt[] = 53 "Usage: %s <fstype> <mp> <dev>[<moptions>]\n";53 "Usage: %s <fstype> <mp> [dev] [<moptions>]\n"; 54 54 if (level == HELP_SHORT) { 55 55 printf("'%s' mounts a file system.\n", cmdname); … … 66 66 unsigned int argc; 67 67 const char *mopts = ""; 68 const char *dev = ""; 68 69 int rc, c, opt_ind; 69 70 … … 79 80 } 80 81 81 if ((argc < 4) || (argc > 5)) {82 if ((argc < 3) || (argc > 5)) { 82 83 printf("%s: invalid number of arguments. Try `mount --help'\n", 83 84 cmdname); 84 85 return CMD_FAILURE; 85 86 } 87 if (argc > 3) 88 dev = argv[3]; 86 89 if (argc == 5) 87 90 mopts = argv[4]; 88 91 89 rc = mount(argv[1], argv[2], argv[3], mopts, 0);92 rc = mount(argv[1], argv[2], dev, mopts, 0); 90 93 if (rc != EOK) { 91 94 printf("Unable to mount %s filesystem to %s on %s (rc=%d)\n", -
uspace/app/bdsh/cmds/modules/pwd/pwd.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/modules/rm/rm.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/modules/sleep/sleep.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/cmds/modules/touch/touch.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 -
uspace/app/bdsh/compl.h
r52a79081 ra33f0a6 1 1 /* 2 * Copyright (c) 200 9 Martin Decky2 * Copyright (c) 2008 Tim Post 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 #include <test.h> 29 #ifndef COMPL_H 30 #define COMPL_H 30 31 31 const char *test_sse1(void) 32 { 33 return NULL; 34 } 32 #include <tinput.h> 33 34 extern tinput_compl_ops_t compl_ops; 35 36 #endif -
uspace/app/bdsh/config.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 /* Various things that are used in many places including a few 2 30 * tidbits left over from autoconf prior to the HelenOS port */ … … 11 39 #define EXIT_FAILURE 1 12 40 #endif 13 14 /* Work around for getenv() */15 #define PATH "/srv:/app"16 #define PATH_DELIM ":"17 41 18 42 /* Used in many places */ -
uspace/app/bdsh/errors.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 38 36 #include "errors.h" 39 37 #include "errstr.h" 38 #include "scli.h" 40 39 41 40 volatile int cli_errno = CL_EOK; -
uspace/app/bdsh/errors.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef ERRORS_H 2 30 #define ERRORS_H -
uspace/app/bdsh/errstr.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef ERRSTR_H 2 30 #define ERRSTR_H -
uspace/app/bdsh/exec.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 54 52 static int try_access(const char *); 55 53 54 const char *search_dir[] = { "/app", "/srv", NULL }; 55 56 56 /* work-around for access() */ 57 57 static int try_access(const char *f) … … 71 71 static char *find_command(char *cmd) 72 72 { 73 char *path_tok; 74 char *path[PATH_MAX]; 75 int n = 0, i = 0; 76 size_t x = str_size(cmd) + 2; 73 size_t i; 77 74 78 75 found = (char *)malloc(PATH_MAX); … … 83 80 } 84 81 85 path_tok = str_dup(PATH);86 87 /* Extract the PATH env to a path[] array */88 path[n] = strtok(path_tok, PATH_DELIM);89 while (NULL != path[n]) {90 if ((str_size(path[n]) + x ) > PATH_MAX) {91 cli_error(CL_ENOTSUP,92 "Segment %d of path is too large, search ends at segment %d",93 n, n-1);94 break;95 }96 path[++n] = strtok(NULL, PATH_DELIM);97 }98 99 82 /* We now have n places to look for the command */ 100 for (i =0; path[i]; i++) {83 for (i = 0; search_dir[i] != NULL; i++) { 101 84 memset(found, 0, sizeof(found)); 102 snprintf(found, PATH_MAX, "%s/%s", path[i], cmd);85 snprintf(found, PATH_MAX, "%s/%s", search_dir[i], cmd); 103 86 if (-1 != try_access(found)) { 104 free(path_tok);105 87 return (char *) found; 106 88 } … … 108 90 109 91 /* We didn't find it, just give it back as-is. */ 110 free(path_tok);111 92 return (char *) cmd; 112 93 } 113 94 114 unsigned int try_exec(char *cmd, char **argv )95 unsigned int try_exec(char *cmd, char **argv, iostate_t *io) 115 96 { 116 97 task_id_t tid; 117 98 task_exit_t texit; 118 99 char *tmp; 119 int rc, retval; 100 int rc, retval, i; 101 fdi_node_t file_nodes[3]; 102 fdi_node_t *file_nodes_p[4]; 103 FILE *files[3]; 120 104 121 105 tmp = str_dup(find_command(cmd)); 122 106 free(found); 107 108 files[0] = io->stdin; 109 files[1] = io->stdout; 110 files[2] = io->stderr; 111 112 for (i = 0; i < 3 && files[i] != NULL; i++) { 113 if (fnode(files[i], &file_nodes[i]) == EOK) { 114 file_nodes_p[i] = &file_nodes[i]; 115 } 116 else { 117 file_nodes_p[i] = NULL; 118 } 119 } 120 file_nodes_p[i] = NULL; 123 121 124 rc = task_spawnv (&tid, tmp, (const char **) argv);122 rc = task_spawnvf(&tid, tmp, (const char **) argv, file_nodes_p); 125 123 free(tmp); 126 124 -
uspace/app/bdsh/exec.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef EXEC_H 2 30 #define EXEC_H 3 31 4 32 #include <task.h> 33 #include "scli.h" 5 34 6 extern unsigned int try_exec(char *, char **); 35 extern const char *search_dir[]; 36 37 extern unsigned int try_exec(char *, char **, iostate_t *); 7 38 8 39 #endif -
uspace/app/bdsh/input.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 3 * Copyright (c) 2011 Jiri Svoboda 2 4 * All rights reserved. 3 5 * 4 6 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 7 * modification, are permitted provided that the following conditions 8 * are met: 6 9 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 10 * - Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * - Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * - The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 9 17 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 28 */ 30 29 … … 45 44 46 45 #include "config.h" 46 #include "compl.h" 47 47 #include "util.h" 48 48 #include "scli.h" … … 50 50 #include "errors.h" 51 51 #include "exec.h" 52 #include "tok.h" 52 53 53 54 extern volatile unsigned int cli_quit; … … 55 56 /** Text input field. */ 56 57 static tinput_t *tinput; 58 59 /* Private helpers */ 60 static int run_command(char **, cliuser_t *, iostate_t *); 61 static void print_pipe_usage(void); 57 62 58 63 /* Tokenizes input from console, sees if the first word is a built-in, if so 59 64 * invokes the built-in entry point (a[0]) passing all arguments in a[] to 60 65 * the handler */ 61 int tok_input(cliuser_t *usr)66 int process_input(cliuser_t *usr) 62 67 { 63 68 char *cmd[WORD_MAX]; 64 int n = 0, i = 0;65 69 int rc = 0; 66 char *tmp; 70 tokenizer_t tok; 71 int i, pipe_count, processed_pipes; 72 int pipe_pos[2]; 73 char **actual_cmd; 74 char *redir_from = NULL; 75 char *redir_to = NULL; 67 76 68 77 if (NULL == usr->line) 69 78 return CL_EFAIL; 70 79 71 tmp = str_dup(usr->line); 72 73 cmd[n] = strtok(tmp, " "); 74 while (cmd[n] && n < WORD_MAX) { 75 cmd[++n] = strtok(NULL, " "); 76 } 77 78 /* We have rubbish */ 79 if (NULL == cmd[0]) { 80 rc = CL_ENOENT; 81 goto finit; 82 } 83 84 /* Its a builtin command ? */ 85 if ((i = (is_builtin(cmd[0]))) > -1) { 86 rc = run_builtin(i, cmd, usr); 87 goto finit; 88 /* Its a module ? */ 89 } else if ((i = (is_module(cmd[0]))) > -1) { 90 rc = run_module(i, cmd); 91 goto finit; 92 } 93 94 /* See what try_exec thinks of it */ 95 rc = try_exec(cmd[0], cmd); 96 80 rc = tok_init(&tok, usr->line, cmd, WORD_MAX); 81 if (rc != EOK) { 82 goto finit; 83 } 84 85 rc = tok_tokenize(&tok); 86 if (rc != EOK) { 87 goto finit; 88 } 89 90 /* Until full support for pipes is implemented, allow for a simple case: 91 * [from <file> |] command [| to <file>] 92 * 93 * First find the pipes and check that there are no more 94 */ 95 int cmd_length = 0; 96 for (i = 0, pipe_count = 0; cmd[i] != NULL; i++, cmd_length++) { 97 if (cmd[i][0] == '|') { 98 if (pipe_count >= 2) { 99 print_pipe_usage(); 100 rc = ENOTSUP; 101 goto finit; 102 } 103 pipe_pos[pipe_count] = i; 104 pipe_count++; 105 } 106 } 107 108 actual_cmd = cmd; 109 processed_pipes = 0; 110 111 /* Check if the first part (from <file> |) is present */ 112 if (pipe_count > 0 && pipe_pos[0] == 2 && str_cmp(cmd[0], "from") == 0) { 113 /* Ignore the first three tokens (from, file, pipe) and set from */ 114 redir_from = cmd[1]; 115 actual_cmd = cmd + 3; 116 processed_pipes++; 117 } 118 119 /* Check if the second part (| to <file>) is present */ 120 if ((pipe_count - processed_pipes) > 0 && 121 pipe_pos[processed_pipes] == cmd_length - 3 && 122 str_cmp(cmd[cmd_length-2], "to") == 0) { 123 /* Ignore the last three tokens (pipe, to, file) and set to */ 124 redir_to = cmd[cmd_length-1]; 125 cmd[cmd_length-3] = NULL; 126 cmd_length -= 3; 127 processed_pipes++; 128 } 129 130 if (processed_pipes != pipe_count) { 131 print_pipe_usage(); 132 rc = ENOTSUP; 133 goto finit; 134 } 135 136 if (actual_cmd[0] == NULL) { 137 print_pipe_usage(); 138 rc = ENOTSUP; 139 goto finit; 140 } 141 142 iostate_t new_iostate = { 143 .stdin = stdin, 144 .stdout = stdout, 145 .stderr = stderr 146 }; 147 148 FILE *from = NULL; 149 FILE *to = NULL; 150 151 if (redir_from) { 152 from = fopen(redir_from, "r"); 153 if (from == NULL) { 154 printf("Cannot open file %s\n", redir_from); 155 rc = errno; 156 goto finit_with_files; 157 } 158 new_iostate.stdin = from; 159 } 160 161 162 if (redir_to) { 163 to = fopen(redir_to, "w"); 164 if (to == NULL) { 165 printf("Cannot open file %s\n", redir_to); 166 rc = errno; 167 goto finit_with_files; 168 } 169 new_iostate.stdout = to; 170 } 171 172 rc = run_command(actual_cmd, usr, &new_iostate); 173 174 finit_with_files: 175 if (from != NULL) { 176 fclose(from); 177 } 178 if (to != NULL) { 179 fclose(to); 180 } 181 97 182 finit: 98 183 if (NULL != usr->line) { … … 100 185 usr->line = (char *) NULL; 101 186 } 102 if (NULL != tmp) 103 free(tmp); 187 tok_fini(&tok); 104 188 105 189 return rc; 190 } 191 192 void print_pipe_usage() 193 { 194 printf("Invalid syntax!\n"); 195 printf("Usage of redirection (pipes in the future):\n"); 196 printf("from filename | command ...\n"); 197 printf("from filename | command ... | to filename\n"); 198 printf("command ... | to filename\n"); 199 200 } 201 202 int run_command(char **cmd, cliuser_t *usr, iostate_t *new_iostate) 203 { 204 int id = 0; 205 206 /* We have rubbish */ 207 if (NULL == cmd[0]) { 208 return CL_ENOENT; 209 } 210 211 /* Is it a builtin command ? */ 212 if ((id = (is_builtin(cmd[0]))) > -1) { 213 return run_builtin(id, cmd, usr, new_iostate); 214 } 215 216 /* Is it a module ? */ 217 if ((id = (is_module(cmd[0]))) > -1) { 218 return run_module(id, cmd, new_iostate); 219 } 220 221 /* See what try_exec thinks of it */ 222 return try_exec(cmd[0], cmd, new_iostate); 106 223 } 107 224 … … 110 227 char *str; 111 228 int rc; 112 113 fflush(stdout); 114 console_set_style(fphone(stdout), STYLE_EMPHASIS); 115 printf("%s", usr->prompt); 116 fflush(stdout); 117 console_set_style(fphone(stdout), STYLE_NORMAL); 229 230 tinput_set_prompt(tinput, usr->prompt); 118 231 119 232 rc = tinput_read(tinput, &str); … … 148 261 } 149 262 263 tinput_set_compl_ops(tinput, &compl_ops); 264 150 265 return 0; 151 266 } -
uspace/app/bdsh/input.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef INPUT_H 2 30 #define INPUT_H … … 7 35 8 36 extern void get_input(cliuser_t *); 9 extern int tok_input(cliuser_t *);37 extern int process_input(cliuser_t *); 10 38 extern int input_init(void); 11 39 -
uspace/app/bdsh/scli.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> 1 /* 2 * Copyright (c) 2008 Tim Post 2 3 * All rights reserved. 3 4 * 4 5 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 6 8 * 7 * Redistributions of source code must retain the above copyright notice, this 8 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 9 16 * 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * Neither the name of the original program's authors nor the names of its 15 * contributors may be used to endorse or promote products derived from this 16 * software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 27 */ 30 28 … … 42 40 /* See scli.h */ 43 41 static cliuser_t usr; 42 static iostate_t *iostate; 43 static iostate_t stdiostate; 44 44 45 45 /* Globals that are modified during start-up that modules/builtins … … 82 82 } 83 83 84 iostate_t *get_iostate(void) 85 { 86 return iostate; 87 } 88 89 90 void set_iostate(iostate_t *ios) 91 { 92 iostate = ios; 93 stdin = ios->stdin; 94 stdout = ios->stdout; 95 stderr = ios->stderr; 96 } 97 84 98 int main(int argc, char *argv[]) 85 99 { 86 100 int ret = 0; 101 102 stdiostate.stdin = stdin; 103 stdiostate.stdout = stdout; 104 stdiostate.stderr = stderr; 105 iostate = &stdiostate; 87 106 88 107 if (cli_init(&usr)) … … 92 111 get_input(&usr); 93 112 if (NULL != usr.line) { 94 ret = tok_input(&usr);113 ret = process_input(&usr); 95 114 cli_set_prompt(&usr); 96 115 usr.lasterr = ret; -
uspace/app/bdsh/scli.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef SCLI_H 2 30 #define SCLI_H … … 4 32 #include "config.h" 5 33 #include <stdint.h> 34 #include <stdio.h> 6 35 7 36 typedef struct { … … 13 42 } cliuser_t; 14 43 44 typedef struct { 45 FILE *stdin; 46 FILE *stdout; 47 FILE *stderr; 48 } iostate_t; 49 15 50 extern const char *progname; 16 51 52 extern iostate_t *get_iostate(void); 53 extern void set_iostate(iostate_t *); 54 17 55 #endif -
uspace/app/bdsh/util.c
r52a79081 ra33f0a6 1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> - All rights reserved 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 2 4 * 3 5 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions 7 * are met: 5 8 * 6 * Redistributions of source code must retain the above copyright notice, this 7 * list of conditions and the following disclaimer. 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 8 16 * 9 * Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 * and/or other materials provided with the distribution. 12 * 13 * Neither the name of the original program's authors nor the names of its 14 * contributors may be used to endorse or promote products derived from this 15 * software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 27 */ 29 28 … … 69 68 return 0; 70 69 } 71 72 -
uspace/app/bdsh/util.h
r52a79081 ra33f0a6 1 /* 2 * Copyright (c) 2008 Tim Post 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #ifndef UTIL_H 2 30 #define UTIL_H -
uspace/app/blkdump/Makefile
r52a79081 ra33f0a6 28 28 # 29 29 30 USPACE_PREFIX = ../../.. 31 EXTRA_CFLAGS = -Iinclude 32 BINARY = char_ms 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBBLOCK_PREFIX)/libblock.a 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) 33 BINARY = blkdump 33 34 34 35 SOURCES = \ 35 proto/ps2.c \ 36 char_mouse.c \ 37 chardev.c 36 blkdump.c 38 37 39 38 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/bnchmark/Makefile
r52a79081 ra33f0a6 1 1 # 2 # Copyright (c) 2005 Martin Decky 3 # Copyright (c) 2007 Jakub Jermar 2 # Copyright (c) 2011 Martin Sucha 4 3 # All rights reserved. 5 4 # … … 28 27 # 29 28 30 USPACE_PREFIX = ../.. /../..31 BINARY = fhc29 USPACE_PREFIX = ../.. 30 BINARY = bnchmark 32 31 33 32 SOURCES = \ 34 fhc.c33 bnchmark.c 35 34 36 35 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/edit/edit.c
r52a79081 ra33f0a6 94 94 } doc_t; 95 95 96 static intcon;96 static console_ctrl_t *con; 97 97 static doc_t doc; 98 98 static bool done; … … 115 115 static void cursor_setvis(bool visible); 116 116 117 static void key_handle_unmod( console_event_t const *ev);118 static void key_handle_ctrl( console_event_t const *ev);119 static void key_handle_shift( console_event_t const *ev);117 static void key_handle_unmod(kbd_event_t const *ev); 118 static void key_handle_ctrl(kbd_event_t const *ev); 119 static void key_handle_shift(kbd_event_t const *ev); 120 120 static void key_handle_movement(unsigned int key, bool shift); 121 121 … … 158 158 int main(int argc, char *argv[]) 159 159 { 160 console_event_t ev;160 kbd_event_t ev; 161 161 coord_t coord; 162 162 bool new_file; … … 164 164 spt_t pt; 165 165 166 con = fphone(stdout);166 con = console_init(stdin, stdout); 167 167 console_clear(con); 168 168 … … 219 219 220 220 while (!done) { 221 console_get_ event(con, &ev);221 console_get_kbd_event(con, &ev); 222 222 pane.rflags = 0; 223 223 … … 277 277 278 278 /** Handle key without modifier. */ 279 static void key_handle_unmod( console_event_t const *ev)279 static void key_handle_unmod(kbd_event_t const *ev) 280 280 { 281 281 switch (ev->key) { … … 320 320 321 321 /** Handle Shift-key combination. */ 322 static void key_handle_shift( console_event_t const *ev)322 static void key_handle_shift(kbd_event_t const *ev) 323 323 { 324 324 switch (ev->key) { … … 344 344 345 345 /** Handle Ctrl-key combination. */ 346 static void key_handle_ctrl( console_event_t const *ev)346 static void key_handle_ctrl(kbd_event_t const *ev) 347 347 { 348 348 switch (ev->key) { … … 497 497 static char *filename_prompt(char const *prompt, char const *init_value) 498 498 { 499 console_event_t ev;499 kbd_event_t ev; 500 500 char *str; 501 501 wchar_t buffer[INFNAME_MAX_LEN + 1]; … … 517 517 518 518 while (!done) { 519 console_get_ event(con, &ev);519 console_get_kbd_event(con, &ev); 520 520 521 521 if (ev.type == KEY_PRESS) { … … 531 531 if (nc > 0) { 532 532 putchar('\b'); 533 fflush(stdout);533 console_flush(con); 534 534 --nc; 535 535 } … … 541 541 if (ev.c >= 32 && nc < max_len) { 542 542 putchar(ev.c); 543 fflush(stdout);543 console_flush(con); 544 544 buffer[nc++] = ev.c; 545 545 } … … 689 689 for (j = 0; j < scr_columns; ++j) 690 690 putchar(' '); 691 fflush(stdout);691 console_flush(con); 692 692 } 693 693 … … 757 757 if (coord_cmp(&csel_start, &rbc) <= 0 && 758 758 coord_cmp(&rbc, &csel_end) < 0) { 759 fflush(stdout);759 console_flush(con); 760 760 console_set_style(con, STYLE_SELECTED); 761 fflush(stdout);761 console_flush(con); 762 762 } 763 763 … … 768 768 while (pos < size) { 769 769 if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) { 770 fflush(stdout);770 console_flush(con); 771 771 console_set_style(con, STYLE_SELECTED); 772 fflush(stdout);772 console_flush(con); 773 773 } 774 774 775 775 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 776 fflush(stdout);776 console_flush(con); 777 777 console_set_style(con, STYLE_NORMAL); 778 fflush(stdout);778 console_flush(con); 779 779 } 780 780 … … 794 794 795 795 if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) { 796 fflush(stdout);796 console_flush(con); 797 797 console_set_style(con, STYLE_NORMAL); 798 fflush(stdout);798 console_flush(con); 799 799 } 800 800 … … 808 808 for (j = 0; j < fill; ++j) 809 809 putchar(' '); 810 fflush(stdout);810 console_flush(con); 811 811 console_set_style(con, STYLE_NORMAL); 812 812 } … … 833 833 int pos = scr_columns - 1 - n; 834 834 printf("%*s", pos, ""); 835 fflush(stdout);835 console_flush(con); 836 836 console_set_style(con, STYLE_NORMAL); 837 837 … … 1158 1158 int pos = -(scr_columns - 3); 1159 1159 printf(" %*s ", pos, str); 1160 fflush(stdout);1160 console_flush(con); 1161 1161 console_set_style(con, STYLE_NORMAL); 1162 1162 -
uspace/app/edit/sheet.c
r52a79081 ra33f0a6 75 75 return ENOMEM; 76 76 77 list_initialize(&sh->tags _head);77 list_initialize(&sh->tags); 78 78 79 79 return EOK; … … 97 97 char *ipp; 98 98 size_t sz; 99 link_t *link;100 99 tag_t *tag; 101 100 char *newp; … … 121 120 /* Adjust tags. */ 122 121 123 link = sh->tags_head.next; 124 while (link != &sh->tags_head) { 122 list_foreach(sh->tags, link) { 125 123 tag = list_get_instance(link, tag_t, link); 126 124 … … 129 127 else if (tag->b_off == pos->b_off && dir == dir_before) 130 128 tag->b_off += sz; 131 132 link = link->next;133 129 } 134 130 … … 150 146 char *spp; 151 147 size_t sz; 152 link_t *link;153 148 tag_t *tag; 154 149 char *newp; … … 162 157 163 158 /* Adjust tags. */ 164 link = sh->tags_head.next; 165 while (link != &sh->tags_head) { 159 list_foreach(sh->tags, link) { 166 160 tag = list_get_instance(link, tag_t, link); 167 161 … … 170 164 else if (tag->b_off >= spos->b_off) 171 165 tag->b_off = spos->b_off; 172 173 link = link->next;174 166 } 175 167 … … 328 320 tag->b_off = pt->b_off; 329 321 tag->sh = sh; 330 list_append(&tag->link, &sh->tags _head);322 list_append(&tag->link, &sh->tags); 331 323 } 332 324 -
uspace/app/edit/sheet.h
r52a79081 ra33f0a6 57 57 char *data; 58 58 59 li nk_t tags_head;59 list_t tags; 60 60 } sheet_t; 61 61 … … 91 91 /* Note: This structure is opaque for the user. */ 92 92 93 /** Link to list of all tags in the sheet (see sheet_t.tags _head) */93 /** Link to list of all tags in the sheet (see sheet_t.tags) */ 94 94 link_t link; 95 95 sheet_t *sh; -
uspace/app/getterm/version.c
r52a79081 ra33f0a6 61 61 printf("HelenOS release %s (%s)%s%s\n", release, name, revision, timestamp); 62 62 printf("Running on %s (%s)\n", arch, term); 63 printf("Copyright (c) 2001-201 0HelenOS project\n\n");63 printf("Copyright (c) 2001-2011 HelenOS project\n\n"); 64 64 } 65 65 -
uspace/app/init/Makefile
r52a79081 ra33f0a6 30 30 USPACE_PREFIX = ../.. 31 31 BINARY = init 32 STATIC_NEEDED = y 32 33 33 34 SOURCES = \ -
uspace/app/init/init.c
r52a79081 ra33f0a6 176 176 static void console(const char *dev) 177 177 { 178 char hid_in[DEVMAP_NAME_MAXLEN]; 179 int rc; 180 181 snprintf(hid_in, DEVMAP_NAME_MAXLEN, "%s/%s", DEVFS_MOUNT_POINT, dev); 182 183 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, hid_in); 178 printf("%s: Spawning %s %s\n", NAME, SRV_CONSOLE, dev); 184 179 185 180 /* Wait for the input device to be ready */ 186 181 devmap_handle_t handle; 187 rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING);188 if (rc != EOK) { 189 printf("%s: Error waiting on %s (%s)\n", NAME, hid_in,190 str_error(rc)); 191 return; 192 } 193 194 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, hid_in, NULL);182 int rc = devmap_device_get_handle(dev, &handle, IPC_FLAG_BLOCKING); 183 if (rc != EOK) { 184 printf("%s: Error waiting on %s (%s)\n", NAME, dev, 185 str_error(rc)); 186 return; 187 } 188 189 rc = task_spawnl(NULL, SRV_CONSOLE, SRV_CONSOLE, dev, NULL); 195 190 if (rc != EOK) { 196 191 printf("%s: Error spawning %s %s (%s)\n", NAME, SRV_CONSOLE, 197 hid_in, str_error(rc));192 dev, str_error(rc)); 198 193 } 199 194 } … … 272 267 mount_tmpfs(); 273 268 274 #ifdef CONFIG_START_DEVMAN275 269 spawn("/srv/devman"); 276 #endif277 270 spawn("/srv/apic"); 278 271 spawn("/srv/i8259"); 279 spawn("/srv/fhc");280 272 spawn("/srv/obio"); 281 273 srv_start("/srv/cuda_adb"); 282 274 srv_start("/srv/i8042"); 283 275 srv_start("/srv/s3c24ser"); 284 srv_start("/srv/adb_ms");285 srv_start("/srv/char_ms");286 276 srv_start("/srv/s3c24ts"); 287 277 288 278 spawn("/srv/fb"); 289 spawn("/srv/ kbd");290 console("hid _in/kbd");279 spawn("/srv/input"); 280 console("hid/input"); 291 281 292 282 spawn("/srv/clip"); … … 304 294 305 295 #ifdef CONFIG_MOUNT_DATA 296 /* Make sure fat is running. */ 297 if (str_cmp(STRING(RDFMT), "fat") != 0) { 298 srv_start("/srv/fat"); 299 } 306 300 mount_data(); 307 301 #else -
uspace/app/klog/klog.c
r52a79081 ra33f0a6 44 44 #include <io/klog.h> 45 45 #include <sysinfo.h> 46 #include <malloc.h> 47 #include <fibril_synch.h> 48 #include <adt/list.h> 49 #include <adt/prodcons.h> 46 50 47 51 #define NAME "klog" 48 52 #define LOG_FNAME "/log/klog" 53 54 /* Producer/consumer buffers */ 55 typedef struct { 56 link_t link; 57 size_t length; 58 wchar_t *data; 59 } item_t; 60 61 static prodcons_t pc; 49 62 50 63 /* Pointer to klog area */ … … 52 65 static size_t klog_length; 53 66 54 static FILE *log; 55 56 static void interrupt_received(ipc_callid_t callid, ipc_call_t *call) 57 { 67 /* Notification mutex */ 68 static FIBRIL_MUTEX_INITIALIZE(mtx); 69 70 /** Klog producer 71 * 72 * Copies the contents of a character buffer to local 73 * producer/consumer queue. 74 * 75 * @param length Number of characters to copy. 76 * @param data Pointer to the kernel klog buffer. 77 * 78 */ 79 static void producer(size_t length, wchar_t *data) 80 { 81 item_t *item = (item_t *) malloc(sizeof(item_t)); 82 if (item == NULL) 83 return; 84 85 size_t sz = sizeof(wchar_t) * length; 86 wchar_t *buf = (wchar_t *) malloc(sz); 87 if (data == NULL) { 88 free(item); 89 return; 90 } 91 92 memcpy(buf, data, sz); 93 94 link_initialize(&item->link); 95 item->length = length; 96 item->data = buf; 97 prodcons_produce(&pc, &item->link); 98 } 99 100 /** Klog consumer 101 * 102 * Waits in an infinite loop for the character data created by 103 * the producer and outputs them to stdout and optionally into 104 * a file. 105 * 106 * @param data Unused. 107 * 108 * @return Always EOK (unreachable). 109 * 110 */ 111 static int consumer(void *data) 112 { 113 FILE *log = fopen(LOG_FNAME, "a"); 114 if (log == NULL) 115 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME, 116 str_error(errno)); 117 118 while (true) { 119 link_t *link = prodcons_consume(&pc); 120 item_t *item = list_get_instance(link, item_t, link); 121 122 for (size_t i = 0; i < item->length; i++) 123 putchar(item->data[i]); 124 125 if (log != NULL) { 126 for (size_t i = 0; i < item->length; i++) 127 fputc(item->data[i], log); 128 129 fflush(log); 130 fsync(fileno(log)); 131 } 132 133 free(item->data); 134 free(item); 135 } 136 137 fclose(log); 138 return EOK; 139 } 140 141 /** Kernel notification handler 142 * 143 * Receives kernel klog notifications. 144 * 145 * @param callid IPC call ID 146 * @param call IPC call structure 147 * @param arg Local argument 148 * 149 */ 150 static void notification_received(ipc_callid_t callid, ipc_call_t *call) 151 { 152 /* 153 * Make sure we process only a single notification 154 * at any time to limit the chance of the consumer 155 * starving. 156 * 157 * Note: Usually the automatic masking of the klog 158 * notifications on the kernel side does the trick 159 * of limiting the chance of accidentally copying 160 * the same data multiple times. However, due to 161 * the non-blocking architecture of klog notifications, 162 * this possibility cannot be generally avoided. 163 */ 164 165 fibril_mutex_lock(&mtx); 166 58 167 size_t klog_start = (size_t) IPC_GET_ARG1(*call); 59 168 size_t klog_len = (size_t) IPC_GET_ARG2(*call); 60 169 size_t klog_stored = (size_t) IPC_GET_ARG3(*call); 61 size_t i; 62 63 for (i = klog_len - klog_stored; i < klog_len; i++) { 64 wchar_t ch = klog[(klog_start + i) % klog_length]; 65 66 putchar(ch); 67 68 if (log != NULL) 69 fputc(ch, log); 70 } 71 72 if (log != NULL) { 73 fflush(log); 74 fsync(fileno(log)); 75 } 170 171 size_t offset = (klog_start + klog_len - klog_stored) % klog_length; 172 173 /* Copy data from the ring buffer */ 174 if (offset + klog_stored >= klog_length) { 175 size_t split = klog_length - offset; 176 177 producer(split, klog + offset); 178 producer(klog_stored - split, klog); 179 } else 180 producer(klog_stored, klog + offset); 181 182 event_unmask(EVENT_KLOG); 183 fibril_mutex_unlock(&mtx); 76 184 } 77 185 … … 111 219 } 112 220 221 prodcons_initialize(&pc); 222 async_set_interrupt_received(notification_received); 113 223 rc = event_subscribe(EVENT_KLOG, 0); 114 224 if (rc != EOK) { … … 118 228 } 119 229 120 log = fopen(LOG_FNAME, "a"); 121 if (log == NULL) 122 printf("%s: Unable to create log file %s (%s)\n", NAME, LOG_FNAME, 123 str_error(errno)); 124 125 async_set_interrupt_received(interrupt_received); 230 fid_t fid = fibril_create(consumer, NULL); 231 if (!fid) { 232 fprintf(stderr, "%s: Unable to create consumer fibril\n", 233 NAME); 234 return ENOMEM; 235 } 236 237 fibril_add_ready(fid); 238 event_unmask(EVENT_KLOG); 126 239 klog_update(); 240 241 task_retval(0); 127 242 async_manager(); 128 243 -
uspace/app/mkfat/mkfat.c
r52a79081 ra33f0a6 144 144 } 145 145 146 rc = block_init( handle, 2048);146 rc = block_init(EXCHANGE_SERIALIZE, handle, 2048); 147 147 if (rc != EOK) { 148 148 printf(NAME ": Error initializing libblock.\n"); -
uspace/app/ping/ping.c
r52a79081 ra33f0a6 340 340 config.dest_str, config.size, config.size); 341 341 342 int icmp_phone = icmp_connect_module(ICMP_CONNECT_TIMEOUT);343 if ( icmp_phone < 0) {342 async_sess_t *sess = icmp_connect_module(); 343 if (!sess) { 344 344 fprintf(stderr, "%s: Unable to connect to ICMP service (%s)\n", NAME, 345 str_error( icmp_phone));346 return icmp_phone;345 str_error(errno)); 346 return errno; 347 347 } 348 348 … … 355 355 str_error(ret)); 356 356 357 async_hangup( icmp_phone);357 async_hangup(sess); 358 358 return ret; 359 359 } 360 360 361 361 /* Ping! */ 362 int result = icmp_echo_msg( icmp_phone, config.size, config.timeout,362 int result = icmp_echo_msg(sess, config.size, config.timeout, 363 363 config.ttl, config.tos, !config.fragments, config.dest_raw, 364 364 config.dest_len); … … 370 370 str_error(ret)); 371 371 372 async_hangup( icmp_phone);372 async_hangup(sess); 373 373 return ret; 374 374 } … … 390 390 } 391 391 392 async_hangup( icmp_phone);392 async_hangup(sess); 393 393 394 394 return 0; -
uspace/app/redir/redir.c
r52a79081 ra33f0a6 49 49 static void usage(void) 50 50 { 51 printf("Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n",51 fprintf(stderr, "Usage: %s [-i <stdin>] [-o <stdout>] [-e <stderr>] -- <cmd> [args ...]\n", 52 52 NAME); 53 53 } … … 83 83 args = (const char **) calloc(argc + 1, sizeof(char *)); 84 84 if (!args) { 85 printf("No memory available\n");85 fprintf(stderr, "No memory available\n"); 86 86 return 0; 87 87 } … … 98 98 99 99 if (rc != EOK) { 100 printf("%s: Error spawning %s (%s)\n", NAME, argv[0],100 fprintf(stderr, "%s: Error spawning %s (%s)\n", NAME, argv[0], 101 101 str_error(rc)); 102 return 0; 102 103 } 103 104 -
uspace/app/sbi/src/compat.h
r52a79081 ra33f0a6 38 38 #ifdef __HELENOS__ 39 39 40 #define list sbi_list 41 #define list_t sbi_list_t 42 40 43 /* 41 44 * Avoid name conflicts with ADT library. … … 44 47 #define list_prepend sbi_list_prepend 45 48 #define list_remove sbi_list_remove 49 #define list_first sbi_list_first 50 #define list_last sbi_list_last 46 51 47 52 #endif -
uspace/app/sbi/src/input.c
r52a79081 ra33f0a6 176 176 int input_get_line(input_t *input, char **line) 177 177 { 178 const char *prompt; 178 179 const char *sp; 179 180 char *dp; … … 212 213 /* Interactive mode */ 213 214 if (input->line_no == 0) 214 pr intf("sbi> ");215 prompt = "sbi> "; 215 216 else 216 pr intf("... ");217 prompt = "... "; 217 218 218 219 fflush(stdout); 219 if (os_input_line( &line_p) != EOK)220 if (os_input_line(prompt, &line_p) != EOK) 220 221 return EIO; 221 222 -
uspace/app/sbi/src/list_t.h
r52a79081 ra33f0a6 30 30 #define LIST_T_H_ 31 31 32 #include "compat.h" 33 32 34 typedef struct list_node { 33 35 struct list_node *prev, *next; -
uspace/app/sbi/src/os/helenos.c
r52a79081 ra33f0a6 210 210 * @param ptr Place to store pointer to new string. 211 211 */ 212 int os_input_line(c har **ptr)212 int os_input_line(const char *prompt, char **ptr) 213 213 { 214 214 char *line; … … 219 219 if (tinput == NULL) 220 220 return EIO; 221 222 tinput_set_prompt(tinput, prompt); 221 223 } 222 224 -
uspace/app/sbi/src/os/os.h
r52a79081 ra33f0a6 38 38 char *os_chr_to_astr(wchar_t chr); 39 39 void os_input_disp_help(void); 40 int os_input_line(c har **ptr);40 int os_input_line(const char *prompt, char **ptr); 41 41 int os_exec(char * const cmd[]); 42 42 -
uspace/app/sbi/src/os/posix.c
r52a79081 ra33f0a6 193 193 * @param ptr Place to store pointer to new string. 194 194 */ 195 int os_input_line(char **ptr) 196 { 195 int os_input_line(const char *prompt, char **ptr) 196 { 197 printf("%s", prompt); 198 197 199 if (fgets(os_input_buffer, OS_INPUT_BUFFER_SIZE, stdin) == NULL) 198 200 os_input_buffer[0] = '\0'; -
uspace/app/taskdump/elf_core.c
r52a79081 ra33f0a6 1 1 /* 2 * Copyright (c) 201 0Jiri Svoboda2 * Copyright (c) 2011 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 38 38 * Looking at core files produced by Linux, these don't have section headers, 39 39 * only program headers, although objdump shows them as having sections. 40 * Basically at the beginning there should be a note segment (which we 41 * do not write) and one loadable segment per memory area (which we do write). 42 * 43 * The note segment probably contains register state, etc. -- we don't 44 * deal with these yet. Nevertheless you can use these core files with 45 * objdump or gdb. 46 */ 47 40 * Basically at the beginning there should be a note segment followed 41 * by one loadable segment per memory area. 42 * 43 * The note segment contains a series of records with register state, 44 * process info etc. We only write one record NT_PRSTATUS which contains 45 * process/register state (anything which is not register state we fill 46 * with zeroes). 47 */ 48 49 #include <align.h> 50 #include <elf/elf.h> 51 #include <elf/elf_linux.h> 48 52 #include <stdio.h> 49 53 #include <stdlib.h> … … 58 62 #include <udebug.h> 59 63 #include <macros.h> 60 61 #include <elf.h> 62 #include " include/elf_core.h"63 64 static off64_t align_foff_up(off64_t foff, uintptr_t vaddr, size_t page_size);65 static int write_all(int fd, void *data, size_t len);66 static int write_mem_area(int fd, as_area_info_t *area, int phoneid);64 #include <libarch/istate.h> 65 66 #include "elf_core.h" 67 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 69 static int align_pos(int, size_t); 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 67 71 68 72 #define BUFFER_SIZE 0x1000 … … 71 75 /** Save ELF core file. 72 76 * 73 * @param file_name Name of file to save to. 74 * @param ainfo Array of @a n memory area info structures. 75 * @param n Number of memory areas. 76 * @param phoneid Debugging phone. 77 * 78 * @return EOK on sucess, ENOENT if file cannot be created, 79 * ENOMEM on out of memory, EIO on write error. 80 */ 81 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid) 77 * @param file_name Name of file to save to. 78 * @param ainfo Array of @a n memory area info structures. 79 * @param n Number of memory areas. 80 * @param sess Debugging session. 81 * 82 * @return EOK on sucess. 83 * @return ENOENT if file cannot be created. 84 * @return ENOMEM on out of memory. 85 * @return EIO on write error. 86 * 87 */ 88 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, 89 async_sess_t *sess, istate_t *istate) 82 90 { 83 91 elf_header_t elf_hdr; … … 86 94 elf_word flags; 87 95 elf_segment_header_t *p_hdr; 96 elf_prstatus_t pr_status; 97 elf_note_t note; 98 size_t word_size; 88 99 89 100 int fd; 90 int rc;101 ssize_t rc; 91 102 unsigned int i; 92 103 93 n_ph = n; 94 95 p_hdr = malloc(sizeof(elf_segment_header_t) * n); 104 #ifdef __32_BITS__ 105 word_size = 4; 106 #endif 107 #ifdef __64_BITS__ 108 /* 109 * This should be 8 per the 64-bit ELF spec, but the Linux kernel 110 * screws up and uses 4 anyway (and screws up elf_note_t as well) 111 * and we are trying to be compatible with Linux GDB target. Sigh. 112 */ 113 word_size = 4; 114 #endif 115 memset(&pr_status, 0, sizeof(pr_status)); 116 istate_to_elf_regs(istate, &pr_status.regs); 117 118 n_ph = n + 1; 119 120 p_hdr = malloc(sizeof(elf_segment_header_t) * n_ph); 96 121 if (p_hdr == NULL) { 97 122 printf("Failed allocating memory.\n"); … … 111 136 * ELF header 112 137 * program headers 138 * note segment 113 139 * repeat: 114 140 * (pad for alignment) 115 * segment data141 * core segment 116 142 * end repeat 117 143 */ … … 143 169 foff = elf_hdr.e_phoff + n_ph * sizeof(elf_segment_header_t); 144 170 145 for (i = 1; i <= n; ++i) { 146 foff = align_foff_up(foff, ainfo[i - 1].start_addr, PAGE_SIZE); 171 memset(&p_hdr[0], 0, sizeof(p_hdr[0])); 172 p_hdr[0].p_type = PT_NOTE; 173 p_hdr[0].p_offset = foff; 174 p_hdr[0].p_vaddr = 0; 175 p_hdr[0].p_paddr = 0; 176 p_hdr[0].p_filesz = sizeof(elf_note_t) 177 + ALIGN_UP((str_size("CORE") + 1), word_size) 178 + ALIGN_UP(sizeof(elf_prstatus_t), word_size); 179 p_hdr[0].p_memsz = 0; 180 p_hdr[0].p_flags = 0; 181 p_hdr[0].p_align = 1; 182 183 foff += p_hdr[0].p_filesz; 184 185 for (i = 0; i < n; ++i) { 186 foff = align_foff_up(foff, ainfo[i].start_addr, PAGE_SIZE); 147 187 148 188 flags = 0; 149 if (ainfo[i - 1].flags & AS_AREA_READ)189 if (ainfo[i].flags & AS_AREA_READ) 150 190 flags |= PF_R; 151 if (ainfo[i - 1].flags & AS_AREA_WRITE)191 if (ainfo[i].flags & AS_AREA_WRITE) 152 192 flags |= PF_W; 153 if (ainfo[i - 1].flags & AS_AREA_EXEC)193 if (ainfo[i].flags & AS_AREA_EXEC) 154 194 flags |= PF_X; 155 195 156 memset(&p_hdr[i - 1], 0, sizeof(p_hdr[i -1]));157 p_hdr[i -1].p_type = PT_LOAD;158 p_hdr[i -1].p_offset = foff;159 p_hdr[i - 1].p_vaddr = ainfo[i - 1].start_addr;160 p_hdr[i -1].p_paddr = 0;161 p_hdr[i - 1].p_filesz = ainfo[i - 1].size;162 p_hdr[i - 1].p_memsz = ainfo[i - 1].size;163 p_hdr[i -1].p_flags = flags;164 p_hdr[i -1].p_align = PAGE_SIZE;165 166 foff += ainfo[i - 1].size;196 memset(&p_hdr[i + 1], 0, sizeof(p_hdr[i + 1])); 197 p_hdr[i + 1].p_type = PT_LOAD; 198 p_hdr[i + 1].p_offset = foff; 199 p_hdr[i + 1].p_vaddr = ainfo[i].start_addr; 200 p_hdr[i + 1].p_paddr = 0; 201 p_hdr[i + 1].p_filesz = ainfo[i].size; 202 p_hdr[i + 1].p_memsz = ainfo[i].size; 203 p_hdr[i + 1].p_flags = flags; 204 p_hdr[i + 1].p_align = PAGE_SIZE; 205 206 foff += ainfo[i].size; 167 207 } 168 208 169 209 rc = write_all(fd, &elf_hdr, sizeof(elf_hdr)); 170 if (rc != EOK) {210 if (rc != sizeof(elf_hdr)) { 171 211 printf("Failed writing ELF header.\n"); 172 212 free(p_hdr); … … 176 216 for (i = 0; i < n_ph; ++i) { 177 217 rc = write_all(fd, &p_hdr[i], sizeof(p_hdr[i])); 178 if (rc != EOK) {218 if (rc != sizeof(p_hdr[i])) { 179 219 printf("Failed writing program header.\n"); 180 220 free(p_hdr); … … 183 223 } 184 224 185 for (i = 0; i < n_ph; ++i) { 225 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 226 printf("Failed writing memory data.\n"); 227 free(p_hdr); 228 return EIO; 229 } 230 231 /* 232 * Write note header 233 */ 234 note.namesz = str_size("CORE") + 1; 235 note.descsz = sizeof(elf_prstatus_t); 236 note.type = NT_PRSTATUS; 237 238 rc = write_all(fd, ¬e, sizeof(elf_note_t)); 239 if (rc != sizeof(elf_note_t)) { 240 printf("Failed writing note header.\n"); 241 free(p_hdr); 242 return EIO; 243 } 244 245 rc = write_all(fd, "CORE", note.namesz); 246 if (rc != (ssize_t) note.namesz) { 247 printf("Failed writing note header.\n"); 248 free(p_hdr); 249 return EIO; 250 } 251 252 rc = align_pos(fd, word_size); 253 if (rc != EOK) { 254 printf("Failed writing note header.\n"); 255 free(p_hdr); 256 return EIO; 257 } 258 259 rc = write_all(fd, &pr_status, sizeof(elf_prstatus_t)); 260 if (rc != sizeof(elf_prstatus_t)) { 261 printf("Failed writing register data.\n"); 262 free(p_hdr); 263 return EIO; 264 } 265 266 for (i = 1; i < n_ph; ++i) { 186 267 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 187 268 printf("Failed writing memory data.\n"); … … 189 270 return EIO; 190 271 } 191 if (write_mem_area(fd, &ainfo[i ], phoneid) != EOK) {272 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 192 273 printf("Failed writing memory data.\n"); 193 274 free(p_hdr); … … 206 287 off64_t rva = vaddr % page_size; 207 288 off64_t rfo = foff % page_size; 208 289 209 290 if (rva >= rfo) 210 291 return (foff + (rva - rfo)); 211 292 212 293 return (foff + (page_size + (rva - rfo))); 213 294 } … … 215 296 /** Write memory area from application to core file. 216 297 * 217 * @param fd File to write to. 218 * @param area Memory area info structure. 219 * @param phoneid Debugging phone. 220 * 221 * @return EOK on success, EIO on failure. 222 */ 223 static int write_mem_area(int fd, as_area_info_t *area, int phoneid) 298 * @param fd File to write to. 299 * @param area Memory area info structure. 300 * @param sess Debugging session. 301 * 302 * @return EOK on success, EIO on failure. 303 * 304 */ 305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess) 224 306 { 225 307 size_t to_copy; 226 308 size_t total; 227 309 uintptr_t addr; 228 int rc;310 ssize_t rc; 229 311 230 312 addr = area->start_addr; … … 233 315 while (total < area->size) { 234 316 to_copy = min(area->size - total, BUFFER_SIZE); 235 rc = udebug_mem_read( phoneid, buffer, addr, to_copy);317 rc = udebug_mem_read(sess, buffer, addr, to_copy); 236 318 if (rc < 0) { 237 319 printf("Failed reading task memory.\n"); … … 240 322 241 323 rc = write_all(fd, buffer, to_copy); 242 if (rc != EOK) {324 if (rc != (ssize_t) to_copy) { 243 325 printf("Failed writing memory contents.\n"); 244 326 return EIO; … … 252 334 } 253 335 254 /** Write until the buffer is written in its entirety. 255 * 256 * This function fails if it cannot write exactly @a len bytes to the file. 257 * 258 * @param fd The file to write to. 259 * @param buf Data, @a len bytes long. 260 * @param len Number of bytes to write. 261 * 262 * @return EOK on error, return value from write() if writing 263 * failed. 264 */ 265 static int write_all(int fd, void *data, size_t len) 336 static int align_pos(int fd, size_t align) 266 337 { 267 int cnt = 0;268 269 do { 270 data += cnt;271 len -= cnt;272 cnt = write(fd, data, len);273 } while (cnt > 0 && (len - cnt) > 0); 274 275 if (cnt < 0)276 return cnt; 277 278 if ( len - cnt >0)279 return EIO;338 off64_t cur_pos; 339 size_t rem, adv; 340 341 cur_pos = lseek(fd, 0, SEEK_CUR); 342 if (cur_pos < 0) 343 return -1; 344 345 rem = cur_pos % align; 346 adv = align - rem; 347 348 cur_pos = lseek(fd, adv, SEEK_CUR); 349 if (cur_pos < 0) 350 return -1; 280 351 281 352 return EOK; 282 353 } 283 354 284 285 355 /** @} 286 356 */ -
uspace/app/taskdump/include/elf_core.h
r52a79081 ra33f0a6 36 36 #define ELF_CORE_H_ 37 37 38 int elf_core_save(const char *file_name, as_area_info_t *ainfo, unsigned int n, int phoneid); 38 #include <async.h> 39 #include <elf/elf_linux.h> 40 #include <libarch/istate.h> 41 42 extern int elf_core_save(const char *, as_area_info_t *, unsigned int, 43 async_sess_t *, istate_t *); 39 44 40 45 #endif -
uspace/app/taskdump/include/symtab.h
r52a79081 ra33f0a6 36 36 #define SYMTAB_H_ 37 37 38 #include <elf/elf.h> 38 39 #include <sys/types.h> 39 #include <elf.h>40 40 41 41 typedef struct { -
uspace/app/taskdump/symtab.c
r52a79081 ra33f0a6 36 36 */ 37 37 38 #include <elf/elf.h> 38 39 #include <stdio.h> 39 40 #include <stdlib.h> … … 43 44 #include <fcntl.h> 44 45 45 #include <elf.h>46 46 #include "include/symtab.h" 47 47 … … 50 50 elf_section_header_t *shdr); 51 51 static int chunk_load(int fd, off64_t start, size_t size, void **ptr); 52 static int read_all(int fd, void *buf, size_t len);53 52 54 53 /** Load symbol table from an ELF file. … … 90 89 91 90 rc = read_all(fd, &elf_hdr, sizeof(elf_header_t)); 92 if (rc != EOK) {91 if (rc != sizeof(elf_header_t)) { 93 92 printf("failed reading elf header\n"); 94 93 free(stab); … … 312 311 313 312 rc = read_all(fd, sec_hdr, sizeof(elf_section_header_t)); 314 if (rc != EOK)313 if (rc != sizeof(elf_section_header_t)) 315 314 return EIO; 316 315 … … 331 330 static int chunk_load(int fd, off64_t start, size_t size, void **ptr) 332 331 { 333 int rc; 334 335 rc = lseek(fd, start, SEEK_SET); 336 if (rc == (off64_t) -1) { 332 ssize_t rc; 333 off64_t offs; 334 335 offs = lseek(fd, start, SEEK_SET); 336 if (offs == (off64_t) -1) { 337 337 printf("failed seeking chunk\n"); 338 338 *ptr = NULL; … … 347 347 348 348 rc = read_all(fd, *ptr, size); 349 if (rc != EOK) {349 if (rc != (ssize_t) size) { 350 350 printf("failed reading chunk\n"); 351 351 free(*ptr); … … 357 357 } 358 358 359 /** Read until the buffer is read in its entirety.360 *361 * This function fails if it cannot read exactly @a len bytes from the file.362 *363 * @param fd The file to read from.364 * @param buf Buffer for storing data, @a len bytes long.365 * @param len Number of bytes to read.366 *367 * @return EOK on error, EIO if file is short or return value368 * from read() if reading failed.369 */370 static int read_all(int fd, void *buf, size_t len)371 {372 int cnt = 0;373 374 do {375 buf += cnt;376 len -= cnt;377 cnt = read(fd, buf, len);378 } while (cnt > 0 && (len - cnt) > 0);379 380 if (cnt < 0)381 return cnt;382 383 if (len - cnt > 0)384 return EIO;385 386 return EOK;387 }388 389 359 /** @} 390 360 */ -
uspace/app/taskdump/taskdump.c
r52a79081 ra33f0a6 34 34 35 35 #include <async.h> 36 #include <elf/elf_linux.h> 36 37 #include <stdio.h> 37 38 #include <stdlib.h> … … 54 55 #define LINE_BYTES 16 55 56 56 static int phoneid;57 static async_sess_t *sess; 57 58 static task_id_t task_id; 58 59 static bool write_core_file; … … 73 74 static char *fmt_sym_address(uintptr_t addr); 74 75 76 static istate_t reg_state; 77 75 78 int main(int argc, char *argv[]) 76 79 { … … 104 107 printf("Failed dumping address space areas.\n"); 105 108 106 udebug_end( phoneid);107 async_hangup( phoneid);109 udebug_end(sess); 110 async_hangup(sess); 108 111 109 112 return 0; … … 112 115 static int connect_task(task_id_t task_id) 113 116 { 114 int rc; 115 116 rc = async_connect_kbox(task_id); 117 118 if (rc == ENOTSUP) { 119 printf("You do not have userspace debugging support " 120 "compiled in the kernel.\n"); 121 printf("Compile kernel with 'Support for userspace debuggers' " 122 "(CONFIG_UDEBUG) enabled.\n"); 123 return rc; 124 } 125 126 if (rc < 0) { 117 async_sess_t *ksess = async_connect_kbox(task_id); 118 119 if (!ksess) { 120 if (errno == ENOTSUP) { 121 printf("You do not have userspace debugging support " 122 "compiled in the kernel.\n"); 123 printf("Compile kernel with 'Support for userspace debuggers' " 124 "(CONFIG_UDEBUG) enabled.\n"); 125 return errno; 126 } 127 127 128 printf("Error connecting\n"); 128 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, rc); 129 return rc; 130 } 131 132 phoneid = rc; 133 134 rc = udebug_begin(phoneid); 129 printf("async_connect_kbox(%" PRIu64 ") -> %d ", task_id, errno); 130 return errno; 131 } 132 133 int rc = udebug_begin(ksess); 135 134 if (rc < 0) { 136 135 printf("udebug_begin() -> %d\n", rc); 137 136 return rc; 138 137 } 139 138 139 sess = ksess; 140 140 return 0; 141 141 } … … 213 213 214 214 /* TODO: See why NULL does not work. */ 215 rc = udebug_thread_read( phoneid, &dummy_buf, 0, &copied, &needed);215 rc = udebug_thread_read(sess, &dummy_buf, 0, &copied, &needed); 216 216 if (rc < 0) { 217 217 printf("udebug_thread_read() -> %d\n", rc); … … 227 227 thash_buf = malloc(buf_size); 228 228 229 rc = udebug_thread_read( phoneid, thash_buf, buf_size, &copied, &needed);229 rc = udebug_thread_read(sess, thash_buf, buf_size, &copied, &needed); 230 230 if (rc < 0) { 231 231 printf("udebug_thread_read() -> %d\n", rc); … … 262 262 int rc; 263 263 264 rc = udebug_areas_read( phoneid, &dummy_buf, 0, &copied, &needed);264 rc = udebug_areas_read(sess, &dummy_buf, 0, &copied, &needed); 265 265 if (rc < 0) { 266 266 printf("udebug_areas_read() -> %d\n", rc); … … 271 271 ainfo_buf = malloc(buf_size); 272 272 273 rc = udebug_areas_read( phoneid, ainfo_buf, buf_size, &copied, &needed);273 rc = udebug_areas_read(sess, ainfo_buf, buf_size, &copied, &needed); 274 274 if (rc < 0) { 275 275 printf("udebug_areas_read() -> %d\n", rc); … … 296 296 if (write_core_file) { 297 297 printf("Writing core file '%s'\n", core_file_name); 298 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, phoneid); 298 299 rc = elf_core_save(core_file_name, ainfo_buf, n_areas, sess, 300 ®_state); 301 299 302 if (rc != EOK) { 300 303 printf("Failed writing core file.\n"); … … 316 319 int rc; 317 320 318 rc = udebug_regs_read( phoneid, thash, &istate);321 rc = udebug_regs_read(sess, thash, &istate); 319 322 if (rc < 0) { 320 323 printf("Failed reading registers (%d).\n", rc); … … 324 327 pc = istate_get_pc(&istate); 325 328 fp = istate_get_fp(&istate); 329 330 /* Save register state for dumping to core file later. */ 331 reg_state = istate; 326 332 327 333 sym_pc = fmt_sym_address(pc); … … 359 365 (void) arg; 360 366 361 rc = udebug_mem_read( phoneid, &data, addr, sizeof(data));367 rc = udebug_mem_read(sess, &data, addr, sizeof(data)); 362 368 if (rc < 0) { 363 369 printf("Warning: udebug_mem_read() failed.\n"); … … 430 436 int rc; 431 437 432 rc = udebug_name_read( phoneid, &dummy_buf, 0, &copied, &needed);438 rc = udebug_name_read(sess, &dummy_buf, 0, &copied, &needed); 433 439 if (rc < 0) 434 440 return NULL; … … 436 442 name_size = needed; 437 443 name = malloc(name_size + 1); 438 rc = udebug_name_read( phoneid, name, name_size, &copied, &needed);444 rc = udebug_name_read(sess, name, name_size, &copied, &needed); 439 445 if (rc < 0) { 440 446 free(name); -
uspace/app/tester/Makefile
r52a79081 ra33f0a6 29 29 30 30 USPACE_PREFIX = ../.. 31 LIBS = $(LIBEXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a 32 EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX) 31 33 BINARY = tester 32 34 33 35 SOURCES = \ 34 36 tester.c \ 37 util.c \ 35 38 thread/thread1.c \ 36 39 print/print1.c \ … … 48 51 ipc/ping_pong.c \ 49 52 loop/loop1.c \ 53 mm/common.c \ 50 54 mm/malloc1.c \ 51 55 mm/malloc2.c \ 56 mm/malloc3.c \ 57 mm/mapping1.c \ 52 58 devs/devman1.c \ 59 devs/devman2.c \ 53 60 hw/misc/virtchar1.c \ 54 hw/serial/serial1.c 61 hw/serial/serial1.c \ 62 libext2/libext2_1.c 55 63 56 64 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/tester/console/console1.c
r52a79081 ra33f0a6 50 50 { 51 51 if (!test_quiet) { 52 console_ctrl_t *console = console_init(stdin, stdout); 53 52 54 printf("Style test: "); 53 fflush(stdout);54 console_set_style( fphone(stdout), STYLE_NORMAL);55 console_flush(console); 56 console_set_style(console, STYLE_NORMAL); 55 57 printf(" normal "); 56 fflush(stdout);57 console_set_style( fphone(stdout), STYLE_EMPHASIS);58 console_flush(console); 59 console_set_style(console, STYLE_EMPHASIS); 58 60 printf(" emphasized "); 59 fflush(stdout);60 console_set_style( fphone(stdout), STYLE_INVERTED);61 console_flush(console); 62 console_set_style(console, STYLE_INVERTED); 61 63 printf(" inverted "); 62 fflush(stdout);63 console_set_style( fphone(stdout), STYLE_SELECTED);64 console_flush(console); 65 console_set_style(console, STYLE_SELECTED); 64 66 printf(" selected "); 65 fflush(stdout);66 console_set_style( fphone(stdout), STYLE_NORMAL);67 console_flush(console); 68 console_set_style(console, STYLE_NORMAL); 67 69 printf("\n"); 68 70 … … 73 75 for (j = 0; j < 2; j++) { 74 76 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 75 fflush(stdout);76 console_set_color( fphone(stdout), i, COLOR_WHITE,77 console_flush(console); 78 console_set_color(console, i, COLOR_WHITE, 77 79 j ? CATTR_BRIGHT : 0); 78 80 printf(" %s ", color_name[i]); 79 81 } 80 fflush(stdout);81 console_set_style( fphone(stdout), STYLE_NORMAL);82 console_flush(console); 83 console_set_style(console, STYLE_NORMAL); 82 84 putchar('\n'); 83 85 } … … 86 88 for (j = 0; j < 2; j++) { 87 89 for (i = COLOR_BLACK; i <= COLOR_WHITE; i++) { 88 fflush(stdout);89 console_set_color( fphone(stdout), COLOR_WHITE, i,90 console_flush(console); 91 console_set_color(console, COLOR_WHITE, i, 90 92 j ? CATTR_BRIGHT : 0); 91 93 printf(" %s ", color_name[i]); 92 94 } 93 fflush(stdout);94 console_set_style( fphone(stdout), STYLE_NORMAL);95 console_flush(console); 96 console_set_style(console, STYLE_NORMAL); 95 97 putchar('\n'); 96 98 } … … 99 101 100 102 for (i = 0; i < 255; i += 16) { 101 fflush(stdout);102 console_set_rgb_color( fphone(stdout), (255 - i) << 16, i << 16);103 console_flush(console); 104 console_set_rgb_color(console, (255 - i) << 16, i << 16); 103 105 putchar('X'); 104 106 } 105 fflush(stdout);106 console_set_color( fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);107 console_flush(console); 108 console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0); 107 109 putchar('\n'); 108 110 109 111 for (i = 0; i < 255; i += 16) { 110 fflush(stdout);111 console_set_rgb_color( fphone(stdout), (255 - i) << 8, i << 8);112 console_flush(console); 113 console_set_rgb_color(console, (255 - i) << 8, i << 8); 112 114 putchar('X'); 113 115 } 114 fflush(stdout);115 console_set_color( fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);116 console_flush(console); 117 console_set_color(console, COLOR_BLACK, COLOR_WHITE, 0); 116 118 putchar('\n'); 117 119 118 120 for (i = 0; i < 255; i += 16) { 119 fflush(stdout);120 console_set_rgb_color( fphone(stdout), 255 - i, i);121 console_flush(console); 122 console_set_rgb_color(console, 255 - i, i); 121 123 putchar('X'); 122 124 } 123 fflush(stdout);124 console_set_style( fphone(stdout), STYLE_NORMAL);125 console_flush(console); 126 console_set_style(console, STYLE_NORMAL); 125 127 putchar('\n'); 126 128 } -
uspace/app/tester/hw/misc/virtchar1.c
r52a79081 ra33f0a6 43 43 #include <str.h> 44 44 #include <vfs/vfs.h> 45 #include <vfs/vfs_sess.h> 45 46 #include <sys/stat.h> 46 47 #include <fcntl.h> … … 66 67 TPRINTF(" ...file handle %d\n", fd); 67 68 68 TPRINTF(" Asking for phone...\n");69 int phone = fd_phone(fd);70 if ( phone < 0) {69 TPRINTF(" Asking for session...\n"); 70 async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd); 71 if (!sess) { 71 72 close(fd); 72 TPRINTF(" ...error: %s\n", str_error( phone));73 return "Failed to get phoneto device";73 TPRINTF(" ...error: %s\n", str_error(errno)); 74 return "Failed to get session to device"; 74 75 } 75 TPRINTF(" ... phone is %d\n", phone);76 TPRINTF(" ...session is %p\n", sess); 76 77 77 78 TPRINTF(" Will try to read...\n"); 78 79 size_t i; 79 80 char buffer[BUFFER_SIZE]; 80 char_dev_read( phone, buffer, BUFFER_SIZE);81 char_dev_read(sess, buffer, BUFFER_SIZE); 81 82 TPRINTF(" ...verifying that we read zeroes only...\n"); 82 83 for (i = 0; i < BUFFER_SIZE; i++) { … … 88 89 89 90 /* Clean-up. */ 90 TPRINTF(" Closing phones and file descriptors\n");91 async_hangup( phone);91 TPRINTF(" Closing session and file descriptor\n"); 92 async_hangup(sess); 92 93 close(fd); 93 94 -
uspace/app/tester/hw/serial/serial1.c
r52a79081 ra33f0a6 71 71 } 72 72 73 int res = devman_get_phone(DEVMAN_CLIENT, IPC_FLAG_BLOCKING);74 75 73 devman_handle_t handle; 76 res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle,74 int res = devman_device_get_handle("/hw/pci0/00:01.0/com1/a", &handle, 77 75 IPC_FLAG_BLOCKING); 78 76 if (res != EOK) 79 77 return "Could not get serial device handle"; 80 78 81 int phone = devman_device_connect(handle, IPC_FLAG_BLOCKING);82 if (phone < 0) {83 devman_hangup_phone(DEVMAN_CLIENT);79 async_sess_t *sess = devman_device_connect(EXCHANGE_SERIALIZE, handle, 80 IPC_FLAG_BLOCKING); 81 if (!sess) 84 82 return "Unable to connect to serial device"; 85 }86 83 87 84 char *buf = (char *) malloc(cnt + 1); 88 85 if (buf == NULL) { 89 async_hangup(phone); 90 devman_hangup_phone(DEVMAN_CLIENT); 86 async_hangup(sess); 91 87 return "Failed to allocate input buffer"; 92 88 } … … 97 93 sysarg_t old_word_size; 98 94 99 res = async_req_0_4(phone, SERIAL_GET_COM_PROPS, &old_baud, 95 async_exch_t *exch = async_exchange_begin(sess); 96 res = async_req_0_4(exch, SERIAL_GET_COM_PROPS, &old_baud, 100 97 &old_par, &old_word_size, &old_stop); 98 async_exchange_end(exch); 99 101 100 if (res != EOK) { 102 101 free(buf); 103 async_hangup(phone); 104 devman_hangup_phone(DEVMAN_CLIENT); 102 async_hangup(sess); 105 103 return "Failed to get old serial communication parameters"; 106 104 } 107 105 108 res = async_req_4_0(phone, SERIAL_SET_COM_PROPS, 1200, 106 exch = async_exchange_begin(sess); 107 res = async_req_4_0(exch, SERIAL_SET_COM_PROPS, 1200, 109 108 SERIAL_NO_PARITY, 8, 1); 109 async_exchange_end(exch); 110 110 111 if (EOK != res) { 111 112 free(buf); 112 async_hangup(phone); 113 devman_hangup_phone(DEVMAN_CLIENT); 113 async_hangup(sess); 114 114 return "Failed to set serial communication parameters"; 115 115 } … … 120 120 size_t total = 0; 121 121 while (total < cnt) { 122 ssize_t read = char_dev_read( phone, buf, cnt - total);122 ssize_t read = char_dev_read(sess, buf, cnt - total); 123 123 124 124 if (read < 0) { 125 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 125 exch = async_exchange_begin(sess); 126 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud, 126 127 old_par, old_word_size, old_stop); 128 async_exchange_end(exch); 129 127 130 free(buf); 128 async_hangup(phone); 129 devman_hangup_phone(DEVMAN_CLIENT); 131 async_hangup(sess); 130 132 return "Failed read from serial device"; 131 133 } 132 134 133 135 if ((size_t) read > cnt - total) { 134 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 136 exch = async_exchange_begin(sess); 137 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud, 135 138 old_par, old_word_size, old_stop); 139 async_exchange_end(exch); 140 136 141 free(buf); 137 async_hangup(phone); 138 devman_hangup_phone(DEVMAN_CLIENT); 142 async_hangup(sess); 139 143 return "Read more data than expected"; 140 144 } … … 151 155 * direction of data transfer. 152 156 */ 153 ssize_t written = char_dev_write( phone, buf, read);157 ssize_t written = char_dev_write(sess, buf, read); 154 158 155 159 if (written < 0) { 156 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 160 exch = async_exchange_begin(sess); 161 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud, 157 162 old_par, old_word_size, old_stop); 163 async_exchange_end(exch); 164 158 165 free(buf); 159 async_hangup(phone); 160 devman_hangup_phone(DEVMAN_CLIENT); 166 async_hangup(sess); 161 167 return "Failed write to serial device"; 162 168 } 163 169 164 170 if (written != read) { 165 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 171 exch = async_exchange_begin(sess); 172 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud, 166 173 old_par, old_word_size, old_stop); 174 async_exchange_end(exch); 175 167 176 free(buf); 168 async_hangup(phone); 169 devman_hangup_phone(DEVMAN_CLIENT); 177 async_hangup(sess); 170 178 return "Written less data than read from serial device"; 171 179 } … … 180 188 181 189 size_t eot_size = str_size(EOT); 182 ssize_t written = char_dev_write(phone, (void *) EOT, eot_size); 183 184 async_req_4_0(phone, SERIAL_SET_COM_PROPS, old_baud, 190 ssize_t written = char_dev_write(sess, (void *) EOT, eot_size); 191 192 exch = async_exchange_begin(sess); 193 async_req_4_0(exch, SERIAL_SET_COM_PROPS, old_baud, 185 194 old_par, old_word_size, old_stop); 195 async_exchange_end(exch); 196 186 197 free(buf); 187 async_hangup(phone); 188 devman_hangup_phone(DEVMAN_CLIENT); 198 async_hangup(sess); 189 199 190 200 if (written < 0) -
uspace/app/tester/ipc/ping_pong.c
r52a79081 ra33f0a6 30 30 #include <stdlib.h> 31 31 #include <sys/time.h> 32 #include < ipc/ns.h>32 #include <ns.h> 33 33 #include <async.h> 34 34 #include <errno.h> … … 61 61 size_t i; 62 62 for (i = 0; i < COUNT_GRANULARITY; i++) { 63 int retval = async_req_0_0(PHONE_NS, NS_PING);63 int retval = ns_ping(); 64 64 65 65 if (retval != EOK) { -
uspace/app/tester/mm/malloc1.c
r52a79081 ra33f0a6 30 30 31 31 #include <stdio.h> 32 #include <unistd.h>33 32 #include <stdlib.h> 34 #include <malloc.h>33 #include "common.h" 35 34 #include "../tester.h" 36 35 … … 45 44 */ 46 45 47 /**48 * sizeof_array49 * @array array to determine the size of50 *51 * Returns the size of @array in array elements.52 */53 #define sizeof_array(array) \54 (sizeof(array) / sizeof((array)[0]))55 56 #define MAX_ALLOC (16 * 1024 * 1024)57 58 /*59 * Subphase control structures: subphase termination conditions,60 * probabilities of individual actions, subphase control structure.61 */62 63 typedef struct {64 unsigned int max_cycles;65 unsigned int no_memory;66 unsigned int no_allocated;67 } sp_term_cond_s;68 69 typedef struct {70 unsigned int alloc;71 unsigned int free;72 } sp_action_prob_s;73 74 typedef struct {75 const char *name;76 sp_term_cond_s cond;77 sp_action_prob_s prob;78 } subphase_s;79 80 81 /*82 * Phase control structures: The minimum and maximum block size that83 * can be allocated during the phase execution, phase control structure.84 */85 86 typedef struct {87 size_t min_block_size;88 size_t max_block_size;89 } ph_alloc_size_s;90 91 typedef struct {92 const char *name;93 ph_alloc_size_s alloc;94 subphase_s *subphases;95 } phase_s;96 97 98 46 /* 99 47 * Subphases are defined separately here. This is for two reasons: … … 101 49 * how many subphases a phase contains. 102 50 */ 103 static subphase_ ssubphases_32B[] = {51 static subphase_t subphases_32B[] = { 104 52 { 105 53 .name = "Allocation", … … 140 88 }; 141 89 142 static subphase_ ssubphases_128K[] = {90 static subphase_t subphases_128K[] = { 143 91 { 144 92 .name = "Allocation", … … 179 127 }; 180 128 181 static subphase_ ssubphases_default[] = {129 static subphase_t subphases_default[] = { 182 130 { 183 131 .name = "Allocation", … … 217 165 } 218 166 }; 219 220 167 221 168 /* 222 169 * Phase definitions. 223 170 */ 224 static phase_ sphases[] = {171 static phase_t phases[] = { 225 172 { 226 173 .name = "32 B memory blocks", … … 257 204 }; 258 205 259 260 /* 261 * Global error flag. The flag is set if an error 262 * is encountered (overlapping blocks, inconsistent 263 * block data, etc.) 264 */ 265 static bool error_flag = false; 266 267 /* 268 * Memory accounting: the amount of allocated memory and the 269 * number and list of allocated blocks. 270 */ 271 static size_t mem_allocated; 272 static size_t mem_blocks_count; 273 274 static LIST_INITIALIZE(mem_blocks); 275 276 typedef struct { 277 /* Address of the start of the block */ 278 void *addr; 279 280 /* Size of the memory block */ 281 size_t size; 282 283 /* link to other blocks */ 284 link_t link; 285 } mem_block_s; 286 287 typedef mem_block_s *mem_block_t; 288 289 290 /** init_mem 291 * 292 * Initializes the memory accounting structures. 293 * 294 */ 295 static void init_mem(void) 206 static void do_subphase(phase_t *phase, subphase_t *subphase) 296 207 { 297 mem_allocated = 0; 298 mem_blocks_count = 0; 299 } 300 301 302 static bool overlap_match(link_t *entry, void *addr, size_t size) 303 { 304 mem_block_t mblk = list_get_instance(entry, mem_block_s, link); 305 306 /* Entry block control structure <mbeg, mend) */ 307 uint8_t *mbeg = (uint8_t *) mblk; 308 uint8_t *mend = (uint8_t *) mblk + sizeof(mem_block_s); 309 310 /* Entry block memory <bbeg, bend) */ 311 uint8_t *bbeg = (uint8_t *) mblk->addr; 312 uint8_t *bend = (uint8_t *) mblk->addr + mblk->size; 313 314 /* Data block <dbeg, dend) */ 315 uint8_t *dbeg = (uint8_t *) addr; 316 uint8_t *dend = (uint8_t *) addr + size; 317 318 /* Check for overlaps */ 319 if (((mbeg >= dbeg) && (mbeg < dend)) || 320 ((mend > dbeg) && (mend <= dend)) || 321 ((bbeg >= dbeg) && (bbeg < dend)) || 322 ((bend > dbeg) && (bend <= dend))) 323 return true; 324 325 return false; 326 } 327 328 329 /** test_overlap 330 * 331 * Test whether a block starting at @addr overlaps with another, previously 332 * allocated memory block or its control structure. 333 * 334 * @param addr Initial address of the block 335 * @param size Size of the block 336 * 337 * @return false if the block does not overlap. 338 * 339 */ 340 static int test_overlap(void *addr, size_t size) 341 { 342 link_t *entry; 343 bool fnd = false; 344 345 for (entry = mem_blocks.next; entry != &mem_blocks; entry = entry->next) { 346 if (overlap_match(entry, addr, size)) { 347 fnd = true; 348 break; 349 } 350 } 351 352 return fnd; 353 } 354 355 356 /** checked_malloc 357 * 358 * Allocate @size bytes of memory and check whether the chunk comes 359 * from the non-mapped memory region and whether the chunk overlaps 360 * with other, previously allocated, chunks. 361 * 362 * @param size Amount of memory to allocate 363 * 364 * @return NULL if the allocation failed. Sets the global error_flag to 365 * true if the allocation succeeded but is illegal. 366 * 367 */ 368 static void *checked_malloc(size_t size) 369 { 370 void *data; 371 372 /* Allocate the chunk of memory */ 373 data = malloc(size); 374 if (data == NULL) 375 return NULL; 376 377 /* Check for overlaps with other chunks */ 378 if (test_overlap(data, size)) { 379 TPRINTF("\nError: Allocated block overlaps with another " 380 "previously allocated block.\n"); 381 error_flag = true; 382 } 383 384 return data; 385 } 386 387 388 /** alloc_block 389 * 390 * Allocate a block of memory of @size bytes and add record about it into 391 * the mem_blocks list. Return a pointer to the block holder structure or 392 * NULL if the allocation failed. 393 * 394 * If the allocation is illegal (e.g. the memory does not come from the 395 * right region or some of the allocated blocks overlap with others), 396 * set the global error_flag. 397 * 398 * @param size Size of the memory block 399 * 400 */ 401 static mem_block_t alloc_block(size_t size) 402 { 403 /* Check for allocation limit */ 404 if (mem_allocated >= MAX_ALLOC) 405 return NULL; 406 407 /* Allocate the block holder */ 408 mem_block_t block = (mem_block_t) checked_malloc(sizeof(mem_block_s)); 409 if (block == NULL) 410 return NULL; 411 412 link_initialize(&block->link); 413 414 /* Allocate the block memory */ 415 block->addr = checked_malloc(size); 416 if (block->addr == NULL) { 417 free(block); 418 return NULL; 419 } 420 421 block->size = size; 422 423 /* Register the allocated block */ 424 list_append(&block->link, &mem_blocks); 425 mem_allocated += size + sizeof(mem_block_s); 426 mem_blocks_count++; 427 428 return block; 429 } 430 431 432 /** free_block 433 * 434 * Free the block of memory and the block control structure allocated by 435 * alloc_block. Set the global error_flag if an error occurs. 436 * 437 * @param block Block control structure 438 * 439 */ 440 static void free_block(mem_block_t block) 441 { 442 /* Unregister the block */ 443 list_remove(&block->link); 444 mem_allocated -= block->size + sizeof(mem_block_s); 445 mem_blocks_count--; 446 447 /* Free the memory */ 448 free(block->addr); 449 free(block); 450 } 451 452 453 /** expected_value 454 * 455 * Compute the expected value of a byte located at @pos in memory 456 * block described by @blk. 457 * 458 * @param blk Memory block control structure 459 * @param pos Position in the memory block data area 460 * 461 */ 462 static inline uint8_t expected_value(mem_block_t blk, uint8_t *pos) 463 { 464 return ((unsigned long) blk ^ (unsigned long) pos) & 0xff; 465 } 466 467 468 /** fill_block 469 * 470 * Fill the memory block controlled by @blk with data. 471 * 472 * @param blk Memory block control structure 473 * 474 */ 475 static void fill_block(mem_block_t blk) 476 { 477 uint8_t *pos; 478 uint8_t *end; 479 480 for (pos = blk->addr, end = pos + blk->size; pos < end; pos++) 481 *pos = expected_value(blk, pos); 482 } 483 484 485 /** check_block 486 * 487 * Check whether the block @blk contains the data it was filled with. 488 * Set global error_flag if an error occurs. 489 * 490 * @param blk Memory block control structure 491 * 492 */ 493 static void check_block(mem_block_t blk) 494 { 495 uint8_t *pos; 496 uint8_t *end; 497 498 for (pos = blk->addr, end = pos + blk->size; pos < end; pos++) { 499 if (*pos != expected_value (blk, pos)) { 500 TPRINTF("\nError: Corrupted content of a data block.\n"); 501 error_flag = true; 502 return; 503 } 504 } 505 } 506 507 508 static link_t *list_get_nth(link_t *list, unsigned int i) 509 { 510 unsigned int cnt = 0; 511 link_t *entry; 512 513 for (entry = list->next; entry != list; entry = entry->next) { 514 if (cnt == i) 515 return entry; 516 517 cnt++; 518 } 519 520 return NULL; 521 } 522 523 524 /** get_random_block 525 * 526 * Select a random memory block from the list of allocated blocks. 527 * 528 * @return Block control structure or NULL if the list is empty. 529 * 530 */ 531 static mem_block_t get_random_block(void) 532 { 533 if (mem_blocks_count == 0) 534 return NULL; 535 536 unsigned int blkidx = rand() % mem_blocks_count; 537 link_t *entry = list_get_nth(&mem_blocks, blkidx); 538 539 if (entry == NULL) { 540 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n"); 541 error_flag = true; 542 } 543 544 return list_get_instance(entry, mem_block_s, link); 545 } 546 547 548 #define RETURN_IF_ERROR \ 549 { \ 550 if (error_flag) \ 551 return; \ 552 } 553 554 555 static void do_subphase(phase_s *phase, subphase_s *subphase) 556 { 557 unsigned int cycles; 558 for (cycles = 0; /* always */; cycles++) { 559 560 if (subphase->cond.max_cycles && 561 cycles >= subphase->cond.max_cycles) { 208 for (unsigned int cycles = 0; /* always */; cycles++) { 209 210 if ((subphase->cond.max_cycles) && 211 (cycles >= subphase->cond.max_cycles)) { 562 212 /* 563 213 * We have performed the required number of … … 572 222 unsigned int rnd = rand() % 100; 573 223 if (rnd < subphase->prob.alloc) { 574 /* Compute a random number lying in interval <min_block_size, max_block_size> */ 224 /* 225 * Compute a random number lying in interval 226 * <min_block_size, max_block_size> 227 */ 575 228 int alloc = phase->alloc.min_block_size + 576 229 (rand() % (phase->alloc.max_block_size - phase->alloc.min_block_size + 1)); 577 230 578 mem_block_t blk = alloc_block(alloc);231 mem_block_t *blk = alloc_block(alloc); 579 232 RETURN_IF_ERROR; 580 233 … … 585 238 break; 586 239 } 587 588 240 } else { 589 241 TPRINTF("A"); 590 242 fill_block(blk); 243 RETURN_IF_ERROR; 591 244 } 592 245 593 246 } else if (rnd < subphase->prob.free) { 594 mem_block_t blk = get_random_block();247 mem_block_t *blk = get_random_block(); 595 248 if (blk == NULL) { 596 249 TPRINTF("F(R)"); … … 599 252 break; 600 253 } 601 602 254 } else { 603 255 TPRINTF("R"); … … 614 266 } 615 267 616 617 static void do_phase(phase_s *phase) 268 static void do_phase(phase_t *phase) 618 269 { 619 unsigned int subno; 620 621 for (subno = 0; subno < 3; subno++) { 622 subphase_s *subphase = & phase->subphases [subno]; 270 for (unsigned int subno = 0; subno < 3; subno++) { 271 subphase_t *subphase = &phase->subphases[subno]; 623 272 624 273 TPRINTF(".. Sub-phase %u (%s)\n", subno + 1, subphase->name); … … 632 281 init_mem(); 633 282 634 unsigned int phaseno;635 for (phaseno = 0; phaseno < sizeof_array(phases);phaseno++) {636 phase_ s*phase = &phases[phaseno];283 for (unsigned int phaseno = 0; phaseno < sizeof_array(phases); 284 phaseno++) { 285 phase_t *phase = &phases[phaseno]; 637 286 638 287 TPRINTF("Entering phase %u (%s)\n", phaseno + 1, phase->name); … … 645 294 } 646 295 296 TPRINTF("Cleaning up.\n"); 297 done_mem(); 647 298 if (error_flag) 648 299 return "Test failed"; -
uspace/app/tester/tester.c
r52a79081 ra33f0a6 63 63 #include "mm/malloc1.def" 64 64 #include "mm/malloc2.def" 65 #include "mm/malloc3.def" 66 #include "mm/mapping1.def" 65 67 #include "hw/serial/serial1.def" 66 68 #include "hw/misc/virtchar1.def" 69 #include "libext2/libext2_1.def" 67 70 #include "devs/devman1.def" 71 #include "devs/devman2.def" 68 72 {NULL, NULL, NULL, false} 69 73 }; -
uspace/app/tester/tester.h
r52a79081 ra33f0a6 38 38 #include <sys/types.h> 39 39 #include <bool.h> 40 #include <stacktrace.h> 40 41 41 42 #define IPC_TEST_SERVICE 10240 … … 46 47 extern char **test_argv; 47 48 49 /** 50 * sizeof_array 51 * @array array to determine the size of 52 * 53 * Returns the size of @array in array elements. 54 */ 55 #define sizeof_array(array) \ 56 (sizeof(array) / sizeof((array)[0])) 57 48 58 #define TPRINTF(format, ...) \ 49 { \59 do { \ 50 60 if (!test_quiet) { \ 51 fprintf(stderr, format, ##__VA_ARGS__); \61 fprintf(stderr, (format), ##__VA_ARGS__); \ 52 62 } \ 53 } 63 } while (0) 64 65 #define TSTACKTRACE() \ 66 do { \ 67 if (!test_quiet) { \ 68 stacktrace_print(); \ 69 } \ 70 } while (0) 54 71 55 72 typedef const char *(*test_entry_t)(void); … … 79 96 extern const char *test_malloc1(void); 80 97 extern const char *test_malloc2(void); 98 extern const char *test_malloc3(void); 99 extern const char *test_mapping1(void); 81 100 extern const char *test_serial1(void); 82 101 extern const char *test_virtchar1(void); 102 extern const char *test_libext2_1(void); 83 103 extern const char *test_devman1(void); 104 extern const char *test_devman2(void); 84 105 85 106 extern test_t tests[]; -
uspace/app/tetris/Makefile
r52a79081 ra33f0a6 34 34 shapes.c \ 35 35 scores.c \ 36 input.c \37 36 tetris.c \ 38 37 screen.c -
uspace/app/tetris/scores.c
r52a79081 ra33f0a6 1 /* $OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray Exp $ */ 2 /* $NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Chris Torek and Darren F. Provine. 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 10 4 * 11 5 * Redistribution and use in source and binary forms, with or without 12 6 * modification, are permitted provided that the following conditions 13 7 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)scores.c 8.1 (Berkeley) 5/31/93 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** Attributations 30 * 31 * scores.c 8.1 (Berkeley) 5/31/93 32 * NetBSD: scores.c,v 1.2 1995/04/22 07:42:38 cgd 33 * OpenBSD: scores.c,v 1.11 2006/04/20 03:25:36 ray 34 * 35 * Based upon BSD Tetris 36 * 37 * Copyright (c) 1992, 1993 38 * The Regents of the University of California. 39 * Distributed under BSD license. 40 * 41 * This code is derived from software contributed to Berkeley by 42 * Chris Torek and Darren F. Provine. 43 * 36 44 */ 37 45 … … 60 68 #include <err.h> 61 69 #include <time.h> 62 63 70 #include "screen.h" 64 71 #include "tetris.h" … … 118 125 int j; 119 126 size_t off; 120 console_event_t ev;127 kbd_event_t ev; 121 128 122 129 clear_screen(); … … 133 140 134 141 while (1) { 135 fflush(stdout);136 if (!console_get_ event(fphone(stdin), &ev))142 console_flush(console); 143 if (!console_get_kbd_event(console, &ev)) 137 144 exit(1); 138 145 -
uspace/app/tetris/scores.h
r52a79081 ra33f0a6 1 /* $OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert Exp $ */ 2 /* $NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd Exp $ */ 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 3 28 4 /*- 29 /** Attributations 30 * 31 * scores.h 8.1 (Berkeley) 5/31/93 32 * NetBSD: scores.h,v 1.2 1995/04/22 07:42:40 cgd 33 * OpenBSD: scores.h,v 1.5 2003/06/03 03:01:41 millert 34 * 35 * Based upon BSD Tetris 36 * 5 37 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 38 * The Regents of the University of California. 39 * Distributed under BSD license. 7 40 * 8 41 * This code is derived from software contributed to Berkeley by 9 42 * Chris Torek and Darren F. Provine. 10 43 * 11 * Redistribution and use in source and binary forms, with or without12 * modification, are permitted provided that the following conditions13 * are met:14 * 1. Redistributions of source code must retain the above copyright15 * notice, this list of conditions and the following disclaimer.16 * 2. Redistributions in binary form must reproduce the above copyright17 * notice, this list of conditions and the following disclaimer in the18 * documentation and/or other materials provided with the distribution.19 * 3. Neither the name of the University nor the names of its contributors20 * may be used to endorse or promote products derived from this software21 * without specific prior written permission.22 *23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33 * SUCH DAMAGE.34 *35 * @(#)scores.h 8.1 (Berkeley) 5/31/9336 44 */ 37 45 … … 41 49 /** @file 42 50 */ 43 44 51 45 52 /* -
uspace/app/tetris/screen.c
r52a79081 ra33f0a6 1 /* $OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray Exp $ */ 2 /* $NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft Exp $ */ 3 4 /*- 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Chris Torek and Darren F. Provine. 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 10 4 * 11 5 * Redistribution and use in source and binary forms, with or without 12 6 * modification, are permitted provided that the following conditions 13 7 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)screen.c 8.1 (Berkeley) 5/31/93 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** Attributations 30 * 31 * screen.c 8.1 (Berkeley) 5/31/93 32 * NetBSD: screen.c,v 1.4 1995/04/29 01:11:36 mycroft 33 * OpenBSD: screen.c,v 1.13 2006/04/20 03:25:36 ray 34 * 35 * Based upon BSD Tetris 36 * 37 * Copyright (c) 1992, 1993 38 * The Regents of the University of California. 39 * Distributed under BSD license. 40 * 41 * This code is derived from software contributed to Berkeley by 42 * Chris Torek and Darren F. Provine. 43 * 36 44 */ 37 45 … … 69 77 static const struct shape *lastshape; 70 78 79 static suseconds_t timeleft = 0; 80 81 console_ctrl_t *console; 82 71 83 72 84 /* … … 82 94 static void start_standout(uint32_t color) 83 95 { 84 fflush(stdout);85 console_set_rgb_color( fphone(stdout), 0xffffff,96 console_flush(console); 97 console_set_rgb_color(console, 0xffffff, 86 98 use_color ? color : 0x000000); 87 99 } … … 89 101 static void resume_normal(void) 90 102 { 91 fflush(stdout);92 console_set_style( fphone(stdout), STYLE_NORMAL);103 console_flush(console); 104 console_set_style(console, STYLE_NORMAL); 93 105 } 94 106 95 107 void clear_screen(void) 96 108 { 97 console_clear( fphone(stdout));109 console_clear(console); 98 110 moveto(0, 0); 99 111 } … … 105 117 { 106 118 resume_normal(); 107 console_clear( fphone(stdout));119 console_clear(console); 108 120 curscore = -1; 109 121 memset(curscreen, 0, sizeof(curscreen)); … … 115 127 void scr_init(void) 116 128 { 117 console_cursor_visibility( fphone(stdout), 0);129 console_cursor_visibility(console, 0); 118 130 resume_normal(); 119 131 scr_clear(); … … 122 134 void moveto(sysarg_t r, sysarg_t c) 123 135 { 124 fflush(stdout);125 console_set_pos( fphone(stdout), c, r);136 console_flush(console); 137 console_set_pos(console, c, r); 126 138 } 127 139 … … 130 142 static int get_display_size(winsize_t *ws) 131 143 { 132 return console_get_size( fphone(stdout), &ws->ws_col, &ws->ws_row);144 return console_get_size(console, &ws->ws_col, &ws->ws_row); 133 145 } 134 146 … … 136 148 { 137 149 sysarg_t ccap; 138 int rc = console_get_color_cap( fphone(stdout), &ccap);150 int rc = console_get_color_cap(console, &ccap); 139 151 140 152 if (rc != 0) … … 179 191 void scr_end(void) 180 192 { 181 console_cursor_visibility( fphone(stdout), 1);193 console_cursor_visibility(console, 1); 182 194 } 183 195 … … 302 314 resume_normal(); 303 315 304 fflush(stdout);316 console_flush(console); 305 317 } 306 318 … … 322 334 } 323 335 336 /** Sleep for the current turn time 337 * 338 * Eat any input that might be available. 339 * 340 */ 341 void tsleep(void) 342 { 343 suseconds_t timeout = fallrate; 344 345 while (timeout > 0) { 346 kbd_event_t event; 347 348 if (!console_get_kbd_event_timeout(console, &event, &timeout)) 349 break; 350 } 351 } 352 353 /** Get char with timeout 354 * 355 */ 356 int tgetchar(void) 357 { 358 /* 359 * Reset timeleft to fallrate whenever it is not positive 360 * and increase speed. 361 */ 362 363 if (timeleft <= 0) { 364 faster(); 365 timeleft = fallrate; 366 } 367 368 /* 369 * Wait to see if there is any input. If so, take it and 370 * update timeleft so that the next call to tgetchar() 371 * will not wait as long. If there is no input, 372 * make timeleft zero and return -1. 373 */ 374 375 wchar_t c = 0; 376 377 while (c == 0) { 378 kbd_event_t event; 379 380 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) { 381 timeleft = 0; 382 return -1; 383 } 384 385 if (event.type == KEY_PRESS) 386 c = event.c; 387 } 388 389 return (int) c; 390 } 391 392 /** Get char without timeout 393 * 394 */ 395 int twait(void) 396 { 397 wchar_t c = 0; 398 399 while (c == 0) { 400 kbd_event_t event; 401 402 if (!console_get_kbd_event(console, &event)) 403 return -1; 404 405 if (event.type == KEY_PRESS) 406 c = event.c; 407 } 408 409 return (int) c; 410 } 411 324 412 /** @} 325 413 */ -
uspace/app/tetris/screen.h
r52a79081 ra33f0a6 1 /* $OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert Exp $ */ 2 /* $NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd Exp $ */ 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 3 28 4 /*- 29 /** Attributations 30 * 31 * screen.h 8.1 (Berkeley) 5/31/93 32 * NetBSD: screen.h,v 1.2 1995/04/22 07:42:42 cgd 33 * OpenBSD: screen.h,v 1.5 2003/06/03 03:01:41 millert 34 * 35 * Based upon BSD Tetris 36 * 5 37 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 38 * The Regents of the University of California. 39 * Distributed under BSD license. 7 40 * 8 41 * This code is derived from software contributed to Berkeley by 9 42 * Chris Torek and Darren F. Provine. 10 43 * 11 * Redistribution and use in source and binary forms, with or without12 * modification, are permitted provided that the following conditions13 * are met:14 * 1. Redistributions of source code must retain the above copyright15 * notice, this list of conditions and the following disclaimer.16 * 2. Redistributions in binary form must reproduce the above copyright17 * notice, this list of conditions and the following disclaimer in the18 * documentation and/or other materials provided with the distribution.19 * 3. Neither the name of the University nor the names of its contributors20 * may be used to endorse or promote products derived from this software21 * without specific prior written permission.22 *23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33 * SUCH DAMAGE.34 *35 * @(#)screen.h 8.1 (Berkeley) 5/31/9336 44 */ 37 45 … … 48 56 49 57 #include <sys/types.h> 58 #include <io/console.h> 50 59 #include <async.h> 51 60 #include <bool.h> … … 56 65 } winsize_t; 57 66 67 extern console_ctrl_t *console; 58 68 extern winsize_t winsize; 59 69 … … 61 71 extern void clear_screen(void); 62 72 63 /* just calls putchar; for tputs */64 73 extern int put(int); 65 74 extern void scr_clear(void); … … 70 79 extern void scr_update(void); 71 80 81 extern void tsleep(void); 82 extern int tgetchar(void); 83 extern int twait(void); 84 72 85 /** @} 73 86 */ -
uspace/app/tetris/shapes.c
r52a79081 ra33f0a6 1 /* $OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt Exp $ */ 2 /* $NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd Exp $ */ 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 3 28 4 /*- 29 /** Attributations 30 * 31 * shapes.c 8.1 (Berkeley) 5/31/93 32 * NetBSD: shapes.c,v 1.2 1995/04/22 07:42:44 cgd 33 * OpenBSD: shapes.c,v 1.8 2004/07/10 07:26:24 deraadt 34 * 35 * Based upon BSD Tetris 36 * 5 37 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 38 * The Regents of the University of California. 39 * Distributed under BSD license. 7 40 * 8 41 * This code is derived from software contributed to Berkeley by 9 42 * Chris Torek and Darren F. Provine. 10 43 * 11 * Redistribution and use in source and binary forms, with or without12 * modification, are permitted provided that the following conditions13 * are met:14 * 1. Redistributions of source code must retain the above copyright15 * notice, this list of conditions and the following disclaimer.16 * 2. Redistributions in binary form must reproduce the above copyright17 * notice, this list of conditions and the following disclaimer in the18 * documentation and/or other materials provided with the distribution.19 * 3. Neither the name of the University nor the names of its contributors20 * may be used to endorse or promote products derived from this software21 * without specific prior written permission.22 *23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33 * SUCH DAMAGE.34 *35 * @(#)shapes.c 8.1 (Berkeley) 5/31/9336 44 */ 37 45 -
uspace/app/tetris/tetris.c
r52a79081 ra33f0a6 1 /* $OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray Exp $ */ 2 /* $NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Chris Torek and Darren F. Provine. 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 10 4 * 11 5 * Redistribution and use in source and binary forms, with or without 12 6 * modification, are permitted provided that the following conditions 13 7 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)tetris.c 8.1 (Berkeley) 5/31/93 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** Attributations 30 * 31 * tetris.c 8.1 (Berkeley) 5/31/93 32 * NetBSD: tetris.c,v 1.2 1995/04/22 07:42:47 cgd 33 * OpenBSD: tetris.c,v 1.21 2006/04/20 03:24:12 ray 34 * 35 * Based upon BSD Tetris 36 * 37 * Copyright (c) 1992, 1993 38 * The Regents of the University of California. 39 * Distributed under BSD license. 40 * 41 * This code is derived from software contributed to Berkeley by 42 * Chris Torek and Darren F. Provine. 43 * 36 44 */ 37 45 … … 56 64 #include <unistd.h> 57 65 #include <getopt.h> 58 59 #include "input.h"60 66 #include "scores.h" 61 67 #include "screen.h" … … 245 251 int ch; 246 252 253 console = console_init(stdin, stdout); 254 247 255 keys = "jkl pq"; 248 256 249 257 classic = 0; 250 showpreview = 1; 258 showpreview = 1; 251 259 252 260 while ((ch = getopt(argc, argv, "ck:ps")) != -1) … … 371 379 scr_msg(key_msg, 0); 372 380 scr_msg(msg, 1); 373 (void) fflush(stdout);374 } while ( rwait((struct timeval *) NULL) == -1);381 console_flush(console); 382 } while (!twait()); 375 383 376 384 scr_msg(msg, 0); -
uspace/app/tetris/tetris.h
r52a79081 ra33f0a6 1 /* $OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert Exp $ */ 2 /* $NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd Exp $ */ 1 /* 2 * Copyright (c) 2011 Martin Decky 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 3 28 4 /*- 29 /** Attributations 30 * 31 * tetris.h 8.1 (Berkeley) 5/31/93 32 * NetBSD: tetris.h,v 1.2 1995/04/22 07:42:48 cgd 33 * OpenBSD: tetris.h,v 1.9 2003/06/03 03:01:41 millert 34 * 35 * Based upon BSD Tetris 36 * 5 37 * Copyright (c) 1992, 1993 6 * The Regents of the University of California. All rights reserved. 38 * The Regents of the University of California. 39 * Distributed under BSD license. 7 40 * 8 41 * This code is derived from software contributed to Berkeley by 9 42 * Chris Torek and Darren F. Provine. 10 43 * 11 * Redistribution and use in source and binary forms, with or without12 * modification, are permitted provided that the following conditions13 * are met:14 * 1. Redistributions of source code must retain the above copyright15 * notice, this list of conditions and the following disclaimer.16 * 2. Redistributions in binary form must reproduce the above copyright17 * notice, this list of conditions and the following disclaimer in the18 * documentation and/or other materials provided with the distribution.19 * 3. Neither the name of the University nor the names of its contributors20 * may be used to endorse or promote products derived from this software21 * without specific prior written permission.22 *23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33 * SUCH DAMAGE.34 *35 * @(#)tetris.h 8.1 (Berkeley) 5/31/9336 44 */ 37 45 -
uspace/app/top/Makefile
r52a79081 ra33f0a6 33 33 SOURCES = \ 34 34 top.c \ 35 screen.c \ 36 input.c 35 screen.c 37 36 38 37 include $(USPACE_PREFIX)/Makefile.common -
uspace/app/top/screen.c
r52a79081 ra33f0a6 46 46 #include "top.h" 47 47 48 #define USEC_COUNT 1000000 49 48 50 static sysarg_t warn_col = 0; 49 51 static sysarg_t warn_row = 0; 52 static suseconds_t timeleft = 0; 53 54 console_ctrl_t *console; 50 55 51 56 static void screen_style_normal(void) 52 57 { 53 fflush(stdout);54 console_set_style( fphone(stdout), STYLE_NORMAL);58 console_flush(console); 59 console_set_style(console, STYLE_NORMAL); 55 60 } 56 61 57 62 static void screen_style_inverted(void) 58 63 { 59 fflush(stdout);60 console_set_style( fphone(stdout), STYLE_INVERTED);64 console_flush(console); 65 console_set_style(console, STYLE_INVERTED); 61 66 } 62 67 63 68 static void screen_moveto(sysarg_t col, sysarg_t row) 64 69 { 65 fflush(stdout);66 console_set_pos( fphone(stdout), col, row);70 console_flush(console); 71 console_set_pos(console, col, row); 67 72 } 68 73 69 74 static void screen_get_pos(sysarg_t *col, sysarg_t *row) 70 75 { 71 fflush(stdout);72 console_get_pos( fphone(stdout), col, row);76 console_flush(console); 77 console_get_pos(console, col, row); 73 78 } 74 79 75 80 static void screen_get_size(sysarg_t *col, sysarg_t *row) 76 81 { 77 fflush(stdout);78 console_get_size( fphone(stdout), col, row);82 console_flush(console); 83 console_get_size(console, col, row); 79 84 } 80 85 … … 84 89 85 90 if (clear) { 86 fflush(stdout);87 console_clear( fphone(stdout));91 console_flush(console); 92 console_clear(console); 88 93 } 89 94 … … 111 116 void screen_init(void) 112 117 { 113 fflush(stdout); 114 console_cursor_visibility(fphone(stdout), false); 118 console = console_init(stdin, stdout); 119 120 console_flush(console); 121 console_cursor_visibility(console, false); 115 122 116 123 screen_restart(true); … … 121 128 screen_restart(true); 122 129 123 fflush(stdout);124 console_cursor_visibility( fphone(stdout), true);130 console_flush(console); 131 console_cursor_visibility(console, true); 125 132 } 126 133 … … 508 515 } 509 516 510 fflush(stdout);517 console_flush(console); 511 518 } 512 519 … … 521 528 522 529 screen_newline(); 523 fflush(stdout); 530 console_flush(console); 531 } 532 533 /** Get char with timeout 534 * 535 */ 536 int tgetchar(unsigned int sec) 537 { 538 /* 539 * Reset timeleft whenever it is not positive. 540 */ 541 542 if (timeleft <= 0) 543 timeleft = sec * USEC_COUNT; 544 545 /* 546 * Wait to see if there is any input. If so, take it and 547 * update timeleft so that the next call to tgetchar() 548 * will not wait as long. If there is no input, 549 * make timeleft zero and return -1. 550 */ 551 552 wchar_t c = 0; 553 554 while (c == 0) { 555 kbd_event_t event; 556 557 if (!console_get_kbd_event_timeout(console, &event, &timeleft)) { 558 timeleft = 0; 559 return -1; 560 } 561 562 if (event.type == KEY_PRESS) 563 c = event.c; 564 } 565 566 return (int) c; 524 567 } 525 568 -
uspace/app/top/screen.h
r52a79081 ra33f0a6 35 35 #define TOP_SCREEN_H_ 36 36 37 #include <io/console.h> 37 38 #include "top.h" 39 40 extern console_ctrl_t *console; 38 41 39 42 extern void screen_init(void); … … 42 45 extern void print_warning(const char *, ...); 43 46 47 extern int tgetchar(unsigned int); 48 44 49 #endif 45 50 -
uspace/app/top/top.c
r52a79081 ra33f0a6 46 46 #include <sort.h> 47 47 #include "screen.h" 48 #include "input.h"49 48 #include "top.h" 50 49 -
uspace/app/trace/ipc_desc.c
r52a79081 ra33f0a6 33 33 */ 34 34 35 #include <ipc/common.h> 35 #include <kernel/ipc/ipc.h> 36 #include <kernel/ipc/ipc_methods.h> 36 37 #include <stdlib.h> 37 38 #include "ipc_desc.h" … … 39 40 ipc_m_desc_t ipc_methods[] = { 40 41 /* System methods */ 41 { IPC_M_CONNECT_TO_ME, "CONNECT_TO_ME" }, 42 { IPC_M_CONNECT_ME_TO, "CONNECT_ME_TO" }, 43 { IPC_M_PHONE_HUNGUP, "PHONE_HUNGUP" }, 44 { IPC_M_SHARE_OUT, "SHARE_OUT" }, 45 { IPC_M_SHARE_IN, "SHARE_IN" }, 46 { IPC_M_DATA_WRITE, "DATA_WRITE" }, 47 { IPC_M_DATA_READ, "DATA_READ" }, 48 { IPC_M_DEBUG_ALL, "DEBUG_ALL" }, 49 50 /* Well-known methods */ 51 { IPC_M_PING, "PING" }, 52 42 { IPC_M_PHONE_HUNGUP, "PHONE_HUNGUP" }, 43 { IPC_M_CONNECT_ME, "CONNECT_ME" }, 44 { IPC_M_CONNECT_ME_TO, "CONNECT_ME_TO" }, 45 { IPC_M_CONNECT_TO_ME, "CONNECT_TO_ME" }, 46 { IPC_M_SHARE_OUT, "SHARE_OUT" }, 47 { IPC_M_SHARE_IN, "SHARE_IN" }, 48 { IPC_M_DATA_WRITE, "DATA_WRITE" }, 49 { IPC_M_DATA_READ, "DATA_READ" }, 50 { IPC_M_DEBUG, "DEBUG" }, 51 53 52 /* Terminating entry */ 54 53 { 0, NULL } -
uspace/app/trace/ipcp.c
r52a79081 ra33f0a6 37 37 #include <adt/hash_table.h> 38 38 #include <sys/typefmt.h> 39 39 #include <kernel/ipc/ipc_methods.h> 40 40 #include "ipc_desc.h" 41 41 #include "proto.h" … … 268 268 proto_t *proto; 269 269 int cphone; 270 270 271 271 sysarg_t *resp; 272 272 oper_t *oper; 273 273 int i; 274 275 // printf("parse_answer\n"); 276 274 277 275 phone = pcall->phone_hash; 278 276 method = IPC_GET_IMETHOD(pcall->question); 279 277 retval = IPC_GET_RETVAL(*answer); 280 278 281 279 resp = answer->args; 282 280 283 281 if ((display_mask & DM_IPC) != 0) { 284 282 printf("Response to %p: retval=%" PRIdn ", args = (%" PRIun ", " … … 288 286 IPC_GET_ARG4(*answer), IPC_GET_ARG5(*answer)); 289 287 } 290 288 291 289 if ((display_mask & DM_USER) != 0) { 292 290 oper = pcall->oper; 293 294 if (oper != NULL && (oper->rv_type != V_VOID || oper->respc > 0)) { 291 292 if ((oper != NULL) && 293 ((oper->rv_type != V_VOID) || (oper->respc > 0))) { 295 294 printf("->"); 296 295 297 296 if (oper->rv_type != V_VOID) { 298 297 putchar(' '); … … 304 303 putchar('('); 305 304 for (i = 1; i <= oper->respc; ++i) { 306 if (i > 1) printf(", "); 305 if (i > 1) 306 printf(", "); 307 307 val_print(resp[i], oper->resp_type[i - 1]); 308 308 } 309 309 putchar(')'); 310 310 } 311 311 312 312 putchar('\n'); 313 313 } 314 314 } 315 316 if (phone == 0 && method == IPC_M_CONNECT_ME_TO && retval == 0) { 315 316 if ((phone == PHONE_NS) && (method == IPC_M_CONNECT_ME_TO) && 317 (retval == 0)) { 317 318 /* Connected to a service (through NS) */ 318 319 service = IPC_GET_ARG1(pcall->question); 319 320 proto = proto_get_by_srv(service); 320 if (proto == NULL) proto = proto_unknown; 321 321 if (proto == NULL) 322 proto = proto_unknown; 323 322 324 cphone = IPC_GET_ARG5(*answer); 323 325 if ((display_mask & DM_SYSTEM) != 0) { 324 326 printf("Registering connection (phone %d, protocol: %s)\n", cphone, 325 proto->name); 326 } 327 proto->name); 328 } 329 327 330 ipcp_connection_set(cphone, 0, proto); 328 331 } … … 334 337 pending_call_t *pcall; 335 338 unsigned long key[1]; 336 337 // printf("ipcp_call_in()\n"); 338 339 339 340 if ((hash & IPC_CALLID_ANSWERED) == 0 && hash != IPCP_CALLID_SYNC) { 340 341 /* Not a response */ … … 344 345 return; 345 346 } 346 347 347 348 hash = hash & ~IPC_CALLID_ANSWERED; 348 349 key[0] = hash; 349 350 350 351 item = hash_table_find(&pending_calls, key); 351 if (item == NULL) return; // No matching question found 352 352 if (item == NULL) 353 return; /* No matching question found */ 354 353 355 /* 354 356 * Response matched to question. … … 357 359 pcall = hash_table_get_instance(item, pending_call_t, link); 358 360 hash_table_remove(&pending_calls, key, 1); 359 361 360 362 parse_answer(hash, pcall, call); 361 363 free(pcall); -
uspace/app/trace/syscalls.c
r52a79081 ra33f0a6 40 40 [SYS_KLOG] ={ "klog", 3, V_INT_ERRNO }, 41 41 [SYS_TLS_SET] = { "tls_set", 1, V_ERRNO }, 42 42 43 [SYS_THREAD_CREATE] = { "thread_create", 3, V_ERRNO }, 43 44 [SYS_THREAD_EXIT] = { "thread_exit", 1, V_ERRNO }, … … 79 80 [SYS_SYSINFO_GET_DATA] = { "sysinfo_get_data", 5, V_ERRNO }, 80 81 81 [SYS_DEBUG_ ENABLE_CONSOLE] = { "debug_enable_console", 0, V_ERRNO },82 [SYS_DEBUG_ACTIVATE_CONSOLE] = { "debug_activate_console", 0, V_ERRNO }, 82 83 [SYS_IPC_CONNECT_KBOX] = { "ipc_connect_kbox", 1, V_ERRNO } 83 84 }; -
uspace/app/trace/trace.c
r52a79081 ra33f0a6 72 72 ipc_call_t thread_ipc_req[THBUF_SIZE]; 73 73 74 int phoneid;74 async_sess_t *sess; 75 75 bool abort_trace; 76 76 … … 81 81 82 82 static bool cev_valid; 83 static console_event_t cev;83 static kbd_event_t cev; 84 84 85 85 void thread_trace_start(uintptr_t thread_hash); … … 146 146 static int connect_task(task_id_t task_id) 147 147 { 148 int rc; 149 150 rc = async_connect_kbox(task_id); 151 152 if (rc == ENOTSUP) { 153 printf("You do not have userspace debugging support " 154 "compiled in the kernel.\n"); 155 printf("Compile kernel with 'Support for userspace debuggers' " 156 "(CONFIG_UDEBUG) enabled.\n"); 157 return rc; 158 } 159 160 if (rc < 0) { 148 async_sess_t *ksess = async_connect_kbox(task_id); 149 150 if (!ksess) { 151 if (errno == ENOTSUP) { 152 printf("You do not have userspace debugging support " 153 "compiled in the kernel.\n"); 154 printf("Compile kernel with 'Support for userspace debuggers' " 155 "(CONFIG_UDEBUG) enabled.\n"); 156 return errno; 157 } 158 161 159 printf("Error connecting\n"); 162 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, rc); 163 return rc; 164 } 165 166 phoneid = rc; 167 168 rc = udebug_begin(phoneid); 160 printf("ipc_connect_task(%" PRIu64 ") -> %d ", task_id, errno); 161 return errno; 162 } 163 164 int rc = udebug_begin(ksess); 169 165 if (rc < 0) { 170 166 printf("udebug_begin() -> %d\n", rc); 171 167 return rc; 172 168 } 173 174 rc = udebug_set_evmask( phoneid, UDEBUG_EM_ALL);169 170 rc = udebug_set_evmask(ksess, UDEBUG_EM_ALL); 175 171 if (rc < 0) { 176 172 printf("udebug_set_evmask(0x%x) -> %d\n ", UDEBUG_EM_ALL, rc); 177 173 return rc; 178 174 } 179 175 176 sess = ksess; 180 177 return 0; 181 178 } … … 188 185 int i; 189 186 190 rc = udebug_thread_read( phoneid, thread_hash_buf,187 rc = udebug_thread_read(sess, thread_hash_buf, 191 188 THBUF_SIZE*sizeof(unsigned), &tb_copied, &tb_needed); 192 189 if (rc < 0) { … … 314 311 315 312 memset(&call, 0, sizeof(call)); 316 rc = udebug_mem_read( phoneid, &call.args, sc_args[1], sizeof(call.args));313 rc = udebug_mem_read(sess, &call.args, sc_args[1], sizeof(call.args)); 317 314 318 315 if (rc >= 0) { … … 325 322 ipc_call_t question, reply; 326 323 int rc; 327 int phoneidx; 328 329 // printf("sc_ipc_call_sync_fast()\n"); 330 phoneidx = sc_args[0]; 324 int phoneid; 325 326 phoneid = sc_args[0]; 331 327 332 328 IPC_SET_IMETHOD(question, sc_args[1]); … … 337 333 IPC_SET_ARG5(question, 0); 338 334 339 // printf("memset\n");340 335 memset(&reply, 0, sizeof(reply)); 341 // printf("udebug_mem_read(phone=%d, buffer_ptr=%u, src_addr=%d, n=%d\n", 342 // phoneid, &reply.args, sc_args[5], sizeof(reply.args)); 343 rc = udebug_mem_read(phoneid, &reply.args, sc_args[5], sizeof(reply.args)); 344 // printf("dmr->%d\n", rc); 345 if (rc < 0) return; 346 347 // printf("call ipc_call_sync\n"); 348 ipcp_call_sync(phoneidx, &question, &reply); 336 rc = udebug_mem_read(sess, &reply.args, sc_args[5], sizeof(reply.args)); 337 if (rc < 0) 338 return; 339 340 ipcp_call_sync(phoneid, &question, &reply); 349 341 } 350 342 … … 355 347 356 348 memset(&question, 0, sizeof(question)); 357 rc = udebug_mem_read( phoneid, &question.args, sc_args[1],349 rc = udebug_mem_read(sess, &question.args, sc_args[1], 358 350 sizeof(question.args)); 359 351 … … 372 364 373 365 memset(&reply, 0, sizeof(reply)); 374 rc = udebug_mem_read( phoneid, &reply.args, sc_args[2],366 rc = udebug_mem_read(sess, &reply.args, sc_args[2], 375 367 sizeof(reply.args)); 376 368 … … 391 383 392 384 memset(&call, 0, sizeof(call)); 393 rc = udebug_mem_read(phoneid, &call, sc_args[0], sizeof(call)); 394 // printf("udebug_mem_read(phone %d, dest %d, app-mem src %d, size %d -> %d\n", 395 // phoneid, (int)&call, sc_args[0], sizeof(call), rc); 396 397 if (rc >= 0) { 385 rc = udebug_mem_read(sess, &call, sc_args[0], sizeof(call)); 386 387 if (rc >= 0) 398 388 ipcp_call_in(&call, sc_rc); 399 }400 389 } 401 390 … … 407 396 408 397 /* Read syscall arguments */ 409 rc = udebug_args_read(phoneid, thread_hash, sc_args); 410 411 async_serialize_start(); 412 413 // printf("[%d] ", thread_id); 398 rc = udebug_args_read(sess, thread_hash, sc_args); 414 399 415 400 if (rc < 0) { 416 401 printf("error\n"); 417 async_serialize_end();418 402 return; 419 403 } … … 432 416 break; 433 417 } 434 435 async_serialize_end();436 418 } 437 419 … … 444 426 445 427 /* Read syscall arguments */ 446 rc = udebug_args_read(phoneid, thread_hash, sc_args); 447 448 async_serialize_start(); 428 rc = udebug_args_read(sess, thread_hash, sc_args); 449 429 450 430 // printf("[%d] ", thread_id); … … 452 432 if (rc < 0) { 453 433 printf("error\n"); 454 async_serialize_end();455 434 return; 456 435 } … … 481 460 break; 482 461 } 483 484 async_serialize_end();485 462 } 486 463 487 464 static void event_thread_b(uintptr_t hash) 488 465 { 489 async_serialize_start();490 466 printf("New thread, hash %p\n", (void *) hash); 491 async_serialize_end();492 493 467 thread_trace_start(hash); 494 468 } … … 527 501 528 502 /* Run thread until an event occurs */ 529 rc = udebug_go( phoneid, thread_hash,503 rc = udebug_go(sess, thread_hash, 530 504 &ev_type, &val0, &val1); 531 505 … … 656 630 { 657 631 (void) arg; 658 632 633 console_ctrl_t *console = console_init(stdin, stdout); 634 659 635 while (true) { 660 636 fibril_mutex_lock(&state_lock); … … 662 638 fibril_condvar_wait(&state_cv, &state_lock); 663 639 fibril_mutex_unlock(&state_lock); 664 665 if (!console_get_ event(fphone(stdin), &cev))640 641 if (!console_get_kbd_event(console, &cev)) 666 642 return -1; 667 643 668 644 fibril_mutex_lock(&state_lock); 669 645 cev_valid = true; 670 646 fibril_condvar_broadcast(&state_cv); 671 fibril_mutex_unlock(&state_lock); 647 fibril_mutex_unlock(&state_lock); 672 648 } 673 649 } … … 675 651 static void trace_task(task_id_t task_id) 676 652 { 677 console_event_t ev;653 kbd_event_t ev; 678 654 bool done; 679 655 int i; … … 727 703 case KC_P: 728 704 printf("Pause...\n"); 729 rc = udebug_stop( phoneid, thash);705 rc = udebug_stop(sess, thash); 730 706 if (rc != EOK) 731 707 printf("Error: stop -> %d\n", rc); … … 743 719 printf("\nTerminate debugging session...\n"); 744 720 abort_trace = true; 745 udebug_end( phoneid);746 async_hangup( phoneid);721 udebug_end(sess); 722 async_hangup(sess); 747 723 748 724 ipcp_cleanup(); … … 816 792 proto_register(SERVICE_VFS, p); 817 793 794 #if 0 818 795 p = proto_new("console"); 819 796 … … 851 828 proto_console = p; 852 829 proto_register(SERVICE_CONSOLE, p); 830 #endif 853 831 } 854 832
Note:
See TracChangeset
for help on using the changeset viewer.
