📄 xlabel.c
字号:
/* Copyright (c) 1995 Entropic Research Laboratory, Inc. *//* * 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-1995 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: David Talkin * Checked by: * Revised by: Alan Parker for ERL * * Brief description: * */static char *sccs_id = "@(#)xlabel.c 1.42 2/2/98 ERL";/* xlabel.c *//* a waveform labeler to be used with programs like "xwaves" *//* (designed to be used as an "attachment") */#ifdef hp400#include <string.h>#endif#ifndef hpux#include <sys/param.h>#else#define MAXPATHLEN 1024#endif#include <Objects.h>#include <wave_colors.h>#include <labels.h>#include <charts.h>#include <xview/font.h>#include <xview/notice.h>#include <esps/esps.h>#include <esps/exview.h>#include <esps/epaths.h>#define _NO_PROTO#include <Xp.h>#include <Xp_pw.h>#include <xprint_util.h>#define DELETE '\177'#define DEBUG(x) if(debug_level > x) fprintf#define SYNTAX USAGE("xlabel [-w wave_pro] [-n<waves or other host program>] [-c<registry name of host>] ");static char *wave_pro = ".wave_pro"; /* .wave_pro file name from command line */Event pseudo_event;int debug_level = 0;int command_paused = 0, da_location = 0;Canvas global_canvas; /* used by meth_print routine *//* from globals.c */extern int print_graphic_printer;extern int print_graphic_resolution;extern char print_graphic_orientation[];extern char print_graphic_type[];extern char print_graphic_file[];extern char print_graphic_command[];extern double print_graphic_scale;extern char *Version;extern char *registry_name;char *meth_print(), *basename();Label *get_nearest_label();Labelfile *get_labelfile();Pixfont *xv_pf_open();extern Visual *visual_ptr;/*********************************************************************/Panel_item temp_item, file_item, object_item, active_item, menu_item, chart_item, top_word_item;void quit_proc(), newFile();Frame daddy = XV_NULL; /* global reference in xprint_setup.c and xnotice.c */Panel panel;/* These globals (in globals.c) are a means of control via the .wave_pro */int xlab_ctlwin_y = -1; /* initial Y pos of xlabel control window */int xlab_ctlwin_x = -1; /* initial X pos of xlabel control window */extern char inputname[], objectname[];extern u_char red[], blue[], green[];static int wind_height = 80; /* Vertical space allocated for each label file. *//* Fudge factors to allow user control of frame offsets to compensatefor unmanageable window manager decorations. */static int xlabel_frame_voff = 33, xlabel_frame_hoff = 0;static int insert_mode = 1; /* 0==REPLACE; 1==INSERT; 2==MOVE */int replace_field = 1;/*global declarations for default font*/Xv_Font def_font = XV_NULL;int def_font_height, def_font_width; int use_dsp32; /* referred to in globals.c */double image_clip = 7.0, image_range = 40.0;char *Ok="ok", *Null="null";char fontfile[MAXPATHLEN]= "";char active[200] = "1";char menufile[MAXPATHLEN] = "labelmenu.def";char chartname[MAXPATHLEN] = "";char topword[NAMELEN] = "";char chartmenu[MAXPATHLEN] = "chartmenu";char *host = "waves", *thisprog = "xlabel";#if !defined(hpux) && !defined(DS3100) && !defined(DEC_ALPHA)char *malloc();#endifint exv_get_help();void remove_cursor();void add_cursor();void label_menu_proc(), done_proc();Notify_value kill_signal_view();Objects *program;static Selector g70 = {"xlabel_ctlwin_y", "%d", (char *) &xlab_ctlwin_y, NULL}, g69 = {"xlabel_ctlwin_x", "%d", (char *) &xlab_ctlwin_x, &g70}, gg0 = {"xlabel_label_height", "%d", (char*)&wind_height, &g69}, gg1 = {"xlabel_menufile", "#qstr", menufile, &gg0}, gg2c = {"xlabel_frame_voff", "%d", (char*) &xlabel_frame_voff, &gg1}, gg2b = {"xlabel_frame_hoff", "%d", (char*) &xlabel_frame_hoff, &gg2c}, gg2 = {"xlabel_fields", "#strq", active, &gg2b}, gg3b = {"xlabel_name", "#qstr", objectname, &gg2}, gg3d = {"xlabel_font", "#qstr", fontfile, &gg3b}, gg3 = {"xlabel_insert_mode", "%d", (char*)&insert_mode, &gg3d}, gg4c = {"xchart_top_word", "#qstr", topword, &gg3}, gg4b = {"xchart_chartfile", "#qstr", chartname, &gg4c}, gg4a = {"xchart_chartmenu", "#qstr", chartmenu, &gg4b}, gg4 = {"xlabel_labelfile", "#qstr", inputname, &gg4a}, g0 = {"label_height", "%d", (char*)&wind_height, &gg4}, g1 = {"menufile", "#qstr", menufile, &g0}, g2b = {"active_fields", "#strq", active, &g1}, g2 = {"fields", "#strq", active, &g2b}, g3c = {"insert_mode", "%d", (char*)&insert_mode, &g2}, g3b = {"object", "#qstr", objectname, &g3c}, g3d = {"name", "#qstr", objectname, &g3b}, g3 = {"font", "#qstr", fontfile, &g3d}, g4c = {"top_word", "#qstr", topword, &g3}, g4b = {"chartfile", "#qstr", chartname, &g4c}, g4a = {"chartmenu", "#qstr", chartmenu, &g4b}, g4 = {"labelfile", "#qstr", inputname, &g4a}; static double m_time, sec_cm, start, rend, rstart; static int color, width, height, loc_x, loc_y; static char signame[NAMELEN]; static int type = 0, nfields = 1; static char sep; static char comment[500]; static Selector a12 = {"signal", "#qstr", signame, &g4}, la1 = {"separator", "%c", &sep, &a12}, la2 = {"type", "%d", (char*)&type, &la1}, la3b = {"nfields", "%d", (char*)&nfields, &la2}, la6 = {"comment", "#strq", comment, &la3b}, a11 = {"rend", "%lf", (char*)&rend, &la6}, a10 = {"rstart", "%lf", (char*)&rstart, &a11}, a9 = {"sec/cm", "%lf", (char*)&sec_cm, &a10}, a8 = {"start", "%lf", (char*)&start, &a9}, a7 = {"width", "%d", (char*)&width, &a8}, a6 = {"height", "%d", (char*)&height, &a7}, a5 = {"loc_y", "%d", (char*)&loc_y, &a6}, a4 = {"loc_x", "%d", (char*)&loc_x, &a5}, a3 = {"color", "%d", (char*)&color, &a4}, a2 = {"time", "%lf", (char*)&m_time, &a3}, a0 = {"file", "#qstr", inputname, &a2};/*********************************************************************/Pixfont*get_default_label_font(){ Pixfont *xv_pf_default(); return(xv_pf_default());}/*********************************************************************/Pixfont*open_label_font(name) char *name;{ return(xv_pf_open(name));}/*********************************************************************/window_wash(handle) caddr_t handle;{ if(handle) return; fprintf(stderr,"Xview can't create a window; sorry...\n"); exit(-1);}/*********************************************************************/Menu make_menu(menufile, nitems, proc) void (*proc)(); char *menufile; int *nitems;{ static char text[MES_BUF_SIZE]; Menu menu; int i, nargs; char item[200], str[NAMELEN], *it, *st; FILE *fp, *fopen(); Pixfont *pf = NULL; static int rows, cols; static Selector a3 = {"font", "#qstr", fontfile, NULL}, a2 = {"rows", "%d", (char*)&rows, &a3}, a1 = {"columns", "%d", (char*)&cols, &a2}; if((fp = fopen(menufile,"r")) && fgets(text,MES_BUF_SIZE,fp)) { Pixfont *xv_pf_open(), *xv_pf_default(); rows = cols = -1; *nitems = 0; nargs = get_args(text,&a1); /* ASSUMES ALL ATTRIBUTES ON FIRST LINE! */ if(*fontfile) { if(!(pf = xv_pf_open(fontfile))) { sprintf(notice_msg, "make_menu(): Can't open fontfile %s; using default.", fontfile); show_notice(0, notice_msg); } } if(!pf) pf = xv_pf_default(); menu = xv_create(XV_NULL, MENU, XV_FONT, pf, MENU_NOTIFY_PROC, proc, MENU_DONE_PROC, done_proc, 0); window_wash(menu); do { if(!nargs) { /* !nargs means first row was menu data (not col/row spec.) */ sscanf(text,"%s%s",item,str); if(!((it = malloc(strlen(item)+1)) && (st = malloc(strlen(str)+1)))) { show_notice(1, "Can't allocate mem for menu strings."); return(FALSE); } strcpy(it,item); strcpy(st,str); xv_set(menu, XV_FONT, pf, MENU_STRING_ITEM, it, st, 0, 0); /* Knowing Sunview, this probably results in lots of little lost memory fragments, even after menu_destroy()... i.e. the it's and str's need to be freed! What a crock. */ (*nitems)++; } nargs = 0; } while(fgets(text,MES_BUF_SIZE,fp)); fclose(fp); if(*nitems) { if(cols == -1) { if(rows > 0) { cols = *nitems/rows; if (*nitems%rows) cols++; } else cols = (int)sqrt((double)*nitems); } if(rows == -1) rows = *nitems/cols; while((cols * rows) < *nitems) rows++; xv_set(menu, MENU_NCOLS, cols, MENU_NROWS, rows, 0); } return(menu); } return(0);}/*********************************************************************/make_labels_menu(lf) Labelfile *lf;{ char text[256]; int i, j, nitems = 0, itsok = FALSE; int rows, cols; Menu mtmp = (Menu)0; if (!FIND_WAVES_MENU(menufile,menufile)) { (void) sprintf(notice_msg, "xlabel: couldn't find menufile %s.", menufile); show_notice(1, notice_msg); return(FALSE); } if((mtmp = make_menu(menufile,&nitems,label_menu_proc))) { itsok = TRUE; if(lf->menu) menu_destroy(lf->menu); lf->menu = mtmp; } else return(FALSE); /* Insure that menu font matches the labelfile font. If both were specified, menu font overrides. */ if(*fontfile && strcmp(fontfile,lf->fontfile)) { Pixfont *xv_pf_open(); strcpy(lf->fontfile,fontfile); lf->font = xv_pf_open(fontfile); plot_labels(lf); } else /* make menu look like label file */ if((! *fontfile) && *(lf->fontfile)) xv_set(lf->menu,XV_FONT,lf->font,0); if(!nitems) { /* make a default (probably useless) menu */ itsok = FALSE; rows = 8; cols = 8; for(i = 0, j = 65; i < 127;) { text[i] = j++; text[i+1] = 0; xv_set(lf->menu, MENU_STRING_ITEM, &text[i], &text[i],0,0); i += 2; } xv_set(lf->menu, MENU_NCOLS, cols, MENU_NROWS, rows, 0); } return(itsok);}/*********************************************************************/time_to_x(ob,time) Objects *ob; double time;{ return((int)(.5 + (PIX_PER_CM * ((time - ob->start)/ob->sec_cm))) + ob->x_off);}/*********************************************************************/double x_to_time(ob,x) Objects *ob; int x;{ x -= ob->x_off; if(x < 0) x = 0; return(ob->start + (double)x * ob->sec_cm / PIX_PER_CM);}/*********************************************************************/char *exec_waves(str) char *str;{ extern char *dispatch(); return(dispatch(str));}/*********************************************************************/char *get_receiver_name(ob) Objects *ob;{ return(ob->name);}/*********************************************************************/char *get_methods(ob) Objects *ob;{ extern Methods base_methods; if(ob) return((char*)(ob->methods)); return((char*)&base_methods);}/*********************************************************************/char *get_receiver(str) char *str;{ Objects *ob; static char name[NAMELEN]; extern Objects *objlist; ob = objlist; if(str && strlen(str)) { sscanf(str,"%s",name); while(ob) { if(ob->name && (! strcmp(ob->name, name))) { return((char*)ob); } ob = ob->next; } } return(NULL);}Notify_valuedestroy_func(client, status)Notify_client client;Destroy_status status;{ DEBUG(1) (stderr,"Inside of destroy_func.\n"); if (status == DESTROY_CHECKING) { } else if (status == DESTROY_CLEANUP) { DEBUG(1) (stderr,"Inside of destroy_func. CLEANUP\n"); quit_proc(); return notify_next_destroy_func(client, status); } else if (status == DESTROY_SAVE_YOURSELF) { } else { DEBUG(1) (stderr,"Inside of destroy_func. DEATH\n"); quit_proc(); } return NOTIFY_DONE;}extern int optind; /* for use of getopt() */extern char *optarg; /* for use of getopt() */extern int fullscreendebug;/*********************************************************************/char *generate_startup_command(registry) char *registry;{ static char com[MES_BUF_SIZE]; sprintf(com,"add_op name %s op #send function %s registry %s command _name mark signal _file time _cursor_time", basename(thisprog), thisprog, registry); return(com);}static char env_str[MAXPATHLEN+20];/*********************************************************************//*********************************************************************/main(ac, av) int ac; char **av;{ Frame frame; static void doit(); extern Objects *objlist, *new_objects(); extern Methods base_methods; extern int attachment; char mess[MES_BUF_SIZE]; int i, locx, locy; extern int optind; extern char *optarg; int ch; char *server_name = "xwaves"; extern Display *X_Display; extern Window comm_window; extern void identify_visual(); fullscreendebug = 1; /* this global inhibits server grabs that cause problems on the SGI */ thisprog = av[0]; while ((ch = getopt(ac, av, "w:n:c:")) != EOF) switch (ch) { case 'n': host = optarg; break; case 'w': wave_pro = optarg; break; case 'c': server_name = optarg; break; default: SYNTAX if(debug_level) for(ch = 0; ch < ac; ch++) fprintf(stderr,"%s ",av[ch]); fprintf(stderr,"\n"); exit(-1); } attachment = TRUE; /* make cmap create static colormap segment */ event_init(&pseudo_event); event_id(&pseudo_event) = MS_RIGHT; def_font = (Xv_Font) xv_find(XV_NULL, FONT, FONT_FAMILY, FONT_FAMILY_DEFAULT_FIXEDWIDTH, 0); def_font_width = (int) xv_get(def_font, FONT_DEFAULT_CHAR_WIDTH); def_font_height = (int) xv_get(def_font, FONT_DEFAULT_CHAR_HEIGHT); get_all_globals(wave_pro, &g4); sprintf(env_str,"XPPATH=%s/lib/Xp",get_esps_base(NULL)); putenv(env_str);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -