Cygwin + Eclipse CDT 로 개발환경 설치하기

Posted at 2020/04/20 23:23 // in Programming // by Daniel

오랜만에 Cygwin + CDT를 써봤습니다.
설정하는데 세시간쯤 걸린 것 같네요.

마지막에 디버깅 환경에서 문제가 있었는데,
( Can’t find a source file at “/cygdrive/c/ 라며 에러 남)
아래 링크에서 답을 찾았습니다.https://stackoverflow.com/questions/17267632/how-to-get-gdb-working-with-eclipse-cdt-under-windows-fails-to-find-source-code

Go to Windows->Preference->C/C++ -> Debug -> Source Lookup Path. Add following ‘Path mapping’. \cygdrive\c -> c:\

방법
Eclipse + CDT 설치
저는 이거 설치 https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2020-03/R/eclipse-cpp-2020-03-R-incubation-win32-x86_64.zip

Cygwin 설치
저는 64비트와 32비트 둘 다 설치했는데 64비트면 충분할 듯.
패키지는 gcc-core, gcc-g++, gdb, make, gconvr 등을 깔면 되는데 저는 libc라던가 엄청 많이 깔아뒀습니다.
심지어 잘 안되길래 mingw64-x86 시리즈도 다 설치...

저는 PATH를 기본 설정을 안했기 때문에, eclipe 설정을 추가해줬습니다. (workspace 설정)
Preferences -> C/C++ -> Build -> Environment 에서 Variable을 Add로 추가. Variable: PATH Value: c:\cygwin64\bin
(설정은 Append variables to native environment)

그리고 위에 얘기했듯이 디버깅 환경을 위해,

Go to Windows->Preference->C/C++ -> Debug -> Source Lookup Path. Add following ‘Path mapping’.
\cygdrive\c -> c:\

이렇게 세팅해주시면 되네요.

프로젝트 생성해봅니다.
new->Project -> C/C++ -> C Project
Next
프로젝트 이름(hello로 여기선 설정)과 Hello World ANSI C Project 에 Cygwin GCC 선택

빌드 된 hello.exe 를 클릭해놓고,
우클릭 -> Run as -> C/C++ Local Application 으로 실행
하면 됩니다.

프로파일링은 기본 Path를 추가해야만(시스템 Path) 동작하더라.
우클릭 -> Profile -> Profiling Tools Configuration에서
Environment -> Path 추가 (아까처럼)해봤자 동작하지 않았음.

크리에이티브 커먼즈 라이센스
Creative Commons License

이클립스 개발 중 org.eclipse.core.runtime.applications extension point 정보가 제대로 보이지 않을 때

Posted at 2019/03/12 08:12 // in Programming // by Daniel

나중을 위해 저장.
이클립스 개발 중 extensions에서 org.eclipse.core.runtime.applications extension point 정보가 제대로 보이지 않을 때
타겟에서 플러그인이 선택되어있지 않아서인데,
필요한 플러그인 이름은 org.eclipse.core.runtime.source 라고 생각하겠지만
사실은 org.eclipse.equinox.app.source 이다. 타겟에 위 플러그인을 추가하면 된다.
이것 때문에 몇주간 삽질함.

크리에이티브 커먼즈 라이센스
Creative Commons License

Apache POI의 엑셀 Formula에BIN2HEX HEX2BIN 지원 추가하기

Posted at 2018/01/10 15:04 // in Programming // by Daniel

POI의 엑셀 Formula 중에, BIN2HEX HEX2BIN 이 지원되지 않았습니다.
이를 커스텀으로 추가하려고 코드를 짜봤습니다.


package com.autron.odin.excel.core.ethercc.imports;

import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;

