Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1470 → Rev 1472

/uspace/trunk/libc/include/string.h
39,9 → 39,11
 
int strcmp(const char *, const char *);
 
char *strcpy(char *dest, const char *src);
char *strncpy(char *dest, const char *src, size_t n);
 
size_t strlen(const char *str);
 
int strcmp(const char *str1, const char *str2);
char *strchr(const char *str, int c);
char *strrchr(const char *str, int c);
 
/uspace/trunk/libc/include/async.h
1,3 → 1,31
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef _libc_ASYNC_H_
#define _libc_ASYNC_H_
 
/uspace/trunk/libc/include/stdlib.h
35,4 → 35,19
#define abort() _exit(1)
#define exit(status) _exit((status))
 
#define RAND_MAX 714025
 
extern long int random(void);
extern void srandom(unsigned int seed);
 
static inline int rand(void)
{
return random();
}
static inline void srand(unsigned int seed)
{
srandom(seed);
}
 
 
#endif
/uspace/trunk/libc/include/err.h
0,0 → 1,35
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef _libc__ERR_H_
#define _libc__ERR_H_
 
extern void errx (int __status, __const char *__format, ...)
__attribute__ ((__noreturn__, __format__ (__printf__, 2, 3)));
 
#endif
/uspace/trunk/libc/generic/string.c
246,3 → 246,15
 
return (sgn?-number:number);
}
 
char *strcpy(char *dest, const char *src)
{
while (*(dest++) = *(src++))
;
}
 
char *strncpy(char *dest, const char *src, size_t n)
{
while (*(dest++) = *(src++) && --n)
;
}
/uspace/trunk/libc/generic/stdlib.c
0,0 → 1,41
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <stdlib.h>
 
static long glbl_seed = 1;
 
long int random(void)
{
return glbl_seed = ((1366*glbl_seed + 150889) % RAND_MAX);
}
 
void srandom(unsigned int seed)
{
glbl_seed = seed;
}
/uspace/trunk/libc/generic/err.c
0,0 → 1,36
/*
* Copyright (C) 2006 Ondrej Palkovsky
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#include <stdio.h>
#include <stdlib.h>
 
void errx (int __status, __const char *__format, ...)
{
printf("TODO...errx\n");
_exit(0);
}
/uspace/trunk/libc/Makefile
69,7 → 69,9
generic/async.c \
generic/libadt/list.o \
generic/libadt/hash_table.o \
generic/time.c
generic/time.c \
generic/err.c \
generic/stdlib.c
 
ARCH_SOURCES += \
arch/$(ARCH)/src/entry.s \
/uspace/trunk/tetris/screen.c
42,8 → 42,8
#include <sys/ioctl.h>
 
#include <err.h>
#include <setjmp.h>
#include <signal.h>
//#include <setjmp.h>
//#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
204,31 → 204,31
}
 
/* this foolery is needed to modify tty state `atomically' */
static jmp_buf scr_onstop;
//static jmp_buf scr_onstop;
 
static void
stopset(int sig)
{
sigset_t sigset;
/* static void */
/* stopset(int sig) */
/* { */
/* sigset_t sigset; */
 
(void) signal(sig, SIG_DFL);
(void) kill(getpid(), sig);
sigemptyset(&sigset);
sigaddset(&sigset, sig);
(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0);
longjmp(scr_onstop, 1);
}
/* (void) signal(sig, SIG_DFL); */
/* (void) kill(getpid(), sig); */
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, sig); */
/* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
/* longjmp(scr_onstop, 1); */
/* } */
 
