summaryrefslogtreecommitdiffhomepage
path: root/public/tools/mk.fwrk/src/CommandLine.cc
blob: 87945ddc803bdeb6e09516adb08ee076370e0bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
 * Created on Thu Oct 17 08:00:42 CEST 2024
 *
 * Copyright (c) 2024-2025 Amlal El Mahrouss
 */

#include <Framework.h>
#include <Steps.h>

#include <libSystem/SystemKit/Err.h>

#include <CoreFoundation.fwrk/headers/Array.h>

/// @brief This program makes a framework/app/steps directory for NeKernel OS.

static const Char* kStepsName    = "Steps";
static const Char* kStepsAuthor  = "John Doe";
static const Char* kStepsCompany = "Company, Inc";

SInt32 _NeMain(SInt32 argc, Char* argv[]) {
  CF::CFArray<const char*, 256U> files;

  auto ext = kFKExtension;

  for (SInt32 i = 2UL; i < argc; ++i) {
    if (MmStrCmp(argv[i], "-h") == 0) {
      PrintOut(nullptr, "%s", "make_app: Framework/Application Creation Tool.\n");
      PrintOut(nullptr, "%s", "make_app: © 2024-2025 Amlal El Mahrouss, All rights reserved.\n");

      PrintOut(nullptr, "%s", "make_app: -a: Application Directory.\n");
      PrintOut(nullptr, "%s", "make_app: -s: Steps (Setup pages) Directory.\n");
      PrintOut(nullptr, "%s", "make_app: -f: Framework Directory.\n");

      return kErrorSuccess;
    }

    if (MmStrCmp(argv[i], "--author") == 0) {
      MmCopyMemory(const_cast<Char*>(kStepsAuthor), const_cast<Char*>(argv[i + 1]),
                   MmStrLen(argv[i + 1]));
      continue;
    }

    if (MmStrCmp(argv[i], "--company") == 0) {
      MmCopyMemory(const_cast<Char*>(kStepsCompany), const_cast<Char*>(argv[i + 1]),
                   MmStrLen(argv[i + 1]));
      continue;
    }

    if (MmStrCmp(argv[i], "--name") == 0) {
      MmCopyMemory(const_cast<Char*>(kStepsName), const_cast<Char*>(argv[i + 1]),
                   MmStrLen(argv[i + 1]));
      continue;
    }

    if (MmStrCmp(argv[i], "-a") == 0) {
      ext = kAppExtension;
      continue;
    } else if (MmStrCmp(argv[i], "-s") == 0) {
      ext = kStepsExtension;
      continue;
    } else if (MmStrCmp(argv[i], "-f") == 0) {
      ext = kFKExtension;
      continue;
    }

    files[i] = argv[i];
  }

  auto path = argv[1];

  if (FsCreateDir(path)) {
    FsCreateDir(StrFmt("{}{}", path, kRootDirectory));
    FsCreateDir(StrFmt("{}{}", path, kExecDirectory));

    if (MmStrCmp(ext, kStepsExtension) == 0) {
      FsCreateFile(StrFmt("{}{}{}{}", path, kRootDirectory, "_setup"));

      auto handle =
          IoOpenFile(StrFmt("{}{}{}{}", path, kRootDirectory, "_setup", kStepsExtension), nullptr);

      struct STEPS_COMMON_RECORD record;

      MmFillMemory(&record, sizeof(STEPS_COMMON_RECORD), 0);

      MmCopyMemory(record.name, const_cast<Char*>(kStepsName), kStepsStrLen);
      MmCopyMemory(record.author, const_cast<Char*>(kStepsAuthor), kStepsStrLen);
      MmCopyMemory(record.company, const_cast<Char*>(kStepsCompany), kStepsStrLen);

      MmCopyMemory(record.magic, const_cast<Char*>(kStepsMagic), kStepsMagicLen);

      record.version = kStepsVersion;

      IoWriteFile(handle, (void*) &record, sizeof(STEPS_COMMON_RECORD));
      IoCloseFile(handle);

      handle = nullptr;
    }

    for (auto i = 0UL; i < files.Count(); ++i) {
      auto& file = files[i];

      FsCopy(path, StrFmt("{}{}", path, file));
    }

    return kErrorSuccess;
  }

  return kErrorInternal;
}