int GetFilename(const char *filename, const char *filepath, char *buf, const int BUFSIZE) { const char *c1, *c2; int found = 0; int lg; int flen = strlen(filename); if (filepath) { c1 = filepath; c2 = c1; while ((!found) && (c2 != NULL)) { c2 = strchr(c1, ';'); if (c2 == NULL) { snprintf(buf, BUFSIZE, "%s/%s", c1, filename); } else { lg = c2 - c1; if (lg + flen + 2 < BUFSIZE) { strncpy(buf, c1, lg); buf[lg] = '/'; strcpy(buf + lg + 1, filename); } else { buf[0] = '\0'; } } if (ulFileExists(buf)) { found = 1; } c1 = c2 + 1; } } else { strncpy(buf, filename, BUFSIZE); if (ulFileExists(buf)) { found = 1; } } if (!found) { printf("File %s not found\n", filename); printf("File Path was %s\n", filepath); return 0; } return 1; }
int grGetFilename(char *filename, char *filepath, char *buf) { char *c1, *c2; int found = 0; int lg; if (filepath) { c1 = filepath; c2 = c1; while ((!found) && (c2 != NULL)) { c2 = strchr(c1, ';'); if (c2 == NULL) { sprintf(buf, "%s/%s", c1, filename); } else { lg = c2 - c1; strncpy(buf, c1, lg); buf[lg] = '/'; strcpy(buf + lg + 1, filename); } if (ulFileExists(buf)) { found = 1; } c1 = c2 + 1; } } else { strcpy(buf, filename); if (ulFileExists(buf)) { found = 1; } } if (!found) { GfOut("File %s not found\n", filename); GfOut("File Path was %s\n", filepath); return 0; } return 1; }
void init_args(int argc, char **argv) { int c; /* int digit_optind = 0; */ while (1) { /* int this_option_optind = optind ? optind : 1; */ int option_index = 0; static struct option long_options[] = { {"help", 0, 0, 0} }; c = getopt_long (argc, argv, "f:o:p:s:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: switch (option_index) { case 0: usage(); exit(0); break; default: usage(); exit(1); } break; case 'f': InputFileName = strdup(optarg); break; case 'o': OutputFileName = strdup(optarg); break; case 'p': ParamFileName = strdup(optarg); break; case 's': SkinFileName = strdup(optarg); break; default: usage(); exit(1); } } if (!ulFileExists(InputFileName)) { InputFileName = "car.ac"; if (!ulFileExists(InputFileName)) { fprintf(stderr, "The Input AC3D file must be provided\n"); usage(); exit(1); } } if (OutputFileName == NULL) { OutputFileName = "car-out.ac"; } if (!ulFileExists(ParamFileName)) { ParamFileName = "texmapper.xml"; if (!ulFileExists(ParamFileName)) { fprintf(stderr, "The parameters file is mandatory\n"); usage(); exit(1); } } ParamHandle = GfParmReadFile(ParamFileName, GFPARM_RMODE_STD); if (ParamHandle == NULL) { fprintf(stderr, "The parameters file should not be empty\n"); usage(); exit(1); } if (SkinFileName == NULL) { SkinFileName = "skin.rgb"; } }