コード例 #1
0
ファイル: env.c プロジェクト: ErisBlastar/osfree
static int SetFromFile( char *szLine, char *pchList, int fRemove )
{
    char *arg;
    char szBuffer[CMDBUFSIZ];
    int i, n, rval = 0;

    for ( i = 0; (( rval == 0 ) && (( arg = ntharg( szLine, i )) != NULL )); i++ ) {

        mkfname( arg, 0 );

        if (( gnGFH = _sopen( arg, (O_RDONLY | O_BINARY), SH_DENYWR )) < 0 )
            return ( error( _doserrno, arg ));

        for ( arg = szBuffer; (( rval == 0 ) && ( getline( gnGFH, arg, CMDBUFSIZ-((arg-szBuffer)+1), EDIT_DATA ) > 0 )); ) {

            // remove leading white space
            strip_leading( arg, WHITESPACE );

            // if last char is escape character, append
            //   the next line
            n = strlen( arg ) - 1;
            if (( arg[0] ) && ( arg[n] == gpIniptr->EscChr )) {
                arg += n;
                continue;
            }

            // skip blank lines & comments
            arg = szBuffer;
            if (( *arg ) && ( *arg != ':' )) {

                if ( fRemove ) {
                    // delete variable
                    for ( n = 0; (( szBuffer[n] ) && ( szBuffer[n++] != '=' )); )
                        ;
                    szBuffer[n] = '\0';
                }

                // create/modify a variable or alias
                rval = add_list( arg, pchList );
            }
        }

        gnGFH = _close( gnGFH );
    }

    return rval;
}
コード例 #2
0
ファイル: audiorip.cpp プロジェクト: leloulight/maestro
// create a directory in current working directory or at specified path
int createDir()
{
 int i = 0;
 int error = 0;
 char xdir[FNBUFSIZE] = {'\0'};	//extraction path and dir
 
 if(strlen(out_path) == 0)
   strcat(out_path, "./");
 else {
   char c = out_path[ strlen(out_path) - 1];
   if( c != '/'  &&  c != '\\' )  //make sure string ends with slash
     strcat(out_path, "/");
 }
 strcat(out_path, "AUDIORIP_");
 
 do
 {
   mkfname(i, 3, xdir, out_path, xdir_suffix);
   error = MKDIR(xdir);
   if(((error != 0) && (errno != EEXIST)) || (i > 999)) {
       cout << "Can't create extraction dir: \"" << xdir << "\""<< endl;;
       switch(errno) {
         case(EACCES) : cout << "Write permission is denied for the parent directory in which the new directory is to be added."; break;
         case(EMLINK) : cout << "The parent directory has too many links (entries)."; break;
         case(ENAMETOOLONG) : cout << "Path or name to long."; break;
         case(ENOENT) : cout << "A component of the path prefix does not name an existing directory."; break;
         case(ENOSPC) : cout << "The file system doesn't have enough room to create the new directory."; break;
         case(EROFS)  : cout << "The parent directory of the directory being created is on a read-only file system and cannot be modified."; break;
         default      : cout << strerror(errno); break;
       }
       cout << endl;
       return -1;
   }
   i++;
 } while(error!=0);

 strcat(xdir,"/");
 strcpy(out_path, xdir);
 return 0;
}
コード例 #3
0
ファイル: log.c プロジェクト: dpalic/openemm
/** Write to logfile.
 * Primary interface to write to logfile using printf like format
 * and varargs parameter passing
 * @param l the logger
 * @param level the loglevel of this message
 * @param mask loglevel mask
 * @param what identification for what the entry is
 * @param fmt printf like format
 * @param par format parameter
 * @return true if successful, false otherwise
 */
