home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / indexor / part01 next >
Encoding:
Text File  |  1989-07-23  |  46.8 KB  |  2,042 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Univ. of Pittsburgh, Comp & Info Sys
  3. subject: v07i100: Index insertor for Scribe, TeX/LaTeX, *roff, etc. part 01/02
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Reply-To: jbw@unix.cis.pittsburgh.edu (Jingbai  Wang)
  6.  
  7. Posting-number: Volume 7, Issue 100
  8. Submitted-by: jbw@unix.cis.pittsburgh.edu (Jingbai  Wang)
  9. Archive-name: indexor/part01
  10.  
  11. [[This arrived as a 75K single-part submission, a single file with no
  12.   shar'ing.  Rather risky, if you ask me...  I have split it into two
  13.   parts.  After unpacking, "cat" indexor.c-1 and indexor.c-2 together
  14.   to make indexor.c.  ++bsa]]
  15.  
  16. If you are a technical writer or book writer, you would have found that
  17. the most tedious job is to add an index to a book you have written. I am
  18. a heavy writer, and I use Scribe (with my own TEC.mak data base) and
  19. TeX/LaTeX to format books.
  20.  
  21. To overcome the tediousness and boresomeness of index making, I developed
  22. a program in C named 'indexor' that I revealed in a previous message in
  23. comp.text. Here I am introducing the source code into comp.text and
  24. comp.source.unix. 
  25.  
  26. This program named `indexor.c' can be compiled on VMS, UNIX or DOS, and have
  27. helped me with two lengthy books already. You can called it a semi-automatic
  28. index insertor. You need an ANSI terminal (like vt100, vt102) to make
  29. it work properly.
  30.  
  31. #! /bin/sh
  32. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  33. # Contents:  indexor.c-1
  34. echo extracting 'indexor.c-1'
  35. if test -f 'indexor.c-1' -a -z "$1"; then echo Not overwriting 'indexor.c-1'; else
  36. sed 's/^X//' << \EOF > 'indexor.c-1'
  37. X/*  Copyright (C) 1988 by Jingbai Wang */
  38. X
  39. X
  40. X/* **********************************************************************
  41. X *            This program is an auxiliary program for Scribe and TeX   *
  42. X *               It inserts index and glossary into Scribe/LaTeX file   *
  43. X *                  It is an important program for book editing         *
  44. X *    The user can set up the programs for other formattors like troff  *
  45. X *                                                                      *
  46. X *                    Copyright by Jingbai Wang August 1988             *
  47. X *                                                                      *
  48. X *    jbw@pittvms.bitnet                                                *
  49. X *    jbw@cisunx.UUCP                                                   *
  50. X ************************************************************************/
  51. X/*
  52. X    This program was created in 1988 by myself in order to include an
  53. X    index in the Scribe and TeX/LaTeX manuals I was writing. It is part
  54. X    of the Scribe TEC.mak package I developed, and can be re-distributed
  55. X    freely for non-profit purposes.
  56. X
  57. X    It is like a special editor to introduce index entries into a Scribe,
  58. X    LaTeX, TeX or *troff file. It indeed makes a tedious and boresome job
  59. X    enjoyable.
  60. X    The primary attempt is to make this program portable among
  61. X    VAX/VMS, UNIX (BSD and Ultrix), and DOS (MSC and MS Quick C).
  62. X
  63. X    To compile on our VMS,
  64. X    $ex indexor
  65. X
  66. X    and on UNIX,
  67. X    %cc -o indexor indexor.c
  68. X
  69. X    It takes two on-line arguments, i.e., the input and output file names,
  70. X    but you can also provide these piece of information when running it.
  71. X    The program is self-instructive, no documentation is necessary.
  72. X*/
  73. X
  74. X#include <string.h>
  75. X#include <stdio.h>
  76. X#define CLS printf("\033[2J")
  77. X#define GOTOXY(x,y) printf("\033[%d;%df",x,y)
  78. X#define REVERSE printf("\033[7m")
  79. X#define NORMAL printf("\033[0m")
  80. X#define SAVE_CURSOR printf("\033[s")
  81. X#define BLINK printf("\033[5m")
  82. X#define BOLD printf("\033[1m")
  83. X#define UNDER printf("\033[4m")
  84. X#define ERASE printf("\033[K")
  85. X#define CURSOR_REPORT(x, y) scanf("\033[%d;%dR",x,y)
  86. X#define BELL printf("%c", 7)
  87. X#define CURSOR_RIGHT printf("\033[1C")
  88. X#define CURSOR_LEFT printf("\033[1D")
  89. X
  90. X#define tt_open 1
  91. X#define tt_close 0
  92. Xint tt_status=0;
  93. X
  94. X#if VMS|unix
  95. X#define RESTORE_CURSOR cursor_position()
  96. X#else
  97. X#define RESTORE_CURSOR printf("\033[u")
  98. X#endif
  99. X
  100. X#if ultrix
  101. X#define V7 1
  102. X#endif
  103. X
  104. X#if unix|VMS
  105. X/*   ANSI escape, good for mainframe systems vt100 terminals, e.g., VAX*/
  106. X#define DEL 127
  107. X#define EXT 27
  108. X#define EXT1 '['
  109. X#define R_ARROW 'C'
  110. X#define L_ARROW 'D'
  111. X#define D_ARROW 'B'
  112. X#define U_ARROW 'A'
  113. X
  114. X#if VMS
  115. X#include        <descrip.h>
  116. X#include        <iodef.h>
  117. X#include        <ssdef.h>
  118. Xshort   iochan;                  /* TTY I/O channel             */
  119. X#endif
  120. X
  121. X
  122. X#else
  123. X /* MSDOS extended code escape */
  124. X#define DEL  8
  125. X#define EXT  0  
  126. X#define R_ARROW 77
  127. X#define L_ARROW 75
  128. X#define D_ARROW 80
  129. X#define U_ARROW 72
  130. X#endif
  131. X
  132. XFILE *infile;
  133. XFILE *outfile;
  134. Xchar buffer[720];
  135. Xint buffer_length;
  136. Xint buffer_line[11];
  137. Xint lines=1;
  138. Xint cursor_mark=0;
  139. Xint cursor_last=0;
  140. X
  141. Xchar marker=0;
  142. Xchar phrase_str[512]="";
  143. Xchar the_phrase[512];
  144. Xchar save_str[128]="";
  145. Xchar out_str[512]="";
  146. Xint phrase_on, phrase_off, phrase_len;
  147. Xchar end_infile=0;
  148. Xchar end_outfile=0;
  149. Xchar exit_flag=0;
  150. Xchar word_mark=0;
  151. Xchar the_index[20]="@Index";
  152. Xchar the_delimiter1[3]="{";
  153. Xchar the_delimiter2[3]="}";
  154. Xchar the2_delimiter1[3]="<";
  155. Xchar the2_delimiter2[3]=">";
  156. Xchar the_primary[20]="Primary=";
  157. Xchar the_second[20]="Secondary=";
  158. Xchar the_gloss[20]="@glossary";
  159. Xchar g_primary[20]="symbol=";
  160. Xchar g_second[20]="expln=";
  161. Xchar the_indexsecond[20]="@IndexSecondary";
  162. Xchar the_seealso[20]="@SeeAlso";
  163. Xchar the_indexentry[20]="@IndexEntry";
  164. Xchar the_entry[20]="Entry=";
  165. Xchar the_key[20]="Key=";
  166. Xchar the_number[20]="Number=";
  167. X
  168. Xstruct CUR
  169. X{
  170. Xshort int x;
  171. Xshort int y;
  172. X} chr[720];
  173. X
  174. Xchar next_str[512];
  175. Xchar next_flag=0;
  176. Xchar command_line[160];
  177. X
  178. X
  179. X
  180. X/* The getch() and getche() */
  181. X
  182. X#if VMS
  183. Xchar getch()
  184. X{
  185. Xint ibuf,status;
  186. Xint     iosb[2];
  187. X                        status = SYS$QIOW(0, iochan, IO$_READLBLK|IO$M_NOECHO,
  188. X                                 iosb, 0, 0, &ibuf, 1, 0, 0, 0, 0);
  189. X
  190. X        return (ibuf & 0xFF);    /* Allow multinational  */
  191. X
  192. X}
  193. X
  194. X#endif
  195. X
  196. X
  197. X#if unix | ultrix | BSD
  198. X
  199. Xchar getch()
  200. X{
  201. Xint tmpch;
  202. Xttopen();
  203. Xtmpch=ttgetc();
  204. Xttclose();
  205. Xreturn(tmpch);
  206. X}
  207. X#endif
  208. X
  209. X
  210. X#if unix | VMS
  211. Xchar getche()
  212. X{
  213. Xchar inchar;
  214. Xfputc(getch(), stdout);
  215. Xreturn((int)inchar);
  216. X}
  217. X
  218. X#endif
  219. X
  220. Xread_in()
  221. X{
  222. Xint i, quit_s;
  223. Xchar string[81],quit;
  224. XGOTOXY(3,1);
  225. Xbuffer_length=0;
  226. Xbuffer[0]=0;
  227. Xstring[0]=0;
  228. X           quit_s=0;
  229. X
  230. X
  231. Xfor (i=1;i<=8;i++)
  232. X  { if( fgets(string,80,infile)==NULL)  { end_infile=1;
  233. X           quit_s=1; goto quit;}
  234. X     else { printf("%s",string);
  235. X           strcat(buffer,string);
  236. X           }
  237. X  }
  238. X
  239. Xquit:
  240. Xbuffer_length=strlen(buffer);
  241. X
  242. Xposition();
  243. XGOTOXY(3,1);
  244. Xreturn(quit_s);
  245. X }
  246. X
  247. Xposition()
  248. X{
  249. Xint i,j;
  250. Xint row,col;
  251. Xchar ch;
  252. Xrow=3; col=1;
  253. Xbuffer_line[1]=0;
  254. Xlines=1;
  255. X
  256. Xfor(i=0;i<buffer_length;i++)
  257. X  {  ch=buffer[i];
  258. X   chr[i].x=row; chr[i].y=col++;
  259. X
  260. X   if(ch==10) {row++;col=1;lines++;buffer_line[lines]=i+1;}
  261. X
  262. X   if (col==81) {row++;col=1;lines++; buffer_line[lines]=i+1;}
  263. X   }  
  264. X
  265. X}
  266. X
  267. X
  268. Xmark_begin()
  269. X{
  270. Xint i;
  271. X
  272. X for (i=cursor_last;i<cursor_mark;i++)
  273. X      {fprintf(outfile, "%c", buffer[i]);
  274. X        if (buffer[i]==10)
  275. X     {if (next_flag==1) {
  276. X             fprintf(outfile, "%s\n", next_str);
  277. X             next_str[0]=0; next_flag=0;
  278. X             }
  279. X     }
  280. X       
  281. X      }
  282. Xmarker=1;
  283. Xcursor_last=cursor_mark;
  284. Xphrase_len=0;
  285. Xphrase_on=cursor_mark;
  286. Xphrase_str[0]=0;
  287. XREVERSE;
  288. Xprintf("%c",buffer[cursor_mark]);
  289. Xcursor_position();
  290. X}
  291. X
  292. Xmark_end()
  293. X{
  294. Xint i, length;
  295. Xchar  ch;
  296. Xmarker=0;
  297. X
  298. X for (i=cursor_last;i<=cursor_mark;i++)
  299. X      { fprintf(outfile, "%c", buffer[i]);
  300. X         if (buffer[i]==10)
  301. X     { 
  302. X           if (next_flag==1) {
  303. X             fprintf(outfile, "%s\n", next_str);
  304. X             next_str[0]=0; next_flag=0;
  305. X             }
  306. X     }
  307. X
  308. X
  309. X      }
  310. X
  311. Xlength=strlen(phrase_str);
  312. Xphrase_off=cursor_mark;
  313. Xcursor_last=cursor_mark+1;
  314. Xcursor_mark=cursor_last; cursor_position();
  315. Xfor (i=phrase_on; i<=phrase_off;i++)
  316. X  { ch=buffer[i];
  317. X   if ((ch==13)||(ch==10)) ch=32;
  318. X    phrase_str[length+i-phrase_on]=ch;
  319. X  }
  320. Xphrase_str[length+1+phrase_off-phrase_on]=0;
  321. Xphrase_on=0; phrase_off=0;
  322. XNORMAL;
  323. X}
  324. X
  325. Xcursor_position()
  326. X{
  327. XGOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  328. X}
  329. X
  330. Xcursor_right()
  331. X{
  332. X
  333. Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
  334. X   ++cursor_mark; cursor_position();
  335. X   if (marker==1) printf("%c",buffer[cursor_mark]);
  336. X   GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  337. X
  338. X}
  339. X
  340. Xcursor_left()
  341. X{
  342. X  if (cursor_mark<=cursor_last) {cursor_mark=cursor_last; cursor_position();BELL; return;}
  343. X  NORMAL; cursor_position();printf("%c",buffer[cursor_mark]);
  344. X  --cursor_mark;
  345. X  if (marker==1) REVERSE;
  346. X  GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  347. X
  348. X
  349. X}
  350. X
  351. Xcursor_down()
  352. X{
  353. Xint i,the_stop;
  354. Xchar check;
  355. Xthe_stop=cursor_mark;
  356. X
  357. Xcursor_position();
  358. Xfor (i=cursor_mark;i<buffer_length;i++)
  359. X {if (i>=buffer_length-2) {next_page();return;}
  360. X  if (buffer[i]==10) {cursor_mark=i+1;
  361. X     cursor_position();goto check;}
  362. X }
  363. X
  364. Xcheck:
  365. X  if (marker)
  366. X   { GOTOXY(chr[the_stop].x,chr[the_stop].y);
  367. X     for (i=the_stop;i<=cursor_mark;i++)
  368. X      printf("%c",buffer[i]);
  369. X     cursor_position();
  370. X   }
  371. X}
  372. X
  373. Xcursor_up()
  374. X{
  375. Xchar check;
  376. Xint i,the_stop;
  377. Xif (cursor_mark<=cursor_last) {cursor_mark=cursor_last;cursor_position(); BELL; return;}
  378. X
  379. Xcursor_position();the_stop=cursor_mark;
  380. Xfor (i=cursor_mark;i>=cursor_last;i--)
  381. X {
  382. X  if (buffer[i]==10) {cursor_mark=i-1;
  383. X  GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  384. X  goto check;}
  385. X }
  386. X cursor_mark=cursor_last; cursor_position(); BELL;
  387. X
  388. Xcheck:
  389. X  if (marker)
  390. X   {
  391. X    NORMAL; GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
  392. X    for (i=cursor_mark+1;i<=the_stop;i++)
  393. X       printf("%c",buffer[i]);
  394. X    REVERSE;
  395. X    GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  396. X   }
  397. X
  398. X}
  399. X
  400. X
  401. X
  402. X
  403. X
  404. X
  405. Xmark_word()
  406. X{
  407. Xif (marker==0) mark_begin(); word_skip();return;
  408. X}
  409. X
  410. Xpass_marked()
  411. X{
  412. Xint i;
  413. Xif (marker==0) { word_skip();return;}
  414. XGOTOXY(chr[cursor_last].x,chr[cursor_last].y);
  415. Xmarker=0; NORMAL;
  416. X phrase_str[0]= 0;
  417. X for (i=cursor_last;i<=cursor_mark;i++)
  418. X     printf("%c",buffer[i]);
  419. X
  420. Xcursor_mark=cursor_last;
  421. Xcursor_position();
  422. X}
  423. X
  424. X
  425. Xword_skip()
  426. X{
  427. Xint i, the_stop;
  428. Xchar check;
  429. X
  430. Xthe_stop=cursor_mark;
  431. Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
  432. X
  433. Xcursor_right();
  434. Xfor (i=cursor_mark; i<buffer_length;i++)
  435. X {
  436. X
  437. X  switch(buffer[i])
  438. X   {case '!':
  439. X    case ',':
  440. X    case '"':
  441. X    case '\'':
  442. X    case '`':
  443. X    case '(':
  444. X    case ')':
  445. X    case '[':
  446. X    case ']':
  447. X    case '/':
  448. X    case '+':
  449. X    case '=':
  450. X    case '?':
  451. X    case '<':
  452. X    case '>':
  453. X    case '{':
  454. X    case '}':
  455. X    case '*':
  456. X    case '^':
  457. X    case '&':
  458. X    case '#':
  459. X    case ':':
  460. X    case ';':
  461. X    case '|':
  462. X    case  9:
  463. X    case 10:
  464. X    case 13:
  465. X    case '~':
  466. X    case '@':
  467. X    case '\\':
  468. X    case 32:
  469. X    case '.': if (word_mark) {word_mark=0;cursor_mark=i-1;
  470. X                 cursor_position();
  471. X                 goto check;}
  472. X          else break;
  473. X    default:   word_mark=1;
  474. X
  475. X   }
  476. X  }
  477. X
  478. Xcheck:
  479. X  if(marker)
  480. X   { GOTOXY(chr[the_stop].x,chr[the_stop].y);
  481. X     for (i=the_stop;i<=cursor_mark;i++)
  482. X    printf("%c",buffer[i]);
  483. X    cursor_position();
  484. X   }
  485. X
  486. X}
  487. X
  488. X
  489. X
  490. Xword_back()
  491. X{
  492. Xint i, the_stop;
  493. Xchar check;
  494. Xthe_stop=cursor_mark;
  495. Xcursor_left();
  496. Xfor (i=cursor_mark; i>=0;i--)
  497. X { if (i<=cursor_last) {cursor_mark=cursor_last;
  498. X            cursor_position();BELL;goto check;}
  499. X
  500. X  switch(buffer[i])
  501. X   {case '!':
  502. X    case ',':
  503. X    case '"':
  504. X    case '\'':
  505. X    case '`':
  506. X    case '(':
  507. X    case ')':
  508. X    case '[':
  509. X    case ']':
  510. X    case '/':
  511. X    case '+':
  512. X    case '=':
  513. X    case '?':
  514. X    case '<':
  515. X    case '>':
  516. X    case '{':
  517. X    case '}':
  518. X    case '*':
  519. X    case '^':
  520. X    case '&':
  521. X    case '#':
  522. X    case ':':
  523. X    case ';':
  524. X    case '|':
  525. X    case  9:
  526. X    case 10:
  527. X    case 13:
  528. X    case '~':
  529. X    case '@':
  530. X    case '\\':
  531. X    case 32:
  532. X    case '.':
  533. X         if (word_mark) {word_mark=0; cursor_mark=i; cursor_position();
  534. X        goto check;
  535. X          }
  536. X          else  break;
  537. X    default:   word_mark=1;
  538. X
  539. X    }
  540. X  }
  541. X
  542. Xcheck:
  543. X  if (marker)
  544. X   {GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
  545. X    NORMAL;
  546. X     for (i=cursor_mark+1;i<=the_stop;i++)
  547. X     printf("%c",buffer[i]);
  548. X
  549. X    REVERSE;
  550. X    cursor_position();
  551. X   }
  552. X}
  553. X
  554. X
  555. Xnext_page()
  556. X{
  557. Xint i, length, pre_row, ch_count;
  558. X
  559. XNORMAL;
  560. XCLS_UP();
  561. XGOTOXY(1,1);  pre_row=0; ch_count=0;
  562. X
  563. Xif (end_outfile) {BELL; return;}
  564. X
  565. X
  566. Xif (marker){
  567. X if ((strlen(phrase_str)+strlen(&buffer[phrase_on]))<510)
  568. X  strcat(phrase_str, &buffer[phrase_on]);
  569. X else marker=0;
  570. X}
  571. X
  572. Xfor (i=buffer_line[lines-2];i<buffer_length;i++)
  573. X {
  574. X if ((marker==1) && (i>=phrase_on)) {REVERSE;}
  575. X   printf("%c", buffer[i]);
  576. X }
  577. X
  578. Xfor (i=cursor_last;i<buffer_length;i++)
  579. X  {   fprintf(outfile,"%c",buffer[i]);
  580. X  if (buffer[i]==10)
  581. X     {
  582. X      if (next_flag==1) {
  583. X             fprintf(outfile, "%s\n", next_str);
  584. X             next_str[0]=0; next_flag=0;
  585. X             }
  586. X     }
  587. X
  588. X  }
  589. X
  590. X
  591. Xcursor_last=0;
  592. Xphrase_on=0;
  593. Xcursor_mark=0;
  594. Xbuffer_length=0;
  595. XNORMAL;
  596. X
  597. Xif (end_infile) {end_outfile=1;
  598. X         GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL; return;}
  599. X
  600. Xend_infile=read_in();
  601. Xif (marker) {REVERSE; printf("%c",buffer[0]);cursor_position();}
  602. X}
  603. X
  604. X
  605. Xcontrol(inchar)
  606. Xchar inchar;
  607. X{
  608. Xchar ch;
  609. X
  610. X
  611. X switch(inchar)
  612. X     {
  613. X       case EXT:
  614. X#if unix|VMS
  615. X             /* mainframe  environment  */
  616. X               if (getch()!=EXT1) {BELL;break;}
  617. X               ch=getch();
  618. X#else
  619. X             /* DOS environment              */ 
  620. X
  621. X             ch=getch();
  622. X#endif            
  623. X
  624. X             switch(ch)
  625. X              { 
  626. X               case L_ARROW: cursor_left(); 
  627. X                   break;
  628. X               case R_ARROW: cursor_right();
  629. X                   break;
  630. X               case D_ARROW: cursor_down();
  631. X                   break;
  632. X           case U_ARROW: cursor_up();
  633. X                   break;
  634. X               default: BELL;
  635. X              }
  636. X
  637. X          break;
  638. X       case 13: if (marker==0) {mark_begin(); break;}
  639. X                if (marker==1) 
  640. X                 {mark_end(); index_now();}
  641. X                 break;     
  642. X       case 9:  word_skip(); break;
  643. X       case 'b':
  644. X       case 'B':
  645. X       case 8:
  646. X       case 127:
  647. X                word_back(); break;
  648. X       case 32: next_page(); break;
  649. X       case 'n':
  650. X       case 'N': if (marker==1) 
  651. X                {mark_end();index_next_line();} 
  652. X                 else BELL; break;    
  653. X       case 'p':
  654. X       case 'P': pass_marked(); break;
  655. X       case 'f':
  656. X       case 'F': finish_up(); return(1); break;
  657. X       case 'a':
  658. X       case 'A': if (marker==1) mark_end(); see_also();break;
  659. X       case 's':
  660. X       case 'S': if (marker==1) mark_end();index_secondary();break;
  661. X       case 'i':
  662. X       case 'I': if (marker==1) mark_end();index_entry();break;
  663. X       case 'g':
  664. X       case 'G': if (marker==1) mark_end();
  665. X          else warning("No current marked, will take the previous one");
  666. X         glossary();
  667. X           break;
  668. X       case 'W':
  669. X       case 'w': mark_word(); break;
  670. X       case '@': set_up(); break;
  671. X       case  6 : str_search(); break;
  672. X       case  3 : all_done(); break;
  673. X#if unix
  674. X       case  4 : all_done(); break;
  675. X#endif
  676. X       default: BELL;
  677. X   }
  678. X
  679. X
  680. X}
  681. X
  682. X
  683. X
  684. X
  685. Xmain(argc, argv)
  686. Xint argc;
  687. Xchar *argv[];
  688. X{
  689. Xint in_file,out_file, status;
  690. Xint i,j;
  691. Xchar infile_name[30], outfile_name[30];
  692. Xchar out_ok=1;
  693. Xchar ch, quit;
  694. Xchar getch();
  695. X
  696. X#if     VMS
  697. X$DESCRIPTOR(terminal,"TT");
  698. X
  699. X        status = SYS$ASSIGN(&terminal, &iochan, 0, 0);
  700. X        if (status != SS$_NORMAL) exit(status);
  701. X
  702. Xsystem("set broadcast=none");
  703. X
  704. X#endif
  705. X
  706. X
  707. XNORMAL;
  708. XCLS;
  709. Xswitch(argc)
  710. X  {
  711. X    case 1: in_file=1; out_file=1; break;
  712. X    case 2: in_file=0; out_file=1; strcpy(infile_name,argv[1]); break;
  713. X    default: in_file=0;out_file=0;
  714. X           strcpy(infile_name,argv[1]); 
  715. X           strcpy(outfile_name,argv[2]); break;
  716. X  }
  717. X
  718. X if (in_file) 
  719. X   {GOTOXY(5,15);
  720. X   printf(" Input file (file to be indexed) >");
  721. X   scanf("%s",infile_name);
  722. X   fflush(stdin);
  723. X   }
  724. X
  725. X   if ((infile=fopen(infile_name,"r"))==NULL)
  726. X     {GOTOXY(20,20); BLINK;
  727. X       printf("Can't find the input file");
  728. X       NORMAL; goto quit;
  729. X     }
  730. X
  731. Xwhile (out_ok)
  732. X
  733. X {
  734. X  if (out_file) 
  735. X    {GOTOXY(6,15); ERASE;
  736. X    printf(" Output file (indexed file) >");
  737. X    fscanf(stdin, "%s",outfile_name);
  738. X    fflush(stdin);
  739. X    }
  740. X
  741. X
  742. X    out_ok=0; 
  743. X   if ((outfile=fopen(outfile_name,"r"))!=NULL)
  744. X     { out_ok=1;
  745. X       GOTOXY(7,16); ERASE;
  746. X       out_file=1;
  747. X      fflush(stdin);
  748. X      printf("File %s already exits, overwrite ? [N]", outfile_name);
  749. X      ch=getch();
  750. X      ch=getch();
  751. X        if ((ch=='y')||(ch=='Y')) out_ok=0;
  752. X        fclose(outfile);
  753. X
  754. X     }
  755. X
  756. X    if (out_ok==0)
  757. X       {
  758. X    outfile=fopen(outfile_name,"w");
  759. X       }
  760. X }
  761. X
  762. X
  763. X
  764. XNORMAL;
  765. XCLS;
  766. X
  767. Xhelp_menu();
  768. Xend_infile=read_in();
  769. X
  770. X while (1)
  771. X  {
  772. X   control(getch());
  773. X   if (exit_flag) goto quit;
  774. X  }
  775. X
  776. Xquit:
  777. XGOTOXY(25, 1);
  778. Xprintf("\n\t>>> Thank you for using INDEX MAKER >>>\n");
  779. Xprintf("\t>>> by Jingbai Wang, August 1988 >>>\n");
  780. X
  781. X
  782. X
  783. X}
  784. X
  785. Xwarning(warn_str)
  786. Xchar *warn_str;
  787. X{
  788. Xchar i;
  789. X
  790. XSAVE_CURSOR;
  791. XGOTOXY(24,5); REVERSE; BLINK;
  792. Xprintf("%s", warn_str); BELL; BELL;
  793. Xfor (i=1;i<10000;i++) ;
  794. XGOTOXY(24,1); RESTORE_CURSOR; NORMAL;
  795. X}
  796. X
  797. Xvoid  clr_show()
  798. X{
  799. Xint i;
  800. Xfor (i=13;i<17;i++)
  801. X  {NORMAL; GOTOXY(i,1);ERASE;}
  802. X}
  803. X
  804. X
  805. Xindex_now()
  806. X{ int i;
  807. Xfprintf(outfile, "%s%s%s%s",the_index,the_delimiter1,phrase_str,the_delimiter2);
  808. XSAVE_CURSOR;
  809. Xclr_show(); out_check();
  810. XGOTOXY(13,1);
  811. XBOLD;
  812. Xprintf("%s%s%s%s",the_index,the_delimiter1,out_str,the_delimiter2);
  813. XNORMAL; RESTORE_CURSOR;
  814. X}
  815. X
  816. Xindex_next_line()
  817. X{
  818. Xint i;
  819. X
  820. Xnext_flag=1;
  821. Xstrcat(next_str, the_index);
  822. Xstrcat(next_str, the_delimiter1);
  823. X    if ((strlen(next_str)+strlen(phrase_str))<510) 
  824. X        strcat(next_str, phrase_str);
  825. Xstrcat(next_str, the_delimiter2);
  826. XSAVE_CURSOR;
  827. Xclr_show(); out_check();
  828. XGOTOXY(13,1);
  829. XBOLD;
  830. Xprintf("%s%s%s%s}", the_index,the_delimiter1,out_str,the_delimiter2);
  831. XNORMAL; RESTORE_CURSOR;
  832. X
  833. X}
  834. X
  835. Xsee_also()
  836. X{
  837. XSAVE_CURSOR;BELL;
  838. XGOTOXY(24,2); BLINK; REVERSE;
  839. Xprintf("  Primary=");  NORMAL;printf("[%s]",save_str);
  840. Xget_line();
  841. Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
  842. X else strcpy(save_str, command_line);
  843. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
  844. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  845. Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
  846. XGOTOXY(24,1);ERASE;
  847. Xclr_show();  out_check();
  848. XGOTOXY(13,1);
  849. XBOLD;
  850. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
  851. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  852. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  853. XNORMAL; RESTORE_CURSOR;
  854. X
  855. X}
  856. X
  857. Xindex_entry()
  858. X{
  859. Xchar entry[20], number[30];
  860. Xstrcpy(save_str, phrase_str);
  861. X
  862. Xstrcpy(number, ",\nNumber=<");
  863. XSAVE_CURSOR;BELL;
  864. XGOTOXY(24,2); BLINK; REVERSE;
  865. Xprintf("  Entry=");  NORMAL;printf("[%s]",phrase_str);
  866. Xget_line();
  867. Xif (memcmp(command_line,"",1)==0) strcpy(entry, phrase_str);
  868. X else strcpy(entry, command_line);
  869. XGOTOXY(24,1);ERASE;
  870. XGOTOXY(24,2); BLINK; REVERSE;
  871. Xprintf("  Number=");  NORMAL;
  872. Xget_line();
  873. Xif (memcmp(command_line,"",1)==0) number[0]=0;
  874. X else  {strcat(number, command_line); strcat(number, ">");}
  875. X
  876. X
  877. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
  878. Xthe_key,the2_delimiter1,phrase_str, the2_delimiter2,the_entry,
  879. Xthe2_delimiter1,entry,the2_delimiter2,  number, the_delimiter2);
  880. XGOTOXY(24,1);ERASE;
  881. Xclr_show();  out_check();
  882. XGOTOXY(13,1);
  883. XBOLD;
  884. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
  885. Xthe_key,the2_delimiter1,out_str, the2_delimiter2,the_entry,
  886. Xthe2_delimiter1,entry,the2_delimiter2, number, the_delimiter2);
  887. XNORMAL; RESTORE_CURSOR;
  888. X
  889. X}
  890. X
  891. Xindex_secondary()
  892. X{
  893. XSAVE_CURSOR;BELL;
  894. XGOTOXY(24,2); BLINK; REVERSE;
  895. Xprintf("  Primary=");  NORMAL;printf("[%s]",save_str);
  896. Xget_line();
  897. Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
  898. X else strcpy(save_str, command_line);
  899. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
  900. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  901. Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
  902. XGOTOXY(24,1);ERASE;
  903. Xclr_show();  out_check();
  904. XGOTOXY(13,1);
  905. XBOLD;
  906. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
  907. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  908. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  909. XNORMAL; RESTORE_CURSOR;
  910. X
  911. X}
  912. X
  913. Xglossary()
  914. X{
  915. XSAVE_CURSOR;
  916. XGOTOXY(24,2); BLINK; REVERSE;
  917. Xprintf("  Description:");  NORMAL;
  918. Xget_line();
  919. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
  920. Xg_primary,the2_delimiter1,phrase_str, the2_delimiter2,g_second,
  921. Xthe2_delimiter1,command_line,the2_delimiter2, the_delimiter2);
  922. XGOTOXY(24,1);ERASE;
  923. Xclr_show();  out_check();
  924. XGOTOXY(13,1);
  925. XBOLD;
  926. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
  927. Xg_primary,the2_delimiter1,command_line, the2_delimiter2,g_second,
  928. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  929. XNORMAL; RESTORE_CURSOR;
  930. X
  931. X}
  932. X
  933. X
  934. Xfinish_up()
  935. X{ char ch;
  936. X  int i;
  937. X
  938. Xif(end_infile && end_outfile) {all_done(); exit();}
  939. X
  940. X
  941. Xif (marker) {mark_end(); index_now(); }
  942. X
  943. Xfor (i=cursor_last;i<buffer_length;i++)
  944. X  {
  945. X  if (buffer[i]==13)
  946. X     { 
  947. X      if (next_flag==1) {
  948. X             fprintf(outfile, "%s\n\n", next_str);
  949. X             next_str[0]=0; next_flag=0;
  950. X             }
  951. X     }
  952. X  else fprintf(outfile,"%c",buffer[i]);
  953. X  }
  954. X
  955. X
  956. X
  957. Xif (end_infile==1) {all_done(); return;}
  958. XGOTOXY(24,35); BLINK; printf("Working ... \n");
  959. X
  960. X    while (fscanf(infile,"%c",&ch)!=EOF)
  961. X      {
  962. X    if (ch==13);
  963. X    else fprintf(outfile, "%c", ch);
  964. X      }
  965. X  all_done();NORMAL;
  966. X}
  967. X
  968. X
  969. Xall_done()
  970. X{
  971. Xfclose(infile); fclose(outfile); exit_flag=1;
  972. X#if VMS
  973. Xsystem("set broadcast=all");
  974. X#endif
  975. X}
  976. X
  977. X
  978. XCLS_UP()
  979. X{ char i;
  980. X
  981. Xfor(i=1;i<12;i++)
  982. X  {GOTOXY(i,1); ERASE;}
  983. X
  984. X}
  985. X
  986. Xhelp_menu()
  987. X{
  988. XGOTOXY(12, 1);
  989. XREVERSE; printf("                                ");
  990. Xprintf(" Inserting                                 ");
  991. X
  992. XGOTOXY(17,1);
  993. Xprintf(" ===== ^H delete ======================== ^F Search string ===============");
  994. XNORMAL;
  995. XGOTOXY(18,3); BOLD; printf("SPACE BAR"); NORMAL; printf(" -- next page");
  996. XGOTOXY(19,3); BOLD; printf("<RETURN> 1"); NORMAL; printf(" -- set mark");
  997. XGOTOXY(20,3); BOLD; printf("<RETURN> 2"); NORMAL; printf(" -- end mark & index");
  998. XGOTOXY(21,3); BOLD; printf("<TAB>"); NORMAL; printf(" -- forward a word");
  999. XGOTOXY(22,40); BOLD; printf("G"); NORMAL; printf(" -- end mark & glossary");
  1000. XGOTOXY(22,3); BOLD; printf("W"); NORMAL; printf(" -- mark word");
  1001. XGOTOXY(21,40); BOLD; printf("B"); NORMAL; printf(" -- backward a word");
  1002. XGOTOXY(20,40); BOLD; printf("N"); NORMAL; printf(" -- end mark & index in next line");
  1003. XGOTOXY(19,40); BOLD; printf("P"); NORMAL; printf(" -- abandon the marked/skip a word ");
  1004. XGOTOXY(18,40); BOLD; printf("F"); NORMAL; printf(" -- finish     \
  1005. X        ^F--string search");
  1006. XGOTOXY(23,40); BOLD; printf("S"); NORMAL; printf(" -- IndexSecondary");
  1007. XGOTOXY(23,17); BOLD; printf("I"); NORMAL; printf(" -- IndexEntry");
  1008. XGOTOXY(23,3); BOLD; printf("A"); NORMAL; printf(" -- SeeAlso");
  1009. XGOTOXY(23,65); BOLD; printf("@"); NORMAL; printf(" -- set up");
  1010. X}
  1011. X
  1012. X
  1013. Xset_up()
  1014. X{
  1015. Xint the_row, i;
  1016. Xint ch_count;
  1017. Xchar ch, string[81];
  1018. X
  1019. Xch_count=0;
  1020. XSAVE_CURSOR;
  1021. XNORMAL; REVERSE;
  1022. XGOTOXY(12,1);
  1023. Xprintf("                            Set-up Menu                  <TAB> to quit      ");
  1024. XNORMAL;
  1025. Xfor (i=13;i<24;i++)
  1026. X  {GOTOXY(i,1);ERASE;}
  1027. X
  1028. XGOTOXY(13,3);printf("[%s]:",the_index);
  1029. XGOTOXY(14,3);printf("[%s]:",the_indexentry);
  1030. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);
  1031. XGOTOXY(16,3);printf("[%s]:",the_seealso);
  1032. XGOTOXY(17,3);printf("[%s]:",the_primary);
  1033. XGOTOXY(18,3);printf("[%s]:",the_second);
  1034. XGOTOXY(19,3);printf("[%s]:",the_gloss);
  1035. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);
  1036. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second);
  1037. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);
  1038. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);
  1039. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1);
  1040. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);
  1041. X
  1042. Xthe_row=13;
  1043. Xset_up_in(the_row);
  1044. X
  1045. X     while(1)
  1046. X      { ch=getch();
  1047. X     switch(ch)
  1048. X     {
  1049. X      case EXT:
  1050. X#if unix | VMS
  1051. X
  1052. X         /* VAX */
  1053. X         ch=getch(); if (ch!=EXT1) {BELL;break;}
  1054. X         ch=getch();
  1055. X#else
  1056. X               /* DOS                 */
  1057. X          ch=getch(); 
  1058. X#endif        
  1059. X         switch(ch)
  1060. X         {
  1061. X          case L_ARROW:
  1062. X          case U_ARROW:
  1063. X               set_up_out(the_row); ch_count=0;string[0]=0;
  1064. X               --the_row; if (the_row<13) the_row=25;
  1065. X               set_up_in(the_row); break;
  1066. X          case R_ARROW:
  1067. X          case D_ARROW:
  1068. X  down:                        set_up_out(the_row);ch_count=0;string[0]=0;
  1069. X               ++the_row; if (the_row>25) the_row=13;
  1070. X               set_up_in(the_row); break;
  1071. X         default: BELL;
  1072. X         } break;
  1073. X       case  3 : all_done(); break;
  1074. X#if unix
  1075. X       case  4 : all_done(); break;
  1076. X#endif
  1077. X      case 1:
  1078. X      case 2:
  1079. X      case 5:
  1080. X      case 6:
  1081. X      case 7:
  1082. X      case 10:
  1083. X      case 11:
  1084. X      case 12:
  1085. X      case 14:
  1086. X      case 15:
  1087. X      case 16:
  1088. X      case 19:
  1089. X      case 20:
  1090. X      case 21:
  1091. X      case 22:
  1092. X      case 23:
  1093. X      case 24:
  1094. X      case 25:
  1095. X      case 26:BELL;break;
  1096. X          case 8:
  1097. X          case 127:
  1098. X              if (ch_count>0){
  1099. X                  CURSOR_LEFT; ERASE;
  1100. X                  string[--ch_count]=0;
  1101. X                  }  break;
  1102. X
  1103. X      case 13: if (ch_count>0)
  1104. X          { string[ch_count]=0;
  1105. X           set_up_save(the_row, string);
  1106. X           } goto down;break;
  1107. X      case 9: NORMAL;for (i=12;i<24;i++)
  1108. X           {GOTOXY(i,1);ERASE;}
  1109. X           help_menu();RESTORE_CURSOR;
  1110. X           return;
  1111. X      default: printf("%c",ch);string[ch_count++]=ch;
  1112. X
  1113. X     }
  1114. X
  1115. X      }
  1116. X
  1117. X
  1118. X}
  1119. X
  1120. X
  1121. X
  1122. X
  1123. X
  1124. Xset_up_in( the_row)
  1125. Xint the_row;
  1126. X{ REVERSE;
  1127. X      switch(the_row)
  1128. X    {
  1129. X     case 13:
  1130. XGOTOXY(13,3);printf("[%s]:",the_index);break;
  1131. Xcase 14:
  1132. XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
  1133. Xcase 15:
  1134. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
  1135. Xcase 16:
  1136. XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
  1137. Xcase 17:
  1138. XGOTOXY(17,3);printf("[%s]:",the_primary); break;
  1139. Xcase 18:
  1140. XGOTOXY(18,3);printf("[%s]:",the_second);  break;
  1141. Xcase 19:
  1142. XGOTOXY(19,3);printf("[%s]:",the_gloss);  break;
  1143. Xcase 20:
  1144. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
  1145. Xcase 21:
  1146. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
  1147. Xcase 22:
  1148. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
  1149. Xcase 23:
  1150. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
  1151. Xcase 24:
  1152. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
  1153. Xcase 25:
  1154. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
  1155. X
  1156. X    }
  1157. X
  1158. X}
  1159. X
  1160. X
  1161. Xset_up_save(the_row, string)
  1162. Xint the_row;
  1163. Xchar *string;
  1164. X{
  1165. X      switch(the_row)
  1166. X    {
  1167. X     case 13:strcpy(the_index,string);break;
  1168. X     case 14:strcpy(the_indexentry,string);break;
  1169. X     case 15:strcpy(the_indexsecond,string);break;
  1170. X     case 16:strcpy(the_seealso,string);break;
  1171. X     case 17:strcpy(the_primary,string);break;
  1172. X     case 18:strcpy(the_second,string);break;
  1173. X     case 19:strcpy(the_gloss,string);break;
  1174. X     case 20:strcpy(g_primary,string);break;
  1175. X     case 21:strcpy(g_second,string);break;
  1176. X     case 22:strcpy(the_delimiter1,string);break;
  1177. X     case 23:strcpy(the_delimiter2,string);break;
  1178. X     case 24:strcpy(the2_delimiter1,string);break;
  1179. X     case 25:strcpy(the2_delimiter2,string);break;
  1180. X
  1181. X    }
  1182. X
  1183. X}
  1184. X
  1185. X
  1186. X
  1187. Xset_up_out(the_row)
  1188. Xint the_row;
  1189. X{  NORMAL;
  1190. X      switch(the_row)
  1191. X    {
  1192. X     case 13:GOTOXY(13,1);ERASE;
  1193. XGOTOXY(13,3); printf("[%s]:",the_index);break;
  1194. Xcase 14:GOTOXY(14,1);ERASE;
  1195. XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
  1196. Xcase 15:GOTOXY(15,1);ERASE;
  1197. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
  1198. Xcase 16:GOTOXY(16,1);ERASE;
  1199. XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
  1200. Xcase 17:GOTOXY(17,1);ERASE;
  1201. XGOTOXY(17,3);printf("[%s]:",the_primary); break;
  1202. Xcase 18:GOTOXY(18,1);ERASE;
  1203. XGOTOXY(18,3);printf("[%s]:",the_second);  break;
  1204. Xcase 19:GOTOXY(19,1);ERASE;
  1205. XGOTOXY(19,3);printf("[%s]:",the_gloss);  break;
  1206. Xcase 20:GOTOXY(20,1);ERASE;
  1207. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
  1208. Xcase 21:GOTOXY(21,1);ERASE;
  1209. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
  1210. Xcase 22:GOTOXY(22,3);printf("                                 ");
  1211. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
  1212. Xcase 23:GOTOXY(22,40);ERASE;
  1213. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
  1214. Xcase 24:GOTOXY(23,3);printf("                               ");
  1215. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
  1216. Xcase 25:GOTOXY(23,40);ERASE;
  1217. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
  1218. X
  1219. X    }
  1220. X
  1221. X}
  1222. X
  1223. Xout_check()
  1224. X{int i, rows, length, trunc;
  1225. Xrows=1;  trunc=256;
  1226. X
  1227. Xstrcpy(out_str,phrase_str);
  1228. Xlength=strlen(out_str);
  1229. X
  1230. Xfor (i=0;i<length; i++)
  1231. X {
  1232. X  if (out_str[i]==10) ++rows;
  1233. X  if (rows==2) {trunc=i-4;break;}
  1234. X }
  1235. X
  1236. X
  1237. Xif (length>trunc) {out_str[trunc]='.';out_str[trunc+1]='.';out_str[trunc+2]='.';
  1238. Xout_str[trunc+3]=0;}
  1239. X}
  1240. X
  1241. X
  1242. X
  1243. Xget_line()
  1244. X{
  1245. Xchar ch;
  1246. Xint ch_count;
  1247. X
  1248. Xch_count=0;
  1249. X
  1250. Xcommand_line[0]=0;
  1251. X
  1252. X     while(1)
  1253. X      { ch=getch();
  1254. X         switch(ch)
  1255. X          {
  1256. X          case 3: all_done(); break;
  1257. X#if unix
  1258. X          case 4: all_done(); break;
  1259. X#endif       
  1260. X          case 0:
  1261. X      case 1:
  1262. X      case 2:
  1263. X
  1264. X      case 5:
  1265. X      case 6: 
  1266. X      case 7:
  1267. X      case 10:
  1268. X      case 11:
  1269. X      case 12:
  1270. X      case 14:
  1271. X      case 15:
  1272. X      case 16:
  1273. X      case 19:
  1274. X      case 20:
  1275. X      case 21:
  1276. X      case 22:
  1277. X      case 23:
  1278. X      case 24:
  1279. X      case 25:
  1280. X      case 26: BELL;break;
  1281. X          case 8:
  1282. X          case 127:
  1283. X              if (ch_count>0){
  1284. X                  CURSOR_LEFT; ERASE;
  1285. X                  command_line[--ch_count]=0;
  1286. X                  }  break;
  1287. X      case 13: if (ch_count>0)
  1288. X             command_line[ch_count]=0;
  1289. X             return;
  1290. X      default: printf("%c",ch);command_line[ch_count++]=ch;
  1291. X
  1292. X     }
  1293. X    }
  1294. X
  1295. X}
  1296. X
  1297. X
  1298. Xstr_search()
  1299. X{
  1300. Xchar *ptr;
  1301. X#if unix
  1302. Xchar *memchr();
  1303. X#endif
  1304. Xint same_page= -1;
  1305. Xvoid  this_page();
  1306. Xint cursor_here=0,i;
  1307. Xcommand_line[0]=0;
  1308. XSAVE_CURSOR;
  1309. X
  1310. XGOTOXY(24,2); REVERSE;
  1311. Xprintf("String:"); NORMAL; printf(" ");
  1312. Xif (the_phrase[0]>0) printf("[%s]", the_phrase);
  1313. Xget_line();
  1314. X
  1315. Xif (command_line[0]>0) strcpy(the_phrase, command_line);
  1316. X  else if (the_phrase[0]==0)  {GOTOXY(24,2); ERASE; RESTORE_CURSOR; 
  1317. X        return;}
  1318. X
  1319. Xptr=buffer;
  1320. Xif (same_page<0)
  1321. X  while ( cursor_here<cursor_mark) {cursor_here++; ptr++;}  
  1322. X
  1323. Xwhile (1){
  1324. X
  1325. Xwhile ((ptr=memchr(ptr, the_phrase[0], buffer_length))!=NULL)
  1326. X    {
  1327. X    if( memcmp(ptr, the_phrase, strlen(the_phrase))==0)
  1328. X      { GOTOXY(24,2); ERASE;
  1329. X       this_page(same_page*cursor_here); return;}
  1330. X    else {ptr++;}       
  1331. X    }
  1332. X
  1333. X   /* Writing the buffer into the output file */
  1334. X
  1335. Xfor (i=cursor_last;i<buffer_length;i++)
  1336. X  {   fprintf(outfile,"%c",buffer[i]);
  1337. X  if ((same_page<0) && (buffer[i]==10))
  1338. X     {
  1339. X      if (next_flag) {
  1340. X             fprintf(outfile, "%s\n", next_str);
  1341. X             next_str[0]=0; next_flag=0;
  1342. X             }
  1343. X     }
  1344. X
  1345. X  }
  1346. X
  1347. X
  1348. Xif (same_page<0)
  1349. X{
  1350. X marker=0;
  1351. Xcursor_last=0;
  1352. Xphrase_on=0;
  1353. Xcursor_mark=0;
  1354. Xbuffer_length=0;
  1355. Xnext_flag=0;
  1356. Xsame_page=1;
  1357. X}
  1358. X
  1359. X
  1360. Xif (end_infile) { end_outfile=1;
  1361. X         GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL;
  1362. XGOTOXY(24, 2); printf("String not found"); 
  1363. Xall_done();
  1364. X exit();}
  1365. X
  1366. Xend_infile=read_in_only(); cursor_here=0; ptr=buffer;
  1367. X }
  1368. X
  1369. X}
  1370. X
  1371. X
  1372. Xint read_in_only()
  1373. X{
  1374. Xint i, quit_s;
  1375. Xchar quit;
  1376. Xchar string[81];
  1377. X
  1378. X
  1379. Xbuffer_length=0;
  1380. Xbuffer[0]=0;
  1381. Xstring[0]=0;
  1382. X           quit_s=0;
  1383. X
  1384. Xfor (i=1;i<=8;i++)
  1385. X  { if( fgets(string,80,infile)==NULL)
  1386. X        {fclose(infile); quit_s=1; goto quit;}
  1387. X           strcat(buffer,string);
  1388. X  }
  1389. X
  1390. Xquit:
  1391. Xbuffer_length=strlen(buffer);
  1392. X
  1393. Xreturn(quit_s);
  1394. X}
  1395. X
  1396. X
  1397. Xvoid this_page(cursor_here)
  1398. Xint cursor_here;
  1399. X{
  1400. Xint i, cursor_there, the_cursor;
  1401. X
  1402. Xif (cursor_here<0) cursor_there= (-1)*cursor_here;
  1403. X   else cursor_there=0;
  1404. X
  1405. Xfor (i=cursor_there;i<buffer_length;i++)
  1406. X if(memcmp(&buffer[i], the_phrase, strlen(the_phrase))==0) 
  1407. X  {the_cursor=i; break;}
  1408. X
  1409. Xif (cursor_here<0) {
  1410. X     if (marker) 
  1411. X      {REVERSE; cursor_mark=cursor_last; cursor_position(); marker=0;
  1412. X       for (i=cursor_last; i<=the_cursor; i++)
  1413. X        {
  1414. X        printf("%c", buffer[i]);
  1415. X        }
  1416. X       NORMAL;
  1417. X      }
  1418. X     cursor_mark= the_cursor;
  1419. X     cursor_position();
  1420. X      }
  1421. X    else 
  1422. X   {
  1423. X   position();
  1424. X   NORMAL; CLS_UP(); NORMAL; 
  1425. X   GOTOXY(3,1);
  1426. X   for (i=0;i<buffer_length;i++)
  1427. X     printf("%c", buffer[i]);
  1428. X   cursor_mark=the_cursor;
  1429. X   cursor_position();
  1430. X   }
  1431. X
  1432. Xreturn;
  1433. X}
  1434. X
  1435. X
  1436. X
  1437. X/* for ultrix define V7 = 1 */
  1438. X
  1439. X/*
  1440. X * The functions in this file negotiate with the operating system for
  1441. X * characters, and write characters in a barely buffered fashion on the display.
  1442. X * All operating systems.
  1443. X */
  1444. X
  1445. X
  1446. X#if   MSDOS & TURBO
  1447. X#include <conio.h>
  1448. X#endif
  1449. X
  1450. X#if     AMIGA
  1451. X#define NEW 1006L
  1452. X#define AMG_MAXBUF      1024L
  1453. Xstatic long terminal;
  1454. Xstatic char     scrn_tmp[AMG_MAXBUF+1];
  1455. Xstatic long     scrn_tmp_p = 0;
  1456. X#endif
  1457. X
  1458. X#if     CPM
  1459. X#include        <bdos.h>
  1460. X#endif
  1461. X
  1462. X#if     MSDOS & (LATTICE | MSC | TURBO | AZTEC | MWC86)
  1463. Xunion REGS rg;          /* cpu register for use of DOS calls */
  1464. Xint nxtchar = -1;       /* character held from type ahead    */
  1465. X#endif
  1466. X
  1467. X#if RAINBOW
  1468. X#include "rainbow.h"
  1469. X#endif
  1470. X
  1471. X#if     USG                     /* System V */
  1472. X#include        <signal.h>
  1473. X#include        <termio.h>
  1474. X#include        <fcntl.h>
  1475. Xint kbdflgs;                    /* saved keyboard fd flags      */
  1476. Xint kbdpoll;                    /* in O_NDELAY mode                     */
  1477. Xint kbdqp;                      /* there is a char in kbdq      */
  1478. Xchar kbdq;                      /* char we've already read      */
  1479. Xstruct  termio  otermio;        /* original terminal characteristics */
  1480. Xstruct  termio  ntermio;        /* charactoristics to use inside */
  1481. X#endif
  1482. X
  1483. X#if V7 | BSD
  1484. X/*
  1485. X#undef  CTRL
  1486. X*/
  1487. X#include        <sgtty.h>        /* for stty/gtty functions */
  1488. X#include        <signal.h>
  1489. Xstruct  sgttyb  ostate;          /* saved tty state */
  1490. Xstruct  sgttyb  nstate;          /* values for editor mode */
  1491. Xstruct tchars   otchars;        /* Saved terminal special character set */
  1492. Xstruct tchars   ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1493. X                                /* A lot of nothing */
  1494. X#if BSD
  1495. X#include <sys/ioctl.h>          /* to get at the typeahead */
  1496. Xextern  int rtfrmshell();       /* return from suspended shell */
  1497. X#define         TBUFSIZ         128
  1498. Xchar tobuf[TBUFSIZ];            /* terminal output buffer */
  1499. X#endif
  1500. X#endif
  1501. X
  1502. X/*
  1503. X * This function is called once to set up the terminal device streams.
  1504. X */
  1505. Xttopen()
  1506. X{
  1507. X
  1508. X#if     AMIGA
  1509. X        char oline[NSTRING];
  1510. X#if     AZTEC
  1511. X        extern  Enable_Abort;   /* Turn off ctrl-C interrupt */
  1512. X
  1513. X        Enable_Abort = 0;       /* for the Manx compiler */
  1514. X#endif
  1515. X        strcpy(oline, "RAW:0/0/640/200/");
  1516. X        strcat(oline, PROGNAME);
  1517. X        strcat(oline, " ");
  1518. X        strcat(oline, VERSION);
  1519. X        strcat(oline, "/Amiga");
  1520. X        terminal = Open(oline, NEW);
  1521. X#endif
  1522. X#if     CPM
  1523. X#endif
  1524. X
  1525. X#if     MSDOS & (HP150 == 0) & LATTICE
  1526. X        /* kill the ctrl-break interupt */
  1527. X        rg.h.ah = 0x33;                 /* control-break check dos call */
  1528. X        rg.h.al = 1;            /* set the current state */
  1529. X        rg.h.dl = 0;            /* set it OFF */
  1530. X        intdos(&rg, &rg);       /* go for it! */
  1531. X#endif
  1532. X
  1533. X#if     USG
  1534. X        ioctl(0, TCGETA, &otermio);     /* save old settings */
  1535. X        ntermio.c_iflag = 0;            /* setup new settings */
  1536. X        ntermio.c_oflag = 0;
  1537. X        ntermio.c_cflag = otermio.c_cflag;
  1538. X        ntermio.c_lflag = 0;
  1539. X        ntermio.c_line = otermio.c_line;
  1540. X        ntermio.c_cc[VMIN] = 1;
  1541. X        ntermio.c_cc[VTIME] = 0;
  1542. X        ioctl(0, TCSETA, &ntermio);     /* and activate them */
  1543. X        kbdflgs = fcntl( 0, F_GETFL, 0 );
  1544. X        kbdpoll = FALSE;
  1545. X#endif
  1546. X
  1547. X#if     V7 | BSD
  1548. Xif (tt_status==tt_open) return;
  1549. X        gtty(0, &ostate);                       /* save old state */
  1550. X        gtty(0, &nstate);                       /* get base of new state */
  1551. X        nstate.sg_flags |= RAW;
  1552. X        nstate.sg_flags &= ~(ECHO|CRMOD);       /* no echo for now... */
  1553. X        stty(0, &nstate);                       /* set mode */
  1554. X        ioctl(0, TIOCGETC, &otchars);           /* Save old characters */
  1555. X        ioctl(0, TIOCSETC, &ntchars);           /* Place new character into K */
  1556. Xtt_status=tt_open;
  1557. X#if     BSD
  1558. X        /* provide a smaller terminal output buffer so that
  1559. X           the type ahead detection works better (more often) */
  1560. X        setbuffer(stdout, &tobuf[0], TBUFSIZ);
  1561. X/*---        signal(SIGTSTP,SIG_DFL);         set signals so that we can
  1562. X        signal(SIGCONT,rtfrmshell);      suspend & restart emacs */
  1563. X#endif
  1564. X#endif
  1565. X        /* on all screens we are not sure of the initial position
  1566. X           of the cursor                                        */
  1567. X/*---   ttrow = 999;
  1568. X        ttcol = 999; */
  1569. X
  1570. X}
  1571. X
  1572. X/*
  1573. X * This function gets called just before we go back home to the command
  1574. X * interpreter. 
  1575. X * Another no-operation on CPM.
  1576. X */
  1577. Xttclose()
  1578. X{
  1579. X
  1580. X#if     AMIGA
  1581. X#if     LATTICE
  1582. X        amg_flush();
  1583. X        Close(terminal);
  1584. X#endif
  1585. X#if     AZTEC
  1586. X        amg_flush();
  1587. X        Enable_Abort = 1;       /* Fix for Manx */
  1588. X        Close(terminal);
  1589. X#endif
  1590. X#endif
  1591. X#if     CPM
  1592. X#endif
  1593. X#if     MSDOS & (HP150 == 0) & LATTICE
  1594. X        /* restore the ctrl-break interupt */
  1595. X        rg.h.ah = 0x33;                 /* control-break check dos call */
  1596. X        rg.h.al = 1;            /* set the current state */
  1597. X        rg.h.dl = 1;            /* set it ON */
  1598. X        intdos(&rg, &rg);       /* go for it! */
  1599. X#endif
  1600. X
  1601. X#if     USG
  1602. X        ioctl(0, TCSETA, &otermio);     /* restore terminal settings */
  1603. X        fcntl(0, F_SETFL, kbdflgs);
  1604. X#endif
  1605. X
  1606. X#if     V7 | BSD
  1607. Xif (tt_status==tt_close) return;
  1608. X        stty(0, &ostate);
  1609. X        ioctl(0, TIOCSETC, &otchars);   /* Place old character into K */
  1610. Xtt_status=tt_close;
  1611. X#endif
  1612. X
  1613. X
  1614. X}
  1615. X
  1616. X#if     AMIGA
  1617. Xamg_flush()
  1618. X{
  1619. X        if(scrn_tmp_p)
  1620. X                Write(terminal,scrn_tmp,scrn_tmp_p);
  1621. X        scrn_tmp_p = 0;
  1622. X}
  1623. X#endif
  1624. X
  1625. X/*
  1626. X * Flush terminal buffer. Does real work where the terminal output is buffered
  1627. X * up. A no-operation on systems where byte at a time terminal I/O is done.
  1628. X */
  1629. Xttflush()
  1630. X{
  1631. X#if     AMIGA
  1632. X        amg_flush();
  1633. X#endif
  1634. X
  1635. X#if     CPM
  1636. X#endif
  1637. X
  1638. X#if     MSDOS
  1639. X#endif
  1640. X
  1641. X#if     V7 | USG | BSD
  1642. X        fflush(stdout);
  1643. X#endif
  1644. X}
  1645. X
  1646. X/*
  1647. X * Read a character from the terminal, performing no editing and doing no echo
  1648. X * at all.
  1649. X */
  1650. Xttgetc()
  1651. X{
  1652. X#if     AMIGA
  1653. X        char ch;
  1654. X        amg_flush();
  1655. X        Read(terminal, &ch, 1L);
  1656. X        return(255 & (int)ch);
  1657. X#endif
  1658. X#if     CPM
  1659. X        return (biosb(BCONIN, 0, 0));
  1660. X#endif
  1661. X
  1662. X#if RAINBOW
  1663. X        int Ch;
  1664. X
  1665. X        while ((Ch = Read_Keyboard()) < 0);
  1666. X
  1667. X        if ((Ch & Function_Key) == 0)
  1668. X                if (!((Ch & 0xFF) == 015 || (Ch & 0xFF) == 0177))
  1669. X                        Ch &= 0xFF;
  1670. X
  1671. X        return Ch;
  1672. X#endif
  1673. X
  1674. X#if     MSDOS & MWC86
  1675. X        return (getcnb());
  1676. X#endif
  1677. X
  1678. X#if     MSDOS & (LATTICE | MSC | TURBO | AZTEC)
  1679. X        int c;          /* character read */
  1680. X
  1681. X        /* if a char already is ready, return it */
  1682. X        if (nxtchar >= 0) {
  1683. X                c = nxtchar;
  1684. X                nxtchar = -1;
  1685. X                return(c);
  1686. X        }
  1687. X
  1688. X        /* call the dos to get a char */
  1689. X        rg.h.ah = 7;            /* dos Direct Console Input call */
  1690. X        intdos(&rg, &rg);
  1691. X        c = rg.h.al;            /* grab the char */
  1692. X        return(c & 255);
  1693. X#endif
  1694. X
  1695. X#if     V7 | BSD
  1696. X        return(127 & fgetc(stdin));
  1697. X#endif
  1698. X
  1699. X#if     USG
  1700. X        if( kbdqp )
  1701. X                kbdqp = FALSE;
  1702. X        else
  1703. X        {
  1704. X                if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
  1705. X                        return FALSE;
  1706. X                kbdpoll = FALSE;
  1707. X                while (read(0, &kbdq, 1) != 1)
  1708. X                        ;
  1709. X        }
  1710. X        return ( kbdq & 127 );
  1711. X#endif
  1712. X}
  1713. X
  1714. XNewsgroups: comp.text,comp.source.unix
  1715. XSubject: Indexor for Scribe, LaTeX/TeX, *roff and etc
  1716. XExpires: 
  1717. XReferences: 
  1718. XSender: 
  1719. XReply-To: jbw@unix.cis.pittsburgh.edu (Jingbai  Wang)
  1720. XFollowup-To: 
  1721. XDistribution: na
  1722. XOrganization: Univ. of Pittsburgh, Comp & Info Sys
  1723. XKeywords: 
  1724. X
  1725. X
  1726. XIf you are a technical writer or book writer, you would have found that
  1727. Xthe most tedious job is to add an index to a book you have written. I am
  1728. Xa heavy writer, and I use Scribe (with my own TEC.mak data base) and
  1729. XTeX/LaTeX to format books.
  1730. X
  1731. XTo overcome the tediousness and boresomeness of index making, I developed
  1732. Xa program in C named 'indexor' that I revealed in a previous message in
  1733. Xcomp.text. Here I am introducing the source code into comp.text and
  1734. Xcomp.source.unix. 
  1735. X
  1736. XThis program named `indexor.c' can be compiled on VMS, UNIX or DOS, and have
  1737. Xhelped me with two lengthy books already. You can called it a semi-automatic
  1738. Xindex insertor. You need an ANSI terminal (like vt100, vt102) to make
  1739. Xit work properly.
  1740. X
  1741. XCut here
  1742. X_________________________________________________________________
  1743. X
  1744. X
  1745. X/*  Copyright (C) 1988 by Jingbai Wang */
  1746. X
  1747. X
  1748. X/* **********************************************************************
  1749. X *            This program is an auxiliary program for Scribe and TeX   *
  1750. X *               It inserts index and glossary into Scribe/LaTeX file   *
  1751. X *                  It is an important program for book editing         *
  1752. X *    The user can set up the programs for other formattors like troff  *
  1753. X *                                                                      *
  1754. X *                    Copyright by Jingbai Wang August 1988             *
  1755. X *                                                                      *
  1756. X *    jbw@pittvms.bitnet                                                *
  1757. X *    jbw@cisunx.UUCP                                                   *
  1758. X ************************************************************************/
  1759. X/*
  1760. X    This program was created in 1988 by myself in order to include an
  1761. X    index in the Scribe and TeX/LaTeX manuals I was writing. It is part
  1762. X    of the Scribe TEC.mak package I developed, and can be re-distributed
  1763. X    freely for non-profit purposes.
  1764. X
  1765. X    It is like a special editor to introduce index entries into a Scribe,
  1766. X    LaTeX, TeX or *troff file. It indeed makes a tedious and boresome job
  1767. X    enjoyable.
  1768. X    The primary attempt is to make this program portable among
  1769. X    VAX/VMS, UNIX (BSD and Ultrix), and DOS (MSC and MS Quick C).
  1770. X
  1771. X    To compile on our VMS,
  1772. X    $ex indexor
  1773. X
  1774. X    and on UNIX,
  1775. X    %cc -o indexor indexor.c
  1776. X
  1777. X    It takes two on-line arguments, i.e., the input and output file names,
  1778. X    but you can also provide these piece of information when running it.
  1779. X    The program is self-instructive, no documentation is necessary.
  1780. X*/
  1781. X
  1782. X#include <string.h>
  1783. X#include <stdio.h>
  1784. X#define CLS printf("\033[2J")
  1785. X#define GOTOXY(x,y) printf("\033[%d;%df",x,y)
  1786. X#define REVERSE printf("\033[7m")
  1787. X#define NORMAL printf("\033[0m")
  1788. X#define SAVE_CURSOR printf("\033[s")
  1789. X#define BLINK printf("\033[5m")
  1790. X#define BOLD printf("\033[1m")
  1791. X#define UNDER printf("\033[4m")
  1792. X#define ERASE printf("\033[K")
  1793. X#define CURSOR_REPORT(x, y) scanf("\033[%d;%dR",x,y)
  1794. X#define BELL printf("%c", 7)
  1795. X#define CURSOR_RIGHT printf("\033[1C")
  1796. X#define CURSOR_LEFT printf("\033[1D")
  1797. X
  1798. X#define tt_open 1
  1799. X#define tt_close 0
  1800. Xint tt_status=0;
  1801. X
  1802. X#if VMS|unix
  1803. X#define RESTORE_CURSOR cursor_position()
  1804. X#else
  1805. X#define RESTORE_CURSOR printf("\033[u")
  1806. X#endif
  1807. X
  1808. X#if ultrix
  1809. X#define V7 1
  1810. X#endif
  1811. X
  1812. X#if unix|VMS
  1813. X/*   ANSI escape, good for mainframe systems vt100 terminals, e.g., VAX*/
  1814. X#define DEL 127
  1815. X#define EXT 27
  1816. X#define EXT1 '['
  1817. X#define R_ARROW 'C'
  1818. X#define L_ARROW 'D'
  1819. X#define D_ARROW 'B'
  1820. X#define U_ARROW 'A'
  1821. X
  1822. X#if VMS
  1823. X#include        <descrip.h>
  1824. X#include        <iodef.h>
  1825. X#include        <ssdef.h>
  1826. Xshort   iochan;                  /* TTY I/O channel             */
  1827. X#endif
  1828. X
  1829. X
  1830. X#else
  1831. X /* MSDOS extended code escape */
  1832. X#define DEL  8
  1833. X#define EXT  0  
  1834. X#define R_ARROW 77
  1835. X#define L_ARROW 75
  1836. X#define D_ARROW 80
  1837. X#define U_ARROW 72
  1838. X#endif
  1839. X
  1840. XFILE *infile;
  1841. XFILE *outfile;
  1842. Xchar buffer[720];
  1843. Xint buffer_length;
  1844. Xint buffer_line[11];
  1845. Xint lines=1;
  1846. Xint cursor_mark=0;
  1847. Xint cursor_last=0;
  1848. X
  1849. Xchar marker=0;
  1850. Xchar phrase_str[512]="";
  1851. Xchar the_phrase[512];
  1852. Xchar save_str[128]="";
  1853. Xchar out_str[512]="";
  1854. Xint phrase_on, phrase_off, phrase_len;
  1855. Xchar end_infile=0;
  1856. Xchar end_outfile=0;
  1857. Xchar exit_flag=0;
  1858. Xchar word_mark=0;
  1859. Xchar the_index[20]="@Index";
  1860. Xchar the_delimiter1[3]="{";
  1861. Xchar the_delimiter2[3]="}";
  1862. Xchar the2_delimiter1[3]="<";
  1863. Xchar the2_delimiter2[3]=">";
  1864. Xchar the_primary[20]="Primary=";
  1865. Xchar the_second[20]="Secondary=";
  1866. Xchar the_gloss[20]="@glossary";
  1867. Xchar g_primary[20]="symbol=";
  1868. Xchar g_second[20]="expln=";
  1869. Xchar the_indexsecond[20]="@IndexSecondary";
  1870. Xchar the_seealso[20]="@SeeAlso";
  1871. Xchar the_indexentry[20]="@IndexEntry";
  1872. Xchar the_entry[20]="Entry=";
  1873. Xchar the_key[20]="Key=";
  1874. Xchar the_number[20]="Number=";
  1875. X
  1876. Xstruct CUR
  1877. X{
  1878. Xshort int x;
  1879. Xshort int y;
  1880. X} chr[720];
  1881. X
  1882. Xchar next_str[512];
  1883. Xchar next_flag=0;
  1884. Xchar command_line[160];
  1885. X
  1886. X
  1887. X
  1888. X/* The getch() and getche() */
  1889. X
  1890. X#if VMS
  1891. Xchar getch()
  1892. X{
  1893. Xint ibuf,status;
  1894. Xint     iosb[2];
  1895. X                        status = SYS$QIOW(0, iochan, IO$_READLBLK|IO$M_NOECHO,
  1896. X                                 iosb, 0, 0, &ibuf, 1, 0, 0, 0, 0);
  1897. X
  1898. X        return (ibuf & 0xFF);    /* Allow multinational  */
  1899. X
  1900. X}
  1901. X
  1902. X#endif
  1903. X
  1904. X
  1905. X#if unix | ultrix | BSD
  1906. X
  1907. Xchar getch()
  1908. X{
  1909. Xint tmpch;
  1910. Xttopen();
  1911. Xtmpch=ttgetc();
  1912. Xttclose();
  1913. Xreturn(tmpch);
  1914. X}
  1915. X#endif
  1916. X
  1917. X
  1918. X#if unix | VMS
  1919. Xchar getche()
  1920. X{
  1921. Xchar inchar;
  1922. Xfputc(getch(), stdout);
  1923. Xreturn((int)inchar);
  1924. X}
  1925. X
  1926. X#endif
  1927. X
  1928. Xread_in()
  1929. X{
  1930. Xint i, quit_s;
  1931. Xchar string[81],quit;
  1932. XGOTOXY(3,1);
  1933. Xbuffer_length=0;
  1934. Xbuffer[0]=0;
  1935. Xstring[0]=0;
  1936. X           quit_s=0;
  1937. X
  1938. X
  1939. Xfor (i=1;i<=8;i++)
  1940. X  { if( fgets(string,80,infile)==NULL)  { end_infile=1;
  1941. X           quit_s=1; goto quit;}
  1942. X     else { printf("%s",string);
  1943. X           strcat(buffer,string);
  1944. X           }
  1945. X  }
  1946. X
  1947. Xquit:
  1948. Xbuffer_length=strlen(buffer);
  1949. X
  1950. Xposition();
  1951. XGOTOXY(3,1);
  1952. Xreturn(quit_s);
  1953. X }
  1954. X
  1955. Xposition()
  1956. X{
  1957. Xint i,j;
  1958. Xint row,col;
  1959. Xchar ch;
  1960. Xrow=3; col=1;
  1961. Xbuffer_line[1]=0;
  1962. Xlines=1;
  1963. X
  1964. Xfor(i=0;i<buffer_length;i++)
  1965. X  {  ch=buffer[i];
  1966. X   chr[i].x=row; chr[i].y=col++;
  1967. X
  1968. X   if(ch==10) {row++;col=1;lines++;buffer_line[lines]=i+1;}
  1969. X
  1970. X   if (col==81) {row++;col=1;lines++; buffer_line[lines]=i+1;}
  1971. X   }  
  1972. X
  1973. X}
  1974. X
  1975. X
  1976. Xmark_begin()
  1977. X{
  1978. Xint i;
  1979. X
  1980. X for (i=cursor_last;i<cursor_mark;i++)
  1981. X      {fprintf(outfile, "%c", buffer[i]);
  1982. X        if (buffer[i]==10)
  1983. X     {if (next_flag==1) {
  1984. X             fprintf(outfile, "%s\n", next_str);
  1985. X             next_str[0]=0; next_flag=0;
  1986. X             }
  1987. X     }
  1988. X       
  1989. X      }
  1990. Xmarker=1;
  1991. Xcursor_last=cursor_mark;
  1992. Xphrase_len=0;
  1993. Xphrase_on=cursor_mark;
  1994. Xphrase_str[0]=0;
  1995. XREVERSE;
  1996. Xprintf("%c",buffer[cursor_mark]);
  1997. Xcursor_position();
  1998. X}
  1999. X
  2000. Xmark_end()
  2001. X{
  2002. Xint i, length;
  2003. Xchar  ch;
  2004. Xmarker=0;
  2005. X
  2006. X for (i=cursor_last;i<=cursor_mark;i++)
  2007. X      { fprintf(outfile, "%c", buffer[i]);
  2008. X         if (buffer[i]==10)
  2009. X     { 
  2010. X           if (next_flag==1) {
  2011. X             fprintf(outfile, "%s\n", next_str);
  2012. X             next_str[0]=0; next_flag=0;
  2013. X             }
  2014. X     }
  2015. X
  2016. X
  2017. X      }
  2018. X
  2019. Xlength=strlen(phrase_str);
  2020. Xphrase_off=cursor_mark;
  2021. Xcursor_last=cursor_mark+1;
  2022. Xcursor_mark=cursor_last; cursor_position();
  2023. Xfor (i=phrase_on; i<=phrase_off;i++)
  2024. X  { ch=buffer[i];
  2025. X   if ((ch==13)||(ch==10)) ch=32;
  2026. X    phrase_str[length+i-phrase_on]=ch;
  2027. X  }
  2028. Xphrase_str[length+1+phrase_off-phrase_on]=0;
  2029. Xphrase_on=0; phrase_off=0;
  2030. XNORMAL;
  2031. X}
  2032. X
  2033. Xcursor_position()
  2034. X{
  2035. XGOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  2036. EOF
  2037. chars=`wc -c < 'indexor.c-1'`
  2038. if test $chars !=    44172; then echo 'indexor.c-1' is $chars characters, should be    44172 characters!; fi
  2039. fi
  2040. exit 0
  2041.