[go: up one dir, main page]

Menu

[082fcc]: / rename.h  Maximize  Restore  History

Download this file

164 lines (129 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Copyright (C) 1998-2011 "Andy Xuming" <xuming@users.sourceforge.net>
This file is part of RENAME, a utility to help file renaming
RENAME is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RENAME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _RENAME_H_
#define _RENAME_H_
#include <regex.h>
#include "libcsoup.h"
#define RENAME_MOD_CORE SLOG_MODUL_ENUM(3)
#define RENAME_MOD_GUI SLOG_MODUL_ENUM(4)
#define RNM_ERR_NONE 0
#define RNM_ERR_SKIP 1
#define RNM_ERR_EVENT 2
#define RNM_ERR_HELP -1
#define RNM_ERR_PARAM -2 /* wrong (command line) parameters */
#define RNM_ERR_GETDIR -3 /* can not get directory name */
#define RNM_ERR_EUID -4 /* invalid user id */
#define RNM_ERR_LOWMEM -5 /* low memory */
#define RNM_ERR_REGPAT -6 /* wrong regex pattern */
#define RNM_ERR_STAT -7 /* failed to stat of the file */
#define RNM_ERR_CHDIR -8
#define RNM_ERR_OPENDIR -9
#define RNM_ERR_LONGPATH -10 /* path name is too long */
#define RNM_ERR_OPENFILE -11
#define RNM_ERR_OVERFLOW -12
#define RNM_ERR_RENAME -13
#define RNM_ERR_IGNORE -14
#define RNM_CFLAG_NONE 0
#define RNM_CFLAG_NEVER 1 /* say no to all existed files */
#define RNM_CFLAG_ALWAYS 2 /* say yes to all existed files */
#define RNM_CFLAG_PROMPT_MASK 3
#define RNM_CFLAG_RECUR 0x100 /* recursive operation */
#define RNM_CFLAG_VERBOSE 0x200 /* verbose mode */
#define RNM_CFLAG_TEST 0x400 /* test mode only */
#define RNM_CFLAG_GUI 0x800 /* GUI mode */
#define RNM_OFLAG_NONE 0 /* do not change output filename */
#define RNM_OFLAG_LOWERCASE 1 /* lowercase the output filename */
#define RNM_OFLAG_UPPERCASE 2 /* uppercase the output filename */
#define RNM_OFLAG_MASKCASE 3
#define RNM_OFLAG_PREFIX 4 /* append a prefix */
#define RNM_OFLAG_SUFFIX 8 /* append a suffix */
#define RNM_ACT_NONE 0
#define RNM_ACT_FORWARD 1 /* search and substitute simplely */
#define RNM_ACT_BACKWARD 2 /* search and substitute backwardly */
#define RNM_ACT_REGEX 3 /* enable regular expression */
#define RNM_ACT_EXTENSION 6 /* search and replace extension name*/
#define RNM_REP_OK 0
#define RNM_REP_SKIP 1
#define RNM_REP_TEST 2
#define RNM_REP_FAILED 3
#define RNM_REP_CHOWN 4
#define RNM_MSG_ENTER_DIR 1
#define RNM_MSG_LEAVE_DIR 2
#define RNM_MSG_ACT_FORWARD 3
#define RNM_MSG_ACT_BACKWARD 4
#define RNM_MSG_ACT_REGEX 5
#define RNM_MSG_ACT_SUFFIX 6
#define RNM_MSG_PPRO_PREFIX 7
#define RNM_MSG_PPRO_SUFFIX 8
#define RNM_MSG_PPRO_LOWCASE 9
#define RNM_MSG_PPRO_UPCASE 10
#define RNM_MSG_SKIP_EXISTED 11
#define RNM_MSG_OVERWRITE 12
#define RNM_MSG_PROMPT 13
#define RNM_MSG_SIMULATION 14
#define RNM_MSG_SYS_FAIL 15
#define RNM_MSG_RENAME 16
/* PATH_MAX and MAX_PATH are all not quite reliable. Currently the NTFS
* seems having the longest path limit of 32768 utf-16 */
#define RNM_PATH_MAX 65536
/* define the maximum accepted patterns */
#define RNM_PTTN_MAX 8
typedef struct {
int oflags;
int cflags;
int action;
char *patbuf; /* buffer for patterns */
regex_t preg[RNM_PTTN_MAX]; /* buffer for regular expression */
int regflag;
char *pattern[RNM_PTTN_MAX]; /* pattern for search */
int pa_len[RNM_PTTN_MAX];
char *substit[RNM_PTTN_MAX]; /* substitution string */
int su_len[RNM_PTTN_MAX];
char *prefix; /* prefix to file name */
int pre_len;
char *suffix; /* suffix to file name */
int suf_len;
int rpnum; /* replace occurance number*/
int rpfrom; /* replace from which occurance */
/* runtime area */
int (*compare)(const char *s1, const char *s2, size_t n);
int (*notify)(void *opt, int msg, int v, void *dest, void *sour);
void *rtpath; /* return path */
int room;
char buffer[RNM_PATH_MAX]; /* change to dynamic allocation */
void *gui; /* handler reserved for GUI */
/* statistics */
int st_process; /* total processed files */
int st_success; /* successfully renamed */
int st_failed; /* failed in rename system call */
int st_same; /* no rename because of the same name */
int st_skip; /* skipped by existed filenames */
} RNOPT;
extern const char *help_version;
extern const char *help_descript;
extern const char *help_credits;
int rename_enfile(RNOPT *opt, char *filename);
int rename_entry(RNOPT *opt, char *filename);
int rename_executing(RNOPT *opt, char *dest, char *sour);
int rename_open_buffer(RNOPT *opt, char *oldname);
int rename_compile_regex(RNOPT *opt);
int rename_status_clean(RNOPT *opt);
int rename_option_dump(RNOPT *opt);
int rename_notify(RNOPT *opt, int msg, int v, void *dest, void *sour);
/* mmgui.c */
void *mmgui_open(RNOPT *ropt, int *argcs, char ***argvs);
int mmgui_close(void *gui);
int mmgui_run(void *guiobj, int argc, char **argv);
#endif