123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- /*
- * Licensed Materials - Property of IBM and/or HCL
- *
- * IBM Informix DataBlade Module
- * Copyright IBM Corporation 1997, 2012
- * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
- */
- /*
- * INFORMIX SOFTWARE, INC.
- *
- * PROPRIETARY DATA
- *
- * THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF
- * INFORMIX SOFTWARE, INC. THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
- * CONFIDENCE. INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR
- * DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT
- * SIGNED BY AN OFFICER OF INFORMIX SOFTWARE, INC.
- *
- * THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
- * SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE.
- * UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
- *
- * Title: sedsql.c
- * Created: dyuan
- * Date: June 26 1997
- * Description: An NT utility simulating UNIX' sed.exe's substitute
- * functionality.
- * For Web Application Page Builder installation use.
- */
- #include <stdio.h>
- #include <string.h>
- #define _LINE_LENGTH 1024
- #define _PARA_NUMBER 9
- char szResult[_LINE_LENGTH];
- char * replace( char * szline, char * szfind, char * szrepl);
- void usage(void);
- void usage(void)
- {
- printf("\nInformix sedsql utility for Windows NT\n\n");
- printf("Usage:\n\tsedsql -r Search_string -n New_string -s Source_file -d Dest_file\n");
- printf("\t- All those 4 parameters are mandatory\n");
- exit(0);
- }
- char * replace( char * szline, char * szfind, char * szrepl)
- {
- char *pdest;
-
- szResult[0]='\0';
- while((pdest= strstr( szline, szfind)) !=NULL)
- {
- strncat(szResult, szline, pdest - szline);
- strcat(szResult, szrepl);
- szline = pdest+strlen(szfind);
- }
-
- strcat(szResult, szline);
- return szResult;
- }
- void main( int argc, char **argv )
- {
- FILE *stream, *stream2;
- char cswtch;
- char szline [ _LINE_LENGTH ];
- int i, iNew,iSearch,iSource,iDest;
-
- if (argc != _PARA_NUMBER)
- usage();
-
- for (i=1;i<_PARA_NUMBER;i++)
- {
- if (*argv[i] == '-')
- {
- cswtch= argv[i][1];
-
- switch(cswtch)
- {
- case 'n':
- iNew=1+i++;
- break;
- case 'r':
- iSearch=1+i++;
- break;
- case 's':
- iSource=1+i++;
- break;
- case 'd':
- iDest=1+i++;
- break;
- default:
- usage();
- break;
- }
- }
- }
- if( (stream = fopen( argv[iSource], "r" )) == NULL )
- {
- printf( "The file %s was not found\n",argv[iSource] );
- return;
- }
-
- if( (stream2 = fopen( argv[iDest], "w+" )) == NULL )
- {
- printf( "The file %s could not be opened\n", argv[iDest] );
- return;
- }
- printf("Changing %s to %s\n", argv[iSearch], argv[iNew]);
- while( !feof( stream ) )
- {
- if(fgets( szline, _LINE_LENGTH, stream)!= NULL)
- fputs( replace( szline, argv[iSearch], argv[iNew]),
- stream2);
- }
- _fcloseall( );
- exit(0);
- }
|