home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / HELP / EDIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-07  |  2.8 KB  |  131 lines

  1. /* ==( help/edit.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   JPK  26-Sep-88                        */
  9. /* Modified  SBF   1-Mar-90  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *   1-Mar-90  SBF - multi-user and cleanup
  17.  *  12-Dec-89  Geo - V2 version with variable lines
  18.  *  25-Oct-89  Geo - 1.32 Merge
  19.  *
  20.  *
  21. */
  22.  
  23. /* 
  24.  * Routines in this file :
  25.  *
  26.  * static void get_editor(void); 
  27.  *     prompts the user for their choice of editors
  28.  *
  29.  * int invoke_editor(void);
  30.  *    copies the help text into the edit file, invokes the editor
  31.  *
  32.  */
  33.  
  34. # include <stdio.h>
  35. # include <bench.h>
  36. # include "field.h"
  37. # include "help.h"
  38.  
  39. # ifdef __WATCOMC__
  40. #  define mktemp(a) tmpnam(a)
  41. # endif
  42.  
  43. char EditName[]     = "Name: ";
  44. char EditorSelect[] = " Editor Selection ";
  45. char FileHlpFail[]  = "invoke_editor(): filetohelp failed";
  46. # ifdef HDEBUG
  47. char HlpFileFail[]  = "invoke_editor(): helptofile failed";
  48. char ErrEditor[]    = "Error from editor call";
  49. # endif
  50.  
  51.  
  52. static PROTO (void get_editor, (void));
  53.  
  54. /*
  55.  * TurboC turns PHXXXXXX into PHAA.AAA, therefore 
  56.  * we cannot append .txt because the file name becomes
  57.  * jibberish.
  58. */
  59. int invoke_editor()
  60. {
  61.     char editfile[20];
  62.  
  63.     strcpy(editfile, "PHXXXXXX");
  64.     mktemp(editfile);
  65. #if !defined(__TURBOC__) && !defined(__WATCOMC__)
  66.     strcat(editfile, ".txt");
  67. #endif
  68.  
  69.     /* invoke the editor chosen by the user passing it the filename to use*/
  70.     if (*editorname == '\0')
  71.     {
  72.         get_editor();
  73.         if (*editorname  ==  '\0')
  74.             return(FALSE);
  75.     }
  76.     if (helptofile(editfile) == FALSE)
  77.     {
  78. #ifdef HDEBUG
  79.         errmsg(HlpFileFail);
  80. #endif
  81.         unlink(editfile);
  82.         return(FALSE);
  83.     }
  84.  
  85.     resetscr();
  86.     if (do_cmd(editorname, editfile, NULL) == -1)
  87.     {
  88. # ifdef HDEBUG
  89.         perror(ErrEditor);
  90.         getchar();
  91. # endif
  92.         redraws();
  93.         unlink(editfile);
  94.         return(FALSE);
  95.     }
  96.  
  97.     if (filetohelp(editfile) == FALSE)
  98.         errmsg(FileHlpFail);
  99.  
  100.     unlink(editfile);
  101.  
  102.     redraws();
  103.     return(TRUE);
  104. }
  105.  
  106. char editorname_mask[] = "BVVVVVVVVV";
  107.  
  108. FIELD f_editorname =
  109. {
  110.     5, 9, 1, editorname, editorname_mask, 1,
  111.     10, F_TEXT, UNDERLINED, REVVID,
  112.     CONFIRM_NEEDED | NO_BLANK,
  113.     NULL, text_input, NULL, NULL
  114. };
  115.  
  116. static void get_editor()
  117. {
  118.     /* setup the editor input window */
  119.     create_w(9, 30, 7, 20);
  120.     border_w(0, BOLD);
  121.     underln_w(3, 1, BOLD, 20);
  122.     disp_w(2, 2, REVVID, EditorSelect);
  123.     disp_w(5, 3, NORMAL, EditName);
  124.  
  125.     /* get editor name */
  126.     input_wx(&f_editorname, K_ESC, 0);
  127.  
  128.     delete_w();
  129. }
  130.  
  131.