<commit_before>/*
 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
 * See the copyright notice in the ACK home directory, in the file "Copyright".
 *
 */

/**********************************************************************/
/*                                                                    */
/*               Several utility routines used throughout ack         */
/*               error handling, string handling and such.            */
/*                                                                    */
/**********************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "ack.h"

#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif

extern  char    *progname ;
extern  int     w_flag ;
extern  int     n_error;

#ifdef DEBUG
# define STDOUT stdout
#else
# define STDOUT stderr
#endif

char *basename(string) char *string ; {
	static char retval[256] ;
	char *last_dot, *last_start ;
	register char *store;
	register char *fetch ;
	register int ctoken ;

	last_dot= (char *)0 ;
	last_start= string ;
	for ( fetch=string ; ; fetch++ ) {
		switch ( ctoken= *fetch&0377 ) {
		case SUFCHAR : last_dot=fetch ; break ;
		case '/'     : last_start=fetch+1 ; break ;
		case  0      : goto out ;
		}
		if ( !isascii(ctoken) || !isprint(ctoken) ) {
			werror("non-ascii characters in argument %s",string) ;
		}
	}
out:
	if ( ! *last_start ) fuerror("empty filename \"%s\"",string) ;
	for ( fetch= last_start, store=retval ;
		*fetch && fetch!=last_dot && store< &retval[sizeof retval-1] ;
		      fetch++, store++ ) {
				*store= *fetch ;
	}
	*store= 0 ;
	return retval ;
}

clr_noscan(str) char *str ; {
	register char *ptr ;
	for ( ptr=str ; *ptr ; ptr++ ) {
		*ptr&= ~NO_SCAN ;
	}
}

char *skipblank(str) char *str ; {
	register char *ptr ;

	for ( ptr=str ; *ptr==SPACE || *ptr==TAB ; ptr++ ) ;
	return ptr ;
}

char *firstblank(str) char *str ; {
	register char *ptr ;

	for ( ptr=str ; *ptr && *ptr!=SPACE && *ptr!=TAB ; ptr++ ) ;
	return ptr ;
}

/* VARARGS1 */
void fatal(const char* fmt, ...)
{
	/* Fatal internal error */
	va_list ap;
	va_start(ap, fmt);
	fprintf(STDOUT,"%s: fatal internal error, ",progname) ;
	vfprintf(STDOUT, fmt, ap);
	fprintf(STDOUT,"\n") ;
	quit(-2) ;
}


/* VARARGS1 */
void vprint(const char* fmt, ...)
{
	/* Diagnostic print, no auto NL */
	va_list ap;
	va_start(ap, fmt);
	vfprintf(STDOUT, fmt, ap);
	va_end(ap);
}

#ifdef DEBUG
prns(s) register char *s ; {
	for ( ; *s ; s++ ) {
		putc((*s&0377)&~NO_SCAN,STDOUT) ;
	}
	putc('\n',STDOUT) ;
}
#endif

/* VARARGS1 */
fuerror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
	/* Fatal user error */
	fprintf(STDOUT,"%s: ",progname) ;
	fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
	fprintf(STDOUT,"\n") ;
	quit(-1) ;
}

/* VARARGS1 */
werror(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
	/* Warning user error, w_flag */
	if ( w_flag ) return ;
	fprintf(STDOUT,"%s: warning, ",progname) ;
	fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
	fprintf(STDOUT,"\n") ;
}

/* VARARGS1 */
error(fmt,p1,p2,p3,p4,p5,p6,p7) char *fmt ; {
	/* User error, it is the callers responsibility to quit */
	fprintf(STDOUT,"%s: ",progname) ;
	fprintf(STDOUT,fmt,p1,p2,p3,p4,p5,p6,p7);
	fprintf(STDOUT,"\n") ;
	n_error++ ;
}

do_flush() {
	fflush(stdout) ;
	fflush(stderr) ;
}

void
noodstop() {
	quit(-3) ;
}

quit(code) {
	rmtemps();
	exit(code);
}
/******
	char *keeps(string)<commit_msg>Fix more functions in util/ack for 64-bit hosts.<commit_after>/*
 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
 * See the copyright notice in the ACK home directory, in the file "Copyright".
 *
 */

/**********************************************************************/
/*                                                                    */
/*               Several utility routines used throughout ack         */
/*               error handling, string handling and such.            */
/*                                                                    */
/**********************************************************************/

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "ack.h"

