int forwards_get(int fd, struct expand *expand) { FILE *fp = NULL; char *line = NULL; size_t len; size_t lineno; size_t save; int ret; struct stat sb; ret = -1; if (fstat(fd, &sb) == -1) goto end; /* if it's empty just pretend that no expansion took place */ if (sb.st_size == 0) { log_info("info: forward file is empty"); ret = 0; goto end; } /* over MAX_FORWARD_SIZE, temporarily fail */ if (sb.st_size >= MAX_FORWARD_SIZE) { log_info("info: forward file exceeds max size"); goto end; } if ((fp = fdopen(fd, "r")) == NULL) { log_warn("warn: fdopen failure in forwards_get()"); goto end; } lineno = 0; save = expand->nb_nodes; while ((line = fparseln(fp, &len, &lineno, NULL, 0)) != NULL) { if (! expand_line(expand, line, 0)) { log_info("info: parse error in forward file"); goto end; } if (expand->nb_nodes > MAX_EXPAND_NODES) { log_info("info: forward file expanded too many nodes"); goto end; } free(line); } ret = expand->nb_nodes > save ? 1 : 0; end: if (line) free(line); if (fp) fclose(fp); else close(fd); return ret; }
int get_var(char *name, char *buffer) { char *cp,*cp2; struct var_node *p; char tmp[100]; for (p=first_var;p && strcmp(p->name,name);p=p->next); if (p) { expand_line(p->subst,buffer); return 1; } else { buffer[0]=0; return 0; } }
PRIVATE void get_scaled_row( double **src, int y, int new_width, double *row, W8 *src_tmp, W8 *srcPR, int old_width, int old_height, int bytes ) { /* get the necesary lines from the source image, scale them, and put them into src[] */ rotate_pointers( (unsigned char **)src, 4 ); if( y < 0 ) { y = 0; } if( y < old_height ) { get_premultiplied_double_row( srcPR, bytes, 0, y, old_width, row, src_tmp, 1 ); if( new_width > old_width ) { expand_line( src[3], row, bytes, old_width, new_width ); } else if( old_width > new_width ) { shrink_line( src[3], row, bytes, old_width, new_width ); } else /* no scailing needed */ { memcpy( src[3], row, sizeof( double ) * new_width * bytes ); } } else { memcpy( src[3], src[2], sizeof( double ) * new_width * bytes ); } }
void process_line(char *st, FILE *fp) { char word[100],*wp,*ws,skip,rd; expand_line(st,z); st=z; if (get_word(&st,word)) { if (!strcmp(word,"INCLUDE")) { if (!get_word(&st,word)) { fprintf(stderr,"expecting filename after INCLUDE on line %d\n",line_on); exit(1); } process_file(word); } else if (!strcmp(word,"SECTION")) { skip=0; rd=0; wp=st; do { while (*wp==' ') wp++; ws=wp; if (*wp==0) skip=1; else { while (*wp!=' ' && *wp) wp++; *wp=0; if (!strcmp(ws,plat_name[detect_platform()])) rd=1; } } while (!skip && !rd); do { fgets(word,100,fp); while (word[strlen(word)-1]=='\n' || word[strlen(word)-1]=='\r') word[strlen(word)-1]=0; strcat(word,"\n"); if (rd) { if (strcmp(word,"END\n")) { if (plat_stuff) { plat_stuff=realloc(plat_stuff,strlen(plat_stuff)+1+strlen(word)); strcat(plat_stuff,word); } else { plat_stuff=malloc(strlen(plat_stuff)+1+strlen(word)); strcpy(plat_stuff,word); } } } } while (strcmp(word,"END\n")); } else { get_equal(&st); store_var(word,st); } } }