2008年9月30日火曜日

GNUStep building with python.

i sometimes forget how to build GNUStep code.
following is code.


#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import re

if __name__ == '__main__':
if len(sys.argv) != 3:
print 'invalid arguments'
sys.exit(1)
print 'compiling starts'

opt_array = ['-fconstant-string-class=NSConstantString',
'-IC:\GNUstep\GNUstep\System\Library\Headers',
'-LC:\GNUstep\GNUstep\System\Library\Libraries',
'-lgnustep-base',
'-lobjc'
]

base_dir = os.getcwd()
filter = re.compile('\.m$')
linker = []
input = sys.argv[1]
output = sys.argv[2]

for dirpath, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filter.search(filename):
if filename == input:
continue
filename, ext = filename.split('.')
filename = os.path.join(dirpath, filename)
action = 'gcc -O %s -c %s.%s -o %s.o' %\
((' ').join(opt_array), filename, ext, filename)
print action
linker.append("%s.o" % filename)
os.system(action)

break
action = "gcc -O %s %s %s -o %s" %\
((' ').join(linker), input, (' ').join(opt_array),output)
print action
os.system(action)
print 'compiling ends'


2008年9月28日日曜日

xcode compiling option

at this time, i talk about C++ Tool of Command Line Utility.

1)expand Targets. after that expand your project.

2)you can see Compile Sources. expand it and click a right mouse button and select Get Info.

3)Select a tab "Build". You can see "Additional Compiler Flags". input compiler options that text area.

this is how to set compiling options. as for the rest, just push the Build button.

check this too.

2008年9月18日木曜日

As a programmer...

Assure codes. Make evidences to say "it's safe" for it.

Read documents.

Never forget data from outside is not secure.

These are principles for me.

2008年9月17日水曜日

handling pgm data with c++

i m trying to get raw data from pgm file. if you calculate file size from width and height, if you like 16bit data, the file size will be double, you can find the header size. but how do we get heaer info without calculating?

following is a part of the code.



int width, height, brightness, counter;
std::ifstream ifs;
//initialize
width = height = brightness = counter = 0;
ifs.open(input_file_name, std::ios::in);

std::string filetype;
std::string filetype_str;
std::getline(ifs, filetype);

std::string size_str;
std::getline(ifs, size_str);
std::istringstream size_stream(size_str);
size_stream >> width >> height;

std::string brightness_str;
std::getline(ifs, brightness_str);
std::istringstream brightness_stream(brightness_str);
brightness_stream >> brightness;

std::string header_needless;
std::getline(ifs, header_needless);

std::cout << filetype << std::endl;
std::cout << width << std::endl;
std::cout << height << std::endl;
std::cout << brightness << std::endl;

this means there are 4 lines for a header.

bayer data with dcraw

if you want to get bayer data from raw data, dcraw may be good. if you type like

dcraw -d -4 rawdata

you can get 16bit pgm data. the order is bayer structure. if you like 8 bit, you don't need to add "-4" option.

i will distribute a software to get bayer image with opencv someday.

2008年9月16日火曜日

iPod music backup script


#!/usr/bin/env python
# -*- coding: utf-8 -*-

### globals
import os
import shutil

def swapextensions(copy_from, copy_to):
count = 0
for path, subdirs, files in os.walk(copy_from):
for file in files:
if file[:1] != '.':
count += 1
shutil.copy('%s/%s'%(path,file), '%s/%s'%(copy_to,file))

if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print 'Usage: swapext rootdir before after'
sys.exit(100)
swapextensions(sys.argv[1], sys.argv[2])



how to use?

python copy_files.py /Volumes/xxx/iPod_Control/Music destination_path

change encoding with python


#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re

if __name__ == "__main__":
base_dir = os.getcwd()
filter = re.compile('\.h$|\.m$|\.cpp$|\.c$')
for dirpath, dirnames, filenames in os.walk(base_dir):
for filename in filenames:
if filter.search(filename):
p = os.path.join(dirpath, filename)
action = 'nkf --utf8 %s > %s_' % (p, p)
os.system(action)
action = 'mv %s_ %s' % (p, p)
os.system(action)