rsalz@bbn.com (Rich Salz) (02/09/88)
Submitted-by: Tom Smith <analog!smith> Posting-number: Volume 13, Issue 26 Archive-name: casette-lbl This is a C program that reads files containing album title, artist, and songlist, and outputs a PostScript description of a cassette label suitable for framing or inserting into a standard-issue cassette case. Documentation is provided in both manpage and README files, and a Makefile is here as well. Our site connection with hplabs gets wedged at times. Thomas Smith {hplabs, ucbvax!sun!sunncal}!analog!smith #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # cassette.c # overhead_ps.c # printlabels # Makefile export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'cassette.c'" '(2403 characters)' if test -f 'cassette.c' then echo shar: "will not over-write existing file 'cassette.c'" else sed 's/^X//' << \SHAR_EOF > 'cassette.c' X/* X * Copyright (C) 1987, Thomas H. Smith -- San Francisco, California X * Program 'Cassette': X * Permission is granted to any individual or institution X * to use, copy, modify, or redistribute this software so long as it X * is not sold for profit and provided this copyright notice is retained. X * X * PostScript is a registered trademark of Adobe Systems, Inc. X */ X#include <stdio.h> X#include "cassette.h" X Xmain(argc, argv) Xint argc; Xchar *argv[]; X{ X FILE *open_file(); X char *album1, *album2; X int number_songs = FALSE; X X album1 = argv[1]; X album2 = argv[2]; X X if (argc > 1) { X if (strcmp(argv[1], "-n") == 0) { X number_songs = TRUE; X argc--; X album1 = argv[2]; X album2 = argv[3]; X } X } X X if ((argc != 3) && (argc != 2)) { X (void) fprintf(stderr, "usage: %s [-n] <album1> [<album2>]\n", X argv[0]); X exit(1); X } X X output_ps_globals(); X output_ps_outline(); X if (argc == 2) { X file_to_postscript(open_file(album1), number_songs, ONLY); X } else { X file_to_postscript(open_file(album1), number_songs, SIDE1); X file_to_postscript(open_file(album2), number_songs, SIDE2); X } X output_ps_trailer(); X} X X XFILE * Xopen_file(filename) Xchar *filename; X{ X FILE *fd, *fopen(); X X fd = fopen(filename, "r"); X if (fd == NULL) { X perror(filename); X exit(1); X } X return(fd); X} X X Xfile_to_postscript(file, number_songs, position) XFILE *file; Xint number_songs, position; X{ X char *title, *artist, *noise_red, **songs1, **songs2; X int noise_type; X extern char *input_title(), *input_artist(), *input_noise_reduction(); X extern char **input_songs(); X X artist = input_artist(file); X title = input_title(file); X noise_red = input_noise_reduction(file, &noise_type); X songs1 = input_songs(file); X if (position == ONLY) /* look for two-record sets */ X songs2 = input_songs(file); X X output_ps_artist(title, artist, position); X output_ps_title(title, artist, position); X output_ps_noise_reduction(noise_red, noise_type, position); X if ((position == ONLY) && (songs2[0] != NULL)) { X output_ps_songs(songs1, number_songs, SIDE1); X output_ps_songs(songs2, number_songs, SIDE2); X } else { X output_ps_songs(songs1, number_songs, position); X } X X (void) free(artist); X (void) free(title); X (void) free(noise_red); X free_song_list(songs1); X if (position == ONLY) X free_song_list(songs2); X} SHAR_EOF if test 2403 -ne "`wc -c < 'cassette.c'`" then echo shar: "error transmitting 'cassette.c'" '(should have been 2403 characters)' fi fi echo shar: "extracting 'overhead_ps.c'" '(6941 characters)' if test -f 'overhead_ps.c' then echo shar: "will not over-write existing file 'overhead_ps.c'" else sed 's/^X//' << \SHAR_EOF > 'overhead_ps.c' X/* X * Copyright (C) 1987, Thomas H. Smith -- San Francisco, California X * Program 'Cassette': X * Permission is granted to any individual or institution X * to use, copy, modify, or redistribute this software so long as it X * is not sold for profit and provided this copyright notice is retained. X * X * PostScript is a registered trademark of Adobe Systems, Inc. X * The name 'Dolby' and the Dolby symbol are trademarks X * of Dolby Industries, Inc. X */ X#include <stdio.h> X#include "dimensions.h" X#include "cassette.h" X X Xoutput_ps_globals() X{ X /* global definitions */ X OUTPUT("%%\tglobals\n"); X OUTPUT("/inches { 72 mul } def\n"); X OUTPUT("/currentx { currentpoint pop } def\n"); X OUTPUT("/currenty { currentpoint exch pop } def\n"); X OUTPUT("/lowerdone { false } def\n"); X OUTPUT("/doscalefont {\n dup dup /maxfontsize exch def\n"); X OUTPUT(" /fontsize exch def scalefont\n} def\n"); X OUTPUT("/adjustfont {\n dup /fontsize exch fontsize mul def\n"); X OUTPUT(" scalefont\n} def\n"); X OUTPUT("/interline { fontsize 1.33 mul } def\n"); X OUTPUT("/creturn { linestart currenty interline sub moveto } def\n"); X X OUTPUT("/overflowsline {"); X OUTPUT(" stringwidth pop currentx add lineend ge } def\n"); X OUTPUT("/indent { %.3f inches 0 rmoveto } def\n", CONTINUEDIST); X OUTPUT("/breakline {\n {\n ( ) search exch\n"); X OUTPUT(" dup overflowsline {\n creturn pageoverflow indent\n"); X OUTPUT(" } if show\n {\t%% test of search\n show\n"); X OUTPUT(" } { exit } ifelse\n } loop\n} def\n"); X X OUTPUT("/shrinkshow {\n {\n dup overflowsline {\n"); X OUTPUT(" fontsize maxfontsize 2 div 1 add lt {\n"); X OUTPUT(" /oldindent /indent load def /indent { } def\n"); X OUTPUT(" 0 fontsize rmoveto breakline\n"); X OUTPUT(" /indent /oldindent load def\n"); X OUTPUT(" exit\n } {\n"); X OUTPUT(" currentfont .9 adjustfont setfont\n } ifelse\n"); X OUTPUT(" } {\n linestart currenty moveto\n"); X OUTPUT(" show exit\n } ifelse\n } loop\n} def\n"); X X OUTPUT("/elipsesshow {\n dup overflowsline {\n"); X OUTPUT(" {\n ( ) search exch dup overflowsline {\n"); X OUTPUT(" (...) show pop { pop } if pop exit\n"); X OUTPUT(" } {\n show\n } ifelse\n"); X OUTPUT(" {\t%%test of search\n show\n"); X OUTPUT(" } { exit } ifelse\n } loop\n"); X OUTPUT(" } { show } ifelse\n} def\n"); X X OUTPUT("/pageoverflow {\n currenty %.3f le lowerdone not and {\n", X VSPACE + BORDERWIDTH); X OUTPUT(" dolowerblock linestart -%.3f moveto\n } if\n} def\n", X SONGSIZE + VSPACE + BORDERWIDTH); X X OUTPUT("/dosong {\n pageoverflow\n"); X OUTPUT(" dup overflowsline {\n breakline\n"); X OUTPUT(" } {\n show\n } ifelse\n creturn\n"); X OUTPUT("} def\n"); X X /* extra lower outline if necessary */ X OUTPUT("%%\textra lower block outline\n"); X OUTPUT("/dolowerblock {\n"); X OUTPUT(" gsave newpath [] 0 setdash 0 0 moveto\n"); X OUTPUT(" 0 -%.3f inches lineto\n", BODYHEIGHT); X OUTPUT(" %.3f inches -%.3f inches lineto\n", WIDTH, BODYHEIGHT); X OUTPUT(" %.3f inches 0 lineto\n", WIDTH); X X OUTPUT(" %.3f setlinewidth stroke\n", BORDERWIDTH); X OUTPUT(" 0 0 moveto %.3f inches 0 lineto\n", WIDTH); X OUTPUT(" %.3f setlinewidth stroke\n", (BORDERWIDTH * 2)); X X OUTPUT(" %.3f inches -%.3f inches %.3f add moveto\n", WIDTH / 2.0, X BODYHEIGHT, VSPACE + BORDERWIDTH); X OUTPUT(" %.3f inches -%.3f lineto\n", WIDTH / 2.0, X VSPACE + (BORDERWIDTH / 2)); X OUTPUT(" [.3 1] 0 setdash %.3f setlinewidth stroke\n", DASHWIDTH); X OUTPUT(" /lowerdone { true } def\n"); X OUTPUT(" grestore\n} def\n"); X X output_ps_dolby(); X} X X Xoutput_ps_outline() X{ X OUTPUT("\n%%\toutline of label\n"); X X /* body of label */ X OUTPUT("newpath\n"); X OUTPUT("0 0 moveto\n"); X OUTPUT("0 %.3f inches lineto\n", BODYHEIGHT + EDGEHEIGHT); X OUTPUT("%.3f inches %.3f inches lineto\n", X WIDTH, BODYHEIGHT + EDGEHEIGHT); X OUTPUT("%.3f inches 0 lineto\n", WIDTH); X OUTPUT("closepath %.3f setlinewidth stroke\n", BORDERWIDTH); X X /* edge of label */ X OUTPUT("newpath\n"); X OUTPUT("0 %.3f inches moveto\n", BODYHEIGHT); X OUTPUT("%.3f inches %.3f inches lineto\n", WIDTH, BODYHEIGHT); X OUTPUT("0 %.3f inches moveto\n", BODYHEIGHT + EDGEHEIGHT); X OUTPUT("%.3f inches %.3f inches lineto\n", X WIDTH, BODYHEIGHT + EDGEHEIGHT); X OUTPUT("%.3f setlinewidth stroke\n", BORDERWIDTH * 2); X X /* overhang of label */ X OUTPUT("newpath\n"); X OUTPUT("0 %.3f inches moveto\n", BODYHEIGHT + EDGEHEIGHT); X OUTPUT("0 %.3f inches rlineto %.3f inches 0 rlineto\n", TABSHORTHEIGHT, X ((WIDTH - TABWIDTH) / 2.0) - TABDELTA); X OUTPUT("%.3f inches %.3f inches rlineto\n", TABDELTA, TABDELTA); X OUTPUT("%.3f inches 0 rlineto\n", TABWIDTH); X OUTPUT("%.3f inches -%.3f inches rlineto\n", TABDELTA, TABDELTA); X OUTPUT("%.3f inches %.3f inches lineto\n", X WIDTH, BODYHEIGHT + EDGEHEIGHT + TABSHORTHEIGHT); X OUTPUT("0 -%.3f inches rlineto\n", TABSHORTHEIGHT); X OUTPUT("%.3f setlinewidth stroke\n", BORDERWIDTH); X X /* dashed interior lines */ X OUTPUT("\n%%\tdashed interior lines\n"); X X OUTPUT("newpath\n"); X OUTPUT("0 %.3f inches %.3f sub moveto\n", BODYHEIGHT, X TITLE2SIZE + (VSPACE * 2) + BORDERWIDTH); X OUTPUT("%.3f inches %.3f inches %.3f sub lineto\n", WIDTH, BODYHEIGHT, X TITLE2SIZE + (VSPACE * 2) + BORDERWIDTH); X X OUTPUT("%.3f inches %.3f inches %.3f sub moveto\n", WIDTH / 2.0, X BODYHEIGHT, VSPACE + BORDERWIDTH); X OUTPUT("%.3f inches %.3f lineto\n", WIDTH / 2.0, X VSPACE + (BORDERWIDTH / 2)); X X OUTPUT("[.3 1] 0 setdash %.3f setlinewidth stroke\n", DASHWIDTH); X} X X Xoutput_ps_trailer() X{ X OUTPUT("showpage\n"); X} X X Xstatic Xoutput_ps_dolby() X{ X OUTPUT("%%\t\tDolby trademark symbol\n"); X OUTPUT("%%\t\t\tThe name Dolby and this symbol\n"); X OUTPUT("%%\t\t\tare trademarks of Dolby Industries, Inc.\n"); X OUTPUT("/dolby {\n"); X OUTPUT(" gsave -%.3f 0 rmoveto currentpoint newpath\n", DOLBY_WIDTH); X OUTPUT(" %.3f add %.3f -90 90 arc\n", DOLBY_RADIUS, DOLBY_RADIUS); X OUTPUT(" currentx %.3f add currenty %.3f sub %.3f 90 -90 arc\n", X DOLBY_WIDTH, DOLBY_RADIUS, DOLBY_RADIUS); X OUTPUT(" -%.3f 0 rmoveto\n", DOLBY_WIDTH); X OUTPUT(" 0 setgray currentpoint fill moveto\n"); X X /* line around it */ X OUTPUT(" 0 %.3f rlineto %.3f 0 rlineto\n", X DOLBY_HEIGHT, DOLBY_WIDTH); X OUTPUT(" 0 -%.3f rlineto -%.3f 0 rlineto\n", X DOLBY_HEIGHT, DOLBY_WIDTH); X OUTPUT(" [] 0 setdash 0 setlinewidth currentpoint stroke moveto\n"); X X /* line through center */ X OUTPUT(" %.3f 0 rmoveto 0 %.3f rlineto\n", X DOLBY_WIDTH / 2.0, DOLBY_HEIGHT); X OUTPUT(" 1 setgray stroke\n"); X OUTPUT(" grestore\n} def\n"); X} SHAR_EOF if test 6941 -ne "`wc -c < 'overhead_ps.c'`" then echo shar: "error transmitting 'overhead_ps.c'" '(should have been 6941 characters)' fi fi echo shar: "extracting 'printlabels'" '(1418 characters)' if test -f 'printlabels' then echo shar: "will not over-write existing file 'printlabels'" else sed 's/^X//' << \SHAR_EOF > 'printlabels' X X# Bourne shell file -- no leading comment! X X# page dimensions XHPage="8.5 inches" XVPage="11 inches" XHMargin=".5 inches" XVMargin=".5 inches" X X# cassette label dimensions XBorder=1 XCWidth="4 inches $Border add" XCHeight="3.5 inches $Border add" X X# division between adjacent labels XDivision=1.5 X XMiddleHPage="$HPage 2 div" XMiddleVPage="$VPage 2 div" X Xif [ ! "$1" ]; then X echo "usage: $0 [-a] [-m] file [file...]" 1>&2 X exit 1 Xfi X X# if printing adjacent labels Xif [ "$1" = "-a" ]; then X LeftEdge="$MiddleHPage $CHeight sub $Division sub" X TopEdge="$MiddleVPage $CWidth add $Division add" X shift Xelse X LeftEdge="$HMargin" X TopEdge="$VPage $VMargin sub" Xfi X X# if manually feeding paper Xif [ "$1" = "-m" ]; then X echo "statusdict begin /manualfeed true store end" X ManualFeed=True X shift Xfi X Xecho "/inches { 72 mul } def" X Xwhile [ "$1" ] ; do X for Position in 1 2 3 4 ; do X if [ "$1" ]; then X File=$1 X case $Position in X 1) X X=$MiddleHPage X Y=$TopEdge X ;; X 2) X X=$MiddleHPage X Y=$MiddleVPage X ;; X 3) X X=$LeftEdge X Y=$TopEdge X ;; X 4) X X=$LeftEdge X Y=$MiddleVPage X ;; X esac X echo gsave X echo $X $Y translate X echo 270 rotate X sed /showpage/d $File X echo grestore X shift X fi X done X echo showpage Xdone X Xif [ "$ManualFeed" ]; then X echo "statusdict begin /manualfeed false store end" Xfi SHAR_EOF if test 1418 -ne "`wc -c < 'printlabels'`" then echo shar: "error transmitting 'printlabels'" '(should have been 1418 characters)' fi fi echo shar: "extracting 'Makefile'" '(1042 characters)' if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else sed 's/^X//' << \SHAR_EOF > 'Makefile' XCFLAGS = -O XLDFLAGS = -s X XCASSETTE = cassette XPRINTLABELS = printlabels XINSTALLDIR = /usr/new XMANDIR = /usr/man/man1 XSHARFILE = cassette.shar X XCFILES = input_file.c cassette.c output_ps.c overhead_ps.c XOFILES = input_file.o cassette.o output_ps.o overhead_ps.o XHFILES = cassette.h dimensions.h XMISCFILES = Makefile README cassette.1 \ X album1.sample album2.sample double.sample $(PRINTLABELS) X XINSTALLFILES = $(INSTALLDIR)/$(CASSETTE) \ X $(INSTALLDIR)/$(PRINTLABELS) \ X $(MANDIR)/cassette.1 X X$(CASSETTE): $(OFILES) X cc $(CFLAGS) $(LDFLAGS) -o $@ $(OFILES) X Xinstall: $(INSTALLFILES) X X$(INSTALLDIR)/$(CASSETTE): $(CASSETTE) X install -m 755 $(CASSETTE) $@ X X$(INSTALLDIR)/$(PRINTLABELS): $(PRINTLABELS) X install -m 755 $(PRINTLABELS) $@ X X$(MANDIR)/cassette.1: cassette.1 X install -m 644 cassette.1 $@ X X$(SHARFILE): $(CFILES) $(HFILES) $(MISCFILES) X shar $(CFILES) $(HFILES) $(MISCFILES) > $@ X Xlint: $(CFILES) X lint $(LINTFLAGS) $(CPPFLAGS) $(CFILES) X Xclean: X /bin/rm -f $(OFILES) $(CASSETTE) $(SHARFILE) tags X Xtags: $(CFILES) X ctags $(CFILES) SHAR_EOF if test 1042 -ne "`wc -c < 'Makefile'`" then echo shar: "error transmitting 'Makefile'" '(should have been 1042 characters)' fi fi exit 0 # End of shell archive exit 0 -- For comp.sources.unix stuff, mail to sources@uunet.uu.net.