v07i100: Index insertor for Scribe, TeX/LaTeX, *roff, etc. part 01/02
Brandon S. Allbery - comp.sources.misc
allbery at uunet.UU.NET
Mon Jul 24 06:15:39 AEST 1989
Posting-number: Volume 7, Issue 100
Submitted-by: jbw at unix.cis.pittsburgh.edu (Jingbai Wang)
Archive-name: indexor/part01
[[This arrived as a 75K single-part submission, a single file with no
shar'ing. Rather risky, if you ask me... I have split it into two
parts. After unpacking, "cat" indexor.c-1 and indexor.c-2 together
to make indexor.c. ++bsa]]
If you are a technical writer or book writer, you would have found that
the most tedious job is to add an index to a book you have written. I am
a heavy writer, and I use Scribe (with my own TEC.mak data base) and
TeX/LaTeX to format books.
To overcome the tediousness and boresomeness of index making, I developed
a program in C named 'indexor' that I revealed in a previous message in
comp.text. Here I am introducing the source code into comp.text and
comp.source.unix.
This program named `indexor.c' can be compiled on VMS, UNIX or DOS, and have
helped me with two lengthy books already. You can called it a semi-automatic
index insertor. You need an ANSI terminal (like vt100, vt102) to make
it work properly.
#! /bin/sh
# This file was wrapped with "dummyshar". "sh" this file to extract.
# Contents: indexor.c-1
echo extracting 'indexor.c-1'
if test -f 'indexor.c-1' -a -z "$1"; then echo Not overwriting 'indexor.c-1'; else
sed 's/^X//' << \EOF > 'indexor.c-1'
X/* Copyright (C) 1988 by Jingbai Wang */
X
X
X/* **********************************************************************
X * This program is an auxiliary program for Scribe and TeX *
X * It inserts index and glossary into Scribe/LaTeX file *
X * It is an important program for book editing *
X * The user can set up the programs for other formattors like troff *
X * *
X * Copyright by Jingbai Wang August 1988 *
X * *
X * jbw at pittvms.bitnet *
X * jbw at cisunx.UUCP *
X ************************************************************************/
X/*
X This program was created in 1988 by myself in order to include an
X index in the Scribe and TeX/LaTeX manuals I was writing. It is part
X of the Scribe TEC.mak package I developed, and can be re-distributed
X freely for non-profit purposes.
X
X It is like a special editor to introduce index entries into a Scribe,
X LaTeX, TeX or *troff file. It indeed makes a tedious and boresome job
X enjoyable.
X The primary attempt is to make this program portable among
X VAX/VMS, UNIX (BSD and Ultrix), and DOS (MSC and MS Quick C).
X
X To compile on our VMS,
X $ex indexor
X
X and on UNIX,
X %cc -o indexor indexor.c
X
X It takes two on-line arguments, i.e., the input and output file names,
X but you can also provide these piece of information when running it.
X The program is self-instructive, no documentation is necessary.
X*/
X
X#include <string.h>
X#include <stdio.h>
X#define CLS printf("\033[2J")
X#define GOTOXY(x,y) printf("\033[%d;%df",x,y)
X#define REVERSE printf("\033[7m")
X#define NORMAL printf("\033[0m")
X#define SAVE_CURSOR printf("\033[s")
X#define BLINK printf("\033[5m")
X#define BOLD printf("\033[1m")
X#define UNDER printf("\033[4m")
X#define ERASE printf("\033[K")
X#define CURSOR_REPORT(x, y) scanf("\033[%d;%dR",x,y)
X#define BELL printf("%c", 7)
X#define CURSOR_RIGHT printf("\033[1C")
X#define CURSOR_LEFT printf("\033[1D")
X
X#define tt_open 1
X#define tt_close 0
Xint tt_status=0;
X
X#if VMS|unix
X#define RESTORE_CURSOR cursor_position()
X#else
X#define RESTORE_CURSOR printf("\033[u")
X#endif
X
X#if ultrix
X#define V7 1
X#endif
X
X#if unix|VMS
X/* ANSI escape, good for mainframe systems vt100 terminals, e.g., VAX*/
X#define DEL 127
X#define EXT 27
X#define EXT1 '['
X#define R_ARROW 'C'
X#define L_ARROW 'D'
X#define D_ARROW 'B'
X#define U_ARROW 'A'
X
X#if VMS
X#include <descrip.h>
X#include <iodef.h>
X#include <ssdef.h>
Xshort iochan; /* TTY I/O channel */
X#endif
X
X
X#else
X /* MSDOS extended code escape */
X#define DEL 8
X#define EXT 0
X#define R_ARROW 77
X#define L_ARROW 75
X#define D_ARROW 80
X#define U_ARROW 72
X#endif
X
XFILE *infile;
XFILE *outfile;
Xchar buffer[720];
Xint buffer_length;
Xint buffer_line[11];
Xint lines=1;
Xint cursor_mark=0;
Xint cursor_last=0;
X
Xchar marker=0;
Xchar phrase_str[512]="";
Xchar the_phrase[512];
Xchar save_str[128]="";
Xchar out_str[512]="";
Xint phrase_on, phrase_off, phrase_len;
Xchar end_infile=0;
Xchar end_outfile=0;
Xchar exit_flag=0;
Xchar word_mark=0;
Xchar the_index[20]="@Index";
Xchar the_delimiter1[3]="{";
Xchar the_delimiter2[3]="}";
Xchar the2_delimiter1[3]="<";
Xchar the2_delimiter2[3]=">";
Xchar the_primary[20]="Primary=";
Xchar the_second[20]="Secondary=";
Xchar the_gloss[20]="@glossary";
Xchar g_primary[20]="symbol=";
Xchar g_second[20]="expln=";
Xchar the_indexsecond[20]="@IndexSecondary";
Xchar the_seealso[20]="@SeeAlso";
Xchar the_indexentry[20]="@IndexEntry";
Xchar the_entry[20]="Entry=";
Xchar the_key[20]="Key=";
Xchar the_number[20]="Number=";
X
Xstruct CUR
X{
Xshort int x;
Xshort int y;
X} chr[720];
X
Xchar next_str[512];
Xchar next_flag=0;
Xchar command_line[160];
X
X
X
X/* The getch() and getche() */
X
X#if VMS
Xchar getch()
X{
Xint ibuf,status;
Xint iosb[2];
X status = SYS$QIOW(0, iochan, IO$_READLBLK|IO$M_NOECHO,
X iosb, 0, 0, &ibuf, 1, 0, 0, 0, 0);
X
X return (ibuf & 0xFF); /* Allow multinational */
X
X}
X
X#endif
X
X
X#if unix | ultrix | BSD
X
Xchar getch()
X{
Xint tmpch;
Xttopen();
Xtmpch=ttgetc();
Xttclose();
Xreturn(tmpch);
X}
X#endif
X
X
X#if unix | VMS
Xchar getche()
X{
Xchar inchar;
Xfputc(getch(), stdout);
Xreturn((int)inchar);
X}
X
X#endif
X
Xread_in()
X{
Xint i, quit_s;
Xchar string[81],quit;
XGOTOXY(3,1);
Xbuffer_length=0;
Xbuffer[0]=0;
Xstring[0]=0;
X quit_s=0;
X
X
Xfor (i=1;i<=8;i++)
X { if( fgets(string,80,infile)==NULL) { end_infile=1;
X quit_s=1; goto quit;}
X else { printf("%s",string);
X strcat(buffer,string);
X }
X }
X
Xquit:
Xbuffer_length=strlen(buffer);
X
Xposition();
XGOTOXY(3,1);
Xreturn(quit_s);
X }
X
Xposition()
X{
Xint i,j;
Xint row,col;
Xchar ch;
Xrow=3; col=1;
Xbuffer_line[1]=0;
Xlines=1;
X
Xfor(i=0;i<buffer_length;i++)
X { ch=buffer[i];
X chr[i].x=row; chr[i].y=col++;
X
X if(ch==10) {row++;col=1;lines++;buffer_line[lines]=i+1;}
X
X if (col==81) {row++;col=1;lines++; buffer_line[lines]=i+1;}
X }
X
X}
X
X
Xmark_begin()
X{
Xint i;
X
X for (i=cursor_last;i<cursor_mark;i++)
X {fprintf(outfile, "%c", buffer[i]);
X if (buffer[i]==10)
X {if (next_flag==1) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X }
Xmarker=1;
Xcursor_last=cursor_mark;
Xphrase_len=0;
Xphrase_on=cursor_mark;
Xphrase_str[0]=0;
XREVERSE;
Xprintf("%c",buffer[cursor_mark]);
Xcursor_position();
X}
X
Xmark_end()
X{
Xint i, length;
Xchar ch;
Xmarker=0;
X
X for (i=cursor_last;i<=cursor_mark;i++)
X { fprintf(outfile, "%c", buffer[i]);
X if (buffer[i]==10)
X {
X if (next_flag==1) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X
X }
X
Xlength=strlen(phrase_str);
Xphrase_off=cursor_mark;
Xcursor_last=cursor_mark+1;
Xcursor_mark=cursor_last; cursor_position();
Xfor (i=phrase_on; i<=phrase_off;i++)
X { ch=buffer[i];
X if ((ch==13)||(ch==10)) ch=32;
X phrase_str[length+i-phrase_on]=ch;
X }
Xphrase_str[length+1+phrase_off-phrase_on]=0;
Xphrase_on=0; phrase_off=0;
XNORMAL;
X}
X
Xcursor_position()
X{
XGOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
X}
X
Xcursor_right()
X{
X
Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
X ++cursor_mark; cursor_position();
X if (marker==1) printf("%c",buffer[cursor_mark]);
X GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
X
X}
X
Xcursor_left()
X{
X if (cursor_mark<=cursor_last) {cursor_mark=cursor_last; cursor_position();BELL; return;}
X NORMAL; cursor_position();printf("%c",buffer[cursor_mark]);
X --cursor_mark;
X if (marker==1) REVERSE;
X GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
X
X
X}
X
Xcursor_down()
X{
Xint i,the_stop;
Xchar check;
Xthe_stop=cursor_mark;
X
Xcursor_position();
Xfor (i=cursor_mark;i<buffer_length;i++)
X {if (i>=buffer_length-2) {next_page();return;}
X if (buffer[i]==10) {cursor_mark=i+1;
X cursor_position();goto check;}
X }
X
Xcheck:
X if (marker)
X { GOTOXY(chr[the_stop].x,chr[the_stop].y);
X for (i=the_stop;i<=cursor_mark;i++)
X printf("%c",buffer[i]);
X cursor_position();
X }
X}
X
Xcursor_up()
X{
Xchar check;
Xint i,the_stop;
Xif (cursor_mark<=cursor_last) {cursor_mark=cursor_last;cursor_position(); BELL; return;}
X
Xcursor_position();the_stop=cursor_mark;
Xfor (i=cursor_mark;i>=cursor_last;i--)
X {
X if (buffer[i]==10) {cursor_mark=i-1;
X GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
X goto check;}
X }
X cursor_mark=cursor_last; cursor_position(); BELL;
X
Xcheck:
X if (marker)
X {
X NORMAL; GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
X for (i=cursor_mark+1;i<=the_stop;i++)
X printf("%c",buffer[i]);
X REVERSE;
X GOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
X }
X
X}
X
X
X
X
X
X
Xmark_word()
X{
Xif (marker==0) mark_begin(); word_skip();return;
X}
X
Xpass_marked()
X{
Xint i;
Xif (marker==0) { word_skip();return;}
XGOTOXY(chr[cursor_last].x,chr[cursor_last].y);
Xmarker=0; NORMAL;
X phrase_str[0]= 0;
X for (i=cursor_last;i<=cursor_mark;i++)
X printf("%c",buffer[i]);
X
Xcursor_mark=cursor_last;
Xcursor_position();
X}
X
X
Xword_skip()
X{
Xint i, the_stop;
Xchar check;
X
Xthe_stop=cursor_mark;
Xif (cursor_mark>=buffer_length-1) {next_page(); return;}
X
Xcursor_right();
Xfor (i=cursor_mark; i<buffer_length;i++)
X {
X
X switch(buffer[i])
X {case '!':
X case ',':
X case '"':
X case '\'':
X case '`':
X case '(':
X case ')':
X case '[':
X case ']':
X case '/':
X case '+':
X case '=':
X case '?':
X case '<':
X case '>':
X case '{':
X case '}':
X case '*':
X case '^':
X case '&':
X case '#':
X case ':':
X case ';':
X case '|':
X case 9:
X case 10:
X case 13:
X case '~':
X case '@':
X case '\\':
X case 32:
X case '.': if (word_mark) {word_mark=0;cursor_mark=i-1;
X cursor_position();
X goto check;}
X else break;
X default: word_mark=1;
X
X }
X }
X
Xcheck:
X if(marker)
X { GOTOXY(chr[the_stop].x,chr[the_stop].y);
X for (i=the_stop;i<=cursor_mark;i++)
X printf("%c",buffer[i]);
X cursor_position();
X }
X
X}
X
X
X
Xword_back()
X{
Xint i, the_stop;
Xchar check;
Xthe_stop=cursor_mark;
Xcursor_left();
Xfor (i=cursor_mark; i>=0;i--)
X { if (i<=cursor_last) {cursor_mark=cursor_last;
X cursor_position();BELL;goto check;}
X
X switch(buffer[i])
X {case '!':
X case ',':
X case '"':
X case '\'':
X case '`':
X case '(':
X case ')':
X case '[':
X case ']':
X case '/':
X case '+':
X case '=':
X case '?':
X case '<':
X case '>':
X case '{':
X case '}':
X case '*':
X case '^':
X case '&':
X case '#':
X case ':':
X case ';':
X case '|':
X case 9:
X case 10:
X case 13:
X case '~':
X case '@':
X case '\\':
X case 32:
X case '.':
X if (word_mark) {word_mark=0; cursor_mark=i; cursor_position();
X goto check;
X }
X else break;
X default: word_mark=1;
X
X }
X }
X
Xcheck:
X if (marker)
X {GOTOXY(chr[cursor_mark+1].x,chr[cursor_mark+1].y);
X NORMAL;
X for (i=cursor_mark+1;i<=the_stop;i++)
X printf("%c",buffer[i]);
X
X REVERSE;
X cursor_position();
X }
X}
X
X
Xnext_page()
X{
Xint i, length, pre_row, ch_count;
X
XNORMAL;
XCLS_UP();
XGOTOXY(1,1); pre_row=0; ch_count=0;
X
Xif (end_outfile) {BELL; return;}
X
X
Xif (marker){
X if ((strlen(phrase_str)+strlen(&buffer[phrase_on]))<510)
X strcat(phrase_str, &buffer[phrase_on]);
X else marker=0;
X}
X
Xfor (i=buffer_line[lines-2];i<buffer_length;i++)
X {
X if ((marker==1) && (i>=phrase_on)) {REVERSE;}
X printf("%c", buffer[i]);
X }
X
Xfor (i=cursor_last;i<buffer_length;i++)
X { fprintf(outfile,"%c",buffer[i]);
X if (buffer[i]==10)
X {
X if (next_flag==1) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X }
X
X
Xcursor_last=0;
Xphrase_on=0;
Xcursor_mark=0;
Xbuffer_length=0;
XNORMAL;
X
Xif (end_infile) {end_outfile=1;
X GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL; return;}
X
Xend_infile=read_in();
Xif (marker) {REVERSE; printf("%c",buffer[0]);cursor_position();}
X}
X
X
Xcontrol(inchar)
Xchar inchar;
X{
Xchar ch;
X
X
X switch(inchar)
X {
X case EXT:
X#if unix|VMS
X /* mainframe environment */
X if (getch()!=EXT1) {BELL;break;}
X ch=getch();
X#else
X /* DOS environment */
X
X ch=getch();
X#endif
X
X switch(ch)
X {
X case L_ARROW: cursor_left();
X break;
X case R_ARROW: cursor_right();
X break;
X case D_ARROW: cursor_down();
X break;
X case U_ARROW: cursor_up();
X break;
X default: BELL;
X }
X
X break;
X case 13: if (marker==0) {mark_begin(); break;}
X if (marker==1)
X {mark_end(); index_now();}
X break;
X case 9: word_skip(); break;
X case 'b':
X case 'B':
X case 8:
X case 127:
X word_back(); break;
X case 32: next_page(); break;
X case 'n':
X case 'N': if (marker==1)
X {mark_end();index_next_line();}
X else BELL; break;
X case 'p':
X case 'P': pass_marked(); break;
X case 'f':
X case 'F': finish_up(); return(1); break;
X case 'a':
X case 'A': if (marker==1) mark_end(); see_also();break;
X case 's':
X case 'S': if (marker==1) mark_end();index_secondary();break;
X case 'i':
X case 'I': if (marker==1) mark_end();index_entry();break;
X case 'g':
X case 'G': if (marker==1) mark_end();
X else warning("No current marked, will take the previous one");
X glossary();
X break;
X case 'W':
X case 'w': mark_word(); break;
X case '@': set_up(); break;
X case 6 : str_search(); break;
X case 3 : all_done(); break;
X#if unix
X case 4 : all_done(); break;
X#endif
X default: BELL;
X }
X
X
X}
X
X
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
Xint in_file,out_file, status;
Xint i,j;
Xchar infile_name[30], outfile_name[30];
Xchar out_ok=1;
Xchar ch, quit;
Xchar getch();
X
X#if VMS
X$DESCRIPTOR(terminal,"TT");
X
X status = SYS$ASSIGN(&terminal, &iochan, 0, 0);
X if (status != SS$_NORMAL) exit(status);
X
Xsystem("set broadcast=none");
X
X#endif
X
X
XNORMAL;
XCLS;
X
Xswitch(argc)
X {
X case 1: in_file=1; out_file=1; break;
X case 2: in_file=0; out_file=1; strcpy(infile_name,argv[1]); break;
X default: in_file=0;out_file=0;
X strcpy(infile_name,argv[1]);
X strcpy(outfile_name,argv[2]); break;
X }
X
X if (in_file)
X {GOTOXY(5,15);
X printf(" Input file (file to be indexed) >");
X scanf("%s",infile_name);
X fflush(stdin);
X }
X
X if ((infile=fopen(infile_name,"r"))==NULL)
X {GOTOXY(20,20); BLINK;
X printf("Can't find the input file");
X NORMAL; goto quit;
X }
X
Xwhile (out_ok)
X
X {
X if (out_file)
X {GOTOXY(6,15); ERASE;
X printf(" Output file (indexed file) >");
X fscanf(stdin, "%s",outfile_name);
X fflush(stdin);
X }
X
X
X out_ok=0;
X if ((outfile=fopen(outfile_name,"r"))!=NULL)
X { out_ok=1;
X GOTOXY(7,16); ERASE;
X out_file=1;
X fflush(stdin);
X printf("File %s already exits, overwrite ? [N]", outfile_name);
X ch=getch();
X ch=getch();
X if ((ch=='y')||(ch=='Y')) out_ok=0;
X fclose(outfile);
X
X }
X
X if (out_ok==0)
X {
X outfile=fopen(outfile_name,"w");
X }
X }
X
X
X
XNORMAL;
XCLS;
X
Xhelp_menu();
Xend_infile=read_in();
X
X while (1)
X {
X control(getch());
X if (exit_flag) goto quit;
X }
X
Xquit:
XGOTOXY(25, 1);
Xprintf("\n\t>>> Thank you for using INDEX MAKER >>>\n");
Xprintf("\t>>> by Jingbai Wang, August 1988 >>>\n");
X
X
X
X}
X
Xwarning(warn_str)
Xchar *warn_str;
X{
Xchar i;
X
XSAVE_CURSOR;
XGOTOXY(24,5); REVERSE; BLINK;
Xprintf("%s", warn_str); BELL; BELL;
Xfor (i=1;i<10000;i++) ;
XGOTOXY(24,1); RESTORE_CURSOR; NORMAL;
X}
X
Xvoid clr_show()
X{
Xint i;
Xfor (i=13;i<17;i++)
X {NORMAL; GOTOXY(i,1);ERASE;}
X}
X
X
Xindex_now()
X{ int i;
Xfprintf(outfile, "%s%s%s%s",the_index,the_delimiter1,phrase_str,the_delimiter2);
XSAVE_CURSOR;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s",the_index,the_delimiter1,out_str,the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X}
X
Xindex_next_line()
X{
Xint i;
X
Xnext_flag=1;
Xstrcat(next_str, the_index);
Xstrcat(next_str, the_delimiter1);
X if ((strlen(next_str)+strlen(phrase_str))<510)
X strcat(next_str, phrase_str);
Xstrcat(next_str, the_delimiter2);
XSAVE_CURSOR;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s}", the_index,the_delimiter1,out_str,the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X
X}
X
Xsee_also()
X{
XSAVE_CURSOR;BELL;
XGOTOXY(24,2); BLINK; REVERSE;
Xprintf(" Primary="); NORMAL;printf("[%s]",save_str);
Xget_line();
Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
X else strcpy(save_str, command_line);
Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
XGOTOXY(24,1);ERASE;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_seealso,the_delimiter1,
Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X
X}
X
Xindex_entry()
X{
Xchar entry[20], number[30];
Xstrcpy(save_str, phrase_str);
X
Xstrcpy(number, ",\nNumber=<");
XSAVE_CURSOR;BELL;
XGOTOXY(24,2); BLINK; REVERSE;
Xprintf(" Entry="); NORMAL;printf("[%s]",phrase_str);
Xget_line();
Xif (memcmp(command_line,"",1)==0) strcpy(entry, phrase_str);
X else strcpy(entry, command_line);
XGOTOXY(24,1);ERASE;
XGOTOXY(24,2); BLINK; REVERSE;
Xprintf(" Number="); NORMAL;
Xget_line();
Xif (memcmp(command_line,"",1)==0) number[0]=0;
X else {strcat(number, command_line); strcat(number, ">");}
X
X
Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
Xthe_key,the2_delimiter1,phrase_str, the2_delimiter2,the_entry,
Xthe2_delimiter1,entry,the2_delimiter2, number, the_delimiter2);
XGOTOXY(24,1);ERASE;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s%s",the_indexentry,the_delimiter1,
Xthe_key,the2_delimiter1,out_str, the2_delimiter2,the_entry,
Xthe2_delimiter1,entry,the2_delimiter2, number, the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X
X}
X
Xindex_secondary()
X{
XSAVE_CURSOR;BELL;
XGOTOXY(24,2); BLINK; REVERSE;
Xprintf(" Primary="); NORMAL;printf("[%s]",save_str);
Xget_line();
Xif (memcmp(command_line,"",1)==0) strcpy(command_line, save_str);
X else strcpy(save_str, command_line);
Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
Xthe2_delimiter1,phrase_str,the2_delimiter2, the_delimiter2);
XGOTOXY(24,1);ERASE;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_indexsecond,the_delimiter1,
Xthe_primary,the2_delimiter1,command_line, the2_delimiter2,the_second,
Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X
X}
X
Xglossary()
X{
XSAVE_CURSOR;
XGOTOXY(24,2); BLINK; REVERSE;
Xprintf(" Description:"); NORMAL;
Xget_line();
Xfprintf(outfile, "%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
Xg_primary,the2_delimiter1,phrase_str, the2_delimiter2,g_second,
Xthe2_delimiter1,command_line,the2_delimiter2, the_delimiter2);
XGOTOXY(24,1);ERASE;
Xclr_show(); out_check();
XGOTOXY(13,1);
XBOLD;
Xprintf("%s%s%s%s%s%s,\n %s%s%s%s%s",the_gloss,the_delimiter1,
Xg_primary,the2_delimiter1,command_line, the2_delimiter2,g_second,
Xthe2_delimiter1,out_str,the2_delimiter2, the_delimiter2);
XNORMAL; RESTORE_CURSOR;
X
X}
X
X
Xfinish_up()
X{ char ch;
X int i;
X
Xif(end_infile && end_outfile) {all_done(); exit();}
X
X
Xif (marker) {mark_end(); index_now(); }
X
Xfor (i=cursor_last;i<buffer_length;i++)
X {
X if (buffer[i]==13)
X {
X if (next_flag==1) {
X fprintf(outfile, "%s\n\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X else fprintf(outfile,"%c",buffer[i]);
X }
X
X
X
Xif (end_infile==1) {all_done(); return;}
XGOTOXY(24,35); BLINK; printf("Working ... \n");
X
X while (fscanf(infile,"%c",&ch)!=EOF)
X {
X if (ch==13);
X else fprintf(outfile, "%c", ch);
X }
X all_done();NORMAL;
X}
X
X
Xall_done()
X{
Xfclose(infile); fclose(outfile); exit_flag=1;
X#if VMS
Xsystem("set broadcast=all");
X#endif
X}
X
X
XCLS_UP()
X{ char i;
X
Xfor(i=1;i<12;i++)
X {GOTOXY(i,1); ERASE;}
X
X}
X
Xhelp_menu()
X{
XGOTOXY(12, 1);
XREVERSE; printf(" ");
Xprintf(" Inserting ");
X
XGOTOXY(17,1);
Xprintf(" ===== ^H delete ======================== ^F Search string ===============");
XNORMAL;
XGOTOXY(18,3); BOLD; printf("SPACE BAR"); NORMAL; printf(" -- next page");
XGOTOXY(19,3); BOLD; printf("<RETURN> 1"); NORMAL; printf(" -- set mark");
XGOTOXY(20,3); BOLD; printf("<RETURN> 2"); NORMAL; printf(" -- end mark & index");
XGOTOXY(21,3); BOLD; printf("<TAB>"); NORMAL; printf(" -- forward a word");
XGOTOXY(22,40); BOLD; printf("G"); NORMAL; printf(" -- end mark & glossary");
XGOTOXY(22,3); BOLD; printf("W"); NORMAL; printf(" -- mark word");
XGOTOXY(21,40); BOLD; printf("B"); NORMAL; printf(" -- backward a word");
XGOTOXY(20,40); BOLD; printf("N"); NORMAL; printf(" -- end mark & index in next line");
XGOTOXY(19,40); BOLD; printf("P"); NORMAL; printf(" -- abandon the marked/skip a word ");
XGOTOXY(18,40); BOLD; printf("F"); NORMAL; printf(" -- finish \
X ^F--string search");
XGOTOXY(23,40); BOLD; printf("S"); NORMAL; printf(" -- IndexSecondary");
XGOTOXY(23,17); BOLD; printf("I"); NORMAL; printf(" -- IndexEntry");
XGOTOXY(23,3); BOLD; printf("A"); NORMAL; printf(" -- SeeAlso");
XGOTOXY(23,65); BOLD; printf("@"); NORMAL; printf(" -- set up");
X}
X
X
Xset_up()
X{
Xint the_row, i;
Xint ch_count;
Xchar ch, string[81];
X
Xch_count=0;
XSAVE_CURSOR;
XNORMAL; REVERSE;
XGOTOXY(12,1);
Xprintf(" Set-up Menu <TAB> to quit ");
XNORMAL;
Xfor (i=13;i<24;i++)
X {GOTOXY(i,1);ERASE;}
X
XGOTOXY(13,3);printf("[%s]:",the_index);
XGOTOXY(14,3);printf("[%s]:",the_indexentry);
XGOTOXY(15,3);printf("[%s]:",the_indexsecond);
XGOTOXY(16,3);printf("[%s]:",the_seealso);
XGOTOXY(17,3);printf("[%s]:",the_primary);
XGOTOXY(18,3);printf("[%s]:",the_second);
XGOTOXY(19,3);printf("[%s]:",the_gloss);
XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);
XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second);
XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);
XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);
XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1);
XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);
X
Xthe_row=13;
Xset_up_in(the_row);
X
X while(1)
X { ch=getch();
X switch(ch)
X {
X case EXT:
X#if unix | VMS
X
X /* VAX */
X ch=getch(); if (ch!=EXT1) {BELL;break;}
X ch=getch();
X#else
X /* DOS */
X ch=getch();
X#endif
X switch(ch)
X {
X case L_ARROW:
X case U_ARROW:
X set_up_out(the_row); ch_count=0;string[0]=0;
X --the_row; if (the_row<13) the_row=25;
X set_up_in(the_row); break;
X case R_ARROW:
X case D_ARROW:
X down: set_up_out(the_row);ch_count=0;string[0]=0;
X ++the_row; if (the_row>25) the_row=13;
X set_up_in(the_row); break;
X default: BELL;
X } break;
X case 3 : all_done(); break;
X#if unix
X case 4 : all_done(); break;
X#endif
X case 1:
X case 2:
X case 5:
X case 6:
X case 7:
X case 10:
X case 11:
X case 12:
X case 14:
X case 15:
X case 16:
X case 19:
X case 20:
X case 21:
X case 22:
X case 23:
X case 24:
X case 25:
X case 26:BELL;break;
X case 8:
X case 127:
X if (ch_count>0){
X CURSOR_LEFT; ERASE;
X string[--ch_count]=0;
X } break;
X
X case 13: if (ch_count>0)
X { string[ch_count]=0;
X set_up_save(the_row, string);
X } goto down;break;
X case 9: NORMAL;for (i=12;i<24;i++)
X {GOTOXY(i,1);ERASE;}
X help_menu();RESTORE_CURSOR;
X return;
X default: printf("%c",ch);string[ch_count++]=ch;
X
X }
X
X }
X
X
X}
X
X
X
X
X
Xset_up_in( the_row)
Xint the_row;
X{ REVERSE;
X switch(the_row)
X {
X case 13:
XGOTOXY(13,3);printf("[%s]:",the_index);break;
Xcase 14:
XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
Xcase 15:
XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
Xcase 16:
XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
Xcase 17:
XGOTOXY(17,3);printf("[%s]:",the_primary); break;
Xcase 18:
XGOTOXY(18,3);printf("[%s]:",the_second); break;
Xcase 19:
XGOTOXY(19,3);printf("[%s]:",the_gloss); break;
Xcase 20:
XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
Xcase 21:
XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
Xcase 22:
XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
Xcase 23:
XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
Xcase 24:
XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
Xcase 25:
XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
X
X }
X
X}
X
X
Xset_up_save(the_row, string)
Xint the_row;
Xchar *string;
X{
X switch(the_row)
X {
X case 13:strcpy(the_index,string);break;
X case 14:strcpy(the_indexentry,string);break;
X case 15:strcpy(the_indexsecond,string);break;
X case 16:strcpy(the_seealso,string);break;
X case 17:strcpy(the_primary,string);break;
X case 18:strcpy(the_second,string);break;
X case 19:strcpy(the_gloss,string);break;
X case 20:strcpy(g_primary,string);break;
X case 21:strcpy(g_second,string);break;
X case 22:strcpy(the_delimiter1,string);break;
X case 23:strcpy(the_delimiter2,string);break;
X case 24:strcpy(the2_delimiter1,string);break;
X case 25:strcpy(the2_delimiter2,string);break;
X
X }
X
X}
X
X
X
Xset_up_out(the_row)
Xint the_row;
X{ NORMAL;
X switch(the_row)
X {
X case 13:GOTOXY(13,1);ERASE;
XGOTOXY(13,3); printf("[%s]:",the_index);break;
Xcase 14:GOTOXY(14,1);ERASE;
XGOTOXY(14,3);printf("[%s]:",the_indexentry);break;
Xcase 15:GOTOXY(15,1);ERASE;
XGOTOXY(15,3);printf("[%s]:",the_indexsecond);break;
Xcase 16:GOTOXY(16,1);ERASE;
XGOTOXY(16,3);printf("[%s]:",the_seealso);break;
Xcase 17:GOTOXY(17,1);ERASE;
XGOTOXY(17,3);printf("[%s]:",the_primary); break;
Xcase 18:GOTOXY(18,1);ERASE;
XGOTOXY(18,3);printf("[%s]:",the_second); break;
Xcase 19:GOTOXY(19,1);ERASE;
XGOTOXY(19,3);printf("[%s]:",the_gloss); break;
Xcase 20:GOTOXY(20,1);ERASE;
XGOTOXY(20,3);printf("Gloss k1 [%s]:",g_primary);break;
Xcase 21:GOTOXY(21,1);ERASE;
XGOTOXY(21,3);printf("Gloss k2 [%s]:",g_second); break;
Xcase 22:GOTOXY(22,3);printf(" ");
XGOTOXY(22,3);printf("left delimiter 1 [%s]:",the_delimiter1);break;
Xcase 23:GOTOXY(22,40);ERASE;
XGOTOXY(22,40);printf("right delimiter 1 [%s]:",the_delimiter2);break;
Xcase 24:GOTOXY(23,3);printf(" ");
XGOTOXY(23,3);printf("left delimiter 2 [%s]:",the2_delimiter1); break;
Xcase 25:GOTOXY(23,40);ERASE;
XGOTOXY(23,40);printf("right delimiter 2 [%s]:",the2_delimiter2);break;
X
X }
X
X}
X
Xout_check()
X{int i, rows, length, trunc;
Xrows=1; trunc=256;
X
Xstrcpy(out_str,phrase_str);
Xlength=strlen(out_str);
X
Xfor (i=0;i<length; i++)
X {
X if (out_str[i]==10) ++rows;
X if (rows==2) {trunc=i-4;break;}
X }
X
X
Xif (length>trunc) {out_str[trunc]='.';out_str[trunc+1]='.';out_str[trunc+2]='.';
Xout_str[trunc+3]=0;}
X}
X
X
X
Xget_line()
X{
Xchar ch;
Xint ch_count;
X
Xch_count=0;
X
Xcommand_line[0]=0;
X
X while(1)
X { ch=getch();
X switch(ch)
X {
X case 3: all_done(); break;
X#if unix
X case 4: all_done(); break;
X#endif
X case 0:
X case 1:
X case 2:
X
X case 5:
X case 6:
X case 7:
X case 10:
X case 11:
X case 12:
X case 14:
X case 15:
X case 16:
X case 19:
X case 20:
X case 21:
X case 22:
X case 23:
X case 24:
X case 25:
X case 26: BELL;break;
X case 8:
X case 127:
X if (ch_count>0){
X CURSOR_LEFT; ERASE;
X command_line[--ch_count]=0;
X } break;
X case 13: if (ch_count>0)
X command_line[ch_count]=0;
X return;
X default: printf("%c",ch);command_line[ch_count++]=ch;
X
X }
X }
X
X}
X
X
Xstr_search()
X{
Xchar *ptr;
X#if unix
Xchar *memchr();
X#endif
Xint same_page= -1;
Xvoid this_page();
Xint cursor_here=0,i;
Xcommand_line[0]=0;
XSAVE_CURSOR;
X
XGOTOXY(24,2); REVERSE;
Xprintf("String:"); NORMAL; printf(" ");
Xif (the_phrase[0]>0) printf("[%s]", the_phrase);
Xget_line();
X
Xif (command_line[0]>0) strcpy(the_phrase, command_line);
X else if (the_phrase[0]==0) {GOTOXY(24,2); ERASE; RESTORE_CURSOR;
X return;}
X
Xptr=buffer;
Xif (same_page<0)
X while ( cursor_here<cursor_mark) {cursor_here++; ptr++;}
X
Xwhile (1){
X
Xwhile ((ptr=memchr(ptr, the_phrase[0], buffer_length))!=NULL)
X {
X if( memcmp(ptr, the_phrase, strlen(the_phrase))==0)
X { GOTOXY(24,2); ERASE;
X this_page(same_page*cursor_here); return;}
X else {ptr++;}
X }
X
X /* Writing the buffer into the output file */
X
Xfor (i=cursor_last;i<buffer_length;i++)
X { fprintf(outfile,"%c",buffer[i]);
X if ((same_page<0) && (buffer[i]==10))
X {
X if (next_flag) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X }
X
X
Xif (same_page<0)
X{
X marker=0;
Xcursor_last=0;
Xphrase_on=0;
Xcursor_mark=0;
Xbuffer_length=0;
Xnext_flag=0;
Xsame_page=1;
X}
X
X
Xif (end_infile) { end_outfile=1;
X GOTOXY(17, 70); BOLD;printf("[EOF]"); BELL;
XGOTOXY(24, 2); printf("String not found");
Xall_done();
X exit();}
X
Xend_infile=read_in_only(); cursor_here=0; ptr=buffer;
X }
X
X}
X
X
Xint read_in_only()
X{
Xint i, quit_s;
Xchar quit;
Xchar string[81];
X
X
Xbuffer_length=0;
Xbuffer[0]=0;
Xstring[0]=0;
X quit_s=0;
X
Xfor (i=1;i<=8;i++)
X { if( fgets(string,80,infile)==NULL)
X {fclose(infile); quit_s=1; goto quit;}
X strcat(buffer,string);
X }
X
Xquit:
Xbuffer_length=strlen(buffer);
X
Xreturn(quit_s);
X}
X
X
Xvoid this_page(cursor_here)
Xint cursor_here;
X{
Xint i, cursor_there, the_cursor;
X
Xif (cursor_here<0) cursor_there= (-1)*cursor_here;
X else cursor_there=0;
X
Xfor (i=cursor_there;i<buffer_length;i++)
X if(memcmp(&buffer[i], the_phrase, strlen(the_phrase))==0)
X {the_cursor=i; break;}
X
Xif (cursor_here<0) {
X if (marker)
X {REVERSE; cursor_mark=cursor_last; cursor_position(); marker=0;
X for (i=cursor_last; i<=the_cursor; i++)
X {
X printf("%c", buffer[i]);
X }
X NORMAL;
X }
X cursor_mark= the_cursor;
X cursor_position();
X }
X else
X {
X position();
X NORMAL; CLS_UP(); NORMAL;
X GOTOXY(3,1);
X for (i=0;i<buffer_length;i++)
X printf("%c", buffer[i]);
X cursor_mark=the_cursor;
X cursor_position();
X }
X
Xreturn;
X}
X
X
X
X/* for ultrix define V7 = 1 */
X
X/*
X * The functions in this file negotiate with the operating system for
X * characters, and write characters in a barely buffered fashion on the display.
X * All operating systems.
X */
X
X
X#if MSDOS & TURBO
X#include <conio.h>
X#endif
X
X#if AMIGA
X#define NEW 1006L
X#define AMG_MAXBUF 1024L
Xstatic long terminal;
Xstatic char scrn_tmp[AMG_MAXBUF+1];
Xstatic long scrn_tmp_p = 0;
X#endif
X
X#if CPM
X#include <bdos.h>
X#endif
X
X#if MSDOS & (LATTICE | MSC | TURBO | AZTEC | MWC86)
Xunion REGS rg; /* cpu register for use of DOS calls */
Xint nxtchar = -1; /* character held from type ahead */
X#endif
X
X#if RAINBOW
X#include "rainbow.h"
X#endif
X
X#if USG /* System V */
X#include <signal.h>
X#include <termio.h>
X#include <fcntl.h>
Xint kbdflgs; /* saved keyboard fd flags */
Xint kbdpoll; /* in O_NDELAY mode */
Xint kbdqp; /* there is a char in kbdq */
Xchar kbdq; /* char we've already read */
Xstruct termio otermio; /* original terminal characteristics */
Xstruct termio ntermio; /* charactoristics to use inside */
X#endif
X
X#if V7 | BSD
X/*
X#undef CTRL
X*/
X#include <sgtty.h> /* for stty/gtty functions */
X#include <signal.h>
Xstruct sgttyb ostate; /* saved tty state */
Xstruct sgttyb nstate; /* values for editor mode */
Xstruct tchars otchars; /* Saved terminal special character set */
Xstruct tchars ntchars = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
X /* A lot of nothing */
X#if BSD
X#include <sys/ioctl.h> /* to get at the typeahead */
Xextern int rtfrmshell(); /* return from suspended shell */
X#define TBUFSIZ 128
Xchar tobuf[TBUFSIZ]; /* terminal output buffer */
X#endif
X#endif
X
X/*
X * This function is called once to set up the terminal device streams.
X */
Xttopen()
X{
X
X#if AMIGA
X char oline[NSTRING];
X#if AZTEC
X extern Enable_Abort; /* Turn off ctrl-C interrupt */
X
X Enable_Abort = 0; /* for the Manx compiler */
X#endif
X strcpy(oline, "RAW:0/0/640/200/");
X strcat(oline, PROGNAME);
X strcat(oline, " ");
X strcat(oline, VERSION);
X strcat(oline, "/Amiga");
X terminal = Open(oline, NEW);
X#endif
X#if CPM
X#endif
X
X#if MSDOS & (HP150 == 0) & LATTICE
X /* kill the ctrl-break interupt */
X rg.h.ah = 0x33; /* control-break check dos call */
X rg.h.al = 1; /* set the current state */
X rg.h.dl = 0; /* set it OFF */
X intdos(&rg, &rg); /* go for it! */
X#endif
X
X#if USG
X ioctl(0, TCGETA, &otermio); /* save old settings */
X ntermio.c_iflag = 0; /* setup new settings */
X ntermio.c_oflag = 0;
X ntermio.c_cflag = otermio.c_cflag;
X ntermio.c_lflag = 0;
X ntermio.c_line = otermio.c_line;
X ntermio.c_cc[VMIN] = 1;
X ntermio.c_cc[VTIME] = 0;
X ioctl(0, TCSETA, &ntermio); /* and activate them */
X kbdflgs = fcntl( 0, F_GETFL, 0 );
X kbdpoll = FALSE;
X#endif
X
X#if V7 | BSD
Xif (tt_status==tt_open) return;
X gtty(0, &ostate); /* save old state */
X gtty(0, &nstate); /* get base of new state */
X nstate.sg_flags |= RAW;
X nstate.sg_flags &= ~(ECHO|CRMOD); /* no echo for now... */
X stty(0, &nstate); /* set mode */
X ioctl(0, TIOCGETC, &otchars); /* Save old characters */
X ioctl(0, TIOCSETC, &ntchars); /* Place new character into K */
Xtt_status=tt_open;
X#if BSD
X /* provide a smaller terminal output buffer so that
X the type ahead detection works better (more often) */
X setbuffer(stdout, &tobuf[0], TBUFSIZ);
X/*--- signal(SIGTSTP,SIG_DFL); set signals so that we can
X signal(SIGCONT,rtfrmshell); suspend & restart emacs */
X#endif
X#endif
X /* on all screens we are not sure of the initial position
X of the cursor */
X/*--- ttrow = 999;
X ttcol = 999; */
X
X}
X
X/*
X * This function gets called just before we go back home to the command
X * interpreter.
X * Another no-operation on CPM.
X */
Xttclose()
X{
X
X#if AMIGA
X#if LATTICE
X amg_flush();
X Close(terminal);
X#endif
X#if AZTEC
X amg_flush();
X Enable_Abort = 1; /* Fix for Manx */
X Close(terminal);
X#endif
X#endif
X#if CPM
X#endif
X#if MSDOS & (HP150 == 0) & LATTICE
X /* restore the ctrl-break interupt */
X rg.h.ah = 0x33; /* control-break check dos call */
X rg.h.al = 1; /* set the current state */
X rg.h.dl = 1; /* set it ON */
X intdos(&rg, &rg); /* go for it! */
X#endif
X
X#if USG
X ioctl(0, TCSETA, &otermio); /* restore terminal settings */
X fcntl(0, F_SETFL, kbdflgs);
X#endif
X
X#if V7 | BSD
Xif (tt_status==tt_close) return;
X stty(0, &ostate);
X ioctl(0, TIOCSETC, &otchars); /* Place old character into K */
Xtt_status=tt_close;
X#endif
X
X
X}
X
X#if AMIGA
Xamg_flush()
X{
X if(scrn_tmp_p)
X Write(terminal,scrn_tmp,scrn_tmp_p);
X scrn_tmp_p = 0;
X}
X#endif
X
X/*
X * Flush terminal buffer. Does real work where the terminal output is buffered
X * up. A no-operation on systems where byte at a time terminal I/O is done.
X */
Xttflush()
X{
X#if AMIGA
X amg_flush();
X#endif
X
X#if CPM
X#endif
X
X#if MSDOS
X#endif
X
X#if V7 | USG | BSD
X fflush(stdout);
X#endif
X}
X
X/*
X * Read a character from the terminal, performing no editing and doing no echo
X * at all.
X */
Xttgetc()
X{
X#if AMIGA
X char ch;
X amg_flush();
X Read(terminal, &ch, 1L);
X return(255 & (int)ch);
X#endif
X#if CPM
X return (biosb(BCONIN, 0, 0));
X#endif
X
X#if RAINBOW
X int Ch;
X
X while ((Ch = Read_Keyboard()) < 0);
X
X if ((Ch & Function_Key) == 0)
X if (!((Ch & 0xFF) == 015 || (Ch & 0xFF) == 0177))
X Ch &= 0xFF;
X
X return Ch;
X#endif
X
X#if MSDOS & MWC86
X return (getcnb());
X#endif
X
X#if MSDOS & (LATTICE | MSC | TURBO | AZTEC)
X int c; /* character read */
X
X /* if a char already is ready, return it */
X if (nxtchar >= 0) {
X c = nxtchar;
X nxtchar = -1;
X return(c);
X }
X
X /* call the dos to get a char */
X rg.h.ah = 7; /* dos Direct Console Input call */
X intdos(&rg, &rg);
X c = rg.h.al; /* grab the char */
X return(c & 255);
X#endif
X
X#if V7 | BSD
X return(127 & fgetc(stdin));
X#endif
X
X#if USG
X if( kbdqp )
X kbdqp = FALSE;
X else
X {
X if( kbdpoll && fcntl( 0, F_SETFL, kbdflgs ) < 0 )
X return FALSE;
X kbdpoll = FALSE;
X while (read(0, &kbdq, 1) != 1)
X ;
X }
X return ( kbdq & 127 );
X#endif
X}
X
XNewsgroups: comp.text,comp.source.unix
XSubject: Indexor for Scribe, LaTeX/TeX, *roff and etc
XExpires:
XReferences:
XSender:
XReply-To: jbw at unix.cis.pittsburgh.edu (Jingbai Wang)
XFollowup-To:
XDistribution: na
XOrganization: Univ. of Pittsburgh, Comp & Info Sys
XKeywords:
X
X
XIf you are a technical writer or book writer, you would have found that
Xthe most tedious job is to add an index to a book you have written. I am
Xa heavy writer, and I use Scribe (with my own TEC.mak data base) and
XTeX/LaTeX to format books.
X
XTo overcome the tediousness and boresomeness of index making, I developed
Xa program in C named 'indexor' that I revealed in a previous message in
Xcomp.text. Here I am introducing the source code into comp.text and
Xcomp.source.unix.
X
XThis program named `indexor.c' can be compiled on VMS, UNIX or DOS, and have
Xhelped me with two lengthy books already. You can called it a semi-automatic
Xindex insertor. You need an ANSI terminal (like vt100, vt102) to make
Xit work properly.
X
XCut here
X_________________________________________________________________
X
X
X/* Copyright (C) 1988 by Jingbai Wang */
X
X
X/* **********************************************************************
X * This program is an auxiliary program for Scribe and TeX *
X * It inserts index and glossary into Scribe/LaTeX file *
X * It is an important program for book editing *
X * The user can set up the programs for other formattors like troff *
X * *
X * Copyright by Jingbai Wang August 1988 *
X * *
X * jbw at pittvms.bitnet *
X * jbw at cisunx.UUCP *
X ************************************************************************/
X/*
X This program was created in 1988 by myself in order to include an
X index in the Scribe and TeX/LaTeX manuals I was writing. It is part
X of the Scribe TEC.mak package I developed, and can be re-distributed
X freely for non-profit purposes.
X
X It is like a special editor to introduce index entries into a Scribe,
X LaTeX, TeX or *troff file. It indeed makes a tedious and boresome job
X enjoyable.
X The primary attempt is to make this program portable among
X VAX/VMS, UNIX (BSD and Ultrix), and DOS (MSC and MS Quick C).
X
X To compile on our VMS,
X $ex indexor
X
X and on UNIX,
X %cc -o indexor indexor.c
X
X It takes two on-line arguments, i.e., the input and output file names,
X but you can also provide these piece of information when running it.
X The program is self-instructive, no documentation is necessary.
X*/
X
X#include <string.h>
X#include <stdio.h>
X#define CLS printf("\033[2J")
X#define GOTOXY(x,y) printf("\033[%d;%df",x,y)
X#define REVERSE printf("\033[7m")
X#define NORMAL printf("\033[0m")
X#define SAVE_CURSOR printf("\033[s")
X#define BLINK printf("\033[5m")
X#define BOLD printf("\033[1m")
X#define UNDER printf("\033[4m")
X#define ERASE printf("\033[K")
X#define CURSOR_REPORT(x, y) scanf("\033[%d;%dR",x,y)
X#define BELL printf("%c", 7)
X#define CURSOR_RIGHT printf("\033[1C")
X#define CURSOR_LEFT printf("\033[1D")
X
X#define tt_open 1
X#define tt_close 0
Xint tt_status=0;
X
X#if VMS|unix
X#define RESTORE_CURSOR cursor_position()
X#else
X#define RESTORE_CURSOR printf("\033[u")
X#endif
X
X#if ultrix
X#define V7 1
X#endif
X
X#if unix|VMS
X/* ANSI escape, good for mainframe systems vt100 terminals, e.g., VAX*/
X#define DEL 127
X#define EXT 27
X#define EXT1 '['
X#define R_ARROW 'C'
X#define L_ARROW 'D'
X#define D_ARROW 'B'
X#define U_ARROW 'A'
X
X#if VMS
X#include <descrip.h>
X#include <iodef.h>
X#include <ssdef.h>
Xshort iochan; /* TTY I/O channel */
X#endif
X
X
X#else
X /* MSDOS extended code escape */
X#define DEL 8
X#define EXT 0
X#define R_ARROW 77
X#define L_ARROW 75
X#define D_ARROW 80
X#define U_ARROW 72
X#endif
X
XFILE *infile;
XFILE *outfile;
Xchar buffer[720];
Xint buffer_length;
Xint buffer_line[11];
Xint lines=1;
Xint cursor_mark=0;
Xint cursor_last=0;
X
Xchar marker=0;
Xchar phrase_str[512]="";
Xchar the_phrase[512];
Xchar save_str[128]="";
Xchar out_str[512]="";
Xint phrase_on, phrase_off, phrase_len;
Xchar end_infile=0;
Xchar end_outfile=0;
Xchar exit_flag=0;
Xchar word_mark=0;
Xchar the_index[20]="@Index";
Xchar the_delimiter1[3]="{";
Xchar the_delimiter2[3]="}";
Xchar the2_delimiter1[3]="<";
Xchar the2_delimiter2[3]=">";
Xchar the_primary[20]="Primary=";
Xchar the_second[20]="Secondary=";
Xchar the_gloss[20]="@glossary";
Xchar g_primary[20]="symbol=";
Xchar g_second[20]="expln=";
Xchar the_indexsecond[20]="@IndexSecondary";
Xchar the_seealso[20]="@SeeAlso";
Xchar the_indexentry[20]="@IndexEntry";
Xchar the_entry[20]="Entry=";
Xchar the_key[20]="Key=";
Xchar the_number[20]="Number=";
X
Xstruct CUR
X{
Xshort int x;
Xshort int y;
X} chr[720];
X
Xchar next_str[512];
Xchar next_flag=0;
Xchar command_line[160];
X
X
X
X/* The getch() and getche() */
X
X#if VMS
Xchar getch()
X{
Xint ibuf,status;
Xint iosb[2];
X status = SYS$QIOW(0, iochan, IO$_READLBLK|IO$M_NOECHO,
X iosb, 0, 0, &ibuf, 1, 0, 0, 0, 0);
X
X return (ibuf & 0xFF); /* Allow multinational */
X
X}
X
X#endif
X
X
X#if unix | ultrix | BSD
X
Xchar getch()
X{
Xint tmpch;
Xttopen();
Xtmpch=ttgetc();
Xttclose();
Xreturn(tmpch);
X}
X#endif
X
X
X#if unix | VMS
Xchar getche()
X{
Xchar inchar;
Xfputc(getch(), stdout);
Xreturn((int)inchar);
X}
X
X#endif
X
Xread_in()
X{
Xint i, quit_s;
Xchar string[81],quit;
XGOTOXY(3,1);
Xbuffer_length=0;
Xbuffer[0]=0;
Xstring[0]=0;
X quit_s=0;
X
X
Xfor (i=1;i<=8;i++)
X { if( fgets(string,80,infile)==NULL) { end_infile=1;
X quit_s=1; goto quit;}
X else { printf("%s",string);
X strcat(buffer,string);
X }
X }
X
Xquit:
Xbuffer_length=strlen(buffer);
X
Xposition();
XGOTOXY(3,1);
Xreturn(quit_s);
X }
X
Xposition()
X{
Xint i,j;
Xint row,col;
Xchar ch;
Xrow=3; col=1;
Xbuffer_line[1]=0;
Xlines=1;
X
Xfor(i=0;i<buffer_length;i++)
X { ch=buffer[i];
X chr[i].x=row; chr[i].y=col++;
X
X if(ch==10) {row++;col=1;lines++;buffer_line[lines]=i+1;}
X
X if (col==81) {row++;col=1;lines++; buffer_line[lines]=i+1;}
X }
X
X}
X
X
Xmark_begin()
X{
Xint i;
X
X for (i=cursor_last;i<cursor_mark;i++)
X {fprintf(outfile, "%c", buffer[i]);
X if (buffer[i]==10)
X {if (next_flag==1) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X }
Xmarker=1;
Xcursor_last=cursor_mark;
Xphrase_len=0;
Xphrase_on=cursor_mark;
Xphrase_str[0]=0;
XREVERSE;
Xprintf("%c",buffer[cursor_mark]);
Xcursor_position();
X}
X
Xmark_end()
X{
Xint i, length;
Xchar ch;
Xmarker=0;
X
X for (i=cursor_last;i<=cursor_mark;i++)
X { fprintf(outfile, "%c", buffer[i]);
X if (buffer[i]==10)
X {
X if (next_flag==1) {
X fprintf(outfile, "%s\n", next_str);
X next_str[0]=0; next_flag=0;
X }
X }
X
X
X }
X
Xlength=strlen(phrase_str);
Xphrase_off=cursor_mark;
Xcursor_last=cursor_mark+1;
Xcursor_mark=cursor_last; cursor_position();
Xfor (i=phrase_on; i<=phrase_off;i++)
X { ch=buffer[i];
X if ((ch==13)||(ch==10)) ch=32;
X phrase_str[length+i-phrase_on]=ch;
X }
Xphrase_str[length+1+phrase_off-phrase_on]=0;
Xphrase_on=0; phrase_off=0;
XNORMAL;
X}
X
Xcursor_position()
X{
XGOTOXY(chr[cursor_mark].x,chr[cursor_mark].y);
EOF
chars=`wc -c < 'indexor.c-1'`
if test $chars != 44172; then echo 'indexor.c-1' is $chars characters, should be 44172 characters!; fi
fi
exit 0
More information about the Comp.sources.misc
mailing list