ftp.nice.ch/pub/next/connectivity/news/NewsBase.3.02.s.tar.gz#/NewsBase302.source/MMEdit/rtf2_parse.c

This is rtf2_parse.c in view mode; [Download] [Up]

/*  
 parse.c of

 Rtf2: a facility to convert RTF files to files 
 compatible with the ATK file format.

 Rtf2 is copyright (c) 1991 by the Massachusetts Institute of Technology.

 RTF is a product of the Microsoft Corporation.

 Permission to use, copy, modify, and distribute this software and
 its documentation for any purpose and without fee is hereby granted,
 provided that the above copyright notice and the name of the author(s)
 appear in all copies; that both that copyright notice, the name of
 the author(s) and this permission notice appear in supporting
 documentation; and that the name of the Massachusetts Institute of
 Technology not be used in advertising or publicity pertaining to
 distribution of the software without specific, written prior
 permission.  The Massachusetts Institute of Technology makes no
 representations about the suitability of this software for any purpose.
 It is provided "as is" without express or implied warranty.

 Rtf2 was written by Jeremy Paul Kirby, jpkirby@ATHENA.MIT.EDU and Scott Rixner, rixner@ATHENA.MIT.EDU

 $Header: /usr2/multimedia/RCS/MMEdit//rtf2_parse.c,v 3.4 92/12/18 13:17:17 suzuki Exp $
*/


#include <stdio.h>
#import  <string.h>
#include <ctype.h>
#include "rtf2.h"
#include <streams/streams.h>
#import  <defaults/defaults.h>

#define fgetc(x) NXGetc(x)
#define getc(x) NXGetc(x)
#define fputc(x,stream) NXPutc(stream,x)
#define putc(x,stream) NXPutc(stream,x)
#define fputs(x,stream) NXPrintf(stream,x)
#define ungetc(x,y) NXUngetc(y)
#define fprintf NXPrintf
#define fscanf NXScanf

extern rtf2_TABLE rtf2_Table;

/*extern int R2UniqueID();*/

void rtf2_CloseFiles(), rtf2_AbsorbSpace();
long int rtf2_ParseText();
void exit();
int atoi(), rtf2_Execute(), rtf2_ReplaceText(), R2Begin();
char *rtf2_GetInstruction(), *rtf2_makelower();
char *makelower();
char *rtf2_GetInstructionfrom();
char *rtf2_GetInstructionRev();
int cal;

void rtf2_ParseMain(countO)
int countO;
/*
 *
 *  Takes care of the beginning of the input and output files.
 *    adds needed styles
 *    detects character set
 */
{
  int in, token, foundver;
  char ch, tmp_instruction[TMP_SIZE];

  CurrLine=1;
  token = 20001;
  MasterToken = token;
  Objcount=countO; 
  multip=1;

//
  rtf2_AbsorbSpace();
  ch = (char) getc(fin);
  if(ch != '{')
    {
      exit(0);
    }
//
  while((in = getc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch=='\\')
	break;
    }
//
  if(in == EOF)
    {
      exit(0);
    }
//
  strcpy(tmp_instruction, rtf2_GetInstruction());
  strcpy(tmp_instruction, makelower(tmp_instruction));
//
  if(!strncmp(tmp_instruction, "info", 4))
  {
  while((in = getc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch=='\\')
        break;
    }
  strcpy(tmp_instruction, rtf2_GetInstruction());
  strcpy(tmp_instruction, makelower(tmp_instruction));

  while((in = getc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch=='\\')
        break;
    }
  strcpy(tmp_instruction, rtf2_GetInstruction());
  strcpy(tmp_instruction, makelower(tmp_instruction));

  }
  if(strncmp(tmp_instruction, "rtf", 3))
     {
       exit(0);
     }
//
  sscanf(tmp_instruction, "rtf%d", &foundver);
//
  if(foundver > RTFverceiling)
    {
      exit(0);
    }
//
  while((in = getc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch=='\\')
	  break;
    }
//
  if(in == EOF)
    {
      exit(0);
    }
//
//
  strcpy(tmp_instruction, rtf2_GetInstruction());
  strcpy(tmp_instruction, makelower(tmp_instruction));
//
  if(!strcmp(tmp_instruction, "ansi"))
    {
      CharSet = ANSI;
    }
  else if(!strcmp(tmp_instruction, "mac"))
    {
      CharSet = MAC;
    }
  else if(!strncmp(tmp_instruction, "pc", 2))
    {
      CharSet = PC;
    }
  else
    {
      ; //exit(0);
    }
//
  oldsent[0]='\0';
  old2sent[0]='\0';
  old3sent[0]='\0';
  sentence[0]='\0';
  sentence1[0]='\0';
  fon=0;
           if (( Objcount >= 3))
           {
                fprintf(fout,"\r\n--%s\r\n", Boundary);
                fprintf(fout,"Content-Type: text/richtext\r\n");
                fprintf(fout,"\r\n" );
                Ismultip =0;
                multip=0;
           }

  rtf2_ParseText(EOF, NORMAL, PRINTTOFILE);
}


