⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text_utils.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 2 页
字号:
    strcat(sc,st+i);		/* replace old final extention */  }  setup_output_dir(sc);   return(sc);} /****************************************************************************//* if ex is the terminal string of name, or if ex is the string immediately   preceeding the last "." in name, return TRUE, else FALSE */is_a_x_file(name,ex)     register char *name, *ex;{  register char *p, q;  register int i, n, m;  if (!name || !ex || !*name || !*ex)    return(FALSE);  p = name + (n = strlen(name)) - (m = strlen(ex));  if((n >= m) && (! strcmp(p,ex))) return(TRUE);  /* does "ex" exist just before an extension? (as might have been put there     by make_x_name())? */  for (i = n; i >= 0 && name[i] != '.'; ) i--;  if(i > m) {		/* could be */    q = name[i];    name[i] = 0;    p = name + (n = strlen(name)) - m;    n = ((n >= m) && (! strcmp(p,ex)));    name[i] = q;    return(n);  }  return(FALSE);}/*      ----------------------------------------------------------      */char *new_ext(oldn,newex)     char *oldn, *newex;{  int	j;  char *dot;  static char newn[256];  static int len = 0;  dot = strrchr(oldn,'.');  if(dot != NULL){    *dot = 0;    j = strlen(oldn) + 1;    *dot = '.';      }  else j = strlen(oldn);  if((len = j + strlen(newex)+ 1) > 256) {    printf("Name too long in new_ext()\n");    return(NULL);  }  strncpy(newn,oldn,j);  newn[j] = 0;  return(strcat(newn,newex));}/*********************************************************************/char *remove_ext(name)     register char *name;{  static char str[50];  register int i;  register char *c, *d;  if(name && (i = strlen(name))) {    c = name + i - 1;    while( c > name ) {      if(*c == '.') {	d = c;	while((d >= name) && (*d != '/')) d--;	strncpy(str,d+1, (i = c - d - 1));	str[i] = 0;	return(str);      }      if(*c == '/') {	strcpy(str, c+1);	return(str);      }      c--;    }    strcpy(str,name);    return(str);  }  return(NULL);}		   /*************************************************************************//* Return TRUE if the last node in a pathname looks like a regular exp. */its_a_reg_exp(s)     register char *s;{  register int n = strlen(s);  register char *c = s + n, p;  while(c-- > s) {    if((p = *c) == '/') return(FALSE);    if((p == '*') || (p == '?') || (p == '(') || (p == '{') || (p == '[') ||       (p == '$'))      return(TRUE);  }  return(FALSE);}/*************************************************************************//* NOTE: This assumes that there is enogh room in name for an extra   character or two! */its_a_directory(name)     char *name;{  if(name) {    struct stat filestat;    u_short filemode;    int ret = stat(name, &filestat);    if((ret == 0) && (filestat.st_mode & S_IFDIR)) {      int n = strlen(name);            if(n) {	if (name[n-1] != '/') {	  name[n] = '/';	  name[n+1] = 0;	}      } else	strcpy(name,"./");      return(TRUE);    }  }  return(FALSE);}/*************************************************************************/its_a_partial_pathname(name)     register char *name;{  register int n;  n = strlen(name);  return(!n || its_a_reg_exp(name) || its_a_directory(name));/* ||	 (name[n-1] == '/') ||     ((name[n-1] == '.') && ((n == 1) || (name[n-2] == '/')))); */}/*************************************************************************/fix_path_end(name)     register char *name;{  register int n;  register char *c;  c = name + (n = strlen(name)) - 1;  if((!n) || (*c == '/')) return;  if((*c == '.') && ((*(c-1) == '/') || (n == 1)))    *c = 0;/*  if((n > 1) && (*(c-1) != '/') && !its_a_reg_exp(name)) *c = '/'; */  return;}/************************************************************************/not_explicitly_named(name)     char *name;{  if(name && *name) {    return((*name != '/') && strncmp(name,"./",2));  }  return(FALSE);}/************************************************************************/char *get_output_file_names(outname, next)     register char *next, *outname;{  static  char name[NAMELEN];  char flist[NAMELEN];  FILE *fdt, *fopen();  int i, eof;  /* If outname begins with "@" this means that the name specified   is that of a filename list.  Otherwise outname is taken as the name   of the output file.  In the latter case, if outname contains a numeric   field (defined as the first occurrence of a contiguous sequence of numbers)   this sequence will be incremented and a new filename will be created   containing the incremented field.  The new (next) filename will be returned   in next in any case. */  if (debug_level) {      (void) fprintf(stderr, "entered get_output_file_names: outname = %s\n",		   outname);    }  if(!strlen(outname)) {    *next = 0;    return(NULL);  }  *name = 0;  if(*outname == '@') {	/* we are dealing with a list of names */    sscanf(&outname[1],"%s%s", flist, name);    if(!(fdt = fopen(flist,"r"))){      printf("List file %s not found\n",flist);      *next = 0;      return(NULL);    }    if(strlen(name)) {		/* index into the current filename */      while((eof = fscanf(fdt, "%s",next)) != EOF) {	if(!strcmp(name,next)) { /* found current name in list! */	  if(fscanf(fdt,"%s",next) != EOF) {	  } else {	    *next = 0;	  }	  fclose(fdt);	  return(name);	}      }      printf("Name (%s) not found in list %s\n",name,flist);      *next = 0;      fclose(fdt);      return(NULL);    } else {			/* start with first name in list */      if(fscanf(fdt, "%s",name) != EOF) {	if(fscanf(fdt,"%s",next) != EOF) {	} else {	  *next = 0;	}	fclose(fdt);	return(name);      } else {	printf("No names were found in list file %s\n",flist);	*next = 0;	fclose(fdt);	return(NULL);      }    }  } else {			/* interpret the name directly */    if(strlen(outname)) {      if(not_explicitly_named(outname))	setup_output_dir(outname);       sscanf(outname,"%s",name);      strcpy(next, name);      make_next_name(next);      if (debug_level)	(void) fprintf(stderr, "make_output_file_names: returning next = %s\n",		   next);      return(name);    } else {      printf("No output file name was specified\n");      *next = 0;      return(NULL);    }  }}/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/insert_numeric_ext(old,num,new)     char *old, *new;     int num;{				/* "abc.x",2 --> "abc.2.x"  */  char *ext, temp[128];    strcpy(new,old);    if ( ext = strrchr(new,'.') ) /* has final extension */      strcpy(temp,ext);		/* save old extension */    else {      temp[0] = '\0';		/* no old extension */      ext = new + strlen(new);    }    sprintf(ext,".%d%s",num,temp);}/*----------------------------------------*//* setup_output_dir is used to adjust output file names so that  * all output files are written in the global output_dir if it  * has been defined; Since build_filename() is used, environment  * variables can be in the output_dir path.   */  voidsetup_output_dir(name)char *name;{  /* No processing is needed unless output_dir is defined */  if (strlen(output_dir) > 0) {      struct stat filestat;      char tnams[NAMELEN];      u_short filemode;      int ret;      if(*output_dir)	expand_name(output_dir,output_dir);      ret = stat(output_dir, &filestat);      filemode = filestat.st_mode;      /* if there's an output_dir, we make sure it exists and has rwx 	 permissions */      if (!((ret == 0)	    && (filemode & S_IFDIR)	    && (filemode & S_IREAD)	    && (filemode & S_IWRITE)	    && (filemode & S_IEXEC)))       {	(void) fprintf(stderr, 	    "ERROR: output_dir doesn't exist or is without rwx permission\n");	(void) fprintf(stderr, "    output_dir reset to /usr/tmp.\n"); 	strcpy(output_dir, "/usr/tmp");      }      strcpy(tnams,basename(name));      /* now build the full output name in the output directory */      build_filename(name, tnams, output_dir);     }}/*********************************************************************/strcmpcover(s1,s2)     char **s1, **s2;{  return(strcmp(*s1, *s2));}/*********************************************************************/char **sort_a_list(list)     char **list;{  if(list && *list && list[1] && *list[0] && *list[1]) {    int n = 1;    while(list[n] && *list[n]) n++;    qsort(list, n, sizeof(char*), strcmpcover);  }  return(list);}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -