home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / SASC6571.LZX / extras / ttx / rexx / ttx_sasc / SafeGetFileName < prev    next >
Encoding:
Text File  |  1996-12-24  |  2.3 KB  |  75 lines

  1. /*
  2. **   SafeGetFileName: makes sure that the currently loaded file has an
  3. ** appropriate name for the operations about to be performed.  It is
  4. ** picky.  If the file has no name, it forces the user to save it.  If
  5. ** the file has a name but needs saving, the user is asked if she wants
  6. ** to continue.  And so on...
  7. **
  8. **   The full pathname of the file is returned to the calling context.
  9. */
  10.  
  11. SafeGetFileName:
  12. Options RESULTS
  13.  
  14. GetFileInfo
  15. parse var RESULT . modified '"'filename'"'
  16.  
  17. /*
  18. ** We need a full filepath.  Cover all our bases
  19. */
  20.  
  21. if modified = NO & filename = "" then do    /* is there a file at all? */
  22.                                             /* no, there isn't */
  23.     RequestBool '"TTX <=> SAS/C" "Load a file to compile?"'
  24.     if RESULT = YES then do                 /* we get a fullpath this    */
  25.                                             /* way, and load it into TTX */
  26.         drop RESULT
  27.         RequestFile 'PROMPT "Load source file" PATTERN #? sc:'
  28.         fullname = RESULT
  29.         if fullname = "RESULT" then do
  30.             SetStatusBar '"No file to compile"'
  31.             exit 0              /* no file, so leave */
  32.         end
  33.         else
  34.             NOP
  35.         OpenFile fullname
  36.         GetFileInfo
  37.         parse var RESULT . . '"'filename'"'
  38.     end
  39.     else do
  40.         SetStatusBar '"No file to compile"'
  41.         exit 0                  /* no file, so leave */
  42.     end
  43. end
  44. else do                         /* yes, there is a file */
  45.     if filename = "" then do    /* but it has no name? */
  46.         drop RESULT
  47.         RequestFile 'PROMPT "Save document as..." PATTERN #? sc:'
  48.         fullname = RESULT
  49.         if fullname = "RESULT" then do
  50.             SetStatusBar '"No file to compile"'
  51.             exit 0              /* no file, so leave */
  52.         end
  53.         else
  54.             NOP
  55.         SaveFileAs fullname     /* Save the file */
  56.         SetFilePath fullname
  57.         GetFileInfo
  58.         parse var RESULT . . '"'filename'"'
  59.     end
  60.     else do                     /* File has a name */
  61.         GetFilePath
  62.         fullname = RESULT
  63.         if modified = YES then do   /* has it been modified? */
  64.             RequestBool '"TTX <=> SAS/C" "Save before compiling?"'
  65.             if RESULT = YES then
  66.                 SaveFile
  67.             else
  68.                 NOP
  69.         end
  70.     end
  71. end
  72.  
  73. Return fullname
  74.  
  75.