이글루스 | 로그인
메뉴릿
카테고리
전체
공지사항
계획
Languages
Humanities
Mathematics
Education
Economics
Computers
HCI
Media
Engineering
Natural Science
TmaxSoft
BluemoonSoft
미분류
최근 등록된 덧글
제가 갖고 있는 소스 파일..
by 언제나19 at 10/17
우왕 고맙습니다~~. ..
by 언제나19 at 10/16
http://nethack.byus..
by uriel at 10/16
근본적으로 activation ..
by uriel at 10/16
다운 안되는데여;;;;;
by 강병진 at 10/14
일단, 형변환 자체가 ..
by uriel at 04/11
어제는 괜히 xfix 실행..
by 언제나19 at 01/18
좀 기다리세요. 내년 4..
by 언제나19 at 11/04
바꾸어라.. 언제나19-..
by kang at 11/03
네 블로그는 언제나 삽..
by kang at 11/03
최근 등록된 트랙백
textcube를 다시 설치
by 공부가 본업.
gnuplot을 c 함수로 ..
by 상품 + 글 의견 남기기
gsl, gnu scientific li..
by 상품 + 글 의견 남기기
ubuntu, ati에서 dual..
by 상품 + 글 의견 남기기
Data browser로 sql d..
by 공부가 본업.
근황
by Yi jeon goo
근황
by Yi jeon goo
라이프로그
화려한 휴가
화려한 휴가

좋지 아니한가
좋지 아니한가

300
300

포토로그

언제나19의 포토로그
메모장 실험
메모장도 로그가 남나 실험
이전블로그
more...
이글루링크
◈ ◈ ◈ 바다가 머무는 ..
Mono log
Liard's newspaper
Yochin의 대전생활.
M log
art.oriented
* Sea of Blue *
이글루 파인더
rss

skin by 狂風
lua로 csv 파일 내용 capture


api spec 정리를 표로 만들었었다.
이걸 header file 형식으로 바꾸기 위해

1,returntype,function,parametertype,parameter,comments,win32api
,,,parametertype,parameter
이런 식으로 된 csv 파일을 만들었다.

  for w in string.gmatch(Line, "(.-),") do
   if (j == 3) then table.insert(Output.parameterTypes, w) end;
   if (j == 4) then table.insert(Output.parameters, w) end;
   j = j + 1;
  end
에서 string.gmatch를 썼는데, string.find로 여러 변수 한번에 대입하기
를 쓸 껄 그랬다.
진작 20.3 - Captures  부터 봤어야 했다.

지금은 아무 것도 없는 빈 줄 찾기가 안된다. 빈 줄은 없어야돼.
parametertype에 해당하는 4번째 field는 언제나 비어있지 않아야해.
void 일 경우에 띄어쓰기 안하는 처리를 안했다.
마지막 파라미터에 쉼표가 안들어가야되는데, 실수했다.

Executables/lua*/work/apicsv2header.lua
dofile(파일이름)으로 실행하면 된다.

function PrintResult(Output)
 local result = '';
 if (Output.returnType and Output.funcName) then
  if (Output.description) then
   result = result .. '/** ' .. Output.description
    .. '\n    matches ' .. Output.win32 .. ' in win32'
    .. ' */\n';
  end
  result = result ..
   Output.returnType .. '\n' ..
   Output.funcName .. '\n' .. '(' .. '\n';
 end
 if
  table.getn(Output.parameterTypes) > 0
  and table.getn(Output.parameters) > 0
  then
  for k1, v1 in ipairs(Output.parameters) do
   result = result
    .. Output.parameterTypes[k1];
   if (Output.parameters[k1] ~= '') then
    result = result .. '\t' .. Output.parameters[k1]
    .. ',';
   end
   result = result .. '\n'
  end 
 end
 if (result ~= '') then result = result .. ');\n'; end
 
 print(result);
end


local file = io.open("work/api.csv");

local I = 0;
local Output = {};
 Output.parameterTypes = {};
 Output.parameters = {};

