📄 text_utils.c
字号:
/* * This material contains unpublished, proprietary software of * Entropic Research Laboratory, Inc. Any reproduction, distribution, * or publication of this work must be authorized in writing by Entropic * Research Laboratory, Inc., and must bear the notice: * * "Copyright (c) 1987-1990 AT&T, Inc. * "Copyright (c) 1986-1990 Entropic Speech, Inc. * "Copyright (c) 1990-1996 Entropic Research Laboratory, Inc. * All rights reserved" * * The copyright notice above does not evidence any actual or intended * publication of this source code. * * Written by: * Checked by: * Revised by: * * Brief description: * a motley collection of more or less specialized text utilities */static char *sccs_id = "@(#)text_utils.c 1.10 9/28/98 ATT/ESI/ERL";#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <string.h>#include <esps/unix.h>#include <esps/epaths.h>#include <w_lengths.h> #define TRUE 1#define FALSE 0extern char output_dir[]; /*defined in globals.c */extern int debug_level;char *build_filename(), *basename(); void setup_output_dir();/*********************************************************************//* This assumes that the input list is sorted. */char **uniq_list(l) char **l;{ if(l && *l && l[1] && *l[0] && *l[1]) { int i, j; for(i=0, j=1; l[i] && *l[i]; ) { while(l[j] && !strcmp(l[i],l[j])) j++; i++; l[i] = l[j]; } } return(l);}/*********************************************************************/strip_newline_at_etc(out,in) char *out, *in;{ if(out && in) { if(*in) { register char *pi = in, *pf; while(*pi && ((*pi == ' ') || (*pi == ' '))) pi++; while(*pi && (*pi == '@')) pi++; pf = pi; while(*pf && (*pf != ' ') && (*pf != ' ') && (*pf != '\n')) pf++; *pf = 0; if(*pi) { strcpy(out,pi); return; } } *out = 0; }} /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/block_build(buf,used,size,arg) char **buf; /* buffer into which the header is being built */ char *arg; /* pointer to data destined for block*/ int *size, /* dimension(-1) of *buf */ *used; /* number of bytes of buff that have been used */{ int n;#if !defined(HP700) && !defined(DEC_ALPHA) char *realloc(), *malloc();#endif n = strlen(arg); if((n + *used) > *size) { /* bump block size */ if(*buf && *size) { if(!(*buf = realloc(*buf, *size + n + MES_BUF_SIZE + 1))) { printf("Can't allocate enough buffer space in block_build()\n"); return(FALSE); } *size += MES_BUF_SIZE + n; } else { if( ! (*buf = malloc(MES_BUF_SIZE + 1))) { fprintf(stderr,"Allocation problems in block_build()\n"); return(FALSE); } *size = MES_BUF_SIZE; *used = 0; } } strcpy((char*)((*buf) + (*used)), arg); *used += n; return(TRUE);}/*************************************************************************//* This removes the carriage return inserted by the pty when waves is drivenby standard input with invocations like "xwaves - < /dev/ptyrf&" */char *clobber_cr(str) register char *str;{ register int n; if(str && *str && ((str[(n = strlen(str) -2)] == '\r') || (str[(n = strlen(str) -1)] == '\r')) && (n >= 0)) { str[n] = ' '; /* convert it to a space */ } return(str);}/*********************************************************************/char *expand_name(out, in) char *out, *in;{ static char name[NAMELEN]; if(in) { if(*in) { int n; build_filename(name,"#",in); n = strlen(name) - 2; if(name[n+1] == '#') name[n] = 0; else fprintf(stderr,"Weird filename in expand_name(%s, %s)\n",in,name); } else { if(out) { strcpy(out,"./"); return(out); } else { strcpy(name,"./"); return(name); } } if(out) { strcpy(out,name); return(out); } return(name); } fprintf(stderr, "Null input name passed to expand_name()\n"); return(NULL);} /*********************************************************************//* This eliminates the silly behavior of requiring a ./ before all paths starting in the current directory. */char *apply_waves_input_path(n1,n2) char *n1, *n2;{ register char *cp = (char*)FIND_WAVES_INPUT(n1,n2), *c2=cp, *c3=cp+2; if(cp && *cp && !strncmp(cp,"./",2)) while((*c2++ = *c3++)); return(cp);}/*********************************************************************//* This eliminates the silly behavior of requiring a ./ before all paths starting in the current directory. */char *apply_esps_bin_path(n1,n2) char *n1, *n2;{ if(n2) { if(*n2) { register char *cp = (char*)FIND_ESPS_BIN(n1,n2), *c2=cp, *c3=cp; if(cp && *cp && (*cp == '.')) { c3++; while(*c3 == '/') c3++; while((*c2++ = *c3++)); } return(cp); } else { if(n1) { *n1 = 0; return(n1); } else return(n2); } } else return(NULL);}/*********************************************************************//* If the terminal node in a pathname contains any of the common regular expression characters (like (){}[]* or ?) remove the terminal node. Return the modified string in situ. */ char *remove_reg_exp(s) register char *s;{ register int n = strlen(s), found = 0; register char *c = s + n, p; while(c-- > s) { if((p = *c) == '/') { if(found) *(c+1) = 0; return(s); } if((p == '*') || (p == '?') || (p == '(') || (p == '{') || (p == '[') || (p == '$')) found = 1; } if(found) *s = 0; return(s);}/*********************************************************************/char *cleaned_for_input(s) register char *s;{ static char scratch[200]; register char *c = s + strlen(s) - 1, p; if(((p = *c) == '@') || (p == '*')) { strncpy(scratch, s, c - s); scratch[c - s] = 0; } else strcpy(scratch,s); return(scratch);} /*********************************************************************/char *first_digit(st) char *st;{ register char *p; if(*st) { p = st + (strlen(st) - 1); while( p >= st) { if(*p == '/') return(NULL); if((*p >= '0') && (*p <= '9')) { while( --p >= st) if((*p < '0') || (*p > '9')) return( ++p ); return(st); } p--; } } return(NULL);}/*********************************************************************/char *after_last_digit(st) char *st;{ register char *p; if(*st) { p = st + (strlen(st) - 1); while( p >= st) { if(*p == '/') return(NULL); if((*p >= '0') && (*p <= '9')) return( ++p ); p--; } } return(NULL);}/*********************************************************************/get_num(st) char *st;{ int i; char t, *p1, *p2; if((p1 = first_digit(st))) { p2 = after_last_digit(st); t = *p2; *p2 = 0; sscanf(p1,"%d",&i); *p2 = t; return(i); } else return(-1);} /*********************************************************************/make_next_name(st) char *st;{ int i, j; char sc[100], *p; if((i = get_num(st)) >= 0) { p = after_last_digit(st); strcpy(sc,p); p = first_digit(st); sprintf(p,"%d%s",i+1,sc); }} /*********************************************************************/char *make_x_name(st,ex) char *st, *ex;{ /* Changed to place new extention BEFORE old one e.g. "xyz.d" + ".ed" -> "xyz.ed.d" */ register int i; static char sc[NAMELEN]; for (i = strlen(st); i >= 0 && st[i] != '.'; i--); if ((i < 0) || ((i == 0) && ((st[0] == '.') || (st[0] == '/')))){ /* no extension, just tack on new one */ strcpy(sc,st); strcat(sc,ex); } else { /* insert new extension */ strncpy(sc,st,i); /* old name without final extension */ sc[i] = 0; /* strncpy doesn't do this! */ strcat(sc,ex); /* new extention */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -