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

📄 xesps.c

📁 speech signal process tools
💻 C
📖 第 1 页 / 共 3 页
字号:
    args[2] = command_line;    args[3] = NULL;/*  fork a new process to run the command*/#if defined(SUN4) || defined(SUN3) || defined(DS3100)    switch (pid = vfork()) {#else    switch (pid = fork()) {#endif	case -1:			/* fork failed */		perror("run_esps_prog_get_pid; fork failed");			return (0);	case 0:				/* child process */			setpgrp(0,getpid());		execvp(args[0], args);		perror("run_esps_prog_get_pid: execvp failed");		return (0);	default:			/* parent *//* first save the pid of the child in the table*/		{		  extern Frame daddy;		  char *current_object_name();		  void *in_a_ipc_dispatch();		  pid_table[pid_slot].pid = pid;		  if(func)pid_table[pid_slot].func = func;		  strcpy(pid_table[pid_slot].oname, current_object_name());		  if(display){     		    int j;	    	    for (j = 0; j < num_esps_out; j++) {		      addstr(output_files, &(pid_table[pid_slot].out_files));		      output_files += strlen(output_files) + 1;		    }			  }			  else 		    pid_table[pid_slot].out_files = NULL;		  (void)notify_set_wait3_func(daddy,esps_w_done,pid);		  pid_table[pid_slot].ipc_client_info = in_a_ipc_dispatch();		  pid_add_command(pid_slot,command_line);		  indicate_pending_process(pid_slot);		}    }    if (w_verbose)	fprintf(stderr,"(pid: %d, request: %d)\n",pid,pid_slot);    return(pid);}/***********************************************************************/int esps_w_done(client, pid, status, rusage)    Notify_client client;    int pid;    union wait *status;    struct rusage *rusage;{    int i,j;#if !defined(DEC_ALPHA) && !defined(OS5)#if defined(XOS5)    union wait status_a = *status;#endif#if defined(XOS5)     if (WIFEXITED(status_a.w_status)) {#else    if (WIFEXITED(*status)) {#endif#else      {#endif      if (debug_level)	fprintf(stderr,"esps_w_done: pid %d just finished. \n",pid);      if((i = pid_get_table_index(pid)) >= 0) {	extern Panel_item newObj_item;	panel_set_value(newObj_item, pid_table[i].oname);	if (pid_table[i].func) {	  if ((w_verbose > 2) || debug_level) 	    fprintf(stderr,"pid: %d, calling function %x\n",pid,pid_table[i].func);	  (*pid_table[i].func)(pid);	}	if (pid_table[i].out_files) { /* display signal output files */	  char **names = pid_table[i].out_files;	  for (j = 0; names[j]; j++) {	    if (w_verbose)	      fprintf(stderr,"Process %d finished, displaying file: %s\n",pid,names[j]);	    if(create_new_signal_view(names[j]))	      add_to_new_files_browser(names[j]);	      	  }	}	if (pid_table[i].text_files) { /* display text output files */	  char **names = pid_table[i].text_files;	  Frame help_win;	  for (j = 0; names[j]; j++) {	    if (w_verbose)	      fprintf(stderr,"Process %d finished, displaying file: %s\n",pid,names[j]);	    help_win = exv_make_text_window(XV_NULL, names[j], basename2(names[j]),					    names[j], 					    WITH_FIND_BUTTON, USE_FRAME_INDEP);	    if(help_win)	      add_to_new_files_browser(names[j]);	  }	}	do_ipc_response_if_any(pid_table[i].ipc_client_info, ok);	indicate_process_complete(i);	pid_clear_out_files(i);	pid_reset_entry(i);	return NOTIFY_DONE;      } else	if (w_verbose > 2)	  fprintf(stderr,"esps_w_done: pid %d not in data structure. \n",pid);      return NOTIFY_IGNORED;    }    if (w_verbose > 2)      fprintf(stderr,"esps_w_done: pid %d not WIFEXITED \n",pid);    return NOTIFY_IGNORED;}/***********************************************************************//* routine for making temporary ESPS files */char *mk_esps_temp(template){  char tpath[NAMELEN];  sprintf(tpath, "%s/%s", temp_path, template);    return(savestring(mktemp(tpath)));/* could also use   return(e_temp_name(template)); */}/* * The following functions (hash, lookup, and inc_esps_name) are  * based on code from Alan Parker's genhd.c -- js *//* very simple hash function */static inthash (s)    char    *s;{    int     sum = 0;    while (*s)	sum += *s++;    return (sum % NAME_TAB);}/* look up an entry in the hash table.   Return NULL if not found, else   return the address of the node*/static struct fname *lookup(s, tab)    char	    *s;    struct fname    *tab[];{    struct fname    *np;    spsassert(tab != NULL && s != NULL,"error in lookup");    for (np = tab[hash (s)]; np != NULL; np = np->next) 	if (strcmp(s, np->name) == 0) 	    return (np);	/* found it */    return (NULL);		/* not found */}/* check to see if file name has been used before; if not, add to    list; if so, increment the name*/char *inc_esps_name(name)    char	    *name;{    struct fname    *np,                    *lookup();    int		    hashval;    int		    i;    char	    *newname[128];    static int	    first = 1;    FILE	    *fd;    if (first) {	for (i=0; i < NAME_TAB; i++) names[i] = NULL;	first = 0;    }    np = lookup(name, names);    if (np == NULL) { /* allocate a node if this name is not defined */	np = (struct fname *) calloc(1, sizeof(*np));	spsassert(np != NULL,"calloc failed");	/* save the name */	np->name = savestring(name);	spsassert(np->name != NULL,"savestring failed");	/* insert the node into the hashtable, and set the count */	hashval = hash(np->name);	np->next = names[hashval];	names[hashval] = np;	/* if the new name is an existing file, we increment the first time*/	if ((fd = fopen(name, "r")) == NULL)	    np->num = 0;	else	{	    np->num = 1;	    fclose(fd);	}    }    else { /* we already saw this name, just increment the count */	np->num++;    }    if (np->num == 0) 	return (savestring(name));    else {	insert_numeric_ext(np->name, np->num, newname);	if (debug_level) 	    (void) fprintf(stderr, "inc_esps_name: newname = %s\n", newname);	return(savestring(newname));    }}/* this function writes the left and right marker information to    ESPS Common */ voidmarkers_to_common(v)    View    *v;			/* view in which markers were changed */{  double start, end;		/* relative times for existing markers */  int startrec, endrec;	/* esps records for existing markers */  Signal *s;  s = v->sig;  if (debug_level)    (void) fprintf(stderr, 		   "markers_to_common: function entered\n");  start = v->lmarker_time - s->start_time;  end = v->rmarker_time - s->start_time;  startrec = 1 + (int)(start*s->freq);  if (startrec < 1) startrec = 1;  endrec = 1 + (int)(end*s->freq);  if (endrec > s->file_size) endrec = s->file_size;  if (debug_level > 1)  {    (void) fprintf(stderr, 		   "markers_to_common: start = %g, end = %g\n",		   start, end);    (void) fprintf(stderr, 		   "markers_to_common: startrec = %d, endrec = %d\n",		   startrec, endrec);  }  (void) putsym_s("filename", s->name);  (void) putsym_s("prog","xwaves");  (void) putsym_i("start", (int) startrec);  (void) putsym_i("nan", (int) (endrec - startrec + 1));}typedef struct pidisplay {  int pid;  char *command;  struct pidisplay *next, *prev;};static Frame pframe = XV_NULL;static Panel ppanel = XV_NULL;static Panel_item plist = XV_NULL;static Frame cframe = XV_NULL;static void ok_command(){  xv_destroy_safe(cframe);}static void process_kill_command(item,event)     Panel_item item;     Event *event;{  int pidi = (int)xv_get(item, PANEL_CLIENT_DATA);  if(pid_table[pidi].pid > 0) {    kill(pid_table[pidi].pid,SIGKILL);    kill(pid_table[pidi].pid+1,SIGKILL);    do_ipc_response_if_any(pid_table[pidi].ipc_client_info, ok);    indicate_process_complete(pidi);    pid_clear_out_files(pidi);    pid_reset_entry(pidi);  }  xv_destroy_safe(cframe);  cframe = XV_NULL;}void show_pending_command(item, string, client_data, op, event, row)     Panel_item item;     char *string;     caddr_t client_data;     Panel_list_op op;     Event *event;     int row;{  Panel panel;  int pidi = (int)client_data;  cframe = (Frame)xv_create(pframe,FRAME,FRAME_SHOW_HEADER, FALSE,			    XV_SHOW, FALSE, XV_X, 5, XV_Y, 5, NULL);  panel = (Panel)xv_create(cframe, PANEL, NULL);  xv_create(panel, PANEL_MESSAGE,	    PANEL_LABEL_STRING, pid_table[pidi].command,	    PANEL_LABEL_BOLD, TRUE,	    NULL);  xv_create(panel, PANEL_BUTTON,	    PANEL_NEXT_ROW, -1,	    PANEL_LABEL_STRING, "OK",	    PANEL_NOTIFY_PROC, ok_command,	    NULL);  xv_create(panel, PANEL_BUTTON,	    PANEL_LABEL_STRING, "Kill This Process",	    PANEL_CLIENT_DATA, pidi,	    PANEL_NOTIFY_PROC, process_kill_command,	    NULL);  window_fit(panel);  window_fit(cframe);  xv_set(cframe, XV_SHOW, TRUE, NULL);}Notify_valuepframe_destroy_func(client, status)     Notify_client client;     Destroy_status status;{    if (status == DESTROY_CHECKING) {	}    else  if (status == DESTROY_CLEANUP) {      plist = XV_NULL;        return notify_next_destroy_func(client, status);	}    else if (status == DESTROY_SAVE_YOURSELF) {	}    else {      plist = XV_NULL;	}	    return NOTIFY_DONE;}void create_plist(pidi)     int pidi;{  char digits[10];  sprintf(digits,"%d",pid_table[pidi].pid);  pframe = (Frame)xv_create(XV_NULL,FRAME, XV_SHOW, FALSE,			    XV_X, 22, XV_Y, 22, NULL);  ppanel = (Panel)xv_create(pframe,PANEL,NULL);  plist = xv_create(ppanel, PANEL_LIST,                     XV_X, 22,                     XV_Y, 22,                    PANEL_LIST_WIDTH, 75,                     PANEL_LIST_DISPLAY_ROWS, 3,                     PANEL_LABEL_STRING, "PENDING:",                     PANEL_LAYOUT, PANEL_VERTICAL,                     PANEL_READ_ONLY, TRUE,                     PANEL_CHOOSE_ONE, TRUE,                     PANEL_CHOOSE_NONE, TRUE,                     PANEL_NOTIFY_PROC, show_pending_command,                     NULL);  xv_set(plist,       PANEL_LIST_STRING, 0, digits,       PANEL_LIST_CLIENT_DATA, 0, pidi,       NULL);  notify_interpose_destroy_func(pframe, pframe_destroy_func);  xv_set(pframe, XV_SHOW, TRUE, 0);   window_fit(ppanel);  window_fit(pframe);}void add_to_plist(pidi)     int pidi;{  if(plist) {    int n = xv_get(plist, PANEL_LIST_NROWS);    char digits[10];        sprintf(digits,"%d",pid_table[pidi].pid);    xv_set(plist,PANEL_LIST_INSERT, n,	   PANEL_LIST_STRING, n, digits,	   PANEL_LIST_CLIENT_DATA, n, pidi,	   NULL);    if(n == 0)      xv_set(pframe, XV_SHOW, TRUE, 0);  }}indicate_process_complete(pidi)     int pidi;{  extern int show_processes;  if(show_processes && plist) {    int n = xv_get(plist, PANEL_LIST_NROWS);    int i;    for(i=0; i < n; i++) {      if((int)xv_get(plist, PANEL_LIST_CLIENT_DATA, i) == pidi) {	xv_set(plist, PANEL_LIST_DELETE, i, NULL);	if(n <= 1) {	  xv_set(pframe, XV_SHOW, FALSE, 0);	  if(cframe) {	    xv_destroy_safe(cframe);	    cframe = XV_NULL;	  }	}	return;      }    }  }}indicate_pending_process(pidi)     int pidi;{  extern int show_processes;  if(show_processes) {    if(!plist)      create_plist(pidi);    else      add_to_plist(pidi);  }}

⌨️ 快捷键说明

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