void _exits(char *s) { if(s == 0 || *s == 0) _exit(0); _exit(exitcode(s)); }
void ToolRunner::PostRun() { if( m_pWrapper->CaptureOutput() && !m_pWrapper->IsTextFilter() ) { tstring exitcode(LS(IDS_TOOL_EXITCODE)); exitcode += IntToTString(GetExitCode()); exitcode += LS(IDS_TOOL_TIMETAKEN); time_t endtime; time(&endtime); endtime -= m_starttime; char buf[100]; strftime(buf, 100, "%M:%S", gmtime(&endtime)); CA2CT bufconv(buf); exitcode += bufconv; exitcode += _T("\n"); m_pWrapper->_AddToolOutput(exitcode.c_str()); } if( m_pWrapper->IsFilter() ) m_pWrapper->Revert(); }
char *init(int argc, char **argv, char **home, int *ifd, int *ofd, int *to, char *dbdir) { char fname[MAXPATHLEN+1]; int i, status, addrlen; char *log = NULL; int debug = NRTS_DEFLOG; int timeout = 1; struct sockaddr_in cli_addr, *cli_addrp; struct hostent *hp, hostent; static char client[1024]; char *dbtmp; static char *defdbdir = NULL; static char *fid = "init"; *home = NULL; *ifd = -1; *ofd = -1; *to = 60; dbtmp = (char *) NULL; /* Get command line arguments */ for (i = 1; i < argc; i++) { if (strncmp(argv[i], "home=", strlen("home=")) == 0) { *home = argv[i] + strlen("home="); } else if (strncmp(argv[i], "debug=", strlen("debug=")) == 0) { debug = atoi(argv[i]+strlen("debug=")); } else if (strncmp(argv[i], "log=", strlen("log=")) == 0) { log = argv[i] + strlen("log="); } else if (strncmp(argv[i], "to=", strlen("to=")) == 0) { *to = atoi(argv[i] + strlen("to=")); } else if (strncmp(argv[i], "dbdir=", strlen("dbdir=")) == 0) { dbtmp = argv[i] + strlen("dbdir="); } else { help(argv[0]); } } if (dbtmp == (char *) NULL) dbtmp = getenv("IDA_DBDIR"); if (dbtmp == (char *) NULL) dbtmp = defdbdir; strcpy(dbdir, dbtmp); /* Determine working home */ if (*home == NULL) { *home = getenv(NRTS_HOME); } if (*home == NULL) { *home = NRTS_DEFHOME; } /* Open log file */ if (log == NULL) { sprintf(fname, "%s/log/xfer", *home); log = fname; } util_logopen(log, 1, NRTS_MAXLOG, debug, NULL, argv[0]); util_log(2, "Version %s", "2.11 (17:40:39 07/23/99)"); if (chdir(*home) != 0) { util_log(1, "%s: can't chdir %s: %s", fid, *home, syserrmsg(errno) ); return NULL; } /* Signal/exit handlers */ if (exitcode() != 0) { util_log(1, "%s: exitcode: %s", fid, syserrmsg(errno)); return NULL; } /* Get client info */ *ifd = fileno(stdin); *ofd = fileno(stdout); addrlen = sizeof(cli_addr); cli_addrp = &cli_addr; if (getpeername(*ifd, (struct sockaddr *)cli_addrp, &addrlen) != 0) { util_log(1, "%s: getpeername: %s", fid, syserrmsg(errno)); return NULL; } else { hp = gethostbyaddr((char *) &cli_addrp->sin_addr, sizeof(struct in_addr), cli_addrp->sin_family ); if (hp == NULL) { hp = &hostent; hp->h_name = inet_ntoa(cli_addrp->sin_addr); } sprintf(client, "%s", hp->h_name); } return client; }
static int unzzip_cat (int argc, char ** argv, int extract) { int done = 0; int argn; FILE* disk; disk = fopen (argv[1], "rb"); if (! disk) { perror(argv[1]); return exitcode(errno); } if (argc == 2) { /* print directory list */ ZZIP_ENTRY* entry = zzip_entry_findfirst(disk); for (; entry ; entry = zzip_entry_findnext(entry)) { char* name = zzip_entry_strdup_name (entry); FILE* out = stdout; if (! name) { done = EXIT_WARNINGS; continue; } if (extract) out = create_fopen(name, "wb", 1); if (! out) { if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); free (name); } return done; } if (argc == 3 && !extract) { /* list from one spec */ ZZIP_ENTRY* entry = 0; while ((entry = zzip_entry_findmatch(disk, argv[2], entry, 0, 0))) { unzzip_big_entry_fprint (entry, stdout); } return 0; } for (argn=1; argn < argc; argn++) { /* list only the matching entries - each in order of commandline */ ZZIP_ENTRY* entry = zzip_entry_findfirst(disk); for (; entry ; entry = zzip_entry_findnext(entry)) { char* name = zzip_entry_strdup_name (entry); DBG3(".. check '%s' to zip '%s'", argv[argn], name); if (! _zzip_fnmatch (argv[argn], name, _zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD)) { FILE* out = stdout; if (extract) out = create_fopen(name, "wb", 1); if (! out) { if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); break; /* match loop */ } free (name); } } return done; }
static int unzzip_cat (int argc, char ** argv, int extract) { int done = 0; int argn; ZZIP_DIR* disk; zzip_error_t error; if (argc == 1) { printf (__FILE__" version "ZZIP_PACKAGE" "ZZIP_VERSION"\n"); return EXIT_OK; /* better provide an archive argument */ } disk = zzip_dir_open (argv[1], &error); if (! disk) { fprintf(stderr, "%s: %s\n", argv[1], zzip_strerror(error)); return exitcode(error); } if (argc == 2) { /* list all */ ZZIP_DIRENT entry; while(zzip_dir_read(disk, &entry)) { char* name = entry.d_name; FILE* out = stdout; if (extract) out = create_fopen(name, "wb", 1); if (! out) { DBG3("fopen' %s : %s", name, strerror(errno)); if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); } } else { /* list only the matching entries - in order of zip directory */ ZZIP_DIRENT entry; while(zzip_dir_read(disk, &entry)) { char* name = entry.d_name; for (argn=1; argn < argc; argn++) { if (! _zzip_fnmatch (argv[argn], name, _zzip_FNM_NOESCAPE|_zzip_FNM_PATHNAME|_zzip_FNM_PERIOD)) { FILE* out = stdout; if (extract) out = create_fopen(name, "wb", 1); if (! out) { DBG3("fopen. %s : %s", name, strerror(errno)); if (errno != EISDIR) done = EXIT_ERRORS; continue; } unzzip_cat_file (disk, name, out); if (extract) fclose(out); break; /* match loop */ } } } } zzip_dir_close(disk); return done; }