Initial commit
This commit is contained in:
381
script/c-syntax-highlight.lua
Normal file
381
script/c-syntax-highlight.lua
Normal file
@@ -0,0 +1,381 @@
|
||||
local tokenMap = {
|
||||
"identifier",
|
||||
"newline",
|
||||
"whitespace",
|
||||
"symbol",
|
||||
"type",
|
||||
"control",
|
||||
"comment",
|
||||
"number",
|
||||
"string",
|
||||
"char",
|
||||
"specialValue"
|
||||
}
|
||||
|
||||
local colorMap = {
|
||||
["identifier"] = "Gray",
|
||||
["symbol"] = "Gray",
|
||||
["type"] = "Yellow",
|
||||
["control"] = "Yellow",
|
||||
["comment"] = "SkyBlue",
|
||||
["number"] = "Dandelion",
|
||||
["string"] = "Magenta",
|
||||
["char"] = "WildStrawberry",
|
||||
["specialValue"] = ""
|
||||
}
|
||||
|
||||
function indexOf(l, v)
|
||||
for j, k in ipairs(l) do
|
||||
if k == v then
|
||||
return j
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function frequency(s)
|
||||
local res = {}
|
||||
for i = 1, #s do
|
||||
local curChar = string.sub(s, i, i)
|
||||
if res[curChar] == nil then
|
||||
res[curChar] = 1
|
||||
else
|
||||
local n = res[curChar]
|
||||
res[curChar] = n + 1
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function getc(s, i)
|
||||
return string.sub(s, i, i)
|
||||
end
|
||||
|
||||
function wrapInColor(s, colorName)
|
||||
return "{$color{" .. colorName .. "}" .. s .. "}"
|
||||
end
|
||||
|
||||
Token = {}
|
||||
|
||||
function Token:new(t, c)
|
||||
local res = {
|
||||
tokType = t,
|
||||
tokContent = c
|
||||
}
|
||||
self.__index = self
|
||||
return setmetatable(res, self)
|
||||
end
|
||||
|
||||
Lexer = {}
|
||||
|
||||
function Lexer:new(src)
|
||||
local res = {
|
||||
source = src,
|
||||
currStrPos = 1,
|
||||
currTokPos = 1,
|
||||
tokens = {},
|
||||
buffer = "",
|
||||
isStrAtEnd = false
|
||||
}
|
||||
self.__index = self
|
||||
return setmetatable(res, self)
|
||||
end
|
||||
|
||||
function Lexer:addToken(tokType, tokContent)
|
||||
table.insert(self.tokens, Token:new(indexOf(tokenMap, tokType), tokContent))
|
||||
end
|
||||
|
||||
function Lexer:printTokens()
|
||||
for i,j in pairs(self.tokens) do
|
||||
print("Token Type: ", tokenMap[j.tokType], "\nToken Content: ", j.tokContent)
|
||||
end
|
||||
end
|
||||
|
||||
function isKeywordType(s)
|
||||
local cTypes = {"int", "long", "short", "char", "bool", "void", "signed", "unsigned", "float", "double", "size_t", "static", "extern"}
|
||||
local res = false;
|
||||
|
||||
for i = 1, #cTypes do
|
||||
res = s == cTypes[i]
|
||||
if res == true then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
function isKeywordControl(s)
|
||||
local controlKeywords = {"do", "while", "for", "switch", "case", "default", "if", "else", "break", "return"}
|
||||
local res = false;
|
||||
|
||||
for i = 1, #controlKeywords do
|
||||
res = s == controlKeywords[i]
|
||||
if res == true then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
function isSymbol(s)
|
||||
local symbols = ""
|
||||
end
|
||||
|
||||
function isDecimalOrOctal(s)
|
||||
if s == "" then
|
||||
return false
|
||||
end
|
||||
local f = frequency(s)
|
||||
local counter = 0
|
||||
local charList = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
||||
for i = 1, #charList do
|
||||
counter = counter + (f[charList[i]] and f[charList[i]] or 0)
|
||||
end
|
||||
|
||||
local charNumDiff = #s - counter
|
||||
if charNumDiff == 3 then
|
||||
local subs = string.sub(s, #s-2, #s)
|
||||
local fsubs = frequency(subs)
|
||||
local unsignedCount = (fsubs["u"] and fsubs["u"] or 0) + (fsubs["U"] and fsubs["U"] or 0)
|
||||
local longCount = (fsubs["l"] and fsubs["l"] or 0) + (fsubs["L"] and fsubs["L"] or 0)
|
||||
if unsignedCount > 1 then
|
||||
return false
|
||||
end
|
||||
if longCount ~= 2 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
elseif charNumDiff == 2 then
|
||||
local subs = string.sub(s, #s-1, #s)
|
||||
local fsubs = frequency(subs)
|
||||
local unsignedCount = (fsubs["u"] and fsubs["u"] or 0) + (fsubs["U"] and fsubs["U"] or 0)
|
||||
local longCount = (fsubs["l"] and fsubs["l"] or 0) + (fsubs["L"] and fsubs["L"] or 0)
|
||||
if unsignedCount == 1 and longCount == 1 then
|
||||
return true
|
||||
elseif longCount == 2 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
elseif charNumDiff == 1 then
|
||||
local subs = getc(s, #s)
|
||||
return subs == "u" or subs == "U" or subs == "l" or subs == "L"
|
||||
else
|
||||
return counter == #s
|
||||
end
|
||||
end
|
||||
|
||||
function isHexadecimal(s)
|
||||
local f = frequency(s)
|
||||
local counter = 0
|
||||
local charList = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'A', 'B', 'C', 'D', 'E', 'F'}
|
||||
|
||||
if f["x"] == nil and f["X"] == nil and string.sub(s,1,1) ~= "0" then
|
||||
return false
|
||||
end
|
||||
|
||||
for i = 1, #charList do
|
||||
counter = counter + (f[charList[i]] and f[charList[i]] or 0)
|
||||
end
|
||||
|
||||
local charNumDiff = #s - counter
|
||||
if charNumDiff == 3 then
|
||||
local subs = string.sub(s, #s-2, #s)
|
||||
local fsubs = frequency(subs)
|
||||
local unsignedCount = (fsubs["u"] and fsubs["u"] or 0) + (fsubs["U"] and fsubs["U"] or 0)
|
||||
local longCount = (fsubs["l"] and fsubs["l"] or 0) + (fsubs["L"] and fsubs["L"] or 0)
|
||||
if unsignedCount > 1 then
|
||||
return false
|
||||
end
|
||||
if longCount ~= 2 then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
elseif charNumDiff == 2 then
|
||||
local subs = string.sub(s, #s-1, #s)
|
||||
local fsubs = frequency(subs)
|
||||
local unsignedCount = (fsubs["u"] and fsubs["u"] or 0) + (fsubs["U"] and fsubs["U"] or 0)
|
||||
local longCount = (fsubs["l"] and fsubs["l"] or 0) + (fsubs["L"] and fsubs["L"] or 0)
|
||||
if unsignedCount == 1 and longCount == 1 then
|
||||
return true
|
||||
elseif longCount == 2 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
elseif charNumDiff == 1 then
|
||||
local subs = getc(s, #s)
|
||||
return subs == "u" or subs == "U" or subs == "l" or subs == "L"
|
||||
else
|
||||
return counter == #s
|
||||
end
|
||||
end
|
||||
|
||||
function isNumber(s)
|
||||
return isDecimalOrOctal(s) or isHexadecimal(s)
|
||||
end
|
||||
|
||||
function isSymbol(s)
|
||||
local symList = "!%^&*()-+=/?,<>{}[];:"
|
||||
for i = 1, #symList do
|
||||
if s == getc(symList, i) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function isNewLine(s)
|
||||
return s == "\n"
|
||||
end
|
||||
|
||||
function isWhitespace(s)
|
||||
return s == " "
|
||||
end
|
||||
|
||||
function isDoubleQuote(s)
|
||||
return s == "\""
|
||||
end
|
||||
|
||||
function isSingleQuote(s)
|
||||
return s == "\'"
|
||||
end
|
||||
|
||||
function doesWordEnd(s)
|
||||
return (isWhitespace(s) or isSymbol(s) or (s == "") or (s == "\n"))
|
||||
end
|
||||
|
||||
function Lexer:readString()
|
||||
self.buffer = self.buffer .. "\""
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
repeat
|
||||
local curr = getc(self.source, self.currStrPos)
|
||||
self.buffer = self.buffer .. curr
|
||||
if curr == "\"" then
|
||||
break
|
||||
end
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
until false
|
||||
|
||||
self:addToken("string", self.buffer)
|
||||
self.buffer = ""
|
||||
end
|
||||
|
||||
function Lexer:readChar()
|
||||
self.buffer = self.buffer .. "\'"
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
local character = getc(self.source, self.currStrPos)
|
||||
self.buffer = self.buffer .. character
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
self.buffer = self.buffer .. "\'"
|
||||
self:addToken("char", self.buffer)
|
||||
self.buffer = ""
|
||||
end
|
||||
|
||||
function Lexer:readComment()
|
||||
self.buffer = self.buffer .. "//"
|
||||
self.currStrPos = self.currStrPos + 2
|
||||
repeat
|
||||
local curr = getc(self.source, self.currStrPos)
|
||||
if isNewLine(curr) or curr == "" then
|
||||
break
|
||||
end
|
||||
self.buffer = self.buffer .. curr
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
until false
|
||||
|
||||
self:addToken("comment", self.buffer)
|
||||
|
||||
if getc(self.source, self.currStrPos) == "\n" then
|
||||
self:addToken("newline", "\n")
|
||||
end
|
||||
|
||||
self.buffer = ""
|
||||
end
|
||||
|
||||
|
||||
function Lexer:read()
|
||||
for i = 1, #self.source do
|
||||
local curr = getc(self.source,self.currStrPos)
|
||||
local nextChar = getc(self.source,self.currStrPos+1)
|
||||
if isWhitespace(curr) then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:addToken("whitespace", " ")
|
||||
elseif isDoubleQuote(curr) then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:readString()
|
||||
elseif isSingleQuote(curr) then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:readChar()
|
||||
elseif curr == "/" and nextChar == "/" then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:readComment()
|
||||
elseif isSymbol(curr) then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:addToken("symbol", curr)
|
||||
elseif isNewLine(curr) then
|
||||
if self.buffer ~= "" then
|
||||
self:addToken("identifier", self.buffer)
|
||||
end
|
||||
self.buffer = ""
|
||||
self:addToken("newline", curr)
|
||||
else
|
||||
self.buffer = self.buffer .. curr
|
||||
if isNumber(self.buffer) and doesWordEnd(nextChar) then
|
||||
self:addToken("number", self.buffer)
|
||||
self.buffer = ""
|
||||
elseif isKeywordType(self.buffer) then
|
||||
self:addToken("type", self.buffer)
|
||||
self.buffer = ""
|
||||
elseif isKeywordControl(self.buffer) then
|
||||
self:addToken("control", self.buffer)
|
||||
self.buffer = ""
|
||||
end
|
||||
end
|
||||
self.currStrPos = self.currStrPos + 1
|
||||
end
|
||||
end
|
||||
|
||||
function Lexer:highlight()
|
||||
local res = ""
|
||||
for i = 1, #self.tokens do
|
||||
local tokType = tokenMap[self.tokens[i].tokType]
|
||||
local tokContent = self.tokens[i].tokContent
|
||||
local hcolor = colorMap[tokType] and colorMap[tokType] or nil
|
||||
if hcolor ~= nil then
|
||||
res = res .. wrapInColor(tokContent, hcolor)
|
||||
else
|
||||
res = res .. tokContent
|
||||
end
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function exec(src)
|
||||
local lex = Lexer:new(src)
|
||||
local res = ""
|
||||
lex:read()
|
||||
res = lex:highlight()
|
||||
return res
|
||||
end
|
||||
|
||||
return exec
|
||||
149
script/generate-main.lua
Normal file
149
script/generate-main.lua
Normal file
@@ -0,0 +1,149 @@
|
||||
local lyaml = require "lyaml"
|
||||
|
||||
local config_file = io.open("document.yaml", 'r')
|
||||
local yml_str = config_file:read('a')
|
||||
local config = lyaml.load(yml_str)
|
||||
|
||||
coverpage = '\\coverpage'
|
||||
titleheading = '\\titleheading'
|
||||
tableofcontents = '\\tableofcontents'
|
||||
compiledtime = '\\compiledTime'
|
||||
printbib = '\\printbibliography[heading=bibintoc,title={参考文献}]'
|
||||
newpg = '\\newpage'
|
||||
romannumbering = '\\pagenumbering{roman}'
|
||||
arabicnumbering = '\\pagenumbering{arabic}'
|
||||
|
||||
function get_doc_class(cfg)
|
||||
return "\\documentclass{class/" .. cfg.doc_class .. "}"
|
||||
end
|
||||
|
||||
function get_title(cfg)
|
||||
return "\\reporttitle{" .. cfg.title .. "}"
|
||||
end
|
||||
|
||||
function get_author(cfg)
|
||||
return "\\reportauthor{" .. cfg.author.name .. "}"
|
||||
end
|
||||
|
||||
function get_stu_id(cfg)
|
||||
return "\\studentid{" .. cfg.author.student_id .. "}"
|
||||
end
|
||||
|
||||
function get_stu_seating_num(cfg)
|
||||
return "\\seatingnum{" .. cfg.author.seating_number .. "}"
|
||||
end
|
||||
|
||||
function get_school_name(cfg)
|
||||
return "\\schoolname{" .. cfg.school_name .. "}"
|
||||
end
|
||||
|
||||
function get_dep(cfg)
|
||||
return "\\department{" .. cfg.department .. "}"
|
||||
end
|
||||
|
||||
function get_subject(cfg)
|
||||
return "\\subject{" .. cfg.subject .. "}"
|
||||
end
|
||||
|
||||
function get_professor(cfg)
|
||||
return "\\professor{" .. cfg.professor .. "}"
|
||||
end
|
||||
|
||||
function get_additional_packages(cfg)
|
||||
local res = ""
|
||||
for i = 1, #cfg.packages do
|
||||
local options = ""
|
||||
if cfg.packages[i].options ~= "" then
|
||||
options = "[" .. cfg.packages[i].options .. "]"
|
||||
end
|
||||
res = res .. "\\usepackage" .. options .. "{" .. cfg.packages[i].name .. "}\n"
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
function format_date(cfg)
|
||||
return "\\reportdate{" .. cfg.date.year .. "}{" .. cfg.date.month .. "}{" .. cfg.date.day .. "}"
|
||||
end
|
||||
|
||||
function format_turnin_date(cfg)
|
||||
return "\\turnindate{" .. cfg.turnin.year .. "}{" .. cfg.turnin.month .. "}{" .. cfg.turnin.day .. "}"
|
||||
end
|
||||
|
||||
function preamble(cfg)
|
||||
local doc_class = get_doc_class(cfg) .. "\n\n"
|
||||
local title = get_title(cfg) .. "\n"
|
||||
local name = get_author(cfg) .. "\n"
|
||||
local stu_id = get_stu_id(cfg) .. "\n"
|
||||
local seating = get_stu_seating_num(cfg) .. "\n"
|
||||
local date = format_date(cfg) .. "\n"
|
||||
local turnin = format_turnin_date(cfg) .. "\n"
|
||||
local school = get_school_name(cfg) .. "\n"
|
||||
local dep = get_dep(cfg) .. "\n"
|
||||
local subject = get_subject(cfg) .. "\n"
|
||||
local professor = get_professor(cfg) .. "\n"
|
||||
local additional_packages = ""
|
||||
local pgnum = ""
|
||||
if cfg.paper_config.include_cover_page == true and cfg.doc_class ~= "nitonepage" then
|
||||
pgnum = "\n" .. romannumbering .. "\n"
|
||||
end
|
||||
if cfg.paper_config.use_additional_packages == true then
|
||||
additional_packages = "\n" .. get_additional_packages(cfg)
|
||||
end
|
||||
return doc_class .. title .. name .. stu_id .. seating .. date .. turnin .. school .. dep .. subject .. professor .. additional_packages .. pgnum .. "\n"
|
||||
end
|
||||
|
||||
function report_content(cfg)
|
||||
local res = "\\begin{document}\n"
|
||||
if cfg.paper_config.include_cover_page == true then
|
||||
res = res .. " " .. coverpage .. "\n\n"
|
||||
end
|
||||
if cfg.paper_config.include_table_of_contents == true then
|
||||
res = res .. " " .. tableofcontents .. "\n " .. newpg .. "\n"
|
||||
end
|
||||
res = res .. " " .. arabicnumbering .. "\n\n"
|
||||
for i = 1, #cfg.sections do
|
||||
res = res .. " " .. "\\input{" .. cfg.sections[i].path .. "}\n"
|
||||
if cfg.sections[i].newpg == true then
|
||||
res = res .. " " .. newpg .. "\n\n"
|
||||
else
|
||||
res = res .. "\n"
|
||||
end
|
||||
end
|
||||
if cfg.paper_config.use_bib == true then
|
||||
res = res .. " " .. printbib .. "\n\n"
|
||||
end
|
||||
if cfg.paper_config.show_compiled_time == true then
|
||||
res = res .. " " .. compiledtime .. "\n"
|
||||
end
|
||||
res = res .. "\\end{document}"
|
||||
return res
|
||||
end
|
||||
|
||||
function onepage_content(cfg)
|
||||
local res = "\\begin{document}\n"
|
||||
res = res .. " " .. titleheading .. "\n\n"
|
||||
res = res .. " Content Here\n\n"
|
||||
res = res .. "\\end{document}"
|
||||
return res
|
||||
end
|
||||
|
||||
function generate(cfg)
|
||||
local pre = preamble(cfg)
|
||||
local doc = ""
|
||||
local file_content = ""
|
||||
if cfg.doc_class == "nitreport" then
|
||||
doc = report_content(cfg)
|
||||
elseif cfg.doc_class == "nitonepage" then
|
||||
doc = onepage_content(cfg)
|
||||
else
|
||||
print("Error: Invalid document class option")
|
||||
os.exit(1)
|
||||
end
|
||||
file_content = pre .. doc
|
||||
return file_content
|
||||
end
|
||||
|
||||
print(generate(config))
|
||||
|
||||
config_file:close()
|
||||
17
script/generate-program-info.bash
Normal file
17
script/generate-program-info.bash
Normal file
@@ -0,0 +1,17 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
FILE=`cat <<EOF
|
||||
{
|
||||
"language": "",
|
||||
"name": "",
|
||||
"description": "",
|
||||
"output": {
|
||||
"type": "screenshot | text",
|
||||
"content": ""
|
||||
},
|
||||
"note": ""
|
||||
}
|
||||
EOF
|
||||
`
|
||||
|
||||
echo "$FILE"
|
||||
30
script/get-exec-env-gcc.bash
Normal file
30
script/get-exec-env-gcc.bash
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function getGCCVersion () {
|
||||
local res=""
|
||||
mkfifo gcc_version
|
||||
gcc -v 2> gcc_version &
|
||||
res="$(tail -n 1 gcc_version)"
|
||||
unlink gcc_version
|
||||
|
||||
echo $res
|
||||
}
|
||||
|
||||
function getOS () {
|
||||
cat /etc/os-release | grep --color=none "^PRETTY" | sed -s 's/PRETTY_NAME=//' | sed -s 's/\"//g'
|
||||
}
|
||||
|
||||
function getArch () {
|
||||
echo $(uname -m | sed -s 's/_/\\_/g')
|
||||
}
|
||||
|
||||
res="\\subsection{実行環境}\n\n"
|
||||
res+="この課題のプログラムは以下の環境で動作することが確認されている:\n\n"
|
||||
res+="\\\\begin{itemize}\n"
|
||||
res+=" \\item OS: $(getOS)\n"
|
||||
res+=" \\item CPU アーキテクチャ: \\\\texttt{$(getArch)}\n"
|
||||
res+=" \\item C コンパイラ: \\\\texttt{$(getGCCVersion)}\n"
|
||||
res+=" \\item C コンパイラオプション: \\\\texttt{}\n"
|
||||
res+="\\\\end{itemize}"
|
||||
|
||||
echo -e "$res"
|
||||
95
script/info-proc-programs.bash
Normal file
95
script/info-proc-programs.bash
Normal file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#==============================================================================
|
||||
# Section Generator for Info Processing Class's Assignment.
|
||||
#
|
||||
# $1 = Directory to program information(info.json)
|
||||
#
|
||||
# With following directory structure for programs, it will generate the LaTeX
|
||||
# section that contains assignment description, code listing, and execution
|
||||
# result:
|
||||
# |-programs
|
||||
# |-prog1
|
||||
# | |-example.h // included
|
||||
# | |-main.c // included
|
||||
# | |-Makefile // excluded
|
||||
# | |-info.json
|
||||
# ...
|
||||
#
|
||||
# For each program directory, it must contain file named "info.json" which
|
||||
# contains assignment name, description, type of output(screenshot, list of
|
||||
# values, or text file), and optional note.
|
||||
#
|
||||
# JSON scheme:
|
||||
# {
|
||||
# "language": "<Name of Language Defined in LaTeX Listings Package>",
|
||||
# "name": "<Name of Assignment>",
|
||||
# "description": "<Description of Assignment>",
|
||||
# "output": {
|
||||
# "type": "<screenshot | text",
|
||||
# "content":
|
||||
# "<path to screenshot or text file relative to project root>"
|
||||
# },
|
||||
# "note": "<Nullable string>"
|
||||
# }
|
||||
#
|
||||
# The output LaTeX section is written to stdout
|
||||
#==============================================================================
|
||||
|
||||
progPath=""
|
||||
|
||||
function writeSection () {
|
||||
local programDirectory="$1"
|
||||
local jsonFile="$programDirectory/info.json"
|
||||
local language="$(jq --raw-output '.language' $jsonFile)"
|
||||
local sectionName="$(jq --raw-output '.name' $jsonFile)"
|
||||
local description="$(jq --raw-output '.description' $jsonFile)"
|
||||
local outType="$(jq --raw-output '.output.type' $jsonFile)"
|
||||
local outContent="$(jq --raw-output '.output.content' $jsonFile)"
|
||||
local note="\n\n$(jq --raw-output '.note' $jsonFile)"
|
||||
declare -a listings
|
||||
local i=0
|
||||
local x=0
|
||||
local res=""
|
||||
|
||||
[[ $note == "\n\nnull" || $note == "\n\n" ]] && note=""
|
||||
|
||||
res+="\\section{$sectionName}\n\n$description\n\n\\subsection{コードリスティング}\n\n"
|
||||
|
||||
for f in $(find $programDirectory -name '*.py' -or -name '*.c' -or -name '*.h'); do
|
||||
listings[i]="\\lstinputlisting[language=$language,title={$sectionName}]{../$f}"
|
||||
i=$(($i+1))
|
||||
done
|
||||
|
||||
while [[ $x -lt $i ]]; do
|
||||
res+="$(echo -e "${listings[x]}")\n"
|
||||
x=$(($x+1))
|
||||
done
|
||||
|
||||
res+="\n\\subsection{実行結果}\n"
|
||||
|
||||
if [[ $outType == "screenshot" ]]; then
|
||||
res+="\n\\\\begin{center}\n \\includegraphics[width=\\\\textwidth]{$outContent}\n\\\\end{center}"
|
||||
elif [[ $outType == "text" ]]; then
|
||||
res+="\n\\\\verbatiminput{$outContent}";
|
||||
else
|
||||
echo "Invalid Output Type: $outType";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [[ $note != "" ]]; then
|
||||
res+="\n\\subsection{考察}\n"
|
||||
res+="$note"
|
||||
fi
|
||||
|
||||
echo -e $res
|
||||
}
|
||||
|
||||
if [[ -n $1 ]]; then
|
||||
progPath="$1"
|
||||
writeSection $progPath
|
||||
else
|
||||
echo "No Arguments Provided"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
5
script/word-count.bash
Normal file
5
script/word-count.bash
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# count all words including source code
|
||||
|
||||
pandoc --from latex $1 --to plain | wc -w
|
||||
Reference in New Issue
Block a user