/** *

 * com.autron.odin.excel.core.ethercc.imports
 *   |_ Hex2Bin.java
 * 
 * Description:    to support formula HEX2BIN
 * Howto Use : AnalysisToolPak.registerFunction("HEX2BIN", Hex2Bin.instance);
 * 
* Company: Hyundai Autron * Author: JSSONG * Date: 2018. 1. 10. * * version *
 * Revision History:  
 * Version No:  Date of update:    Updated by:  Changes
 * 1.0.0   		2018. 1. 10.        JSSONG       refs #10669 #11020 to support formula HEX2BIN
 * 
*/
class Hex2Bin implements FreeRefFunction { public static final FreeRefFunction instance = new Hex2Bin(); /* (non-Javadoc) * see org.apache.poi.ss.formula.functions.FreeRefFunction#evaluate(org.apache.poi.ss.formula.eval.ValueEval[], org.apache.poi.ss.formula.OperationEvaluationContext) */ Override public ValueEval evaluate(ValueEval[] paramArrayOfValueEval, OperationEvaluationContext paramOperationEvaluationContext) { return evaluateHex2Bin(paramArrayOfValueEval); }

/** * Desc : evaluate HEX2BIN * HEX2BIN * 16진수를 2진수로 변환합니다. * – number 필수 요소입니다. 변환할 16진수입니다. * number는 최대 10자까지 사용할 수 있습니다. * number의 최상위 비트는 부호 비트(오른쪽에서 40번째 비트)이고, 나머지 9비트는 값을 나타내는 비트입니다. * 음수는 2의 보수 표기법으로 표시됩니다. * – places 선택 요소입니다. * 사용할 자릿수입니다. * places를 생략하면 HEX2BIN에서는 필요한 최소 자릿수가 사용됩니다. * places를 지정하면 반환 값의 앞부분을 0으로 채울 수 있습니다. * * Method Name : evaluateHex2Bin * param paramArrayOfValueEval * @return evaluated StringEval(BIN value) or ErrorEval.VALUE_INVALID */ private ValueEval evaluateHex2Bin(ValueEval[] paramArrayOfValueEval) { String strHex = “”; int places = -1; if (paramArrayOfValueEval.length==1) { strHex = OperandResolver.coerceValueToString(paramArrayOfValueEval0); } if (paramArrayOfValueEval.length==2) { strHex = OperandResolver.coerceValueToString(paramArrayOfValueEval0); try { places = OperandResolver.coerceValueToInt(paramArrayOfValueEval1); } catch (EvaluationException e) { e.printStackTrace(); } } try { String binStr = Integer.toString(Integer.parseInt(strHex, 16),2); if (places>0) { if (places > binStr.length()) { int num0 = places – binStr.length(); String str0 = “”; for (;num0>0;num0—) { str0 += “0”; } binStr = str0 + binStr; } } // System.out.println(strHex + “ “ + places + “ -> “ + binStr); return new StringEval(binStr); } catch (Exception e) { return ErrorEval.VALUE_INVALID; } }
}


package com.autron.odin.excel.core.ethercc.imports;

import org.apache.poi.ss.formula.OperationEvaluationContext;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.functions.FreeRefFunction;

/** *

 * com.autron.odin.excel.core.ethercc.imports
 *   |_ Bin2Hex.java
 * 
 * Description:    to support formula BIN2HEX.
 * Howto Use : AnalysisToolPak.registerFunction("BIN2HEX", Bin2Hex.instance);
 * 
* Company: Hyundai Autron * Author: JSSONG * Date: 2018. 1. 10. * * version *
 * Revision History:  
 * Version No:  Date of update:    Updated by:  Changes
 * 1.0.0   		2018. 1. 10.        JSSONG       refs #10669 #11020 to support formula BIN2HEX
 * 
*/
class Bin2Hex implements FreeRefFunction { public static final FreeRefFunction instance = new Bin2Hex(); /** * Desc : Private Constructor of Bin2Hex.java class */ private Bin2Hex() { // make it private } /** * Desc : * Method Name : evaluate * param paramArrayOfValueEval * param paramOperationEvaluationContext * return */ @Override public ValueEval evaluate(ValueEval[] paramArrayOfValueEval, OperationEvaluationContext paramOperationEvaluationContext) {
// System.out.println(“BIN2HEX “ + paramArrayOfValueEval + paramOperationEvaluationContext); return evaluateBin2Hex(paramArrayOfValueEval); }

/** * Desc : evaluate BIN2HEX * Method Name : evaluateBin2Hex * BIN2HEX(number, [places]) * - number 필수 요소입니다. 변환할 2진수입니다. * number는 최대 10자(10비트)까지 사용할 수 있습니다. 최상위 비트는 부호 비트이고 나머지 9비트는 값을 * 나타내는 비트입니다. 음수는 2의 보수 표기법으로 표시됩니다. * - places 선택 요소입니다. 사용할 자릿수입니다. * places를 생략하면 필요한 최소 자릿수가 사용됩니다. places를 지정하면 반환 값의 앞부분을 0으로 채울 수 * 있습니다. * param paramArrayOfValueEval * @return evaluated StringEval(HEX value) or ErrorEval.VALUE_INVALID */ private ValueEval evaluateBin2Hex(ValueEval[] paramArrayOfValueEval) { String strBin = “”; int places = -1; if (paramArrayOfValueEval.length==1) { strBin = OperandResolver.coerceValueToString(paramArrayOfValueEval0); } if (paramArrayOfValueEval.length==2) { strBin = OperandResolver.coerceValueToString(paramArrayOfValueEval0); try { places = OperandResolver.coerceValueToInt(paramArrayOfValueEval1); } catch (EvaluationException e) { e.printStackTrace(); } } try { String hexStr = Integer.toString(Integer.parseInt(strBin, 2),16); if (places>0) { if (places > hexStr.length()) { int num0 = places – hexStr.length(); String str0 = “”; for (;num0>0;num0—) { str0 += “0”; } hexStr = str0 + hexStr; } } // System.out.println(strBin + “ “ + places + “ -> “ + hexStr); return new StringEval(hexStr); } catch (Exception e) { return ErrorEval.VALUE_INVALID; } } }

사용법은 위 클래스를 추가하고 런타임에

AnalysisToolPak.registerFunction("BIN2HEX", Bin2Hex.instance);
AnalysisToolPak.registerFunction("HEX2BIN", Hex2Bin.instance);

코드를 호출하면 됩니다.
이외에도 지원안되는 함수가 많이 있습니다.

제 사용 예는 아래와 같습니다.


// Register BIN2HEX Formula
AnalysisToolPak.registerFunction(“BIN2HEX”, Bin2Hex.instance);

// Register HEX2BIN formula
AnalysisToolPak.registerFunction(“HEX2BIN”, Hex2Bin.instance);

evaluator = wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();

wb는 org.apache.poi.ss.usermodel.Workbook 타입입니다.

크리에이티브 커먼즈 라이센스
Creative Commons License

opal - SWT 위에서 아기자기한 위젯들

Posted at 2017/02/14 16:59 // in Programming // by Daniel

https://github.com/lcaron/opal

여기 가면 있다.
원래 nebula 말고 다른 위젯이 있나 찾아보고있었는데
이런 것도 있더군.

https://github.com/lcaron/opal/blob/releases/V1.0.4/opal-1.0.4-src.zip?raw=true
를 다운 받는다면 test 폴더에 각 위젯들을 테스트한 코드가 들어있다.
로그인창 부터 프로퍼티 테이블, blur 패널, notification 등등 자그만 위젯들이 많다.

사용자 삽입 이미지

사용자 삽입 이미지
사용자 삽입 이미지

하나씩 실행해보면 알 수 있다.

크리에이티브 커먼즈 라이센스
Creative Commons License

C, C++ 주석 인식해 비교하는 diff 스크립트 (sh, sed)

Posted at 2014/07/03 17:05 // in Programming // by Daniel

제가 잊어버릴까봐 공유합니다.

사용자 스크립트로 먼저 코멘트를 strip 하고
그 결과를 가지고 비교하여 diff 여부를 리턴합니다.

#!/bin/sh
	
  1. C, C++ comments aware diff
  2. this uses stripcomment script to strip comments

Usage=“Usage: {script name} {file1} {file2}”
if [ $# -eq 0 ]; then # if no argument specified echo $Usage # print Usage string value exit 1
fi
if [ $# -eq 1 ]; then # if no argument specified echo $Usage # print Usage string value exit 1
fi
FILE1=$1
FILE2=$2
TMPFILE1=/tmp/aa$$
TMPFILE2=/tmp/bb$$

~/bin/stripcomment $FILE1 > $TMPFILE1
~/bin/stripcomment $FILE2 > $TMPFILE2

#echo diff $TMPFILE1 $TMPFILE2
diff $TMPFILE1 $TMPFILE2
exit $?


위 스크립트는 제가 짠 거고

아래는 http://bash.cyberciti.biz/academic/sed-remove-c-cpp-comments/ 여기서 퍼왔습니다.

#! /bin/sed -nf

  1. Remove C and C++ comments, by Brian Hiles (brian_hiles@rocketmail.com)
  1. Sped up (and bugfixed to some extent) by Paolo Bonzini (bonzini@gnu.org)
  2. Works its way through the line, copying to hold space the text up to the
  3. first special character (/, “, ‘). The original version went exactly a
  4. character at a time, hence the greater speed of this one. But the concept
  5. and especially the trick of building the line in hold space are entirely
  6. merit of Brian.

:loop

  1. This line is sufficient to remove C++ comments!

/^\/\// s,.*,,

/^$/{

x p n b loop

}

/^”/{

:double /^$/{ x p n /^”/b break b double } H x s,\n\(.[^\”]*\).*,\1, x s,.[^\”]*,, /^”/b break /^\\/{ H x s,\n\(.\).*,\1, x s/.// } b double

}

/^’/{

:single /^$/{ x p n /^’/b break b single } H x s,\n\(.[^\’]*\).*,\1, x s,.[^\’]*,, /^’/b break /^\\/{ H x s,\n\(.\).*,\1, x s/.// } b single

}

/^\/\*/{

s/.// :ccom s,.[*]*,, /^$/ n /^\*\//{ s/..// b loop } b ccom

}

:break

H

x

s,\n\(.[^”’/]*\).*,\1,

x

s/.[^”’/]*//

b loop

크리에이티브 커먼즈 라이센스
Creative Commons License

배치파일 for문에서 에서 폴더 안의 파일명 가져오기

Posted at 2014/04/09 08:20 // in Programming // by Daniel
setlocal enabledelayedexpansion
for /r %%I in (*) do (
  @REM echo %%~nxI
  set _CMDL=!_CMDL! %%~nxI
  )
endlocal&set CMDLINE=%_CMDL%
enabledelayedexpansion 을 써서 for문 안에서 변수가 갱신되도록 한다. (_CMDL) 이때는 %대신 !를 써서 표시.
%%~nxI - 파일의 이름과 확장자 (for /?로 확인 가능)

 %~I         - 따옴표(")를 제거하는 %I을 확장합니다.
 %~fI        - %I을 정규화된 경로 이름으로 확장합니다.
 %~dI        - %I을 드라이브 문자로만 확장합니다.
 %~pI        - %I을 경로로만 확장합니다.
 %~nI        - %I을 파일 이름으로만 확장합니다.
 %~xI        - %I을 파일 확장명으로만 확장합니다.
 %~sI        - 확장된 경로가 짧은 이름만 가지고 있습니다.
 %~aI        - %I이 파일의 파일 속성으로만 확장합니다.
 %~tI        - %I을 파일의 날짜/시간으로만 확장합니다.
 %~zI        - %I을 파일 크기로만 확장합니다.
 %~$PATH:I   - PATH 환경 변수 목록에 있는
                디렉터리를 찾고 %I을 처음으로 찾은
                정규화된 이름으로 확장합니다.
                환경 변수 이름이 정의되지 않았거나
                찾기에서 파일을 찾지 못하면
                이 구문에서 빈 문자열로
                확장합니다
위의 구문은 여러 가지 결과를 얻기 위해 결합될 수 있습니다.

   %~dpI       - %I을 드라이브 문자와 경로로만 확장합니다.
   %~nxI       - %I을 파일 이름과 확장명으로만 확장합니다.
   %~fsI       - %I 을 짧은 이름을 가진 전체 경로 이름으로만 확장합니다.
   %~dp$PATH:i - %I에 대한 PATH 환경 변수 목록에 있는
                  디렉터리를 찾고 처음 찾은 것의
                  드라이브 문자와 경로로 확장합니다.
   %~ftzaI     - %I을 출력줄과 같은 DIR로 확장합니다.

위의 예제에서 %I과 PATH는 다른 유효한 값으로 바뀔 수 있습니다.
%~ 구문은 유효한 FOR 변수 이름으로 종료됩니다.
%I와 같은 대문자 변수 이름을 선택하면 쉽게 읽을 수 있으며
대/소문자를 구분하지 않는 구문에서 혼동을 피할 수 있습니다.
아래 스크립트(함수)는 인자로 주어진 폴더로 부터 모든 파일명들을 가져다가 폴더명과 함께 붙여 커맨드라인을 만드는 스크립트입니다.
:SET_SUBFOLDER_FILES_CMDLINE
@REM get sub folder files

@echo off
setlocal enabledelayedexpansion
set _CMDL=
for %%f in (%*) do (
for /r %%I in (%%f\*.arxml) do (
  @REM echo %%~nxI
  set _CMDL=!_CMDL! %%f/%%~nxI
  )
)
endlocal&set CMDLINE=%_CMDL%
@REM echo %CMDLINE%

goto:eof
크리에이티브 커먼즈 라이센스
Creative Commons License

Converting EMF Resource to Platform Resource (IFile)

Posted at 2014/02/18 08:02 // in Programming // by Daniel

Converting EMF Resource to Platform Resource (IFile)
Simple one:

EObject eObject = ...;
Resource eResource = eObject.eResource();
URI eUri = eResource.getURI();
if (eUri.isPlatformResource()) {
String platformString = eUri.toPlatformString(true);
return ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
}
return null;

http://blog.eclipse-tips.com/2008/03/converting-emf-resource-to-platform.html

active project 얻기
http://wiki.eclipse.org/FAQ_How_do_I_access_the_active_project%3F

크리에이티브 커먼즈 라이센스
Creative Commons License

정규표현식을 이용 문자열 수정 - JAVA

Posted at 2013/06/17 10:02 // in Programming // by Daniel

strValidatedPath = strPath.replaceAll(”[^a-zA-Z0-9]”, “_”);

이와 같이 하면 알파벳과 숫자 이외의 값인 경우 _ 로 변경된 문자열을 얻을 수 있다. (파일 이름 규칙에 사용하려고 한 예제)
정규식에서 ^ 는 not을 의미, a~z, A~Z, 0~9 이외 라는 뜻이고 replaceAll은 이 정규식 형태를 읽어와서 변경한다.
정규식 테스트는 http://www.gskinner.com/RegExr/ 에서 볼 수 있다.

크리에이티브 커먼즈 라이센스
Creative Commons License

VIM에서 컬럼 너비 체크 및 수정

Posted at 2012/08/22 18:45 // in Programming // by Daniel
코드 짤 때 컬럼 너비가 80으로 정해져있는데 내 코드에 가끔 그보다 넓게 짜서 수정해야 할 때,
vim에서는 gqq 라는 명령어가 있습니다.
gqq를 누르면 해당 라인이 설정된 컬럼 너비에 맞게 변화됩니다.
http://stackoverflow.com/questions/3033 ··· -columns
컬럼 너비 설정은
set textwidth=80 으로 합니다.

그리고 컬럼 너비가 너무 긴 행을 표시하려면 .vimrc에 다음과 같이 추가하면 됩니다.
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/

이렇게 해놓으면 80 컬럼을 넘는 긴 행이 빨간 색으로 표시됩니다.
http://stackoverflow.com/questions/2354 ··· concerns

크리에이티브 커먼즈 라이센스
Creative Commons License

간단한 큐

Posted at 2012/03/23 17:25 // by Daniel

보호되어 있는 글 입니다.
내용을 보시려면 비밀번호를 입력하세요.