void wait_time (int *iper, int *iret) { int ier; unsigned waittime; set_sigs(); AVAL = 0; waittime = 60 * (*iper); printf("waiting %u seconds<ctrl-c to continue>\n",waittime); alarm(waittime); ier = pause(); *iret = AVAL; }
/*********************************************************************** ** POST_PRINT.C mainline. ** ***********************************************************************/ void main(int argc, char *argv[]) { int num_read, i; int one_shot; int pipe_in, pipe_out; int result; char tp_extend[18]; char *new_Psf_path_ptr; char *parse_buff_ptr; umask(0); set_sigs(); /* get all traces out at end */ p_init(0); lc_init(1); memset ( (char *)&ObjPageWn.page_number[0], 0, sizeof (struct obj_pg_wn) ); obj_wn_count = 0; one_shot = 0; Current_FgColor = 1; /* BUG 594q Initialize current color to black */ Current_FgShade = 100; /* BUG 594q Initialize current shade to 100% */ msg_parse_args(argc, argv, KEYWORD_COUNT, msg); pipe_in = atoi(msg[0].answer); pipe_out = atoi(msg[1].answer); if((pipe_in == 0) && (pipe_out ==0)) one_shot = 1; /* don't read from pipe */ p_info(PI_INFO, "Postprint Startup.\n"); /* log in first message. */ strcpy (overflow_path,"overflow.pos1"); /* Build name of overflow-text temp file, using ipc suffix.*/ bmtop = 0; /* Init dynamic PDF bookmark mem array. */ uidtop = 0; /* Init dynamic PDF bookmark-idrid mem array. */ /***************************** start of big loop ***************************/ for(;;) { if (p_LogFd) { fclose (p_LogFd); p_LogFd = NULL; } if (TrailerName) { fclose(TrailerName); TrailerName = NULL; } if (PrologName) { fclose(PrologName); PrologName = NULL; } p_LogCnt = 0; if (Fofd) p_close(Fofd); FoName[0] = 0; parse_buff = p_alloc(2048); if ( !m_fprintf_size) { m_fprintf_size = 4096; m_fprintf_buff = p_alloc(m_fprintf_size); } if( !one_shot) { /* read from the pipe */ num_read = read(pipe_in, parse_buff, 2048); switch (num_read) { case -1: p_info(PI_ELOG, "pipe read failed\n"); exit(1); case 0: p_info(PI_ELOG, "pipe_in EOF\n"); exit(1); default: break; } /* end switch(num_read) */ #ifdef TRACE if(debugger_trace) p_info(PI_TRACE, "pipe num_read= %d, '%s' \n",num_read,parse_buff); #endif msg_parse(parse_buff, num_read, KEYWORD_COUNT, msg); } /* end of pipe read */ else { /* read from arg & argv or from file */ if ((one_shot == 1) && !source_pfd) { if ( msg[44].answer[0]) { /* KEYWORD 'source', read from file */ one_shot = 2; if((source_pfd = p_open(NO_STRING, OTHER_FILE, NO_STRING, msg[44].answer, "r")) == 0) { p_info(PI_ELOG, "Failed to open source '%s'\n",msg[44].answer); exit(2); } } } if ( source_pfd) { /* get next job from source file */ if (p_fgets(parse_buff, 2048, source_pfd) == 0) { p_info(PI_ELOG, "source file empty\n"); exit(3); } parse_buff_ptr = parse_buff; while ( *parse_buff_ptr) { if ( *parse_buff_ptr == '\012') { *parse_buff_ptr = 0; break; } parse_buff_ptr++; } msg_parse (parse_buff, (int)(parse_buff_ptr - parse_buff + 1), KEYWORD_COUNT, msg); } } #if LPMfloat for (i = 0; i < LPM_MaxOption; i++) LPMK[i] = lpm_option(i); #else LPMK = lpm_query(LPM_Options,LPM_CurrRev); #endif result = job_setup(); p_free(parse_buff); if(result) { /* only if setting traces */ if(!one_shot) { if((num_read = write(pipe_out, "0", 2))== -1) { p_info(PI_ELOG, "write to pipe failed\n"); exit(1); } else continue; /* traces only, get next pipe message */ } exit(1); } strcpy(tpname, JobName); /* TP filename. */ if ( FileType) { /* layout */ tp_extend[0] = 0; if (MasterNameFlag) sprintf (tp_extend, ".%s", PageName); if ( LYPrintFlag) strcat (tp_extend, ".lyp"); strcat (tpname, tp_extend); if ( (FirstPage >= 0) && ( !MasterNameFlag) ) { if (LastPage != FirstPage) sprintf(tp_extend, ".%d_%d",FirstPage,LastPage); else /* if equal only use one page number */ sprintf(tp_extend, ".%d",FirstPage); strcat(tpname,tp_extend); } else if (BookPrint) { if (LastParentIndex > ParentIndex) sprintf(tp_extend, ".u%d_u%d",ParentIndex,LastParentIndex); else sprintf(tp_extend, ".u%d",ParentIndex); strcat(tpname,tp_extend); } } if (EpsFlag) strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname)); else if (BookPrint) strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname)); else strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname)); strcpy (prologname, logname); strcpy (trailername, logname); strcat (logname, ".log"); p_LogFd = fopen (logname, "w+"); strcat (prologname, ".plog"); PrologName = fopen(prologname, "w+"); strcat (trailername,".ptrl"); TrailerName = fopen(trailername, "w+"); new_Psf_path_ptr = p_path(TreeName, USERDATA, UserdataPath, PsfTableName); if ( strcmp( Psf_path_name, new_Psf_path_ptr) ) { /* no match, need a new name and Psftable */ strcpy(Psf_path_name, new_Psf_path_ptr); if ( !Psftable_load_with_name(TreeName, SubDirName, PsfTableName) ) { /* bad psftable load, abort */ p_info(PI_ELOG, "Unable to open file '%s'",Psf_path_name); exit(101); } PsfNameIndex = 0; PsfCodeIndex = 0; HelveticaFontNumber = 0; for (i=0; i<MaxPentaFont; i++) { /* find Helvetica */ if ( PentaToPsf[i].name) { if ( !strcmp(PentaToPsf[i].name, "Helvetica") ) HelveticaFontNumber = i; } } } /* psftable loaded */ if (HdrPNamPrt) get_prt_name(); /* Bug 367p get actual printer name from .psh file */ else PrtNam[0] = 0; getpgsize(); /* Parse header lines */ if(lnumbers & 1) { /* Print line numbers? */ if (!FileType) { /* In galley mode: */ OffL += 40; /* =15pts space at left + 25 for big line number */ if (LineStats) OffL += 30; /* =5pts at left + 25 line# + 40 for band & ls */ } else /* In page mode: */ OffL += 10; /* just 10 pts of room. */ } /*********************************************************************** ** Call the PostScript mainline processor. ** ***********************************************************************/ psmain(); /*********************************************************************** ** Wrap it all up. ** ***********************************************************************/ if (EpsFlag) strcpy (logname, p_path(TreeName, EPS_FILE, SubDirName, tpname)); else if (BookPrint) strcpy (logname, p_path(TreeName, OUTPUT_FILE, ParentDirName, tpname)); else strcpy (logname, p_path(TreeName, OUTPUT_FILE, SubDirName, tpname)); if (PrinterName[0]) { /* output to the printer queue */ fflush (p_LogFd); if( !GraphicsPresentFlag) result = 0; else result = 1; sprintf(shell_msg,"/usr/local/bin/%s.psh %s %d %d %s %s %d %d %d %d", PrinterName, logname, result, FileType, TreeName, SubDirName, FirstPage, LastPage, HNJ_LockFailureFlag, DistillFlag); system(shell_msg); } /* If user asked for "Distill to PDF" (and there's no H&J lock), then test to find the newest .tp, .eps or .ps in the .drawer, and see if it's newer than any .pdf file there. If so, this means the printer script did NOT create a .pdf, so distill the .tp to .pdf using ghostscript's ps2pdf script here. */ if (DistillFlag && !HNJ_LockFailureFlag) { struct stat tpstat, psstat, pdfstat; int tpind, psind, pdfind, buildpdf; char *dotptr; strcpy (prologname, logname); strcat (prologname, ".pdf"); /* Get stat of *.tp.pdf file: */ pdfind = stat(prologname, &pdfstat); if (pdfind) /* If that doesn't exit, alt try: */ { strcpy (prologname, logname); dotptr = strrchr (prologname, '.'); *dotptr = 0; /* Strip whatever suffix we have, */ strcat (prologname, ".pdf");/* replace with .pdf. */ /* Get stat of that pdf file: */ pdfind = stat(prologname, &pdfstat); } tpind = stat(logname, &tpstat); /* Get stat of .tp (or .eps) file */ psind = 1; /* (assume unused) */ if (!EpsFlag) /* If we started with .tp file, */ { /* also get stat of .ps file: */ strcpy (prologname, logname); strcpy (&prologname[strlen(logname)-3], ".ps"); psind = stat(prologname, &psstat); } buildpdf = 0; /* Assume no need to build a .pdf */ if (!tpind && /* If .tp (or .eps) exists, and */ (psind || /* .ps does not, or .tp is newer, then: */ tpstat.st_mtime > psstat.st_mtime)) { strcpy (prologname, logname); /* (use .tp name) */ /* if there's no .pdf or it's older, */ if (pdfind || tpstat.st_mtime > pdfstat.st_mtime) buildpdf = 1; /* set flag to distill the .tp file. */ } else if (!psind && /* If .ps exists, and */ (tpind || /* .tp does not, or .ps is newer, then: */ tpstat.st_mtime <= psstat.st_mtime)) { strcpy (logname, prologname); /* (use .ps name) */ /* if there's no .pdf or it's older, */ if (pdfind || psstat.st_mtime > pdfstat.st_mtime) buildpdf = 1; /* set flag to distill the .ps file. */ } else /* Neither exist, forget it. */ ; if (buildpdf) /* If we decided to distill a .pdf, then */ { /* build basename by stripping suffix, */ *(dotptr = strrchr (prologname, '.')) = 0; /* build little script calling ps2pdf, */ sprintf (shell_msg, "PATH=/usr/local/bin/ghostscript:$PATH; export PATH; ps2pdf %s %s.pdf", logname, prologname); p_info(PI_INFO, "Executing distillation to PDF from Postprint\n"); system(shell_msg); /* and send it off, wait for done. */ } } /* end if (DistillFlag && !HNJ_LockFailureFlag) */ p_free(m_fprintf_buff); m_fprintf_size = 0; if(!one_shot) { if((num_read =write(pipe_out, "0", 2))== -1) { p_info(PI_ERROR, "write to pipe failed\n"); exit(1); } else p_info(PI_INFO, "Post completed for %s \n",tpname); } else { if (!source_pfd) { p_info(PI_INFO, "Post completed for %s, program exit. \n",JobName); break; } else p_info(PI_INFO, "Post completed for %s \n",JobName); } } /* end of for(;;) */ exit(ExitError); } /* end of PSMAIN */