From ae2779e504ca5ae11a87e047b4536a5f428cce4d Mon Sep 17 00:00:00 2001 From: pixel Date: Sat, 27 Nov 2004 21:46:02 +0000 Subject: Large dos2unix commit... --- src/Main.cc | 430 ++++++++++++++++++++++++++++++------------------------------ src/misc.cc | 132 +++++++++---------- src/paq.cc | 330 +++++++++++++++++++++++----------------------- 3 files changed, 446 insertions(+), 446 deletions(-) (limited to 'src') diff --git a/src/Main.cc b/src/Main.cc index 7cc062e..ecec54e 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -1,215 +1,215 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#include -#include "Handle.h" -#include "Task.h" -#include "TaskMan.h" -#include "HttpServ.h" -#include "Socket.h" -#include "config.h" -#include "Message.h" -#include "Menu.h" -#include "Exceptions.h" -#include "Form.h" -#include "Confirm.h" -#include "Table.h" -#include "InPipe.h" -#include "Image.h" -#include "CopyJob.h" -#include "IRC.h" -#include "Main.h" -#include "gettext.h" - -InPipe * in; - -class ad_run : public Task { - public: - ad_run(Variables * av, Variables * ahds, Handle * ah) : v(*av), hds(*ahds), h(ah) { - SetBurst(); - } - virtual ~ad_run() {} - virtual String GetName() { return "Action dynamique"; } - protected: - virtual int Do() throw (GeneralException) { - pid_t p; - - switch (current) { - case 0: - if (!(p = fork())) { - execlp("uptime", "uptime", NULL); - } - current = 1; - WaitFor(p); - Suspend(TASK_ON_HOLD); - - case 1: - (*in) >> ut; - if (!(p = fork())) { - execlp("uname", "uname", "-a", NULL); - } - current = 2; - WaitFor(p); - Suspend(TASK_ON_HOLD); - - case 2: - (*in) >> un; - for (int i = 0; i < hds.GetNb(); i++) { - shds += hds[i] + "
\n"; - } - - m = new Message("Action dynamique", - String("Vous avez choisi l'action dynamique. L'uptime de la machine est '") + - ut + "' et sa définition complète est '" + un + "'


Voici la liste des entêtes:

