summaryrefslogtreecommitdiff
path: root/language/tamil/wntamil/tamilize.c
blob: 368bbd573b9e99ad2ddb450aeae9cb60927e9d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* Convert transliterated Tamil text to codes known to the Tamilmax.tex */
/* set of macros using the wntml fonts */

#include <stdio.h>
#include <ctype.h>


/* globally accessible variables */

int	tamilflag,t_errors,true,false,errorcount,transflag;
char	switcher,tdelim;
char	tspace[2];
void	changestate();
FILE	*input,*output;
char filename[128];



/* functions */

/*  void bracket_err()
{
   printf("\nCharacter '}' read while scanning Tamil; need to edit file.\n");
   printf("Examine end of the output file to find location of problem.");
   fclose(input);
   fclose(output);
   abort();
} */

void haccbox()
{
    puts("Tamilize: Tamil to TeX converter v:0.97 of 4/24/90");
    puts("Humanities And Arts Computing Center, DR-10");
    puts("University of Washington");
    puts("Seattle, Washington, 98195  USA");
    puts("phone (206)-543-4218");
    puts("ridgeway@blake.u.washington.edu");
    puts("Copyright 1990 Humanities and Arts Computing Center");
    puts("You are welcome to use this work-in-progress, but please do not");
    puts("redistribute: rather, refer other interested parties to us.");
    puts("Since this is a work in progress, we do not want uncontrolled");
    puts("proliferation of pre-release versions.");
    return;
}

FILE *getopen(char *access)
{
	int	temp;
	FILE	*handle;
	gets(filename);
	handle=fopen(filename,access);
	if (handle ==  (FILE *) NULL) {
            printf("Can't open file %s",filename);
            errorcount++;
            if (errorcount > 9) {
                 printf("\n\n\n\n\nToo many errors!\n");
                 abort();
                 }
	  }
	return handle;
}
FILE *get_file(char *access,char *prompt)
{
	puts(prompt);
	return getopen(access);
}

int isvowel(char thischar)
{
  switch (thischar) {
     case 'a' :
     case 'e' :
     case 'i' :
     case 'o' :
     case 'u' : return true;
     default  : return false;
     }
}

void stringout(char *string)
{
  fputs(string,output);
}

void charout(char thischar)
{
  putc(thischar,output);
}

void romanout(char thischar)
{
  stringout("{\\roman ");
  charout(thischar);
  charout('}');
}

void transcribe_err(char thischar)
{
  printf("Character %c encountered in Tamil environment.\n",thischar);
  romanout(thischar);
}

void pushback(char thischar)
{
  ungetc(thischar,input);
}

void processtamil()
{
  char ch;
  int  newsyl;
  newsyl=true;
  for (tamilflag=true; tamilflag==true; ) {
    ch = getc(input);
    if (ch == EOF) abort();
    if (ch == switcher) changestate();
    else if (isspace(ch)) {
            stringout(tspace);
            charout(ch);            
            for ( ch=getc(input); isspace(ch); ch=getc(input)) charout(ch);
            pushback(ch);
            newsyl=true;
	    }
    else if (ispunct(ch) ) {
             if (ch == 125) printf("\nCharacter } encountered while scanning tamil -- probable error.\n");
             romanout(ch);
             newsyl=true;
             }
    else {
            switch (ch) {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u': if (newsyl==true) {
			      charout(tdelim);
			      newsyl=false;
			      }
                          charout(ch);
                          break;
                case 'c':
                case 't':
                case 'p':
                case 'm':
                case 'y':
                case 'r':
                case 'l':
                case 'v':
                case 's':
                case 'j':
                case 'x':
                case 'h': charout(tdelim);
                          charout(ch);
                          newsyl=false;
                          break;
                case 'k': charout(tdelim);
                          ch=getc(input);
                          if (ch=='4') charout('X');
                          else {
                              charout('k');
                              pushback(ch);
                              }
                          newsyl=false;
                          break;
                case '2': charout(tdelim);
                          charout('N');
                          newsyl=false;
                          break;
                case '3': charout(tdelim);
                          stringout("NN");
                          newsyl=false;
                          break;
                case '4': charout(tdelim);
                          charout('S');
                          newsyl=false;
                          break;
                case '5': charout(tdelim);
                          stringout("NY");
                          newsyl=false;
                          break;
                case '6': charout(tdelim);
                          charout('R');
                          newsyl=false;
                          break;
                case '7': charout(tdelim);
                          charout('Z');
                          newsyl=false;
                          break;
                case '8': charout(tdelim);
                          charout('T');
                          newsyl=false;
                          break;
                case '9': charout(tdelim);
                          charout('L');
                          newsyl=false;
                          break;
                case 'n': charout(tdelim);
                          ch=getc(input);
                          if (ch=='g') stringout("ng");
                          else {
                              charout('n');
                              pushback(ch);
                              }
                          newsyl=false;
                          break;
                default : transcribe_err(ch);
                          newsyl=true;
                } /* endcase */
    }  /* endif */
  }  /* endfor*/
}

