home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume7 / indexor / part02 < prev    next >
Encoding:
Text File  |  1989-07-23  |  32.1 KB  |  1,410 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Univ. of Pittsburgh, Comp & Info Sys
  3. subject: v07i101: Index insertor for Scribe, TeX/LaTeX, *roff, etc. part 02/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 101
  8. Submitted-by: jbw@unix.cis.pittsburgh.edu (Jingbai  Wang)
  9. Archive-name: indexor/part02
  10.  
  11. [[See part 1 for unpacking instructions.  ++bsa]]
  12. #! /bin/sh
  13. # This file was wrapped with "dummyshar".  "sh" this file to extract.
  14. # Contents:  indexor.c-2
  15. echo extracting 'indexor.c-2'
  16. if test -f 'indexor.c-2' -a -z "$1"; then echo Not overwriting 'indexor.c-2'; else
  17. sed 's/^X//' << \EOF > 'indexor.c-2'
  18. X
  19. X}
  20. X
  21. Xcursor_right()
  22. X{
  23. X
  24. Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
  25. X   ++cursor_mark; cursor_position();
  26. X   if (marker==1) printf("%c",buffer[cursor_mark]);
  27. X   GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  28. X
  29. X}
  30. X
  31. Xcursor_left()
  32. X{
  33. X  if (cursor_mark<=cursor_last) {cursor_mark=cursor_last; cursor_position();BELL; return;}
  34. X  NORMAL; cursor_position();printf("%c",buffer[cursor_mark]);
  35. X  --cursor_mark;
  36. X  if (marker==1) REVERSE;
  37. X  GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  38. X
  39. X
  40. X}
  41. X
  42. Xcursor_down()
  43. X{
  44. Xint i,the_stop;
  45. Xchar check;
  46. Xthe_stop=cursor_mark;
  47. X
  48. Xcursor_position();
  49. Xfor (i=cursor_mark;i<buffer_length;i++)
  50. X {if (i>=buffer_length-2) {next_page();return;}
  51. X  if (buffer[i]==10) {cursor_mark=i+1;
  52. X     cursor_position();goto check;}
  53. X }
  54. X
  55. Xcheck:
  56. X  if (marker)
  57. X   { GOTOXY(chr[the_stop].x,chr[the_stop].y);
  58. X     for (i=the_stop;i<=cursor_mark;i++)
  59. X      printf("%c",buffer[i]);
  60. X     cursor_position();
  61. X   }
  62. X}
  63. X
  64. Xcursor_up()
  65. X{
  66. Xchar check;
  67. Xint i,the_stop;
  68. Xif (cursor_mark<=cursor_last) {cursor_mark=cursor_last;cursor_position(); BELL; return;}
  69. X
  70. Xcursor_position();the_stop=cursor_mark;
  71. Xfor (i=cursor_mark;i>=cursor_last;i--)
  72. X {
  73. X  if (buffer[i]==10) {cursor_mark=i-1;
  74. X  GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  75. X  goto check;}
  76. X }
  77. X cursor_mark=cursor_last; cursor_position(); BELL;
  78. X
  79. Xcheck:
  80. X  if (marker)
  81. X   {
  82. X    NORMAL; GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
  83. X    for (i=cursor_mark+1;i<=the_stop;i++)
  84. X       printf("%c",buffer[i]);
  85. X    REVERSE;
  86. X    GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
  87. X   }
  88. X
  89. X}
  90. X
  91. X
  92. X
  93. X
  94. X
  95. X
  96. Xmark_word()
  97. X{
  98. Xif (marker==0) mark_begin(); word_skip();return;
  99. X}
  100. X
  101. Xpass_marked()
  102. X{
  103. Xint i;
  104. Xif (marker==0) { word_skip();return;}
  105. XGOTOXY(chr[cursor_last].x,chr[cursor_last].y);
  106. Xmarker=0; NORMAL;
  107. X phrase_str[0]= 0;
  108. X for (i=cursor_last;i<=cursor_mark;i++)
  109. X     printf("%c",buffer[i]);
  110. X
  111. Xcursor_mark=cursor_last;
  112. Xcursor_position();
  113. X}
  114. X
  115. X
  116. Xword_skip()
  117. X{
  118. Xint i, the_stop;
  119. Xchar check;
  120. X
  121. Xthe_stop=cursor_mark;
  122. Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
  123. X
  124. Xcursor_right();
  125. Xfor (i=cursor_mark; i<buffer_length;i++)
  126. X {
  127. X
  128. X  switch(buffer[i])
  129. X   {case '!':
  130. X    case ',':
  131. X    case '"':
  132. X    case '\'':
  133. X    case '`':
  134. X    case '(':
  135. X    case ')':
  136. X    case '[':
  137. X    case ']':
  138. X    case '/':
  139. X    case '+':
  140. X    case '=':
  141. X    case '?':
  142. X    case '<':
  143. X    case '>':
  144. X    case '{':
  145. X    case '}':
  146. X    case '*':
  147. X    case '^':
  148. X    case '&':
  149. X    case '#':
  150. X    case ':':
  151. X    case ';':
  152. X    case '|':
  153. X    case  9:
  154. X    case 10:
  155. X    case 13:
  156. X    case '~':
  157. X    case '@':
  158. X    case '\\':
  159. X    case 32:
  160. X    case '.': if (word_mark) {word_mark=0;cursor_mark=i-1;
  161. X                 cursor_position();
  162. X                 goto check;}
  163. X          else break;
  164. X    default:   word_mark=1;
  165. X
  166. X   }
  167. X  }
  168. X
  169. Xcheck:
  170. X  if(marker)
  171. X   { GOTOXY(chr[the_stop].x,chr[the_stop].y);
  172. X     for (i=the_stop;i<=cursor_mark;i++)
  173. X    printf("%c",buffer[i]);
  174. X    cursor_position();
  175. X   }
  176. X
  177. X}
  178. X
  179. X
  180. X
  181. Xword_back()
  182. X{
  183. Xint i, the_stop;
  184. Xchar check;
  185. Xthe_stop=cursor_mark;
  186. Xcursor_left();
  187. Xfor (i=cursor_mark; i>=0;i--)
  188. X { if (i<=cursor_last) {cursor_mark=cursor_last;
  189. X            cursor_position();BELL;goto check;}
  190. X
  191. X  switch(buffer[i])
  192. X   {case '!':
  193. X    case ',':
  194. X    case '"':
  195. X    case '\'':
  196. X    case '`':
  197. X    case '(':
  198. X    case ')':
  199. X    case '[':
  200. X    case ']':
  201. X    case '/':
  202. X    case '+':
  203. X    case '=':
  204. X    case '?':
  205. X    case '<':
  206. X    case '>':
  207. X    case '{':
  208. X    case '}':
  209. X    case '*':
  210. X    case '^':
  211. X    case '&':
  212. X    case '#':
  213. X    case ':':
  214. X    case ';':
  215. X    case '|':
  216. X    case  9:
  217. X    case 10:
  218. X    case 13:
  219. X    case '~':
  220. X    case '@':
  221. X    case '\\':
  222. X    case 32:
  223. X    case '.':
  224. X         if (word_mark) {word_mark=0; cursor_mark=i; cursor_position();
  225. X        goto check;
  226. X          }
  227. X          else  break;
  228. X    default:   word_mark=1;
  229. X
  230. X    }
  231. X  }
  232. X
  233. Xcheck:
  234. X  if (marker)
  235. X   {GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
  236. X    NORMAL;
  237. X     for (i=cursor_mark+1;i<=the_stop;i++)
  238. X     printf("%c",buffer[i]);
  239. X
  240. X    REVERSE;
  241. X    cursor_position();
  242. X   }
  243. X}
  244. X
  245. X
  246. Xnext_page()
  247. X{
  248. Xint i, length, pre_row, ch_count;
  249. X
  250. XNORMAL;
  251. XCLS_UP();
  252. XGOTOXY(1,1);  pre_row=0; ch_count=0;
  253. X
  254. Xif (end_outfile) {BELL; return;}
  255. X
  256. X
  257. Xif (marker){
  258. X if ((strlen(phrase_str)+strlen(&buffer[phrase_on]))<510)
  259. X  strcat(phrase_str, &buffer[phrase_on]);
  260. X else marker=0;
  261. X}
  262. X
  263. Xfor (i=buffer_line[lines-2];i<buffer_length;i++)
  264. X {
  265. X if ((marker==1) && (i>=phrase_on)) {REVERSE;}
  266. X   printf("%c", buffer[i]);
  267. X }
  268. X
  269. Xfor (i=cursor_last;i<buffer_length;i++)
  270. X  {   fprintf(outfile,"%c",buffer[i]);
  271. X  if (buffer[i]==10)
  272. X     {
  273. X      if (next_flag==1) {
  274. X             fprintf(outfile, "%s\n", next_str);
  275. X             next_str[0]=0; next_flag=0;
  276. X             }
  277. X     }
  278. X
  279. X  }
  280. X
  281. X
  282. Xcursor_last=0;
  283. Xphrase_on=0;
  284. Xcursor_mark=0;
  285. Xbuffer_length=0;
  286. XNORMAL;
  287. X
  288. Xif (end_infile) {end_outfile=1;
  289. X         GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL; return;}
  290. X
  291. Xend_infile=read_in();
  292. Xif (marker) {REVERSE; printf("%c",buffer[0]);cursor_position();}
  293. X}
  294. X
  295. X
  296. Xcontrol(inchar)
  297. Xchar inchar;
  298. X{
  299. Xchar ch;
  300. X
  301. X
  302. X switch(inchar)
  303. X     {
  304. X       case EXT:
  305. X#if unix|VMS
  306. X             /* mainframe  environment  */
  307. X               if (getch()!=EXT1) {BELL;break;}
  308. X               ch=getch();
  309. X#else
  310. X             /* DOS environment              */ 
  311. X
  312. X             ch=getch();
  313. X#endif            
  314. X
  315. X             switch(ch)
  316. X              { 
  317. X               case L_ARROW: cursor_left(); 
  318. X                   break;
  319. X               case R_ARROW: cursor_right();
  320. X                   break;
  321. X               case D_ARROW: cursor_down();
  322. X                   break;
  323. X           case U_ARROW: cursor_up();
  324. X                   break;
  325. X               default: BELL;
  326. X              }
  327. X
  328. X          break;
  329. X       case 13: if (marker==0) {mark_begin(); break;}
  330. X                if (marker==1) 
  331. X                 {mark_end(); index_now();}
  332. X                 break;     
  333. X       case 9:  word_skip(); break;
  334. X       case 'b':
  335. X       case 'B':
  336. X       case 8:
  337. X       case 127:
  338. X                word_back(); break;
  339. X       case 32: next_page(); break;
  340. X       case 'n':
  341. X       case 'N': if (marker==1) 
  342. X                {mark_end();index_next_line();} 
  343. X                 else BELL; break;    
  344. X       case 'p':
  345. X       case 'P': pass_marked(); break;
  346. X       case 'f':
  347. X       case 'F': finish_up(); return(1); break;
  348. X       case 'a':
  349. X       case 'A': if (marker==1) mark_end(); see_also();break;
  350. X       case 's':
  351. X       case 'S': if (marker==1) mark_end();index_secondary();break;
  352. X       case 'i':
  353. X       case 'I': if (marker==1) mark_end();index_entry();break;
  354. X       case 'g':
  355. X       case 'G': if (marker==1) mark_end();
  356. X          else warning("No current marked, will take the previous one");
  357. X         glossary();
  358. X           break;
  359. X       case 'W':
  360. X       case 'w': mark_word(); break;
  361. X       case '@': set_up(); break;
  362. X       case  6 : str_search(); break;
  363. X       case  3 : all_done(); break;
  364. X#if unix
  365. X       case  4 : all_done(); break;
  366. X#endif
  367. X       default: BELL;
  368. X   }
  369. X
  370. X
  371. X}
  372. X
  373. X
  374. X
  375. X
  376. Xmain(argc, argv)
  377. Xint argc;
  378. Xchar *argv[];
  379. X{
  380. Xint in_file,out_file, status;
  381. Xint i,j;
  382. Xchar infile_name[30], outfile_name[30];
  383. Xchar out_ok=1;
  384. Xchar ch, quit;
  385. Xchar getch();
  386. X
  387. X#if     VMS
  388. X$DESCRIPTOR(terminal,"TT");
  389. X
  390. X        status = SYS$ASSIGN(&terminal, &iochan, 0, 0);
  391. X        if (status != SS$_NORMAL) exit(status);
  392. X
  393. Xsystem("set broadcast=none");
  394. X
  395. X#endif
  396. X
  397. X
  398. XNORMAL;
  399. XCLS;
  400. Xswitch(argc)
  401. X  {
  402. X    case 1: in_file=1; out_file=1; break;
  403. X    case 2: in_file=0; out_file=1; strcpy(infile_name,argv[1]); break;
  404. X    default: in_file=0;out_file=0;
  405. X           strcpy(infile_name,argv[1]); 
  406. X           strcpy(outfile_name,argv[2]); break;
  407. X  }
  408. X
  409. X if (in_file) 
  410. X   {GOTOXY(5,15);
  411. X   printf(" Input file (file to be indexed) >");
  412. X   scanf("%s",infile_name);
  413. X   fflush(stdin);
  414. X   }
  415. X
  416. X   if ((infile=fopen(infile_name,"r"))==NULL)
  417. X     {GOTOXY(20,20); BLINK;
  418. X       printf("Can't find the input file");
  419. X       NORMAL; goto quit;
  420. X     }
  421. X
  422. Xwhile (out_ok)
  423. X
  424. X {
  425. X  if (out_file) 
  426. X    {GOTOXY(6,15); ERASE;
  427. X    printf(" Output file (indexed file) >");
  428. X    fscanf(stdin, "%s",outfile_name);
  429. X    fflush(stdin);
  430. X    }
  431. X
  432. X
  433. X    out_ok=0; 
  434. X   if ((outfile=fopen(outfile_name,"r"))!=NULL)
  435. X     { out_ok=1;
  436. X       GOTOXY(7,16); ERASE;
  437. X       out_file=1;
  438. X      fflush(stdin);
  439. X      printf("File %s already exits, overwrite ? [N]", outfile_name);
  440. X      ch=getch();
  441. X      ch=getch();
  442. X        if ((ch=='y')||(ch=='Y')) out_ok=0;
  443. X        fclose(outfile);
  444. X
  445. X     }
  446. X
  447. X    if (out_ok==0)
  448. X       {
  449. X    outfile=fopen(outfile_name,"w");
  450. X       }
  451. X }
  452. X
  453. X
  454. X
  455. XNORMAL;
  456. XCLS;
  457. X
  458. Xhelp_menu();
  459. Xend_infile=read_in();
  460. X
  461. X while (1)
  462. X  {
  463. X   control(getch());
  464. X   if (exit_flag) goto quit;
  465. X  }
  466. X
  467. Xquit:
  468. XGOTOXY(25, 1);
  469. Xprintf("\n\t>>> Thank you for using INDEX MAKER >>>\n");
  470. Xprintf("\t>>> by Jingbai Wang, August 1988 >>>\n");
  471. X
  472. X
  473. X
  474. X}
  475. X
  476. Xwarning(warn_str)
  477. Xchar *warn_str;
  478. X{
  479. Xchar i;
  480. X
  481. XSAVE_CURSOR;
  482. XGOTOXY(24,5); REVERSE; BLINK;
  483. Xprintf("%s", warn_str); BELL; BELL;
  484. Xfor (i=1;i<10000;i++) ;
  485. XGOTOXY(24,1); RESTORE_CURSOR; NORMAL;
  486. X}
  487. X
  488. Xvoid  clr_show()
  489. X{
  490. Xint i;
  491. Xfor (i=13;i<17;i++)
  492. X  {NORMAL; GOTOXY(i,1);ERASE;}
  493. X}
  494. X
  495. X
  496. Xindex_now()
  497. X{ int i;
  498. Xfprintf(outfile, "%s%s%s%s",the_index,the_delimiter1,phrase_str,the_delimiter2);
  499. XSAVE_CURSOR;
  500. Xclr_show(); out_check();
  501. XGOTOXY(13,1);
  502. XBOLD;
  503. Xprintf("%s%s%s%s",the_index,the_delimiter1,out_str,the_delimiter2);
  504. XNORMAL; RESTORE_CURSOR;
  505. X}
  506. X
  507. Xindex_next_line()
  508. X{
  509. Xint i;
  510. X
  511. Xnext_flag=1;
  512. Xstrcat(next_str, the_index);
  513. Xstrcat(next_str, the_delimiter1);
  514. X    if ((strlen(next_str)+strlen(phrase_str))<510) 
  515. X        strcat(next_str, phrase_str);
  516. Xstrcat(next_str, the_delimiter2);
  517. XSAVE_CURSOR;
  518. Xclr_show(); out_check();
  519. XGOTOXY(13,1);
  520. XBOLD;
  521. Xprintf("%s%s%s%s}", the_index,the_delimiter1,out_str,the_delimiter2);
  522. XNORMAL; RESTORE_CURSOR;
  523. X
  524. X}
  525. X
  526. Xsee_also()
  527. X{
  528. XSAVE_CURSOR;BELL;
  529. XGOTOXY(24,2); BLINK; REVERSE;
  530. Xprintf("  Primary=");  NORMAL;printf("[%s]",save_str);
  531. Xget_line();
  532. Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
  533. X else strcpy(save_str, command_line);
  534. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
  535. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  536. Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
  537. XGOTOXY(24,1);ERASE;
  538. Xclr_show();  out_check();
  539. XGOTOXY(13,1);
  540. XBOLD;
  541. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
  542. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  543. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  544. XNORMAL; RESTORE_CURSOR;
  545. X
  546. X}
  547. X
  548. Xindex_entry()
  549. X{
  550. Xchar entry[20], number[30];
  551. Xstrcpy(save_str, phrase_str);
  552. X
  553. Xstrcpy(number, ",\nNumber=<");
  554. XSAVE_CURSOR;BELL;
  555. XGOTOXY(24,2); BLINK; REVERSE;
  556. Xprintf("  Entry=");  NORMAL;printf("[%s]",phrase_str);
  557. Xget_line();
  558. Xif (memcmp(command_line,"",1)==0) strcpy(entry, phrase_str);
  559. X else strcpy(entry, command_line);
  560. XGOTOXY(24,1);ERASE;
  561. XGOTOXY(24,2); BLINK; REVERSE;
  562. Xprintf("  Number=");  NORMAL;
  563. Xget_line();
  564. Xif (memcmp(command_line,"",1)==0) number[0]=0;
  565. X else  {strcat(number, command_line); strcat(number, ">");}
  566. X
  567. X
  568. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
  569. Xthe_key,the2_delimiter1,phrase_str, the2_delimiter2,the_entry,
  570. Xthe2_delimiter1,entry,the2_delimiter2,  number, the_delimiter2);
  571. XGOTOXY(24,1);ERASE;
  572. Xclr_show();  out_check();
  573. XGOTOXY(13,1);
  574. XBOLD;
  575. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
  576. Xthe_key,the2_delimiter1,out_str, the2_delimiter2,the_entry,
  577. Xthe2_delimiter1,entry,the2_delimiter2, number, the_delimiter2);
  578. XNORMAL; RESTORE_CURSOR;
  579. X
  580. X}
  581. X
  582. Xindex_secondary()
  583. X{
  584. XSAVE_CURSOR;BELL;
  585. XGOTOXY(24,2); BLINK; REVERSE;
  586. Xprintf("  Primary=");  NORMAL;printf("[%s]",save_str);
  587. Xget_line();
  588. Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
  589. X else strcpy(save_str, command_line);
  590. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
  591. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  592. Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
  593. XGOTOXY(24,1);ERASE;
  594. Xclr_show();  out_check();
  595. XGOTOXY(13,1);
  596. XBOLD;
  597. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
  598. Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
  599. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  600. XNORMAL; RESTORE_CURSOR;
  601. X
  602. X}
  603. X
  604. Xglossary()
  605. X{
  606. XSAVE_CURSOR;
  607. XGOTOXY(24,2); BLINK; REVERSE;
  608. Xprintf("  Description:");  NORMAL;
  609. Xget_line();
  610. Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
  611. Xg_primary,the2_delimiter1,phrase_str, the2_delimiter2,g_second,
  612. Xthe2_delimiter1,command_line,the2_delimiter2, the_delimiter2);
  613. XGOTOXY(24,1);ERASE;
  614. Xclr_show();  out_check();
  615. XGOTOXY(13,1);
  616. XBOLD;
  617. Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
  618. Xg_primary,the2_delimiter1,command_line, the2_delimiter2,g_second,
  619. Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
  620. XNORMAL; RESTORE_CURSOR;
  621. X
  622. X}
  623. X
  624. X
  625. Xfinish_up()
  626. X{ char ch;
  627. X  int i;
  628. X
  629. Xif(end_infile && end_outfile) {all_done(); exit();}
  630. X
  631. X
  632. Xif (marker) {mark_end(); index_now(); }
  633. X
  634. Xfor (i=cursor_last;i<buffer_length;i++)
  635. X  {
  636. X  if (buffer[i]==13)
  637. X     { 
  638. X      if (next_flag==1) {
  639. X             fprintf(outfile, "%s\n\n", next_str);
  640. X             next_str[0]=0; next_flag=0;
  641. X             }
  642. X     }
  643. X  else fprintf(outfile,"%c",buffer[i]);
  644. X  }
  645. X
  646. X
  647. X
  648. Xif (end_infile==1) {all_done(); return;}
  649. XGOTOXY(24,35); BLINK; printf("Working ... \n");
  650. X
  651. X    while (fscanf(infile,"%c",&ch)!=EOF)
  652. X      {
  653. X    if (ch==13);
  654. X    else fprintf(outfile, "%c", ch);
  655. X      }
  656. X  all_done();NORMAL;
  657. X}
  658. X
  659. X
  660. Xall_done()
  661. X{
  662. Xfclose(infile); fclose(outfile); exit_flag=1;
  663. X#if VMS
  664. Xsystem("set broadcast=all");
  665. X#endif
  666. X}
  667. X
  668. X
  669. XCLS_UP()
  670. X{ char i;
  671. X
  672. Xfor(i=1;i<12;i++)
  673. X  {GOTOXY(i,1); ERASE;}
  674. X
  675. X}
  676. X
  677. Xhelp_menu()
  678. X{
  679. XGOTOXY(12, 1);
  680. XREVERSE; printf("                                ");
  681. Xprintf(" Inserting                                 ");
  682. X
  683. XGOTOXY(17,1);
  684. Xprintf(" ===== ^H delete ======================== ^F Search string ===============");
  685. XNORMAL;
  686. XGOTOXY(18,3); BOLD; printf("SPACE BAR"); NORMAL; printf(" -- next page");
  687. XGOTOXY(19,3); BOLD; printf("<RETURN> 1"); NORMAL; printf(" -- set mark");
  688. XGOTOXY(20,3); BOLD; printf("<RETURN> 2"); NORMAL; printf(" -- end mark & index");
  689. XGOTOXY(21,3); BOLD; printf("<TAB>"); NORMAL; printf(" -- forward a word");
  690. XGOTOXY(22,40); BOLD; printf("G"); NORMAL; printf(" -- end mark & glossary");
  691. XGOTOXY(22,3); BOLD; printf("W"); NORMAL; printf(" -- mark word");
  692. XGOTOXY(21,40); BOLD; printf("B"); NORMAL; printf(" -- backward a word");
  693. XGOTOXY(20,40); BOLD; printf("N"); NORMAL; printf(" -- end mark & index in next line");
  694. XGOTOXY(19,40); BOLD; printf("P"); NORMAL; printf(" -- abandon the marked/skip a word ");
  695. XGOTOXY(18,40); BOLD; printf("F"); NORMAL; printf(" -- finish     \
  696. X        ^F--string search");
  697. XGOTOXY(23,40); BOLD; printf("S"); NORMAL; printf(" -- IndexSecondary");
  698. XGOTOXY(23,17); BOLD; printf("I"); NORMAL; printf(" -- IndexEntry");
  699. XGOTOXY(23,3); BOLD; printf("A"); NORMAL; printf(" -- SeeAlso");
  700. XGOTOXY(23,65); BOLD; printf("@"); NORMAL; printf(" -- set up");
  701. X}
  702. X
  703. X
  704. Xset_up()
  705. X{
  706. Xint the_row, i;
  707. Xint ch_count;
  708. Xchar ch, string[81];
  709. X
  710. Xch_count=0;
  711. XSAVE_CURSOR;
  712. XNORMAL; REVERSE;
  713. XGOTOXY(12,1);
  714. Xprintf("                            Set-up Menu                  <TAB> to quit      ");
  715. XNORMAL;
  716. Xfor (i=13;i<24;i++)
  717. X  {GOTOXY(i,1);ERASE;}
  718. X
  719. XGOTOXY(13,3);printf("[%s]:",the_index);
  720. XGOTOXY(14,3);printf("[%s]:",the_indexentry);
  721. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);
  722. XGOTOXY(16,3);printf("[%s]:",the_seealso);
  723. XGOTOXY(17,3);printf("[%s]:",the_primary);
  724. XGOTOXY(18,3);printf("[%s]:",the_second);
  725. XGOTOXY(19,3);printf("[%s]:",the_gloss);
  726. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);
  727. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second);
  728. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);
  729. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);
  730. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1);
  731. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);
  732. X
  733. Xthe_row=13;
  734. Xset_up_in(the_row);
  735. X
  736. X     while(1)
  737. X      { ch=getch();
  738. X     switch(ch)
  739. X     {
  740. X      case EXT:
  741. X#if unix | VMS
  742. X
  743. X         /* VAX */
  744. X         ch=getch(); if (ch!=EXT1) {BELL;break;}
  745. X         ch=getch();
  746. X#else
  747. X               /* DOS                 */
  748. X          ch=getch(); 
  749. X#endif        
  750. X         switch(ch)
  751. X         {
  752. X          case L_ARROW:
  753. X          case U_ARROW:
  754. X               set_up_out(the_row); ch_count=0;string[0]=0;
  755. X               --the_row; if (the_row<13) the_row=25;
  756. X               set_up_in(the_row); break;
  757. X          case R_ARROW:
  758. X          case D_ARROW:
  759. X  down:                        set_up_out(the_row);ch_count=0;string[0]=0;
  760. X               ++the_row; if (the_row>25) the_row=13;
  761. X               set_up_in(the_row); break;
  762. X         default: BELL;
  763. X         } break;
  764. X       case  3 : all_done(); break;
  765. X#if unix
  766. X       case  4 : all_done(); break;
  767. X#endif
  768. X      case 1:
  769. X      case 2:
  770. X      case 5:
  771. X      case 6:
  772. X      case 7:
  773. X      case 10:
  774. X      case 11:
  775. X      case 12:
  776. X      case 14:
  777. X      case 15:
  778. X      case 16:
  779. X      case 19:
  780. X      case 20:
  781. X      case 21:
  782. X      case 22:
  783. X      case 23:
  784. X      case 24:
  785. X      case 25:
  786. X      case 26:BELL;break;
  787. X          case 8:
  788. X          case 127:
  789. X              if (ch_count>0){
  790. X                  CURSOR_LEFT; ERASE;
  791. X                  string[--ch_count]=0;
  792. X                  }  break;
  793. X
  794. X      case 13: if (ch_count>0)
  795. X          { string[ch_count]=0;
  796. X           set_up_save(the_row, string);
  797. X           } goto down;break;
  798. X      case 9: NORMAL;for (i=12;i<24;i++)
  799. X           {GOTOXY(i,1);ERASE;}
  800. X           help_menu();RESTORE_CURSOR;
  801. X           return;
  802. X      default: printf("%c",ch);string[ch_count++]=ch;
  803. X
  804. X     }
  805. X
  806. X      }
  807. X
  808. X
  809. X}
  810. X
  811. X
  812. X
  813. X
  814. X
  815. Xset_up_in( the_row)
  816. Xint the_row;
  817. X{ REVERSE;
  818. X      switch(the_row)
  819. X    {
  820. X     case 13:
  821. XGOTOXY(13,3);printf("[%s]:",the_index);break;
  822. Xcase 14:
  823. XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
  824. Xcase 15:
  825. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
  826. Xcase 16:
  827. XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
  828. Xcase 17:
  829. XGOTOXY(17,3);printf("[%s]:",the_primary); break;
  830. Xcase 18:
  831. XGOTOXY(18,3);printf("[%s]:",the_second);  break;
  832. Xcase 19:
  833. XGOTOXY(19,3);printf("[%s]:",the_gloss);  break;
  834. Xcase 20:
  835. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
  836. Xcase 21:
  837. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
  838. Xcase 22:
  839. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
  840. Xcase 23:
  841. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
  842. Xcase 24:
  843. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
  844. Xcase 25:
  845. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
  846. X
  847. X    }
  848. X
  849. X}
  850. X
  851. X
  852. Xset_up_save(the_row, string)
  853. Xint the_row;
  854. Xchar *string;
  855. X{
  856. X      switch(the_row)
  857. X    {
  858. X     case 13:strcpy(the_index,string);break;
  859. X     case 14:strcpy(the_indexentry,string);break;
  860. X     case 15:strcpy(the_indexsecond,string);break;
  861. X     case 16:strcpy(the_seealso,string);break;
  862. X     case 17:strcpy(the_primary,string);break;
  863. X     case 18:strcpy(the_second,string);break;
  864. X     case 19:strcpy(the_gloss,string);break;
  865. X     case 20:strcpy(g_primary,string);break;
  866. X     case 21:strcpy(g_second,string);break;
  867. X     case 22:strcpy(the_delimiter1,string);break;
  868. X     case 23:strcpy(the_delimiter2,string);break;
  869. X     case 24:strcpy(the2_delimiter1,string);break;
  870. X     case 25:strcpy(the2_delimiter2,string);break;
  871. X
  872. X    }
  873. X
  874. X}
  875. X
  876. X
  877. X
  878. Xset_up_out(the_row)
  879. Xint the_row;
  880. X{  NORMAL;
  881. X      switch(the_row)
  882. X    {
  883. X     case 13:GOTOXY(13,1);ERASE;
  884. XGOTOXY(13,3); printf("[%s]:",the_index);break;
  885. Xcase 14:GOTOXY(14,1);ERASE;
  886. XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
  887. Xcase 15:GOTOXY(15,1);ERASE;
  888. XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
  889. Xcase 16:GOTOXY(16,1);ERASE;
  890. XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
  891. Xcase 17:GOTOXY(17,1);ERASE;
  892. XGOTOXY(17,3);printf("[%s]:",the_primary); break;
  893. Xcase 18:GOTOXY(18,1);ERASE;
  894. XGOTOXY(18,3);printf("[%s]:",the_second);  break;
  895. Xcase 19:GOTOXY(19,1);ERASE;
  896. XGOTOXY(19,3);printf("[%s]:",the_gloss);  break;
  897. Xcase 20:GOTOXY(20,1);ERASE;
  898. XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
  899. Xcase 21:GOTOXY(21,1);ERASE;
  900. XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
  901. Xcase 22:GOTOXY(22,3);printf("                                 ");
  902. XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
  903. Xcase 23:GOTOXY(22,40);ERASE;
  904. XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
  905. Xcase 24:GOTOXY(23,3);printf("                               ");
  906. XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
  907. Xcase 25:GOTOXY(23,40);ERASE;
  908. XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
  909. X
  910. X    }
  911. X
  912. X}
  913. X
  914. Xout_check()
  915. X{int i, rows, length, trunc;
  916. Xrows=1;  trunc=256;
  917. X
  918. Xstrcpy(out_str,phrase_str);
  919. Xlength=strlen(out_str);
  920. X
  921. Xfor (i=0;i<length; i++)
  922. X {
  923. X  if (out_str[i]==10) ++rows;
  924. X  if (rows==2) {trunc=i-4;break;}
  925. X }
  926. X
  927. X
  928. Xif (length>trunc) {out_str[trunc]='.';out_str[trunc+1]='.';out_str[trunc+2]='.';
  929. Xout_str[trunc+3]=0;}
  930. X}
  931. X
  932. X
  933. X
  934. Xget_line()
  935. X{
  936. Xchar ch;
  937. Xint ch_count;
  938. X
  939. Xch_count=0;
  940. X
  941. Xcommand_line[0]=0;
  942. X
  943. X     while(1)
  944. X      { ch=getch();
  945. X         switch(ch)
  946. X          {
  947. X          case 3: all_done(); break;
  948. X#if unix
  949. X          case 4: all_done(); break;
  950. X#endif       
  951. X          case 0:
  952. X      case 1:
  953. X      case 2:
  954. X
  955. X      case 5:
  956. X      case 6: 
  957. X      case 7:
  958. X      case 10:
  959. X      case 11:
  960. X      case 12:
  961. X      case 14:
  962. X      case 15:
  963. X      case 16:
  964. X      case 19:
  965. X      case 20:
  966. X      case 21:
  967. X      case 22:
  968. X      case 23:
  969. X      case 24:
  970. X      case 25:
  971. X      case 26: BELL;break;
  972. X          case 8:
  973. X          case 127:
  974. X              if (ch_count>0){
  975. X                  CURSOR_LEFT; ERASE;
  976. X                  command_line[--ch_count]=0;
  977. X                  }  break;
  978. X      case 13: if (ch_count>0)
  979. X             command_line[ch_count]=0;
  980. X             return;
  981. X      default: printf("%c",ch);command_line[ch_count++]=ch;
  982. X
  983. X     }
  984. X    }
  985. X
  986. X}
  987. X
  988. X
  989. Xstr_search()
  990. X{
  991. Xchar *ptr;
  992. X#if unix
  993. Xchar *memchr();
  994. X#endif
  995. Xint same_page= -1;
  996. Xvoid  this_page();
  997. Xint cursor_here=0,i;
  998. Xcommand_line[0]=0;
  999. XSAVE_CURSOR;
  1000. X
  1001. XGOTOXY(24,2); REVERSE;
  1002. Xprintf("String:"); NORMAL; printf(" ");
  1003. Xif (the_phrase[0]>0) printf("[%s]", the_phrase);
  1004. Xget_line();
  1005. X
  1006. Xif (command_line[0]>0) strcpy(the_phrase, command_line);
  1007. X  else if (the_phrase[0]==0)  {GOTOXY(24,2); ERASE; RESTORE_CURSOR; 
  1008. X        return;}
  1009. X
  1010. Xptr=buffer;
  1011. Xif (same_page<0)
  1012. X  while ( cursor_here<cursor_mark) {cursor_here++; ptr++;}  
  1013. X
  1014. Xwhile (1){
  1015. X
  1016. Xwhile ((ptr=memchr(ptr, the_phrase[0], buffer_length))!=NULL)
  1017. X    {
  1018. X    if( memcmp(ptr, the_phrase, strlen(the_phrase))==0)
  1019. X      { GOTOXY(24,2); ERASE;
  1020. X       this_page(same_page*cursor_here); return;}
  1021. X    else {ptr++;}       
  1022. X    }
  1023. X
  1024. X   /* Writing the buffer into the output file */
  1025. X
  1026. Xfor (i=cursor_last;i<buffer_length;i++)
  1027. X  {   fprintf(outfile,"%c",buffer[i]);
  1028. X  if ((same_page<0) && (buffer[i]==10))
  1029. X     {
  1030. X      if (next_flag) {
  1031. X             fprintf(outfile, "%s\n", next_str);
  1032. X             next_str[0]=0; next_flag=0;
  1033. X             }
  1034. X     }
  1035. X
  1036. X  }
  1037. X
  1038. X
  1039. Xif (same_page<0)
  1040. X{
  1041. X marker=0;
  1042. Xcursor_last=0;
  1043. Xphrase_on=0;
  1044. Xcursor_mark=0;
  1045. Xbuffer_length=0;
  1046. Xnext_flag=0;
  1047. Xsame_page=1;
  1048. X}
  1049. X
  1050. X
  1051. Xif (end_infile) { end_outfile=1;
  1052. X         GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL;
  1053. XGOTOXY(24, 2); printf("String not found"); 
  1054. Xall_done();
  1055. X exit();}
  1056. X
  1057. Xend_infile=read_in_only(); cursor_here=0; ptr=buffer;
  1058. X }
  1059. X
  1060. X}
  1061. X
  1062. X
  1063. Xint read_in_only()
  1064. X{
  1065. Xint i, quit_s;
  1066. Xchar quit;
  1067. Xchar string[81];
  1068. X
  1069. X
  1070. Xbuffer_length=0;
  1071. Xbuffer[0]=0;
  1072. Xstring[0]=0;
  1073. X           quit_s=0;
  1074. X
  1075. Xfor (i=1;i<=8;i++)
  1076. X  { if( fgets(string,80,infile)==NULL)
  1077. X        {fclose(infile); quit_s=1; goto quit;}
  1078. X           strcat(buffer,string);
  1079. X  }
  1080. X
  1081. Xquit:
  1082. Xbuffer_length=strlen(buffer);
  1083. X
  1084. Xreturn(quit_s);
  1085. X}
  1086. X
  1087. X
  1088. Xvoid this_page(cursor_here)
  1089. Xint cursor_here;
  1090. X{
  1091. Xint i, cursor_there, the_cursor;
  1092. X
  1093. Xif (cursor_here<0) cursor_there= (-1)*cursor_here;
  1094. X   else cursor_there=0;
  1095. X
  1096. Xfor (i=cursor_there;i<buffer_length;i++)
  1097. X if(memcmp(&buffer[i], the_phrase, strlen(the_phrase))==0) 
  1098. X  {the_cursor=i; break;}
  1099. X
  1100. Xif (cursor_here<0) {
  1101. X     if (marker) 
  1102. X      {REVERSE; cursor_mark=cursor_last; cursor_position(); marker=0;
  1103. X       for (i=cursor_last; i<=the_cursor; i++)
  1104. X        {
  1105. X        printf("%c", buffer[i]);
  1106. X        }
  1107. X       NORMAL;
  1108. X      }
  1109. X     cursor_mark= the_cursor;
  1110. X     cursor_position();
  1111. X      }
  1112. X    else 
  1113. X   {
  1114. X   position();
  1115. X   NORMAL; CLS_UP(); NORMAL; 
  1116. X   GOTOXY(3,1);
  1117. X   for (i=0;i<buffer_length;i++)
  1118. X     printf("%c", buffer[i]);
  1119. X   cursor_mark=the_cursor;
  1120. X   cursor_position();
  1121. X   }
  1122. X
  1123. Xreturn;
  1124. X}
  1125. X
  1126. X
  1127. X
  1128. X/* for ultrix define V7 = 1 */
  1129. X
  1130. X/*
  1131. X * The functions in this file negotiate with the operating system for
  1132. X * characters, and write characters in a barely buffered fashion on the display.
  1133. X * All operating systems.
  1134. X */
  1135. X
  1136. X
  1137. X#if   MSDOS & TURBO
  1138. X#include <conio.h>
  1139. X#endif
  1140. X
  1141. X#if     AMIGA
  1142. X#define NEW 1006L
  1143. X#define AMG_MAXBUF      1024L
  1144. Xstatic long terminal;
  1145. Xstatic char     scrn_tmp[AMG_MAXBUF+1];
  1146. Xstatic long     scrn_tmp_p = 0;
  1147. X#endif
  1148. X
  1149. X#if     CPM
  1150. X#include        <bdos.h>
  1151. X#endif
  1152. X
  1153. X#if     MSDOS & (LATTICE | MSC | TURBO | AZTEC | MWC86)
  1154. Xunion REGS rg;          /* cpu register for use of DOS calls */
  1155. Xint nxtchar = -1;       /* character held from type ahead    */
  1156. X#endif
  1157. X
  1158. X#if RAINBOW
  1159. X#include "rainbow.h"
  1160. X#endif
  1161. X
  1162. X#if     USG                     /* System V */
  1163. X#include        <signal.h>
  1164. X#include        <termio.h>
  1165. X#include        <fcntl.h>
  1166. Xint kbdflgs;                    /* saved keyboard fd flags      */
  1167. Xint kbdpoll;                    /* in O_NDELAY mode                     */
  1168. Xint kbdqp;                      /* there is a char in kbdq      */
  1169. Xchar kbdq;                      /* char we've already read      */
  1170. Xstruct  termio  otermio;        /* original terminal characteristics */
  1171. Xstruct  termio  ntermio;        /* charactoristics to use inside */
  1172. X#endif
  1173. X
  1174. X#if V7 | BSD
  1175. X/*
  1176. X#undef  CTRL
  1177. X*/
  1178. X#include        <sgtty.h>        /* for stty/gtty functions */
  1179. X#include        <signal.h>
  1180. Xstruct  sgttyb  ostate;          /* saved tty state */
  1181. Xstruct  sgttyb  nstate;          /* values for editor mode */
  1182. Xstruct tchars   otchars;        /* Saved terminal special character set */
  1183. Xstruct tchars   ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  1184. X                                /* A lot of nothing */
  1185. X#if BSD
  1186. X#include <sys/ioctl.h>          /* to get at the typeahead */
  1187. Xextern  int rtfrmshell();       /* return from suspended shell */
  1188. X#define         TBUFSIZ         128
  1189. Xchar tobuf[TBUFSIZ];            /* terminal output buffer */
  1190. X#endif
  1191. X#endif
  1192. X
  1193. X/*
  1194. X * This function is called once to set up the terminal device streams.
  1195. X */
  1196. Xttopen()
  1197. X{
  1198. X
  1199. X#if     AMIGA
  1200. X        char oline[NSTRING];
  1201. X#if     AZTEC
  1202. X        extern  Enable_Abort;   /* Turn off ctrl-C interrupt */
  1203. X
  1204. X        Enable_Abort = 0;       /* for the Manx compiler */
  1205. X#endif
  1206. X        strcpy(oline, "RAW:0/0/640/200/");
  1207. X        strcat(oline, PROGNAME);
  1208. X        strcat(oline, " ");
  1209. X        strcat(oline, VERSION);
  1210. X        strcat(oline, "/Amiga");
  1211. X        terminal = Open(oline, NEW);
  1212. X#endif
  1213. X#if     CPM
  1214. X#endif
  1215. X
  1216. X#if     MSDOS & (HP150 == 0) & LATTICE
  1217. X        /* kill the ctrl-break interupt */
  1218. X        rg.h.ah = 0x33;                 /* control-break check dos call */
  1219. X        rg.h.al = 1;            /* set the current state */
  1220. X        rg.h.dl = 0;            /* set it OFF */
  1221. X        intdos(&rg, &rg);       /* go for it! */
  1222. X#endif
  1223. X
  1224. X#if     USG
  1225. X        ioctl(0, TCGETA, &otermio);     /* save old settings */
  1226. X        ntermio.c_iflag = 0;            /* setup new settings */
  1227. X        ntermio.c_oflag = 0;
  1228. X        ntermio.c_cflag = otermio.c_cflag;
  1229. X        ntermio.c_lflag = 0;
  1230. X        ntermio.c_line = otermio.c_line;
  1231. X        ntermio.c_cc[VMIN] = 1;
  1232. X        ntermio.c_cc[VTIME] = 0;
  1233. X        ioctl(0, TCSETA, &ntermio);     /* and activate them */
  1234. X        kbdflgs = fcntl( 0, F_GETFL, 0 );
  1235. X        kbdpoll = FALSE;
  1236. X#endif
  1237. X
  1238. X#if     V7 | BSD
  1239. Xif (tt_status==tt_open) return;
  1240. X        gtty(0, &ostate);                       /* save old state */
  1241. X        gtty(0, &nstate);                       /* get base of new state */
  1242. X        nstate.sg_flags |= RAW;
  1243. X        nstate.sg_flags &= ~(ECHO|CRMOD);       /* no echo for now... */
  1244. X        stty(0, &nstate);                       /* set mode */
  1245. X        ioctl(0, TIOCGETC, &otchars);           /* Save old characters */
  1246. X        ioctl(0, TIOCSETC, &ntchars);           /* Place new character into K */
  1247. Xtt_status=tt_open;
  1248. X#if     BSD
  1249. X        /* provide a smaller terminal output buffer so that
  1250. X           the type ahead detection works better (more often) */
  1251. X        setbuffer(stdout, &tobuf[0], TBUFSIZ);
  1252. X/*---        signal(SIGTSTP,SIG_DFL);         set signals so that we can
  1253. X        signal(SIGCONT,rtfrmshell);      suspend & restart emacs */
  1254. X#endif
  1255. X#endif
  1256. X        /* on all screens we are not sure of the initial position
  1257. X           of the cursor                                        */
  1258. X/*---   ttrow = 999;
  1259. X        ttcol = 999; */
  1260. X
  1261. X}
  1262. X
  1263. X/*
  1264. X * This function gets called just before we go back home to the command
  1265. X * interpreter. 
  1266. X * Another no-operation on CPM.
  1267. X */
  1268. Xttclose()
  1269. X{
  1270. X
  1271. X#if     AMIGA
  1272. X#if     LATTICE
  1273. X        amg_flush();
  1274. X        Close(terminal);
  1275. X#endif
  1276. X#if     AZTEC
  1277. X        amg_flush();
  1278. X        Enable_Abort = 1;       /* Fix for Manx */
  1279. X        Close(terminal);
  1280. X#endif
  1281. X#endif
  1282. X#if     CPM
  1283. X#endif
  1284. X#if     MSDOS & (HP150 == 0) & LATTICE
  1285. X        /* restore the ctrl-break interupt */
  1286. X        rg.h.ah = 0x33;                 /* control-break check dos call */
  1287. X        rg.h.al = 1;            /* set the current state */
  1288. X        rg.h.dl = 1;            /* set it ON */
  1289. X        intdos(&rg, &rg);       /* go for it! */
  1290. X#endif
  1291. X
  1292. X#if     USG
  1293. X        ioctl(0, TCSETA, &otermio);     /* restore terminal settings */
  1294. X        fcntl(0, F_SETFL, kbdflgs);
  1295. X#endif
  1296. X
  1297. X#if     V7 | BSD
  1298. Xif (tt_status==tt_close) return;
  1299. X        stty(0, &ostate);
  1300. X        ioctl(0, TIOCSETC, &otchars);   /* Place old character into K */
  1301. Xtt_status=tt_close;
  1302. X#endif
  1303. X
  1304. X
  1305. X}
  1306. X
  1307. X#if     AMIGA
  1308. Xamg_flush()
  1309. X{
  1310. X        if(scrn_tmp_p)
  1311. X                Write(terminal,scrn_tmp,scrn_tmp_p);
  1312. X        scrn_tmp_p = 0;
  1313. X}
  1314. X#endif
  1315. X
  1316. X/*
  1317. X * Flush terminal buffer. Does real work where the terminal output is buffered
  1318. X * up. A no-operation on systems where byte at a time terminal I/O is done.
  1319. X */
  1320. Xttflush()
  1321. X{
  1322. X#if     AMIGA
  1323. X        amg_flush();
  1324. X#endif
  1325. X
  1326. X#if     CPM
  1327. X#endif
  1328. X
  1329. X#if     MSDOS
  1330. X#endif
  1331. X
  1332. X#if     V7 | USG | BSD
  1333. X        fflush(stdout);
  1334. X#endif
  1335. X}
  1336. X
  1337. X/*
  1338. X * Read a character from the terminal, performing no editing and doing no echo
  1339. X * at all.
  1340. X */
  1341. Xttgetc()
  1342. X{
  1343. X#if     AMIGA
  1344. X        char ch;
  1345. X        amg_flush();
  1346. X        Read(terminal, &ch, 1L);
  1347. X        return(255 & (int)ch);
  1348. X#endif
  1349. X#if     CPM
  1350. X        return (biosb(BCONIN, 0, 0));
  1351. X#endif
  1352. X
  1353. X#if RAINBOW
  1354. X        int Ch;
  1355. X
  1356. X        while ((Ch = Read_Keyboard()) < 0);
  1357. X
  1358. X        if ((Ch & Function_Key) == 0)
  1359. X                if (!((Ch & 0xFF) == 015 || (Ch & 0xFF) == 0177))
  1360. X                        Ch &= 0xFF;
  1361. X
  1362. X        return Ch;
  1363. X#endif
  1364. X
  1365. X#if     MSDOS & MWC86
  1366. X        return (getcnb());
  1367. X#endif
  1368. X
  1369. X#if     MSDOS & (LATTICE | MSC | TURBO | AZTEC)
  1370. X        int c;          /* character read */
  1371. X
  1372. X        /* if a char already is ready, return it */
  1373. X        if (nxtchar >= 0) {
  1374. X                c = nxtchar;
  1375. X                nxtchar = -1;
  1376. X                return(c);
  1377. X        }
  1378. X
  1379. X        /* call the dos to get a char */
  1380. X        rg.h.ah = 7;            /* dos Direct Console Input call */
  1381. X        intdos(&rg, &rg);
  1382. X        c = rg.h.al;            /* grab the char */
  1383. X        return(c & 255);
  1384. X#endif
  1385. X
  1386. X#if     V7 | BSD
  1387. X        return(127 & fgetc(stdin));
  1388. X#endif
  1389. X
  1390. X#if     USG
  1391. X        if( kbdqp )
  1392. X                kbdqp = FALSE;
  1393. X        else
  1394. X        {
  1395. X                if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
  1396. X                        return FALSE;
  1397. X                kbdpoll = FALSE;
  1398. X                while (read(0, &kbdq, 1) != 1)
  1399. X                        ;
  1400. X        }
  1401. X        return ( kbdq & 127 );
  1402. X#endif
  1403. X}
  1404. EOF
  1405. chars=`wc -c < 'indexor.c-2'`
  1406. if test $chars !=    30576; then echo 'indexor.c-2' is $chars characters, should be    30576 characters!; fi
  1407. fi
  1408. exit 0
  1409.