This is output.c in view mode; [Download] [Up]
/* -*-C-*- ****************************************************************************** * * File: output.c * RCS: $Header: /home/chris/Psopt/cvs/psopt/src/output.c,v 1.2 1997/08/25 20:58:06 chris Exp $ * Description: * Author: Christian Limpach <chris@nice.ch> * Created: Thu Jun 19 03:28:18 1997 * Modified: Mon Aug 25 22:42:52 1997 (Christian Limpach) chris@nice.ch * Language: C * Package: N/A * Status: Experimental (Do Not Distribute) * * (C) Copyright 1997, Christian Limpach, all rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, a copy can be obtained from this * program's author (send electronic mail to chris@nice.ch) or from * the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA * 02139, USA. * ****************************************************************************** */ #include "psopt.h" #define CUTOFF 78 /* 78 */ #ifdef HAVE_VPRINTF #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (STDC_HEADERS) #include <stdarg.h> #define VA_START(args, lastarg) va_start(args, lastarg) #else #include <varargs.h> #define VA_START(args, lastarg) va_start(args) #endif #else #define va_alist a1, a2, a3, a4, a5, a6, a7, a8 #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8; #endif static int pos; static int need_space; static int prepend_space; static char tmp[CUTOFF+10]; /* VARARGS */ #if defined (HAVE_VPRINTF) && (defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)) void outline (const char *fmt,...) #else void outline (fmt, va_alist) char *fmt; va_dcl #endif { #ifdef HAVE_VPRINTF va_list args; #endif if (pos != 0) printf (prepend_space ? " %s\n" : "%s\n", tmp); #ifdef HAVE_VPRINTF VA_START (args, fmt); (void) vprintf (fmt, args); va_end (args); #else (void) printf (fmt, a1, a2, a3, a4, a5, a6, a7, a8); #endif putchar ('\n'); pos = 0; prepend_space = 0; tmp[0] = '\0'; } #define PRINT_TMP { if (prepend_space) putchar (' '); printf ("%s", tmp); tmp[0] = '\0'; } static void handle_linefeeds_and_spaces (len) int len; { if (need_space) { PRINT_TMP; prepend_space++; pos++; } if (pos + len > CUTOFF) { if (!prepend_space) PRINT_TMP; putchar ('\n'); prepend_space = 0; pos = strlen (tmp); } } void outstring (str) char *str; { handle_linefeeds_and_spaces (strlen (str)); strcat (tmp, str); pos += strlen (str); } /* VARARGS */ #if defined (HAVE_VPRINTF) && (defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)) void outstringf (int len, const char *fmt,...) #else void outstringf (len, fmt, va_alist) int len; char *fmt; va_dcl #endif { #ifdef HAVE_VPRINTF va_list args; #endif char buf[len+10]; handle_linefeeds_and_spaces (len); #ifdef HAVE_VPRINTF VA_START (args, fmt); (void) vsprintf (buf, fmt, args); va_end (args); #else (void) sprintf (buf, fmt, a1, a2, a3, a4, a5, a6, a7, a8); #endif strcat (tmp, buf); pos += len; } void outbinstring (str) char *str; { char buf[CUTOFF+10]; /* caller should set need_space == 0 */ /* need_space = 0; */ handle_linefeeds_and_spaces (1); if (pos + strlen (str) > CUTOFF) { if (prepend_space) { putchar ('\n'); pos = strlen (tmp); } printf ("%s", tmp); tmp[0] = '\0'; prepend_space = 0; while (pos + strlen (str) > CUTOFF) { printf ("%.*s\n", CUTOFF - pos, str); str = str + CUTOFF - pos; pos = 0; } } sprintf (buf, "%s", str); strcat (tmp, buf); pos += strlen (str); } void output (head) Code *head; { pos = 0; need_space = 0; prepend_space = 0; tmp[0] = '\0'; while (head != NULL) { switch (head->type) { case START: puts ("%!PS-Adobe-2.0"); while (head->next != NULL && head->next->type == COMMENT) { head = head->next; outline ("%%%%%s", head->d.comment); } output_folding (); break; case ARGUMENT: outstring (head->d.argument->newname); need_space++; break; case COMMAND: outstring (head->d.command->newname); need_space++; break; case DIRECT: need_space = 0; outstringf (1 + strlen (head->d.direct->newname), /* fixme !!! */ "/%s", head->d.direct->newname); need_space++; break; case STRING: need_space = 0; outstring (head->d.string); break; case BINSTRING: need_space = 0; outbinstring (head->d.binstring); break; case COMMENT: need_space = 0; outline ("%%%%%s", head->d.comment); break; case OPEN_BRACE: need_space = 0; outstring ("{"); break; case CLOSE_BRACE: need_space = 0; outstring ("}"); break; case OPEN_BRACKET: need_space = 0; outstring ("["); break; case CLOSE_BRACKET: need_space = 0; outstring ("]"); break; } head = head->next; } }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.