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

📄 part02

📁 speech signal process tools
💻
📖 第 1 页 / 共 4 页
字号:
#! /bin/sh# This is a shell archive, meaning:# 1. Remove everything above the #! /bin/sh line.# 2. Save the resulting text in a file.# 3. Execute the file with /bin/sh (not csh) to create the files:#	sf.c form.c load.c field.c selection.c keyword.c option.c#	msg.c term.c io.c summary.cexport PATH; PATH=/bin:$PATHecho shar: extracting "'sf.c'" '(4115 characters)'if test -f 'sf.c'then	echo shar: will not over-write existing file "'sf.c'"elsesed 's/^X//' << \SHAR_EOF > 'sf.c'X/**************************************************************************X*X* File name:	sf.cX*X* Author:	Paul Lew, General Systems Group, Inc. Salem NHX* Created at:	05/08/86  10:11 AMX* Last update:	02/08/88  00:23 AM  (Edition: 29)X*X* Description:	This program will take standard input  (if no argumentX*		specified in  command line) or  the specified  file asX*		form  template and  display   it  on  the terminal  toX*		perform basic form editing function.  It then generateX*		the Csh  or Bourne shell set script  on  stdout  to beX*		executed (ala tset -s).X*X*		This program is designed to  give programmer  an  easyX*		way of doing form filling in shell level.X*X* Update History:X*X*    Date	Modification Description				ByX*  --------	------------------------------------------------------	---X*  05/08/86	Initial version						LewX*  08/04/87	added Help_display flag					LewX*  12/29/87	modify to add Bourne shell output flag, use getopt()	LewX*  01/12/88	added init_sno(), added CTRL L redisplay function,	LewX*		added signal trap handling.X*  01/26/88	added AUTOTAB at end of a field, added NUMERIC field	LewX*		attributeX*  02/08/88	modified to add perl script output flag			LewX*X***************************************************************************/X#define	EXTERNX#include	<stdio.h>X#include	<ctype.h>X#include	"form.h"X#include	"basic.h"XXchar	*Version = "1.8  02/08/88  00:21 AM";Xchar	*Bugs = "Bug report send to: decvax!gsg!lew (UUCP)";Xchar	*Copyright = "Copyright by Paul Lew (1987,1988) All rights reserved";Xchar	*Prgname;			/* program name */XXextern	unsigned char	Shell;Xextern	int		Help_display;Xint			Debug = NO;XX/*------------------------------------------------------------07/13/84--+X|									|X|	    M a i n    R o u t i n e    S t a r t s    H e r e		|X|									|X+----------------------------------------------------------------------*/Xmain (argc, argv)Xint	argc;		/* number of argument passed */Xchar	**argv;		/* pointer to argument list */X	{X	int		n;		/* number of files (so far 2)	*/X	char		*fname;		/* form file name */XX	Prgname = *argv;X	n = procarg (argc, argv);X	if (n == argc) fname = NULL;	/* read from stdin if no input	*/X	else fname = argv[n];X	edit_form (fname, (int (*)())NULL);X	exit (0);X	}XX/*----------------------------------------------------------------------+X|									|X|	proc_arg : process input argument and set global flags		|X|									|X+----------------------------------------------------------------------*/Xprocarg (argc, argv)Xint	argc;Xchar	**argv;X	{X	int		rvideo = 0;X	int		undline = 0;X	int		hilite = 0;X	char		*fname = NULL;X	int		c;X	extern	char	*optarg;	/* ptr to argument */X	extern	int	optind;		/* remember which one to process next */XX	ENTER (procarg);X	while ((c = getopt (argc, argv, "Hbdhmo:pru")) != EOF) {X		switch (c) {X			when 'b': Shell = BOURNE;X			when 'd': Debug = YES;X			when 'h': hilite = YES;X			when 'm': Help_display = YES;X			when 'o': fname = optarg;X			when 'p': Shell = PERL;X			when 'r': rvideo = YES;X			when 'u': undline = YES;X			otherwise:help ();X				  exit (1);X			}X		}X	set_options (hilite, rvideo, undline, fname);X	RETURN (optind);X	}XX/*-------------------------------------------------------------05/08/86-+X|									|X|		       help : display help message			|X|									|X+----------------------------------------------------------------------*/Xhelp ()X	{X	ENTER(help);X	fprintf (stderr, "%s Version %s\r\n", Prgname, Version);X	fprintf (stderr, "Command Options:\r\n");X	fprintf (stderr, "  -H        display this help message\r\n");X	fprintf (stderr, "  -b        generate Bourne shell output [Csh]\r\n");X	fprintf (stderr, "  -d        debug mode, will show CTRL chars\r\n");X	fprintf (stderr, "  -h        input in highlight mode\r\n");X	fprintf (stderr, "  -m        display selection help automatically\r\n");X	fprintf (stderr, "  -o file   use file as output file\r\n");X	fprintf (stderr, "  -p        generate perl script output\r\n");X	fprintf (stderr, "  -r        input in reverse video mode\r\n");X	fprintf (stderr, "  -u        input in underline mode\r\n");X	EXIT;X	}SHAR_EOFif test 4115 -ne "`wc -c < 'sf.c'`"then	echo shar: error transmitting "'sf.c'" '(should have been 4115 characters)'fifi # end of overwriting checkecho shar: extracting "'form.c'" '(5898 characters)'if test -f 'form.c'then	echo shar: will not over-write existing file "'form.c'"elsesed 's/^X//' << \SHAR_EOF > 'form.c'X/* Last update: 02/08/88  00:18 AM  (Edition: 56) */X#include	<stdio.h>X#include	<ctype.h>X#include	<signal.h>X#include	"form.h"X#include	"field.h"X#include	"term.h"X#include	"basic.h"XXchar	Screen [SCRLINE][SCRCOL+1];Xchar	Form_name[20] = "";		/* current form name */Xchar	Exitc;				/* field exit char */X Xchar	Enter_mode [20];		/* display before input field */Xchar	Exit_mode [20];			/* display after input field */XXstruct	field	Field[MAXFIELD];	/* field nodes */Xint		Fno;			/* next field to use (or count) */Xunsigned char	Fhead[SCRLINE];		/* 1st field index on each line */Xunsigned char	Flcount[SCRLINE];	/* number of fields on this line */Xunsigned char	Lastdata = 24;		/* last line with data on form */XXchar	Varfile [MAXFNAME];		/* output variable file name */XXextern	int		Form_msg;	/* defined in msg.c */Xextern	unsigned char	Shell;		/* output shell script type */XXint	sig_interrupt();Xint	sig_stop();XX/*----------------------------------------------------------------------+X|									|X|		show_form : display a given form file			|X|									|X+----------------------------------------------------------------------*/Xshow_form (fname)Xchar	*fname;		/* name of form file, NULL = stdin, 1 = redisplay */X	{X	int		i, j;X	int		idx;		/* index to current field */X	unsigned	size;X	unsigned	off;X	unsigned	len;		/* string length */X	int		pend;		/* previous end position */X	char		*lp;		/* line pointer (for speed) */X	char		*p;X	extern	char	*Prgname;XX	ENTER(show_form);X	if (fname != (char *)1 &&		/* redisplay */X	    (fname == NULL || strcmp (fname, Form_name) != 0)) {X		if (!load_form (fname)) RETURN (0);X		}XX	screen (SCR_ERASE);X	for (i=0; i<SCRLINE; i++) {X		p = lp = Screen[i];X		if (Flcount[i] != 0) {X			pend = 0;X			for (j=0, idx=Fhead[i]; j<Flcount[i]; j++, idx++) {X				size = Field[idx].f_len;X				off = Field[idx].f_off;X				put_string (p, off-pend);X				put_string (Enter_mode, 0); X				put_string (lp + off, size);X				put_string (Exit_mode, 0);X				p = lp + off + size;X				pend = off + size;X				}X			}X		if ((len = strlen (p)) == 0) continue;X		put_string (p, len);X		put_char ('\r');X		}X	RETURN (1);X	}XX/*----------------------------------------------------------------------+X|									|X|	   edit_form : edit a form on all the input fields		|X|									|X+----------------------------------------------------------------------*/Xedit_form (fname, action)Xchar	*fname;		/* name of the form to edit */Xint	(*action) ();	/* action routine to check at end of each field */X	{X	unsigned	fdx = 0;	/* current cursor in field index */X	struct	field	*fp;		/* pointer to current edit field */X	int		n;		/* action routine return status */X	int		efopt;		/* option to edit field */XX	ENTER(edit_form);X	signal (SIGINT, sig_interrupt);X	signal (SIGTSTP, sig_stop);XX	term_init ();X	cbreakio (1);X	if (!show_form (fname)) goto end;X	if (Fno == 0) goto end;X X	form_msg ((char *)NULL, 1, 1);X	screen (SCR_KEYXMIT);X	while (1) {X		fp = &Field[fdx];X		efopt = EF_BOF;X		do	{X			if (fp->f_attr & FA_SELECTION) sel_field (fdx);X			else edit_field (fdx, efopt);X			if (!action) break;X			n = (*action) (fdx, &Screen[fp->f_line-1][fp->f_off],X					fp->f_len, Exitc);X			switch (n) {X				when EF_ERR:	efopt = EF_BOF;X				when EF_FILL:	efopt = EF_FILL;X				}X			} while (n != EF_OK);X X		if ((Exitc & 0x80) == 0x80) {X			switch (Exitc & 0x7f) {X				when KU:	Exitc = CTRL('P');X				when KD:	Exitc = CTRL('N');X				}X			}X		switch (Exitc) {X			when CTRL('L'):	show_form ((char *)1);X			when CTRL('M'): goto wrout;X			when CTRL('J'):	goto wrout;X			when CTRL('P'):	fdx = closest (fdx, -1);X			when CTRL('N'):	fdx = closest (fdx, 1);X			when CTRL('T'): fdx = (fdx == 0) ? Fno-1 : (fdx-1);X			when CTRL('I'): if (++fdx == Fno) fdx = 0;X			otherwise:	show_summary ();X					show_form ((char *)1);X			}X		}Xwrout:	write_var ();X	poscur (Lastdata, (unsigned char)1, "\n"); screen (SCR_EEOL);Xend:X	screen (SCR_NOKEYXMIT);X	cbreakio (0);X	term_close ();X	EXIT;X	}XX/*-------------------------------------------------------------05/08/86-+X|									|X|	       write_var : write field variables to a file		|X|									|X+----------------------------------------------------------------------*/Xwrite_var ()X	{X	register int	i;X	FILE		*fd;		/* output file pointer */X	char		*p;X	char		*op;X	char		c;X	char		buf[80+1];X	char		obuf[80+1];X	struct	field	*f;XX	ENTER(write_var);X	if (!strlen (Varfile)) EXIT;XX	if ((fd = fopen (Varfile, "w")) == NULL) {X		fprintf (stderr, "write_var: can not open file %s for write\r\n",X			 Varfile);X		exit (1);X		}XX	for (i=0; i<Fno; i++) {X		f = &Field[i];X		if (f-> f_var != NULL) {X			get_field (i, buf);X			p = buf;  op = obuf;X			while (c = *p++) {X				switch (c) {X				    when '\'':	if (Shell== PERL) *op++ = '\\';X						else	{X							*op++ ='\'';*op++ ='"';X							*op++ ='\'';*op++ ='"';X							}X				    when '!':	if (Shell == CSH) *op++ = '\\';X				    }X				*op++ = c;X				}X			*op = EOS;X			fprintf (fd, "%s%s='%s'%s\n",X				 (Shell==CSH)?"set ":((Shell==PERL)?"$":""),X				 f-> f_var, obuf,X				 (Shell == PERL) ? ";" : "");X			}X		}X	fclose (fd);X	EXIT;X	}XX/*-------------------------------------------------------------01/12/88-+X|									|X|		 sig_interrupt : Interrupt signal handler		|X|									|X+----------------------------------------------------------------------*/Xsig_interrupt ()X	{X	ENTER (sig_interrupt);X	form_msg ("Aborted by user\n", 24+1, 1);X	screen (SCR_NORMAL);X	cbreakio (1);X	exit (1);X	}XX/*-------------------------------------------------------------01/12/88-+X|									|X|		      sig_stop : Stop signal handler			|X|									|X+----------------------------------------------------------------------*/Xsig_stop ()X	{X	ENTER (sig_stop);X	form_msg ("stopped by user\n", 24+1, 1);X	screen (SCR_NORMAL);X	cbreakio (0);X	kill (getpid(), SIGSTOP);X	put_string ("Press CTRL L to refresh display: ", 33);X	cbreakio (1);X	}SHAR_EOFif test 5898 -ne "`wc -c < 'form.c'`"then	echo shar: error transmitting "'form.c'" '(should have been 5898 characters)'fifi # end of overwriting checkecho shar: extracting "'load.c'" '(8779 characters)'if test -f 'load.c'then	echo shar: will not over-write existing file "'load.c'"elsesed 's/^X//' << \SHAR_EOF > 'load.c'X/* Last update: 01/26/88  10:53 PM  (Edition: 63) */X#include	<stdio.h>X#include	<strings.h>X#include	"form.h"X#include	"field.h"X#include	"basic.h"XX#define	TOKENSIZE	256XXchar	Varname [MAXVNAME];		/* variable name string pool */Xchar	*Varwp = Varname;		/* next write position */XXextern	char		Screen[SCRLINE][SCRCOL+1];Xextern	char		Form_name[];Xextern	unsigned char	Fhead[];	/* 1st field index on each line */Xextern	unsigned char	Flcount[];	/* number of fields on this line */Xextern	unsigned char	Lastdata;Xextern	struct	field	Field[];	/* field nodes */Xextern	int		Fno;		/* next field to use (or count) */XX/*----------------------------------------------------------------------+X|									|X|		load_form : load a form from disk file			|X|									|X+----------------------------------------------------------------------*/Xload_form (fname)Xchar	*fname;X	{X	FILE			*fp;X	register unsigned char	i;XX	ENTER (load_form);X	if (fname == NULL) fp = stdin;X	else if ((fp = fopen (fname, "r")) == 0) {X		fprintf (stderr, "Can not open form file %s\r\n", fname);X		RETURN (0);X		}X	for (i=0; i<SCRLINE; i++) Screen[i][0] = '\0';X	init_field ();X	for (i=0; i<SCRLINE; i++) {X		if (fgets (Screen[i], SCRCOL+1, fp) == 0) break;X		if (Screen[i][0] == CTRL('L')) {X			Screen[i][0] = EOS;X			field_attr (fp);X			break;X			}X		make_field (i+1, Screen[i]);X		}X	init_sno ();		/* fill data for field with selections */X	Lastdata = i;X	if (fname != NULL) {X		strcpy (Form_name, fname);X		}X	RETURN (1);X	}XX/*----------------------------------------------------------------------+X|									|X|    bcopy : copy len byte from src to dest (extra fill with blanks)	|X|									|X+----------------------------------------------------------------------*/Xbcopy (dest, src, len)Xchar		*dest;Xchar		*src;Xunsigned	len;X	{X	char		c = ' ';XX	ENTER (bcopy);X	while (len-- != 0) {X		if (c == EOS) *dest++ = ' ';	/* fill blanks to end */X		else if ((c = *src++) != EOS)X			*dest++ = c;X		else	*dest++ = ' ';X		}X	EXIT;X	}XX/*-------------------------------------------------------------05/08/86-+X|									|X|	   add_var : add a variable name to field structure		|X|									|X+----------------------------------------------------------------------*/Xadd_var (fno, name)Xint	fno;Xchar	*name;X	{X	int		len = strlen (name) + 1;XX	ENTER (add_var);X	if (Varwp + len >= &Varname[MAXVNAME]) {X		fprintf (stderr, "add_var: no more space for variable name\r\n");X		exit (1);X		}X	Field[fno].f_var = Varwp;X	strcpy (Varwp, name);X	Varwp += len;X	EXIT;X	}XX/*-------------------------------------------------------------05/08/86-+X|									|X|	  field_attr : read in field attribute of the form		|X|									|X+----------------------------------------------------------------------*/Xfield_attr (fd)XFILE	*fd;X	{X	int		field = -1;X	char		tokbuf [TOKENSIZE];	/* token value */X	char		token;			/* token specifier */X	int		i, n;X	unsigned	len, size;X	struct	field	*f;X	char		*p;

⌨️ 快捷键说明

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