1 /* files.h -- filesystem routines 2 * $Id: files.h,v 1.1 2003/11/01 23:45:56 bitman Exp $ 3 * Copyright (C) 2000 Ryan Phillips <bitman@scn.org> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place Suite 330; Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef __FILES_H 21 #define __FILES_H 22 23 #include "structures/svector.h" 24 25 /* Copy flags */ 26 #define COPY_NOOVERWRITE 0 27 #define COPY_OVERWRITE 1 28 #define COPY_DISPLACE 2 29 30 /* Copy results */ 31 #define COPY_SUCCESS 0 /* Ok */ 32 #define COPY_EXISTS 1 /* Destination file already exists */ 33 #define COPY_BADSOURCE 2 /* Can't open source file */ 34 #define COPY_BADDEST 3 /* Can't open destination file */ 35 36 /* General file types */ 37 #define FTYPE_FILE 1 38 #define FTYPE_DIR 2 39 #define FTYPE_ALL 3 40 41 /* Types of slashes */ 42 #define SLASH_FORWARD 0 43 #define SLASH_BACK 1 44 45 #ifdef WIN32 46 #define SLASH_DEFAULT SLASH_BACK 47 #else 48 #define SLASH_DEFAULT SLASH_FORWARD 49 #endif 50 51 /* Displacement constants */ 52 #define DISPLACE_LEADER "~" 53 #define DISPLACE_SEPERATOR "?" 54 55 /* filetosvector() - loads a textfile into a new stringvector */ 56 stringvector filetosvector(char* filename, int wrapwidth, int editwidth); 57 58 /* svectortofile() - copies a stringvector into a file. sv is not changed */ 59 void svectortofile(stringvector * sv, char *filename); 60 61 /* readdirectorytosvector() - reads a directory listing into an svector */ 62 stringvector readdirectorytosvector(char * dir, char * extension, 63 int filetypes); 64 65 /* globtosvector() - put raw glob information in an svector */ 66 stringvector globtosvector(char * pattern, int filetypes); 67 68 /* globdirectorytosvector() - globs a directory listing into an svector */ 69 stringvector globdirectorytosvector(char * dir, char * pattern, int filetypes); 70 71 /* File access */ 72 int fileexists(char* filename); 73 int fileisdir(char* filename); 74 75 /* File copying */ 76 int copyfile(char* srcname, char* destname, int flags); 77 int copyfilebydir(char* srcdir, char* destdir, char* filename, int flags); 78 int copyfilepatternbydir(char* srcdir, char* destdir, char* pattern, int flags, stringvector* successlist); 79 80 /* Determine path of self from main's argv[0] */ 81 char* locateself(char* argv0); 82 83 /* Deduce filename or path from a file's full path */ 84 char* fileof(char* buffer, char* fullpath, int buflen); 85 char* pathof(char* buffer, char* fullpath, int buflen); 86 char* fullpath(char* path, char* file, int slashtype); 87 88 /* Change all the slashes in a pathname */ 89 char* reslash(char* pathname, int slashtype); 90 91 /* Run a program with given path and arguments in current directory */ 92 int run(char* path, char* program, char* args); 93 94 #endif 95