void add_file(char *filename) { char buff[PATH_MAX]; FILE *f; char *ptr; char *p2; int count = 0; if (strcmp(filename, "-") == 0) { f = stdin; } else { f = fopen(filename, "r"); if (f == NULL) { #ifdef USE_LIBSCHILY comerr("Cannot open '%s'.\n", filename); #else perror("fopen"); exit(1); #endif } } while (fgets(buff, sizeof (buff), f)) { count++; ptr = buff; while (isspace(*ptr)) ptr++; if (*ptr == 0) continue; if (*ptr == '#') continue; if (ptr[strlen(ptr) - 1] == '\n') ptr[strlen(ptr) - 1] = 0; p2 = strchr(ptr, '='); if (p2 == NULL) { #ifdef USE_LIBSCHILY comerrno(EX_BAD, "Error in file '%s' line %d: %s\n", filename, count, buff); #else fprintf(stderr, "Error in file '%s' line %d: %s\n", filename, count, buff); exit(1); #endif } *p2 = 0; p2++; add_one_file(ptr, p2); } if (f != stdin) fclose(f); }
/* * Function: add_file_list * * Purpose: Register an add-in file. * * Arguments: */ void add_file_list(int argc, char **argv, int ind) { char *ptr; char *dup_arg; while (ind < argc) { dup_arg = strdup(argv[ind]); ptr = strchr(dup_arg, '='); if (ptr == NULL) { free(dup_arg); return; } *ptr = 0; ptr++; add_one_file(dup_arg, ptr); free(dup_arg); ind++; } }
/* ** Add all files in the sfile temp table. ** ** Automatically exclude the repository file. */ static int add_files_in_sfile(int vid, int caseSensitive){ const char *zRepo; /* Name of the repository database file */ int nAdd = 0; /* Number of files added */ int i; /* Loop counter */ const char *zReserved; /* Name of a reserved file */ Blob repoName; /* Treename of the repository */ Stmt loop; /* SQL to loop over all files to add */ int (*xCmp)(const char*,const char*); if( !file_tree_name(g.zRepositoryName, &repoName, 0) ){ blob_zero(&repoName); zRepo = ""; }else{ zRepo = blob_str(&repoName); } if( caseSensitive ){ xCmp = fossil_strcmp; }else{ xCmp = fossil_stricmp; db_multi_exec( "CREATE INDEX IF NOT EXISTS vfile_nocase" " ON vfile(pathname COLLATE nocase)" ); } db_prepare(&loop, "SELECT x FROM sfile ORDER BY x"); while( db_step(&loop)==SQLITE_ROW ){ const char *zToAdd = db_column_text(&loop, 0); if( fossil_strcmp(zToAdd, zRepo)==0 ) continue; for(i=0; (zReserved = fossil_reserved_name(i))!=0; i++){ if( xCmp(zToAdd, zReserved)==0 ) break; } if( zReserved ) continue; nAdd += add_one_file(zToAdd, vid, caseSensitive); } db_finalize(&loop); blob_reset(&repoName); return nAdd; }
int main(int argc, char **argv) { int ok = 0; FILE *fp = tmpfile(); if (fp != NULL) { int err = 0; int nfiles = 0; if (argc > 1) { int i; for (i=1; i<argc; ++i) { if (add_one_file(fp, argv[i])) ++nfiles; else { err = 1; break; } } } else { char filename[FILENAME_MAX+1]; while (fgets(filename, FILENAME_MAX+1, stdin)) { size_t len = strlen(filename); if (filename[len-1] == '\n') { filename[len-1] = 0; if (add_one_file(fp, filename)) ++nfiles; else { err = 1; break; } } else { fprintf(stderr, "timepng: truncated file name ...%s\n", filename+len-32); err = 1; break; } } if (ferror(stdin)) { fprintf(stderr, "timepng: stdin: read error\n"); err = 1; } } if (!err) { if (nfiles > 0) ok = perform_one_test(fp, nfiles); else fprintf(stderr, "usage: timepng {files} or ls files | timepng\n"); } (void)fclose(fp); } else fprintf(stderr, "timepng: could not open temporary file\n"); /* Exit code 0 on success. */ return ok == 0; }
void initramfs_to_fs() { printf("START add to initranfs\n"); current_addr = init_ref; while (add_one_file()); printf("FINISH add to initranfs\n"); }