long int rtf2_ParseText(tofind, transform, action)
     int tofind, transform, action;
/*
 *
 *  Actually goes through the input file, character by
 *  character, and detects commands and performs the
 *  appropriate action.
 *
 *  tofind:     used to tell when this recursion of
 *              ParseText should fall back.
 *  transform:  used to check if individual characters
 *              should be transformed into anything.
 *              i.e. change to all caps
 *  action:     if set to PRINTTOFILE (0), normal
 *              parsing occurs.  Presently the only
 *              other option is NOP, which causes
 *              everything to be passed over until
 *              tofind is encountered, at which point
 *              it falls back.
 *
 */
{
  char ch, instruction[TMP_SIZE], tmp_instruction[TMP_SIZE];
  char tmps[2], *r, *cr, *nomalize();
  rtf2_TABLE tmp, rtf2_FindNode();
  int rtf2_Execute(), rtf2_ReplaceText(), in;
  int st=0 , R2Size();
//  char autoold[10000];
//  char autosent1[10000];
  void GetRev();
   fontp=0;

  while((in = fgetc(fin)) != tofind && in != -1)
    {
      ch = (char) in;
      st=0;
      if(ch == '\\')
      {
          sentence[0] = '\0';
	  tmps[0]=ch;
	  tmps[1]='\0';
	  strcat(sentence, tmps);

	  fontp++;

	  ch = (char) fgetc(fin);
	  if ( ch == '\\' || ch =='{' || ch =='}' ){
            fprintf(fout, "\\%c", ch);
	    continue;
	  }
	  if ( ch == '\n' || ch == '\r')
	  {
	     strcat(sentence, "par");
  	  }else{
	     tmps[0]=ch;
	     tmps[1]='\0';
	     strcat(sentence, tmps);
	     while((ch = (char) fgetc(fin)) !=' ' && ch != '\n' 
				 && ch != '\r' && ch != EOF){
   	       tmps[0]=ch;
	       tmps[1]='\0';
	       strcat(sentence, tmps);
	     }
	  }
          //sentence1[0] = '\0';
        while( (r= rtf2_GetInstructionfrom()) != NULL)
	{
	  strcpy(tmp_instruction, r);
          sscanf(tmp_instruction, "%[A-z]", instruction);
          strcpy(instruction, makelower(instruction));
          tmp = rtf2_FindNode(RTFCOLUMN, instruction);
          if(tmp == NULL && (!action))
            {
              fprintf(ferr, "* RTF command \\%s not recognized\n",
                      instruction);
            }
          else if((tmp != NULL) && (!action))
            rtf2_Execute(tmp_instruction);
	}
    if ((strlen(oldsent)==0) && strlen(old2sent) == 0) fontp =1;
	    if (*oldsent=='\r'){
		strcpy(oldsent,oldsent+2);
	        if (*oldsent=='\r'){
		   strcpy(oldsent,oldsent+2);
		}
	    }
	    if ( Levels == 0 && Levels1 == 0 ){
		cr = index(oldsent,'\r');
		if ( cr ){
			*cr = '\0';
		}
	    }else{
		cr = index(oldsent,'\r');
                if ( cr ){
			*cr = '\0';
			strcat(oldsent,cr+2);
		}
	    }
	    if (*sentence1=='\r'){
	         strcpy(sentence1,sentence1+2);
            }
//	if( fontp == 1 ){
	if (strlen(oldsent) == 0 || strcmp(oldsent, sentence1)){
	    nomalize(oldsent);
	    strcat(oldsent, sentence1);
	    strcpy(sentence1,nomalize(oldsent));		
		R2Size("fs", he, tofind);
	    strcpy(sentence1,nomalize(oldsent));		
	}
      }
      else if(ch=='<'){
	fprintf(fout,"<lt>");
	    fontp=0;
	}
      else if(ch=='.'){
	fprintf(fout,". ");
	}
      else if(ch=='\r'){
	CurrLine++;
	}
      else if(ch=='\n' || ch == '\0'){
//	fprintf(fout,"\r\n");
	CurrLine++;
	}
      else if(ch=='}')
	{
		;
	}
      else if((ch=='{') && (!action)){
//	   strcpy(autoold, oldsent);
//	   strcpy(autosent1, sentence1);
	   R2Begin();
//	   strcpy(oldsent,autoold);
//	   strcpy(sentence1,autosent1);
	   oldsent[0]='\0';
	   sentence1[0]='\0';
	   Levels=0;
	   Levels1=0;
	}
      else if((ch=='{') && (action))
	   rtf2_ParseText('}', NORMAL, action);
      else if(!action)
	{
	  /* Perform transformations */
/*
           if ( (Ismultip == 1) && ( Objcount >= 3))
           {
                fprintf(fout,"\r\n--%s\r\n", Boundary);
                fprintf(fout,"Content-Type: text/richtext\r\n");
                fprintf(fout,"\r\n" );
		Ismultip =0;
		multip=0;
           }
*/
	  fprintf(fout, "%s", sentence1);

          fprintf(fout, "%c", ch);
          while((ch = (char) fgetc(fin)) !='\\' && ch !='{' && ch !='}'
		&& ch != '\0'	 && ch != EOF){
/*
	    st++;
	    if ( st >= 430) {
		fprintf(fout,"\r\n");
		st=0;
	    }
*/
	    if ( ch =='<')
              fprintf(fout, "<lt>");
 	    else if ( ch == '\n')
              fprintf(fout, "\r\n");
	    else				
              fprintf(fout, "%c", ch);
   	    Ismultip=0;
	    fontp=0;
	  }
	  if (ch =='\\') ungetc(ch,fin);
   	    Ismultip=0;
	    fontp=0;

	    GetRev();
 	    fprintf(fout, "\r\n");
	}
    }
  return(CurrLine);
}


