some code added

This commit is contained in:
Kolan Sh 2011-12-05 18:15:15 +03:00
parent ab6e95d5ff
commit ce649bbcb2
12 changed files with 920 additions and 0 deletions

336
bash/chess/chess.sh Executable file
View File

@ -0,0 +1,336 @@
#!/bin/bash
# Network chess by Evgeny Stepanischev http://bolknote.ru 2011
if [ $# -ne 2 ]; then
echo Usage: $0 host-of-opponent port
exit
fi
# Хост оппонента
HOST="$1"
# Общий порт
PORT="$2"
# Клавиатурные комбинации извстной длины
SEQLEN=(1b5b4. [2-7]. [cd]... [89ab].{5} f.{7})
# Фигуры
WHITE=(♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖)
BLACK=(♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟)
# Наш ход?
OURMOVE=
# Я чёрный или белый?
MYCOLOR=
# Доска
declare -a XY
# Курсор
CX=1 CY=7
TAKEN=
# Необходимые нам клавиатурные коды
KUP=1b5b41
KDOWN=1b5b42
KLEFT=1b5b44
KRIGHT=1b5b43
KSPACE=20
# Восстановление экрана
function Restore {
echo -ne "\033[5B\033[5B\033[?25h\033[m"
stty "$ORIG" 2>/dev/null
bind '"\r":accept-line'
}
trap Restore EXIT
# Выключаем Enter
bind -r '\r'
# Выключаем остальную клавиатуру
ORIG=`stty -g`
stty -echo
# Убирам курсор
echo -e "\033[?25l"
# Отдаём события клавиатуры в сеть
function ToNet {
echo $1 | nc "$HOST" "$PORT"
}
# Реакция на клавиши курсора
function React {
case $1 in
$KLEFT)
if [ $CX -gt 1 ]; then
CX=$(($CX-1))
PrintBoard
fi
;;
$KRIGHT)
if [ $CX -lt 8 ]; then
CX=$(($CX+1))
PrintBoard
fi
;;
$KUP)
if [ $CY -gt 1 ]; then
CY=$(($CY-1))
PrintBoard
fi
;;
$KDOWN)
if [ $CY -lt 8 ]; then
CY=$(($CY+1))
PrintBoard
fi
esac
# Отдаём события клавиатуры в сеть
[ "$OURMOVE" ] && ToNet $1
}
# Проверка совпадения с известной клавиатурной комбинацией
function CheckCons {
local i
for i in ${SEQLEN[@]}; do
if [[ $1 =~ ^$i ]]; then
return 0
fi
done
return 1
}
# Функция реакции на клавиатуру, вызывает React на каждую нажатую клавишу,
# кроме KSPACE — на неё возвращается управление
function PressEvents {
local real code action
# Цикл обработки клавиш, здесь считываются коды клавиш,
# по паузам между нажатиями собираются комбинации и известные
# обрабатываются сразу
while true; do
# измеряем время выполнения команды read и смотрим код нажатой клавиши
# akw NR==1||NR==4 забирает только строку №1 (там время real) и №4 (код клавиши)
eval $( (time -p read -r -s -n1 ch; printf 'code %d\n' "'$ch") 2>&1 |
awk 'NR==1||NR==4 {print $1 "=" $2}' | tr '\r\n' ' ')
# read возвращает пусто для Enter и пробела, присваиваем им код 20,
# а так же возвращаются отрицательные коды для UTF8
if [ "$code" = 0 ]; then
code=20
else
[ $code -lt 0 ] && code=$((256+$code))
code=$(printf '%02x' $code)
fi
if [ $code = $KSPACE ]; then
[ "$OURMOVE" ] && ToNet $KSPACE
SpaceEvent && return
continue
fi
# Если клавиши идут подряд (задержки по времени нет)
if [ $real = 0.00 ]; then
seq="$seq$code"
if CheckCons $seq; then
React $seq
seq=
fi
# Клавиши идут с задержкой (пользователь не может печатать с нулевой задержкой),
# значит последовательность собрана, надо начинать новую
else
[ "$seq" ] && React $seq
seq=$code
# возможно последовательность состоит из одного символа
if CheckCons $seq; then
React $seq
seq=
fi
fi
done
}
# Проверяем чёрная или белая фигура
function CheckColor {
echo -n ${1:0:1}
}
# Первичное заполнение доски
function FillBoard {
local x y ch
for y in {1..8}; do
for x in {1..8}; do
ch='S '
if [ $y -le 2 ]; then
ch=B${BLACK[$x+8*$y-9]}
else
if [ $y -ge 7 ]; then
ch=W${WHITE[$x+8*$y-57]}
fi
fi
XY[$x+100*$y]=$ch
done
done
}
# Вывод букв по краю доски
function PrintBoardLetters {
local letters=abcdefgh
[ -z "$OURMOVE" ] && echo -ne "\033[30m" || echo -ne "\033[0m"
echo -n ' '
for x in {0..7}; do
echo -n "${letters:$x:1} "
done
echo
}
# Вывод цифры по краю доски
function PrintBoardDigit {
[ -z "$OURMOVE" ] && echo -ne "\033[30m"
echo -en " $((9-$1))\033[0m "
}
# Вывод доски
function PrintBoard {
local x y c ch
local colors=('48;5;209;37;1' '48;5;94;37;1')
PrintBoardLetters
for y in {1..8}; do
PrintBoardDigit $y
for x in {1..8}; do
c=${colors[($x+$y) & 1]}
ch=${XY[$x+100*$y]}
if [[ $CX == $x && $CY == $y ]]; then
c="$c;7"
[ "$TAKEN" ] && ch=$TAKEN
[ $MYCOLOR == B ] && c="$c;38;5;16"
fi
[[ $(CheckColor "$ch") == "B" ]] && c="$c;38;5;16"
echo -en "\033[${c}m${ch:1:1} \033[m"
done
PrintBoardDigit $y
echo
done
PrintBoardLetters
echo -e "\033[11A"
}
# Приём событий
function NetListen {
nc -l -p $PORT
}
# Готовы слушать события сети
function NetEvents {
local code
while true; do
code=$(NetListen)
[[ "$code" == "$KSPACE" ]] && SpaceEvent && return
React $code
done
}
# Реакция на нажатие Space и Enter — взять или положить фигуру
function SpaceEvent {
local xy
# Проверяем, есть ли фигура под курсором
let xy="$CX+$CY*100"
# Фигуры нет
if [ "${XY[$xy]:-S }" = "S " ]; then
if [ -z "$TAKEN" ]; then
echo -en "\007"
else
# Положили фигуру
XY[$xy]=$TAKEN
TAKEN=
return 0
fi
# Фигура есть
else
# Мы не должны позволять «съесть» свою фигуру
if [[ $(CheckColor "$TAKEN") == $(CheckColor "${XY[$xy]}") ]]; then
echo -en "\007"
else
# Мы взяли фигуру
TAKEN=${XY[$xy]}
XY[$xy]="S "
fi
fi
return 1
}
# Очистка клавиатурного буфера
function ClearKeyboardBuffer {
# Быстро — через zsh
which -s zsh && (zsh -c 'while {} {read -rstk1 || break}'; return)
# Медленно — через bash
local delta
while true; do
delta=`(time -p read -rs -n1 -t1) 2>&1 | awk 'NR==1{print $2}'`
[[ "$delta" == "0.00" ]] || break
done
}
FillBoard
# Кто будет ходить первым
ToNet HI
[[ "$(NetListen)" == "HI" ]] && OURMOVE=1
ToNet ULOOSE
[ "$OURMOVE" ] && MYCOLOR=W || MYCOLOR=B
PrintBoard
# Основной цикл — обрабатываем события из сети или с клавиатуры
while true; do
if [ -n "$OURMOVE" ]; then
ClearKeyboardBuffer
PressEvents
OURMOVE=
else
NetEvents
OURMOVE=1
fi
PrintBoard
done

