<commit_before>/*
    main.c:

    Copyright (C) 1991-2002 <NAME>, <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include <ctype.h>
#include "csoundCore.h"         /*                      MAIN.C          */
#include "soundio.h"
#include "csmodule.h"
#include "corfile.h"

#include "csound_orc.h"

#ifdef PARCS
#include "cs_par_base.h"
#include "cs_par_orc_semantics.h"
#include "cs_par_dispatch.h"
#endif

#if defined(USE_OPENMP)
#include <omp.h>
#endif


extern  void    dieu(CSOUND *, char *, ...);
extern  int     argdecode(CSOUND *, int, char **);
extern  int     init_pvsys(CSOUND *);
extern  char    *get_sconame(CSOUND *);
extern  void    print_benchmark_info(CSOUND *, const char *);
extern  void    openMIDIout(CSOUND *);
extern  int     read_unified_file(CSOUND *, char **, char **);
extern  uintptr_t  kperfThread(void * cs);
extern void cs_init_math_constants_macros(CSOUND *csound, PRE_PARM *yyscanner);
extern void cs_init_omacros(CSOUND *csound, PRE_PARM*, NAMES *nn);

PUBLIC int csoundCompile(CSOUND *csound, int argc, char **argv)
{
    OPARMS  *O = csound->oparms;
    char    *s;
    char    *sortedscore = NULL;
    //    char    *xtractedscore = "score.xtr";
    FILE    *xfile = NULL;
    int     n;
    int     csdFound = 0;
    char    *fileDir;

    if ((n = setjmp(csound->exitjmp)) != 0) {
      return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS);
    }

    if (--argc <= 0) {
      dieu(csound, Str("insufficient arguments"));
    }
    /* command line: allow orc/sco/csd name */
    csound->orcname_mode = 0;   /* 0: normal, 1: ignore, 2: fail */
    if (argdecode(csound, argc, argv) == 0)
      csound->LongJmp(csound, 1);
    /* do not allow orc/sco/csd name in .csoundrc */
    csound->orcname_mode = 2;
    {
      const char  *csrcname;
      const char  *home_dir;
      FILE        *csrc = NULL;
      void        *fd = NULL;
      /* IV - Feb 17 2005 */
      csrcname = csoundGetEnv(csound, "CSOUNDRC");
      if (csrcname != NULL && csrcname[0] != '\0') {
        fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, csrcname, "r", NULL,
                               CSFTYPE_OPTIONS, 0);
        if (fd == NULL)
          csoundMessage(csound, Str("WARNING: cannot open csoundrc file %s\n"),
                                csrcname);
        else
          csound->Message(csound, Str("Reading options from $CSOUNDRC: %s \n"),
                           csrcname);
      }
      if (fd == NULL && ((home_dir = csoundGetEnv(csound, "HOME")) != NULL &&
                         home_dir[0] != '\0')) {
        s = csoundConcatenatePaths(csound, home_dir, ".csoundrc");
        fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, s, "r", NULL,
                               CSFTYPE_OPTIONS, 0);
        if (fd != NULL)
          csound->Message(csound, Str("Reading options from $HOME/.csoundrc\n"));
        mfree(csound, s);
      }
      /* read global .csoundrc file (if exists) */
      if (fd != NULL) {

        readOptions(csound, csrc, 0);
        csound->FileClose(csound, fd);
      }
      /* check for .csoundrc in current directory */
      fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, ".csoundrc", "r", NULL,
                             CSFTYPE_OPTIONS, 0);
      if (fd != NULL) {
        readOptions(csound, csrc, 0);
        csound->Message(csound,
                        "Reading options from local directory .csoundrc \n");
        csound->FileClose(csound, fd);
      }
    }
    if (csound->delayederrormessages) {
      if (O->msglevel>8)
        csound->Warning(csound, csound->delayederrormessages);
      free(csound->delayederrormessages);
      csound->delayederrormessages = NULL;
    }
    /* check for CSD file */
    if (csound->orchname == NULL)
      dieu(csound, Str("no orchestra name"));
    else if (csound->scorename == NULL || csound->scorename[0] == (char) 0) {
      int   tmp = (int) strlen(csound->orchname) - 4;
      if (tmp >= 0 && csound->orchname[tmp] == '.' &&
          tolower(csound->orchname[tmp + 1]) == 'c' &&
          tolower(csound->orchname[tmp + 2]) == 's' &&
          tolower(csound->orchname[tmp + 3]) == 'd') {
        /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */
        csound->orcname_mode = 0;
        csound->Message(csound, "UnifiedCSD:  %s\n", csound->orchname);

        /* Add directory of CSD file to search paths before orchname gets
         * replaced with temp orch name if default paths is enabled */
        if (!O->noDefaultPaths) {
          fileDir = csoundGetDirectoryForPath(csound, csound->orchname);
          csoundAppendEnv(csound, "SADIR", fileDir);
          csoundAppendEnv(csound, "SSDIR", fileDir);
          csoundAppendEnv(csound, "INCDIR", fileDir);
          csoundAppendEnv(csound, "MFDIR", fileDir);
          mfree(csound, fileDir);
        }

        csound->csdname = csound->orchname; /* save original CSD name */
        if (!read_unified_file(csound, &(csound->orchname),
                                       &(csound->scorename))) {
          csound->Die(csound, Str("Reading CSD failed ... stopping"));
        }

        csdFound = 1;
      }
    }<commit_msg>avoid the check of the csd extension for a single file<commit_after>/*
    main.c:

    Copyright (C) 1991-2002 <NAME>, <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include <ctype.h>
#include "csoundCore.h"         /*                      MAIN.C          */
#include "soundio.h"
#include "csmodule.h"
#include "corfile.h"

