Пример #1
0
 string FSName::to_string()
 {
   char buffer[256];
   snprintf(buffer, 256, "block_id: %"PRI64_PREFIX"u, file_id: %"PRI64_PREFIX"u, seq_id: %u, suffix: %u, name: %s",
            get_block_id(), get_file_id(), get_seq_id(), get_suffix(), get_name());
   return string(buffer);
 }
Пример #2
0
CString VoiceActingManager::generate_filename(CString section, int number, int digits)
{
	if (section == "")
		return "none.wav";

	int i;
	CString str = "";
	CString num;

	// build prefix
	if (m_abbrev_campaign != "")
		str = str + m_abbrev_campaign;
	if (m_abbrev_mission != "")
		str = str + m_abbrev_mission;
	str = str + section;
	
	// build number
	num.Format("%d", number);;
	digits -= num.GetLength();
	for (i = 0; i < digits; i++)
	{
		num = "0" + num;
	}
	str = str + num;

	// suffix
	str = str + get_suffix();

	return str;
}
Пример #3
0
static int
quh_set_fname (const char *fname)
{
//  const char *suffix = NULL;

#ifdef  DEBUG
  printf ("\n%s\n\n", fname);
  fflush (stdout);
#endif

#if 0
  // playlist? 
  suffix = get_suffix (fname);
  if (*suffix)
    if (!stricmp (suffix, ".m3u"))// ||
//        !stricmp (suffix, ".pls"))
      {
        FILE *fh = fopen (fname, "r");
        char buf[MAXBUFSIZE];

        if (fh)
          {
            while (fgets (buf, MAXBUFSIZE, fh))
              quh_set_fname2 (buf);
            fclose (fh);
          }

        return 0; // failed
      }
#endif

  if (!access (fname, R_OK))
    return quh_set_fname2 (fname);
  return 0;
}
Пример #4
0
char *
set_suffix (char *filename, const char *suffix)
{
  // always use set_suffix() and NEVER the code below
  strcpy ((char *) get_suffix (filename), suffix);

  return filename;
}
Пример #5
0
int __cdecl main( int argc, char *argv[] )
{
	char *path, *suffix, *source, target[255];
	unsigned resolution;

	if( argc <= 2 )
		goto error;

	path = argv[2];
	suffix = get_suffix( path );
	resolution = atoi( suffix );

	source = get_name( path );
	sprintf( target, "%s%s", source, ".dds" );

	if( strcmp( argv[1], "-c" ) == 0 )
	{
		if( strcmp( suffix, "dds" ) != 0 )
			goto error;

		cut_header( path );
	}
	else if( strcmp( argv[1], "-r" ) != 0 )
	{
		
	}

	free( suffix );
	free( source );

	switch( resolution )
	{
	case 512:
		recover_texture( path, target, 512 );
		break;
	case 1024:
		recover_texture( path, target, 1024 );
		break;
	case 2048:
		recover_texture( path, target, 2048 );
		break;
	}

	goto exit;

error:
	printf( "syntax: magicdds.exe option filename\n"
				"options:\n-c - convert .dds image into 4A-Engine format\n"
				"-r - recover 4A-Engine image into original .dds format\n" );

exit:
	return 0;
}
Пример #6
0
void
get_eigen_outfile_name(char *in_name, int j, int k)
{
  char prefix[MAX_FNL];
  char suffix[MAX_FNL];
  char new_name[MAX_FNL];
  char mode_string[MAX_FNL];
  char wave_string[MAX_FNL];

  int i;
  int suffix_length;
  int prefix_length;

/* Initialize string pieces */
  for ( i=0; i<MAX_FNL; i++)
    {
      prefix[i] = '\0';
      suffix[i] = '\0';
      new_name[i] = '\0';
      mode_string[i] = '\0';
      wave_string[i] = '\0';
    }

/* Save beginning and end of specified file name */
  suffix_length = get_suffix(suffix, in_name);
  prefix_length = get_prefix(prefix, in_name);

/* Determine if doing 3D of 2D LSA; set k = -1 if not */
  if ( !(Linear_Stability == LSA_3D_OF_2D)
    && !(Linear_Stability == LSA_3D_OF_2D_SAVE)) k = -1;

/* Always construct mode string */
  sprintf(mode_string, "_mode%d", j);

/* Construct wave string for 3D of 2D LSA only */
  if (k != -1) sprintf(wave_string, "_wn=%g", LSA_wave_numbers[k]);

/* Assemble the pieces of the name string */
  if (prefix_length > 0) strcpy(new_name, prefix);
  strcat(new_name, mode_string);
  if (k != -1) strcat(new_name, wave_string);
  if (suffix_length > 0) strcat(new_name, suffix);

/* Multiname for this processor if parallel */
  if (Num_Proc > 1) multiname(new_name, ProcID, Num_Proc);

/* Return the name as in_name */
  strcpy(in_name, new_name);
  return;
}
Пример #7
0
/* is_object_source_kind returns TRUE only for objects. FALSE everything else
   including archives (.a) and shared objects (.so) */