34
c/dtparser_test/File1.cpp Normal file
View File

@ -0,0 +1,34 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
#include <stdio.h>
#include "insys_parser/vcl/DataFilesFunctions.hpp"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s = "2010.10.22 11:12:13.14";
printf("%s\n", s.c_str());
prec_tm dt = datetime_sscanf(s.c_str());
printf("year = %.4d\n", dt.tm.tm_year + 1900);
printf("month = %.2d\n", dt.tm.tm_mon + 1);
printf("day = %.2d\n", dt.tm.tm_mday);
printf("hour = %.2d\n", dt.tm.tm_hour);
printf("min = %.2d\n", dt.tm.tm_min);
printf("sec = %.2d\n", dt.tm.tm_sec);
printf("ssec = %.2d\n", dt.ss);
AnsiString as = "123";
printf("%c\n", as[1]);
system("pause");
return 0;
}
//---------------------------------------------------------------------------

88
c/dtparser_test/File2.cpp Normal file
View File

@ -0,0 +1,88 @@
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <tchar.h>
//---------------------------------------------------------------------------
#pragma argsused
//---------------------------------------------------------------------------
#define _XOPEN_SOURCE /* glibc2 needs this */
#include <time.h>
#include <stdio.h>
// òî÷íîå âðåìÿ
struct prec_tm {
struct tm tm; // ñòàíäàðòíûé timestamp
unsigned char ss; // ñàíòèñåêóíäû
};
// òî÷íîå âðåìÿ -> êîë-âî ñàíòèñåêóíä (!!)
int time2ss(struct prec_tm * ptm, __int64 * ss) {
time_t time = mktime(&ptm->tm);
if (time == (time_t)-1) {
fprintf(stderr, "mktime(3) fails with error: can't convert date to time!\n");
return 1;
}
*ss = ((__int64)time) * 100 + ptm->ss;
return 0;
}
// êîë-âî ñàíòèñåêóíä -> òî÷íîå âðåìÿ (!!)
int ss2time(const __int64 * ss, struct prec_tm * ptm) {
time_t time = (*ss)/100;
struct tm * ret = localtime(&time);
if (ret == NULL) {
fprintf(stderr, "localtime_r(3) fails with error: can't convert time to date!\n");
return 1;
}
ptm->tm = *ret;
ptm->ss = (*ss)%100;
return 0;
}
// ñòðîêà -> òî÷íîå âðåìÿ
int str2time(const char * date, struct prec_tm * ptm) {
char *ret = strptime(date, "%d.%m.%Y %T", &ptm->tm);
// ÿ íå ïîíÿë ñòàíäàðòà, âèäèìî îòâåòñòâåííîñòü çà êîððåêòíîñòü âõîäíûõ äàííûõ ëîæèòñÿ íà òîãî, êòî êëàä¸ò...
// if (ret == NULL) {
// fprintf(stderr, "strptime(3) error: can't parse date!\n");
// return 1;
// }
// ptm->tm.tm_year -= 1900;
int len = strlen(date); // ìåäëåííàÿ îïåðàöèÿ, ó ïðèíöèïå...
ptm->ss = atoi(date + len - 2);
return 0;
}
// òî÷íîå âðåìÿ -> ñòðîêà
int time2str(struct prec_tm * ptm, char * buf) {
sprintf(buf, "%.2u.%.2u.%.4u %.2u:%.2u:%.2u.%.2u", ptm->tm.tm_mday, ptm->tm.tm_mon + 1,
ptm->tm.tm_year + 1900, ptm->tm.tm_hour, ptm->tm.tm_min, ptm->tm.tm_sec, ptm->ss);
return 0;
}
int main(void) {
const char date[] = "23.12.2008 10:50:59.36";
char buf[1024];
struct prec_tm ptm;
str2time(date, &ptm);
__int64 ss;
time2ss(&ptm, &ss);
ss2time(&ss, &ptm);
time2str(&ptm, buf);
printf("%s\n", buf);
system("pause");
return 0;
}

