home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / suntar1.cpt / suntar.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-14  |  17.1 KB  |  545 lines

  1. /*******************************************************************************\
  2.  
  3. include file
  4.  
  5. suntar 1.3, ⌐1991-92 Sauro & Gabriele Speranza
  6.  
  7. This program is public domain, feel free to use it or part of it for anything
  8.  
  9. \*******************************************************************************/
  10. #include <setjmp.h>
  11.  
  12. #define V_13
  13.  
  14. #define hqxID    145
  15. #define writeID 132
  16. #define hackID    133
  17. #define tarPopupID 146
  18. #define ntAPopupID 147
  19.  
  20. #define fmGetInfo    1
  21. #define fmOpen        2
  22. #define fmClose        3
  23. #define fmEject        3
  24. #define fmCopy        5
  25. #define fmList        6
  26. #define fmExtract     7
  27. #define fmSelect    8
  28. #define fmAppend    10
  29. #define fmWriteTar    11
  30. #define fmWriteBar    12
  31. #define fmFormat    14
  32. #define fmPause        16
  33. #define fmAbort        17
  34. #define fmQuit        18
  35. #define last_fm_command fmFormat
  36.  
  37. #define pmOptions    6
  38. #define pmEnglish    10
  39. #define pmConfirm    11
  40. #define pmExpert    8
  41. #define pmIgnore    12
  42. #define pmNoConvers 13
  43.  
  44. #define wmDataFork 1
  45. #define wmASCII 2
  46. #define wmWriteMacBin 3
  47. #define wmWriteTar 4
  48. #define wmEndWrite 6
  49.  
  50. #define hmView 1
  51. #define hmClear 2
  52. #define hmSave 3
  53. #define hmOverwrite 4
  54. #define hmMac_ize 5
  55. #define hmDriveList 6
  56. #define hmFind 7
  57. #define hmUntar 8
  58. #define hmUnbar 9
  59. #define hmList 10
  60. #define hmAgain 11
  61.  
  62. #define bmDisable 1
  63. #define bmShowExtr 3
  64. #define bmSaveInfo 4
  65. #define bmShowList 6
  66.  
  67. #define ff_tarbar 1
  68. #define ff_ASCII 2
  69. #define ff_macbin 3
  70. #define ff_c_macbin 4
  71. #define ff_binhex 5
  72. #define ff_packit 6
  73.  
  74. #define SHOWINFO (all_listonly&&(disable_binhex&4) || (!all_listonly&&(disable_binhex&2) ))
  75. #define SAVEINFO (!listonly&&(disable_binhex&9)==8)
  76.  
  77. /* this define is used to compare the return value of a menu selection 
  78. with known menu items */
  79. #define menuItemMess(ID,item) (((long)ID<<16)+item)
  80.  
  81. #define signature 'S691';    /* useless, since OpenWD usually ignores it... */
  82.  
  83. #ifndef LF
  84. #define LF     '\012'    /*    '\n' in Think C, '\r' in MPW    */
  85. #define CR     '\015'    /*    '\r' in Think C, '\n' in MPW     */
  86. #endif
  87.  
  88. #define highbyte(x)        (((unsigned char *) &(x))[0])
  89. #define lowbyte(x)        (((unsigned char *) &(x))[1])
  90.  
  91. #define max_drive 4
  92.  
  93. typedef long sector_t;
  94. #define SECTOR_T_SIZE 4
  95.  
  96. typedef struct tarh_type{
  97.     char name[100];
  98.     char mode[8];
  99.     char uid[8];
  100.     char gid[8];
  101.     char size[12];
  102.     char mtime[12];
  103.     char chksum[8];
  104.     char linkflag;
  105.     char linkname[100];
  106.     char magic[8];
  107.     char uname[32];
  108.     char gname[32];
  109.     char devmajor[8];
  110.     char devminor[8];
  111.         /* these following fields were added by JF for gnu */
  112.         /* and are NOT standard */
  113.         char    atime[12];
  114.         char    ctime[12];
  115.         char    offset[12];
  116.         char    longnames[4];
  117.     char fill[127];
  118. } tarh_type;
  119. extern tarh_type tarh;
  120.  
  121. typedef struct barh_type{    /* dalla documentazione UNIX 
  122.                             -- from the bar(5) page of man */
  123.     char mode[8];
  124.     char uid[8];        /* in ottale nell'header di file, in decimale in quello di volume 
  125.                         --in octal in file headers, decimal in volume headers */
  126.     char gid[8];        /* idem */
  127.     char size[12];        /* in ottale; nel volume header, Å il numero di bytes restanti del 
  128.                         file a metê tra due dischetti (sempre multiplo di 512)
  129.                         -- in octal; in the volume header, it's the number of bytes 
  130.                         remaining from a previous file (always multiple of 512) */
  131.     char mtime[12];        /* in ottale, secondi dal 1 gen 1970 
  132.                         -- in octal, seconds since 1 jan 1970 */
  133.     char chksum[8];        /* in ottale */
  134.     char rdev[8];        /* ??? */
  135.     char linkflag;
  136.     char bar_magic[2];    /* 'V\0', solo nell'header di volume 
  137.                         -- 'V\0', only in the volume header */
  138.     char volume_num[4];    /* decimale... */
  139.     char compressed;    /* '0', solo nel volume header 
  140.                         -- '0', only in the volume header */
  141.     char cdate[12];        /* nel volume header, dice quando si e' creato l'archivio: YYMMDDHHmm\0 
  142.                         -- in the volume header, archive creation date: YYMMDDHHmm\0 */
  143.     char name[100];
  144.     char linkname[100];    /* in file normali tutto 0, come i seguenti...
  145.                         perÿ, non Å cosô: il nome del link parte immediatamente
  146.                         dopo il \0 che chiude il nome, non ad un offset fisso 
  147.                         -- see comments in the untar.c file */
  148.     char uname[32];
  149.     char gname[32];
  150.     char devmajor[8];
  151.     char devminor[8];
  152.     char fill[148];
  153. } barh_type;
  154.  
  155. extern struct binh_type{
  156.     /*byte version;*/         /* the first byte is present in the MacBinary file but is
  157.                             NOT copied to this struct, so that the most commonly used
  158.                             fields start at an even address */
  159.     unsigned char nlen;        /* Length of filename. */
  160.     char name[63];            /* Filename (only 1st nlen are significant) */
  161.     FInfo finfo;            /* type, creator, flags, zero1 (flags 0-7 must be cleared),
  162.                             point in folder, enclosing folder */
  163.     char protected;            /* = 1 for protected file, 0 otherwise */
  164.     char zero;                /* must be 0 */
  165.     long dflen;                /* Data Fork length (bytes) */
  166.     long rflen;                /* Resource Fork length */
  167.     long cdate;                /* File's creation date */
  168.     long mdate;                /* File's "last modified" date */
  169.     short gilen;            /* GetInfo message length (MacBinary II only) */
  170.     char extra_fflags;        /* Finder flags, bits 0-7 (MacBinary II only) */
  171.     char unused[14];       
  172.     char packlen[4];        /* length of total files when unpacked */
  173.     char headlen[2];        /* length of secondary header (MacBinary II only) */
  174.     unsigned char uploadvers;        /* Version of MacBinary II that the uploading program is written for */
  175.     unsigned char readvers;            /* Minimum MacBinary II version needed to read this file */
  176.     char crc[2];            /* CRC of the previous 124 bytes */
  177.     char padding[2];        /* two trailing unused bytes */
  178. } macbinh;
  179.  
  180. extern int err_code;        /* error code from read_sectors and write_sectors */
  181. extern short drive_number;
  182.  
  183. extern Boolean non_convertire;    /* disable conversions */
  184. extern OSType text_creator;
  185. extern Boolean ignore_errors,in_Italia,expert_mode,confirm_saves,bar_archive,multiVolume;
  186. extern unsigned char listonly;
  187. extern unsigned int max_hqx_header;
  188. extern unsigned char previousFormat;
  189. extern short info_file_open;
  190. extern int info_file;
  191. extern short current_crc,disable_binhex;
  192. extern short show_info;
  193. extern Boolean save_info;
  194.  
  195. extern long hqx_length;
  196. extern sector_t sect_n,sectors_on_floppy;
  197.  
  198. extern SFReply reply;
  199. extern Point where[];
  200. extern MenuHandle myMenus[4],hqxM;
  201. extern jmp_buf main_loop;
  202. extern unsigned char disk_buffer[512];
  203. extern char ultimo_header[184];    /* non tutto, solo la parte che tiene i campi 
  204.         importanti: lo uso sia in lettura sia in scrittura
  205.         -- see in untar.c and tar.c */
  206. extern Boolean ultimo_disco_espulso,ultimo_header_valido;
  207. extern sector_t avail_sectors_for_file;
  208. extern long last_offset;
  209. extern Boolean gHasResolveAlias;
  210. extern Boolean hasVheader;
  211. extern int inputFile;
  212. extern Boolean inf_is_open;
  213. extern unsigned char file_aperto;
  214. extern int floppy_n;
  215. extern sector_t settori_passati;
  216. extern int curr_vrefnum;
  217.  
  218.  
  219. enum tipo_fase {
  220. /* the "fase" (phase) variable always remembers what suntar is currently doing, so that
  221. some decisions may be performed by any function, not only by the higher levels of 
  222. the functions hierarchy */
  223. non_faccio_nulla,        /* nessun comando in corso di esecuzione, in attesa di uno 
  224.                         -- no command is being executed, waiting for one */
  225. ricevuto_comando,        /* ho ricevuto un comando ma sono ancora nei preliminari 
  226.                         (aspetta_inserzione...) e posso ancora uscirne premendo un
  227.                         bottone di annulla 
  228.                         -- received a command, but I am in the preliminary phase
  229.                         of its execution (disk insertion dialog box...) hence the
  230.                         command may still be cancelled by clicking on a button */
  231. paused,                    /* tra Pause e Resume... */
  232. in_writing,                /* sono nel men¥ di writing, pronto a ricevere comandi 
  233.                         -- ready to accept commands from the Write menu */
  234. reading_sect_n,            /* sto leggendo un numero di settore dalla console
  235.                         -- in expert mode, reading from the console */
  236. initializing,            /* sto eseguendo il comando di inizializzare un disco: a
  237.                         differenza dagli altri casi, la fase diventa questa prima 
  238.                         di chiamare aspetta_inserzione
  239.                         -- initializing a disk: in this case, the phase includes 
  240.                         the preliminaries which otherwise are ricevuto_comando
  241.                         */
  242. writing_disk,            /* sto realmente scrivendo su floppy disk, ma potrei
  243.                         anche essere in pausa per attesa disco successivo o per il
  244.                         comando "Pause": se sono chiamato da MainEvent posso usare la
  245.                         variabile sto_lavorando per sapere se non sono nÄ in pausa
  246.                         nÄ in semimodal e finestra_sm_aperta per sapere se sono
  247.                         in semimodal: assolutamente non assegnare quelle variabili!
  248.                         -- writing to a floppy disk, or maybe paused or waiting for 
  249.                         another disk: the two variables sto_lavorando (I'm working) and 
  250.                         finestra_sm_aperta (semimodal window is open) may be consulted to
  251.                         distinguish the three cases
  252.                         */
  253. reading_disk,            /* sto realmente leggendo da floppy disk, ma come sopra 
  254.                         -- as above... */
  255. hack_listing,            /* sto eseguendo un expert list
  256.                         -- executing the expert list command
  257.                         */
  258. hack_reading,            /* sto eseguendo un untar at sector o unbar at sector
  259.                         -- executing untar at sector or unbar at sector
  260.                         */
  261. selected_reading        /* sto leggendo col comando Extract selected files
  262.                         -- reading by "Extract selected files" */
  263. };
  264. extern enum tipo_fase fase;
  265.  
  266. enum os_type {unknown_os,mac_MFS,mac_HFS,msdos};
  267. extern struct disk_info{
  268.     Boolean is_not_initialized,is_write_protected;
  269.     enum os_type os;
  270.     short disk_code;        /* as the return value of PBMountVol, but often it's
  271.                             computed by suntar itself */
  272.     /* the following fields are useful only if the disk must be initialized */
  273.     sector_t max_format;
  274.     short format_index,
  275.         supports_720K;
  276.     } di;
  277.  
  278. enum formats{unreadable_disk,tar_format,bar_format,unknown_format};
  279.  
  280. typedef struct {
  281.     OSType tx_cr;
  282.     #define text_creator options.tx_cr
  283.     short d_back;    /* delay when going to background during a disk write */
  284.     #define delay_back options.d_back
  285.     unsigned short m_to_beep;
  286.     #define min_to_beep options.m_to_beep
  287. #ifdef V_122
  288.     unsigned char opt_bytes[12];
  289. #else
  290.     unsigned char opt_bytes[20];
  291. #endif
  292.     #define tar_version options.opt_bytes[0]            /* popup */
  293.  
  294. #define tar_unknown 0
  295. #define tar_singlevol 1
  296. #define tar_GNU 2
  297. #define tar_AIX 3
  298.  
  299.     #define accetta_GCR options.opt_bytes[1]
  300.     #define resolve_aliases options.opt_bytes[2]
  301.     #define crea_mac_dir options.opt_bytes[3]
  302.     #define non_text_ASCII options.opt_bytes[4]        /* was radio buttons, now is popup */
  303.     #define save_modi_date options.opt_bytes[5]
  304.     #define useSys7_SF options.opt_bytes[6]
  305.     #define del_incompl options.opt_bytes[7]
  306.     #define trunc_14 options.opt_bytes[8]
  307.     #define pres_underscore !options.opt_bytes[9]
  308.     #define suppress_shell_chars !options.opt_bytes[10]
  309.     #define verify_writes options.opt_bytes[11]
  310.     #define smallFilesAreASCII options.opt_bytes[12]
  311.  
  312. #define first_check_option 1
  313. #define last_check_option  12
  314. #define skip_check_option   4
  315.  
  316.     #ifdef V_13        /* new field added in the 1.3; I preferred not to alter
  317.                     the layout of the previous fields in case somebody uses
  318.                     ResEdit to move his old OPTs resource to the new version
  319.                     */
  320.     OSType gif_cr;
  321.     #define gif_creator options.gif_cr
  322.     #endif
  323.     } options_type;
  324. extern options_type options;
  325.  
  326. /* prototypes for untar.c */
  327. char *p2cstr(unsigned char*);
  328. unsigned char*c2pstr(char*);
  329. void mcopy(char *,char *,unsigned short);
  330. void init_hd_buffering(void);
  331. short readblock(char*,int);
  332. void unget_block(void);
  333. void unget_char(void);
  334. void end_of_file(void);
  335. void skip_file(long);
  336. void stampa_buffer(sector_t,unsigned char *);
  337. short isASCII(long,int*);
  338. Boolean print_if_string(char*,char*,int);
  339. void my_untar(void);
  340. void my_unbar(void);
  341. short unbar_checksum(unsigned char *,int,long *);
  342. unsigned char guess_bar_linkflag(void);
  343. void unbar(void);
  344. void copia_ultimo_header(char*,sector_t);
  345. void bar_check_floppy_swap(short);
  346. short inserzione_assicurata(char*,Boolean);
  347. short bar_check_settore0(sector_t*,Boolean);
  348. void tar_check_floppy_swap(int);
  349. short tar_check_settore0(Boolean);
  350. void close_or_del_out_file(void);
  351. void check_confirmation(void);
  352. void check_conf_dir(char*);
  353. void my_itoa(long,char *);
  354. void clear_unused_fields(void);
  355. void print_type_creator(OSType,OSType);
  356. void print_one_date(long,char*);
  357. #ifdef V_122
  358.     void controlla_spazio(long,long);
  359.     void conferma_invisibili(void);
  360. #else
  361.     short controlla_spazio(long,long);
  362.     short crea_e_controlla(Boolean);
  363. #endif
  364. void get_openfile_location(int);
  365. void untar_hqx (long);
  366. void write_hqx_fork(short,long);
  367. void write_pit_fork(short,long);
  368. void set_binhex(void);
  369. short untar_checksum(unsigned char*,int,Boolean);
  370. short chkmacbin (long ,int);
  371. void setdata (void);
  372. void untar (void);
  373. void untar_file (long);
  374. void untar_data (long);
  375. void untar_macbin (long);
  376. void writefork(short,long,Boolean);
  377. void setmacbin (void);
  378. void untar_directory (void);
  379. void create_directory (char *);
  380. short create_file (char *,int,Boolean);
  381. void untar_link (void);
  382. void unix_to_mac (char *);
  383. long untar_number (char*,short);
  384. void pbsyserr (IOParam *);
  385.  
  386. /* prototypes for suntar.c */
  387. void apri_archivio(void);
  388. void chiudi_archivio(void);
  389. void copia_da_disco_a_file(void);
  390. void estrai_da_floppy(void);
  391. void scrivi_su_floppy(void);
  392. void disk_initialize(void);
  393. enum formats identify_format(void);
  394. short apri_file(char *,int *);
  395. OSErr new_text_file(int*);
  396. OSErr create_overwrite(OSType,OSType,int *);
  397. int mac_fread(char*,int,short);
  398. int mac_fwrite(char*,int,short);
  399. OSErr open_overwrite (char *,short,int *);
  400. Boolean my_disk_is_in(void);
  401. void handle_pause(void);
  402. void check_events(void);
  403. short check_error_and_events(void);
  404. void accept_abort_command(void);
  405. Boolean is_abort_command(void);
  406. Boolean is_pause_command(void);
  407. short aspetta_inserzione(char*);
  408. void check_foreground(void);
  409. void beep_in_foreground(void);
  410. void about_box(void);
  411. Boolean check_all_zero(char *);
  412. void print_info(char *,long);
  413. void raise_error(void);
  414. void error_message(char *);
  415. void error_message_1(char *,int);
  416. short check_error(void);
  417. void hacking(int);
  418. short read_sect_n(sector_t *);
  419. short my_atoi(char*,int*);
  420. short my_atol(char*,long*);
  421. void overwrite_sectors(void);
  422. void print_sector_n(sector_t);
  423. void stampa_info_bar(int);
  424. void DriveList(void);
  425. void fine_lavoro(void);
  426. void set_skip_all(int);
  427. void prefs_da_risorsa(void);
  428. void load_options(void);
  429. void save_options(void);
  430.  
  431. /* prototypes for diskdriver.c */
  432. void disk_format(Boolean);
  433. short testa_stato(short*,Boolean);
  434. Boolean is_wrprot(void);
  435. enum os_type riconosci_disco_mac(unsigned char*);
  436. void identifica_hardware(void);
  437. void init_buffering(void);
  438. void check_allocated(void*);
  439. void flush_buffers(void);
  440. void invalid_buffers(void);
  441. void invalid_after(sector_t);
  442.  
  443. Boolean dirty_buffers(void);
  444. void leggi_settore(sector_t,char*);
  445. void scrivi_settore(sector_t,char*);
  446. void diskEject(void);
  447. void read_sectors(sector_t,char*,int);
  448. void write_sectors(sector_t,char*,int);
  449. void read_one_sector(sector_t,char *,short);
  450.  
  451. /* prototypes for tar.c */
  452. void fillmem(char*,char,int);
  453. void reset_sector_count(void);
  454. void warning_400_800(void);
  455. void printf_protetto(void);
  456. short warning_first_write(int);
  457. void de_Mac_ize(char*);
  458. void write_tar_volume_header(void);
  459. void write_bar_volume_header(void);
  460. short bar_header(char *,long,barh_type *);
  461. void bar_checksum(char *);
  462. void writeblock(char*,int);
  463. unsigned char get_linkflag(long *);
  464. void cerca_fine(void);
  465. void svuota_buffer(void);
  466. void azzera_settore(void);
  467. void tronca_archivio(void);
  468. Boolean compare_mem(char*,char*,int);
  469. void print_ready(void);
  470. void check_and_eject(void);
  471. void check_wr_err(void);
  472. void my_tar(int);
  473. void close_input_files(void);
  474. void FillMacBin2Fields(void);
  475. void assegna_tar_version(void);
  476. void controlla_che_ci_stia(sector_t);
  477. void tar_file_or_folder (char *);
  478. void tardir (char *);
  479. void tarfile (char*);
  480. void tardata (char*,short);
  481. void tarmacbin(char*,short);
  482. void macbinheader(void);
  483. void tar_writefork (long,int);
  484. short tarheader (char *,long);
  485. void fill_checksum(tarh_type *);
  486. void mac_to_unix(char*,char*);
  487. void numstr (char *,long,int);
  488. void statf (char *);
  489. short getvrefnum (char *);
  490. void nametoolong (char *);
  491.  
  492. /* prototypes for dialogs.c */
  493. void options_box(void);
  494. void select_and_extract(void);
  495. void my_alert(void);
  496. short my_modal_dialog(short,char **i,int);
  497. void SetCheckBox(DialogPtr,short);
  498. int dialogo_tipo_file(void);
  499.  
  500. /* prototypes for dehqx.c */
  501. void close_info_file(void);
  502. int ci_strcmp(char*,char*);
  503. short is_hqx_name(void);
  504. void check_CRC(void);
  505. short hqx_header(void);
  506. void FindStart (void);
  507. void init_hqx_tab(void);
  508. void read_hqx(char *,int);
  509. int read_3_hqx(unsigned char *,int);
  510. unsigned char get_hqx_byte(Boolean *);
  511. void open_info_file(void);
  512. void flush_hqx_header(int);
  513. void hqx_end_of_file(void);
  514. void CalcCRC(char);
  515.  
  516. /* prototypes for unpit.c */
  517. void my_unpit(void);
  518. void get_pit_bytes(char*,int);
  519. void deall_tree(void);
  520.  
  521. /* prototypes for folderSTDfile.c */
  522. void my_SF_Put(unsigned char *,unsigned char *);
  523. void my_SF_Get(short,SFTypeList);
  524. int get_file_or_folder(Str255,short,SFTypeList*);
  525. void select_directory(void);
  526. Boolean get_file_with_checkbox(Boolean *);
  527. Boolean SFPut_con_pausa(unsigned char *);
  528. void close_all_open_WD(void);
  529. void register_WD(short);
  530.  
  531. /* prototypes for StdFile.c & selectbutton.c */
  532. void pStrcat(unsigned char *,unsigned char *);
  533. void pStrcpy(unsigned char *,unsigned char *);
  534. OSErr PathNameFromDirID(long,short,char*);
  535. void doForceDirectory(WDPBRec*);
  536. void SetRadioButton(DialogPtr,short,short);
  537. void SelectButton(ControlHandle);
  538. void OutlineControl(ControlHandle);
  539.  
  540. /* prototypes for semimodal.c */
  541. int semimodalDialog(int,Point *,int (*)(EventRecord*),char **,int,
  542.     Str255,Str255,Str255,int,Boolean);
  543. void close_semimodal(void);
  544.  
  545.