home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / starter / sqdate.doc < prev    next >
Text File  |  1994-03-07  |  10KB  |  282 lines

  1.             SQPC / NSQ / NUSQ
  2.         DATE AND TIME ENCODING IN SQUEEZED FILES
  3.  
  4.             February 23, 1985
  5.  
  6.             Paul J. Homchick
  7.           Chimitt Gilman Homchick, Inc.
  8.           One Radnor Station, Suite 300
  9.             Radnor, PA 19087
  10.  
  11.  
  12.  
  13.  
  14. I.  Standardized Time and Date encoding in Greenlaw-type
  15.     squeezed files.
  16.  
  17. A few Public Domain contributions have been truly remarkable, and
  18. because they have either  done  something  first  or  best,  have
  19. gained almost universal usage and  acclaim.   Ward  Christensen's
  20. XMODEM  communications  protocol  is one such contribution,  Gary
  21. Novosielski's LU is another such contribution.
  22.  
  23. The   third   one  that  comes  to  mind  is  Richard  Greenlaw's
  24. implementation of Huffman code compression and expansion  in  his
  25. SQ  and  USQ  BDS C programs.  This compression method has spread
  26. throughout the world, and is now available on  CP/M,  MSDOS,  and
  27. UNIX  systems.  Any files squeezed using Greenlaw's format on any
  28. of these ASCII-based systems can be unsqueezed and  recovered  on
  29. any of the other systems having Greenlaw-standard programs.
  30.  
  31. When  SQ  and  USQ  were implemented on MSDOS, it became apparent
  32. that greater utility would be available if SQ and  USQ  supported
  33. the  MSDOS  time  and  date  stamping.  Since SQ and USQ predated
  34. MSDOS and were developed on CP/M (no  time  and  date  stamping),
  35. this  was  not  available.   So  someone  developed a new program
  36. (known as SQ2, or ZSQ) that did incorporate  time and date stamp-
  37. ing, and it began to see use on IBMPC BBS systems.
  38.  
  39. Although  SQ2  added  time  and  date  stamping, it did so at the
  40. expense of downwards compatibility.  A  file  squeezed  with  the
  41. time  and  date  mode  of  SQ2  could ONLY be unsqueezed with the
  42. companion unsqueezer USQ2  (or  ZUSQ).   Thus  the  advantage  of
  43. standardization  was  lost.   No  file squeezed with SQ2 could be
  44. unsqueezed with the older standard programs or moved to  CP/M  or
  45. UNIX  systems.   Clearly,  SQ2  created  a  number of unfortunate
  46. consequences along with its time and date stamping.
  47.  
  48. The authors of NUSQ (an MSDOS assembly language Greenlaw-standard
  49. unsqueeze program) noted both the time and date stamping  of  SQ2
  50. and  its unfortunate break with the standard.  They developed and
  51. implemented a method of  encoding  and  decoding  time  and  date
  52. stamping  in  squeezed  files  that  retains  complete  downwards
  53. compatibility with earlier programs.
  54.  
  55. This  date and time encoding was implemented in NSQ.EXE v 2.03, a
  56. compatible squeezer, and has been adopted by SQPC.COM  the  first
  57. assembly  language squeeze program available for MSDOS.  Any file
  58. squeezed by NSQ or SQPC will have  its  original  time  and  date
  59. encoded  in  it,  and yet can still be successfully unsqueezed by
  60. any standard unsqueeze program.  If that  file is  unsqueezed  by
  61. NUSQ  or  any  compatible program, it will have its original time
  62. and date intact after the emerging from the process.
  63.  
  64. Standardization  across  a  wide range of systems and programs is
  65. clearly advantageous, as is time and date  encoding.   Since  the
  66. NSQ/SQPC/NUSQ  method  achieves both of these goals, this note is
  67. being provided to document the method used  and  to  promote  its
  68. use.
  69.  
  70. II.  Specifications of the standard.
  71.  
  72. To encode the date and time of the original file in the squeezed
  73. file, add the following 4 words after the SPEOF (Special End Of
  74. File Mark).
  75.  
  76.     Date and Time Signature Word =        FF77
  77.   + Date (MSDOS FCB format)      =        ????
  78.   + Time (MSDOS FCB format)      =        ????
  79.   = Mod 64K checksum             =        ????
  80.  
  81. The  storage  format  for  the date conforms to MS-DOS standards,
  82. wherein the 16-bit word comprises three sub-fields as follows:
  83.  
  84.  byte:  <==2==> <==1==>
  85.  bit:   76543210 76543210
  86.  field: yyyyyyym mmmddddd
  87.  y = Year.  Treated as a 7-bit binary integer in the range 0..119 (1980-2099)
  88.  m = Month.  Treated as a 4-bit binary integer in the range 1..12
  89.  d = Day.  Treated as a 5-bit binary integer in the range 1..31.
  90.  
  91. The   storage  format  for  the  time  also  conforms  to  MS-DOS
  92. standards, where:
  93.  
  94.  byte:  <==2==> <==1==>
  95.  bit:   76543210 76543210
  96.  field: hhhhhmmm mmmsssss
  97.  h = Hours.  Treated as a 5-bit binary integer in the range 0..23
  98.  m = Minutes.  Treated as a 6-bit binary integer in the range 0..59
  99.  s = Seconds/2.  Treated as a 5-bit binary integer in the range 0..29,
  100.      allowing resolution to the nearest 2-second interval.
  101.  
  102. So,  13:11:31,  Feb  17,  1985  would be encoded as: 0FF77, 0A51,
  103. 696F, 7337, or as actually stored in the file in Intel format: 77
  104. FF 51 0A 6F 69 37 73.
  105.  
  106. III.  C Code from NSQ.C to install time and date at end of squeezed file.
  107.  
  108. /* structure for MS DOS filestamping */
  109.  
  110. struct filestamp {
  111.     unsigned int date;
  112.     unsigned int time;
  113. };
  114.  
  115. squeeze(infile, outfile)
  116. char *infile, *outfile;
  117. {
  118.     register INT i, c;
  119.     FILE *inbuff, *outbuff;    /* file buffers */
  120.     INT file;
  121.     UNSIGNED check2;
  122.  
  123. /*                        */
  124. /*    chunk of code removed from here        */
  125. /*                        */
  126.  
  127.     while((c = gethuff(inbuff)) != EOF)
  128.         if( (putc(c, outbuff) == ERROR) && (ferror(outbuff)) ) {
  129.             fprintf(stderr, "nsq: write error\n");
  130.             goto closeall;
  131.         }
  132.     fprintf(stderr, "done.");
  133.  
  134.     /* find out filestamp info for input file */
  135.  
  136.     if (filedate(fileno(inbuff),0,fdatePtr) < 0) {
  137.         fprintf(stderr,"nsq: Error getting filestamp.\n");
  138.     }
  139.  
  140. closeall:
  141.     fclose(inbuff);
  142. closeout:            /* install time and date at file end      */
  143.     putwe(0xFF77,outbuff);            /* special date signature */
  144.     putwe(fdatePtr->date,outbuff);        /* MS DOS format date      */
  145.     putwe(fdatePtr->time,outbuff);        /* MS DOS format time      */
  146.     check2= 0xFF77 + fdatePtr->date + fdatePtr->time;
  147.     putwe(check2,outbuff);            /* checksum of time & date */
  148.  
  149.     fflush(outbuff);
  150.     fclose(outbuff);
  151.  
  152.     /* stamp input file time and date on output file */
  153.  
  154.     file= open(outfile,BUPDATE);        /* binary update */
  155.     if( filedate(file,1,fdatePtr) < 0) {
  156.         fprintf(stderr,"nsq: Error setting filestamp.\n");
  157.     }
  158.     close(file);
  159. }
  160.  
  161. /*
  162.  * get / set file date and time
  163.  * date and time passed in ms-dos format
  164.  *
  165.  * returns -1 on error, 1 on OK
  166.  *
  167.  * this code is specific to the Computer Innovations C86
  168.  * C compiler version 2.20
  169.  */
  170.  
  171. #include <fileio2.h>
  172.  
  173. filedate(fd,mode,fdate)
  174. int fd;                /* file descriptor    */
  175. int mode;            /* 0 = get ; 1 = set    */
  176. struct filestamp *fdate;    /* date and time    */
  177. {
  178. struct regval{unsigned ax,bx,cx,dx,si,di,ds,es;};
  179. struct regval srv;
  180. struct bufstr *buf;
  181.  
  182.     srv.ax= 0x5700+mode;        /* set time/date mode    */
  183.     buf=_opentab[fd];        /* get file handle    */
  184.     srv.bx= buf->bufhand;        /*              from C    */
  185.     if (mode) {            /* we're setting    */
  186.         srv.dx= fdate->date;
  187.         srv.cx= fdate->time;
  188.     }
  189.     if (sysint21(&srv,&srv)&1)
  190.         return(-1);
  191.     if (!mode) {            /* we're getting    */
  192.         fdate->date= srv.dx;
  193.         fdate->time= srv.cx;
  194.     }
  195.         return(1);
  196. }
  197.  
  198. /*
  199.  * machine independent put-word that writes low order byte first
  200.  *  (compatible with CP/M original) regardless of host cpu.
  201.  */
  202.  
  203. putwe(w, iob)
  204. INT w;
  205. FILE *iob;
  206. {
  207.     putc(w, iob);
  208.     putc(w>>8, iob);
  209.     if (ferror(iob)) {
  210.         fprintf(stderr, "nsq: write error\n");
  211.         exit(1);
  212.     }
  213. }
  214.  
  215. IV.  NUSQ date and time options from NUSQ manual.
  216.  
  217.                 OVERVIEW
  218.  
  219.      MS-DOS versions of NUSQ including and subsequent to 1.10 can
  220. use  date and time information encoded in files squeezed with NSQ
  221. or SQPC.  This means that a file squeezed with NSQ, 'modemed'  to
  222. another  location,  and  unsqueezed  with  NUSQ (version 1.10D or
  223. greater) will retain the date  and  time  of  ORIGIN  instead  of
  224. DESTINATION.   NSQ  encodes  this  information  at the END of the
  225. squeezed file, so such files RETAIN  COMPATIBILITY  with  earlier
  226. squeeze and unsqueeze programs.
  227.  
  228.      See the installation section of this document for details on
  229. how  to  implement this feature in NUSQ.  Any files squeezed with
  230. NSQ (versions 2.01 or higher) or SQPC (1.28 is the first bug-free
  231. version) will  have  the  necessary  date  and  time  information
  232. encoded in them.
  233.  
  234.  
  235.               INSTALLATION
  236.  
  237. Select Date Option allows you four choices for the way the output
  238. file is dated.  As distributed, NUSQ will date the output file in
  239. the  same  manner  as  most other programs do, i.e.  the date and
  240. time shown in directory displays will be the  date  and  time  at
  241. which  you  unsqueezed  the  file.  You may change this option by
  242. changing the byte at location 0104H.  Copies of NUSQ  patched  in
  243. this  manner  will  display  a  'D'  after  the  version  number,
  244. signifying that the input file date option has been enabled, i.e.
  245. "1.10D".
  246.  
  247. The available options are:
  248.  
  249.      0) Leave it to DOS
  250.      1) Output file gets the same date/time as the input file
  251.      2) If the squeezed file contains the special date/time
  252.       signature inserted by NSQ or SQPC at squeeze time,
  253.           use the date/time contained in that signature;
  254.           otherwise, use the current date/time
  255.      3) If the squeezed file contains the special date/time
  256.       signature inserted by NSQ or SQPC at squeeze time,
  257.       use the date/time contained in that signature;
  258.       otherwise, use the same date/time as the input file
  259.  
  260. If you would like the unsqueezed file to retain the same date and
  261. time  shown for the input file (option 1),  patch 0104H  to  0FH. 
  262. For option 2,  patch 0104H to 0F0H;  for option 3, patch 0104H to
  263. 0FFH.
  264.  
  265. Following is a table that explains these options:
  266.  
  267. option   value     use current   use input file    use encoded 
  268. ======   =====    =============   =============   =============
  269. 0.        00           yes              -               -
  270. 1.        0F            -              yes              -
  271. 2.        F0            -               -              yes
  272. 3.        FF            -         do this second  try this first
  273.  
  274. There  is  a reason for NUSQ being distributed with the date/time
  275. options disabled.  If you have a  backup  utility  (usually  this
  276. applies  to  a  "hard"  disk) that uses the file date and time to
  277. determine whether or not a  file  should  be  backed  up,  it  is
  278. possible  that  using  the  input file date could cause loss of a
  279. file by having an 'old' date  on  a  'new'  file,  and  losing  a
  280. backup.  If you are unsure whether this applies to you, leave the
  281. date/time options unchanged until you can find out.
  282.