sedsql.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Licensed Materials - Property of IBM and/or HCL
  3. *
  4. * IBM Informix DataBlade Module
  5. * Copyright IBM Corporation 1997, 2012
  6. * (c) Copyright HCL Technologies Ltd. 2017. All Rights Reserved.
  7. */
  8. /*
  9. * INFORMIX SOFTWARE, INC.
  10. *
  11. * PROPRIETARY DATA
  12. *
  13. * THIS DOCUMENT CONTAINS TRADE SECRET DATA WHICH IS THE PROPERTY OF
  14. * INFORMIX SOFTWARE, INC. THIS DOCUMENT IS SUBMITTED TO RECIPIENT IN
  15. * CONFIDENCE. INFORMATION CONTAINED HEREIN MAY NOT BE USED, COPIED OR
  16. * DISCLOSED IN WHOLE OR IN PART EXCEPT AS PERMITTED BY WRITTEN AGREEMENT
  17. * SIGNED BY AN OFFICER OF INFORMIX SOFTWARE, INC.
  18. *
  19. * THIS MATERIAL IS ALSO COPYRIGHTED AS AN UNPUBLISHED WORK UNDER
  20. * SECTIONS 104 AND 408 OF TITLE 17 OF THE UNITED STATES CODE.
  21. * UNAUTHORIZED USE, COPYING OR OTHER REPRODUCTION IS PROHIBITED BY LAW.
  22. *
  23. * Title: sedsql.c
  24. * Created: dyuan
  25. * Date: June 26 1997
  26. * Description: An NT utility simulating UNIX' sed.exe's substitute
  27. * functionality.
  28. * For Web Application Page Builder installation use.
  29. */
  30. #include <stdio.h>
  31. #include <string.h>
  32. #define _LINE_LENGTH 1024
  33. #define _PARA_NUMBER 9
  34. char szResult[_LINE_LENGTH];
  35. char * replace( char * szline, char * szfind, char * szrepl);
  36. void usage(void);
  37. void usage(void)
  38. {
  39. printf("\nInformix sedsql utility for Windows NT\n\n");
  40. printf("Usage:\n\tsedsql -r Search_string -n New_string -s Source_file -d Dest_file\n");
  41. printf("\t- All those 4 parameters are mandatory\n");
  42. exit(0);
  43. }
  44. char * replace( char * szline, char * szfind, char * szrepl)
  45. {
  46. char *pdest;
  47. szResult[0]='\0';
  48. while((pdest= strstr( szline, szfind)) !=NULL)
  49. {
  50. strncat(szResult, szline, pdest - szline);
  51. strcat(szResult, szrepl);
  52. szline = pdest+strlen(szfind);
  53. }
  54. strcat(szResult, szline);
  55. return szResult;
  56. }
  57. void main( int argc, char **argv )
  58. {
  59. FILE *stream, *stream2;
  60. char cswtch;
  61. char szline [ _LINE_LENGTH ];
  62. int i, iNew,iSearch,iSource,iDest;
  63. if (argc != _PARA_NUMBER)
  64. usage();
  65. for (i=1;i<_PARA_NUMBER;i++)
  66. {
  67. if (*argv[i] == '-')
  68. {
  69. cswtch= argv[i][1];
  70. switch(cswtch)
  71. {
  72. case 'n':
  73. iNew=1+i++;
  74. break;
  75. case 'r':
  76. iSearch=1+i++;
  77. break;
  78. case 's':
  79. iSource=1+i++;
  80. break;
  81. case 'd':
  82. iDest=1+i++;
  83. break;
  84. default:
  85. usage();
  86. break;
  87. }
  88. }
  89. }
  90. if( (stream = fopen( argv[iSource], "r" )) == NULL )
  91. {
  92. printf( "The file %s was not found\n",argv[iSource] );
  93. return;
  94. }
  95. if( (stream2 = fopen( argv[iDest], "w+" )) == NULL )
  96. {
  97. printf( "The file %s could not be opened\n", argv[iDest] );
  98. return;
  99. }
  100. printf("Changing %s to %s\n", argv[iSearch], argv[iNew]);
  101. while( !feof( stream ) )
  102. {
  103. if(fgets( szline, _LINE_LENGTH, stream)!= NULL)
  104. fputs( replace( szline, argv[iSearch], argv[iNew]),
  105. stream2);
  106. }
  107. _fcloseall( );
  108. exit(0);
  109. }