void starttamil()
{
  stringout("{\\btam ");  /*   stringout("{\\starttamil\%\n"); */
  processtamil();
}

void endtamil()
{
  stringout("}\\etam{}");  /* stringout("}\\endtamil\%\n");  */
  tamilflag=false;
}

void changestate()
{
  if (tamilflag==true) endtamil();
  else starttamil();
}

main(int argc, char *argv[])
{
  int ch,err,notdone,vowflag,initflag;
  errorcount=0;
  switcher='~';
  true=1;
  false=0;
  tamilflag=false;
  tdelim=1;  /* i.e. control-a ::: if yah don't like it, change it */
  tspace[0]=tdelim;
  tspace[1]=' ';
  haccbox();
  vowflag=0;
  if (argc > 1) input = fopen(argv[1],"rb");
  if (input == (FILE *) NULL) {
	/* prompt for and open input file */
	for ( ; input == (FILE *) NULL ; input=get_file("rb","Enter name of input file: ")) ;
        }
        /* we are making these binary, as we have no guarantee what kind */
        /* of character may be in the transcription: we don't care about */
        /* ends of lines, as we are reading character by character */
   if (argc > 2) output = fopen(argv[2],"wb");
   if (output == (FILE *) NULL) {
	for ( ; output == (FILE *) NULL ; output=get_file("wb","Enter name of output file: ")) ;
	/* prompt for and open output file */
        }
   while ((ch = getc(input)) != EOF) {
	if (ch == switcher) changestate();
	else {
		if (ch == '|') {
                  vowflag=1;
		  notdone=1;
		  initflag=2;
		  while (notdone) {
		  ch=getc(input);
                  if (isalnum(ch)) {
                    initflag--;
                    if (vowflag==0) {
		       if (! isvowel(ch)) stringout("\\-");
                       }
		    if (isvowel(ch)) vowflag=1;
                    else vowflag=0;
                    }
                  else {
                     vowflag=1;
                     initflag=2;
                     }
		  if (ch==EOF) notdone=0;
		  else {
		    switch(ch) {
		      case '2': stringout("\\ndot{}");
		      	break;
		      case '3': stringout("\\nndot{}");
		      	break;
		      case '4': stringout("\\skts{}");
			break;
		      case '5': stringout("\\paln{}");
		      	break;
		      case '6': stringout("\\rdot{}");
		      	break;
		      case '7': stringout("\\rdotdot{}");
			break;
		      case 'T': stringout("\\tdot{}");
			 break;
		      case 'D': stringout("\\dotd{}");
			 break;
		      case '8':
		                 if ( initflag > 0 ) stringout("\\tdot{}");
		                 else {
		                      err=getc(input);
		                      if (err == '8') stringout("\\tdot{}\\tdot{}");
				      else {
					  stringout("\\dotd{}");
					  pushback(err);
					  }
		                      }
		      	break;
		      case '9': stringout("\\dotl{}");
		      	break;
		      case '|': notdone=0;
		        break;
		      default: putc(ch,output);
			} /* endcase */
		  } /* end else */
		} /* endwhile */
		} /* endif */
		else putc(ch,output);
	}  /* endelse */
	} /* endwhile */
   fclose(input);
   fclose(output);
   puts("Tamilize is done.");
}