/*5:*/ #line 411 "./dvlabel.w" #include #include #include #include #include #include #include #define VERSION "1.6" #define DEFAULT_DVIPSOPTS "-ta4 -D1200" #define DEFAULT_LINETHICKNESS (0.5) #define DEFAULT_CROPLINETHICKNESS (0.15) #define DEFAULT_EDGESEPARATION (1.0) #define MAXCHAR (128) #define SUCCESS (0) #define FAILURE (1) #define INSTREAM (infile_specified?infile:stdin) #define OUTSTREAM (outfile_specified?outfile:stdout) #define log(...) log_printf(__func__, __VA_ARGS__) /*6:*/ #line 482 "./dvlabel.w" extern char*optarg; char*progname; /*:6*/ #line 435 "./dvlabel.w" /*7:*/ #line 488 "./dvlabel.w" /*8:*/ #line 514 "./dvlabel.w" void log_printf(const char*function_name,const char*format,...){ va_list args; time_t time0; struct tm lt; struct timeval tv; char logentry[1024]; gettimeofday(&tv,NULL); time(&time0); lt= *localtime(&time0); sprintf(logentry,"%02u%02u%02u %02u:%02u:%02u.%03d ", lt.tm_year-100,lt.tm_mon+1,lt.tm_mday, lt.tm_hour,lt.tm_min,lt.tm_sec,tv.tv_usec/1000); sprintf(logentry+strlen(logentry),"(%s) ",function_name); va_start(args,format); vsprintf(logentry+strlen(logentry),format,args); va_end(args); sprintf(logentry+strlen(logentry),"\n"); fprintf(stdout,"%s",logentry); return; } /*:8*/ #line 489 "./dvlabel.w" /*9:*/ #line 539 "./dvlabel.w" /*10:*/ #line 607 "./dvlabel.w" void hl(const char*format,...){ va_list args; char line[1024]; va_start(args,format); vsprintf(line,format,args); va_end(args); sprintf(line+strlen(line),"\n"); fprintf(stdout,"%s",line); return; } /*:10*/ #line 540 "./dvlabel.w" void showsomehelp(void){ hl("Usage: %s [options]",progname); hl("When invoked without any command line options, this program enters"); hl("interactive mode."); hl("Options:"); hl(" -i, --inputfile "); hl(" Specifies the file where to read the label text strings, entered in"); hl(" a format corresponding to the input order as would have been"); hl(" entered in interactive mode."); hl(" -o, --outputfile "); hl(" Specifies the file where to save the generated TeX source code for"); hl(" the label. whenever this option is omitted, the generated source"); hl(" code will be written to standard terminal output instead. Notice"); hl(" that the name specified using this option is used as the *base"); hl(" name* for the generated output; this means that the TeX file"); hl(" automatically will get .tex as suffix, the DVIfile .dvi, etc."); hl(" For example, if you want to have your TeX output stored into a file"); hl(" named, say, 'foo.tex', just specify '-o foo'."); hl(" -H, --headline"); hl(" Toggle display of generation time and input source in page header"); hl(" of the generated TeX code. Default: off"); hl(" -C, --cropmarks"); hl(" Toggle display of crop marks (alignment marks) in the generated TeX"); hl(" code. Default: off"); hl(" -t, --linethick "); hl(" Use linethickness of typographic points in generating the boxes"); hl(" of the label. (One point, or pt, equals to 1/72.27 inch.)"); hl(" -s, --edgeseparation "); hl(" Insert extra space of typographic points between the text boxes"); hl(" at the folded edges of the label. This is useful when, for example,"); hl(" thick paper is used. By changing the line thickness, the internal"); hl(" margins of the label are also changed, since the inner edge-to-edge"); hl(" distance between the lines of the inner and outer boxes are linked"); hl(" to be twice the value of the line thickness. The correction of"); hl(" inner bounding boxes of the label text is automatically adjusted so"); hl(" as to ensure that the overall outer dimensions of the label are"); hl(" unchanged."); hl(" -c, --compile"); hl(" Try to compile the generated TeX code. This requires DVIPS to be"); hl(" installed on your system, see www.radicaleye.com for further info."); hl(" -e, --eps"); hl(" When compiling the generated TeX code, generate Encapsulated"); hl(" PostScript (EPS) instead of the default regular PostScript."); hl(" -d, --dvipsopts "); hl(" When compiling the generated TeX code, use as options to be"); hl(" supplied to DVIPS. In order to parse for an arbitrary number of"); hl(" DVIPS options at the command line, it is important to enclose the"); hl(" list of DVIPS options by quotes. Hence, for example, to force DVIPS"); hl(" to generate output pages of US letter format and at a resolution of"); hl(" 720 dpi one could invoke DVLABEL with"); hl(" dvlabel --dvipsopts \"-tletter -D720\""); hl(" The quotes are only necessary if the number of DVIPS options are"); hl(" two or more. Default: -D1200 -ta4 (1200 DPI on A4 paper)."); hl(" -v, --verbose"); hl(" Toggle verbose mode. Default: off"); hl(" -h, --help"); hl(" Display this help message and exit clean."); hl("\nCopyright (C) 2003-2011 Fredrik Jonsson "); } /*:9*/ #line 490 "./dvlabel.w" /*11:*/ #line 628 "./dvlabel.w" short newlabel(FILE*instream){ char ch; fprintf(stdout,"Create new label record or quit?\n"); fprintf(stdout,"['n'=new label / 'q'=quit]:\n"); fprintf(stdout,"**"); while((ch= fgetc(instream))==' '); if(ch=='n'){ while((ch= fgetc(instream))!='\n'); return(1); }else if(ch=='q'){ while((ch= fgetc(instream))!='\n'); return(0); }else{ log("%s: Error: Unrecognized input stream control character '%c'.\n", progname,ch); exit(FAILURE); } } /*:11*/ #line 491 "./dvlabel.w" /*12:*/ #line 660 "./dvlabel.w" /*13:*/ #line 674 "./dvlabel.w" short pathcharacter(int ch){ return(isalnum(ch)||(ch=='.')||(ch=='/')||(ch=='\\')||(ch=='_')|| (ch=='-')||(ch=='+')); } /*:13*/ #line 661 "./dvlabel.w" char*strip_away_path(char filename[]){ int j,k= 0; while(pathcharacter(filename[k]))k++; j= (--k); while(isalnum((int)(filename[j])))j--; j++; return(&filename[j]); } /*:12*/ #line 492 "./dvlabel.w" /*:7*/ #line 436 "./dvlabel.w" int main(int argc,char*argv[]) { /*14:*/ #line 685 "./dvlabel.w" time_t now= time(NULL); long j,k,n,num_address_lines,num_toc_lines,num_labels,num_labels_per_page= 4; int no_arg,tmpch; FILE*infile= NULL,*outfile= NULL; char inputfilename[MAXCHAR]= "",outputfilename[MAXCHAR]= "",tmpstr[MAXCHAR]; char dvipsopts[MAXCHAR]= DEFAULT_DVIPSOPTS; char timestamp[MAXCHAR]= "\today",title[MAXCHAR]= ""; char author[MAXCHAR]= "",email[MAXCHAR]= ""; char address[10*MAXCHAR]= "",toc[50*MAXCHAR]= ""; short done,verbose= 0,compile= 0,eps_output= 0; short headline= 1,generate_crop_marks= 1; short infile_specified= 0,outfile_specified= 0,dvipsopts_specified= 0; float linethickness= DEFAULT_LINETHICKNESS; float clthick= DEFAULT_CROPLINETHICKNESS; float edgeseparation= DEFAULT_EDGESEPARATION; float facewidth,faceheight,spineheight,flapheight; float ifacewidth,ifaceheight,ispineheight,iflapheight; /*:14*/ #line 440 "./dvlabel.w" /*15:*/ #line 711 "./dvlabel.w" { progname= strip_away_path(argv[0]); no_arg= argc; while(--argc){ if(!strcmp(argv[no_arg-argc],"-o")|| !strcmp(argv[no_arg-argc],"--outputfile")){ --argc; strcpy(outputfilename,argv[no_arg-argc]); outfile_specified= 1; }else if(!strcmp(argv[no_arg-argc],"-i")|| !strcmp(argv[no_arg-argc],"--inputfile")){ --argc; strcpy(inputfilename,argv[no_arg-argc]); infile_specified= 1; }else if(!strcmp(argv[no_arg-argc],"-v")|| !strcmp(argv[no_arg-argc],"--verbose")){ verbose= (verbose?0:1); }else if(!strcmp(argv[no_arg-argc],"-h")|| !strcmp(argv[no_arg-argc],"--help")){ showsomehelp(); exit(SUCCESS); }else if(!strcmp(argv[no_arg-argc],"-H")|| !strcmp(argv[no_arg-argc],"--headline")){ headline= (headline?0:1); }else if(!strcmp(argv[no_arg-argc],"-C")|| !strcmp(argv[no_arg-argc],"--cropmarks")){ generate_crop_marks= (generate_crop_marks?0:1); }else if(!strcmp(argv[no_arg-argc],"-t")|| !strcmp(argv[no_arg-argc],"--linethick")){ --argc; if(!sscanf(argv[no_arg-argc],"%f",&linethickness)){ log("Error in linethickness argument."); exit(1); } }else if(!strcmp(argv[no_arg-argc],"-s")|| !strcmp(argv[no_arg-argc],"--edgeseparation")){ --argc; if(!sscanf(argv[no_arg-argc],"%f",&edgeseparation)){ log("Error in edgeseparation argument."); exit(1); } }else if(!strcmp(argv[no_arg-argc],"-c")|| !strcmp(argv[no_arg-argc],"--compile")){ compile= (compile?0:1); }else if(!strcmp(argv[no_arg-argc],"-e")|| !strcmp(argv[no_arg-argc],"--eps")){ eps_output= (eps_output?0:1); }else if(!strcmp(argv[no_arg-argc],"-d")|| !strcmp(argv[no_arg-argc],"--dvipsopts")){ --argc; strcpy(dvipsopts,argv[no_arg-argc]); dvipsopts_specified= 1; }else{ log("Error: Unknown option '%s'.",argv[no_arg-argc]); showsomehelp(); exit(FAILURE); } } if(verbose&&!outfile_specified){ fprintf(stdout, "You have specified verbose mode without any specification of\n" "a file where to save the generated TeX source code. This means\n" "that any program comments that appear, due to the verbose mode,\n" "will be mixed with the source code. It is highly recommended that\n" "you either turn off verbose mode or specify a file where to save\n" "the generated output (using the -o or --outputfile option).\n"); fprintf(stdout, "In order to make a clean output, the TeX code is separately\n" "enclosed in the blocks below.\n"); } if(verbose&&dvipsopts_specified){ fprintf(stdout,"Specified options for later use with DVIPS: "); fprintf(stdout,"%s\n",dvipsopts); } } /*:15*/ #line 441 "./dvlabel.w" /*16:*/ #line 790 "./dvlabel.w" { fprintf(stdout,"This is %s, Version %s\n",progname,VERSION); } /*:16*/ #line 442 "./dvlabel.w" /*18:*/ #line 808 "./dvlabel.w" { if(infile_specified){ if((infile= fopen(inputfilename,"r"))==NULL){ if((infile= fopen(strcat(inputfilename,".dvl"),"r"))==NULL){ log("Could not open file %s for reading!",inputfilename); exit(FAILURE); } } fseek(infile,0L,SEEK_SET); if(verbose){ log("Opened input file %s for reading.",inputfilename); } }else{ if(verbose) log("No input filename specified (Entering interactive mode)."); } } /*:18*/ #line 443 "./dvlabel.w" /*19:*/ #line 829 "./dvlabel.w" { if(outfile_specified){ sprintf(tmpstr,"%s.tex",outputfilename); if((outfile= fopen(tmpstr,"w"))==NULL){ log("Could not open file %s for writing!",tmpstr); exit(FAILURE); } fseek(outfile,0L,SEEK_SET); if(verbose){ log("Opened output file %s for writing.",outputfilename); } }else{ if(verbose){ log("No output filename specified."); log("Will write generated TeX output to standard terminal output."); } } } /*:19*/ #line 444 "./dvlabel.w" /*29:*/ #line 1075 "./dvlabel.w" { facewidth= 190.6+3.0*72.27/25.4; faceheight= 133.7; spineheight= 35.6; flapheight= 41.3; ifacewidth= facewidth-14.0*linethickness; ifaceheight= faceheight-11.0*linethickness-0.5*edgeseparation; ispineheight= spineheight-8.0*linethickness-edgeseparation; iflapheight= flapheight-11.0*linethickness-0.5*edgeseparation; if(!outfile_specified) fprintf(OUTSTREAM,"%%-------- TEX CODE BEGINS HERE -----------------\n"); fprintf(OUTSTREAM,"%% File: %s.tex\n",outputfilename); fprintf(OUTSTREAM,"%% TeX code generated by %s, v.%s, %s", progname,VERSION,ctime(&now)); fprintf(OUTSTREAM,"%% Copyright (C) Fredrik Jonsson, 2003-2005\n%%\n"); fprintf(OUTSTREAM,"\\hoffset=-35pt\\voffset=-25pt\n"); fprintf(OUTSTREAM,"\\hsize=175mm\\vsize=254mm\n"); fprintf(OUTSTREAM,"\\font\\eightcmssqeight=cmssq8\n"); fprintf(OUTSTREAM,"\\font\\sevencmtt=cmtt7\n"); fprintf(OUTSTREAM,"\\font\\tencmssqten=cmssq8 at 10 truept\n"); fprintf(OUTSTREAM,"\\font\\deffacefont=cmr7\n"); fprintf(OUTSTREAM,"\\font\\deftimestampfont=cmtt8 at 7 truept\n"); fprintf(OUTSTREAM,"\\font\\defspinefont=cmr9\n"); fprintf(OUTSTREAM,"\\font\\defflapfont=cmr7\n"); fprintf(OUTSTREAM,"\\def\\monthname{\\ifcase\\month%%\n"); fprintf(OUTSTREAM," \\or Jan\\or Feb\\or Mar\\or Apr\\or May\\or Jun%%\n"); fprintf(OUTSTREAM," \\or Jul\\or Aug\\or Sep\\or Oct\\or Nov\\or Dec%%\n"); fprintf(OUTSTREAM," \\fi}\n"); fprintf(OUTSTREAM,"\\def\\fullmonthname{\\ifcase\\month%%\n"); fprintf(OUTSTREAM," \\or January\\or February\\or March\\or April%%\n"); fprintf(OUTSTREAM," \\or May\\or June\\or July\\or August\\or September\n"); fprintf(OUTSTREAM," \\or October\\or November\\or December\\fi}\n"); fprintf(OUTSTREAM,"\\def\\today{\\fullmonthname\\space\\number\\day,%%\n"); fprintf(OUTSTREAM," \\space\\number\\year}\n"); fprintf(OUTSTREAM,"\\def\\dvby{Digital Video by\\ }\n"); fprintf(OUTSTREAM,"\\parindent 0pt\n"); fprintf(OUTSTREAM,"\\newdimen\\facewidth\n"); fprintf(OUTSTREAM,"\\newdimen\\faceheight\n"); fprintf(OUTSTREAM,"\\newdimen\\spineheight\n"); fprintf(OUTSTREAM,"\\newdimen\\flapheight\n"); fprintf(OUTSTREAM,"\\newdimen\\linethick\n"); fprintf(OUTSTREAM,"\\newdimen\\spacethick\n"); fprintf(OUTSTREAM,"\\newdimen\\edgeseparation\n"); fprintf(OUTSTREAM,"\\newdimen\\cropthick\n"); fprintf(OUTSTREAM,"\\facewidth=%1.3fpt\n",facewidth); fprintf(OUTSTREAM,"\\faceheight=%1.3fpt\n",faceheight); fprintf(OUTSTREAM,"\\spineheight=%1.3fpt\n",spineheight); fprintf(OUTSTREAM,"\\flapheight=%1.3fpt\n",flapheight); fprintf(OUTSTREAM,"\\linethick=%1.3fpt\n",linethickness); fprintf(OUTSTREAM,"\\spacethick=%1.3fpt\n",2.0*linethickness); fprintf(OUTSTREAM,"\\edgeseparation=%1.3fpt\n",edgeseparation); fprintf(OUTSTREAM,"\\cropthick=%1.3fpt\n",clthick); if(headline){ fprintf(OUTSTREAM,"\\headline={\\hfill{\\tt dvlabel output"); fprintf(OUTSTREAM," %s",ctime(&now)); fprintf(OUTSTREAM," [%s]}}\n",(infile_specified?inputfilename:"stdin")); fprintf(OUTSTREAM,"\\footline={\\hfill\\folio\\hfill}\n"); }else{ fprintf(OUTSTREAM,"\\headline={\\hfil}\n"); fprintf(OUTSTREAM,"\\nopagenumbers\n"); } fprintf(OUTSTREAM,"\\def\\boxit#1{\\vbox{\\hrule height\\linethick%%\n"); fprintf(OUTSTREAM," \\hbox{\\vrule width\\linethick\\kern\\spacethick%%\n"); fprintf(OUTSTREAM," \\vbox{\\kern\\spacethick#1\\kern\\spacethick}%%\n"); fprintf(OUTSTREAM," \\kern\\spacethick\\vrule width\\linethick}%%\n"); fprintf(OUTSTREAM," \\hrule height\\linethick}}%%\n"); } /*:29*/ #line 445 "./dvlabel.w" num_labels= 0; while(newlabel(INSTREAM)){ num_labels++; /*22:*/ #line 876 "./dvlabel.w" { /*23:*/ #line 893 "./dvlabel.w" { fprintf(stdout,"Specify table of contents of the DV tape\n"); fprintf(stdout,"[Enter text and finish with single dot on blank line]:\n"); done= 0; n= 0; num_toc_lines= 0; while(!done){ fprintf(stdout,"**"); while((tmpch= fgetc(INSTREAM))==' '); ungetc(tmpch,INSTREAM); k= 0; while((tmpstr[k++]= fgetc(INSTREAM))!='\n'); if(k> 1){ if((tmpstr[0]=='.')&&(tmpstr[1]=='\n')){ done= 1; }else{ for(j= 0;j 1) for(j= 0;j 1) for(j= 0;j 1) for(j= 0;j 1){ if((tmpstr[0]=='.')&&(tmpstr[1]=='\n')){ done= 1; }else{ for(j= 0;j 1) for(j= 0;j