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

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

/*  
 misc.c of

 2rtf: a facility to convert files in the ATK file format to files compatible with the RTF format.

 Scribetext is copyright (c) 1989, 1990 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.
 
 2rtf was written by Scott Rixner, rixner@ATHENA.MIT.EDU and Jeremy Paul Kirby, jpkirby@ATHENA.MIT.EDU

 $Header: /usr2/multimedia/RCS/MMEdit//2rtf_misc.c,v 3.1 92/12/08 17:13:29 suzuki Exp $
*/


#include <stdio.h>
#include <ctype.h>
#include <strings.h>
#import "2rtf.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 fclose(x) NXCloseMemory(x, NX_FREEBUFFER)
#define fprintf NXPrintf


extern struct TableStruct *Table;
/* extern struct FileStackStruct *FileStack; */

int offset(), roffset();
void AbsorbSpace();
char *makelower();
/*
char *index();
char *rindex();
*/

char *makelower(instruction)
     char *instruction;
{
  int i;
  
  for(i=0; i<strlen(instruction); i++)
    {
      if(isupper(instruction[i]))
	instruction[i] = tolower(instruction[i]);
    }

  return(instruction);
}
  

int offset(string, character)
     char *string, character;
{
  char *loc;

  loc = index(string, character);

  if (loc) return (strlen(string) - strlen(loc));
  else return(strlen(string));
}


int roffset(string, character)
     char *string, character;
{
  char *loc;

  loc = rindex(string, character);

  if (loc) return (strlen(string) - strlen(loc));
  else return(strlen(string));
}


void CloseFiles()
{

  fclose(fout);
  fclose(ftrans);
  if(ferr != NULL)
    fclose(ferr);
}


void AbsorbSpace()
{
  int in;
  char ch;

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

void AbsorbNewlines()
/* doesn't handle putting in the proper number of "\par"'s. */
{
  int in;
  char ch;

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

void Newlines()
{
   int n = 0;
   char ch;//, tmp_instruction[TMP_SIZE];

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

   if(n>0)
      paragraph = 1;

   for(; n>0; n--)
      fputs("\\par\n", fout);
}

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