home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / BoxMaker++ / BoxMaker++ ƒ / outfile.cp < prev    next >
Encoding:
Text File  |  1995-01-20  |  1.7 KB  |  61 lines  |  [TEXT/KAHL]

  1. #include <stdlib.h>
  2.  
  3. #include <Folders.h>
  4.  
  5. #include "outfile.h"
  6.  
  7. outfile::outfile( unsigned char *postfix, OSType inWhichFolder)
  8. {
  9.     Str31 fileName;
  10.     makeprefix( fileName);    
  11.     const int append_len = (postfix[ 0] > 17) ? 17 : postfix[ 0];
  12.     fileName[ 0] = append_len + 14;
  13.     for( int i = 1; i <= append_len; i++)
  14.     {
  15.         fileName[ 14 + i] = postfix[ i];
  16.     }
  17.  
  18.     long foundDirID;
  19.     short foundVRefnum;
  20.     //
  21.     // As I once read somewhere:
  22.     //        'Real programs do error checking here'
  23.     //
  24.     (void)FindFolder( kOnSystemDisk, inWhichFolder, kCreateFolder, &foundVRefnum, &foundDirID);
  25.     (void)FSMakeFSSpec( foundVRefnum, foundDirID, fileName, &theFile);
  26.  
  27.     (void)FSpCreate( &theFile, 'R*ch', 'TEXT', 0);
  28.     (void)FSpOpenDF( &theFile, fsWrPerm, &fileno);
  29. }
  30. //
  31. // set2chars is a quick hack which puts the ascii representation of the last two
  32. // digits of the number passed in in the two characters pointed to by two_chars.
  33. //
  34. void outfile::set2chars( const int n, unsigned char *two_chars)
  35. {
  36.     const char lastdigit  = n % 10;
  37.     const char firstdigit = ((n - lastdigit) / 10) % 10;
  38.     two_chars[ 0] = firstdigit + '0';
  39.     two_chars[ 1] = lastdigit  + '0';
  40. }
  41. //
  42. // makeprefix sets the first letters of the string specified to the current
  43. // date and time The time format used is "yymmdd hhmmss "
  44. // This format has the property that alphabetical and chronological sorts of
  45. // dates are equal.
  46. //
  47. void outfile::makeprefix( Str31 thename)
  48. {
  49.     DateTimeRec now;    
  50.     GetTime( &now);
  51.     
  52.     set2chars( now.year,   &thename[  1]);
  53.     set2chars( now.month,  &thename[  3]);
  54.     set2chars( now.day,    &thename[  5]);
  55.     thename[ 7] = ' ';
  56.     set2chars( now.hour,    &thename[  8]);
  57.     set2chars( now.minute,  &thename[ 10]);
  58.     set2chars( now.second,  &thename[ 12]);
  59.     thename[ 14] = ' ';
  60. }
  61.