/* pscalendar Unix C tool for generating continuous calendar pages in Postscript Copyright (C) 2004 Dave Bayer. Subject to the terms and conditions of the MIT License. This tool has no interface; to adjust settings, change the program constants below. To compile, type gcc pscalendar.c -o pscalendar To execute, type ./pscalendar */ /* output file name */ char file_name[] = "calendar.ps"; /* starting day, month, year */ unsigned firstday = 28; unsigned firstmonth = 12; int firstyear = 2003; /* columns, rows, pages */ unsigned cols = 7; unsigned rows = 6; unsigned pages = 20; /* font */ char font_name[] = "Times-Roman"; unsigned font_size = 12; /* define units, e.g. 1 inch = 72 points, 1 cm = 28.3 points */ unsigned points_per_unit = 72; /* page dimensions in chosen units */ double pagewidth = 8.5; double pageheight = 11; double leftmargin = 0.2; double rightmargin = 0.2; double topmargin = 0.2; double bottommargin = 0.2; double gap_between_boxes = 0.03; double text_offset_x = 0.1; double text_offset_y = 0.2; /*------------------------------------------------------------------------------------------------*/ #include #define LEN 256 int month_length[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; char *month_name[13] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; typedef struct date { unsigned day; unsigned month; int year; } date; static void date_advance( date *d ) { int day, month, year; day = d->day; month = d->month; year = d->year; if ( day == 28 && month == 2 && year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 )) {} else if ( day >= month_length[month] ) { day = 0; if ( ++month == 13 ) { month = 1; ++year; } } ++day; d->day = day; d->month = month; d->year = year; } static char *date_string( date *d, int level ) { static char s[LEN]; if ( d->day == 1 ) level = 2; switch ( level ) { case 2: sprintf( s, "%d %s %02d", d->day, month_name[d->month], d->year % 100 ); break; default: sprintf( s, "%d", d->day ); break; } return s; } char *ps_header[] = { "%!PS-Adobe-3.0", "%%Creator: Dave Bayer", "%%EndComments", "", "/choosefont", "{", " exch findfont", " exch scalefont", " setfont", "} def", "", "/daybox", "{", " /text exch def", " /uly exch units def", " /ulx exch units def", " 0.75 setlinewidth", " newpath", " ulx uly moveto", " 0 height neg rlineto", " width 0 rlineto", " 0 height rlineto", " closepath", " stroke", " ulx xoff add uly yoff sub moveto", " text show ", "} def", "", 0 }; char ps_constants[] = "/units {%d mul} def\n" "/width %.4f units def\n" "/height %.4f units def\n" "/xoff %.4f units def\n" "/yoff %.4f units def\n" "/%s %d choosefont\n\n" ; char ps_daybox[] = "%.4f %.4f (%s) daybox\n"; char ps_page[] = "\nshowpage\n\n"; static void calendar ( FILE *fout ) { char **p; int i, j, k, level; double xinc, yinc; date d = { firstday, firstmonth, firstyear }; xinc = ( pagewidth - leftmargin - rightmargin + gap_between_boxes ) / cols; yinc = ( pageheight - topmargin - bottommargin + gap_between_boxes ) / rows; for ( p=ps_header; *p!=0; ++p ) fprintf( fout, "%s\n", *p ); fprintf( fout, ps_constants, points_per_unit, xinc - gap_between_boxes, yinc - gap_between_boxes, text_offset_x, text_offset_y, font_name, font_size ); for ( k=0; k