| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#ifndef VMFILNAM_H |
| 23 |
#define VMFILNAM_H |
| 24 |
|
| 25 |
#include "t3std.h" |
| 26 |
#include "vmtype.h" |
| 27 |
#include "vmglob.h" |
| 28 |
#include "vmobj.h" |
| 29 |
#include "vmundo.h" |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
struct vm_filnam_ext |
| 51 |
{ |
| 52 |
|
| 53 |
static vm_filnam_ext *alloc_ext(VMG_ class CVmObjFileName *self, |
| 54 |
int32_t sfid, const char *str, size_t len); |
| 55 |
|
| 56 |
|
| 57 |
size_t get_len() { return vmb_get_len(str); } |
| 58 |
const char *get_str() { return str + VMB_LEN; } |
| 59 |
|
| 60 |
|
| 61 |
int32_t sfid; |
| 62 |
|
| 63 |
|
| 64 |
char sfid_valid; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
char from_ui; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
char str[1]; |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
class CVmObjFileName: public CVmObject |
| 91 |
{ |
| 92 |
friend class CVmMetaclassFileName; |
| 93 |
|
| 94 |
public: |
| 95 |
|
| 96 |
static class CVmMetaclass *metaclass_reg_; |
| 97 |
class CVmMetaclass *get_metaclass_reg() const { return metaclass_reg_; } |
| 98 |
|
| 99 |
|
| 100 |
virtual int is_of_metaclass(class CVmMetaclass *meta) const |
| 101 |
{ |
| 102 |
|
| 103 |
return (meta == metaclass_reg_ |
| 104 |
|| CVmObject::is_of_metaclass(meta)); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
static int is_vmfilnam_obj(VMG_ vm_obj_id_t obj) |
| 109 |
{ return vm_objp(vmg_ obj)->is_of_metaclass(metaclass_reg_); } |
| 110 |
|
| 111 |
|
| 112 |
static vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, |
| 113 |
uint argc); |
| 114 |
|
| 115 |
|
| 116 |
static vm_obj_id_t create_from_url(VMG_ const char *str, size_t len); |
| 117 |
|
| 118 |
|
| 119 |
static vm_obj_id_t create_from_local(VMG_ const char *str, size_t len); |
| 120 |
|
| 121 |
|
| 122 |
static vm_obj_id_t create_from_sfid( |
| 123 |
VMG_ int32_t sfid, const char *path, size_t len); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
static vm_obj_id_t combine_path( |
| 132 |
VMG_ const char *path, size_t pathl, const char *file, size_t filel, |
| 133 |
int literal); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
static int call_stat_prop(VMG_ vm_val_t *result, |
| 140 |
const uchar **pc_ptr, uint *argc, |
| 141 |
vm_prop_id_t prop); |
| 142 |
|
| 143 |
|
| 144 |
void notify_delete(VMG_ int in_root_set); |
| 145 |
|
| 146 |
|
| 147 |
virtual int equals(VMG_ vm_obj_id_t self, const vm_val_t *val, |
| 148 |
int depth) const; |
| 149 |
|
| 150 |
|
| 151 |
virtual int add_val(VMG_ vm_val_t *result, |
| 152 |
vm_obj_id_t self, const vm_val_t *val); |
| 153 |
|
| 154 |
|
| 155 |
virtual const char *cast_to_string(VMG_ vm_obj_id_t , |
| 156 |
vm_val_t * ) const |
| 157 |
{ return get_path_string(); } |
| 158 |
|
| 159 |
|
| 160 |
const char *get_path_string() const; |
| 161 |
|
| 162 |
|
| 163 |
int is_special_file() const { return get_ext()->sfid != 0; } |
| 164 |
int32_t get_sfid() const { return get_ext()->sfid; } |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
void set_from_ui(int typ) { get_ext()->from_ui = (char)typ; } |
| 172 |
int get_from_ui() const { return get_ext()->from_ui; } |
| 173 |
|
| 174 |
|
| 175 |
void set_prop(VMG_ class CVmUndo *undo, |
| 176 |
vm_obj_id_t self, vm_prop_id_t prop, const vm_val_t *val); |
| 177 |
|
| 178 |
|
| 179 |
int get_prop(VMG_ vm_prop_id_t prop, vm_val_t *val, |
| 180 |
vm_obj_id_t self, vm_obj_id_t *source_obj, uint *argc); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
void notify_new_savept() { } |
| 187 |
|
| 188 |
|
| 189 |
void apply_undo(VMG_ struct CVmUndoRecord *) { } |
| 190 |
|
| 191 |
|
| 192 |
void discard_undo(VMG_ struct CVmUndoRecord *) { } |
| 193 |
|
| 194 |
|
| 195 |
void mark_undo_ref(VMG_ struct CVmUndoRecord *) { } |
| 196 |
|
| 197 |
|
| 198 |
void mark_refs(VMG_ uint) { } |
| 199 |
|
| 200 |
|
| 201 |
void remove_stale_weak_refs(VMG0_) { } |
| 202 |
void remove_stale_undo_weak_ref(VMG_ struct CVmUndoRecord *) { } |
| 203 |
|
| 204 |
|
| 205 |
void load_from_image(VMG_ vm_obj_id_t self, const char *ptr, size_t siz); |
| 206 |
|
| 207 |
|
| 208 |
void reload_from_image(VMG_ vm_obj_id_t self, |
| 209 |
const char *ptr, size_t siz); |
| 210 |
|
| 211 |
|
| 212 |
virtual ulong rebuild_image(VMG_ char *buf, ulong buflen); |
| 213 |
|
| 214 |
|
| 215 |
void save_to_file(VMG_ class CVmFile *fp); |
| 216 |
|
| 217 |
|
| 218 |
void restore_from_file(VMG_ vm_obj_id_t self, |
| 219 |
class CVmFile *fp, class CVmObjFixup *fixups); |
| 220 |
|
| 221 |
|
| 222 |
int is_changed_since_load() const { return FALSE; } |
| 223 |
|
| 224 |
protected: |
| 225 |
|
| 226 |
vm_filnam_ext *get_ext() const { return (vm_filnam_ext *)ext_; } |
| 227 |
|
| 228 |
|
| 229 |
static const char *get_local_path(VMG_ const vm_val_t *val); |
| 230 |
|
| 231 |
|
| 232 |
void load_image_data(VMG_ const char *ptr, size_t siz); |
| 233 |
|
| 234 |
|
| 235 |
CVmObjFileName() { ext_ = 0; } |
| 236 |
|
| 237 |
|
| 238 |
CVmObjFileName(VMG_ int32_t sfid, const char *str, size_t len); |
| 239 |
|
| 240 |
|
| 241 |
static char *url_to_local(VMG_ const char *str, size_t len, int nullterm); |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
char *to_universal(VMG0_) const; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
int32_t special_filetype_flags(VMG0_); |
| 254 |
|
| 255 |
|
| 256 |
int getp_undef(VMG_ vm_obj_id_t, vm_val_t *, uint *) { return FALSE; } |
| 257 |
|
| 258 |
|
| 259 |
int getp_getName(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 260 |
|
| 261 |
|
| 262 |
int getp_getRootName(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 263 |
|
| 264 |
|
| 265 |
int getp_getPath(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 266 |
|
| 267 |
|
| 268 |
int getp_fromUniversal(VMG_ vm_obj_id_t, vm_val_t *retval, uint *argc) |
| 269 |
{ return s_getp_fromUniversal(vmg_ retval, argc); } |
| 270 |
|
| 271 |
|
| 272 |
static int s_getp_fromUniversal(VMG_ vm_val_t *retval, uint *argc); |
| 273 |
|
| 274 |
|
| 275 |
int getp_toUniversal( |
| 276 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 277 |
|
| 278 |
|
| 279 |
int getp_addToPath(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 280 |
|
| 281 |
|
| 282 |
int getp_isAbsolute(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 283 |
|
| 284 |
|
| 285 |
int getp_getAbsolutePath( |
| 286 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 287 |
|
| 288 |
|
| 289 |
int getp_getRootDirs(VMG_ vm_obj_id_t, vm_val_t *retval, uint *argc) |
| 290 |
{ return s_getp_getRootDirs(vmg_ retval, argc); } |
| 291 |
|
| 292 |
|
| 293 |
static int s_getp_getRootDirs(VMG_ vm_val_t *retval, uint *argc); |
| 294 |
|
| 295 |
|
| 296 |
int getp_getFileType(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 297 |
|
| 298 |
|
| 299 |
int getp_getFileInfo(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 300 |
|
| 301 |
|
| 302 |
int getp_deleteFile(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 303 |
|
| 304 |
|
| 305 |
int getp_renameFile(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 306 |
|
| 307 |
|
| 308 |
int getp_listDir(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 309 |
|
| 310 |
|
| 311 |
int getp_forEachFile(VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 312 |
|
| 313 |
|
| 314 |
int getp_createDirectory( |
| 315 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 316 |
|
| 317 |
|
| 318 |
int getp_removeDirectory( |
| 319 |
VMG_ vm_obj_id_t self, vm_val_t *retval, uint *argc); |
| 320 |
|
| 321 |
|
| 322 |
static int (CVmObjFileName::*func_table_[])(VMG_ vm_obj_id_t self, |
| 323 |
vm_val_t *retval, uint *argc); |
| 324 |
}; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
class CVmMetaclassFileName: public CVmMetaclass |
| 332 |
{ |
| 333 |
public: |
| 334 |
|
| 335 |
const char *get_meta_name() const { return "filename/030000"; } |
| 336 |
|
| 337 |
|
| 338 |
void create_for_image_load(VMG_ vm_obj_id_t id) |
| 339 |
{ |
| 340 |
new (vmg_ id) CVmObjFileName(); |
| 341 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
void create_for_restore(VMG_ vm_obj_id_t id) |
| 346 |
{ |
| 347 |
new (vmg_ id) CVmObjFileName(); |
| 348 |
G_obj_table->set_obj_gc_characteristics(id, FALSE, FALSE); |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
vm_obj_id_t create_from_stack(VMG_ const uchar **pc_ptr, uint argc) |
| 353 |
{ return CVmObjFileName::create_from_stack(vmg_ pc_ptr, argc); } |
| 354 |
|
| 355 |
|
| 356 |
int call_stat_prop(VMG_ vm_val_t *result, |
| 357 |
const uchar **pc_ptr, uint *argc, |
| 358 |
vm_prop_id_t prop) |
| 359 |
{ |
| 360 |
return CVmObjFileName:: |
| 361 |
call_stat_prop(vmg_ result, pc_ptr, argc, prop); |
| 362 |
} |
| 363 |
}; |
| 364 |
|
| 365 |
#endif |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
VM_REGISTER_METACLASS(CVmObjFileName) |