input.c (245676) | input.c (248980) |
---|---|
1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Kenneth Almquist. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 22 unchanged lines hidden (view full) --- 31 */ 32 33#ifndef lint 34#if 0 35static char sccsid[] = "@(#)input.c 8.3 (Berkeley) 6/9/95"; 36#endif 37#endif /* not lint */ 38#include <sys/cdefs.h> |
39__FBSDID("$FreeBSD: head/bin/sh/input.c 245676 2013-01-19 22:12:08Z jilles $"); | 39__FBSDID("$FreeBSD: head/bin/sh/input.c 248980 2013-04-01 17:18:22Z jilles $"); |
40 41#include <stdio.h> /* defines BUFSIZ */ 42#include <fcntl.h> 43#include <errno.h> 44#include <unistd.h> 45#include <stdlib.h> 46#include <string.h> 47 --- 13 unchanged lines hidden (view full) --- 61#include "parser.h" 62#include "myhistedit.h" 63#include "trap.h" 64 65#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ 66 67struct strpush { 68 struct strpush *prev; /* preceding string on stack */ | 40 41#include <stdio.h> /* defines BUFSIZ */ 42#include <fcntl.h> 43#include <errno.h> 44#include <unistd.h> 45#include <stdlib.h> 46#include <string.h> 47 --- 13 unchanged lines hidden (view full) --- 61#include "parser.h" 62#include "myhistedit.h" 63#include "trap.h" 64 65#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */ 66 67struct strpush { 68 struct strpush *prev; /* preceding string on stack */ |
69 char *prevstring; | 69 const char *prevstring; |
70 int prevnleft; 71 int prevlleft; 72 struct alias *ap; /* if push was associated with an alias */ 73}; 74 75/* 76 * The parsefile structure pointed to by the global variable parsefile 77 * contains information about the current file being read. 78 */ 79 80struct parsefile { 81 struct parsefile *prev; /* preceding file on stack */ 82 int linno; /* current line */ 83 int fd; /* file descriptor (or -1 if string) */ 84 int nleft; /* number of chars left in this line */ 85 int lleft; /* number of lines left in this buffer */ | 70 int prevnleft; 71 int prevlleft; 72 struct alias *ap; /* if push was associated with an alias */ 73}; 74 75/* 76 * The parsefile structure pointed to by the global variable parsefile 77 * contains information about the current file being read. 78 */ 79 80struct parsefile { 81 struct parsefile *prev; /* preceding file on stack */ 82 int linno; /* current line */ 83 int fd; /* file descriptor (or -1 if string) */ 84 int nleft; /* number of chars left in this line */ 85 int lleft; /* number of lines left in this buffer */ |
86 char *nextc; /* next char in buffer */ | 86 const char *nextc; /* next char in buffer */ |
87 char *buf; /* input buffer */ 88 struct strpush *strpush; /* for pushing strings at this level */ 89 struct strpush basestrpush; /* so pushing one is fast */ 90}; 91 92 93int plinno = 1; /* input line number */ 94int parsenleft; /* copy of parsefile->nleft */ 95MKINIT int parselleft; /* copy of parsefile->lleft */ | 87 char *buf; /* input buffer */ 88 struct strpush *strpush; /* for pushing strings at this level */ 89 struct strpush basestrpush; /* so pushing one is fast */ 90}; 91 92 93int plinno = 1; /* input line number */ 94int parsenleft; /* copy of parsefile->nleft */ 95MKINIT int parselleft; /* copy of parsefile->lleft */ |
96char *parsenextc; /* copy of parsefile->nextc */ | 96const char *parsenextc; /* copy of parsefile->nextc */ |
97static char basebuf[BUFSIZ + 1];/* buffer for top level input file */ 98static struct parsefile basepf = { /* top level input file */ 99 .nextc = basebuf, 100 .buf = basebuf 101}; 102static struct parsefile *parsefile = &basepf; /* current input file */ 103int whichprompt; /* 1 == PS1, 2 == PS2 */ 104 --- 75 unchanged lines hidden (view full) --- 180 if (rl_cp == NULL) 181 rl_cp = el_gets(el, &el_len); 182 if (rl_cp == NULL) 183 nr = el_len == 0 ? 0 : -1; 184 else { 185 nr = el_len; 186 if (nr > BUFSIZ) 187 nr = BUFSIZ; | 97static char basebuf[BUFSIZ + 1];/* buffer for top level input file */ 98static struct parsefile basepf = { /* top level input file */ 99 .nextc = basebuf, 100 .buf = basebuf 101}; 102static struct parsefile *parsefile = &basepf; /* current input file */ 103int whichprompt; /* 1 == PS1, 2 == PS2 */ 104 --- 75 unchanged lines hidden (view full) --- 180 if (rl_cp == NULL) 181 rl_cp = el_gets(el, &el_len); 182 if (rl_cp == NULL) 183 nr = el_len == 0 ? 0 : -1; 184 else { 185 nr = el_len; 186 if (nr > BUFSIZ) 187 nr = BUFSIZ; |
188 memcpy(parsenextc, rl_cp, nr); | 188 memcpy(parsefile->buf, rl_cp, nr); |
189 if (nr != el_len) { 190 el_len -= nr; 191 rl_cp += nr; 192 } else 193 rl_cp = NULL; 194 } 195 } else 196#endif | 189 if (nr != el_len) { 190 el_len -= nr; 191 rl_cp += nr; 192 } else 193 rl_cp = NULL; 194 } 195 } else 196#endif |
197 nr = read(parsefile->fd, parsenextc, BUFSIZ); | 197 nr = read(parsefile->fd, parsefile->buf, BUFSIZ); |
198 199 if (nr <= 0) { 200 if (nr < 0) { 201 if (errno == EINTR) 202 goto retry; 203 if (parsefile->fd == 0 && errno == EWOULDBLOCK) { 204 int flags = fcntl(0, F_GETFL, 0); 205 if (flags >= 0 && flags & O_NONBLOCK) { --- 41 unchanged lines hidden (view full) --- 247again: 248 if (parselleft <= 0) { 249 if ((parselleft = preadfd()) == -1) { 250 parselleft = parsenleft = EOF_NLEFT; 251 return PEOF; 252 } 253 } 254 | 198 199 if (nr <= 0) { 200 if (nr < 0) { 201 if (errno == EINTR) 202 goto retry; 203 if (parsefile->fd == 0 && errno == EWOULDBLOCK) { 204 int flags = fcntl(0, F_GETFL, 0); 205 if (flags >= 0 && flags & O_NONBLOCK) { --- 41 unchanged lines hidden (view full) --- 247again: 248 if (parselleft <= 0) { 249 if ((parselleft = preadfd()) == -1) { 250 parselleft = parsenleft = EOF_NLEFT; 251 return PEOF; 252 } 253 } 254 |
255 q = p = parsenextc; | 255 q = p = parsefile->buf + (parsenextc - parsefile->buf); |
256 257 /* delete nul characters */ 258 something = 0; 259 for (more = 1; more;) { 260 switch (*p) { 261 case '\0': 262 p++; /* Skip nul */ 263 goto check; --- 170 unchanged lines hidden (view full) --- 434} 435 436 437/* 438 * Like setinputfile, but takes input from a string. 439 */ 440 441void | 256 257 /* delete nul characters */ 258 something = 0; 259 for (more = 1; more;) { 260 switch (*p) { 261 case '\0': 262 p++; /* Skip nul */ 263 goto check; --- 170 unchanged lines hidden (view full) --- 434} 435 436 437/* 438 * Like setinputfile, but takes input from a string. 439 */ 440 441void |
442setinputstring(char *string, int push) | 442setinputstring(const char *string, int push) |
443{ 444 INTOFF; 445 if (push) 446 pushfile(); 447 parsenextc = string; 448 parselleft = parsenleft = strlen(string); 449 parsefile->buf = NULL; 450 plinno = 1; --- 103 unchanged lines hidden --- | 443{ 444 INTOFF; 445 if (push) 446 pushfile(); 447 parsenextc = string; 448 parselleft = parsenleft = strlen(string); 449 parsefile->buf = NULL; 450 plinno = 1; --- 103 unchanged lines hidden --- |