This commit is contained in:
Kolan Sh 2011-09-01 22:53:49 +04:00
commit a740b628ce
11 changed files with 527 additions and 5 deletions

View File

@ -1,14 +1,34 @@
#!/bin/bash
ninstalled=0
installed=
for p in `qlist -IC`; do
installed[ninstalled]=$p
let ninstalled++
done
idx=0
cd /usr/portage/ || exit -1
for d in *-* virtual; do
if [[ `qlist -IC $d/ | wc -l` == 0 ]]; then
dir_list=`ls -1 --color=never -d *-*/ virtual/ | sed 's~/$~~' | sort`
for d in $dir_list ; do
d=${d%/}
if [[ `qlist -IC $d | wc -l` == 0 ]]; then
echo $d/
else
for pn in $d/*; do
if [[ `qlist -IC $pn | wc -l` == 0 ]]; then
pn_list=`ls -1 --color=never -d ${d}/*/ | sed 's~/$~~' | sort`
for pn in $pn_list; do
pn=${pn%/}
while [[ "${installed[$idx]}" < "$pn" && $idx -lt $ninstalled ]]; do
let idx++
done
if [[ "$pn" == "${installed[$idx]}" ]]; then
let idx++
else
echo $pn/
fi
done
fi
done

102
c/fp_overflow/Makefile Normal file
View File

@ -0,0 +1,102 @@
# This file is generated with smake.sh.
# You can use this make file with instruction make to
# use one of build mode: debug, profile, develop, release.
# No need to call make clean if You make with other mode,
# because the Makefile containes rules for automatically clean.
# Some usage examples:
# make # default mode is debug
# CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release
# Report bugs to <mecareful@gmail.com>
#_________________________________
# ENVIRONMENT |
#________________________________|
CC=cc
CXX=c++
LIBRARIES=
TARGET0=fp_overflow
TARGET= $(TARGET0)
INCLUDE1=$(HOME)/projects/include
INCLUDE2=/usr/local/include
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
#________________________________________
# BUILD SCRIPT (don't change) |
#_______________________________________|
ifeq ($(mode),)
mode = debug
endif
ifeq ($(mode),debug)
CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS := $(LDFLAGS)
endif
ifeq ($(mode),profile)
CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS := -g -p $(LDFLAGS)
endif
ifeq ($(mode),develop)
CFLAGS := -O2 -g $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
ifeq ($(mode),release)
CFLAGS := -O2 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
CFLAGS += -Wall
LDFLAGS += -Wall $(LIBRARIES)
all: change_make_options $(TARGET)
ifneq ($(mode),debug)
ifneq ($(mode),profile)
ifneq ($(mode),develop)
ifneq ($(mode),release)
@echo "Invalid build mode."
@echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'"
@exit 1
endif
endif
endif
endif
@echo ".........................."
@echo "Building on "$(mode)" mode "
@echo "CFLAGS=$(CFLAGS)"
@echo "LDFLAGS=$(LDFLAGS)"
@echo ".........................."
OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~')
OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~')
OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~')
change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING...
@make clean &>/dev/null
@echo "MODE=$(mode)" > make_options.out
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif
%.o :
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
clean:
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGET)
.PHONY: all change_make_options clean
#_________________________________
# R U L E S |
#________________________________|
target_objs0 = \
fp_overflow.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
fp_overflow.o: \
fp_overflow.c

View File

@ -0,0 +1,94 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <signal.h>
#include <sys/types.h>
#include <ucontext.h>
#include <fpu_control.h>
/*#ifdef DEBUG
#define DIE_HERE raise(SIGFPE)
#else
#define DIE_HERE
#endif*/
void sigfpe_handler(int signo, siginfo_t *si, void *data)
{
ucontext_t *uc = (ucontext_t *) data;
uc->uc_flags = 0;
/*ucontext_t *uc;
uc = (ucontext_t *) data;
switch (signo) {
case SIGFPE:
fprintf(stdout, "Caught FPE\n");
uc->uc_mcontext.gregs[REG_PC] = uc->uc_mcontext.gregs[REG_nPC];
break;
default:
fprintf(stdout, "default handler\n");
}*/
}
void no_exc()
{
double a = 1.932847289347532947238e20;
double b = 1.932847293472394732424e-128;
a /= b;
a /= b;
a /= b;
a /= b;
a /= b;
a /= b;
a /= b;
double zero = 0;
a /= zero;
printf("a=%f\n", a);
unsigned int c = 3984794;
c *= c;
c *= c;
c *= c;
printf("c=%u\n", c);
}
int div_by_zero()
{
/* "volatile" needed to eliminate compile-time optimizations */
volatile unsigned long x = 42;
volatile unsigned long y = 0;
x=x/y;
return 0; /* Never reached */
}
int div_intmin_by_invone()
{
volatile unsigned long x=INT_MIN;
volatile unsigned long y=-1;
x=x/y;
return 0;
}
int main(void)
{
//_FPU_SETCW (_FPU_DEFAULT);
/* register SIGFPE handler */
/*struct sigaction sa, osa;
unsigned int b = ULONG_MAX;
sa.sa_sigaction = sigfpe_handler;
sigaction(SIGFPE, &sa, &osa);*/
//no_exc();
//div_by_zero();
div_intmin_by_invone();
return EXIT_SUCCESS;
}

102
c/printf_round/Makefile Normal file
View File

@ -0,0 +1,102 @@
# This file is generated with smake.sh.
# You can use this make file with instruction make to
# use one of build mode: debug, profile, develop, release.
# No need to call make clean if You make with other mode,
# because the Makefile containes rules for automatically clean.
# Some usage examples:
# make # default mode is debug
# CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release
# Report bugs to <mecareful@gmail.com>
#_________________________________
# ENVIRONMENT |
#________________________________|
CC=cc
CXX=c++
LIBRARIES=
TARGET0=printf_round
TARGET= $(TARGET0)
INCLUDE1=$(HOME)/projects/include
INCLUDE2=/usr/local/include
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
#________________________________________
# BUILD SCRIPT (don't change) |
#_______________________________________|
ifeq ($(mode),)
mode = debug
endif
ifeq ($(mode),debug)
CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS := $(LDFLAGS)
endif
ifeq ($(mode),profile)
CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS := -g -p $(LDFLAGS)
endif
ifeq ($(mode),develop)
CFLAGS := -O2 -g $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
ifeq ($(mode),release)
CFLAGS := -O2 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
CFLAGS += -Wall
LDFLAGS += -Wall $(LIBRARIES)
all: change_make_options $(TARGET)
ifneq ($(mode),debug)
ifneq ($(mode),profile)
ifneq ($(mode),develop)
ifneq ($(mode),release)
@echo "Invalid build mode."
@echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'"
@exit 1
endif
endif
endif
endif
@echo ".........................."
@echo "Building on "$(mode)" mode "
@echo "CFLAGS=$(CFLAGS)"
@echo "LDFLAGS=$(LDFLAGS)"
@echo ".........................."
OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~')
OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~')
OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~')
change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING...
@make clean &>/dev/null
@echo "MODE=$(mode)" > make_options.out
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif
%.o :
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
clean:
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGET)
.PHONY: all change_make_options clean
#_________________________________
# R U L E S |
#________________________________|
target_objs0 = \
printf_round.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
printf_round.o: \
printf_round.c

View File

@ -0,0 +1,9 @@
#include <stdio.h>
int main(void)
{
long double tmp = 4.1 * 0.25 - 1;
tmp = 0.025;
printf("%.20lf\n", tmp);
}

View File

@ -203,7 +203,6 @@ void tex_parse(const char *source, size_t len, struct tex_struct_s **tex_struct,
return;
}
#ifdef __TEX_PARSER_DEBUG
puts("<-OBJ_UNDEF");
puts("<-OBJ_UNDEF");

102
cpp/list_sort/Makefile Normal file
View File

@ -0,0 +1,102 @@
# This file is generated with smake.sh.
# You can use this make file with instruction make to
# use one of build mode: debug, profile, develop, release.
# No need to call make clean if You make with other mode,
# because the Makefile containes rules for automatically clean.
# Some usage examples:
# make # default mode is debug
# CFLAGS="-O2 -march=core2 -mtune=core2 --msse4.1 mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,-ass-needed" make mode=develop
# CFLAGS="-O2 -march=amdfam10 -mtune=amdfam10 -msse4a --mfpmath=sse -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=profile
# CFLAGS="-O2 -march=k6-2 -mtune=k6-2 -m3dnow --mfpmath=387 -fomit-frame-pointer -pipe" LDFLAGS="-Wl,-O1 -Wl,--as-needed" make mode=release
# Report bugs to <mecareful@gmail.com>
#_________________________________
# ENVIRONMENT |
#________________________________|
CC=cc
CXX=c++
LIBRARIES=-lstdc++
TARGET0=list_sort
TARGET= $(TARGET0)
INCLUDE1=$(HOME)/projects/include
INCLUDE2=/usr/local/include
INCLUDE=-I$(INCLUDE1) -I$(INCLUDE2)
#________________________________________
# BUILD SCRIPT (don't change) |
#_______________________________________|
ifeq ($(mode),)
mode = debug
endif
ifeq ($(mode),debug)
CFLAGS := -O0 -g -std=gnu99 -pedantic -Wextra -Wconversion $(CFLAGS)
LDFLAGS := $(LDFLAGS)
endif
ifeq ($(mode),profile)
CFLAGS := -O0 -g -p -ftest-coverage -Wcoverage-mismatch $(CFLAGS)
LDFLAGS := -g -p $(LDFLAGS)
endif
ifeq ($(mode),develop)
CFLAGS := -O2 -g $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
ifeq ($(mode),release)
CFLAGS := -O2 $(CFLAGS)
LDFLAGS := -O1 $(LDFLAGS)
endif
CFLAGS += -Wall
LDFLAGS += -Wall $(LIBRARIES)
all: change_make_options $(TARGET)
ifneq ($(mode),debug)
ifneq ($(mode),profile)
ifneq ($(mode),develop)
ifneq ($(mode),release)
@echo "Invalid build mode."
@echo "Please use 'make mode=release', 'make mode=develop', 'make mode=profile' or 'make mode=debug'"
@exit 1
endif
endif
endif
endif
@echo ".........................."
@echo "Building on "$(mode)" mode "
@echo "CFLAGS=$(CFLAGS)"
@echo "LDFLAGS=$(LDFLAGS)"
@echo ".........................."
OLD_BUILD_MODE=$(shell grep ^MODE make_options.out 2>/dev/null | sed 's~^MODE=~~')
OLD_BUILD_CFLAGS=$(shell grep ^CFLAGS make_options.out 2>/dev/null | sed 's~^CFLAGS=~~')
OLD_BUILD_LDFLAGS=$(shell grep ^LDFLAGS make_options.out 2>/dev/null | sed 's~^LDFLAGS=~~')
change_make_options:
ifneq ($(mode)|$(CFLAGS)|$(LDFLAGS), $(OLD_BUILD_MODE)|$(OLD_BUILD_CFLAGS)|$(OLD_BUILD_LDFLAGS))
@echo CLEANING...
@make clean &>/dev/null
@echo "MODE=$(mode)" > make_options.out
@echo "CFLAGS=$(CFLAGS)" >> make_options.out
@echo "LDFLAGS=$(LDFLAGS)" >> make_options.out
endif
%.o :
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
clean:
$(RM) *.o *.out callgrind.out.* *.gcno $(TARGET)
.PHONY: all change_make_options clean
#_________________________________
# R U L E S |
#________________________________|
target_objs0 = \
list_sort.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
list_sort.o: \
list_sort.cpp

View File

@ -0,0 +1,46 @@
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <list>
#include <string>
bool str_num_cmp(const std::string& s1, const std::string& s2)
{
return atoi(s1.c_str()) < atoi(s2.c_str()) ? true : false;
}
void show_list(const std::list<std::string> lst)
{
for (std::list<std::string>::const_iterator it = lst.begin();
it != lst.end();
it++)
std::cout << it->c_str() << " " << std::endl;
}
int main(void)
{
char *arr[] = {
"324", "2133", "938", "202", "199", "200"
};
std::list<std::string> lst;
for (size_t i = 0, max_i = sizeof(arr) / sizeof(char *); i < max_i; i++)
lst.push_back(arr[i]);
std::cout << "Not sorted:" << std::endl;
show_list(lst);
lst.sort();
std::cout << "Standart sorted:" << std::endl;
show_list(lst);
lst.sort(str_num_cmp);
std::cout << "str_num_cmp sorted:" << std::endl;
show_list(lst);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,21 @@
#include <set>
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
char *m[] = {"slkdjfs", "klsdjf", "lskdjfl", "lskdjf", "lskdjfl", "iogsfdneowrf", "oisdisjfwe", "qwldjsdj", "fsoiosjfs"};
set<string> s;
for (size_t i = 0, max_i = sizeof(m) / sizeof(char *); i < max_i; i++)
s.insert(m[i]);
for (set<string>::const_iterator it = s.begin(); it != s.end(); it++)
cout << it->c_str() << endl;
return 0;
}

View File

@ -0,0 +1,8 @@
# -*- coding: cp1251 -*-
for i in range(0,256):
c=unicode(chr(i),"koi8-r")
c.encode("UTF-8")
for i in range(0,128):
print i," "

19
python/unicode.py Normal file
View File

@ -0,0 +1,19 @@
declare
@ucs nvarchar(4000),
@utf varchar(8000),
@w varbinary(2),
@i int
set @ucs = N'яфя Åk Paço عوديهالشرموطةناناالشرموطةفاطمةالشرموطةليلىالسحاقيةهالة'
set @utf = ''
set @i = 1
while @i <= len(@ucs)
begin
set @w = (select utf8 from ucs2utf8 where ucs2 = unicode(substring(@ucs, @i, 1)))
if @w/256 != 0 set @utf = @utf + char(@w/256)
if @w-(@w/256)*256 != 0 set @utf = @utf + char(@w-(@w/256)*256)
set @i = @i + 1
end
print @utf