static void msg_reg_parse(json_t *jobj, struct message_registry *mr) { json_t *oem_json = NULL; json_t *mjobj = NULL; load_json_str_value(mr->name, MAX_NAME_SIZE, jobj, "Name"); load_json_str_value(mr->modified, MAX_MODIFIED_SIZE, jobj, "Modified"); load_json_str_value(mr->type, MAX_TYPE_SIZE, jobj, "Type"); load_json_str_value(mr->lang, MAX_LANGUAGE_SIZE, jobj, "Language"); load_json_str_value(mr->desc, MAX_DESCRIPTION_SIZE, jobj, "Description"); load_json_str_value(mr->prefix, MAX_PREFIX_SIZE, jobj, "RegistryPrefix"); load_json_str_value(mr->ver, MAX_VERSION_SIZE, jobj, "Version"); load_json_str_value(mr->entity, MAX_ENTITY_SIZE, jobj, "OwningEntity"); mjobj = json_object_get(jobj, "Messages"); if (mjobj == NULL){ printf("fail to get json Message field.\n"); return; } mr->msg_header = msg_parse(mjobj); oem_json = json_object_get(jobj, "Oem");; if (oem_json == NULL) { printf("fail to get json Oem field.\n"); return; } mr->oem_data = oem_parse(oem_json); }
static void msg_reg_parse(json_t *jobj, struct message_registry *mr) { json_t *oem_json = NULL; json_t *mjobj = NULL; load_json_str_value(mr->odata_context, MAX_NAME_SIZE, jobj, "@odata.context"); load_json_str_value(mr->odata_id, MAX_MODIFIED_SIZE, jobj, "@odata.id"); load_json_str_value(mr->odata_type, MAX_TYPE_SIZE, jobj, "@odata.type"); load_json_str_value(mr->lang, MAX_LANGUAGE_SIZE, jobj, "Language"); load_json_str_value(mr->prefix, MAX_PREFIX_SIZE, jobj, "RegistryPrefix"); load_json_str_value(mr->ver, MAX_VERSION_SIZE, jobj, "RegistryVersion"); load_json_str_value(mr->entity, MAX_ENTITY_SIZE, jobj, "OwningEntity"); mjobj = json_object_get(jobj, "Messages"); if (mjobj == NULL){ printf("fail to get json Message field.\n"); return; } mr->msg_header = msg_parse(mjobj); /* oem_json = json_object_get(jobj, "Oem");; if (oem_json == NULL) { printf("fail to get json Oem field.\n"); return; } mr->oem_data = oem_parse(oem_json); */ }
/** * Callback for networking core. */ int rtp_handle_packet ( void *object, const uint8_t *data, uint32_t length ) { RTPSession *session = object; RTPMessage *msg; if ( !session || length < 13 ) { /* 12 is the minimum length for rtp + desc. byte */ LOGGER_WARNING("No session or invalid length of received buffer!"); return -1; } msg = msg_parse ( data + 1, length - 1 ); if ( !msg ) { LOGGER_WARNING("Could not parse message!"); return -1; } /* Check if message came in late */ if ( check_late_message(session, msg) < 0 ) { /* Not late */ session->rsequnum = msg->header->sequnum; session->timestamp = msg->header->timestamp; } queue_message(session, msg); return 0; }
static int msg_recv(int fd, msg_t *m) { m->mode = M_FD; m->fd = fd; int r = msg_parse(m); if (r) return r; return 0; }
sip_msg_t * call_get_next_msg(sip_call_t *call, sip_msg_t *msg) { sip_msg_t *ret; pthread_mutex_lock(&call->lock); if (msg == NULL) { ret = call->msgs; } else { ret = msg_parse(msg->next); } pthread_mutex_unlock(&call->lock); return ret; }
static void test_imap_bodystructure_write(void) { struct message_part *parts; string_t *str = t_str_new(128); pool_t pool = pool_alloconly_create("imap bodystructure write", 1024); test_begin("imap bodystructure write"); parts = msg_parse(pool, TRUE); imap_bodystructure_write(parts, str, TRUE); test_assert(strcmp(str_c(str), testmsg_bodystructure) == 0); str_truncate(str, 0); imap_bodystructure_write(parts, str, FALSE); test_assert(strcmp(str_c(str), testmsg_body) == 0); pool_unref(&pool); test_end(); }
void call_add_message(sip_call_t *call, sip_msg_t *msg) { sip_msg_t *cur, *prev; pthread_mutex_lock(&call->lock); // Set the message owner msg->call = call; // XXX Put this msg at the end of the msg list // Order is important!!! if (!call->msgs) { call->msgs = msg_parse(msg); } else { for (cur = call->msgs; cur; prev = cur, cur = cur->next) ; prev->next = msg; } pthread_mutex_unlock(&call->lock); }
void init_color(void) { #define CLRBUFSZ 256 char clr_parse_buff[CLRBUFSZ]; char clr_parse_buff_temp[CLRBUFSZ]; char temp_name[128], temp_chap_dir[128]; char chap_tree[64]; char chap_dir[64]; char *result_ptr; float temp; int length, i; int plate_name_input; int temp_plate; int screen_found_flag; int plate_zero_stored = 0; int endflag = 0; int parent_flag = 0; memset((char *)&plate_nm[0].name[0], 0, sizeof(struct plate_name) * 33); clear_vlist(); /* clear list of reverses */ clear_color_list(); /* clear the non-standard colors */ strcpy(clr_parse_buff, SubDirName); if ((result_ptr = strrchr(clr_parse_buff, '.')) != NULL) *result_ptr = '\0'; colorfd = p_get_table1(TreeName, clr_parse_buff, ColorTableName, default_color_name); if (colorfd <= 0) { /* parent */ if(lc_parent(TreeName, SubDirName, temp_name)) { parent_flag++; p_parent_path(TreeName, clr_parse_buff, temp_name, chap_tree, chap_dir); strcpy(temp_chap_dir, chap_dir); if ((result_ptr = strrchr(temp_chap_dir, '.')) != NULL) *result_ptr = '\0'; colorfd = p_get_table1(chap_tree, temp_chap_dir, ColorTableName, default_color_name); } } if (colorfd <= 0) /* Tree/tables and .default/tables */ colorfd = p_get_table2(TreeName, clr_parse_buff, ColorTableName, default_color_name); if ( (colorfd <= 0) && strcmp(ColorTableName, "colortable") ) { /* try using colortable.ct */ strcpy (clr_parse_buff_temp, "colortable"); colorfd = p_get_table1(TreeName, clr_parse_buff, clr_parse_buff_temp, default_color_name); if (colorfd <= 0) { if ( parent_flag) colorfd = p_get_table1(chap_tree, temp_chap_dir, clr_parse_buff_temp, default_color_name); } if (colorfd <= 0) /* Tree/tables and .default/tables */ colorfd = p_get_table2(TreeName, clr_parse_buff, clr_parse_buff_temp, default_color_name); if (colorfd > 0) p_info(PI_WLOG, "Color table %s does not exist, using colortable.ct\n", ColorTableName); } if ( colorfd <= 0 ) { /* no colortable, use black and white */ colorfd = 0; store_white_and_black(); sprintf(default_color_name, "Penta/%s/%s/???.ct", DEFAULT_DIR, TABLES_DIR); p_info(PI_WLOG, "No color table exists, only colors 0 (white) and 1 (black) are valid.\n"); return; } spot_pass = 1; /* 1st pass */ cur_color_id = -1; while ( !endflag ) { memset(clr_parse_buff, 0, CLRBUFSZ); if ( p_fgets(clr_parse_buff, CLRBUFSZ, colorfd) != clr_parse_buff) endflag++; /* out of data */ if ( (length = strlen (clr_parse_buff)) < 5 ) continue; /* not long enough for a valid string */ /* OTOH, err if line fills buff completely: */ if ( length >= (CLRBUFSZ-1) ) { p_info(PI_WLOG, "WARNING: Color table '%s' line too long, ignored after %d:\n '%s'\n", ColorTableName, CLRBUFSZ, clr_parse_buff); do { /* Flush until EOL: */ *clr_parse_buff_temp = 0; if (p_fgets(clr_parse_buff_temp, CLRBUFSZ, colorfd) != clr_parse_buff_temp) endflag++; /* out of data */ } while (strlen(clr_parse_buff_temp) >= (CLRBUFSZ-1)); } if ( (clr_parse_buff[0] == '%') || (clr_parse_buff[0] == '!') || (clr_parse_buff[0] == '#') ) continue; /* skip command lines */ strcpy (clr_parse_buff_temp, clr_parse_buff); if ( !strncmp(clr_parse_buff, "AI_Sep", 6) ) continue; /* ignore Separation Key Words */ if ( !strncmp(clr_parse_buff, "CD_Sep", 6) ) continue; /* ignore Separation Key Words */ if ( !strncmp(clr_parse_buff, "G_FG_Color", 10) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "G_BG_Color", 10) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "G_BW_Overprint", 14) ) continue; /* ignore default graphic color Key Words */ if ( !strncmp(clr_parse_buff, "Plate_Name", 10) ) { /* Save Plate Name */ plate_name_input = atoi((char *)&clr_parse_buff[11]); if ( (plate_name_input < 0) || (plate_name_input > 32)) continue; /* no number */ memset((char *)&plate_nm[plate_name_input].name[0], 0, sizeof(struct plate_name)); /* p=(strstr((char *)&clr_parse_buff[11],"-")); p++; strncpy((char *)&plate_nm[plate_name_input], p, 30); */ strncpy((char *)&plate_nm[plate_name_input], (char *)&clr_parse_buff[11], 30); plate_nm[plate_name_input].name[30] = 0; if ( (result_ptr = strrchr((char *)&plate_nm[plate_name_input], '\n') ) ) *result_ptr = 0; /* null out the new line */ continue; } msg_parse(clr_parse_buff_temp, length, CLR_KEYWORD_COUNT, clr_msg); for (i=0; i<CLR_KEYWORD_COUNT; i++) { if ( clr_msg[i].answer[0] && (i != 72)) break; /* got an answer */ } if (i >= 11) continue; /* no valid message */ if (i == 0) { /* got a color id */ if ( (cur_color_id > 0) && !plate_zero_stored) { cur_plate = 0; store_color(0); /* store plate zero for prev color */ } plate_zero_stored = 0; cur_plate = -1; cur_screen = 72; cur_pct = 100; cur_tint = 100; strcpy(cur_shape, "dot"); cur_angle = 45.; cur_reverse = 0; cur_cmyk_flag = 0; strcpy(cur_op, "false"); strcpy(cur_color_name,""); strcpy(cur_type,"process"); for (i=0; i<4; i++) cur_cmyk[i] = 0.0; cur_color_id = atoi(clr_msg[0].answer); if (cur_color_id < 0) { cur_color_id = 0; p_info(PI_ELOG, "ERROR - Negative color '%s' is invalid.\n", clr_msg[0].answer); continue; } for (i=7; i<11; i++) { /* look for CMYK values */ if ( clr_msg[i].answer[0]) { temp = atof(clr_msg[i].answer); if ( (temp < 0.0 ) || (temp > 1.0) ) p_info(PI_ELOG, "ERROR - CMYK value on line '%s' does not lie between 0 and 1.0\n",clr_parse_buff); else { #if LPMfloat if(LPMK[LPM_ColorMaster]) #else if((LPMK & LPM_ColorMaster)) #endif { cur_cmyk[i-7] = temp; cur_cmyk_flag = 1; } } } } /* end for(i=7;i<11;i++) */ if ( clr_msg[6].answer[0]) { /* got a Tint */ cur_tint = atoi(clr_msg[6].answer); if ( (cur_tint <= 0) || (cur_tint > 100) ) { cur_tint = 100; p_info(PI_ELOG, "ERROR - color Tint must be above 0, below 100;\n"); p_info(PI_ELOG, " '%s' is not valid. \n",clr_msg[6].answer); } } if ( clr_msg[45].answer[0]) /* got Overprint */ { strncpy(cur_op, clr_msg[45].answer, 5); *(cur_op+5) = 0; if ( strcmp(cur_op, "true") && strcmp(cur_op, "false")) { p_info(PI_ELOG, "ERROR - color op '%s' must be true or false, will use true.\n", cur_op); strcpy(cur_op, "true"); } } else strcpy(cur_op,"false"); if ( clr_msg[46].answer[0]) { strcpy(cur_type,(clr_msg[46].answer)); } else strcpy(cur_type,"process"); if ( clr_msg[47].answer[0]) { if (strlen(clr_msg[47].answer) > 31) { p_info(PI_ELOG, "ERROR - color name '%s' exceeds 31 characters.\n", clr_msg[47].answer); continue; } strcpy (cur_color_name,(clr_msg[47].answer)); } else strcpy(cur_color_name,""); continue; } /* end got a color id */ if ( cur_color_id < 0) { p_info(PI_ELOG, "ERROR - color id missing before line '%s' \n",clr_parse_buff); continue; } if (i == 1) { /* Plate being defined */ cur_plate = atoi(clr_msg[1].answer); if ( (cur_plate < 0) || (cur_plate >= MAX_CLRS) ) { p_info(PI_ELOG, "ERROR - Color '%d', Plate '%d' less than 0 or greater than 31 \n",cur_color_id,cur_plate); p_info(PI_ELOG, " Line in error reads '%s'\n",clr_parse_buff); cur_plate = -1; continue; } continue; } /* end define Plate */ if ( cur_plate < 0) { p_info(PI_ELOG, "ERROR - color Plate is missing before line '%s' \n", clr_parse_buff); continue; } screen_found_flag = 0; switch (i) { case 2: /* Shape */ if ( clr_msg[2].answer[0]) strcpy(cur_shape, clr_msg[2].answer); else { p_info(PI_ELOG, "ERROR - Shape '%s' is not supported.\n", clr_msg[2].answer); strcpy(cur_shape, "dot"); } case 3: /* Angle */ if ( clr_msg[3].answer[0]) cur_angle = atof(clr_msg[3].answer); /* got an Angle */ case 4: /* Screen */ if ( clr_msg[4].answer[0]) { /* got a Screen */ cur_screen = atoi(clr_msg[4].answer); if (cur_screen < 0) cur_screen = 6; } case 5: /* Percent */ if ( clr_msg[5].answer[0]) { /* got a Percent */ cur_pct = atof(clr_msg[5].answer); if ( (cur_pct < 0.0) || (cur_pct > 100.) ) { cur_pct = 0.0; p_info(PI_ELOG, "ERROR - color Percent must be between 0 and 100\n"); p_info(PI_ELOG, " '%s' is not valid. \n",clr_msg[5].answer); } } screen_found_flag++; /* set if any case 2 thru 6 found */ break; default: continue; } /* end switch (i) */ if (cur_plate && !plate_zero_stored && screen_found_flag) { /* store Plate 0 first */ temp_plate = cur_plate; cur_plate = 0; store_color(0); cur_plate = temp_plate; } if (screen_found_flag) { store_color(1); plate_zero_stored++; } } /* end while( !endflag ) */ p_close(colorfd); store_white_and_black(); cur_cmyk_flag = 0; cur_tint = 100; } /* end of init_color */
// For LDTs only: void repl_write_handle_multiop(cf_node node, msg* m) { uint8_t* ns_name; size_t ns_name_len; if (msg_get_buf(m, RW_FIELD_NAMESPACE, &ns_name, &ns_name_len, MSG_GET_DIRECT) != 0) { cf_warning(AS_RW, "handle_multiop: no namespace"); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } as_namespace* ns = as_namespace_get_bybuf(ns_name, ns_name_len); if (! ns) { cf_warning(AS_RW, "handle_multiop: invalid namespace"); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } cf_digest* keyd; size_t sz; if (msg_get_buf(m, RW_FIELD_DIGEST, (uint8_t**)&keyd, &sz, MSG_GET_DIRECT) != 0) { cf_warning(AS_RW, "handle_multiop: no digest"); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } // Note - there should be an RW_FIELD_INFO with LDT bit set, but not // bothering to get it here since we never use it. uint8_t* pickled_buf; size_t pickled_sz; if (msg_get_buf(m, RW_FIELD_MULTIOP, (uint8_t**)&pickled_buf, &pickled_sz, MSG_GET_DIRECT) != 0) { cf_warning(AS_RW, "handle_multiop: no buffer"); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } as_partition_reservation rsv; as_partition_reserve_migrate(ns, as_partition_getid(*keyd), &rsv, NULL); if (rsv.state == AS_PARTITION_STATE_ABSENT) { as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_CLUSTER_KEY_MISMATCH); return; } ldt_prole_info linfo; memset(&linfo, 1, sizeof(ldt_prole_info)); int offset = 0; while (true) { const uint8_t* buf = (const uint8_t*)(pickled_buf + offset); size_t sz = pickled_sz - offset; if (sz == 0) { break; } uint32_t op_msg_len = 0; msg_type op_msg_type = 0; if (msg_get_initial(&op_msg_len, &op_msg_type, buf, sz) != 0 || op_msg_type != M_TYPE_RW) { cf_warning(AS_RW, "handle_multiop: peek multiop msg failed"); as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } msg* op_msg = as_fabric_msg_get(op_msg_type); if (! op_msg) { cf_warning(AS_RW, "handle_multiop: can't get fabric msg"); as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } if (msg_parse(op_msg, buf, sz) != 0) { cf_warning(AS_RW, "handle_multiop: can't parse multiop msg"); as_fabric_msg_put(op_msg); as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } offset += op_msg_len; if (! handle_multiop_subop(node, op_msg, &rsv, &linfo)) { cf_warning(AS_RW, "handle_multiop: write_process_new failed"); as_fabric_msg_put(op_msg); as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_FAIL_UNKNOWN); return; } as_fabric_msg_put(op_msg); } as_partition_release(&rsv); send_multiop_ack(node, m, AS_PROTO_RESULT_OK); }
/*********************************************************************** ** 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 */