/****************************************************************************** Copyright (c) 2004, Perforce Software, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *******************************************************************************/ /****************************************************************************** * ap4.cpp - description * ------------------- * begin : 2005/04/20 * copyright : (C) 2005 by Harald K. Strack * copyright : (C) 2005 by Trymedia Inc. * email : hstrack@trymedia.com ****************************************************************************** * changes name date comment * hks 2005/05/24 Mask support added. Revert fixed. * hks 2005/05/26 ap4 integrate support added. * hks 2005/05/27 ap4 help hooked. */ /* Main program of ap4. Option parsing has to be done here. The code for * this purpose was taken from Tony Smith's project: * * http://public.perforce.com:8080/guest/tony_smith/perforce/p4u/main/?ac=83 * * Thanks to him, I did not need to fiddle around with this stuff. */ //Perforce headers are buggy #ifndef _P4_CLIENTAPI_H_ #define _P4_CLIENTAPI_H_ #include "clientapi.h" #endif #include <error.h> #include <errorlog.h> #include <errornum.h> #include <enviro.h> #include <hostenv.h> #include <ident.h> #include <i18napi.h> #include <options.h> #include <debug.h> //Standard headers #include <string.h> #include <iostream> //Trymedia headers #include "TMClientUser.h" #include "TMSyncUser.h" #include "TMRevertUser.h" #include "TMIntegUser.h" #include "TMSubmitUser.h" #include "TMHelpUser.h" #include "TMBO.h" using namespace std; class MyIdent { public: void Format (StrBuf & b); const char *name; const char *os; const char *rel; const char *patch; const char *api_rel; const char *api_patch; }; void MyIdent::Format (StrBuf & b) { b.Clear (); b << "A Perforce client for Unix System Administrators.\n"; b << "Copyright 2004 Perforce Software. All rights reserved.\n"; b << "(C) 2005 by Harald K. Strack.\n"; b << "(C) 2005 by Trymedia Inc.\n"; // b << name << "/" << os << "/" << rel << "/" << patch; //b << " (Perforce API " << api_rel << "/" << api_patch << ")\n"; } //FIXME: should be like: /* MyIdent ident = { "P4U", ID_OS, P4U_VERSION, P4U_PATCH, ID_REL, ID_PATCH }; */ MyIdent ident = { "P4U", "1", "2", "3", "4", "5" }; ErrorId usage = { ErrorOf (ES_CLIENT, 0, E_INFO, EV_USAGE, 0), "\n" "Usage:\n" "\n" " ap4 [options] command [command-options] [command-args]\n\n" "\n" " Where options are:\n\n" " -h -? print this message\n" " -v level debug modes\n" " -V print version\n" " -x file read args from named file\n" "\n" " -c client set client name (default $P4CLIENT)\n" " -C charset set character set (default $P4CHARSET)\n" " -d dir set current directory for relative paths\n" " -H host set host name (default $P4HOST)\n" " -L language set message langauge (default $P4LANGUAGE)\n" " -p port set server port (default $P4PORT)\n" " -P password set user's password (default $P4PASSWD)\n" " -u user set user's username (default $P4USER)\n" "\n" " Try 'ap4 help' for information on Perforce commands.\n" "\n" }; int main (int argc, char **argv); int main (int argc, char **argv) { // // Parse the command line // Options opts; Error *e = new Error; StrPtr *s = 0; StrPtr *xfile = 0; opts.Parse (--argc, ++argv, "?C:c:d:H:hL:P:p:u:Vv:x:", OPT_ANY, usage, e); ErrorLog::Abort (e); // // Now override the defaults with values from the command line // where appropriate. We don't have to worry about the values in the // environment or in P4CONFIG files since the ClientApi class will // load those for us. // ClientApi client; // // Simple options first // if (s = opts['c']) client.SetClient (s); if (s = opts['d']) client.SetCwd (s); if (s = opts['H']) client.SetHost (s); if (s = opts['L']) client.SetLanguage (s); if (s = opts['P']) client.SetPassword (s); if (s = opts['p']) client.SetPort (s); if (s = opts['u']) client.SetUser (s); xfile = opts['x']; // // Now the options that would cause us to exit without much further // ado. // if (opts['h'] || opts['?']) { StrBuf t; e->Set (usage); e->Fmt (&t); printf ("%s", t.Text ()); exit (0); } if (opts['V']) { StrBuf t; ident.Format (t); printf ("%s", t.Text ()); return 0; } // // Now the options that need more complex handling // int i; for (i = 0; s = opts.GetValue ('v', i); i++) p4debug.SetLevel (s->Text ()); // // Charset needs special handling because ClientApi::SetCharset() // doesn't work properly. We need to use SetTrans() and that means // we need to lookup the value. We also check the environment value // now to make sure they're using a valid charset before we continue. // const char *charset = 0; if (s = opts['C']) { charset = s->Text (); } else { Enviro env; HostEnv hostEnv; StrBuf cwd; hostEnv.GetCwd (cwd); env.Config (cwd); charset = env.Get ("P4CHARSET"); } if (charset) { CharSetApi::CharSet cs = CharSetApi::Lookup (charset); if (cs == (CharSetApi::CharSet) - 1) { fprintf (stderr, "Bad Charset: %s is not a valid charset\n", charset); return 1; } client.SetTrans (cs); } // // If the user's forgotten to type a command, we'll run // 'p4 help' for them. // if (!argc) { argv = new char *[2]; argv[0] = "help"; argv[1] = 0; argc = 1; } // // OK, we're about ready to go. Connect to the server // client.Init (e); ErrorLog::Abort (e); ClientUser *ui = NULL; StrBuf cmd; cmd.Set (argv[0]); //Switch through the commands and hook them if necessary if (cmd == "sync") { //performs attribute writing and hooks out p4 chmodding ui = new TMSyncUser (&client); } else if (cmd == "submit") { //performs attribute saving on submit and hooks out p4 chmodding ui = new TMSubmitUser (&client); } else if (cmd == "edit") { //hooks p4 chmodding ui = new TMClientUser (&client, EDIT_HANDLER); } else if (cmd == "revert") { //performs attribute writing and hooks out p4 chmodding ui = new TMRevertUser (&client); } else if (cmd == "add") { //hooks out p4 chmodding ui = new TMClientUser (&client, ADD_HANDLER); } else if (cmd == "integrate") { //hooks out p4 chmodding ui = new TMIntegUser (&client); } else if (cmd == "help") { //hooks out p4 chmodding ui = new TMHelpUser (&client); } else { //standard behaviour ui = new ClientUser (); } // // Run the command: // If we've got a -x flag we have to read our arguments from // a file. If not, we just go with what we've got. Get the simple // version out of the way first. // if (!xfile) { client.SetArgv (argc - 1, argv + 1); client.Run (argv[0], ui); //Close TMClientuser and perform this way the Handler (TMBO::Run) delete ui; // Close connection client.Final (e); ErrorLog::Abort (e); return 0; } // -x version FileSys *xf = FileSys::Create (FST_TEXT); xf->Set (*xfile); xf->Open (FOM_READ, e); ErrorLog::Abort (e); StrBuf l; int eof = 0; int ac = 0; while (!e->Test () && !client.Dropped () && !eof) { eof = !xf->ReadLine (&l, e); if (!eof) { if (ac == 0) client.SetArgv (argc - 1, argv + 1); client.SetVar ("", &l); ac++; } if (eof && ac || (ac == 128)) { client.Run (argv[0], ui); ac = 0; } } xf->Close (e); ErrorLog::Abort (e); //Close TMClientuser and perform this way the Handler (TMBO::Run) delete ui; client.Final (e); ErrorLog::Abort (e); return 0; }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#6 | 5056 | harald_strack |
Directory support. Serious bug concerned to not unzipped binaries removed. Some other small bugfixes. |
||
#5 | 4980 | harald_strack |
Since I am maintaining the stuff in a local repository, I did some copy errors in the last revisions. Fixed. |
||
#4 | 4979 | harald_strack | Help output hooked. | ||
#3 | 4978 | harald_strack |
ap4 integrate implemented. Octal format is now used to save permissions. NOT backwards compatible anymore!!! |
||
#2 | 4975 | harald_strack |
Permissions are now masked to 555, so no write is possible. If you edit the Makefile and give the parameter -DFULL_PERMS, you have the old behaviour. Bugfix in ap4 revert: Edited and changed files were not reverted correctly. |
||
#1 | 4948 | harald_strack | Initial revision. |