static void
scr_stop(int sig)
{
sigset_t sigset;
// sigset_t sigset;
 
scr_end();
(void) kill(getpid(), sig);
sigemptyset(&sigset);
sigaddset(&sigset, sig);
(void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0);
/* (void) kill(getpid(), sig); */
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, sig); */
/* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
scr_set();
scr_msg(key_msg, 1);
}
241,24 → 241,24
{
struct winsize ws;
struct termios newtt;
sigset_t sigset, osigset;
// sigset_t sigset, osigset;
void (*ttou)(int);
 
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
sigaddset(&sigset, SIGTTOU);
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN)
(void) signal(SIGTSTP, SIG_IGN);
if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN)
(void) signal(SIGTTOU, SIG_IGN);
/*
* At last, we are ready to modify the tty state. If
* we stop while at it, stopset() above will longjmp back
* to the setjmp here and we will start over.
*/
(void) setjmp(scr_onstop);
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* sigaddset(&sigset, SIGTTOU); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
/* if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */
/* (void) signal(SIGTSTP, SIG_IGN); */
/* if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */
/* (void) signal(SIGTTOU, SIG_IGN); */
/* /\* */
/* * At last, we are ready to modify the tty state. If */
/* * we stop while at it, stopset() above will longjmp back */
/* * to the setjmp here and we will start over. */
/* *\/ */
/* (void) setjmp(scr_onstop); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
Rows = 0, Cols = 0;
if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
Rows = ws.ws_row;
283,7 → 283,7
newtt.c_oflag &= ~OXTABS;
if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
stop("tcsetattr() fails");
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
/*
* We made it. We are now in screen mode, modulo TIstr
291,13 → 291,13
*/
if (TIstr)
putstr(TIstr); /* termcap(5) says this is not padded */
if (tstp != SIG_IGN)
(void) signal(SIGTSTP, scr_stop);
if (ttou != SIG_IGN)
(void) signal(SIGTTOU, ttou);
/* if (tstp != SIG_IGN) */
/* (void) signal(SIGTSTP, scr_stop); */
/* if (ttou != SIG_IGN) */
/* (void) signal(SIGTTOU, ttou); */
 
isset = 1;
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
// (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
scr_clear();
}
 
307,12 → 307,12
void
scr_end(void)
{
sigset_t sigset, osigset;
// sigset_t sigset, osigset;
 
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
sigaddset(&sigset, SIGTTOU);
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* sigaddset(&sigset, SIGTTOU); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
/* move cursor to last line */
if (LLstr)
putstr(LLstr); /* termcap(5) says this is not padded */
321,12 → 321,12
/* exit screen mode */
if (TEstr)
putstr(TEstr); /* termcap(5) says this is not padded */
(void) fflush(stdout);
// (void) fflush(stdout);
(void) tcsetattr(0, TCSADRAIN, &oldtt);
isset = 0;
/* restore signals */
(void) signal(SIGTSTP, tstp);
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
/* (void) signal(SIGTSTP, tstp); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
}
 
void
365,12 → 365,12
cell *bp, *sp;
regcell so, cur_so = 0;
int i, ccol, j;
sigset_t sigset, osigset;
// sigset_t sigset, osigset;
static const struct shape *lastshape;
 
sigemptyset(&sigset);
sigaddset(&sigset, SIGTSTP);
(void) sigprocmask(SIG_BLOCK, &sigset, &osigset);
/* sigemptyset(&sigset); */
/* sigaddset(&sigset, SIGTSTP); */
/* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
 
/* always leave cursor after last displayed point */
curscreen[D_LAST * B_COLS - 1] = -1;
465,8 → 465,8
}
if (cur_so)
putpad(SEstr);
(void) fflush(stdout);
(void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
/* (void) fflush(stdout); */
/* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */
}
 
/*
/uspace/trunk/tetris/tetris.c
45,7 → 45,7
* Tetris (or however it is spelled).
*/
 
#include <sys/param.h>
//#include <sys/param.h>
#include <sys/time.h>
#include <sys/types.h>
 
151,8 → 151,15
tmp = &shapes[classic? tmp->rotc : tmp->rot];
return (tmp);
}
 
static void srandomdev(void)
{
struct timeval tv;
 
gettimeofday(&tv, NULL);
srandom(tv.tv_sec + tv.tv_usec / 100000);
}
 
int
main(int argc, char *argv[])
{
216,7 → 223,7
errx(1, "duplicate command keys specified.");
}
if (keys[i] == ' ')
strlcpy(key_write[i], "<space>", sizeof key_write[i]);
strncpy(key_write[i], "<space>", sizeof key_write[i]);
else {
key_write[i][0] = keys[i];
key_write[i][1] = '\0';
291,7 → 298,7
scr_update();
scr_msg(key_msg, 0);
scr_msg(msg, 1);
(void) fflush(stdout);
// (void) fflush(stdout);
} while (rwait((struct timeval *)NULL) == -1);
scr_msg(msg, 0);
scr_msg(key_msg, 1);