Skip to content

Commit ec42032

Browse files
committed
programs dir helper
1 parent 05f4246 commit ec42032

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/lang/program_util.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,21 @@ void ProgramUtil::avoidNopOrOverflow(Operation &op) {
562562
}
563563
}
564564

565+
std::string ProgramUtil::getProgramsDir(char domain) {
566+
std::string dir;
567+
switch (domain) {
568+
case 'A':
569+
dir = "oeis";
570+
break;
571+
case 'P':
572+
dir = "prg";
573+
break;
574+
default:
575+
throw std::runtime_error("Unknown domain: " + std::string(1, domain));
576+
}
577+
return Setup::getProgramsHome() + dir + FILE_SEP;
578+
}
579+
565580
std::string ProgramUtil::dirStr(UID id) {
566581
std::stringstream s;
567582
s << std::setw(3) << std::setfill('0') << (id.number() / 1000);
@@ -572,19 +587,8 @@ std::string ProgramUtil::getProgramPath(UID id, bool local) {
572587
if (local || id.domain() == 'U') {
573588
return Setup::getProgramsHome() + "local" + FILE_SEP + id.string() + ".asm";
574589
} else {
575-
std::string dir;
576-
switch (id.domain()) {
577-
case 'A':
578-
dir = "oeis";
579-
break;
580-
case 'P':
581-
dir = "prg";
582-
break;
583-
default:
584-
throw std::runtime_error("Unknown domain: " + id.string());
585-
}
586-
return Setup::getProgramsHome() + dir + FILE_SEP + dirStr(id) + FILE_SEP +
587-
id.string() + ".asm";
590+
auto dir = getProgramsDir(id.domain());
591+
return dir + dirStr(id) + FILE_SEP + id.string() + ".asm";
588592
}
589593
}
590594

src/lang/program_util.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class ProgramUtil {
8787

8888
static std::string dirStr(UID id);
8989

90+
static std::string getProgramsDir(char domain);
91+
9092
static std::string getProgramPath(UID id, bool local = false);
9193

9294
static int64_t getOffset(const Program &p);

0 commit comments

Comments
 (0)