bool_t
log_vmout (log_t *l, int level, logmask_t mask, const char *what, const char *fmt, va_list par) /*{{{*/
{
	bool_t	st;
	
	if ((level <= l -> level) && LM_MATCH (mask, l -> use)) {
		time_t		now;
		struct tm	*tt;
		long		spos, epos;
		byte_t		*scratch;
		
		st = false;
		time (& now);
		if (((! log_suspend (l, LS_LOGFILE)) && mkfname (l, now)) ||
		    ((! log_suspend (l, LS_FILEDESC)) && (l -> logfd != -1)) ||
		    ((! log_suspend (l, LS_SYSLOG)) && l -> slactive && (l -> slprio != -1)) ||
		    ((! log_suspend (l, LS_COLLECT)) && l -> collect)) {
			if ((l -> obuf || (l -> obuf = buffer_alloc (512))) &&
			    (tt = localtime (& now))) {
				buffer_clear (l -> obuf);
				if (buffer_format (l -> obuf, "[%02d.%02d.%04d  %02d:%02d:%02d] %d ",
						   tt -> tm_mday, tt -> tm_mon + 1, tt -> tm_year + 1900,
						   tt -> tm_hour, tt -> tm_min, tt -> tm_sec, (int) getpid ()) &&
				    (((level >= 0) && (level < sizeof (logtab) / sizeof (logtab[0]))) ?
				     buffer_appends (l -> obuf, logtab[level].name) :
				     buffer_format (l -> obuf, "(%d)", level)) &&
				    (what ? buffer_format (l -> obuf, "/%s: ", what) : buffer_appends (l -> obuf, ": "))) {
					spos = l -> obuf -> length;
					if (buffer_vformat (l -> obuf, fmt, par)) {
						epos = l -> obuf -> length;
						if (buffer_appendch (l -> obuf, '\n')) {
							st = true;
							if ((! log_suspend (l, LS_LOGFILE)) && l -> lfp)
								if ((fwrite (l -> obuf -> buffer, sizeof (byte_t), l -> obuf -> length, l -> lfp) != l -> obuf -> length) ||
								    (fflush (l -> lfp) != EOF)) {
									fclose (l -> lfp);
									l -> lfp = NULL;
									st = false;
								}
							if ((! log_suspend (l, LS_FILEDESC)) && (l -> logfd != -1) && (spos < epos))
								if ((write (l -> logfd, l -> obuf -> buffer + spos, epos - spos) != epos - spos) ||
								    (write (l -> logfd, "\n", 1) != 1)) {
									/* no closing required, as passed from caller! */
									l -> logfd = -1;
									st = false;
								}
							if ((! log_suspend (l, LS_SYSLOG)) && l -> slactive && (l -> slprio != -1) && (spos < epos) &&
							    (scratch = buffer_cut (l -> obuf, spos, epos - spos, NULL))) {
								syslog (l -> slprio, "%s", scratch);
								free (scratch);
							}
							if ((! log_suspend (l, LS_COLLECT)) && (level <= l -> clevel) && l -> collect)
								buffer_appendbuf (l -> collect, l -> obuf);
						}
					}
				}
			}
		}
	} else
		st = true;
	return st;
}/*}}}*/
コード例 #4
0
ファイル: chain.C プロジェクト: ptkila/cowichan
int
main(
  int		argc,			/* arg count */
  char	      * argv[]			/* arg vector */
){
  static char * context = "main(chain)";
  char	      * stem = NULL;		/* dump filename stem */
  char	      * suffix = NULL;		/* dump filename suffix */
  char	      * suff2 = NULL;		/* last half of suffix */
  int		nr, nc;			/* integer matrix sizes */
  int		n;			/* square matrix/vector size */
  real		base_x, base_y;		/* base of Mandelbrot */
  real		ext_x, ext_y;		/* extent of Mandelbrot */
  int		limit, seed;		/* randmat controls */
  real		fraction;		/* invperc/thresh filling */
  int		itersLife;		/* life iterations */
  int		itersElastic, relax;	/* elastic controls */
  int2D		i2D;			/* integer matrix */
  bool2D	b2D;			/* boolean matrix */
  pt1D		cities;			/* cities point vector */
  int		n_cities;		/* number of cities */
  pt1D		net;			/* net point vector */
  int		n_net;			/* number of net points */
  real2D	r2D_gauss;		/* real matrix for Gaussian */
  real2D	r2D_sor;		/* real matrix for SOR */
  real1D	r1D_gauss_v;		/* real vector input for Gaussian */
  real1D	r1D_sor_v;		/* real vector input for SOR */
  real1D	r1D_gauss_a;		/* real vector answer for Gaussian */
  real1D	r1D_sor_a;		/* real vector answer for SOR */
  real1D	r1D_gauss_c;		/* real vector check for Gaussian */
  real1D	r1D_sor_c;		/* real vector check for SOR */
  real		tol;			/* SOR tolerance */
  real		realDiff;		/* vector difference */
  bool		choicesSet = FALSE;	/* path choices set? */
  bool		doMandel = TRUE;	/* mandel vs. randmat */
  bool		doInvperc = TRUE;	/* invperc vs. thresholding */
  bool		doDump = FALSE;		/* dump intermediate results? */
  int		argd = 1;		/* argument index */

  /* arguments */
#if NUMA
  MAIN_INITENV(,32000000)
#endif
  while (argd < argc){
    CHECK(argv[argd][0] == '-',
	  fail(context, "bad argument", "index", "%d", argd, NULL));
    switch(argv[argd][1]){
     case 'E' :				/* elastic */
      itersElastic = arg_int(context, argc, argv, argd+1, argv[argd]);
      relax = arg_int(context, argc, argv, argd+2, argv[argd]);
      argd += 3;
      break;
     case 'F' :				/* fraction (invperc/thresh) */
      fraction = arg_real(context, argc, argv, argd+1, argv[argd]);
      argd += 2;
      break;
     case 'L' :				/* life */
      itersLife = arg_int(context, argc, argv, argd+1, argv[argd]);
      argd += 2;
      break;
     case 'M' :				/* mandel */
      base_x = arg_real(context, argc, argv, argd+1, argv[argd]);
      base_y = arg_real(context, argc, argv, argd+2, argv[argd]);
      ext_x  = arg_real(context, argc, argv, argd+3, argv[argd]);
      ext_y  = arg_real(context, argc, argv, argd+4, argv[argd]);
      argd += 5;
      break;
     case 'N' :				/* winnow */
      n_cities = arg_int(context, argc, argv, argd+1, argv[argd]);
      argd += 2;
      break;
     case 'R' :				/* randmat */
      limit = arg_int(context, argc, argv, argd+1, argv[argd]);
      seed  = arg_int(context, argc, argv, argd+2, argv[argd]);
      argd += 3;
      break;
     case 'S' :				/* matrix size */
      nr = arg_int(context, argc, argv, argd+1, argv[argd]);
      nc = arg_int(context, argc, argv, argd+2, argv[argd]);
      argd += 3;
      break;
     case 'T' :				/* SOR tolerance */
      tol = arg_real(context, argc, argv, argd+1, argv[argd]);
      argd += 2;
      break;
     case 'c' :				/* choice */
      CHECK(!choicesSet,
	    fail(context, "choices already set", NULL));
      suffix = arg_str(context, argc, argv, argd+1, argv[argd]);
      argd += 2;
      switch(suffix[0]){
       case 'i' :	doInvperc = TRUE;	break;
       case 't' :	doInvperc = FALSE;	break;
       default :
	fail(context, "unknown choice(s)", "choice", "%s", suffix, NULL);
      }
      switch(suffix[1]){
       case 'm' :	doMandel = TRUE;	break;
       case 'r' :	doMandel = FALSE;	break;
       default :
	fail(context, "unknown choice(s)", "choice", "%s", suffix, NULL);
      }
      suff2 = suffix+1;
      choicesSet = TRUE;
      break;
     case 'd' :				/* dump */
      doDump = TRUE;
      argd += 1;
      if ((argd < argc) && (argv[argd][0] != '-')){
        stem = arg_str(context, argc, argv, argd, argv[argd-1]);
        argd += 1;
      }
      break;
#if GRAPHICS
     case 'g' :
      gfx_open(app_chain, arg_gfxCtrl(context, argc, argv, argd+1, argv[argd]));
      argd += 2;
      break;
#endif
#if MIMD
     case 'p' :
      DataDist = arg_dataDist(context, argc, argv, argd+1, argv[argd]);
      ParWidth = arg_int(context, argc, argv, argd+2, argv[argd]);
      argd += 3;
      break;
#endif
     case 'u' :
      io_init(FALSE);
      argd += 1;
      break;
     default :
      fail(context, "unknown flag", "flag", "%s", argv[argd], NULL);
      break;
    }
  }
  CHECK(choicesSet,
	fail("context", "choices not set using -c flag", NULL));

  /* initialize */
#if MIMD
  sch_init(DataDist);
#endif

  /* mandel vs. randmat */
  if (doMandel){
    mandel(i2D, nr, nc, base_x, base_y, ext_x, ext_y);
    if (doDump) io_wrInt2D(context, mkfname(stem, NULL, suff2, "i2"), i2D, nr, nc);
  } else {
    randmat(i2D, nr, nc, limit, seed);
    if (doDump) io_wrInt2D(context, mkfname(stem, NULL, suff2, "i2"), i2D, nr, nc);
  }

  /* half */
  half(i2D, nr, nc);
  if (doDump) io_wrInt2D(context, mkfname(stem, "h", suff2, "i2"), i2D, nr, nc);

  /* invperc vs. thresh */
  if (doInvperc){
    invperc(i2D, b2D, nr, nc, fraction);
    if (doDump) io_wrBool2D(context, mkfname(stem, NULL, suffix, "b2"), b2D, nr, nc);
  } else {
    thresh(i2D, b2D, nr, nc, fraction);
    if (doDump) io_wrBool2D(context, mkfname(stem, NULL, suffix, "b2"), b2D, nr, nc);
  }

  /* life */
  life(b2D, nr, nc, itersLife);
  if (doDump) io_wrBool2D(context, mkfname(stem, "l", suffix, "b2"), b2D, nr, nc);

  /* winnow */
  winnow(i2D, b2D, nr, nc, cities, n_cities);
  if (doDump) io_wrPt1D(context, mkfname(stem, "w", suffix, "p1"), cities, n_cities);

  /* norm */
  norm(cities, n_cities);
  if (doDump) io_wrPt1D(context, mkfname(stem, "n", suffix, "p1"), cities, n_cities);

  /* elastic */
  n_net = (int)(ELASTIC_RATIO * n_cities);
  CHECK(n_net <= MAXEXT,
	fail(context, "too many net points required",
	     "number of net points", "%d", n_net, NULL));
  elastic(cities, n_cities, net, n_net, itersElastic, relax);
  if (doDump) io_wrPt1D(context, mkfname(stem, "e", suffix, "p1"), net, n_net);

  /* outer */
  n = n_net;
  outer(net, r2D_gauss, r1D_gauss_v, n);
  if (doDump){
    io_wrReal2D(context, mkfname(stem, "o", suffix, "r2"), r2D_gauss, n, n);
    io_wrReal1D(context, mkfname(stem, "o", suffix, "r1"), r1D_gauss_v, n);
  }

  cpReal2D(r2D_gauss, r2D_sor, n, n);
  cpReal1D(r1D_gauss_v, r1D_sor_v, n);

  /* gauss */
  gauss(r2D_gauss, r1D_gauss_v, r1D_gauss_a, n);
  if (doDump) io_wrReal1D(context, mkfname(stem, "g", suffix, "r1"), r1D_gauss_a, n);

  /* product (gauss) */
  product(r2D_gauss, r1D_gauss_a, r1D_gauss_c, n, n);
  if (doDump) io_wrReal1D(context, mkfname(stem, "pg", suffix, "r1"), r1D_gauss_c, n);

  /* sor */
  sor(r2D_sor, r1D_sor_v, r1D_sor_a, n, tol);
  if (doDump) io_wrReal1D(context, mkfname(stem, "s", suffix, "r1"), r1D_gauss_a, n);

  /* product (sor) */
  product(r2D_sor, r1D_sor_a, r1D_sor_c, n, n);
  if (doDump) io_wrReal1D(context, mkfname(stem, "ps", suffix, "r1"), r1D_gauss_c, n);

  /* difference */
  vecdiff(r1D_gauss_a, r1D_sor_a, n, &realDiff);
  if (doDump) io_wrReal0D(context, mkfname(stem, "v", suffix, "r0"), realDiff);

#if IEEE
  ieee_retrospective(stderr);
#endif
#if NUMA
  MAIN_END;
#endif

  return 0;
}
コード例 #5
0
ファイル: listc.c プロジェクト: CivilPol/sdcboot
// edit or display a file with vertical & horizontal scrolling & text searching
int _near List_Cmd( LPTSTR pszCmdLine )
{
	int nFVal, nReturn = 0, argc;
	TCHAR szSource[MAXFILENAME+1], szFileName[MAXFILENAME+1], *pszArg;
	FILESEARCH dir;

	memset( &dir, '\0', sizeof(FILESEARCH) );
	
	// check for and remove switches
	if ( GetRange( pszCmdLine, &(dir.aRanges), 0 ) != 0 )
		return ERROR_EXIT;
	
	// check for /T"search string"
	GetMultiCharSwitch( pszCmdLine, _TEXT("T"), szSource, 255 );
	if ( szSource[0] == _TEXT('"') )
		sscanf( szSource+1, _TEXT("%79[^\"]"), szListFindWhat );
	else if ( szSource[0] )
		sprintf( szListFindWhat, FMT_PREC_STR, 79, szSource );
	
	if ( GetSwitches( pszCmdLine, _TEXT("*HIRSWX"), &lListFlags, 0 ) != 0 )
		return ( Usage( LIST_USAGE ));
	
	if ( szSource[0] )
		lListFlags |= LIST_SEARCH;
	
	// check for pipe to LIST w/o explicit /S switch
	if ( first_arg( pszCmdLine ) == NULL ) {

		if ( _isatty( STDIN ) == 0 )

				lListFlags |= LIST_STDIN;
			else if (( lListFlags & LIST_STDIN ) == 0 )
				return ( Usage( LIST_USAGE ));
	}
	
	// initialize buffers & globals
	
	if ( ListInit() )
		return ERROR_EXIT;
	nCurrent = nStart = 0;
	
	// ^C handling
	if ( setjmp( cv.env ) == -1 ) {
list_abort:
		FindClose( dir.hdir );
		Cls_Cmd( NULL );
		nReturn = CTRLC;
		goto list_bye;
	}
	
RestartFileSearch:
	for ( argc = 0; ; argc++ ) {
		
		// break if at end of arg list, & not listing STDIN
		if (( pszArg = ntharg( pszCmdLine, argc )) == NULL ) {
			if (( lListFlags & LIST_STDIN ) == 0 )
				break;
		} else
			strcpy( szSource, pszArg );
		
		for ( nFVal = FIND_FIRST; ; ) {
			
			szClip[0] = _TEXT('\0');
			
			// if not reading from STDIN, get the next matching file
			if (( lListFlags & LIST_STDIN ) == 0 ) {
				
				// qualify filename
				if ( nFVal == FIND_FIRST ) {
					mkfname( szSource, 0 );
					if ( is_dir( szSource ))
						mkdirname( szSource, WILD_FILE );
				}

				if ( stricmp( szSource, CLIP ) == 0 ) {
					
					RedirToClip( szClip, 99 );
					if ( CopyFromClipboard( szClip ) != 0 )
						break;
					strcpy( szFileName, szClip );
					
				} else if ( QueryIsPipeName( szSource )) {
					
					// only look for pipe once
					if ( nFVal == FIND_NEXT )
						break;
					copy_filename( szFileName, szSource );
					
				} else if ( find_file( nFVal, szSource, ( FIND_BYATTS | FIND_RANGE | FIND_EXCLUDE | 0x07), &dir, szFileName ) == NULL ) {
					nReturn = (( nFVal == FIND_FIRST ) ? ERROR_EXIT : 0 );
					break;
					
				} else if ( nStart < nCurrent ) {
					nStart++;
					nFVal = FIND_NEXT;
					continue;
					
				} else if ( dir.ulSize > 0L )
					LFile.lSize = dir.ulSize;
			}
			
			// clear the screen (scrolling the buffer first to save the current screen)

			Cls_Cmd( NULL );
			
			if (( nReturn = _list( szFileName )) == CTRLC )
				goto list_abort;
			
			if ( szClip[0] )
				remove( szClip );
			
			if ( nReturn != 0 )
				break;
			
			SetCurPos( nScreenRows, 0 );
			
			if (( szClip[0] ) || ( lListFlags & LIST_STDIN ))
				break;

			if ( LFile.hHandle > 0 )
				_close( LFile.hHandle );
			LFile.hHandle = -1;
			
			// increment index to current file
			if ( nCurrent < nStart ) {
				FindClose( dir.hdir );
				nStart = 0;
				goto RestartFileSearch;
			} else {
				nFVal = FIND_NEXT;
				nCurrent++;
				nStart++;
			}
		}
		
		// we can only read STDIN once!
		lListFlags &= ~LIST_STDIN;
	}
	
	crlf();
list_bye:
	FreeMem( LFile.lpBufferStart );
	if ( LFile.hHandle > 0 )
		_close( LFile.hHandle );
	LFile.hHandle = -1;
	
	return nReturn;
}
コード例 #6
0
ファイル: env.c プロジェクト: CivilPol/sdcboot
static int SetFromFile( LPTSTR pszLine, TCHAR _far *pchList, long fFlags )
{
	static TCHAR szDelimiters[] = _TEXT("%[^= \t]");
	register LPTSTR pszArg;
	TCHAR szBuffer[CMDBUFSIZ];
	int i, n, nError = 0, nEditFlags = EDIT_DATA, nFH = -1;


	if (( *pszLine == _TEXT('\0') ) && ( QueryIsConsole( STDIN ) == 0 )) {
		pszLine = CONSOLE;
		nFH = STDIN;
	}

	for ( i = 0; (( nError == 0 ) && (( pszArg = ntharg( pszLine, i )) != NULL )); i++ ) {

		if ( nFH != STDIN ) {
			mkfname( pszArg, 0 );
			if (( nFH = _sopen( pszArg, _O_RDONLY | _O_BINARY, _SH_DENYWR )) < 0 )
				return ( error( _doserrno, pszArg ));
		}

		if ( setjmp( cv.env ) == -1 ) {
			if ( nFH > 0 ) {
				_close( nFH );
				nFH = -1;
			}
            return CTRLC;
		}

		for ( pszArg = szBuffer; (( nError == 0 ) && ( getline( nFH, pszArg, CMDBUFSIZ - (UINT)(( pszArg - szBuffer ) + 1 ), nEditFlags ) > 0 )); ) {

			// remove leading white space
			strip_leading( pszArg, WHITESPACE );

			// if last char is escape character, append the next line
			n = strlen( pszArg ) - 1;
			if (( pszArg[0] ) && ( pszArg[n] == gpIniptr->EscChr )) {
				pszArg += n;
				continue;
			}

			// skip blank lines & comments
			pszArg = szBuffer;
			if (( *pszArg ) && ( *pszArg != _TEXT(':') )) {

				// delete variable
				if ( fFlags & 1 ) {
					// an UNSET requires a '=' delimiter; it's optional elsewhere
					szDelimiters[4] = (( pchList == glpEnvironment ) ? _TEXT('\0') : _TEXT(' '));
					sscanf( szBuffer, szDelimiters, szBuffer );
				}

				// create/modify a variable or alias
				nError = add_list( pszArg, pchList );
			}
		}

		if ( nFH != STDIN ) {
			 _close( nFH );
			 nFH = -1;
		}
	}

	return nError;
}