/** BEGIN COPYRIGHT BLOCK * Copyright 2001 Sun Microsystems, Inc. * Portions copyright 1999, 2001-2003 Netscape Communications Corporation. * All rights reserved. * END COPYRIGHT BLOCK **/ /* namegen.c - utility program to generate name * * of backup files in the format YYYY_MM_DD_HMS * * and set it up as an environment variable to * * be used by batch files on NT * * * * to use it do the following in your batch file* * namegen * * call bstart * * ....... * * call bend * * rm end.bat * * * * start and end are batch files generated by * * name gen. * * Example: ldif2db.bat */ #include #include #include #include #define STARTFILE "bstart.bat" #define ENDFILE "bend.bat" #define CMD "set DATESTR=%0\n" int main (int argc, char **argv) { char szDate [64]; char szDateFile [64]; char szCmd [256]; struct tm *sCurTime; long lCurTime; int rt; FILE *fBatch; time( &lCurTime ); sCurTime = localtime( &lCurTime ); strftime(szDate, sizeof (szDateFile), "%Y_%m_%d_%H%M%S", sCurTime); sprintf (szDateFile, "%s.bat", szDate); /* create date batch file */ fBatch = fopen (szDateFile, "w"); if (fBatch == NULL) { perror ("Unable to create date file!"); exit (1); } rt = fwrite (CMD, strlen (CMD), 1, fBatch); if (rt != 1) { perror ("Unable to write date file\n"); exit (1); } fclose (fBatch); /* create bstart.bat that executest date batch file */ fBatch = fopen (STARTFILE, "w"); if (fBatch == NULL) { perror ("Unable to bstart file!"); exit (1); } sprintf (szCmd, "call %s", szDate); rt = fwrite (szCmd, strlen (szCmd), 1, fBatch); if (rt != 1) { perror ("Unable to write bstart file\n"); exit (1); } fclose (fBatch); /* create bstart.bat that executest date batch file */ fBatch = fopen (ENDFILE, "w"); if (fBatch == NULL) { perror ("Unable to bend file!"); exit (1); } sprintf (szCmd, "del %s\ndel bstart.bat\nset DATESTR=", szDateFile); rt = fwrite (szCmd, strlen(szCmd), 1, fBatch); if (rt != 1) { perror ("Unable to write bend file\n"); exit (1); } fclose (fBatch); return 0; }