boolean
is_object_source_kind(char *src)
{
	int j;
	char *suf = get_suffix(src);
	if (suf == NULL) return FALSE;
	for (j = 0; j < MAX_SUFFIXES && source_info[S_o].suffix[j] != NULL; j++) {
	    if (strcmp(source_info[S_o].suffix[j], suf) == 0) {
		return TRUE;
	    }

	}
	return FALSE;
}
Пример #8
0
source_kind_t
get_source_kind (const char *src)
{
	if (ignore_suffix) {
		if (default_source_kind != S_NONE)
			return default_source_kind;
		else {
			/* assume is of invoked lang */
			switch (invoked_lang) {
			case L_cc: return S_c;
			case L_CC: return S_C;
			case L_f90: return S_f90;
			case L_as: return S_s;
			}
		}
	}
	return get_source_kind_from_suffix (get_suffix(src));
}
Пример #9
0
FCTWH *get_wh_handler(char *name)
{
  FCTWH *back = NULL;
  if(name) {
    char *suffix;
    suffix = get_suffix(name);
    if(suffix) {
      HANDLERENTRY *he;
      he = handlers;
      while((he->suffix) && (back == NULL)) {
        if( STRCASECMP(suffix,(he->suffix)) == 0 ) {
          back = he->wh;
        }
        he++;
      }
    }
  }
  return back;
}
Пример #10
0
FileType *detect_type(char *filename) {
    ///////////////////////////////////////////////////////////////////
    // This function returns a pointer to the FileType parsed from   //
    // the filename passed to the function.                          //
    // params :                                                      //
    // - filename (char *) : the file name to parse                  //
    // returns :                                                     //
    // - (FileType *) : the file type parsed                         //
    ///////////////////////////////////////////////////////////////////

    char *suffix;
    suffix = get_suffix(filename);
    if (strncmp(suffix, "md", 50)
        || strncmp(suffix, "mdown", 50)
        || strncmp(suffix, "markdown", 50))
        return file_type_new("Markdown", suffix, 1);
    if (strncmp(suffix, "textile", 50))
        return file_type_new("Textile", suffix, 0);
    if (strncmp(suffix, "rst", 50))
        return file_type_new("reStructuredText", suffix, 0);
    if (strncmp(suffix, "html", 50) || strncmp(suffix, "php", 50))
        return file_type_new("HTML", suffix, 0);
    if (strncmp(suffix, "tex", 50))
        return file_type_new("LaTeX", suffix, 0);
    if (strncmp(suffix, "mw", 50))
        return file_type_new("MediaWiki", suffix, 0);
    if (strncmp(suffix, "tw", 50))
        return file_type_new("TWiki", suffix, 0);
    if (strncmp(suffix, "hd", 50))
        return file_type_new("Haddock", suffix, 0);
    if (strncmp(suffix, "opml", 50))
        return file_type_new("OPML", suffix, 0);
    if (strncmp(suffix, "dbk", 50))
        return file_type_new("DockBook", suffix, 0);
    if (strncmp(suffix, "odt", 50) || strncmp(suffix, "fodt", 50))
        return file_type_new("OpenDocument", suffix, 0);
    if (strncmp(suffix, "epub", 50))
        return file_type_new("Epub", suffix, 0);
    if (strncmp(suffix, "docx", 50) || strncmp(suffix, "doc", 50))
        return file_type_new("Word Doc", suffix, 0);
    return file_type_new("NULL", suffix, 0);
}
Пример #11
0
/* Produce a single rectangle corresponding to the given BSDF dimensions */
static void
faceBSDF(const SDData *bsp, double zval)
{
	const char	*sfx = get_suffix(zval);
							/* output material */
	printf("void BSDF m_%s%s\n", bsp->name, sfx);
	printf("6 %g %s.xml 0 1 0 .\n", zval*1.00004, bsp->name);
	printf("0\n0\n\n");
							/* output surface */
	zval *= (zval < 0) + 0.00002;
	printf("m_%s%s polygon %s%s\n", bsp->name, sfx, bsp->name, sfx);
	printf("0\n0\n12\n");
	printf("\t%.6e\t%.6e\t%.6e\n",
				-.5*bsp->dim[0], -.5*bsp->dim[1], zval);
	printf("\t%.6e\t%.6e\t%.6e\n",
				.5*bsp->dim[0], -.5*bsp->dim[1], zval);
	printf("\t%.6e\t%.6e\t%.6e\n",
				.5*bsp->dim[0], .5*bsp->dim[1], zval);
	printf("\t%.6e\t%.6e\t%.6e\n\n",
				-.5*bsp->dim[0], .5*bsp->dim[1], zval);
}
Пример #12
0
st_strpath_t *
strpath (st_strpath_t *path, const char *path_s)
{
// TODO: compare this with splitpath()
  if (path_s == NULL)
    return NULL;

  realpath2 (path_s, path->realpath);

#if     defined DJGPP || defined __CYGWIN__ || defined _WIN32
  if (isalpha (path->realpath[0]) &&
      path->realpath[1] == ':' &&
      path->realpath[2] == FILE_SEPARATOR)
    sprintf (path->drive, "%c:\\", toupper (path->realpath[0]));
#else
  strcpy (path->drive, FILE_SEPARATOR_S);
#endif

  dirname2 (path_s, path->dirname);
  strcpy (path->basename, basename2 (path_s));
  strcpy (path->suffix, get_suffix (path_s));

  return path;
}
Пример #13
0
int
main(void)
{
    const template *t;
    const prefix_entry *p;
    int32_t prefix;

    uint32_t i, j, type0, type1;
    char **op0, **op1;
    char *suffix;

	for(t = i386_optab; t < i386_optab_end; t++){
	    /*
	     * Don't use the table entries that are prefixes and not
	     * instructions.
	     */
	    prefix = 0;
	    for(p = i386_prefixtab; p < i386_prefixtab_end; p++){
		prefix = (p->prefix_code == t->base_opcode);
		if(prefix)
		    break;
	    }
	    if(prefix)
		continue;
	    /*
	     * The string instructions with operands take only specific
	     * operands and are not checked here.
	     */
	    if(t->operands != 0 && IS_STRING_INSTRUCTION(t->base_opcode))
		continue;
	   
	    if(t->operands == 0){
		if((t->opcode_modifier & W) == 0) {
		    printf("\t%s\n", t->name);
		}
		else{
		    printf("\t%sb\n", t->name);
		    printf("\t%sw\n", t->name);
		    printf("\t%sl\n", t->name);
		}
	    }

	    if(t->operands == 1){
		for(i = 0; i < 32; i++){
		    type0 = 1 << i;
		    if((type0 & t->operand_types[0]) == 0)
			continue;

		    /* These only take byte displacement */
		    if(IS_LOOP_ECX_TIMES(t->base_opcode) &&
		       (type0 == Disp16 || type0 == Disp32))
			continue;

		    /* These only take byte displacement */
		    if((strcmp(t->name, "jcxz") == 0 ||
		        strcmp(t->name, "jecxz") == 0) &&
		       (type0 == Disp16 || type0 == Disp32))
			continue;

		    if(type0 == Disp8 &&
		       ((t->operand_types[0] & (Disp16 | Disp32)) != 0))
			continue;

		    suffix = "";
		    if((type0 & Mem) != 0)
			suffix = get_suffix(type0);

		    /*
		     * This is to avoid the problem with the
		     * fildll opcode which is a fildq and
		     * fistpll opcode which is a fistpq
		     */
		    if((strcmp(t->name, "fildl") == 0 ||
			strcmp(t->name, "fistpl") == 0) &&
			strcmp(suffix, "l") == 0)
			suffix = "";

		    /*
		     * This is to avoid the problems with the
		     * fisttpl opcode and the fisttpll opcodes.
		     */
		    if((strcmp(t->name, "fisttpl") == 0 ||
			strcmp(t->name, "fisttpll") == 0))
			continue;
		
		    /* fwait prefixed instructions */
		    if((t->base_opcode & 0xff00) == 0x9b00 &&
		       strcmp(suffix, "w") == 0)
			continue;

		    op0 = get_operand(type0);
		    for( ; *op0; op0++){
			printf("\t%s%s\t%s\n", t->name, suffix, *op0);
		    }
		}
	    }

	    if(t->operands == 2){
		for(i = 0; i < 32; i++){
		    type0 = 1 << i;
		    if((type0 & t->operand_types[0]) == 0)
			continue;
		    for(j = 0; j < 32; j++){
			type1 = 1 << j;
			if((type1 & t->operand_types[1]) == 0)
			    continue;
			if((type0 & RegALL) != 0 && (type1 & RegALL) != 0)
			    if(type0 != type1)
				continue;

			suffix = "";
			if((type0 & (Imm|Imm1)) != 0 && (type1 & Mem) != 0)
			    suffix = get_suffix(type0);
			if((type0 & Mem) != 0 && (type1 & (Imm|Imm1)) != 0)
			    suffix = get_suffix(type1);

			op0 = get_operand(type0);
			op1 = get_operand(type1);
			for( ; *op0; op0++){
			    for( ; *op1; op1++){
				printf("\t%s%s\t%s,%s\n", t->name, suffix,
				       *op0, *op1);
				if(t->opcode_modifier & D){
				    printf("\t%s%s\t%s,%s\n", t->name, suffix,
					   *op1, *op0);
				}
			    }
			}
		    }
		}
	    }
	}
	return(0);
}
Пример #14
0
static int
decompress_file(struct deflate_decompressor *decompressor, const tchar *path,
		const struct options *options)
{
	tchar *newpath = NULL;
	struct file_stream in;
	struct file_stream out;
	struct stat stbuf;
	int ret;
	int ret2;

	if (path != NULL && !options->to_stdout) {
		const tchar *suffix = get_suffix(path, options->suffix);
		if (suffix == NULL) {
			msg("\"%"TS"\" does not end with the .%"TS" suffix -- "
			    "skipping", path, options->suffix);
			ret = -2;
			goto out;
		}
		newpath = xmalloc((suffix - path + 1) * sizeof(tchar));
		tmemcpy(newpath, path, suffix - path);
		newpath[suffix - path] = '\0';
	}

	ret = xopen_for_read(path, &in);
	if (ret != 0)
		goto out_free_newpath;

	if (!options->force && isatty(in.fd)) {
		msg("Refusing to read compressed data from terminal.  "
		    "Use -f to override.\nFor help, use -h.");
		ret = -1;
		goto out_close_in;
	}

	ret = stat_file(&in, &stbuf, options->force || newpath == NULL);
	if (ret != 0)
		goto out_close_in;

	ret = xopen_for_write(newpath, options->force, &out);
	if (ret != 0)
		goto out_close_in;

	ret = map_file_contents(&in, stbuf.st_size);
	if (ret != 0)
		goto out_close_out;

	ret = do_decompress(decompressor, &in, &out);
	if (ret != 0)
		goto out_close_out;

	if (path != NULL && newpath != NULL)
		restore_metadata(&out, newpath, &stbuf);
	ret = 0;
out_close_out:
	ret2 = xclose(&out);
	if (ret == 0)
		ret = ret2;
	if (ret != 0 && newpath != NULL)
		tunlink(newpath);
out_close_in:
	xclose(&in);
	if (ret == 0 && path != NULL && newpath != NULL && !options->keep)
		tunlink(path);
out_free_newpath:
	free(newpath);
out:
	return ret;
}
Пример #15
0
static bool
has_suffix(const tchar *path, const tchar *suffix)
{
	return get_suffix(path, suffix) != NULL;
}
Пример #16
0
// Get program path from PATH variable.
static char *
get_executable_dir_from_path(char *name)
{
  if (is_dir_separator (name[0]))
    return name;
#if defined(_WIN32)
  else if (name[1] == ':' && is_dir_separator(name[2]))
    return name;
#endif
  else {
    /* relative path */
    char *path = getenv("PATH");
    if (path != NULL) {
      char *p = string_copy(path);
      char *tmp;
      char *dir;
#if defined(_WIN32)
#if defined(__MINGW32__)
      /* mingw uses semicolon as separator */
      while ((dir = strtok(p, ";")) != NULL) {
#else
      /* strtok_r doesn't exist */
      while ((dir = strtok(p, ":")) != NULL) {
#endif /* __MINGW32__ */
#else
      while ((dir = strtok_r(p, ":", &tmp)) != NULL) {
#endif /* _WIN32 */
	if (is_directory(dir)) {
	  char filename[MAXPATHLEN];
	  snprintf(filename, MAXPATHLEN, "%s%s%s", dir, DIR_SEPARATOR_STR, name);
	  if (is_executable(filename)) {
	    return string_copy(filename);
	  }
#if defined(_WIN32)
	  else {
	     /* if not found, then try again with or without .exe suffix,
	      * depending on whether the original filename had one; 
	      * e.g. if invoked opencc when opencc.exe is full name.
	      */
	      char *suffix = get_suffix(filename);
	      if (suffix != NULL && strcmp(suffix, "exe") == 0) {
	        /* has suffix so try without suffix */
	        *(suffix-1) = NIL;
	      }
	      else {
	        /* add exe suffix */
	        strcat(filename, ".exe");
	      }
	      if (is_executable(filename)) {
	          return string_copy(filename);
	      }
	  }
#endif
	}
        p = NULL;
      }
    }
  }
  return name;
}

char *
get_executable_dir (void)
{
	char path[MAXPATHLEN];
	int rval = 0;
	int i;

#if defined(linux)
	/* Look in this special place for a link to the executable. This
	   only works on Linux, but it is benign if we try it elsewhere. */
	rval = readlink ("/proc/self/exe", path, sizeof(path));
#endif
	if (rval <= 0) {
		// If can't read /proc/self/exe, get program path from PATH
		// variable.
		char *p = get_executable_dir_from_path(saved_orig_program_name);
		strncpy(path, p, sizeof(path));
		rval = strlen(path);
	} else {
		path[rval] = '\0';	// readlink doesn't append NULL
	}
	if (rval > 0) {
		for (i=rval-1; i >= 0; i--) {
			if (is_dir_separator(path[i])) break;
		}
		if (i > 0) {
			/* Overwrite the trailing slash, giving the directory
			   portion of the path. */
			path[i] = '\0';      
		} else if (i == 0) {
			/* Directory is the root */
		        strcpy (path, DIR_SEPARATOR_STR);
		}
		if (is_directory (path)) {
			/* Verify that it is a directory */
			return string_copy (path);
		}
	}

	/* TBD: try to extract the name from argv0 */

	/* Can't get anything reasonable. */
#ifdef TARG_NVISA
	internal_error("unable to find $PATH for nvopencc");
#endif
	return NULL;
}

void
dump_file_to_stdout(char *filename)
{
  char buf[buf_size];
  FILE *f;
  int n;

  if (filename == NULL || !file_exists(filename))
    internal_error("file does not exist");
  
  f = fopen(filename, "r");
  if (f == NULL)
    internal_error("cannot open file for read");

  // Copy the content of file to stdout.
  while ((n = fread(buf, 1, buf_size, f)) > 0) {
    if (-1 == write(1, buf, n)) {
      internal_error("cannot write to file");
      break;
    }
  }
  fclose(f);
}