" + shds, ""); - - current = 3; - WaitFor(m->Do(&v, &hds, h)); - Suspend(TASK_ON_HOLD); - - case 3: - delete m; - testimg = new Image(100, 100); - testimg->Prepare(); - - testoutput = new Output("TestImg.tga"); - - current = 4; - WaitFor(new CopyJob(testimg, testoutput, -1, true, true)); - Suspend(TASK_ON_HOLD); - - case 4: - return TASK_DONE; - } - return TASK_DONE; - } - private: - Variables v, hds; - Handle * h; - String ut, un, shds; - Action * m; - Image * testimg; - Output * testoutput; -}; - -class ad_t : public Action { - public: - ad_t() : Action("menu6") { } - virtual ~ad_t() { } - virtual String GetTitle() { return "Action dynamique"; } - virtual Task * Do(Variables * v, Variables * hds, Handle * h) { - return new ad_run(v, hds, h); - } -}; -Action * ad = new ad_t(); - -class dostop_t : public Action { - public: - dostop_t() : Action("dostop") { } - virtual ~dostop_t() { } - virtual String GetTitle() { return "Arret du serveur"; } - virtual Task * Do(Variables * v, Variables * hds, Handle * h) { - TaskMan::Stop(); - return 0; - } -}; -Action * dostop = new dostop_t(); - -String Noms[] = {"Champ1", "Champ2", "Champ3"}; -String Defaults[] = {"Default1", "Default2", 0}; -String Invites[] = {"Champ 1:", "Champ 2:", "Champ 3:"}; -String Options[] = {"Option1", "Option2", ""}; -String ODescs[] = {"Description 1", "Description 2", ""}; -String * Lists[] = {0, 0, Options}; -String * Descs[] = {0, 0, ODescs}; -String Titres[] = {"Titre 1", "Titre 2", "Titre 3"}; -String Cells[] = {"L1C1", "L1C2", "L1C3", "L2C1", "L2C2", "L2C3", "L3C1", "L3C2", "L3C3", "L4C1", "L4C2", "L4C3"}; -Action * a1 = new Message("Action 1", "Vous avez cliqué sur l'option 1 du menu", "menu1"); -Action * a2 = new Table("Petite table", "menu2", Titres, Cells, 3, 4); -Action * a3 = new Message("Test d'image", -"Voici un test d'affichage d'image:" -"
", -"menu3"); -Action * a4 = new Form("Test de formulaire...", "menu4", "Rentrez des trucs...", Noms, Invites, Defaults, Lists, Descs, 3); -Action * a5 = new Confirm("Confirmation", "Oui ou non?", "menu5", 0, 0); -Action * java = new Message("Applet JAVA", -"\n" -"
\n" -"\n" -"\n" -"
\n", "java"); - -Action * up = new Message("Test d'upload", -"\n" -"
\n" -"\n" -"Send this file: \n" -"\n" -"
\n", "upload"); - -Action * stop = new Confirm("Stopper", "Stopper le serveur?", "stop", dostop, 0); - -Action * Liste[] = {a1, a2, a3, a4, a5, ad, java, up, stop}; -String Labels[] = {"Action 1", "Action 2", "Action 3", "Action 4", "Action 5", "Action dynamique", "Essai de java", "Test d'upload", "Stop"}; - -CODE_BEGINS - -Action * buildmenu(void) { - Action * m = new Menu("Menu Principal", "start", Labels, Liste, 9); - return m; -} - -int startup() throw (GeneralException) { - int c; - String port = "1500"; - - std::list testlist; - testlist.push_front("poide"); - - in = new InPipe(); - - in->Hook(); - - String test = "poide\n", r; - std::cout << test; - std::cout.flush(); - (*in) >> r; - if (r != "poide") { - printm(M_ERROR, "The stdout redirect has failed.\n"); - exit(-1); - } - - while ((c = getopt(argc, argv, "p:")) != EOF) { - switch (c) { - case 'p': - port = optarg; - break; - default: - printm(M_BARE, String(_("Usage: ")) + argv[0] + " [-p port]\n"); - exit(-1); - } - } - - try { - HttpServ h(buildmenu(), port.to_int(), "testing"); -// IRC i("botalacon"); -// i.Connect(); -// i.MainLoop(); - TaskMan::MainLoop(); - } - catch (GeneralException e) { - std::cerr << "Main function got an exception: '" << e.GetMsg() << "'.\n"; - exit(-1); - } - - catch (...) { - std::cerr << "Unknow exception.\n" << std::endl; - exit(-1); - } - - delete in; - return 0; -} -CODE_ENDS +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include "Handle.h" +#include "Task.h" +#include "TaskMan.h" +#include "HttpServ.h" +#include "Socket.h" +#include "config.h" +#include "Message.h" +#include "Menu.h" +#include "Exceptions.h" +#include "Form.h" +#include "Confirm.h" +#include "Table.h" +#include "InPipe.h" +#include "Image.h" +#include "CopyJob.h" +#include "IRC.h" +#include "Main.h" +#include "gettext.h" + +InPipe * in; + +class ad_run : public Task { + public: + ad_run(Variables * av, Variables * ahds, Handle * ah) : v(*av), hds(*ahds), h(ah) { + SetBurst(); + } + virtual ~ad_run() {} + virtual String GetName() { return "Action dynamique"; } + protected: + virtual int Do() throw (GeneralException) { + pid_t p; + + switch (current) { + case 0: + if (!(p = fork())) { + execlp("uptime", "uptime", NULL); + } + current = 1; + WaitFor(p); + Suspend(TASK_ON_HOLD); + + case 1: + (*in) >> ut; + if (!(p = fork())) { + execlp("uname", "uname", "-a", NULL); + } + current = 2; + WaitFor(p); + Suspend(TASK_ON_HOLD); + + case 2: + (*in) >> un; + for (int i = 0; i < hds.GetNb(); i++) { + shds += hds[i] + "
\n"; + } + + m = new Message("Action dynamique", + String("Vous avez choisi l'action dynamique. L'uptime de la machine est '") + + ut + "' et sa définition complète est '" + un + "'