rtf2_TABLE rtf2_FindNode(field, string)
     int field;
     char *string;
/*
 *
 *  Look up command in table created from the trans file.
 *
 */
{
  rtf2_TABLE tmp=rtf2_Table;

  if(field == RTFCOLUMN)
    {
      while(tmp != NULL)
	{
	  if(!strcmp(tmp->rtfword, string))
	    return(tmp);
	  else
	    tmp = tmp->next;
	}
      return(NULL);
    }
  
  if(field == EZCOLUMN)
    {
      while(tmp != NULL)
	{
	  if(!strcmp(tmp->ez.word, string))
	    return(tmp);
	  else
	    tmp = tmp->next;
	}
      return(NULL);    
    }

  return(0);
}


int rtf2_ExecuteSpecial(character)
     char character;
/*
 *
 *  Handle special rtf characters.
 *
 */
{
  rtf2_TABLE tmp;
  char string[2];
  
  sprintf(string, "%c", character);
  
  tmp = rtf2_FindNode(RTFCOLUMN, string);
  
  if(tmp == NULL)
    {
      exit(0);
    }
  else
    rtf2_Execute(string);
   return(0);
}


char *rtf2_GetInstruction()
/*
 *
 *  Read command in from the input file.
 *
 */
{
  char character, *instruction;
  int in;

  instruction = (char *) calloc (TMP_SIZE, sizeof(char));

  while((in = fgetc(fin)) != EOF)
    {
      character = (char) in;
      if(character == '\\' || character == '{' || character == '}')
	{
	  ungetc(character, fin);
	  return(instruction);
	}
      else if(character==' ' || character=='\t')
	return(instruction);
      else if(character=='\n' || character=='\r')
	{ 
	  CurrLine++;
	  return(instruction);
	}
      else
	sprintf(instruction, "%s%c", instruction, character);
    }
  return(instruction);
  
}


