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

C5

[C : ls] C๋กœ ls ๊ตฌํ˜„ ์‹œ, -a ์˜ต์…˜ ์ฒ˜๋ฆฌ #getopt ์ด์ „ ํฌ์ŠคํŒ…์—์„œ getopt๋ฅผ ์•Œ์•„๋ดค๊ณ , ์ด๋ฒˆ์—” ls ๊ตฌํ˜„ ์‹œ -a ์˜ต์…˜์— ๋Œ€ํ•œ ์ธ์ž์ฒ˜๋ฆฌ๋ฅผ ํ•ด๋ณด๋ ค๊ณ  ํ•จ ๋‹ค๋ฅธ ์˜ต์…˜๋“ค๋„ ๋‚˜์ค‘์—.. ์–ธ์  ๊ฐ„.. ํ•ด๋ด์•ผ์ง€... argc๊ฐ€ 1๊ฐœ์ธ์ง€ (ls ๋งŒ ์ž…๋ ฅ๋œ ๊ฒฝ์šฐ) argc๊ฐ€ 1๊ฐœ๊ฐ€ ์•„๋‹Œ์ง€ (ls์™€ ์˜ต์…˜์ด ํ•จ๊ป˜ ์ž…๋ ฅ ๋œ ๊ฒฝ์šฐ) ๋ฅผ ๋‚˜๋ˆ ์„œ ์ž‘์„ฑ argc๊ฐ€ 1๊ฐœ์ธ๊ฒฝ์šฐ .์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ˆจ๊น€ํŒŒ์ผ์„ ์ œ์™ธํ•œ ๋‚˜๋จธ์ง€ ํŒŒ์ผ๋“ค์„ ์ถœ๋ ฅํ•˜๊ณ  1๊ฐœ๊ฐ€ ์•„๋‹Œ๊ฒฝ์šฐ์—๋Š” getopt()๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜ต์…˜์— ๋งž๊ฒŒ ์ถœ๋ ฅํ•˜๋„๋ก ๊ตฌํ˜„ ํ˜„์žฌ ์˜ต์…˜์€ a๋งŒ ์‚ฌ์šฉ ! #include #include #include #include int main(int argc, char* argv[]) { struct dirent *dir; int c; DIR *dp = opendir("."); if (dp == NULL) { r.. 2023. 12. 18.
[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.
๋ฐ˜์‘ํ˜•