home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / EXTRAS / UUCODE / UUPC / TEST / UPC12ES1.ZIP / LIB / filebkup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-11  |  3.5 KB  |  111 lines

  1. /*--------------------------------------------------------------------*/
  2. /*       f i l e b k u p                                              */
  3. /*                                                                    */
  4. /*       UUPC/extended file backup routines                           */
  5. /*                                                                    */
  6. /*       Copyright (c) 1991-1993 by Andrew H. Derbyshire;             */
  7. /*       all rights reserved except as granted by UUPC/extended       */
  8. /*       license included with documention.                           */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. /*--------------------------------------------------------------------*/
  12. /*                          RCS Information                           */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*
  16.  *    $Id: filebkup.c 1.4 1993/10/12 00:43:34 ahd Exp $
  17.  *
  18.  *    Revision history:
  19.  *    $Log: filebkup.c $
  20.  *     Revision 1.4  1993/10/12  00:43:34  ahd
  21.  *     Normalize comments
  22.  *
  23.  *     Revision 1.3  1993/04/11  00:33:38  dmwatt
  24.  *     Global edits for year, TEXT, etc.
  25.  *
  26.  * Revision 1.2  1992/11/19  02:57:51  ahd
  27.  * drop rcsid
  28.  *
  29.  * Revision 1.1  1992/11/16  05:00:26  ahd
  30.  * Initial revision
  31.  *
  32.  */
  33.  
  34.  
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /*                        System include files                        */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <time.h>
  44.  
  45. #ifndef __GNUC__
  46. #include <direct.h>
  47. #endif
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                    UUPC/extended include files                     */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. #include "lib.h"
  54. #include "hlib.h"
  55.  
  56. currentfile();
  57.  
  58. /*--------------------------------------------------------------------*/
  59. /*    f i l e b k u p                                                 */
  60. /*                                                                    */
  61. /*    Backup a file to the standard UUPC/extended defined             */
  62. /*    extension.                                                      */
  63. /*--------------------------------------------------------------------*/
  64.  
  65. int filebkup( const char *input )
  66. {
  67.    char fdrive[FILENAME_MAX];
  68.    char fpath[FILENAME_MAX];
  69.    char fname[FILENAME_MAX];
  70.    char ftype[FILENAME_MAX];
  71.    char backup[FILENAME_MAX];
  72.  
  73.    if ( !bflag[F_BACKUP] )    /* Are we to not back it up?            */
  74.       return 1;               /* Yes --> Report we did not            */
  75.  
  76. #ifdef __TURBOC__
  77.    fnsplit( input, fdrive, fpath, fname, ftype );
  78.  
  79.    if ( E_backup == NULL )
  80.       strcpy(ftype, ".BAK" );
  81.    else if ( *E_backup == '.' )
  82.       strcpy( ftype, E_backup );
  83.    else {
  84.       *ftype = '.';
  85.       strcpy(  ftype + 1 , E_backup );
  86.    } /* else */
  87.  
  88.    fnmerge( backup, fdrive, fpath, fname, ftype );
  89. #else
  90.  
  91.    if ( E_backup == NULL )
  92.       E_backup = ".BAK";
  93.  
  94.    _splitpath( input , fdrive, fpath, fname, ftype );
  95.    _makepath( backup , fdrive, fpath, fname, E_backup );
  96. #endif /* __TURBOC__ */
  97.  
  98.    remove( backup );
  99.  
  100.    if (rename( input, backup ))
  101.    {
  102.       printerr( backup );
  103.       printmsg(1,"Unable to rename %s to %s\n", input, backup );
  104.       return 1;
  105.  
  106.    } /* if (rename( input, backup )) */
  107.    else
  108.       return 0;
  109.  
  110. } /* filebkup */
  111.