appletfileversion.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletfileversion.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "applet.h"
00008 #include "appletresource.h"
00009 #include "appletfilesinternal.h"
00010 #include "appletfileversion.h"
00011 
00012 
00013 typedef struct lNumVersion {
00014     unsigned short majorRev1: 4;        /*1st part of version number in BCD*/
00015     unsigned short majorRev2: 4;        /*  2nd nibble of 1st part*/
00016     unsigned short minorRev : 4;        /*2nd part is 1 nibble in BCD*/
00017     unsigned short bugFixRev : 4;       /*3rd part is 1 nibble in BCD*/
00018     unsigned short stage : 8;           /*stage code: dev, alpha, beta, final*/
00019     unsigned short nonRelRev1 : 4;      /*revision level of non-released version*/
00020     unsigned short nonRelRev2: 4;       /*  2nd nibble of revision level*/
00021     } lNumVersion;
00022 
00023 typedef struct lVersRec {
00024     lNumVersion numericVersion;     /*encoded version number*/
00025     short countryCode;              /*country code from intl utilities*/
00026     Str255 shortVersion;            /*version number string - worst case*/
00027     Str255 reserved;                /*longMessage string packed after shortVersion*/
00028     } lVersRec, *lVersRecPtr, **lVersRecHndl;
00029 
00030 
00031 static byte bsstages [] = "\pdab";  /*dev, alpha, beta*/
00032 
00033 #define emptyversionsize ((long) sizeof (lNumVersion) + sizeof (short) + 2)
00034 
00035 
00036 static boolean versionnumtostring (lNumVersion numvers, bigstring bs) {
00037     
00038     /*
00039     return the packed version number as a string, e.g. "1.0b2".  need 
00040     definitions above, which is mis-defined in the Think C headers
00041     */
00042     
00043     setemptystring (bs);
00044     
00045     if (numvers.majorRev1 != 0)
00046         NumToString (numvers.majorRev1, bs);
00047     
00048     pushint (numvers.majorRev2, bs);
00049     
00050     pushchar ('.', bs);
00051     
00052     pushint (numvers.minorRev, bs);
00053     
00054     if (numvers.bugFixRev > 0) {
00055         
00056         pushchar ('.', bs);
00057         
00058         pushint (numvers.bugFixRev, bs);
00059         }
00060     
00061     if (numvers.stage < finalStage) {
00062         
00063         pushchar (bsstages [numvers.stage / developStage], bs);
00064         
00065         if (numvers.nonRelRev1 > 0)
00066             pushint (numvers.nonRelRev1, bs);
00067         
00068         pushint (numvers.nonRelRev2, bs);
00069         }
00070     
00071     return (true);
00072     } /*versionnumtostring*/
00073     
00074     
00075 boolean filegetversion (FSSpec *pfs, bigstring version, bigstring position) {
00076     
00077     lNumVersion versionnumber;
00078     VersRecHndl hvers;
00079     short rnum;
00080     
00081     setstringlength (version, 0);
00082     
00083     setstringlength (position, 0);
00084     
00085     if (!openresourcefile (pfs, &rnum)) /*can't open resource fork of file*/
00086         return (false);
00087     
00088     if (getresourcehandle (rnum, 'vers', 2, (Handle *) &hvers)) {
00089     
00090         register byte *p;
00091         
00092         p = (**hvers).shortVersion;
00093         
00094         p += stringlength (p) + 1; /*skip to next contiguous string -- the long version*/
00095         
00096         copystring (p, position);
00097         
00098         disposehandle ((Handle) hvers);
00099         }
00100     
00101     if (getresource (rnum, 'vers', 1, longsizeof (versionnumber), &versionnumber))
00102         versionnumtostring (versionnumber, version);
00103         
00104     closeresourcefile (rnum);
00105     
00106     return (true);
00107     } /*filegetversion*/
00108     
00109     

Generated on Wed May 31 18:19:42 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6