102
c/dtparser_test/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=time2ss2time
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 = \
time2ss2time.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
time2ss2time.o: \
time2ss2time.c

View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include "dtparser.h"
int main(int argc, char *argv[])
{
std::string s = "2010.10.22 11:12:13.14";
printf("%s\n", s.c_str());
prec_tm dt = datetime_sscanf(s.c_str());
printf("year = %.4d\n", dt.tm.tm_year + 1900);
printf("month = %.2d\n", dt.tm.tm_mon + 1);
printf("day = %.2d\n", dt.tm.tm_mday);
printf("hour = %.2d\n", dt.tm.tm_hour);
printf("min = %.2d\n", dt.tm.tm_min);
printf("sec = %.2d\n", dt.tm.tm_sec);
printf("ssec = %.2d\n", dt.ss);
return 0;
}

View File

@ -0,0 +1,50 @@
#define _XOPEN_SOURCE
#include <time.h>
#define __USE_UNIX98
#include <stdio.h>
#include <string.h>
int mktime_test(const char* str)
{
struct tm local_tm, local_tm2;
time_t local_time;
char buffer[128];
memset(buffer, 0, sizeof(buffer));
puts(str);
if (strptime(str, "%Y-%m-%d %H:%M:%S", &local_tm) == NULL)
{
fprintf(stderr, "failed to convert `%s' to struct tm\n", str);
return 1;
}
snprintf(buffer, sizeof(buffer), "%d-%02d-%02d %02d:%02d:%02d",
local_tm.tm_year + 1900, local_tm.tm_mon + 1, local_tm.tm_mday,
local_tm.tm_hour, local_tm.tm_min, local_tm.tm_sec);
puts(buffer);
if (strcmp(str, buffer) != 0)
{
fprintf(stderr, "strptime() failed\n");
return 1;
}
local_tm.tm_isdst = -1;
local_time = mktime(&local_tm);
localtime_r(&local_time, &local_tm2);
snprintf(buffer, sizeof(buffer), "%d-%02d-%02d %02d:%02d:%02d",
local_tm2.tm_year + 1900, local_tm2.tm_mon + 1, local_tm2.tm_mday,
local_tm2.tm_hour, local_tm2.tm_min, local_tm2.tm_sec);
puts(buffer);
if (strcmp(str, buffer) != 0)
{
fprintf(stderr, "mktime() or localtime_r() failed\n");
return 1;
}
return 0;
}
int main()
{
mktime_test("1981-07-01 00:00:00");
mktime_test("1981-07-01 00:00:00");
return 0;
}

View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <time.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
putenv("TZ=");
tzset();
int64_t ss;
struct tm t;
//t.tm_isdst = -1;
t.tm_year = 2007;
t.tm_mon = 11;
t.tm_mday = 25;
t.tm_hour = 17;
t.tm_min = 33;
t.tm_sec = 52;
time_t time = mktime(&t);
t = *gmtime(&time);
printf("%d.%d.%d %d:%d:%d", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
return 0;
}

102
c/eps_pass/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=eps_pass
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 = \
eps_pass.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
eps_pass.o: \
eps_pass.c

35
c/eps_pass/eps_pass.c Normal file
View File

@ -0,0 +1,35 @@
#include <stdio.h>
int main() {
int eps = 5, r = 0, s = 0;
printf("[0, 0]");
for (r = 1; r < eps; r++) {
printf(" (r = %d)", r);
printf(" [%d, %d]", r, 0);
printf(" [%d, %d]", -r, 0);
printf(" [%d, %d]", 0, r);
printf(" [%d, %d]", 0, -r);
for (s = 1; s < eps; s++) {
printf(" (s = %d)", s);
printf(" [%d, %d]", r, s);
printf(" [%d, %d]", r, -s);
printf(" [%d, %d]", -r, s);
printf(" [%d, %d]", -r, -s);
if (s != r) {
printf(" [%d, %d]", s, r);
printf(" [%d, %d]", s, -r);
printf(" [%d, %d]", -s, r);
printf(" [%d, %d]", -s, -r);
}
}
}
return 0;
}

102
c/localtime/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=localtime
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 = \
localtime.o
$(TARGET0): $(target_objs0)
$(CC) $(LDFLAGS) -o $@ $(target_objs0)
localtime.o: \
localtime.c

15
c/localtime/localtime.c Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
#include <time.h>
#include <inttypes.h>
int main(void)
{
time_t result;
result = time(NULL);
printf("%s%ju secs since the Epoch\n",
asctime(localtime(&result)),
(uintmax_t)result);
return(0);
}

6
php/email_test.php Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/php
<?php
mail("mecareful@gmail.com","subject","message","headers");
?>