char *rtf2_GetInstructionfrom()
/*
 *
 *  Read command in from the sentence.
 *
 */
{
  char *instruction;
  char *t,*s;

  instruction = (char *) calloc (10000, sizeof(char));


    t = index(sentence, '\\');
    if ( t == NULL ){
	return(0);
    }
	s = index(t+1, '\\');
   	if ( s == NULL )
	{
		strcpy(instruction, t+1); 
		sentence[0]='\0';
		return(instruction);
	}
	else{
		*s = '\0';
		strcpy(instruction, t+1); 
		*s = '\\';
		strcpy(sentence, s);
		return(instruction);
	}
  return(0);
}

char *rtf2_GetInstructionRev()
/*
 *
 *  Reverse read command in from the sentence1.
 *
 */
{
  char  *t,*instruction;
  char  *s;
  void free();

  if (strlen(sentence1) == 0) return(0);
  instruction = (char *) calloc (TMP_SIZE, sizeof(char));
  s = (char *) calloc (TMP_SIZE, sizeof(char));

  t = rindex(sentence1,'<');
  if ( t == NULL )
	return(NULL);
  strcpy(s, t);
  *t = '\0';
  if ( t = index(s+1,'\r') ){
     cal=1;
     *t = '\0';
     strncpy(instruction, s+1,strlen(s)-2);
  }
  else{
     cal=0;
     strncpy(instruction, s+1,strlen(s)-2);
  }
  free(s);
  return(instruction);
}


int rtf2_Execute(instruction)
     char *instruction;
/*
 *
 *  Read in the delimiter associated with INSTRUCTION,
 *  if any, then call the associated function with the 
 *  appropriate parameters.
 *
 */
{
  rtf2_TABLE tmp;
  char alphastring[TMP_SIZE], numdelstring[TMP_SIZE];
  int i, numdel, lettersaintover, unaryminusfound;

  alphastring[0]='\0';
  numdelstring[0]='\0';
  lettersaintover = 1;
  unaryminusfound = 0;

  for(i=0; i<strlen(instruction); i++)
       {
	 if(((isalpha(instruction[i])) || (index(RTFchars, instruction[i]) && instruction[i]!='-') || (!strcmp(instruction, "-"))) && lettersaintover)

	      sprintf(alphastring, "%s%c", alphastring, instruction[i]);
      else if(instruction[i]=='-' && !unaryminusfound)
	{
	  unaryminusfound = 1;
	  lettersaintover = 0;
	  sprintf(numdelstring, "-");
	}
      else if(isdigit(instruction[i]))
	{
	  lettersaintover = 0;
	  sprintf(numdelstring, "%s%c", numdelstring, instruction[i]);
	}
      else
	{
	 // exit(0);
	}
    }

  if ( strlen(numdelstring) == 0 )
    numdel = 1;
  else 
    numdel = atoi(numdelstring);
  tmp = rtf2_FindNode(RTFCOLUMN, makelower(alphastring));

  if ( tmp != NULL ){
  if(tmp->mode & QUOTEDCHAR)
    fputc(tmp->ez.quote, fout);
  else if(tmp->mode & NAKED)
  {
      if(!(tmp->mode & COMMAND)){
	i = rtf2_ReplaceText(tmp->ez.word, tmp->mode, ' ', instruction,numdel);
	return(i);
      }
      else{
	i = tmp->ez.fun(alphastring, numdel, ' ');
	return(i);
      }
  }
  else
  {
      if(!(tmp->mode & COMMAND))
      {
	i = rtf2_ReplaceText(tmp->ez.word, tmp->mode, '}', instruction, numdel);
	if ( i == 1 )
	i = rtf2_ReplaceText(tmp->ez.word, tmp->mode, '}', alphastring, numdel);

	return(i);
      }
      else
      {
	i = tmp->ez.fun(alphastring, numdel, '}');
	return(i);
      }
  }
  }
  return(0);
}


