home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / sig11.zip / SIG.CPP < prev    next >
C/C++ Source or Header  |  1993-03-16  |  13KB  |  324 lines

  1. //---------------------------------------------------------------------------//
  2. //                                                                           //
  3. //                                 SIG.CPP                                   //
  4. //                                 -------                                   //
  5. //                                                                           //
  6. //  Author        :  John Eady                                               //
  7. //  Installation  :  Arrow Consulting Services                               //
  8. //  Date Written  :  1993-03-16                                              //
  9. //  Environment   :  DOS                                                     //
  10. //  Status        :  Freeware                                                //
  11. //                                                                           //
  12. // This program is to be used in conjunction with OLX to simplify appending  //
  13. // a signature file to the end of your messages and replies.                 //
  14. //                                                                           //
  15. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  16. //                                                                           //
  17. // USE: - Copy SIG.EXE into your OLX directory                               //
  18. //                                                                           //
  19. //      - Create a signature file called "SIG.OLX" and copy it into your     //
  20. //        OLX directory                                                      //
  21. //                                                                           //
  22. //      - Go into OLX and modify (ALT-N) the name of the editor that you     //
  23. //        are using to place SIG before the editor name.                     //
  24. //                                                                           //
  25. //             i.e.   before :      "Q"                                      //
  26. //                    after  :      "SIG Q"                                  //
  27. //                                                                           //
  28. //                    before :      "C:\SPFPC\SPFPC REPLY.MSG"               //
  29. //                    after  :      "SIG C:\SPFPC\SPFPC REPLY.MSG"           //
  30. //                                                                           //
  31. //                    etc...                                                 //
  32. //                                                                           //
  33. //      - Thats it!                                                          //
  34. //                                                                           //
  35. //      - Each time you enter a message in OLX, the text within SIG.OLX      //
  36. //        will automatically be appended to the end of your message.         //
  37. //                                                                           //
  38. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
  39. //                                                                           //
  40. // If you have any comments and or suggestions, please feel free to contact  //
  41. // me via the following methods:                                             //
  42. //                                                                           //
  43. // BBS      : Canada Remote Systems @ 1-416-629-7044                         //
  44. //                                                                           //
  45. // USENET   : john.eady@canrem.com                                           //
  46. //                                                                           //
  47. // NETWORKS : I usually hang out on most of the C/C++ conferences on         //
  48. //            USENET/NANET/ILINK, etc...                                     //
  49. //                                                                           //
  50. // POSTAL   : John Eady              <---------- Slow, but at least          //
  51. //            6 Dubarry avenue                   they are reliable.          //
  52. //            West Hill, Ontario                                             //
  53. //            M1E 3G8                                                        //
  54. //                                                                           //
  55. //---------------------------------------------------------------------------//
  56.  
  57. #include <stdio.h>
  58. #include <stdlib.h>
  59. #include <dos.h>
  60. #include <io.h>
  61. #include <string.h>
  62. #include <process.h>
  63.  
  64. //---------------------------------------------------------------------------//
  65. //          G L O B A L   V A R I A B L E   D E F I N I T I O N S            //
  66. //---------------------------------------------------------------------------//
  67.  
  68. char path_to_files[80];
  69.  
  70. //---------------------------------------------------------------------------//
  71. //                 F U N C T I O N   P R O T O T Y P E S                     //
  72. //---------------------------------------------------------------------------//
  73.  
  74. void add_signature();
  75. void determine_reply_filename(char *);
  76. void determine_path(char *);
  77.  
  78. //---------------------------------------------------------------------------//
  79. //                                                                           //
  80. //                                  main                                     //
  81. //                                                                           //
  82. // - insure that enough arguments were passed                                //
  83. // - execute the users editor with passed arguments                          //
  84. // - append signature file                                                   //
  85. // - return to caller (usually OLX)                                          //
  86. //                                                                           //
  87. //---------------------------------------------------------------------------//
  88.  
  89. main(int argc ,char *argv[])
  90. {
  91.  
  92. /////////////////////////////////////////////
  93. // insure that the editor name was entered //
  94. /////////////////////////////////////////////
  95.  
  96. if (argc < 2)
  97.    {
  98.    printf("\nSIG V1.1 - Signature file append for OLX and OLX-TD");
  99.    printf("\n\nBy John Eady - Arrow Consulting Services");
  100.    printf("\n\nReleased to public domain on 1993-03-16\n");
  101.    exit(1);
  102.    }
  103.  
  104. /////////////////////////////////////////////////////
  105. // figure out what directory SIG is being run from //
  106. /////////////////////////////////////////////////////
  107.  
  108. strcpy(path_to_files,argv[0]);
  109. determine_path(path_to_files);
  110.  
  111. ////////////////////////////////////////
  112. // set archive bit off for reply file //
  113. ////////////////////////////////////////
  114.  
  115. char reply_file_name[80];
  116. determine_reply_filename(reply_file_name);
  117. _chmod(reply_file_name,1,FA_NORMAL);
  118.  
  119. ////////////////////////
  120. // execute the editor //
  121. ////////////////////////
  122.  
  123. if (spawnlp(P_WAIT, argv[1], argv[0], argv[2], argv[3], argv[4], NULL))
  124.    {
  125.    exit(1);
  126.    }
  127.  
  128. /////////////////////
  129. // append sig file //
  130. /////////////////////
  131.  
  132. add_signature();
  133.  
  134. ///////////////////
  135. // return to OLX //
  136. ///////////////////
  137.  
  138. exit(0);
  139.  
  140. }
  141.  
  142. //---------------------------------------------------------------------------//
  143. //                                                                           //
  144. //                            add_signature                                  //
  145. //                                                                           //
  146. // - determine reply file name                                               //
  147. // - open the reply file for append                                          //
  148. // - open the signature file                                                 //
  149. // - read signature file, and append to reply file                           //
  150. // - close all files                                                         //
  151. //                                                                           //
  152. // - NOTE: If the file ARCHIVE bit is not on, then the reply file is not     //
  153. //         modified. This is to insure that if the user backs out of         //
  154. //         entering a message, SIG will not blindly add the sig file.        //
  155. //                                                                           //
  156. //---------------------------------------------------------------------------//
  157. void add_signature()
  158. {
  159.  
  160. FILE *sig_file;
  161. FILE *reply_file;
  162.  
  163. char message_line[256];
  164. char reply_file_name[80];
  165.  
  166. /////////////////////////////////////////////////
  167. // determine reply file to append signature to //
  168. /////////////////////////////////////////////////
  169.  
  170. determine_reply_filename(reply_file_name);
  171.  
  172. ////////////////////////////////////////////////////
  173. // if the archive bit is set, do not add sig file //
  174. ////////////////////////////////////////////////////
  175.  
  176. int attrib = _chmod(reply_file_name,0);
  177.  
  178. if (attrib == -1) return;
  179.  
  180. if (!(attrib & FA_ARCH)) return;
  181.  
  182. //////////////////////////////////////
  183. // open the message file for append //
  184. //////////////////////////////////////
  185.  
  186. reply_file = fopen(reply_file_name, "at");
  187. if (reply_file == NULL)
  188.    {
  189.    printf("error in opening reply file\n");
  190.    exit(1);
  191.    }
  192.  
  193. /////////////////////////////
  194. // open the signature file //
  195. /////////////////////////////
  196.  
  197. char sig_file_name[80];
  198. strcpy(sig_file_name,path_to_files);
  199. strncat(sig_file_name,"sig.olx",7);
  200.  
  201. sig_file = fopen(sig_file_name, "rt");
  202. if (sig_file == NULL)
  203.    {
  204.    printf("error in opening signature file\n");
  205.    exit(1);
  206.    }
  207.  
  208. ///////////////////////////////////////////////////////
  209. // read signature records and append to message file //
  210. ///////////////////////////////////////////////////////
  211.  
  212. while (fgets(message_line,256,sig_file) != NULL)
  213.    {
  214.    fputs(message_line,reply_file);
  215.    }
  216.  
  217. //////////////////////////////
  218. // close the signature file //
  219. //////////////////////////////
  220.  
  221. if ((fclose(sig_file)) != 0)
  222.    {
  223.    printf("error in closing signature file\n");
  224.    exit(1);
  225.    }
  226.  
  227. ////////////////////////////
  228. // close the message file //
  229. ////////////////////////////
  230.  
  231. if ((fclose(reply_file)) != 0)
  232.    {
  233.    printf("error in closing reply file\n");
  234.    exit(1);
  235.    }
  236.  
  237. }
  238.  
  239. //---------------------------------------------------------------------------//
  240. //                                                                           //
  241. //                     determine_reply_filename                              //
  242. //                                                                           //
  243. // - search OLX's config.olx file to determine name of reply file            //
  244. //                                                                           //
  245. //---------------------------------------------------------------------------//
  246. void determine_reply_filename(char reply_file_name[])
  247. {
  248.  
  249. char config_record[80];
  250.  
  251. FILE *config_file;
  252.  
  253. //////////////////////////
  254. // open the config file //
  255. //////////////////////////
  256.  
  257. char config_file_name[80];
  258. strcpy(config_file_name,path_to_files);
  259. strncat(config_file_name,"config.olx",10);
  260.  
  261. config_file = fopen(config_file_name, "rt");
  262. if (config_file == NULL)
  263.    {
  264.    printf("error in opening config.olx\n");
  265.    exit(1);
  266.    }
  267.  
  268. ///////////////////////////////////////////////////
  269. // read config file until REPLYFILE record found //
  270. ///////////////////////////////////////////////////
  271.  
  272. while (fgets(config_record,256,config_file) != NULL)
  273.    {
  274.    if (strncmpi(config_record,"REPLYFILE",9) == 0)
  275.       {
  276.       strcpy(reply_file_name,&config_record[15]);
  277.       for(int x = 0;x<80;x++)
  278.          {
  279.          if (reply_file_name[x] == '\n')
  280.             {
  281.             reply_file_name[x] = '\0';
  282.             break;
  283.             }
  284.          }
  285.  
  286.       break;
  287.       }
  288.    }
  289.  
  290. ///////////////////////////
  291. // close the config file //
  292. ///////////////////////////
  293.  
  294. if ((fclose(config_file)) != 0)
  295.    {
  296.    printf("error in closing config file\n");
  297.    exit(1);
  298.    }
  299.  
  300. }
  301.  
  302. //---------------------------------------------------------------------------//
  303. //                                                                           //
  304. //                             determine_path                                //
  305. //                                                                           //
  306. // - determine where SIG was executed from                                   //
  307. // - this path then points to where the signaure file (SIG.OLX), and where   //
  308. //   OLX's config file is located.                                           //
  309. //                                                                           //
  310. //---------------------------------------------------------------------------//
  311. void determine_path(char execution_path[])
  312. {
  313.  
  314. int x;
  315.  
  316. for (x = 0;execution_path[x] != '\0';x++);
  317.  
  318. for(;execution_path[x] != '\\';x--);
  319.  
  320. execution_path[++x] = '\0';
  321.  
  322. }
  323.  
  324.