Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19 from nikolauska/new-repo-example
Browse files Browse the repository at this point in the history
New repo layout and unified test
  • Loading branch information
Marvin Blum authored and Marvin Blum committed Nov 2, 2015
2 parents 67e950b + afad182 commit f6b5ed4
Show file tree
Hide file tree
Showing 33 changed files with 380 additions and 386 deletions.
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

45 changes: 22 additions & 23 deletions src/main/asl.go → asl.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"parser"
"tokenizer"
"fmt"
"io/ioutil"
"path/filepath"
Expand All @@ -15,6 +13,7 @@ const (
extension = ".asl"
sqfextension = ".sqf"
PathSeparator = string(os.PathSeparator)
new_line = "\r\n"
)

type ASLFile struct {
Expand Down Expand Up @@ -43,7 +42,7 @@ func usage() {

func flags(flag string) bool {
flag = strings.ToLower(flag)

if flag[0] == '-' {
if flag == "-v" {
fmt.Println("asl version "+version)
Expand All @@ -56,24 +55,24 @@ func flags(flag string) bool {
usage()
exit = true
}

return true
}

return false
}

func readAslFiles(path string) {
dir, err := ioutil.ReadDir(path)

if err != nil {
fmt.Println("Error reading in directory!")
return
}

for i := 0; i < len(dir); i++ {
name := dir[i].Name()

if dir[i].IsDir() && recursive {
readAslFiles(filepath.FromSlash(path+PathSeparator+name))
continue
Expand All @@ -82,8 +81,8 @@ func readAslFiles(path string) {
if !dir[i].IsDir() && strings.ToLower(filepath.Ext(name)) == extension {
in := filepath.FromSlash(path+PathSeparator+dir[i].Name())
out := filepath.FromSlash("./"+path[len(inDir):len(path)])
newname := name[:len(name)-len(filepath.Ext(name))]
newname := name[:len(name)-len(filepath.Ext(name))]

file := ASLFile{in, out, newname}
aslFiles = append(aslFiles, file)
}
Expand All @@ -95,19 +94,19 @@ func compile(path string) {
out := filepath.FromSlash(path+PathSeparator+aslFiles[i].out+PathSeparator+aslFiles[i].newname+sqfextension)
fmt.Println(aslFiles[i].in+" -> "+out)
code, err := ioutil.ReadFile(aslFiles[i].in)

if err != nil {
fmt.Println("Error reading file: "+aslFiles[i].in)
continue
}
token := tokenizer.Tokenize(code)
compiler := parser.Compiler{}

token := Tokenize(code)
compiler := Compiler{}
sqf := compiler.Parse(token, pretty)

os.MkdirAll(filepath.FromSlash(path+PathSeparator+aslFiles[i].out), 0777)
err = ioutil.WriteFile(out, []byte(sqf), 0666)

if err != nil {
fmt.Println("Error writing file: "+aslFiles[i].out)
fmt.Println(err)
Expand All @@ -117,34 +116,34 @@ func compile(path string) {

func main() {
args := os.Args

// flags
if len(args) < 2 {
usage()
return
}

var i int
for i = 1; i < len(args) && flags(args[i]); i++ {}

if exit {
return
}

// in/out parameter
out := ""

if i < len(args) {
inDir = args[i]
i++
} else {
return
}

if i < len(args) {
out = args[i]
}

readAslFiles(inDir)
compile(out)
}
Loading

0 comments on commit f6b5ed4

Please sign in to comment.