Voici la liste des entêtes:

" + shds, ""); + + current = 3; + WaitFor(m->Do(&v, &hds, h)); + Suspend(TASK_ON_HOLD); + + case 3: + delete m; + testimg = new Image(100, 100); + testimg->Prepare(); + + testoutput = new Output("TestImg.tga"); + + current = 4; + WaitFor(new CopyJob(testimg, testoutput, -1, true, true)); + Suspend(TASK_ON_HOLD); + + case 4: + return TASK_DONE; + } + return TASK_DONE; + } + private: + Variables v, hds; + Handle * h; + String ut, un, shds; + Action * m; + Image * testimg; + Output * testoutput; +}; + +class ad_t : public Action { + public: + ad_t() : Action("menu6") { } + virtual ~ad_t() { } + virtual String GetTitle() { return "Action dynamique"; } + virtual Task * Do(Variables * v, Variables * hds, Handle * h) { + return new ad_run(v, hds, h); + } +}; +Action * ad = new ad_t(); + +class dostop_t : public Action { + public: + dostop_t() : Action("dostop") { } + virtual ~dostop_t() { } + virtual String GetTitle() { return "Arret du serveur"; } + virtual Task * Do(Variables * v, Variables * hds, Handle * h) { + TaskMan::Stop(); + return 0; + } +}; +Action * dostop = new dostop_t(); + +String Noms[] = {"Champ1", "Champ2", "Champ3"}; +String Defaults[] = {"Default1", "Default2", 0}; +String Invites[] = {"Champ 1:", "Champ 2:", "Champ 3:"}; +String Options[] = {"Option1", "Option2", ""}; +String ODescs[] = {"Description 1", "Description 2", ""}; +String * Lists[] = {0, 0, Options}; +String * Descs[] = {0, 0, ODescs}; +String Titres[] = {"Titre 1", "Titre 2", "Titre 3"}; +String Cells[] = {"L1C1", "L1C2", "L1C3", "L2C1", "L2C2", "L2C3", "L3C1", "L3C2", "L3C3", "L4C1", "L4C2", "L4C3"}; +Action * a1 = new Message("Action 1", "Vous avez cliqué sur l'option 1 du menu", "menu1"); +Action * a2 = new Table("Petite table", "menu2", Titres, Cells, 3, 4); +Action * a3 = new Message("Test d'image", +"Voici un test d'affichage d'image:" +"
", +"menu3"); +Action * a4 = new Form("Test de formulaire...", "menu4", "Rentrez des trucs...", Noms, Invites, Defaults, Lists, Descs, 3); +Action * a5 = new Confirm("Confirmation", "Oui ou non?", "menu5", 0, 0); +Action * java = new Message("Applet JAVA", +"\n" +"
\n" +"\n" +"\n" +"
\n", "java"); + +Action * up = new Message("Test d'upload", +"\n" +"
\n" +"\n" +"Send this file: \n" +"\n" +"
\n", "upload"); + +Action * stop = new Confirm("Stopper", "Stopper le serveur?", "stop", dostop, 0); + +Action * Liste[] = {a1, a2, a3, a4, a5, ad, java, up, stop}; +String Labels[] = {"Action 1", "Action 2", "Action 3", "Action 4", "Action 5", "Action dynamique", "Essai de java", "Test d'upload", "Stop"}; + +CODE_BEGINS + +Action * buildmenu(void) { + Action * m = new Menu("Menu Principal", "start", Labels, Liste, 9); + return m; +} + +int startup() throw (GeneralException) { + int c; + String port = "1500"; + + std::list testlist; + testlist.push_front("poide"); + + in = new InPipe(); + + in->Hook(); + + String test = "poide\n", r; + std::cout << test; + std::cout.flush(); + (*in) >> r; + if (r != "poide") { + printm(M_ERROR, "The stdout redirect has failed.\n"); + exit(-1); + } + + while ((c = getopt(argc, argv, "p:")) != EOF) { + switch (c) { + case 'p': + port = optarg; + break; + default: + printm(M_BARE, String(_("Usage: ")) + argv[0] + " [-p port]\n"); + exit(-1); + } + } + + try { + HttpServ h(buildmenu(), port.to_int(), "testing"); +// IRC i("botalacon"); +// i.Connect(); +// i.MainLoop(); + TaskMan::MainLoop(); + } + catch (GeneralException e) { + std::cerr << "Main function got an exception: '" << e.GetMsg() << "'.\n"; + exit(-1); + } + + catch (...) { + std::cerr << "Unknow exception.\n" << std::endl; + exit(-1); + } + + delete in; + return 0; +} +CODE_ENDS diff --git a/src/misc.cc b/src/misc.cc index d79204d..ea72572 100644 --- a/src/misc.cc +++ b/src/misc.cc @@ -1,66 +1,66 @@ -#include -#include "Handle.h" -#include "String.h" - -void GeneDeroul(Handle * h, String * & l1, String * & l2) { - int count; - list result; - String r1, r2; - - count = 0; - - while (1) { - (*h) >> r1; - (*h) >> r2; - if ((r1 == "") && (r2 == "")) break; - result.push_back(r1); - result.push_back(r2); - count++; - } - - l1 = new String[count + 1]; - l2 = new String[count + 1]; - - for (int i = 0; i < count; i++) { - r1 = result.front(); - result.pop_front(); - r2 = result.front(); - result.pop_front(); - l1[i] = r1; - l2[i] = r2; - } - - l1[count] = ""; - l2[count] = ""; -} - -int GeneList(Handle * h, int nbcol, String * & l) { - int nblig; - list result; - String r; - bool is_null; - - nblig = 0; - while (1) { - is_null = true; - for (int i = 0; i < nbcol; i++) { - (*h) >> r; - result.push_back(r); - if (r != "") is_null = false; - } - if (is_null) break; - nblig++; - } - - l = new String[nbcol * nblig + 1]; - - for (int i = 0; i < (nbcol * nblig); i++) { - r = result.front(); - result.pop_front(); - l[i] = r; - } - - l[nbcol * nblig] = ""; - - return nblig; -} +#include +#include "Handle.h" +#include "String.h" + +void GeneDeroul(Handle * h, String * & l1, String * & l2) { + int count; + list result; + String r1, r2; + + count = 0; + + while (1) { + (*h) >> r1; + (*h) >> r2; + if ((r1 == "") && (r2 == "")) break; + result.push_back(r1); + result.push_back(r2); + count++; + } + + l1 = new String[count + 1]; + l2 = new String[count + 1]; + + for (int i = 0; i < count; i++) { + r1 = result.front(); + result.pop_front(); + r2 = result.front(); + result.pop_front(); + l1[i] = r1; + l2[i] = r2; + } + + l1[count] = ""; + l2[count] = ""; +} + +int GeneList(Handle * h, int nbcol, String * & l) { + int nblig; + list result; + String r; + bool is_null; + + nblig = 0; + while (1) { + is_null = true; + for (int i = 0; i < nbcol; i++) { + (*h) >> r; + result.push_back(r); + if (r != "") is_null = false; + } + if (is_null) break; + nblig++; + } + + l = new String[nbcol * nblig + 1]; + + for (int i = 0; i < (nbcol * nblig); i++) { + r = result.front(); + result.pop_front(); + l[i] = r; + } + + l[nbcol * nblig] = ""; + + return nblig; +} diff --git a/src/paq.cc b/src/paq.cc index 7a56989..2cbddd4 100644 --- a/src/paq.cc +++ b/src/paq.cc @@ -1,165 +1,165 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef WORDS_BIGENDIAN -#define SIGNATURE 0x4e504151 -#else -#define SIGNATURE 0x5141504e -#endif - -String current_dir; - -extern "C" int sortdir(const void * d1, const void * d2) { - struct stat fstats1, fstats2; - String n; - - n = current_dir + "/" + (**((const dirent **)d1)).d_name; - stat(n.to_charp(), &fstats1); - - n = current_dir + "/" + (**((const dirent **)d2)).d_name; - stat(n.to_charp(), &fstats2); - - if (!((S_ISDIR(fstats1.st_mode) ? 1 : 0) ^ (S_ISDIR(fstats2.st_mode) ? 1 : 0))) { - return alphasort(d1, d2); - } else { - if (S_ISDIR(fstats1.st_mode)) - return -1; - else - return 1; - } -} - -CODE_BEGINS - -private: - -struct couple { - String p, v; -}; - -Output * Archive; - -std::list filelist; - -void finalize(void) { - int size; - Input * file; - for (std::list::iterator i = filelist.begin(); i != filelist.end(); i++) { - cerr << "Finalize file " << *i << endl; - file = new Input(*i); - size = file->GetSize(); - Archive->writeU32(size); - delete file; - file = new Input(*i + ".gz"); - copy(file, Archive); - delete file; - unlink((*i + ".gz").to_charp()); - } -} - -void process_file(const String & filename) { - char t; - int size, old_size; - cerr << "Processing file " << filename << "... "; - - Input * from = new Input(filename); - Output * to = new Output(filename + ".gz"); - - to->SetZ(); - - old_size = from->GetSize(); - - copy(from, to); - - delete to; - delete from; - - filelist.push_back(filename); - - from = new Input(filename + ".gz"); - size = from->GetSize() + 4; - cerr << old_size << " --> " << from->GetSize() << " (" << 100 * from->GetSize() / old_size << "%)\n"; - - Archive->writeU32(size); - - delete from; - - t = 0; - Archive->writeU8(t); -} - -void process_directory(const String & dirname) throw (GeneralException) { - struct dirent ** namelist; - int n, i; - Uint32 t; - struct stat fstats; - String fname; - - current_dir = dirname; - n = scandir(dirname.to_charp(), &namelist, NULL, sortdir); - cerr << "Processing directory " << dirname << endl; - - if (n < 0) { - throw GeneralException("Unable to open directory " + dirname); - } - - for (i = 0; i < n; i++) { - fname = dirname + "/" + namelist[i]->d_name; - stat(fname.to_charp(), &fstats); - if (S_ISDIR(fstats.st_mode)) { - if (!Regex("^\\.{1,2}$").Match(namelist[i]->d_name)) { - t = strlen(namelist[i]->d_name); - Archive->writeU8(t); - Archive->write(namelist[i]->d_name, t); - t = 0; - Archive->writeU32(t); - t = 1; - Archive->writeU8(t); - process_directory(dirname + "/" + namelist[i]->d_name); - } - } else { - if (!Regex("\\.gz$").Match(namelist[i]->d_name)) { - t = strlen(namelist[i]->d_name); - Archive->writeU8(t); - Archive->write(namelist[i]->d_name, t); - process_file(dirname + "/" + namelist[i]->d_name); - } - } - free((void *)namelist[i]); - } - - free((void *)namelist); - - t = 0; - Archive->writeU8(t); -} - -void build_archive(const String & dirname) { - char buff[4]; - - *((int *) buff) = SIGNATURE; - - Archive->write(buff, 4); - - process_directory(dirname); - - finalize(); -} - -public: - -virtual int startup(void) throw (GeneralException) { - Archive = new Output("/tmp/bleh.paq"); - build_archive("."); - return 0; -} -CODE_ENDS +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef WORDS_BIGENDIAN +#define SIGNATURE 0x4e504151 +#else +#define SIGNATURE 0x5141504e +#endif + +String current_dir; + +extern "C" int sortdir(const void * d1, const void * d2) { + struct stat fstats1, fstats2; + String n; + + n = current_dir + "/" + (**((const dirent **)d1)).d_name; + stat(n.to_charp(), &fstats1); + + n = current_dir + "/" + (**((const dirent **)d2)).d_name; + stat(n.to_charp(), &fstats2); + + if (!((S_ISDIR(fstats1.st_mode) ? 1 : 0) ^ (S_ISDIR(fstats2.st_mode) ? 1 : 0))) { + return alphasort(d1, d2); + } else { + if (S_ISDIR(fstats1.st_mode)) + return -1; + else + return 1; + } +} + +CODE_BEGINS + +private: + +struct couple { + String p, v; +}; + +Output * Archive; + +std::list filelist; + +void finalize(void) { + int size; + Input * file; + for (std::list::iterator i = filelist.begin(); i != filelist.end(); i++) { + cerr << "Finalize file " << *i << endl; + file = new Input(*i); + size = file->GetSize(); + Archive->writeU32(size); + delete file; + file = new Input(*i + ".gz"); + copy(file, Archive); + delete file; + unlink((*i + ".gz").to_charp()); + } +} + +void process_file(const String & filename) { + char t; + int size, old_size; + cerr << "Processing file " << filename << "... "; + + Input * from = new Input(filename); + Output * to = new Output(filename + ".gz"); + + to->SetZ(); + + old_size = from->GetSize(); + + copy(from, to); + + delete to; + delete from; + + filelist.push_back(filename); + + from = new Input(filename + ".gz"); + size = from->GetSize() + 4; + cerr << old_size << " --> " << from->GetSize() << " (" << 100 * from->GetSize() / old_size << "%)\n"; + + Archive->writeU32(size); + + delete from; + + t = 0; + Archive->writeU8(t); +} + +void process_directory(const String & dirname) throw (GeneralException) { + struct dirent ** namelist; + int n, i; + Uint32 t; + struct stat fstats; + String fname; + + current_dir = dirname; + n = scandir(dirname.to_charp(), &namelist, NULL, sortdir); + cerr << "Processing directory " << dirname << endl; + + if (n < 0) { + throw GeneralException("Unable to open directory " + dirname); + } + + for (i = 0; i < n; i++) { + fname = dirname + "/" + namelist[i]->d_name; + stat(fname.to_charp(), &fstats); + if (S_ISDIR(fstats.st_mode)) { + if (!Regex("^\\.{1,2}$").Match(namelist[i]->d_name)) { + t = strlen(namelist[i]->d_name); + Archive->writeU8(t); + Archive->write(namelist[i]->d_name, t); + t = 0; + Archive->writeU32(t); + t = 1; + Archive->writeU8(t); + process_directory(dirname + "/" + namelist[i]->d_name); + } + } else { + if (!Regex("\\.gz$").Match(namelist[i]->d_name)) { + t = strlen(namelist[i]->d_name); + Archive->writeU8(t); + Archive->write(namelist[i]->d_name, t); + process_file(dirname + "/" + namelist[i]->d_name); + } + } + free((void *)namelist[i]); + } + + free((void *)namelist); + + t = 0; + Archive->writeU8(t); +} + +void build_archive(const String & dirname) { + char buff[4]; + + *((int *) buff) = SIGNATURE; + + Archive->write(buff, 4); + + process_directory(dirname); + + finalize(); +} + +public: + +virtual int startup(void) throw (GeneralException) { + Archive = new Output("/tmp/bleh.paq"); + build_archive("."); + return 0; +} +CODE_ENDS -- cgit v1.2.3