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

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

/*  
 misc.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_misc.c,v 3.1 92/12/10 18:23:32 suzuki Exp $
*/


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

#define fgetc(x) NXGetc(x)
#define fputc(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 FILESTACK FileStack;
void rtf2_AbsorbSpace(), rtf2_AbsorbWhiteSpace();

  
/* For Development Use Only:  Comment Out for Final Production */
void rtf2_TempPrintList()
{
  rtf2_TABLE tmp=rtf2_Table;

  while(tmp != NULL)
    {
      printf("rtfword is %s  mode is %d ez is ", tmp->rtfword, tmp->mode);
      if(tmp->mode & COMMAND)
	printf("COMMAND\n");
      else 
	printf("%s\n", tmp->ez.word);
      tmp = tmp-> next;
    }
}


void rtf2_CloseFiles()
{
}


void rtf2_AbsorbSpace()
{
  int in;
  char ch;

  while((in = fgetc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch != ' ' && ch != '\t')
	{
	  ungetc(ch, fin);
	  break;
	}
    }
}


void rtf2_AbsorbNewlines()
{
  int in;
  char ch;

  while((in = fgetc(fin)) != EOF)
    {
      ch = (char) in;
      if(ch != '\n' && ch != '\r')
	{
	  ungetc(ch, fin);
	  break;
	}
      else
	CurrLine++;
    }
}


void rtf2_AbsorbWhiteSpace()
{
  int in;
  char ch;

  while((in=fgetc(fin)) != EOF)
    {
      ch = (char) in;
      if (ch=='\n' || ch=='\r')
	CurrLine++;
      else if(ch != ' ' && ch!='\t')
	{
	  ungetc(ch, fin);
	  break;
	}
    }
}

void reverse(s)
char s[];
{
    int c, i, j;
    for(i=0, j=strlen(s)-1; i<j; i++, j--)
    {
	c=s[i];
	s[i]=s[j];
	s[j]=c;
    }
}

int itoa(n, s)
int n;
char s[];
{
    int i, sign;
    if ((sign=n) < 0)
	n = -n;
    i=0;
    do{
	s[i++] = n % 10 + '0';
    } while ((n /=10)>0);
    if(sign<0)
	s[i++] = '-';
    s[i] = '\0';
    reverse(s);
	return(0);
}

void rtf2_CloseBraces(instruction)
char *instruction;
{
   for(; Levels>0; Levels--)
      fprintf(fout,"</%s>\n", instruction );
}

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