#include "csound_orc.h"

#ifdef PARCS
#include "cs_par_base.h"
#include "cs_par_orc_semantics.h"
#include "cs_par_dispatch.h"
#endif

#if defined(USE_OPENMP)
#include <omp.h>
#endif


extern  void    dieu(CSOUND *, char *, ...);
extern  int     argdecode(CSOUND *, int, char **);
extern  int     init_pvsys(CSOUND *);
extern  char    *get_sconame(CSOUND *);
extern  void    print_benchmark_info(CSOUND *, const char *);
extern  void    openMIDIout(CSOUND *);
extern  int     read_unified_file(CSOUND *, char **, char **);
extern  uintptr_t  kperfThread(void * cs);
extern void cs_init_math_constants_macros(CSOUND *csound, PRE_PARM *yyscanner);
extern void cs_init_omacros(CSOUND *csound, PRE_PARM*, NAMES *nn);

PUBLIC int csoundCompile(CSOUND *csound, int argc, char **argv)
{
    OPARMS  *O = csound->oparms;
    char    *s;
    char    *sortedscore = NULL;
    //    char    *xtractedscore = "score.xtr";
    FILE    *xfile = NULL;
    int     n;
    int     csdFound = 0;
    char    *fileDir;

    if ((n = setjmp(csound->exitjmp)) != 0) {
      return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS);
    }

    if (--argc <= 0) {
      dieu(csound, Str("insufficient arguments"));
    }
    /* command line: allow orc/sco/csd name */
    csound->orcname_mode = 0;   /* 0: normal, 1: ignore, 2: fail */
    if (argdecode(csound, argc, argv) == 0)
      csound->LongJmp(csound, 1);
    /* do not allow orc/sco/csd name in .csoundrc */
    csound->orcname_mode = 2;
    {
      const char  *csrcname;
      const char  *home_dir;
      FILE        *csrc = NULL;
      void        *fd = NULL;
      /* IV - Feb 17 2005 */
      csrcname = csoundGetEnv(csound, "CSOUNDRC");
      if (csrcname != NULL && csrcname[0] != '\0') {
        fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, csrcname, "r", NULL,
                               CSFTYPE_OPTIONS, 0);
        if (fd == NULL)
          csoundMessage(csound, Str("WARNING: cannot open csoundrc file %s\n"),
                                csrcname);
        else
          csound->Message(csound, Str("Reading options from $CSOUNDRC: %s \n"),
                           csrcname);
      }
      if (fd == NULL && ((home_dir = csoundGetEnv(csound, "HOME")) != NULL &&
                         home_dir[0] != '\0')) {
        s = csoundConcatenatePaths(csound, home_dir, ".csoundrc");
        fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, s, "r", NULL,
                               CSFTYPE_OPTIONS, 0);
        if (fd != NULL)
          csound->Message(csound, Str("Reading options from $HOME/.csoundrc\n"));
        mfree(csound, s);
      }
      /* read global .csoundrc file (if exists) */
      if (fd != NULL) {

        readOptions(csound, csrc, 0);
        csound->FileClose(csound, fd);
      }
      /* check for .csoundrc in current directory */
      fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, ".csoundrc", "r", NULL,
                             CSFTYPE_OPTIONS, 0);
      if (fd != NULL) {
        readOptions(csound, csrc, 0);
        csound->Message(csound,
                        "Reading options from local directory .csoundrc \n");
        csound->FileClose(csound, fd);
      }
    }
    if (csound->delayederrormessages) {
      if (O->msglevel>8)
        csound->Warning(csound, csound->delayederrormessages);
      free(csound->delayederrormessages);
      csound->delayederrormessages = NULL;
    }
    /* check for CSD file */
    if (csound->orchname == NULL)
      dieu(csound, Str("no orchestra name"));
    else if ((csound->scorename == NULL || csound->scorename[0] == (char) 0)
             && csound->orchname[0] != '\0') {
      /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */
      csound->orcname_mode = 0;
      csound->Message(csound, "UnifiedCSD:  %s\n", csound->orchname);

      /* Add directory of CSD file to search paths before orchname gets
       * replaced with temp orch name if default paths is enabled */
      if (!O->noDefaultPaths) {
	fileDir = csoundGetDirectoryForPath(csound, csound->orchname);
	csoundAppendEnv(csound, "SADIR", fileDir);
	csoundAppendEnv(csound, "SSDIR", fileDir);
	csoundAppendEnv(csound, "INCDIR", fileDir);
	csoundAppendEnv(csound, "MFDIR", fileDir);
	mfree(csound, fileDir);
      }

      csound->csdname = csound->orchname; /* save original CSD name */
      if (!read_unified_file(csound, &(csound->orchname),
                                       &(csound->scorename))) {
	csound->Die(csound, Str("Reading CSD failed ... stopping"));
      }

      csdFound = 1;
    }
{'fraction_non_alphanumeric': 0.12731541873206365, 'fraction_numerical': 0.010522654143838595, 'mean_word_length': 2.3655253146034534, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 84, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4059319', 'n_tokens_mistral': 3970, 'n_tokens_neox': 3766, 'n_words': 1036}