Last active
May 14, 2019 18:16
-
-
Save ear7h/2eb1cb4d260f5b291b27f791bd41df99 to your computer and use it in GitHub Desktop.
script to generate pa files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# uses python 3 | |
# usage: pafile filename [pretty name] | |
# the file must not exist | |
import sys | |
from datetime import date | |
raise Exception('remove me and fill in `userid` and `author`') | |
fname = sys.argv[1] | |
ext = fname.split(".")[-1] | |
fname_noext = '' | |
if len(sys.argv) > 3: | |
fname_noext = sys.argv[2] | |
else: | |
fname_noext = '.'.join(fname.split('.')[:-1]) | |
userid = 'YOUR ID' | |
author = 'YOUR NAME' | |
date = date.today().strftime('%d %b %Y') | |
md_tmpl = """=== | |
filename: {fname} | |
user-id: {userid} | |
author: {author} | |
date: {date} | |
sources of help: na | |
=== | |
# {fname_noext} | |
# Building | |
# Running | |
## Example | |
## Errors | |
# Testing | |
# Questions | |
""" | |
s_tmpl = """# | |
# Filename: {fname} | |
# UserID: {userid} | |
# Author: {author} | |
# Date: {date} | |
# Sources of help: na | |
.cpu cortex-a53 | |
.syntax unified | |
.equ FP_OFFSET, 4 | |
.global {fname_noext} | |
.text | |
.align 2 | |
/* | |
* Name: {fname_noext} | |
* Function Prototype: | |
* Description: | |
* Parameters: | |
* Side Effects: | |
* Error Condition: | |
* Return Value: | |
* Registers Used: | |
*/ | |
{fname_noext}: | |
# standard prologue | |
push {{fp, lr}} | |
add fp, sp, FP_OFFSET | |
# standard epilogue | |
sub sp, fp, FP_OFFSET | |
pop {{fp, pc}} | |
""" | |
c_tmpl = """/* | |
* Filename: {fname} | |
* UserID: {userid} | |
* Author: {author} | |
* Date: {date} | |
* Sources of help: man pages, cplusplus.com | |
*/ | |
""" | |
c_test_tmpl = """/* | |
* Filename: {fname} | |
* UserID: {userid} | |
* Author: {author} | |
* Date: {date} | |
* Sources of help: man pages, cplusplus.com | |
*/ | |
#include <stdio.h> | |
#include "test.h" | |
typedef struct {{ | |
}} tc_t; | |
void {fname_noext} () {{ | |
tc_t tcs[] = {{ | |
}}; | |
int i; | |
tc_t tc; | |
for (i = 0; | |
i < sizeof(tcs) / sizeof(tc_t); | |
i++) {{ | |
tc = tcs[i]; | |
TEST( ); | |
}} | |
}} | |
int main( void ) {{ | |
fprintf( stderr, "Running tests for {fname_noext}...\\n" ); | |
{fname_noext}(); | |
fprintf( stderr, "Done running tests!\\n" ); | |
return 0; | |
}} | |
""" | |
with open(fname, 'x') as f: | |
tmpl = '' | |
if ext == 's': | |
# assembly files | |
tmpl = s_tmpl | |
elif fname.startswith('test') and ext == 'c': | |
# c test files | |
tmpl = c_test_tmpl | |
elif ext == 'c': | |
# c files | |
tmpl = c_tmpl | |
elif ext == 'md' or fname.lower() == 'readme': | |
# markdown and readme | |
tmpl = md_tmpl | |
msg = tmpl.format( | |
fname=fname, | |
userid=userid, | |
author=author, | |
date=date, | |
fname_noext=fname_noext) | |
f.write(msg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment