mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
[apps/code] Default script name is in class Script, not menu controller
This commit is contained in:
@@ -1,10 +1,53 @@
|
||||
#include "script.h"
|
||||
#include "script_store.h"
|
||||
|
||||
namespace Code {
|
||||
|
||||
Script::Script(Record f) :
|
||||
Record(f)
|
||||
{
|
||||
static inline void intToText(int i, char * buffer, int bufferSize) {
|
||||
// We only support integers from 0 to 99.
|
||||
assert(i>=0);
|
||||
assert(i<100);
|
||||
assert(bufferSize >= 3);
|
||||
if (i/10 == 0) {
|
||||
buffer[0] = i+'0';
|
||||
buffer[1] = 0;
|
||||
return;
|
||||
}
|
||||
buffer[0] = i/10+'0';
|
||||
buffer[1] = i-10*(i/10)+'0';
|
||||
buffer[2] = 0;
|
||||
}
|
||||
|
||||
void Script::DefaultName(char buffer[], size_t bufferSize) {
|
||||
assert(bufferSize >= k_defaultScriptNameMaxSize);
|
||||
static constexpr char defaultScriptName[] = "script";
|
||||
static constexpr int defaultScriptNameLength = 6;
|
||||
memcpy(buffer, defaultScriptName, bufferSize);
|
||||
|
||||
// We will only name scripts from script1.py to script99.py.
|
||||
int currentScriptNumber = 1;
|
||||
while (currentScriptNumber < 100) {
|
||||
// Change the number in the script name.
|
||||
intToText(currentScriptNumber, &buffer[defaultScriptNameLength], bufferSize - defaultScriptNameLength );
|
||||
if (ScriptStore::ScriptNameIsFree(buffer)) {
|
||||
break;
|
||||
}
|
||||
currentScriptNumber++;
|
||||
}
|
||||
assert(false);
|
||||
}
|
||||
|
||||
bool Script::nameCompliant(const char * name) {
|
||||
/* The name format is [a-z0-9_\.]+ */
|
||||
const char * currentChar = name;
|
||||
while (*currentChar != 0) {
|
||||
if ((*currentChar >= 'a' && *currentChar <= 'z') || *currentChar == '_' || (*currentChar >= '0' && *currentChar <= '9') || *currentChar == '.') {
|
||||
currentChar++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return name != currentChar;
|
||||
}
|
||||
|
||||
bool Script::importationStatus() const {
|
||||
@@ -25,17 +68,4 @@ const char * Script::readContent() const {
|
||||
return (const char *)d.buffer+k_importationStatusSize;
|
||||
}
|
||||
|
||||
bool Script::nameCompliant(const char * name) {
|
||||
/* The name format is [a-z0-9_\.]+ */
|
||||
const char * currentChar = name;
|
||||
while (*currentChar != 0) {
|
||||
if ((*currentChar >= 'a' && *currentChar <= 'z') || *currentChar == '_' || (*currentChar >= '0' && *currentChar <= '9') || *currentChar == '.') {
|
||||
currentChar++;
|
||||
continue;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return name != currentChar;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user