/* This returns a MALLOCED string */ char *SLpath_dircat (SLFUTURE_CONST char *dir, SLFUTURE_CONST char *name) { unsigned int len, dirlen; char *file; #ifndef VMS int requires_fixup; #endif if (name == NULL) name = ""; if ((dir == NULL) #if !TEST_VMS_ON_UNIX || (SLpath_is_absolute_path (name)) #endif ) dir = ""; /* Both VMS and MSDOS have default directories associated with each drive. * That is, the meaning of something like C:X depends upon more than just * the syntax of the string. Since this concept has more power under VMS * it will be honored here. However, I am going to treat C:X as C:\X * under MSDOS. * * Note!!! * VMS has problems of its own regarding path names, so I am simply * going to strcat. Hopefully the VMS RTL is smart enough to deal with * the result. */ dirlen = strlen (dir); #ifndef VMS # if TEST_VMS_ON_UNIX requires_fixup = 0; # else requires_fixup = (dirlen && (0 == IS_PATH_SEP(dir[dirlen - 1]))); # endif #endif len = dirlen + strlen (name) + 2; if (NULL == (file = (char *)SLmalloc (len))) return NULL; strcpy (file, dir); #ifndef VMS if (requires_fixup) file[dirlen++] = PATH_SEP; #endif strcpy (file + dirlen, name); #if defined(IBMPC_SYSTEM) convert_slashes (file); #endif #if TEST_VMS_ON_UNIX || defined (VMS) return vms_fixup_filename (file); #else return file; #endif }
/* * Return a string with ~ and ~user expanded via getpw*. If buf != NULL, * then it is a newly allocated string. Returns NULL on getpw failure or * if path is NULL. */ char *expand_user_path(const char *path) { struct strbuf user_path = STRBUF_INIT; const char *to_copy = path; if (path == NULL) goto return_null; if (path[0] == '~') { const char *first_slash = strchrnul(path, '/'); const char *username = path + 1; size_t username_len = first_slash - username; if (username_len == 0) { const char *home = getenv("HOME"); if (!home) goto return_null; strbuf_addstr(&user_path, home); #ifdef GIT_WINDOWS_NATIVE convert_slashes(user_path.buf); #endif } else { struct passwd *pw = getpw_str(username, username_len); if (!pw) goto return_null; strbuf_addstr(&user_path, pw->pw_dir); } to_copy = first_slash; } strbuf_addstr(&user_path, to_copy); return strbuf_detach(&user_path, NULL); return_null: strbuf_release(&user_path); return NULL; }
char *SLpath_getcwd (void) { char cwd[4096]; char *p; size_t len; #ifndef HAVE_GETCWD p = getwd (cwd); #else # if defined (__EMX__) p = _getcwd2(cwd, sizeof(cwd)); /* includes drive specifier */ # else p = getcwd(cwd, sizeof(cwd)); /* djggp includes drive specifier */ # endif #endif if (p == NULL) return NULL; #ifdef IBMPC_SYSTEM convert_slashes (cwd); #endif len = strlen (cwd); p = (char *) SLmalloc (len+2); /* \0 + trailing / */ if (p == NULL) { #ifdef ENOMEM errno = ENOMEM; #endif return NULL; } strcpy (p, cwd); #ifndef VMS if (len && (p[len-1] != PATH_SEP)) { p[len++] = PATH_SEP; p[len] = 0; } #endif return p; }
int create_file_names_for_track (_main_data * main_data, int track, char **wfp, char **efp) { static char *buffer; int rc; char *conv_str = NULL; GtkWidget *main_window = main_window_handler(MW_REQUEST_MW, NULL, NULL); rc = parse_rx_format_string (&buffer, ((char *) config_read (CONF_CDDB_FORMATSTR)), track, main_data->disc_artist, main_data->disc_title, main_data->disc_year, main_data->track[track].title); if (rc < 0) { err_handler (GTK_WINDOW(main_window), RX_PARSING_ERR, _ ("Check if the filename format string contains format characters other than %a %# %v %y or %s.")); return 0; } if (buffer[0] == 0) strcpy (buffer, main_data->track[track].title); conv_str = g_locale_from_utf8 (buffer, -1, NULL, NULL, NULL); remove_non_unix_chars (conv_str); convert_slashes (conv_str, '-'); if ((int) config_read (CONF_GNRL_CONVSPC)) { convert_spaces (conv_str, '_'); } if (wfp) mk_strcat (wfp, wd, conv_str, wfext, NULL); if (efp) mk_strcat (efp, ed, conv_str, ecfext, NULL); g_free (conv_str); return 1; }
/* * Unlike prefix_path, this should be used if the named file does * not have to interact with index entry; i.e. name of a random file * on the filesystem. */ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg) { static struct strbuf path = STRBUF_INIT; #ifndef GIT_WINDOWS_NATIVE if (!pfx_len || is_absolute_path(arg)) return arg; strbuf_reset(&path); strbuf_add(&path, pfx, pfx_len); strbuf_addstr(&path, arg); #else /* don't add prefix to absolute paths, but still replace '\' by '/' */ strbuf_reset(&path); if (is_absolute_path(arg)) pfx_len = 0; else if (pfx_len) strbuf_add(&path, pfx, pfx_len); strbuf_addstr(&path, arg); convert_slashes(path.buf + pfx_len); #endif return path.buf; }
int exists_path(struct IncludesCollection *incCollection, char *path) { convert_slashes(path); return call_IncludesCollection_exists(incCollection, path); }
int cddb_handle_data (const char *data, char **artist, char **dtitle, char *titles[], int *totaltracks, char **year, char **dgenre) { char *row, *mark; const char *tmp = data; int i, j, counter = 0, track, previoustrack = 100, ttcounter = 0; char *tempstr; if (strncmp (data, "# xmcd", 6) != 0) return -1; (*dtitle) = NULL; while (*tmp != 0) { /* check against end of string */ /* get the row */ i = strcspn (tmp, "\r\n"); while (tmp[i] == '\r' || tmp[i] == '\n') i++; row = (char *) malloc (i + 1); strncpy (row, tmp, i); row[i] = 0; tmp += i; /* eval the row */ if (strncmp (row, "DYEAR", 5) == 0) { /* CD Year */ tempstr = malloc (MAX_YEAR_LENGTH); strcpy (tempstr, row); tempstr = strchr (row, '='); tempstr++; j = strlen (tempstr); (*year) = (char *) malloc (j + 1); strncpy ((*year), tempstr, (j + 1)); remove_non_unix_chars (*year); } else if (strncmp (row, "DGENRE", 6) == 0) { /* Disc Genre */ tempstr = malloc (MAX_GENRE_LENGTH); strcpy (tempstr, row); tempstr = strchr (row, '='); tempstr++; j = strlen (tempstr); (*dgenre) = (char *) malloc (j + 1); strncpy ((*dgenre), tempstr, (j + 1)); remove_non_unix_chars (*dgenre); } else if (strncmp (row, "TTITLE", 6) == 0) { /* Track Title */ /* get the track number before going on */ /* skip the TTITLE */ mark = row + 6; counter = 0; /* convert ascii -> int */ while (*mark != '=') { counter *= 10; counter += *mark - 0x30; mark++; } mark++; /* and skip the '=' */ track = counter; if (previoustrack != track) ttcounter++; /* create the filename. Append previous title if necessary */ tempstr = malloc (MAX_TITLE_LENGTH); if (previoustrack == track) strcpy (tempstr, titles[track]); else strcpy (tempstr, ""); /* put in the track name */ titles[track] = strcat (tempstr, mark); strip_trailing_space (&titles[track]); strip_leading_space (&titles[track]); previoustrack = track; remove_non_unix_chars (titles[track]); #ifdef DEBUG printf ("Track %d: %s\n", track, titles[track]); #endif } else if ((strncmp (row, "DTITLE", 6) == 0) && (*dtitle == NULL)) { /* CD Title */ i = strcspn (row, "="); i++; /* skip to the data */ mark = row + i; // tm: hack around bogus CDDB entries if (strstr (mark, " / ")) { j = strstr (mark, " / ") - mark + 1; (*artist) = (char *) malloc (j + 1); strncpy ((*artist), mark, j); (*artist)[j] = 0; (*dtitle) = (char *) malloc (strlen (mark) - j); mark = mark + j + 1; strcpy ((*dtitle), mark); } else { #ifdef DEBUG printf ("malformed DTITLE, copying full DTITLE into both artist and dtitle\n"); #endif j = strlen (mark); (*artist) = (char *) malloc (j + 1); strncpy ((*artist), mark, j); (*artist)[j] = 0; (*dtitle) = (char *) malloc (j + 1); strncpy ((*dtitle), mark, j); (*dtitle)[j] = 0; } strip_trailing_space (artist); strip_leading_space (artist); strip_trailing_space (dtitle); strip_leading_space (dtitle); remove_non_unix_chars (*artist); remove_non_unix_chars (*dtitle); convert_slashes (*artist, '_'); // dc: _ Artist, - others convert_slashes (*dtitle, '-'); #ifdef CONVERT_SPACES_IN_ID3_DATA if (((int) config_read (CONF_CDDB_CONVSPC)) == TRUE) { convert_spaces (*artist, '_'); convert_spaces (*dtitle, '_'); } #endif #ifdef DEBUG printf ("Artist: %s\n", (*artist)); printf ("Dtitle: %s\n", (*dtitle)); #endif } /* ignore any other results */ free (row); } *totaltracks = ttcounter; return 0; }
int ImportFederalReturnData( char *fedlogfile, struct FedReturnData *fed_data ) { FILE *infile; char fline[1000], word[1000]; int linenum; for (linenum=0; linenum<MAX_LINES; linenum++) { fed_data->fedline[linenum] = 0.0; fed_data->schedA[linenum] = 0.0; fed_data->schedD[linenum] = 0.0; } convert_slashes( fedlogfile ); infile = fopen(fedlogfile, "r"); if (infile==0) { printf("Error: Could not open Federal return '%s'\n", fedlogfile); fprintf(outfile,"Error: Could not open Federal return '%s'\n", fedlogfile); return 0; } fed_data->Itemized = 1; /* Set initial default values. */ read_line(infile,fline); linenum = 0; while (!feof(infile)) { if (strstr(fline,"Use standard deduction.")!=0) fed_data->Itemized = 0; next_word(fline, word, " \t="); if ((strstr(word,"L")==word) && (strstr(fline," = ")!=0)) { if (strcmp(word,"L9b") != 0) { if (sscanf(&word[1],"%d",&linenum)!=1) { printf("Error: Reading Fed line number '%s%s'\n",word,fline); fprintf(outfile,"Error: Reading Fed line number '%s%s'\n",word,fline); } next_word(fline, word, " \t="); if (sscanf(word,"%lf", &fed_data->fedline[linenum])!=1) { printf("Error: Reading Fed line %d '%s%s'\n",linenum,word,fline); fprintf(outfile,"Error: Reading Fed line %d '%s%s'\n",linenum,word,fline); } if (verbose) printf("FedLin[%d] = %2.2f\n", linenum, fed_data->fedline[linenum]); } } else if ((strstr(word,"A")==word) && (strstr(word,"AMT")!=word) && (strstr(fline," = ")!=0)) { if (sscanf(&word[1],"%d",&linenum)!=1) { printf("Error: Reading Fed line number '%s%s'\n",word,fline); fprintf(outfile,"Error: Reading Fed line number '%s%s'\n",word,fline); } next_word(fline, word, " \t="); if (sscanf(word,"%lf", &fed_data->schedA[linenum])!=1) { printf("Error: Reading Fed schedA %d '%s%s'\n",linenum,word,fline); fprintf(outfile, "Error: Reading Fed schedA %d '%s%s'\n",linenum,word,fline); } if (verbose) printf("FedLin[%d] = %2.2f\n", linenum, fed_data->schedA[linenum]); } else if ((strstr(word,"D")==word) && (strstr(fline," = ")!=0)) { if (sscanf(&word[1],"%d",&linenum)!=1) { printf("Error: Reading Fed line number '%s%s'\n",word,fline); fprintf(outfile,"Error: Reading Fed line number '%s%s'\n",word,fline); } next_word(fline, word, " \t="); if (strcmp(word,"d") == 0) { /*Basis,Sale,Gain line. Capture last value.*/ next_word(fline, word, " \teh=" ); while (word[0] != '\0') { if (sscanf(word,"%lf", &fed_data->schedD[linenum]) != 1) fprintf(outfile,"Error: Reading Fed schedD %d '%s %s'\n", linenum, word, fline); next_word(fline, word, " \teh=" ); } } else if (sscanf(word,"%lf", &fed_data->schedD[linenum]) != 1) { if (strncasecmp(word,"yes",1) == 0) fed_data->schedD[linenum] = 1; else if (strncasecmp(word,"no",1) == 0) fed_data->schedD[linenum] = 0; else { printf("Error: Reading fed schedD %d '%s%s'\n", linenum, word, fline); fprintf(outfile,"Error: Reading Fed schedD %d '%s%s'\n", linenum, word, fline); } } if (verbose) printf("FedLin[%d] = %2.2f\n", linenum, fed_data->schedD[linenum]); } else if (strcmp(word,"Status") == 0) { next_word(fline, word, " \t="); if (strncasecmp(word,"Single",4)==0) status = SINGLE; else if (strncasecmp(word,"Married/Joint",13)==0) status = MARRIED_FILLING_JOINTLY; else if (strncasecmp(word,"Married/Sep",11)==0) status = MARRIED_FILLING_SEPARAT; else if (strncasecmp(word,"Head_of_House",4)==0) status = HEAD_OF_HOUSEHOLD; else if (strncasecmp(word,"Widow",4)==0) status = WIDOW; else { printf("Error: unrecognized status '%s'. Exiting.\n", word); fprintf(outfile,"Error: unrecognized status '%s'. Exiting.\n", word); return 0; } } read_line(infile,fline); } fclose(infile); return 1; }
int main(int a_c, char **a_v) { int ok = 1; sort_field_t sort_field = SORT_BY_NAME_TIME; { int opt; while (ok && (opt = getopt(a_c, a_v, "htUSn")) != -1) { switch(opt) { case 'h': usage(); ok = 0; break; case 'U': sort_field = SORT_UNSORTED; break; case 't': sort_field = SORT_BY_TIME; break; case 'S': sort_field = SORT_BY_SIZE; break; case 'n': sort_field = SORT_BY_NAME; break; case 'N': sort_field = SORT_BY_NAME_TIME; break; default: ok = 0; } } } if(ok) { puppy_t p = puppy_open(NULL); if(puppy_ok(p)) { char *dir = convert_slashes(a_c > optind ? a_v[optind] : ""); const char *glob = a_c > optind + 1 ? a_v[optind + 1] : "*"; puppy_dir_entry_t *entries = puppy_hdd_dir(p, dir); puppy_dir_entry_t *ptr = entries; int num_entries = 0; int c; while(ptr->name[0]) { ++num_entries; ++ptr; } sort_dir_entries(entries, num_entries, sort_field); for(c = 0; c < num_entries; ++c) { puppy_dir_entry_t *entry = entries + c; if(fnmatch(glob, entry->name, 0) == 0) { char tmStr[1024]; struct tm tm = *localtime(&entry->time); strftime(tmStr, sizeof(tmStr), "%Y-%m-%d %H:%M:%S", &tm); printf("%s %12lld %s\n", tmStr, entry->size, entry->name); } } free(entries); free(dir); } else { fprintf(stderr, "Failed to initialize puppy\n"); } puppy_done(p); } return 0; }