static void addroute(struct session *ses, int a, int b, char *way, int dist, char *cond) { struct routenode *r; r=ses->routes[a]; while (r&&(r->dest!=b)) r=r->next; if (r) { SFREE(r->path); r->path=mystrdup(way); r->distance=dist; SFREE(r->cond); r->cond=mystrdup(cond); } else { r=TALLOC(struct routenode); r->dest=b; r->path=mystrdup(way); r->distance=dist; r->cond=mystrdup(cond); r->next=ses->routes[a]; ses->routes[a]=r; } }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_syment * * Purpose: Reclaim the space of the given syment. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 5, 1996 12:05 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_rl_syment (syment *ep) { SFREE(PD_entry_type(ep)); SFREE(PD_entry_blocks(ep)); SFREE(ep); }
/*------------------------------------------------------------------------- * Function: lite_SC_rl_hash_table * * Purpose: Release a hash table. Call SC_HASH_CLR first to * release the contents of the table. * * Return: void * * Programmer: Adapted from PACT SCORE * Mar 12, 1996 * * Modifications: * *------------------------------------------------------------------------- */ void lite_SC_rl_hash_table (HASHTAB *tab) { lite_SC_hash_clr(tab); SFREE(tab->table); SFREE(tab); }
int fetchannotations(void) { int afirst = 1, i; WFDB_Anninfo ai; WFDB_Time ta0, taf; if (nann < 1) return (0); if (tfreq != ffreq) { ta0 = (WFDB_Time)(t0*tfreq/ffreq + 0.5); taf = (WFDB_Time)(tf*tfreq/ffreq + 0.5); } else { ta0 = t0; taf = tf; } printf(" %c \"annotator\":\n [", nosig > 0 ? ' ' : '{'); setgvmode(WFDB_HIGHRES); for (i = 0; i < nann; i++) { ai.name = annotator[i]; ai.stat = WFDB_READ; if (annopen(recpath, &ai, 1) >= 0) { char *p; int first = 1; WFDB_Annotation annot; if (ta0 > 0L) iannsettime(ta0); if (!afirst) printf(","); else afirst = 0; printf("\n { \"name\": \"%s\",\n", annotator[i]); printf(" \"annotation\":\n"); printf(" ["); while ((getann(0, &annot) == 0) && (taf <= 0 || annot.time < taf)) { if (!first) printf(","); else first = 0; printf("\n { \"t\": %ld,\n", (long)(annot.time)); printf(" \"a\": %s,\n", p = strjson(annstr(annot.anntyp))); SFREE(p); printf(" \"s\": %d,\n", annot.subtyp); printf(" \"c\": %d,\n", annot.chan); printf(" \"n\": %d,\n", annot.num); if (annot.aux && *(annot.aux)) { printf(" \"x\": %s\n", p = strjson(annot.aux+1)); SFREE(p); } else printf(" \"x\": null\n"); printf(" }"); } printf("\n ]\n }"); } } printf("\n ]\n }\n"); return (1); }
void delete_Platform(Platform *self) { for(int i = 0; i < kPlatformInfoSize; ++i) SFREE(self->platform_info[i]); for(int i = 0; i < self->num_devices; ++i) delete_Device(self->devices[i]); SFREE(self); }
/* Function flushcal empties the calibration list. */ FVOID flushcal(void) { while (first_cle) { SFREE(first_cle->sigtype); SFREE(first_cle->units); this_cle = first_cle->next; SFREE(first_cle); first_cle = this_cle; } }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_standard * * Purpose: Release a data standard structure. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 4, 1996 1:01 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_rl_standard (data_standard *std) { if (lite_SC_arrlen(std) > 0) { SFREE(std->float_format); SFREE(std->float_order); SFREE(std->double_format); SFREE(std->double_order); SFREE(std); } }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_alignment * * Purpose: Release a data alignment structure. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 4, 1996 12:57 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_rl_alignment (data_alignment *align) { if (lite_SC_arrlen(align) > 0) { SFREE(align); } }
void pardiso_solve_as(double *b, ITG *neq){ char *env; ITG maxfct=1,mnum=1,mtype=11,phase=33,*perm=NULL,nrhs=1, msglvl=0,i,error=0; double *x=NULL; printf(" Solving the system of equations using the asymmetric pardiso solver\n"); iparmas[0]=0; /* pardiso_factor has been called befor, MKL_NUM_THREADS=nthread_mkl_as is set*/ printf(" number of threads =% d\n\n",nthread_mkl_as); NNEW(x,double,*neq); FORTRAN(pardiso,(ptas,&maxfct,&mnum,&mtype,&phase,neq,aupardisoas, pointersas,irowpardisoas,perm,&nrhs,iparmas,&msglvl, b,x,&error)); for(i=0;i<*neq;i++){b[i]=x[i];} SFREE(x); return; }
void pardiso_cleanup_as(ITG *neq){ ITG maxfct=1,mnum=1,mtype=11,phase=-1,*perm=NULL,nrhs=1, msglvl=0,error=0; double *b=NULL,*x=NULL; FORTRAN(pardiso,(ptas,&maxfct,&mnum,&mtype,&phase,neq,aupardisoas, pointersas,irowpardisoas,perm,&nrhs,iparmas,&msglvl, b,x,&error)); SFREE(irowpardisoas); SFREE(aupardisoas); SFREE(pointersas); return; }
char *str_uri_path(char *str_request) { char *str_return = NULL; // if the request is not long enough to have a URI then abort ERROR_CHECK(strlen(str_request) >= 5, "request too short to parse;"); // find uri start character char *ptr_uri; if (strncmp(str_request, "GET ", 4) == 0 ) { ptr_uri = str_request + 4; } else if (strncmp(str_request, "HEAD ", 5) == 0 || strncmp(str_request, "POST ", 5) == 0) { ptr_uri = str_request + 5; } else { ERROR("unknown request type"); } // return just the Request-URI char *ptr_uri_end = strstr(ptr_uri, " "); int int_uri_len = (int)(ptr_uri_end - ptr_uri); DEBUG("int_uri_len: %i", int_uri_len); ERROR_SALLOC(str_return, int_uri_len + 1); memcpy(str_return, ptr_uri, int_uri_len); str_return[int_uri_len] = '\0'; return str_return; error: SFREE(str_return); return NULL; }
void lwfail(char *error_message) { char *p = strjson(error_message); printf("{\n \"success\": false,\n \"error\": %s\n}\n", p); SFREE(p); }
void dblist(void) { char *next, *wfdb = getwfdb(); int first = 1; while (*wfdb) { /* Isolate the next component of the WFDB path. */ for (next = wfdb; *next && next - wfdb < MFNLEN - 6; next++) if (*next == ' ') { *next++ = '\0'; break; } /* Look for a "DBS" file in the next possible location. */ sprintf(wfdb_filename, "%s/DBS", wfdb); if ((ifile = wfdb_fopen(wfdb_filename, "rb")) != NULL) { if (first) printf("{ \"database\": [\n"); while (wfdb_fgets(buf, sizeof(buf), ifile)) { char *p, *name, *desc; for (p = buf; p < buf + sizeof(buf) && *p != '\t'; p++) ; if (*p != '\t') continue; *p++ = '\0'; while (p < buf + sizeof(buf) - 1 && *p == '\t') p++; p[strlen(p)-1] = '\0'; if (!first) printf(",\n"); else first = 0; name = strjson(buf); desc = strjson(p); printf(" { \"name\": %s,\n \"desc\": %s\n }", name, desc); SFREE(desc); SFREE(name); } wfdb_fclose(ifile); first = 0; /* ensure that the database array will be closed in the output even if the DBS file was empty */ } wfdb = next; /* prepare to search the next location in the WFDB path */ } if (!first) { printf("\n ],\n"); printf(" \"version\": \"%s\",\n", LWVER); lwpass(); } else { lwfail("The list of databases could not be read"); } }
void log_off(struct session *ses) { fclose(ses->logfile); ses->logfile = NULL; SFREE(ses->logname); ses->logname = NULL; cleanup_conv(&ses->c_log); }
/* Expand command substitutions in VAR; needed if libcurl is included in LDFLAGS, so that we invoke the curl-config program rather than simply printing "`curl-config --libs`". */ static void expand_var(const char *var) { char *buffer; SUALLOC(buffer, strlen(var) + 6, 1); sprintf(buffer, "echo %s", var); system(buffer); SFREE(buffer); }
void _lite_PD_convert_attrtab (PDBfile *file) { int i, sz; defstr *dp; hashel *np, *prev; memdes *desc; struct ohashel { char *name; char *type; byte *def; struct ohashel *next; } *onp, *nxt, **otb; dp = PD_inquire_type(file, "hashel"); for (desc = dp->members; desc != 0; desc = desc->next) { if (strcmp(desc->member, "integer free") == 0) return; } sz = file->attrtab->size; otb = (struct ohashel **) file->attrtab->table; for (i = 0; i < sz; i++) { prev = NULL; for (onp = otb[i]; onp!= NULL; onp = nxt) { np = FMAKE(hashel, "_PD_CONVERT_ATTRTAB:np"); np->name = onp->name; np->type = onp->type; np->def = onp->def; #ifdef FIX_ME np->free = TRUE; #endif np->next = NULL; if (prev == NULL) otb[i] = (struct ohashel *) np; else prev->next = np; prev = np; nxt = onp->next; SFREE(onp); } } _lite_PD_rl_defstr(dp); lite_SC_hash_rem("hashel", file->host_chart); lite_SC_hash_rem("hashel", file->chart); dp = lite_PD_defstr(file, "hashel", "char *name", "char *type", "char *def", "integer free", "hashel *next", lite_LAST); if (dp == NULL) { lite_PD_error("COULDN'T DEFINE HASHEL - _PD_CONVERT_ATTRTAB", PD_OPEN); } lite_PD_cast(file, "hashel", "def", "type"); }
void kill_routes(struct session *ses) { for (int i=0;i<MAX_LOCATIONS;i++) { SFREE(ses->locations[i]); ses->locations[i]=0; struct routenode *r=ses->routes[i]; while (r) { struct routenode *p=r; r=r->next; SFREE(p->path); SFREE(p->cond); TFREE(p, struct routenode); } ses->routes[i]=0; } }
//take a file list and convert it into json //int_remove_length is the number of characters to remove from each line //useful if your list is like: // /path/to/file1 // /path/to/file2 //and you want it like: // file1 // file2 char *file_list_to_json (char *str_content, int int_remove_length) { char *str_return = NULL; char *str_temp = NULL; char *str_temp_json = NULL; ERROR_NORESPONSE("int_remove_length: %d", int_remove_length); ERROR_CAT_CSTR(str_return, ""); char *ptr_content = str_content + int_remove_length + 1; // + 1 means remove / if (*(ptr_content - 1) == '\n') { //if we are at a newline, //then the first line must be the full length to remove, so skip that line ptr_content = ptr_content + int_remove_length + 1; // + 1 means remove \n } int int_length; int int_done = 1; char *ptr_end_content = str_content + strlen(str_content); while (int_done > 0) { if (ptr_content <= ptr_end_content && strchr(ptr_content, '\n') != 0) { int_length = (strchr(ptr_content, '\n') - ptr_content); if (int_length > 0) { ERROR_SALLOC(str_temp, int_length + 1); memcpy(str_temp, ptr_content, int_length); str_temp[int_length] = 0; str_temp_json = jsonify(str_temp); SFREE(str_temp); if (strlen(str_return) > 0) { ERROR_CAT_APPEND(str_return, ",", str_temp_json); } else { ERROR_CAT_APPEND(str_return, str_temp_json); } ERROR_NORESPONSE(">%s|%s|%s<", str_return, str_temp_json, ptr_content); SFREE(str_temp_json); } ptr_content = strchr(ptr_content, '\n') + int_remove_length + 1 + 1; // + 1 means remove \n // + 1 means remove / } else { int_done = 0; } } return str_return; error: SFREE(str_temp); SFREE(str_temp_json); SFREE(str_return); return NULL; }
int btree_init(BTreePtr btree, FILE* fp) { ssize_t nbytes = 0; void* buf = NULL; buf = ALLOC(512); assert(buf != NULL); // First, init the fork record for future calls. btree->fp = fp; // Now load up the header node. if ( (nbytes = fpread(btree->fp, buf, sizeof(BTNodeDescriptor), 0)) < 0 ) { SFREE(buf); return -1; } btree->nodeDescriptor = *(BTNodeDescriptor*)buf; swap_BTNodeDescriptor(&btree->nodeDescriptor); // If there's a header record, we'll likely want that as well. if (btree->nodeDescriptor.numRecords > 0) { memset(buf, 0, 512); if ( (nbytes = fpread(btree->fp, buf, sizeof(BTHeaderRec), sizeof(BTNodeDescriptor))) < 0 ) { SFREE(buf); return -1; } btree->headerRecord = *(BTHeaderRec*)buf; swap_BTHeaderRec(&btree->headerRecord); // Next comes 128 bytes of "user" space for record 2 that we don't care about. // TODO: Then the remainder of the node is allocation bitmap data for record 3 which we'll care about later. } // Init the node cache. cache_init(&btree->nodeCache, 100); SFREE(buf); return 0; }
/*------------------------------------------------------------------------- * Function: _lite_PD_clr_table * * Purpose: Release the storage associated with a homogeneous hash * table. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 5, 1996 1:36 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_clr_table (HASHTAB *tab, FreeFuncType rel) { int i, n; hashel **tb, *hp, *nxt; n = tab->size; tb = tab->table; for (i = 0; i < n; i++) { for (hp = tb[i]; hp != NULL; hp = nxt) { nxt = hp->next; SFREE(hp->name); if (rel != NULL) (*rel)(hp->def); SFREE(hp); } tb[i] = NULL; } lite_SC_rl_hash_table(tab); }
void unroute_command(const char *arg, struct session *ses) { char a[BUFFER_SIZE], b[BUFFER_SIZE]; bool found=false; arg=get_arg(arg, a, 0, ses); arg=get_arg(arg, b, 1, ses); if ((!*a)||(!*b)) { tintin_eprintf(ses, "#SYNTAX: #unroute <from> <to>"); return; } for (int i=0;i<MAX_LOCATIONS;i++) if (ses->locations[i]&&match(a, ses->locations[i])) for (struct routenode**r=&ses->routes[i];*r;) { if (match(b, ses->locations[(*r)->dest])) { struct routenode *p=*r; if (ses->mesvar[MSG_ROUTE]) { tintin_printf(ses, "#Ok. There is no longer a route from {%s~-1~} to {%s~-1~}.", ses->locations[i], ses->locations[p->dest]); } found=true; *r=(*r)->next; SFREE(p->path); SFREE(p->cond); TFREE(p, struct routenode); } else r=&((*r)->next); } if (found) kill_unused_locations(ses); else if (ses->mesvar[MSG_ROUTE]) tintin_printf(ses, "#THAT ROUTE (%s) IS NOT DEFINED.", b); }
char *str_cookie(char *str_request, char *str_cookie_name) { char *str_return = NULL; DEFINE_VAR_ALL(str_full_cookie); DEBUG("str_cookie 1"); ERROR_CAT_CSTR(str_full_cookie, str_cookie_name, "="); DEBUG("str_cookie 2"); // find the cookie char *ptr_cookie = strstr(str_request, "Cookie:"); WARN_CHECK(ptr_cookie != NULL, "no cookie found"); ptr_cookie = strstr(ptr_cookie, str_full_cookie); WARN_CHECK(ptr_cookie != NULL, "no cookie found"); ptr_cookie = ptr_cookie + strlen(str_full_cookie); // advance cursor past "postage=" SFREE(str_full_cookie); DEBUG("str_cookie 3"); // get cookie length char *ptr_cookie_end_return = strstr(ptr_cookie, "\r\n"); char *ptr_cookie_end_semi = strstr(ptr_cookie, ";"); int int_cookie_len; DEBUG("str_cookie 4"); if (ptr_cookie_end_return == NULL && ptr_cookie_end_semi == NULL) { int_cookie_len = strlen(ptr_cookie); } else if (ptr_cookie_end_return != NULL && ptr_cookie_end_semi == NULL) { int_cookie_len = ptr_cookie_end_return - ptr_cookie; } else if (ptr_cookie_end_return == NULL && ptr_cookie_end_semi != NULL) { int_cookie_len = ptr_cookie_end_semi - ptr_cookie; } else { int_cookie_len = (ptr_cookie_end_return < ptr_cookie_end_semi) ? ptr_cookie_end_return - ptr_cookie : ptr_cookie_end_semi - ptr_cookie; } DEBUG("str_cookie 5"); // return just the postage cookie ERROR_SALLOC(str_return, int_cookie_len + 1); memcpy(str_return, ptr_cookie, int_cookie_len); str_return[int_cookie_len] = '\0'; DEBUG("str_cookie 6"); SFREE_PWORD_ALL(); return str_return; error: SFREE_PWORD_ALL(); SFREE_PWORD(str_return); return NULL; }
int main(void) { // read data from stdin // read data count TYPE count = 0; if(scanf("%d\n", &count) != 1 && count <= 0) { DEBUG_PRINT_STATE; DEBUG_PRINT_STRING("can not get right data count.\n"); DEBUG_PRINT_VALUE("%d", count); fflush(stdout); assert(0); exit(EXIT_FAILURE); } TYPE* array = SCALLOC(count, TYPE); // read data to array // get first value TYPE temp; if(scanf("%d\n", &temp) != 1) { DEBUG_PRINT_STATE; DEBUG_PRINT_STRING("can not get data.\n"); DEBUG_PRINT_VALUE("%d", temp); fflush(stdout); assert(0); exit(EXIT_FAILURE); } // get difference value TYPE i; TYPE current; for(i = 0; i < count - 1; i++) { if(scanf("%d\n", ¤t) != 1) { DEBUG_PRINT_STATE; DEBUG_PRINT_STRING("can not get data.\n"); DEBUG_PRINT_VALUE("%d", i); DEBUG_PRINT_VALUE("%d", current); fflush(stdout); assert(0); exit(EXIT_FAILURE); } array[i] = current - temp; temp = current; DEBUG_PRINT_VALUE("%d", i); DEBUG_PRINT_VALUE("%d", array[i]); } count--; // get result in linear time struct subarray data_final; data_final = find_maximum_subarray(array, 0, count - 1); // output result printf("max different value = %d\n", data_final.sum_max); printf("index in array: %d to %d\n", data_final.index_begin, data_final.index_end + 1); SFREE(&array); return EXIT_SUCCESS; }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_defstr * * Purpose: Free up the storage associated with a defstr. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 5, 1996 3:18 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_rl_defstr (defstr *dp) { memdes *desc, *next; int *ord; long *frm; for (desc = dp->members; desc != NULL; desc = next) { next = desc->next; _lite_PD_rl_descriptor(desc); } ord = dp->order; if ((ord != NULL) && (lite_SC_arrlen(ord) > -1)) SFREE(ord); frm = dp->format; if ((frm != NULL) && (lite_SC_arrlen(frm) > -1)) SFREE(dp->format); SFREE(dp->type); SFREE(dp); }
/*------------------------------------------------------------------------- * Function: lite_SC_hash_clr * * Purpose: Clear the specified hash table. * * Return: void * * Programmer: Adapted from PACT SCORE * Mar 12, 1996 * * Modifications: * *------------------------------------------------------------------------- */ void lite_SC_hash_clr (HASHTAB *tab) { int i, sz; hashel **tb, *np, *nxt; sz = tab->size; tb = tab->table; for (i = 0; i < sz; i++) { for (np = tb[i]; np != NULL; np = nxt) { nxt = np->next; /* * Undo the MARK in SC_install. */ SFREE(np->def); SFREE(np->name); SFREE(np); } tb[i] = NULL; } }
void delete_ContextManager(ContextManager *self) { for(int i = 0; i < self->num_platforms; ++i) delete_Platform(self->platforms[i]); ContextManager_ShutdownQueues(self); for(int i = 0; i < self->num_threads; ++i) { pthread_join(self->threads[i], NULL); } delete_Queue(self->incoming_queue, true); delete_Queue(self->outgoing_queue, true); SFREE(self); }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_dimensions * * Purpose: Release a dimension descriptor. * * Return: void * * Programmer: Adapted from PACT PDB * Mar 5, 1996 3:19 PM EST * * Modifications: * *------------------------------------------------------------------------- */ void _lite_PD_rl_dimensions (dimdes *dims) { dimdes *pp, *nxt; int nc; for (pp = dims; pp != NULL; pp = nxt) { nxt = pp->next; nc = lite_SC_ref_count(pp); SFREE(pp); if (nc > 1) break; } }
/*------------------------------------------------------------------------- * Function: _lite_PD_rl_pdb * * Purpose: Release the storage associated with the PDBfile * * Return: void * * Programmer: Adapted from PACT PDB * Mar 5, 1996 12:03 PM EST * * Modifications: * Eric Brugger, Mon Dec 7 10:51:58 PST 1998 * Removed call to lite_PD_reset_ptr_list since it was removed. I * added a call to free current_prefix to close a memory leak. * *------------------------------------------------------------------------- */ void _lite_PD_rl_pdb (PDBfile *file) { SFREE(file->date); _lite_PD_rl_standard(file->std); _lite_PD_rl_standard(file->host_std); _lite_PD_rl_alignment(file->align); _lite_PD_rl_alignment(file->host_align); if (file->attrtab != NULL) _lite_PD_clr_table(file->attrtab, NULL); _lite_PD_clr_table(file->host_chart,(FreeFuncType)_lite_PD_rl_defstr); _lite_PD_clr_table(file->chart,(FreeFuncType)_lite_PD_rl_defstr); _lite_PD_clr_table(file->symtab,(FreeFuncType)_lite_PD_rl_syment_d); if (file->previous_file != NULL) SFREE(file->previous_file); if (file->current_prefix != NULL) SFREE(file->current_prefix); if (file->type != NULL) SFREE(file->type); if (lite_LAST != NULL) SFREE(lite_LAST); if (lite_PD_DEFSTR_S != NULL) SFREE(lite_PD_DEFSTR_S); lite_PD_DEFSTR_S = NULL; if (lite_PD_SYMENT_S != NULL) SFREE(lite_PD_SYMENT_S); lite_PD_SYMENT_S = NULL; if (lite_io_close_hook == (PFfclose) _lite_PD_pio_close) lite_io_close_hook = (PFfclose) fclose; if (lite_io_seek_hook == (PFfseek) _lite_PD_pio_seek) lite_io_seek_hook = (PFfseek) fseek; if (lite_io_printf_hook == (PFfprintf) _lite_PD_pio_printf) lite_io_printf_hook = (PFfprintf) fprintf; SFREE(file->name); SFREE(file); }
/*------------------------------------------------------------------------- * Function: lite_PD_cd * * Purpose: Change the current working directory. The directory * may be specified by an absolute or relative path. * * Return: Success: TRUE * * Failure: FALSE * * Programmer: Adapted from PACT PDB * Mar 4, 1996 11:41 AM EST * * Modifications: * *------------------------------------------------------------------------- */ int lite_PD_cd (PDBfile *file, char *dirname) { char name[MAXLINE]; syment *ep; lite_PD_err[0] = '\0'; if (file == NULL) { sprintf(lite_PD_err, "ERROR: BAD FILE ID - PD_CD\n"); return(FALSE); } if (dirname == NULL) { strcpy(name, "/"); } else { strcpy(name, _lite_PD_fixname(file, dirname)); if (name[strlen(name) - 1] != '/') strcat(name, "/"); } ep = lite_PD_inquire_entry(file, name, FALSE, NULL); if (ep == NULL) { if (dirname == NULL) { return(FALSE); } else { if (strcmp(name, "/") != 0) { name[strlen(name) - 1] = '\0'; ep = lite_PD_inquire_entry(file, name, FALSE, NULL); strcat(name, "/"); } if (ep == NULL) { sprintf(lite_PD_err, "ERROR: DIRECTORY %s NOT FOUND - PD_CD\n", dirname); return(FALSE); } } } if (strcmp(ep->type, "Directory") != 0) { sprintf(lite_PD_err, "ERROR: BAD DIRECTORY %s - PD_CD\n", dirname); return(FALSE); } else { if (file->current_prefix) SFREE(file->current_prefix); file->current_prefix = lite_SC_strsavef(name, "char*:PD_CD:name"); } return(TRUE); }
// Check path environment variable for a program char *where_is_program(char *str_program_name) { DEFINE_VAR_ALL(str_PATH, str_PATH2); char *str_return = NULL; ERROR_CAT_CSTR(str_PATH, getenv("PATH")); char *ptr_PATH = str_PATH; char *ptr_PATH_end = str_PATH + strlen(str_PATH); int int_next_colon; while (ptr_PATH < ptr_PATH_end) { //DEBUG("%s", ptr_PATH); int_next_colon = strcspn(ptr_PATH, ":"); ERROR_SALLOC(str_PATH2, int_next_colon + 2); memcpy(str_PATH2, ptr_PATH, int_next_colon); str_PATH2[int_next_colon] = '/'; str_PATH2[int_next_colon + 1] = '\0'; //DEBUG("%s", str_ptr_PATH); str_return = canonical(str_PATH2, str_program_name, "read_dir_or_file"); //"read_file"); SFREE(str_PATH2); if (str_return != NULL) { SFREE_ALL(); return str_return; } //DEBUG("%i", int_next_colon); ptr_PATH += int_next_colon + 1; } WARN("Could not find program: %s", str_program_name); //ERROR("Could not find program: %s", str_program_name); error: SFREE_ALL(); SFREE(str_return); return NULL; }