repeat
 local Line = file:read("*l");
 if (Line == nil) then break; end;
 
 Line = Line..",";

 --
 if (string.find(Line, "%d*,,,") == 1) then
  local j = 0;
  for w in string.gmatch(Line, "(.-),") do
   if (j == 3) then table.insert(Output.parameterTypes, w) end;
   if (j == 4) then table.insert(Output.parameters, w) end;
   j = j + 1;
  end
 else --if (string.find(Line, ".*,.*,.*,.*")) then
--  if not string.find(Line, ".*,.*,.*,.*") then
--   break;
--  end
  local j = 0;
  if Output then
   PrintResult(Output);
  end
  Output = {};
  Output.parameterTypes = {};
  Output.parameters = {};
  for w in string.gmatch(Line, "(.-),") do
   if (j == 1) then Output.returnType = w; end
   if (j == 2) then Output.funcName = w; end
   if (j == 3) then table.insert(Output.parameterTypes, w); end
   if (j == 4) then table.insert(Output.parameters, w); end
   if (j == 5) then Output.description = w; end
    if (j == 6) then Output.win32 = w; end
   j = j + 1;
  end
 end
 
 I = I + 1;

until Line == nil;

PrintResult(Output);

file:close();




local file = io.open("work/api.csv");

local I = 0;
repeat
 local Line = file:read("*l");
 if (Line == nil) then break; end;
 
 Line = Line..",";
 
 local Output = {};
 Output.parameterTypes = {};
 Output.parameters = {};
 
 --
 if (string.find(Line, "%d*,,,") == 1) then
  local j = 0;
  for w in string.gmatch(Line, "(.-),") do
   if (j == 3) then table.insert(Output.parameterTypes, w) end;
   if (j == 4) then table.insert(Output.parameters, w) end;
   j = j + 1;
  end
 else
  local j = 0;
  for w in string.gmatch(Line, "(.-),") do
   if (j == 1) then Output.returnType = w; end
   if (j == 2) then Output.funcName = w; end
   if (j == 3) then table.insert(Output.parameterTypes, w); end
   if (j == 4) then table.insert(Output.parameters, w); end
   if (j == 5) then Output.description = w; end
    if (j == 6) then Output.win32 = w; end
   j = j + 1;
  end
 end
 
 local result = '';
 

 if (Output.returnType and Output.funcName) then
  if I ~= 0 then
   result = result .. ')' .. '\n';
  end
  if (Output.description) then
   result = result .. '/** ' .. Output.description
    .. '\n    matches ' .. Output.win32 .. ' in win32'
    .. ' */\n';
  end
  result = result ..
   Output.returnType .. '\n' ..
   Output.funcName .. '\n' .. '(' .. '\n';
 end
 if
 table.getn(Output.parameterTypes) > 0
  and table.getn(Output.parameters) > 0
  then
  for k1, v1 in ipairs(Output.parameters) do
   result = result
    .. Output.parameterTypes[k1];
   if (Output.parameters[k1] ~= '') then
    result = result .. '\t' .. Output.parameters[k1]
    .. ',';
   end
   result = result .. '\n'
  end 
 end
 
 print(result);
 
 I = I + 1;

until Line == nil;
if I ~= 0 then print(');\n'); end

file:close();

by 언제나19 | 2008/10/13 22:06 | Computers | 트랙백 | 덧글(3)
트랙백 주소 : http://always19.egloos.com/tb/2092378
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by kang at 2008/11/03 17:44
네 블로그는 언제나 삽질하는 글밖에 없구나...ㅎㅎㅎ
Commented by kang at 2008/11/03 17:48
바꾸어라.. 언제나19->언제나삽질...
그나저나 OS는 언제 나오는겨?..
Commented by 언제나19 at 2008/11/04 20:14
좀 기다리세요. 내년 4월까지 만들지만, 시디 굽는데 시간이 더 걸려요. 신혼여행 사진 보니까 엄청 부럽네요. 난 아직 만들어지지도 않은 OS랑 지루해하고 있는데_

:         :

:

비공개 덧글


◀ 이전 페이지 다음 페이지 ▶