bool convertTGA (char * filename) { char * oldName = joinStrings (filename, ""); filename[strlen (filename) - 3] = 's'; filename[strlen (filename) - 2] = 'l'; filename[strlen (filename) - 1] = getDither() ? '2' : 'x'; int i, j; if (newerFile (oldName, filename)) { backdrop32 = false; setCompilerText (COMPILER_TXT_ITEM, "Compressing image"); i = loadBackDropForCompiler (oldName); if (! i) return false; if (backdrop32) { j = savePNG (filename, HORZ_RES, VERT_RES, backDrop32Image); delete backDrop32Image; if (! j) return false; } else { j = saveHSI (filename); for (int a = 0; a < VERT_RES; a ++) delete backDropImage[a]; delete backDropImage; if (! j) return false; } setCompilerText (COMPILER_TXT_ITEM, ""); } delete oldName; return true; }
static LC_StringArray_t buildManList(char *suffix, char *name) { static char buffer1[FILENAME_MAX]; static char buffer2[FILENAME_MAX]; DIR *directory; struct dirent *entry; LC_StringArray_t list1, list2; size_t len; int i, j, k; char *p, *fn, *L1, *L2; /* initialization */ list1 = LC_StringArrayNew(); list2 = LC_StringArrayNew(); #ifdef DEBUG /* sanity check on arguments */ if(MAX(strlen(manstr),strlen(catstr)) + strlen(suffix) >= FILENAME_MAX) { fprintf(stderr,"internal error: buffer overflow at line %d of %s\n", __LINE__,__FILE__); } #endif /* * look in man subdirectory */ strcpy(buffer1,manstr); strcat(buffer1,suffix); if ((directory = opendir(buffer1)) != NULL) { while ((entry = readdir(directory)) != (struct dirent *) NULL) { /* skip if no match */ len = strlen(name); if (strncasecmp(entry->d_name,name,len) || (entry->d_name[len] != '.')) continue; if (strlen(manstr) + strlen(suffix) + strlen(entry->d_name) + strlen(suffix) + 1 >= FILENAME_MAX) { errx(1, "internal error: buffer overflow at line %s:%d\n", __FILE__, __LINE__); } sprintf(buffer1,"%s%s:%s",manstr,suffix,entry->d_name); /* look for "links" to aroff files. (what a kludge) */ if ((buffer1[3] != 'l') && (strcasecmp(".l",&buffer1[strlen(buffer1)-2])==0)) { FILE *linkptr; char *tp; /* dereference the "link" */ if ((linkptr = fopen(buffer1,"r")) == NULL) { fprintf(stderr,"couldn't open %s\n",buffer1); } else if (fgets(buffer2,FILENAME_MAX,linkptr)==NULL) { fprintf(stderr,"couldn't read %s\n",buffer1); } else { /* drop trailing space and newline */ tp = buffer2 + strlen(buffer2) -1; while ((tp>=buffer2) && (isspace(*tp) || *tp == '\n')) { *tp = '\0'; tp--; } fclose(linkptr); if (access(buffer2,R_OK) == 0) { LC_StringArrayAdd(list1, buffer2); } } } else { /* not a .l "link"; a normal file */ LC_StringArrayAdd(list1, buffer1); } } closedir(directory); } if (!t_flag) { /* * look in cat subdirectory */ strcpy(buffer1,catstr); strcat(buffer1,suffix); if ((directory = opendir(buffer1)) != NULL) { while ((entry = readdir(directory)) != (struct dirent *) NULL) { /* skip if no match */ len = strlen(name); if (strncasecmp(entry->d_name,name,len) || (entry->d_name[len] != '.')) continue; if (strlen(catstr) + strlen(suffix) + strlen(entry->d_name) + strlen(suffix) + 1 >= FILENAME_MAX) { fprintf(stderr,"internal error: buffer overflow at line %d of %s\n", __LINE__,__FILE__); } sprintf(buffer1,"%s%s:%s",catstr,suffix,entry->d_name); LC_StringArrayAdd(list2, buffer1); } closedir(directory); } } /* * eliminate files common to both lists */ len = strlen(suffix); for(i=0; i< list1->lc_used; i++) { L1 = (list1->lc_vec)[i]; for (j=0; j< list2->lc_used; j++) { L2 = (list2->lc_vec)[j]; getBaseName(buffer1, L1); getBaseName(buffer2, L2); #ifdef DEBUG if ((strlen(buffer1) < len + 5) || (strlen(buffer2) < len + 5)) { err(1, "internal error at line %d of %s\n", __LINE__, __FILE__); } #endif /* match after the respective "manXX/" and "catXX/" */ if (strcasecmp(&buffer1[len+4],&buffer2[len+4]) == 0 ) { p = newerFile(L1,L2); if (p == L1) { LC_StringArrayDelete(list2, L2); --j; } else if (p == (list2->lc_vec)[j]) { LC_StringArrayDelete(list1, L1); --i; break; } else { err(1, "internal error at %s:%d (newerFile failed)", __FILE__, __LINE__); } } /* endif */ } /* endfor */ } /* endfor */ /* * combine the two lists */ j = list2->lc_used; for (i=0; i<j; i++) { LC_StringArrayAdd(list1, (list2->lc_vec)[i]); } LC_StringArrayDestroy(list2); return list1; }