#ifndef NORCSID
static char rcs_id[] = "$Id$" ;
#endif

extern  char    *progname ;
extern  int     w_flag ;
extern  int     n_error;

#ifdef DEBUG
# define STDOUT stdout
#else
# define STDOUT stderr
#endif

char *basename(string) char *string ; {
	static char retval[256] ;
	char *last_dot, *last_start ;
	register char *store;
	register char *fetch ;
	register int ctoken ;

	last_dot= (char *)0 ;
	last_start= string ;
	for ( fetch=string ; ; fetch++ ) {
		switch ( ctoken= *fetch&0377 ) {
		case SUFCHAR : last_dot=fetch ; break ;
		case '/'     : last_start=fetch+1 ; break ;
		case  0      : goto out ;
		}
		if ( !isascii(ctoken) || !isprint(ctoken) ) {
			werror("non-ascii characters in argument %s",string) ;
		}
	}
out:
	if ( ! *last_start ) fuerror("empty filename \"%s\"",string) ;
	for ( fetch= last_start, store=retval ;
		*fetch && fetch!=last_dot && store< &retval[sizeof retval-1] ;
		      fetch++, store++ ) {
				*store= *fetch ;
	}
	*store= 0 ;
	return retval ;
}

clr_noscan(str) char *str ; {
	register char *ptr ;
	for ( ptr=str ; *ptr ; ptr++ ) {
		*ptr&= ~NO_SCAN ;
	}
}

char *skipblank(str) char *str ; {
	register char *ptr ;

	for ( ptr=str ; *ptr==SPACE || *ptr==TAB ; ptr++ ) ;
	return ptr ;
}

char *firstblank(str) char *str ; {
	register char *ptr ;

	for ( ptr=str ; *ptr && *ptr!=SPACE && *ptr!=TAB ; ptr++ ) ;
	return ptr ;
}

/* VARARGS1 */
void fatal(const char* fmt, ...)
{
	/* Fatal internal error */
	va_list ap;
	va_start(ap, fmt);
	fprintf(STDOUT,"%s: fatal internal error, ",progname) ;
	vfprintf(STDOUT, fmt, ap);
	fprintf(STDOUT,"\n") ;
	quit(-2) ;
}


/* VARARGS1 */
void vprint(const char* fmt, ...)
{
	/* Diagnostic print, no auto NL */
	va_list ap;
	va_start(ap, fmt);
	vfprintf(STDOUT, fmt, ap);
	va_end(ap);
}

#ifdef DEBUG
prns(s) register char *s ; {
	for ( ; *s ; s++ ) {
		putc((*s&0377)&~NO_SCAN,STDOUT) ;
	}
	putc('\n',STDOUT) ;
}
#endif

/* VARARGS1 */
void fuerror(const char *fmt, ...) {
	/* Fatal user error */
	va_list ap;
	va_start(ap, fmt);
	fprintf(STDOUT,"%s: ",progname) ;
	vfprintf(STDOUT, fmt, ap);
	fprintf(STDOUT,"\n") ;
	quit(-1) ;
}

/* VARARGS1 */
void werror(const char *fmt, ...) {
	/* Warning user error, w_flag */
	va_list ap;
	if ( w_flag ) return ;
	va_start(ap, fmt);
	fprintf(STDOUT,"%s: warning, ",progname) ;
	vfprintf(STDOUT, fmt, ap);
	fprintf(STDOUT,"\n") ;
	va_end(ap);
}

/* VARARGS1 */
void error(const char *fmt, ...) {
	/* User error, it is the callers responsibility to quit */
	va_list ap;
	va_start(ap, fmt);
	fprintf(STDOUT,"%s: ",progname) ;
	vfprintf(STDOUT, fmt, ap);
	fprintf(STDOUT,"\n") ;
	n_error++ ;
	va_end(ap);
}

do_flush() {
	fflush(stdout) ;
	fflush(stderr) ;
}

void
noodstop() {
	quit(-3) ;
}

quit(code) {
	rmtemps();
	exit(code);
}
/******
	char *keeps(string)
{'fraction_non_alphanumeric': 0.20817949446180062, 'fraction_numerical': 0.014200511218403862, 'mean_word_length': 2.994895065229722, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3691979', 'n_tokens_mistral': 2776, 'n_tokens_neox': 2650, 'n_words': 621}