<commit_before>/*=============================================================================

Copyright 2008 <NAME> (<EMAIL>)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
=============================================================================*/

#include <apr.h>
#include <apr_getopt.h>

#if APR_HAVE_STDLIB_H
#include <stdlib.h>
#endif

#if APR_HAVE_STRING_H
#include <string.h>
#endif

#include "../util/util.h"
#include "options.h"
#include "managelogs.h"
#include "id.h"

/*----------------------------------------------*/

#define KILO	1024
#define MEGA	(KILO*KILO)
#define GIGA	(MEGA*KILO)

/*----------------------------------------------*/

static apr_getopt_t *opt_s;
static apr_getopt_option_t long_options[]=
	{
	{"help",'h',0 },
	{"debug-file",'d',1 },
	{"verbose",'v',0 },
	{"compress",'c',1 },
	{"size",'s',1 },
	{"global-size",'S',1 },
	{"mode",'m',1 },
	{"user",'u',1 },
	{"keep",'k',1 },
	{"version",'V',0 },
	{"link",'l',0 },
	{"backup-links",'L',0 },
	{"hardlink",'H',0 },
	{"ignore-eol",'e',0 },
	{"time",'t',1 },
	{"stats",'I',0 },
	{"refresh-only",'R',0 },
	{"rotate-cmd",'C',1 },
	{"rotate-delay",'r',1 },
	{"purge-delay",'p',1 },
	{"enospc-abort",'x',0 },
	{"",'\0', 0 }
	};

/*----------------------------------------------*/

static apr_off_t convert_size_string(const char *str);
static TIMESTAMP convert_delay(const char *str);
static void usage(int rc);

/*----------------------------------------------*/

static void usage(int rc)
{
FILE *fd;
char *clist;

fd=((rc>0) ? stderr : stdout);
clist=logmanager_compression_list();

fprintf(fd,MANAGELOGS_BANNER "\n\
Usage: managelogs [options...] <base-path1> [[options...] <base-path2> ...] \n");

fprintf(fd,"\
\n\
*---- Global options (these options apply to the whole process) :\n\
\n\
 -h|--help           Display this message\n\
\n\
 -u|--user <id>      Program runs with this user ID\n\
                       <id> = <uid>[:<gid>]\n\
                       <uid> and <gid> are user/group names or numeric ids\n\
\n\
 -V|--version        Print version banner and exit\n\
\n\
 -I|--stats          Display internal stats before exiting (for\n\
                     troubleshooting, debugging, and performance tests)\n\
\n\
 -R|--refresh-only   Just refresh/purge files, then exit\n\
\n\
*---- per-manager options (these options apply to the next <base-path> only) :\n\
\n\
 -v|--verbose        Increment debug level\n\
\n\
 -d|--debug <path>   Write debug messages to <path>\n\
                       <path> can be a file path, 'stdout', or 'stderr'.\n\
                       Default: stderr\n\
\n");

if (clist[0]) /* If at least one compression scheme is supported */
	{
	fprintf(fd,"\
 -c|--compress <comp>[:<level>]  Activate compression and appends the\n\
                     corresponding suffix to the log file names.\n\
                       <comp> must be one of : %s\n\
                       <level> is one of [123456789bf] (f=fast, b=best)\n\
                       Default level: best\n\
\n",clist);
	}

fprintf(fd,"\
 -s|--size <size>    Set the maximum file size at which rotation occurs\n\
                       <size> is a numeric value optionnally followed\n\
                       by 'K' (Kilo), 'M' (Mega), or 'G' (Giga).\n\
                       Default: no limit\n\
\n\
 -r|--rotate-delay <delay>  Set the maximum delay between the creation of a new\n\
                       log file and the next rotation.\n\
                         <delay> is a suite of patterns in the form\n\
                         '[0-9]+[dhm]' (d=days, h=hours, m=minutes)\n\
                         Example : 1d12h = 1 day and 12 hours (same as '36h')\n\
 \n\
 -p|--purge-delay <delay>  Remove backup log files older than <delay>\n\
                         Argument: same format as for '--rotate-delay'\n\
\n\
 -S|--global-size <size>  Set the maximum size the whole set of log files can\n\
                     take on disk (active log + backups).\n\
                       Argument: same as for '--size'\n\
\n\
 -m|--mode <mode>    Permissions to set when creating a new log file\n\
                       <mode> is an octal Unix-style file permission\n\
                       (see man chmod(2) for more). Default mode: %x\n\
\n\
 -k|--keep <n>       Only keep <n> log files (the active one + <n-1>\n\
                     backups)\n\
\n\
 -l|--link           Maintain a link to the active log file\n\
\n\
 -L|--backup-links   Maintain links to the active and backup log files\n\
\n\
 -H|--hardlink       Create hard links instead of symbolic links\n\
\n\
 -e|--ignore-eol     Disables the internal mechanism ensuring that log files\n\
                     are rotated on line boundaries\n\
\n\
 -C|--rotate-cmd <cmd>    Execute <cmd> on every rotation\n\
\n\
 -x|--enospc-abort   Abort on 'no more space' write error (default: ignore)\n\
\n",LOGFILE_MODE);

(void)allocate(clist,0);

if (rc >= 0) exit_proc(rc);
}

