<commit_before>#if !defined(lint) && !defined(DOS)
static char rcsid[] = "$Id: filesys.c 770 2007-10-24 00:23:09Z <EMAIL> $";
#endif

/*
 * ========================================================================
 * Copyright 2013-2018 <NAME>
 * Copyright 2006-2007 University of Washington
 *
 * 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
 *
 * ========================================================================
 */

/* includable WITHOUT dependency on c-client */
#include "../../c-client/mail.h"
#include "../../c-client/utf8.h"

#ifdef _WINDOWS
/* wingdi.h uses ERROR (!) and we aren't using the c-client ERROR so... */
#undef ERROR
#endif

#include <system.h>
#include <general.h>

#include "../../c-client/fs.h"

/* includable WITHOUT dependency on pico */
#include "../../pico/keydefs.h"
#ifdef _WINDOWS
#include "../../pico/osdep/mswin.h"
#endif

#include "filesys.h"
#include "utf8.h"


#define bad_char ((UCS) '?')


/*
 * Make it easier to use the convert_to_locale function for filenames
 * and directory names. Note, only one at a time because there's only
 * one buffer.
 * This isn't being freed as it stands now.
 */
char *
fname_to_locale(char *fname)
{
    static char *fname_locale_buf = NULL;
    static size_t fname_locale_len = 0;
    char *converted_fname, *p;

    if(fname == NULL){	/* special call to free memory */
      if(fname_locale_buf) fs_give((void **) &fname_locale_buf);
      return NULL;
    }

    p = convert_to_locale(fname);
    if(p)
      converted_fname = p;
    else
      converted_fname = fname;

    if(converted_fname){
	if(strlen(converted_fname)+1 > fname_locale_len){
	    if(fname_locale_buf)
	      fs_give((void **) &fname_locale_buf);

	    fname_locale_len = strlen(converted_fname)+1;
	    fname_locale_buf = (char *) fs_get(fname_locale_len * sizeof(char));
	}

	strncpy(fname_locale_buf, converted_fname, fname_locale_len);
	fname_locale_buf[fname_locale_len-1] = '\0';
    }
    else{
	if(fname_locale_len == 0){
	    fname_locale_len = 1;
	    fname_locale_buf = (char *) fs_get(fname_locale_len * sizeof(char));
	}

	fname_locale_buf[0] = '\0';
    }

    if(p)
      fs_give((void **) &p);

    return(fname_locale_buf);
}


/*
 * Make it easier to use the convert_to_utf8 function for filenames
 * and directory names. Note, only one at a time because there's only
 * one buffer.
 * This isn't being freed as it stands now.
 */
char *
fname_to_utf8(char *fname)
{
    static char *fname_utf8_buf = NULL;
    static size_t fname_utf8_len = 0;
    char *converted_fname, *p;

    if(fname == NULL){	/* special call to free memory */
      if(fname_utf8_buf) fs_give((void **) &fname_utf8_buf);
      return NULL;
    }

    p = convert_to_utf8(fname, NULL, 0);
    if(p)
      converted_fname = p;
    else
      converted_fname = fname;

    if(converted_fname){
	if(strlen(converted_fname)+1 > fname_utf8_len){
	    if(fname_utf8_buf)
	      fs_give((void **) &fname_utf8_buf);

	    fname_utf8_len = strlen(converted_fname)+1;
	    fname_utf8_buf = (char *) fs_get(fname_utf8_len * sizeof(char));
	}

	strncpy(fname_utf8_buf, converted_fname, fname_utf8_len);
	fname_utf8_buf[fname_utf8_len-1] = '\0';
    }
    else{
	if(fname_utf8_len == 0){<commit_msg>   * Crashing bug when suspending Alpine and attempting to return to      Alpine from a subshell. Reported by <NAME>.<commit_after>#if !defined(lint) && !defined(DOS)
static char rcsid[] = "$Id: filesys.c 770 2007-10-24 00:23:09Z <EMAIL> $";
#endif

/*
 * ========================================================================
 * Copyright 2013-2018 <NAME>
 * Copyright 2006-2007 University of Washington
 *
 * 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
 *
 * ========================================================================
 */

/* includable WITHOUT dependency on c-client */
#include "../../c-client/mail.h"
#include "../../c-client/utf8.h"

#ifdef _WINDOWS
/* wingdi.h uses ERROR (!) and we aren't using the c-client ERROR so... */
#undef ERROR
#endif

#include <system.h>
#include <general.h>

#include "../../c-client/fs.h"

/* includable WITHOUT dependency on pico */
#include "../../pico/keydefs.h"
#ifdef _WINDOWS
#include "../../pico/osdep/mswin.h"
#endif

#include "filesys.h"
#include "utf8.h"


#define bad_char ((UCS) '?')


/*
 * Make it easier to use the convert_to_locale function for filenames
 * and directory names. Note, only one at a time because there's only
 * one buffer.
 * This isn't being freed as it stands now.
 */
char *
fname_to_locale(char *fname)
{
    static char *fname_locale_buf = NULL;
    static size_t fname_locale_len = 0;
    char *converted_fname, *p;

    if(fname == NULL){	/* special call to free memory */
      if(fname_locale_buf) fs_give((void **) &fname_locale_buf);
      fname_locale_len = 0;
      return NULL;
    }

    p = convert_to_locale(fname);
    if(p)
      converted_fname = p;
    else
      converted_fname = fname;

    if(converted_fname){
	if(strlen(converted_fname)+1 > fname_locale_len){
	    if(fname_locale_buf)
	      fs_give((void **) &fname_locale_buf);

	    fname_locale_len = strlen(converted_fname)+1;
	    fname_locale_buf = (char *) fs_get(fname_locale_len * sizeof(char));
	}

	strncpy(fname_locale_buf, converted_fname, fname_locale_len);
	fname_locale_buf[fname_locale_len-1] = '\0';
    }
    else{
	if(fname_locale_len == 0){
	    fname_locale_len = 1;
	    fname_locale_buf = (char *) fs_get(fname_locale_len * sizeof(char));
	}

	fname_locale_buf[0] = '\0';
    }

    if(p)
      fs_give((void **) &p);

    return(fname_locale_buf);
}


/*
 * Make it easier to use the convert_to_utf8 function for filenames
 * and directory names. Note, only one at a time because there's only
 * one buffer.
 * This isn't being freed as it stands now.
 */
char *
fname_to_utf8(char *fname)
{
    static char *fname_utf8_buf = NULL;
    static size_t fname_utf8_len = 0;
    char *converted_fname, *p;

    if(fname == NULL){	/* special call to free memory */
      if(fname_utf8_buf) fs_give((void **) &fname_utf8_buf);
      fname_utf8_len = 0;
      return NULL;
    }

    p = convert_to_utf8(fname, NULL, 0);
    if(p)
      converted_fname = p;
    else
      converted_fname = fname;

    if(converted_fname){
	if(strlen(converted_fname)+1 > fname_utf8_len){
	    if(fname_utf8_buf)
	      fs_give((void **) &fname_utf8_buf);

	    fname_utf8_len = strlen(converted_fname)+1;
	    fname_utf8_buf = (char *) fs_get(fname_utf8_len * sizeof(char));
	}

	strncpy(fname_utf8_buf, converted_fname, fname_utf8_len);
	fname_utf8_buf[fname_utf8_len-1] = '\0';
    }
    else{
	if(fname_utf8_len == 0){
{'fraction_non_alphanumeric': 0.1691008018327606, 'fraction_numerical': 0.021334478808705613, 'mean_word_length': 3.5416124837451237, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, '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': '1424691', 'n_tokens_mistral': 2658, 'n_tokens_neox': 2517, 'n_words': 596}