Previous Month   February 2012
Sun
Mon
Tue
Wed
Thu
Fri
Sat
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
 
 
Recent Entries
Recent Comments

XHTML Validator RSS Syndication Get Firefox
no newline at end of file °æ°í
by ±è¿µ½Ä(bitwise) on 2007-07-08 20:08:57

ÇöÀç ÁøÇàÇϰí ÀÖ´Â ÇÁ·ÎÁ§Æ®¿¡¼­ ÇÑâ ±¸Çö ´Ü°è¿¡ ÀÖÀ» ¶§, Áß°£ Áß°£ ÀÌ»óÇÑ Çö»óÀÌ ¸ñ°ÝµÇ¾ú´Ù. void ¸®ÅÏÀÌ ¾Æ´Ñ ÇÔ¼ö¿¡¼­ ¸®ÅÏ ±¸¹®À» »ý·«Çصµ gcc ÄÄÆÄÀÏ·¯°¡ ¾Æ¹«·± ºÒÆò ºÒ¸¸À» ÇÏÁö ¾Ê´Â °ÍÀÌ´Ù. (Áö±ÝÀº ±â¾ïÀÌ ³ªÁö ¾ÊÁö¸¸ ÄÄÆÄÀÏ·¯·Î½áÀÇ ÀÚÁúÀÌ Àǽɽº·¯¿î Çö»óµéÀÌ ¹ß°ßµÇ°ï Çß´Ù.) ³Ê¹« ¹Ù»Û ³ª¸ÓÁö ±×³É Àذí ÀÖ´Ù°¡ ¾î´À³¯ »ìÆìº¸´Ï Çã°Æ! ¾îó±¸´Ï ¾ø°Ôµµ ¸ðµç °æ°í ¸Þ½ÃÁö°¡ ¸·Çô ÀÖ¾ú´Ù. ±×·¡¼­ °æ°í¸¦ ´Ù½Ã ÄѰí Àçºôµå. À¸¾Æ¾Æ¾Æ, À̹ø¿£ ¼ö¸¹Àº °æ°íµé ¼Ó¿¡µµ µµÀúÈ÷ ºôµå¸¦ ³¡³¾ ¼ö ¾ø´Â Áö°æÀ̾ú´Ù. ±× Áß ¹Ýº¹µÇ´Â °æ°í Áß¿¡ Çϳª°¡ ¹Ù·Î "no newline at end of file". ¼Ò½º ¸¶Áö¸· ¶óÀο¡ newline ¹®ÀÚ°¡ ¾øÀ» °æ¿ì ¹ß»ýÇÏ´Â °æ°í´Ù.

¾Æ¹«¸® ã¾ÆºÁµµ Àú °æ°í¸¸ ¼±ÅÃÀûÀ¸·Î ²ø ¼öµµ ¾ø°í (ÀϺΠÆÐÄ¡¸¦ ¸¸µé¾î »ç¿ëÇÏ´Â °æ¿ì°¡ ÀÖ±ä ÀÖÁö¸¸...) µµ´ëü newline ¹®ÀÚ°¡ ¾ø´Â °ÍÀÌ ¿Ö ¹®Á¦°¡ µÉ±î ÇÏ´Â ÀDZ¸½ÉÀÌ µé¾ú´Ù. Á» ´õ ã¾Æº» °á°ú, C Ç¥ÁØ¿¡ ¼Ò½º ÆÄÀÏ ¸¶Áö¸·¿¡ newline ¹®ÀÚ°¡ ÀÖ¾î¾ß ÇÑ´Ù´Â ³»¿ëÀÌ µé¾î ÀÖ´Ù°í ÇÑ´Ù. ´õºÒ¾î newline ¹®ÀÚ°¡ µé¾î ÀÖÁö ¾ÊÀ» °æ¿ìÀÇ ºÎÀÛ¿ëµµ ã¾Æ º¼ ¼ö ÀÖ¾ú´Ù.

ÇÏ´Â ¼ö ¾øÀÌ newlineÀ» Ãß°¡Çϱâ·Î ¸¶À½ ¸Ô°í ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÇß´Ù. ÆÄÀ̽ã ÃÊÂ¥¶ó Dive Into Python ¿¹Á¦ ¼Ò½º¸¦ Âü°í »ï¾Æ ´õµë ´õµë ÀÛ¼º.

#!/usr/bin/env python 

import os
import sys

def getFileList(directory, extList):
    fileList = [os.path.normcase(f)
		for f in os.listdir(directory)]
    fileList = [os.path.join(directory, f) 
		for f in fileList 
		if os.path.splitext(f)[1] in extList]
    return fileList


def getDirectoryList (directory):
    dirList = [f for f in os.listdir(directory)
	       if os.path.isdir(os.path.join(directory, f)) and f[0] != '.' ]
    return dirList

      
def appendNewLine(filePath):
    try:
	f = open(filePath, "at")
	try:
	    f.write("\n")
	finally:
	    f.close()
    except IOError:
	pass


def readLastByte(filePath):
    lastChar = ''
    try:
	f = open(filePath, "rt")
	try:
	    f.seek(-1, 2)
	    lastChar = f.read(1)
	finally:
	    f.close()
    except IOError:
	pass
    return lastChar


def scanSourceTree(entryPath):
    print "Path :", entryPath

    fileList = getFileList(entryPath, [".h", ".c", ".cpp", ".s", ".pgm"])
    for filePath in fileList:
	sys.stdout.write(" | " + filePath)
	lastChar = readLastByte(filePath)
	if lastChar != '\n':
	    appendNewLine(filePath)
	    sys.stdout.write(" : Newline appended")
	sys.stdout.write("\n");

    "Look into sub-directories"
    dirList = getDirectoryList(entryPath)
    for dirPath in dirList:
	scanSourceTree(os.path.join(entryPath, dirPath))


if __name__ == "__main__":
    print 'Let\'s get rid of GCC warning "No newline at end of file"'

    entryPath = "."
    if len(sys.argv) == 2:
        entryPath = sys.argv[1]
    scanSourceTree(entryPath)

    print "Finished"

À̰ɷΠnewline °æ°í¸¦ ¾ø¾Ù ¼ö´Â ÀÖ¾ú´Âµ¥, °á·Ð¸¸ ¸»ÇÏÀÚ¸é °æ°í ÄÑ°í ²ô°íÀÇ ¾öû³­ ºôµå ¼Óµµ Â÷ÀÌ·Î ÀÎÇØ °á±¹¿£ °æ°í¸¦ ²ø ¼ö ¹Û¿¡ ¾ø¾ú´Ù. (À©µµ ȯ°æ¿¡¼­ ÀÛ¼ºµÈ ¼Ò½º¸¦ ¸®´ª½º·Î °¡Á®¿Â °Å¶ó ´Ù¸¥ °æ°íµµ ¸¹¾Ò°í, Áö¼ÓÀûÀ¸·Î À©µµ¿¡¼­ ¸®´ª½º·ÎÀÇ ¾÷µ¥ÀÌÆ®°¡ ÀÌ·ïÁö±â ¶§¹®¿¡ Çѹø °æ°í°¡ ¹ß»ýÇÏÁö ¾Êµµ·Ï ¼öÁ¤ÇÑ´Ù°í ÇØ¼­ ÇØ°áµÉ¸¸ÇÑ »óȲÀÌ ¾Æ´Ï¾ú´Ù.) ¾Æ¸¶ make ¿¡¼­ Ãâ·ÂµÇ´Â ¸Þ½ÃÁö¸¦ ¸·À¸¸é Â÷À̰¡ Á» ÁÙ¾îµéÁö ¾ÊÀ»±î ½ÍÁö¸¸ ¾î¶µç Áö±ÝÀº ÇÁ·ÎÁ§Æ®ÀÇ ¸¶¹«¸® ´Ü°è¶ó´Â°Å-.

comments(0)