๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

์ „์ฒด ๊ธ€35

[C : ls] ls ์˜ต์…˜ ์ธ์ž์ฒ˜๋ฆฌ #getopts /* OPTS์— ์ฃผ์–ด์ง„ ์˜ต์…˜์— ๋Œ€ํ•ด ARGV(ํ”„๋กœ๊ทธ๋žจ ์ด๋ฆ„์„ ๋บ€ ARGC)์˜ ์ธ์ˆ˜๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜์˜ ์ •์˜์™€ ํ”„๋กœํ† ํƒ€์ž…์„ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค. ๋ฐฉ๊ธˆ ์ฝ์€ OPTS์—์„œ ์˜ต์…˜ ๋ฌธ์ž๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋” ์ด์ƒ ์˜ต์…˜์ด ์—†์œผ๋ฉด -1์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ธ์‹ํ•  ์ˆ˜ ์—†๋Š” ์˜ต์…˜ ๋˜๋Š” ์ธ์ˆ˜๊ฐ€ ๋ˆ„๋ฝ๋œ ์˜ต์…˜์˜ ๊ฒฝ์šฐ ์˜ต์…˜ ๋ฌธ์ž๋กœ 'optopt'๊ฐ€ ์„ค์ •๋˜๊ณ  '?'๊ฐ€ ๋ฐ˜ํ™˜๋ฉ๋‹ˆ๋‹ค. OPTS ๋ฌธ์ž์—ด์€ ์ธ์‹๋˜๋Š” ์˜ต์…˜ ๋ฌธ์ž์˜ ๋ชฉ๋ก์ด๋ฉฐ, ์„ ํƒ์ ์œผ๋กœ ์ฝœ๋ก ์ด ๋’ค์— ์™€์„œ ํ•ด๋‹น ๋ฌธ์ž๊ฐ€ ์ธ์ˆ˜๋ฅผ ๋ฐ›๋„๋ก ์ง€์ •ํ•˜์—ฌ 'optarg'์— ๋ฐฐ์น˜ํ•ฉ๋‹ˆ๋‹ค. OPTS์˜ ๋ฌธ์ž ๋’ค์— ์ฝœ๋ก  ๋‘ ๊ฐœ๊ฐ€ ์˜ค๋Š” ๊ฒฝ์šฐ ํ•ด๋‹น ์ธ์ˆ˜๋Š” ์„ ํƒ ์‚ฌํ•ญ์ž…๋‹ˆ๋‹ค. ์ด ๋™์ž‘์€ GNU 'getopt'์—๋งŒ ํ•ด๋‹น๋ฉ๋‹ˆ๋‹ค. ์ธ์ž '--'์€ ์ธ์ž ๊ฒ€์ƒ‰์„ ์กฐ๊ธฐ์— ์ข…๋ฃŒํ•˜์—ฌ ๋” ์ด์ƒ ์˜ต์…˜์ด ์—†์Œ์„ 'getopt'์— ๋ช…์‹œ์ ์œผ๋กœ ์•Œ๋ฆฝ๋‹ˆ.. 2023. 12. 17.
[C : ls] C์–ธ์–ด๋กœ ls ๊ตฌํ˜„ํ•˜๊ธฐ #dirent ls๋ฅผ ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ ํ•  dirent์— ๋Œ€ํ•ด ์•Œ์•„๋ด„ directory ๋ฅผ ์—ด๊ธฐ ์œ„ํ•ด opendir() ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๋ฐ, ์–˜๋Š” ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฒฝ๋กœ๋ฅผ ๋ฐ›๊ณ , ๋””๋ ‰ํ„ฐ๋ฆฌ๋ฅผ ์—ด ์ˆ˜ ์žˆ์œผ๋ฉด DIR *, ์—ด ์ˆ˜ ์—†์œผ๋ฉด NULL ๋ฐ˜ํ™˜ /* Open a directory stream on NAME. Return a DIR stream on the directory, or NULL if it could not be opened. This function is a possible cancellation point and therefore not marked with __THROW. */ extern DIR *opendir (const char *__name) __nonnull ((1)); DIR์€ ๋ญ์ง€ ? /* This i.. 2023. 12. 16.
[C : ctags] ctags ์„ค์น˜ #universal-ctags ctags ์•„๋‹ˆ๊ณ  universal-ctags ์˜ค๋žœ๋งŒ์— C์–ธ์–ด๋ฅผ ๋‹ค์‹œ๋ณด๋ฉด์„œ.. ctags๋ฅผ ์“ฐ๋ ค๊ณ  ํ–ˆ๋”๋‹ˆ ์„ค์น˜๊ฐ€ ์•ˆ๋˜์–ด ์žˆ์–ด์„œ ์„ค์น˜ํ•˜๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ.. ๐Ÿ˜ฅ ์™œ๋•Œ๋ฌธ์— ํŒจํ‚ค์ง€๊ฐ€ ์—…์จ !!! ๐Ÿ˜ก E: Package 'ctags' has no installation candidate mimi@mimi:~/Mimi/lang/c$ sudo apt-get install -y ctags Reading package lists... Done Building dependency tree... Done Reading state information... Done Package ctags is a virtual package provided by: exuberant-ctags 1:5.9~svn20110310-16ubuntu0.2.. 2023. 12. 16.
[C : echo] ํ„ฐ๋ฏธ๋„๋กœ ์ž…๋ ฅ๋ฐ›์€ ๊ฐ’ ์ถœ๋ ฅํ•˜๊ธฐ #argc #argv echo๋ฅผ c์–ธ์–ด๋กœ ๊ตฌํ˜„ํ•ด๋ณด๊ณ ์ž ํ•จ ! mimi@mimi:~/Mimi/lang/c$ echo aaa bbb ccc aaa bbb ccc ๋ช…๋ น๊ณผ ํ•จ๊ป˜ ์ž…๋ ฅ๋ฐ›์€ ์ธ์ž๋“ค์„ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅํ•ด์ฃผ๊ธฐ ! ์ž…๋ ฅ๋ฐ›์€ ์ธ์ž์˜ ๊ธธ์ด๋Š” ์–ด๋–ป๊ฒŒ ์•Œ์ง€ ? int argc ์ž…๋ ฅ๋ฐ›์€ ์ธ์ž์˜ ๋‚ด์šฉ์€ ์–ด๋–ป๊ฒŒ ์•Œ์ง€ ? char* argv[] (๋˜๋Š” char** argv) ๊ทธ๋Ÿผ ์ด๊ฑธ ์–ด๋–ป๊ฒŒ ์“ฐ์ง€ ? main ํ•จ์ˆ˜์—์„œ int argc์™€ char* argv[] ๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋„๋ก ์ž‘์„ฑํ•˜๊ธฐ ! #include int main(int argc, char* argv[]) { // ์ฝ”๋“œ์ž‘์„ฑ return 0; } argc๋Š” ๊ณต๋ฐฑ์„ ๊ธฐ์ค€์œผ๋กœ ํ„ฐ๋ฏธ๋„์—์„œ ๋ช…๋ น์œผ๋กœ ์ž…๋ ฅ๋œ ๊ฐœ์ˆ˜๋ฅผ ์„ธ์–ด์ฃผ๊ณ  argv๋Š” ์ž…๋ ฅ๋œ ๋‚ด์šฉ์„ ๋ฌธ์ž์—ด๋กœ ์ €์žฅํ•ด์„œ ๊ฐ€์ง€๊ฒŒ ๋จ ! argc๋Š” ๊ฐœ์ˆ˜๋ฅผ .. 2023. 12. 16.
๋ฐ˜์‘ํ˜•