/*----------------------------------------------*/
/*-- Get options from command line */

LOGMANAGER_OPTIONS **get_options(int argc, char **argv, int *countp)
{
apr_status_t status;
LOGMANAGER_OPTIONS **opp, *op;
int optch;
const char *opt_arg;
DECLARE_TPOOL

opp=(LOGMANAGER_OPTIONS **)0;
(*countp)=0;<commit_msg>Shring '-h' message to a more compact format<commit_after>/*=============================================================================

Copyright 2008 <NAME> (<EMAIL>)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
=============================================================================*/

#include <apr.h>
#include <apr_getopt.h>

#if APR_HAVE_STDLIB_H
#include <stdlib.h>
#endif

#if APR_HAVE_STRING_H
#include <string.h>
#endif

#include "../util/util.h"
#include "options.h"
#include "managelogs.h"
#include "id.h"

/*----------------------------------------------*/

#define KILO	1024
#define MEGA	(KILO*KILO)
#define GIGA	(MEGA*KILO)

/*----------------------------------------------*/

static apr_getopt_t *opt_s;
static apr_getopt_option_t long_options[]=
	{
	{"help",'h',0 },
	{"debug-file",'d',1 },
	{"verbose",'v',0 },
	{"compress",'c',1 },
	{"size",'s',1 },
	{"global-size",'S',1 },
	{"mode",'m',1 },
	{"user",'u',1 },
	{"keep",'k',1 },
	{"version",'V',0 },
	{"link",'l',0 },
	{"backup-links",'L',0 },
	{"hardlink",'H',0 },
	{"ignore-eol",'e',0 },
	{"time",'t',1 },
	{"stats",'I',0 },
	{"refresh-only",'R',0 },
	{"rotate-cmd",'C',1 },
	{"rotate-delay",'r',1 },
	{"purge-delay",'p',1 },
	{"enospc-abort",'x',0 },
	{"",'\0', 0 }
	};

/*----------------------------------------------*/

static apr_off_t convert_size_string(const char *str);
static TIMESTAMP convert_delay(const char *str);
static void usage(int rc);

/*----------------------------------------------*/

static void usage(int rc)
{
FILE *fd;
char *clist;

fd=((rc>0) ? stderr : stdout);
clist=logmanager_compression_list();

fprintf(fd,MANAGELOGS_BANNER "\n\
Usage: managelogs [options...] <base-path1> [[options...] <base-path2> ...] \n");

fprintf(fd,"\n\
*---- Global options (these options apply to the whole process) :\n\
\n\
 -h|--help                 Display this message\n\
 -u|--user <id>            Program runs with this user ID\n\
 -V|--version              Print version banner and exit\n\
 -I|--stats                Display internal stats before exiting \n\
 -R|--refresh-only         Just refresh/purge files, then exit\n\
\n\
*---- per-manager options (these options apply to the next <base-path> only) :\n\
\n\
 -v|--verbose              Increment debug level\n\
 -d|--debug <path>         Write debug messages to <path>\n");

if (clist[0]) /* If at least one compression scheme is supported */
	{
	fprintf(fd,"\
 -c|--compress <cp>[:lvl]  Activate compression\n",clist);
	}

fprintf(fd,"\
 -s|--size <size>          Set the file size limit\n\
 -r|--rotate-delay <delay> Set the rotation delay\n\
 -p|--purge-delay <delay>  Set the purge delay\n\
 -S|--global-size <size>   Set the global size limit\n\
 -m|--mode <mode>          Permissions to set when creating a log file\n\
 -k|--keep <n>             Only keep <n> log files\n\
 -l|--link                 Maintain a link to the active log file\n\
 -L|--backup-links         Also maintain links to backup log files\n\
 -H|--hardlink             Create hard links instead of symbolic links\n\
 -e|--ignore-eol           Disables the eol buffering mechanism\n\
 -C|--rotate-cmd <cmd>     Execute <cmd> on every rotation\n\
 -x|--enospc-abort         Abort on 'no more space' write error\n\
\n",LOGFILE_MODE);

(void)allocate(clist,0);

if (rc >= 0) exit_proc(rc);
}

/*----------------------------------------------*/
/*-- Get options from command line */

LOGMANAGER_OPTIONS **get_options(int argc, char **argv, int *countp)
{
apr_status_t status;
LOGMANAGER_OPTIONS **opp, *op;
int optch;
const char *opt_arg;
DECLARE_TPOOL

opp=(LOGMANAGER_OPTIONS **)0;
(*countp)=0;
{'fraction_non_alphanumeric': 0.2324307879525403, 'fraction_numerical': 0.010850826488185783, 'mean_word_length': 2.2807717897538256, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3545854', 'n_tokens_mistral': 3336, 'n_tokens_neox': 3239, 'n_words': 958}