editlib.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett/***********************************************************************
e071fb22ea9923a2a4ff41184d80ca46b55ee932Till Mossakowski* This software is part of the ast package *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Copyright (c) 1984-2011 AT&T Intellectual Property *
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu* and is licensed under the *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Eclipse Public License, Version 1.0 *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* by AT&T Intellectual Property *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* A copy of the License is available at *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* http://www.eclipse.org/org/documents/epl-v10.html *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Information and Software Systems Research *
9ebbce450fb242e1a346f9f89367d8c46fcb2ec8Andy Gimblett* AT&T Research *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Florham Park NJ *
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder* David Korn <dgk@research.att.com> *
020cdb5dad6b871aba61136a0e1567c00426de87Andy Gimblett* Pat Sullivan *
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder***********************************************************************/
9ebbce450fb242e1a346f9f89367d8c46fcb2ec8Andy Gimblett * Miscellaneous routine needed for standalone library for edit modes
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly# endif /* _sys_ioctl */
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly#endif /* TIOCLBIC */
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederstruct fileblk *io_ftable[NFILE+USERIO] = { 0 };
9f93b2a8b552789cd939d599504d39732672dc84Christian Maederstatic struct fileblk outfile = { ed_errbuf, ed_errbuf, ed_errbuf+IOBSIZE, 2, IOWRT};
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reillystatic int output = 0;
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder#if 0 /* almost always false. Makes a good block comment */
9f93b2a8b552789cd939d599504d39732672dc84Christian Maeder **********************************************************************
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett * 1) We ALWAYS want ksh-editing on the terminal input.
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett * 2) We SOMETIMES want ksh-editing on the terminal input.
53f89daf88665d3ea96d871110a5c0d9d8326bd2Andy Gimblett * If you are running with case 1, then just call read() in the usual
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett * If you want to only have line-editing sometimes, and the very first
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett * read() is not one of those times, then you must perform the
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett * initialization first, turn OFF editing, perform your read(), and
c052e3ee4a53ee3a2da829aa142fd596ef6c9e3dAndy Gimblett * so forth. An example of this is in a curses application in which
a09bfcbcb0fba5663fca1968aa82daebf2e092c4Andy Gimblett * single characters are read in RAW mode and acted upon immediately.
05b3e12808da901dccd665715cb934462290d550Andy Gimblett * SAVopt_flag = set_edit(0,0); /* fd=0 set to NO editing */
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett * read(0,buffer,1); /* do your single char read */
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett * set_edit(0,SAVopt_flag); /* restore editing on fd=0 */
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett **********************************************************************
61051521e4d82769a47f23aecb5fb477de47d534Andy Gimblett#endif /* 0 */
1c7c4d95775a8ad5f7373e5cf0bad86f8301c56cAndy Gimblett register char *sp;
a1f6118e7ce7f8892fc4299e316630ec74083f0aAndy Gimblett * read routine with edit modes
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly static void* dll;
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett static char msg[] = "ie: cannot intercept read() system call\n";
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett * on some systems read() is globally bound by the
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett * runtime linker which may get us into a loop if
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett * another library intercepts read() between us and
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett * the system library
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett * on these systems the (dllnext)() call bypasses
20ed727452613e36c0a95ddabf7ecc81cf941ed2Andy Gimblett * any intermediate libraries and gets directly to
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett * the system library
9aeda2b3ae8ce0b018955521e4ca835a8ba8a27bLiam O'Reilly if (!(readfn = (Read_f)dlsym(dll, "_read")) && !(readfn = (Read_f)dlsym(dll, "read")))
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly#endif /* LDYNAMIC */
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett register int r, flag;
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett#endif /* SYSCALL */
06dd4e7c29f33f6122a910719e3bd9062256e397Andy Gimblett if(fd==editfd && hist_ptr && (opt_flag&NOHIST)==0 && r>0)
afc52bfaabee38c4d55cee9f35b1a0028ba3854aAndy Gimblett /* write and flush history */
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly * enable edit mode <mode> on file number <fd>
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly * the NOHIST bit can also be set to avoid writing the history file
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly * <fd> cannot be file two
576a4ca6de740c90afd448607c2323477139de24Liam O'Reilly * flush the output queue and reset the output stream
576a4ca6de740c90afd448607c2323477139de24Liam O'Reillyregister int fd;
7371f8fe3a9a286a74ea30a3cd18e7740f67d537Andy Gimblett * flush the output if necessary and null terminate the buffer
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly register struct fileblk *fp = io_ftable[output];
fd4ad12563262ebe380d810df8f7755cfab5fb42Liam O'Reilly register int count;
void p_char(c)
p_flush();
register char *string;
register int cc;
cc = c,c = 0;
string++;
if(cc==0)
p_flush();
char *ed_movstr(a,b)
register char *string;
#ifdef TIOCLBIC
int mode;
while(c= *string++)
*dp++ = c;
p_char(c);
*dp = 0;
p_flush();