Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/qsubst Some KNF, via indent(1) and hand work. Still ...
details: https://anonhg.NetBSD.org/src/rev/7dd8b49ecae4
branches: trunk
changeset: 540266:7dd8b49ecae4
user: perry <perry%NetBSD.org@localhost>
date: Sun Dec 08 21:29:27 2002 +0000
description:
Some KNF, via indent(1) and hand work. Still needs a lot of cleanup.
diffstat:
usr.bin/qsubst/qsubst.c | 855 ++++++++++++++++++++++++-----------------------
1 files changed, 428 insertions(+), 427 deletions(-)
diffs (truncated from 921 to 300 lines):
diff -r 76e9c4fbac37 -r 7dd8b49ecae4 usr.bin/qsubst/qsubst.c
--- a/usr.bin/qsubst/qsubst.c Sun Dec 08 20:19:56 2002 +0000
+++ b/usr.bin/qsubst/qsubst.c Sun Dec 08 21:29:27 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: qsubst.c,v 1.4 2001/04/22 05:35:35 simonb Exp $ */
+/* $NetBSD: qsubst.c,v 1.5 2002/12/08 21:29:27 perry Exp $ */
/*
* qsubst -- designed for renaming routines existing in a whole bunch
@@ -124,8 +124,8 @@
static char *str2;
static int s1l;
static int s2l;
-static long nls[MAX_C_A+1];
-static char buf[(BUF_SIZ*2)+2];
+static long nls[MAX_C_A + 1];
+static char buf[(BUF_SIZ * 2) + 2];
static char *bufp;
static char *bufp0;
static char *bufpmax;
@@ -145,475 +145,476 @@
static char cap_buf[1024];
static struct termios orig_tio;
-static void tstp_self(void)
+static void
+tstp_self(void)
{
- void (*old_tstp)(int);
- int mask;
+ void (*old_tstp) (int);
+ int mask;
- mask = sigblock(0);
- kill(getpid(),SIGTSTP);
- old_tstp = signal(SIGTSTP,SIG_DFL);
- sigsetmask(mask&~sigmask(SIGTSTP));
- signal(SIGTSTP,old_tstp);
+ mask = sigblock(0);
+ kill(getpid(), SIGTSTP);
+ old_tstp = signal(SIGTSTP, SIG_DFL);
+ sigsetmask(mask & ~sigmask(SIGTSTP));
+ signal(SIGTSTP, old_tstp);
}
/* ARGSUSED */
-static void sigtstp(int sig)
+static void
+sigtstp(int sig)
{
- struct termios tio;
+ struct termios tio;
- if (tcgetattr(0,&tio) < 0)
- { tstp_self();
- return;
- }
- tcsetattr(0,TCSAFLUSH|TCSASOFT,&orig_tio);
- tstp_self();
- tcsetattr(0,TCSADRAIN|TCSASOFT,&tio);
+ if (tcgetattr(0, &tio) < 0) {
+ tstp_self();
+ return;
+ }
+ tcsetattr(0, TCSAFLUSH | TCSASOFT, &orig_tio);
+ tstp_self();
+ tcsetattr(0, TCSADRAIN | TCSASOFT, &tio);
}
-static void limit_above_below(void)
+static void
+limit_above_below(void)
{
- if (cabove > MAX_C_A)
- { cabove = MAX_C_A;
- }
- if (cbelow > MAX_C_B)
- { cbelow = MAX_C_B;
- }
+ if (cabove > MAX_C_A) {
+ cabove = MAX_C_A;
+ }
+ if (cbelow > MAX_C_B) {
+ cbelow = MAX_C_B;
+ }
}
-static int issymchar(char c)
+static int
+issymchar(char c)
{
- return( isascii(c) &&
- ( isalnum(c) ||
- (c == '_') ||
- (c == '$') ) );
+ return (isascii(c) && (isalnum(c) || (c == '_') || (c == '$')));
+}
+
+static int
+foundit(void)
+{
+ if (wordmode) {
+ return (!issymchar(bufp[-1]) &&
+ !issymchar(bufp[-2 - s1l]) &&
+ !bcmp(bufp - 1 - s1l, str1, s1l));
+ } else {
+ return (!bcmp(bufp - s1l, str1, s1l));
+ }
}
-static int foundit(void)
+static int
+putcharf(int c)
{
- if (wordmode)
- { return( !issymchar(bufp[-1]) &&
- !issymchar(bufp[-2-s1l]) &&
- !bcmp(bufp-1-s1l,str1,s1l) );
- }
- else
- { return(!bcmp(bufp-s1l,str1,s1l));
- }
+ return (putchar(c));
}
-static int putcharf(int c)
+static void
+put_ul(char *s)
{
- return(putchar(c));
+ if (ul_) {
+ for (; *s; s++) {
+ printf("_\b%c", *s);
+ }
+ } else {
+ tputs(beginul, 1, putcharf);
+ fputs(s, stdout);
+ tputs(endul, 1, putcharf);
+ }
}
-static void put_ul(char *s)
-{
- if (ul_)
- { for (;*s;s++)
- { printf("_\b%c",*s);
- }
- }
- else
- { tputs(beginul,1,putcharf);
- fputs(s,stdout);
- tputs(endul,1,putcharf);
- }
-}
-
-static int getc_cbreak(void)
+static int
+getc_cbreak(void)
{
- struct termios tio;
- struct termios otio;
- char c;
+ struct termios tio;
+ struct termios otio;
+ char c;
- if (tcgetattr(0,&tio) < 0) return(getchar());
- otio = tio;
- tio.c_lflag &= ~(ICANON|ECHOKE|ECHOE|ECHO|ECHONL);
- tio.c_cc[VMIN] = 1;
- tio.c_cc[VTIME] = 0;
- tcsetattr(0,TCSANOW|TCSASOFT,&tio);
- switch (read(0,&c,1))
- { case -1:
- break;
- case 0:
- break;
- case 1:
- break;
- }
- tcsetattr(0,TCSANOW|TCSASOFT,&otio);
- return(c);
+ if (tcgetattr(0, &tio) < 0)
+ return (getchar());
+ otio = tio;
+ tio.c_lflag &= ~(ICANON | ECHOKE | ECHOE | ECHO | ECHONL);
+ tio.c_cc[VMIN] = 1;
+ tio.c_cc[VTIME] = 0;
+ tcsetattr(0, TCSANOW | TCSASOFT, &tio);
+ switch (read(0, &c, 1)) {
+ case -1:
+ break;
+ case 0:
+ break;
+ case 1:
+ break;
+ }
+ tcsetattr(0, TCSANOW | TCSASOFT, &otio);
+ return (c);
}
-static int doit(void)
+static int
+doit(void)
{
- long save;
- int i;
- int lastnl;
- int use_replacement;
+ long save;
+ int i;
+ int lastnl;
+ int use_replacement;
- if (flying)
- { return(flystate);
- }
- use_replacement = 0;
- save = ftell(workf);
- do
- { for (i=MAX_C_A-cabove;nls[i]<0;i++) ;
- fseek(workf,nls[i],0);
- for (i=save-nls[i]-rahead;i;i--)
- { putchar(getc(workf));
- }
- put_ul(use_replacement?str2:str1);
- fseek(workf,save+s1l-rahead,0);
- lastnl = 0;
- i = cbelow + 1;
- while (i > 0)
- { int c;
- c = getc(workf);
- if (c == EOF)
- { clearerr(workf);
- break;
- }
- putchar(c);
- lastnl = 0;
- if (c == '\n')
- { i --;
- lastnl = 1;
+ if (flying) {
+ return (flystate);
}
- }
- if (! lastnl) printf("\n[no final newline] ");
- fseek(workf,save,0);
- i = -1;
- while (i == -1)
- { switch (getc_cbreak())
- { case ' ':
- i = 1;
- break;
- case '.':
- i = 1;
- flying = 1;
- flystate = 0;
- break;
- case 'n':
- i = 0;
- break;
- case '\7':
- i = 0;
- flying = 1;
- flystate = 0;
- break;
- case '!':
- i = 1;
- flying = 1;
- flystate = 1;
- break;
- case ',':
- use_replacement = ! use_replacement;
- i = -2;
- printf("(using %s string gives)\n",use_replacement?"new":"old");
- break;
- case '?':
- printf("File is `%s'\n",current_file);
- break;
- default:
- putchar('\7');
- break;
+ use_replacement = 0;
+ save = ftell(workf);
+ do {
+ for (i = MAX_C_A - cabove; nls[i] < 0; i++);
+ fseek(workf, nls[i], 0);
+ for (i = save - nls[i] - rahead; i; i--) {
+ putchar(getc(workf));
+ }
+ put_ul(use_replacement ? str2 : str1);
+ fseek(workf, save + s1l - rahead, 0);
+ lastnl = 0;
+ i = cbelow + 1;
+ while (i > 0) {
+ int c;
+ c = getc(workf);
+ if (c == EOF) {
+ clearerr(workf);
+ break;
Home |
Main Index |
Thread Index |
Old Index