pswstring.c revision 824
824N/A/*
824N/A * pswstring.c
824N/A *
824N/A * (c) Copyright 1988-1994 Adobe Systems Incorporated.
824N/A * All rights reserved.
824N/A *
824N/A * Permission to use, copy, modify, distribute, and sublicense this software
824N/A * and its documentation for any purpose and without fee is hereby granted,
824N/A * provided that the above copyright notices appear in all copies and that
824N/A * both those copyright notices and this permission notice appear in
824N/A * supporting documentation and that the name of Adobe Systems Incorporated
824N/A * not be used in advertising or publicity pertaining to distribution of the
824N/A * software without specific, written prior permission. No trademark license
824N/A * to use the Adobe trademarks is hereby granted. If the Adobe trademark
824N/A * "Display PostScript"(tm) is used to describe this software, its
824N/A * functionality or for any other purpose, such use shall be limited to a
824N/A * statement that this software works in conjunction with the Display
824N/A * PostScript system. Proper trademark attribution to reflect Adobe's
824N/A * ownership of the trademark shall be given whenever any such reference to
824N/A * the Display PostScript system is made.
824N/A *
824N/A * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
824N/A * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
824N/A * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
824N/A * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
824N/A * NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
824N/A * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
824N/A * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
824N/A * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
824N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
824N/A * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
824N/A *
824N/A * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
824N/A * Incorporated which may be registered in certain jurisdictions
824N/A *
824N/A * Author: Adobe Systems Incorporated
824N/A */
824N/A/* $XFree86$ */
824N/A
824N/A#include <stdio.h>
824N/A#include <ctype.h>
824N/A#include <string.h>
824N/A
824N/A#include "pswpriv.h"
824N/A#include "psw.h"
824N/A
824N/A#define outfil stdout
824N/A#define MAX_PER_LINE 16
824N/A
824N/Aint PSWStringLength(char *s)
824N/A{
824N/A register char *c = s;
824N/A register int len = 0;
824N/A
824N/A while (*c != '\0') { /* skip \\ and \ooo */
824N/A if (*c++ == '\\') {
824N/A if (*c++ != '\\') c += 2;
824N/A }
824N/A len++;
824N/A }
824N/A return (len);
824N/A}
824N/A
824N/Avoid PSWOutputStringChars(char *s)
824N/A{
824N/A register char *c = s;
824N/A register char b;
824N/A register int perline = 0;
824N/A
824N/A while (*c != '\0') {
824N/A putc('\'',outfil);
824N/A switch (b = *c++) {
824N/A case '\\':
824N/A putc('\\',outfil);
824N/A fputc(b = *c++,outfil);
824N/A if (b != '\\') {putc(*c++,outfil);putc(*c++,outfil);}
824N/A break;
824N/A case '\'':
824N/A fprintf(outfil,"\\'");
824N/A break;
824N/A case '\"':
824N/A fprintf(outfil,"\\\"");
824N/A break;
824N/A case '\b':
824N/A fprintf(outfil,"\\b");
824N/A break;
824N/A case '\f':
824N/A fprintf(outfil,"\\f");
824N/A break;
824N/A/* avoid funny interpretations of \n, \r by MPW */
824N/A case '\012':
824N/A fprintf(outfil,"\\012"); perline++;
824N/A break;
824N/A case '\015':
824N/A fprintf(outfil,"\\015"); perline++;
824N/A break;
824N/A case '\t':
824N/A fprintf(outfil,"\\t");
824N/A break;
824N/A default:
824N/A putc(b,outfil); perline--;
824N/A break;
824N/A }
824N/A putc('\'',outfil);
824N/A if (*c != '\0') {
824N/A if (++perline >= MAX_PER_LINE) {
824N/A fprintf(outfil,",\n ");
824N/A outlineno++;
824N/A }
824N/A else {putc(',',outfil);}
824N/A perline %= MAX_PER_LINE;
824N/A }
824N/A }
824N/A}
824N/A
824N/A
824N/Aint PSWHexStringLength(char *s)
824N/A{
824N/A return ((int) (strlen(s)+1)/2);
824N/A}
824N/A
824N/Avoid PSWOutputHexStringChars(register char *s)
824N/A{
824N/A register int perline = 0;
824N/A char tmp[3];
824N/A
824N/A tmp[2] ='\0';
824N/A while ((tmp[0] = *s++)!= '\0') {
824N/A tmp[1] = *s ? *s++ : '\0';
824N/A fprintf(outfil,"0x%s",tmp);
824N/A if (*s != '\0') {
824N/A if (++perline >= MAX_PER_LINE) {
824N/A fprintf(outfil,",\n ");
824N/A outlineno++;
824N/A }
824N/A else {putc(',',outfil);}
824N/A perline %= MAX_PER_LINE;
824N/A }
824N/A } /* while */
824N/A}