PackageManager: Converted cmdline interface to C

svn path=/trunk/rosapps/packmgr/; revision=20
This commit is contained in:
Maarten Bosma 2005-04-16 11:11:52 +00:00
parent 3c5a322cee
commit eb2cc84e6f
5 changed files with 214 additions and 209 deletions

207
cmd-line/main.c Normal file
View File

@ -0,0 +1,207 @@
////////////////////////////////////////////////////////
//
// main.cpp
//
// Implementation of a Commandlne Interface
// for the ReactOs Package Manager
//
// Maarten Bosma, 09.01.2004
// maarten.paul@bosma.de
//
////////////////////////////////////////////////////////////////////
#include "main.h"
#include <stdio.h>
int main (int argc, char **argv)
{
wprintf(L"ReactOs PackageManager %d.%d.%d Commandline Interface \n\n", PACKMGR_VERSION_MAJOR, PACKMGR_VERSION_MINOR, PACKMGR_VERSION_PATCH_LEVEL);
Argv = argv; Argc = argc;
if(argc<2)
return Help();
// install a package
if (argv[1] == "install")
Install();
// install a package from source
else if (argv[1] == "src-inst")
{
wprintf(L"Sorry but I can't do that yet. \n");
}
// update a package
else if (argv[1] == "update")
{
wprintf(L"Sorry but I can't do that yet. \n");
}
// update everything
else if (argv[1] == "dist-upgrade")
{
wprintf(L"Sorry but I can't do that yet. \n");
}
// remove a package
else if (argv[1] == "remove")
{
wprintf(L"Sorry but I can't do that yet. \n");
}
// search for a package
else if (argv[1] == "show")
{
Show();
}
// search for a package
else if (argv[1] == "search")
{
wprintf(L"Sorry but I can't do that yet. \n");
}
else
Help();
//
wprintf(L"\n");
return 0;
}
int Help (void)
{
wprintf(L"Usage: ros-get [command] \n\n");
wprintf(L"Possible commands: \n");
wprintf(L" install [package name] \t Installs a package \n\n");
wprintf(L" show [package name] \t\t Shows you detailed information about a package \n");
wprintf(L"Currently unimplemented commands: \n");
wprintf(L" src-install [package name] \t Installs a package from source code \n");
wprintf(L" update [package name] \t Updates a package \n");
wprintf(L" dist-update [package name] \t Updates a package \n");
wprintf(L" remove [package name] \t Uninstalls a package \n\n");
wprintf(L" search [search agrument] \t Finds a package \n");
wprintf(L" list \t\t\t\t Lists all installed programs \n");
return 0;
}
int Ask (const WCHAR* question)
{
// ask the user
wprintf(L"%s [y/n] ", question);
char answer = getchar();
// clear keybuffer
while(getchar()!='\n');
wprintf(L"\n");
// prozess answer
if (answer == 'y')
return 1;
else if (answer == 'n')
return 0;
return Ask(question);
}
int SetStatus (int status1, int status2, WCHAR* text)
{
if(text)
wprintf(L"%s\n", text);
// If the Status is 1000 things are done
if(status1==1000)
{
wprintf(L"%s\n", PML_TransError(status2));
done = TRUE;
}
return 0;
}
int Install (void)
{
pTree tree;
int i, error;
// load the tree
error = PML_LoadTree (&tree, "tree.xml", NULL);
if(error)
{
wprintf(PML_TransError(error));
return 0;
}
// look up the item
for (i=2; i<Argc; i++)
{
int id = PML_FindItem(tree, Argv[i]);
if(id)
{
PML_LoadPackage(tree, id, NULL);
PML_SetAction(tree, id, 1, NULL, Ask);
}
else
printf("Could not find the Package \"%s\"\n", Argv[i]);
}
// do it
error = PML_DoIt (tree, SetStatus, Ask);
if(error)
{
wprintf(PML_TransError(error));
PML_CloseTree (tree);
return 0;
}
// wait
while (!done)
Sleep(1000);
// clean up
PML_CloseTree (tree);
return 0;
}
int Show (void)
{
pTree tree;
int i, error;
// load the tree
error = PML_LoadTree (&tree, "tree.xml", NULL);
if(error)
{
wprintf(PML_TransError(error));
return 0;
}
// look up the item
for (i=2; i<Argc; i++)
{
int id = PML_FindItem(tree, Argv[i]);
if(id)
printf(PML_GetDescription(tree, id));
else
printf("Could not find the Package \"%s\"\n", Argv[i]);
}
// clean up
PML_CloseTree (tree);
return 0;
}

View File

@ -1,201 +0,0 @@
////////////////////////////////////////////////////////
//
// main.cpp
//
// Implementation of a Commandlne Interface
// for the ReactOs Package Manager
//
// Maarten Bosma, 09.01.2004
// maarten.paul@bosma.de
//
////////////////////////////////////////////////////////////////////
#include "main.h"
int main (int argc, char **argv)
{
cout << "ReactOs PackageManager " << PACKMGR_VERSION_MAJOR << "." << PACKMGR_VERSION_MINOR << "." << PACKMGR_VERSION_PATCH_LEVEL << " Commandline Interface \n\n";
int i;
if(argc<2)
return Help();
for (i=1; i<argc; i++)
cmdline.push_back(argv[i]);
// install a package
if (cmdline[0] == "install")
Install();
// install a package from source
else if (cmdline[0] == "src-inst")
{
cout << "Sorry but I can't do that yet. \n";
}
// update a package
else if (cmdline[0] == "update")
{
cout << "Sorry but I can't do that yet. \n";
}
// update everything
else if (cmdline[0] == "dist-upgrade")
{
cout << "Sorry but I can't do that yet. \n";
}
// remove a package
else if (cmdline[0] == "remove")
{
cout << "Sorry but I can't do that yet. \n";
}
// search for a package
else if (cmdline[0] == "show")
{
Show();
}
// search for a package
else if (cmdline[0] == "search")
{
cout << "Sorry but I can't do that yet. \n";
}
else
Help();
return 0;
}
int Help (void)
{
cout << "Usage: ros-get [command] \n\n";
cout << "Possible commands: \n";
cout << " install [package name] \t Installs a package \n\n";
cout << " show [package name] \t\t Shows you detailed information about a package \n";
cout << "Currently unimplemented commands: \n";
cout << " src-install [package name] \t Installs a package from source code \n";
cout << " update [package name] \t Updates a package \n";
cout << " dist-update [package name] \t Updates a package \n";
cout << " remove [package name] \t Uninstalls a package \n\n";
cout << " search [search agrument] \t Finds a package \n";
cout << " list \t\t\t\t Lists all installed programs \n\n";
return 0;
}
int Ask (const WCHAR* question)
{
char answer[255];
wprintf(question);
cout << " [y/n] ";
cin >> answer;
cout << endl;
if (answer[0]=='y')
return 1;
else if (answer[0]=='n')
return 0;
return Ask(question);
}
int SetStatus (int status1, int status2, WCHAR* text)
{
if(text)
wprintf(L"%s\n", text);
// If the Status is 1000 things are done
if(status1==1000)
{
wprintf(L"%s\n", PML_TransError(status2));
done = true;
}
return 0;
}
int Install (void)
{
pTree tree;
int i, error;
// load the tree
error = PML_LoadTree (&tree, "tree.xml", NULL);
if(error)
{
cout << PML_TransError(error);
return 0;
}
// look up the item
for (i=1; (UINT)i<cmdline.size(); i++)
{
int id = PML_FindItem(tree, cmdline[i].c_str());
if(id)
PML_SetAction(tree, id, 1, NULL, Ask);
else
cout << "Could not find the Package \"" << cmdline[i] << "\"\n";
}
// do it
error = PML_DoIt (tree, SetStatus, Ask);
if(error)
{
wprintf(L"%s\n", PML_TransError(error));
PML_CloseTree (tree);
return 0;
}
// wait
while (!done)
Sleep(1000);
// clean up
PML_CloseTree (tree);
return 0;
}
int Show (void)
{
pTree tree;
int i, error;
// load the tree
error = PML_LoadTree (&tree, "tree.xml", NULL);
if(error)
{
cout << PML_TransError(error);
return 0;
}
// look up the item
for (i=1; (UINT)i<cmdline.size(); i++)
{
int id = PML_FindItem(tree, cmdline[i].c_str());
if(id)
cout << PML_GetDescription (tree, id) << "\n";
else
cout << "Could not find the Package \"" << cmdline[i] << "\"\n";
}
// clean up
PML_CloseTree (tree);
return 0;
}

View File

@ -4,13 +4,11 @@
// main.cpp's lumber room :)
///////////////////////////////////////////////////
#include "package.hpp"
#include <package.h>
#include <iostream>
vector<string> cmdline;
bool done = false;
int Argc;
char **Argv;
BOOL done = FALSE;
int Help (void);
int Install (void);

View File

@ -53,7 +53,8 @@ char* PML_Download (const char* url, const char* server = "tree", const char* fi
// get the url
if (!server);
if (!server)
strcpy(downl, "");
else if(!strcmp(server, "tree"))
strcpy(downl, tree_server);

View File

@ -17,7 +17,7 @@ BEGIN
ERR_DEP1 "To install this package you have to install the following package(s) as well:\n\n"
ERR_DEP2 "\nDo you want this ?"
ERR_READY "You choosen to install %d package(s). To install them you have to read and agree with each of thier licences.\n\n Do you want still want to ?"
ERR_READY "You choosen to install %d package(s). To install them you have to read and agree with each of thier licences. \n\nDo you want still want to ?"
END
/* EOF */