int rtf2_ReplaceText(instruction, mode, tofind, allinstruction, num)
     char *instruction, tofind;
     char *allinstruction;
     int mode, num;
{
  char *deltoken();
  char tmpstr[20];

  tmpstr[0] = '\0';
  if(mode & NAKED)
    {
      fprintf(fout, "\n<%s>", instruction);      
      if(!(mode & SUPPRESSDELS))
	fputs("{}\n", fout);
      else
	fputs("\n", fout);
	return(0);
    }
  else if ( !strcmp(allinstruction, "b")){
	bold_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "b0")){
	if (bold_flag > 0 ){
	bold_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "i")){
	italic_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "i0")){
	if (italic_flag > 0){
	italic_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "ul") ){
	underl_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction,"ul0") || !strcmp(allinstruction,"ulnone")){
	if ( underl_flag > 0){
	underl_flag--;
	strcpy(oldsent, deltoken("underline", oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "up") || !strcmp(instruction,"up")){
	supers_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "up0")){
	if ( supers_flag > 0){
	supers_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "dn")|| !strcmp(instruction,"dn")){
	subs_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "dn0")){
	if ( subs_flag > 0){
	subs_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "qr")){
	fright_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "qr0")){
	if ( fright_flag > 0 )
	fright_flag--;
	return(0);
    }
  else if ( !strcmp(allinstruction, "ql")){
	fleft_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction, "ql0")){
	if ( fleft_flag > 0){
	fleft_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
    }
  else if ( !strcmp(allinstruction, "qc")){
	center_flag++;
	sprintf(tmpstr, "<%s>", instruction);
	strcat(sentence1, tmpstr);
	return(0);
    }
  else if ( !strcmp(allinstruction,"qc0")){
	if ( center_flag > 0){
	center_flag--;
	strcpy(oldsent, deltoken(instruction, oldsent));
	}
	return(0);
   }
	return(1);
}

char *deltoken(token, sen)
char *token;
char *sen;
{
  	char *t;
  	char *s;
  	char *e;
	char *in;
	char buf[40];

	if (strlen(sen) == 0) return(sen);
        in = (char *) calloc (TMP_SIZE, sizeof(char));
	s=sen;
     while(1){
	t = index(s,'<');
	if ( !t ) return(sen);
	e = index(s,'>');
	if ( !e ) return(sen);
	strncpy(buf, ++t, (e-t)-1);
	buf[(e-t)]='\0';
	if ( !strcmp(buf,token) ){
		t = index(s,'<');
		strcpy(in, ++e);
		*t = '\0';
		strcat(sen,in);
		if ( !strcmp(buf,"bigger")){
			Levels--;
		}
		if ( !strcmp(buf,"smaller")){
			Levels1--;
		}
		break;
	}else{
	   s = ++e;
	   continue;
	}
     }
        return(sen);
}

char *nomalize(r)
char *r;
{
  	char *t;
  	char *s;
  	char *e;
	char *in;
	int ata=0;
	char buf[40];
	char buf1[40];

        in = (char *) calloc (TMP_SIZE, sizeof(char));
	if ( bold_flag == 0 ){
		  deltoken("bold", sentence1);
		  deltoken("bold", sentence1);
		  deltoken("bold", oldsent);
		  deltoken("bold", oldsent);
	}
	if ( italic_flag ==0){
		  deltoken("italic", sentence1);
		  deltoken("italic", sentence1);
		  deltoken("italic", oldsent);
		  deltoken("italic", oldsent);
	}
	if ( supers_flag ==0){
		  deltoken("superscript", sentence1);
		  deltoken("superscript", sentence1);
		  deltoken("superscript", oldsent);
		  deltoken("superscript", oldsent);
	}
	if ( subs_flag ==0){
		  deltoken("subscript", sentence1);
		  deltoken("subscript", sentence1);
		  deltoken("subscript", oldsent);
		  deltoken("subscript", oldsent);
	}
	if ( center_flag ==0){
		  deltoken("center", sentence1);
		  deltoken("center", sentence1);
		  deltoken("center", oldsent);
		  deltoken("center", oldsent);
	}
	if ( fleft_flag ==0){
		  deltoken("flushleft", sentence1);
		  deltoken("flushleft", sentence1);
		  deltoken("flushleft", oldsent);
		  deltoken("flushleft", oldsent);
	}
	if ( fright_flag ==0){
		  deltoken("flushright", sentence1);
		  deltoken("flushright", sentence1);
		  deltoken("flushright", oldsent);
		  deltoken("flushright", oldsent);
	}
	if ( underl_flag ==0){
		  deltoken("underline", sentence1);
		  deltoken("underline", sentence1);
		  deltoken("underline", oldsent);
		  deltoken("underline", oldsent);
	}

	s = oldsent;
     while(1){
        t = index(s,'<');
        if ( !t ) break;
        e = index(s,'>');
        if ( !e ) break;
        strncpy(buf, ++t, (e-t)-1);
        buf[(e-t)]='\0';
        if (!strcmp(buf, "f0")
                        || !strcmp(buf, "f1")
                        || !strcmp(buf, "f2")
                        || !strcmp(buf, "f3")
                        || !strcmp(buf, "f4")
                        || !strcmp(buf, "f5")
                        || !strcmp(buf, "f6")
                        || !strcmp(buf, "f7")
                        || !strcmp(buf, "f8")
                        || !strcmp(buf, "f9")
                        || !strcmp(buf, "f10")
                        || !strcmp(buf, "f11")
                        || !strcmp(buf, "f12")
                        || !strcmp(buf, "f13")
                        || !strcmp(buf, "f14")
                        || !strcmp(buf, "f15")
                        || !strcmp(buf, "f16")
                        || !strcmp(buf, "f17")
                        || !strcmp(buf, "f18")
                        || !strcmp(buf, "f19")) {
                t = index(s,'<');
                strcpy(in, ++e);
		strcpy(buf1, buf);
                *t = '\0';
                strcat(oldsent,in);
		ata=1;
                s = oldsent;
	}else{
	   s = ++e;
	   continue;
	}
    }
    if (ata==1 && strlen(buf1) !=0){
	    buf[0]='\0';
	    sprintf(buf, "<%s>", buf1);
	    strcat(oldsent,buf);
    }
    return(oldsent);
}

void GetRev()
{	
  char tmp_instruction[TMP_SIZE];
  char *r;
  int rtf2_ReplaceText();


          while(( r = rtf2_GetInstructionRev()) != NULL ){
	    strncpy(tmp_instruction, r, TMP_SIZE);
   	    Ismultip=0;
            if (!strcmp(tmp_instruction, "f0")
                        || !strcmp(tmp_instruction, "f1")
                        || !strcmp(tmp_instruction, "f2")
                        || !strcmp(tmp_instruction, "f3")
                        || !strcmp(tmp_instruction, "f4")
                        || !strcmp(tmp_instruction, "f5")
                        || !strcmp(tmp_instruction, "f6")
                        || !strcmp(tmp_instruction, "f7")
                        || !strcmp(tmp_instruction, "f8")
                        || !strcmp(tmp_instruction, "f9")
                        || !strcmp(tmp_instruction, "f10")
                        || !strcmp(tmp_instruction, "f11")
                        || !strcmp(tmp_instruction, "f12")
                        || !strcmp(tmp_instruction, "f13")
                        || !strcmp(tmp_instruction, "f14")
                        || !strcmp(tmp_instruction, "f15")
                        || !strcmp(tmp_instruction, "f16")
                        || !strcmp(tmp_instruction, "f17")
                        || !strcmp(tmp_instruction, "f18")
                        || !strcmp(tmp_instruction, "f19")) {
		    continue;
	    } else if ( cal == 1){
       		      fprintf(fout, "</%s>\r\n", tmp_instruction);
	    } else{
	   	      fprintf(fout, "</%s>", tmp_instruction);
	    }
	}
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.