|
Forum Index : Microcontroller and PC projects : Quick "project" creator
| Author | Message | ||||
| elk1984 Senior Member Joined: 11/07/2020 Location: United KingdomPosts: 229 |
I have the following script in my path. When I want to knock up a quick program with all of my defaults I can get the project ready with *new-project <project-name> I hope someone finds this useful - it isn't fancy (i.e. no error trapping ). If anyone would like to finesse the code a bit more, feel free. Comments welcome.new-project.bas OPTION EXPLICIT ON OPTION DEFAULT NONE OPTION BASE 0 DIM commandLine As String = MM.CMDLINE$ DIM templateLine As String = "" DIM templateFolder As String = "/"+commandLine IF LEN(commandLine)>0 THEN OPEN "/.new-structure" FOR INPUT AS #1 mkdir templateFolder DO LINE INPUT #1, templateFolder IF LEN(templateFolder)>0 THEN templateFolder = Replace(templateFolder,"<name>",commandLine) mkdir "/"+templateFolder END IF LOOP UNTIL EOF(#1) OPEN "/.new-template" FOR INPUT AS #2 OPEN "/"+commandLine+"/"+commandLine+".bas" FOR OUTPUT AS #3 DO LINE INPUT #2, templateLine templateLine = Replace(Replace(templateLine,"<name>",commandLine),"<date>",date$) PRINT #3, templateLine LOOP UNTIL EOF(#2) CLOSE #1 CLOSE #2 CLOSE #3 CHDIR "/"+commandLine ELSE PRINT "NEW-PROJECT" PRINT "-----------" PRINT "Creates a new project with default parameters" PRINT "Usage: NEW-PROJECT <program-name>" END IF END '------------------------------------------------------------------------------------------------------------------------------ FUNCTION Replace(inputString As String, textToReplace As String, replacementString As String) As String LOCAL foundPosition As Integer = 1 LOCAL lastFoundPosition As Integer = 1 LOCAL newString As String = "" LOCAL preFindString As String = "" LOCAL postFindString As String = "" lastFoundPosition=foundPosition foundPosition=INSTR(inputString, textToReplace) IF foundPosition > 0 THEN 'Replace The Found Text preFindString=MID$(inputString,lastFoundPosition,foundPosition-1) postFindString = MID$(inputString,foundPosition+LEN(textToReplace),LEN(inputString)-foundPosition+LEN(textToReplace)) newString=preFindString + replacementString + postFindString 'Search for the next instance by recursing the string newString=Replace(newString, textToReplace, replacementString) ELSE newString=inputString END IF Replace=newString END FUNCTION Save this file as .new-structure in the SD Card root. <name>/includes <name>/resources <name>/files <name>/config Save this file as .new-template in the SD Card root. This is your template code. The example include here refers to my Auto Backup program 'File : <name> 'Created : <date> 'MM Version : OPTION EXPLICIT ON OPTION DEFAULT NONE OPTION BASE 0 #include "/!includes/libraries/sub-backup-program.inc" DoBackup (10,0) '------------------------------------------------------------------------- After running this program, you'll have a directory created in root of your SD card, with a default directory structure and a template.bas file |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |