Skip to content

Instantly share code, notes, and snippets.

@nori26
Last active September 2, 2021 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nori26/4a217659d4886603244d65387600dd62 to your computer and use it in GitHub Desktop.
Save nori26/4a217659d4886603244d65387600dd62 to your computer and use it in GitHub Desktop.
add_42header
import sys
import os
from datetime import datetime
def main():
name = "unko"
mail = f"{name}@student.42tokyo.jp"
files = sys.argv[1:]
start = '/* ************************************************************************** */'
for file in files:
s = None
now = time(datetime.now())
filename = os.path.basename(file)
with open(file, 'r') as f:
s = f.read()
if s[:len(start)] == start:
continue
with open(file, 'w') as f:
f.write(f'''\
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* {filename.ljust(51) }:+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: {adjust(f"{name} <{mail}>", 43) }+#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: {now} by {adjust(name, 17) } #+# #+# */
/* Updated: {now} by {adjust(name, 17) }### ########.fr */
/* */
/* ************************************************************************** */
''' + s)
def time(time):
return time.strftime("%Y/%m/%d %H:%M:%S")
def adjust(str, size):
return str.ljust(size)[:size]
if __name__ == "__main__":
main()
find `pwd` -type f -name "*.c" -o -type f -name "*.h" | xargs python3 ~/42header.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment