home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 287.lha / TY_v1.3 / src / prompt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  4.1 KB  |  106 lines

  1. /*************************************************************************
  2.  ***                        prompt.c                     (JJB TEMPLAR) ***
  3.  *** Date modifications begun: 7/8/89.                                 ***
  4.  *** Last modified: 10/8/89.                                           ***
  5.  ***                14/8/89 - prompt in titlebar. NEVER return NULL!   ***
  6.  *************************************************************************/
  7. /*** Needs to be tightened up.                                         ***
  8.  *************************************************************************/
  9.  
  10. #include "less.h"
  11. #include "position.h"
  12. #include <workbench/startup.h>
  13.  
  14. extern int  pr_type;
  15. extern int  hit_eof;
  16. extern int  new_file;
  17. extern int  sc_width;
  18. extern char current_file[];
  19. extern int  ac;
  20. extern char **av;
  21. extern struct WBArg *wbArgs;
  22. extern int  curr_ac;
  23. extern char errmsg[];
  24.  
  25. int     oldpr;
  26. static char message[500];   /* Should be long enough */
  27.  
  28. static void ap_filename() /*=============================================*/
  29. {                         /* Init prompt to filename :                   */
  30.     strcpy(message,current_file);   strcat(message," :");
  31. }
  32.  
  33. static void ap_of() /*===================================================*/
  34. {                   /* Append file N of M to message.                    */
  35.     if (ac > 1)
  36.         sprintf(message+strlen(message)," (file %d of %d) ",curr_ac+1,ac);
  37. }
  38.  
  39. static void ap_byte() /*=================================================*/
  40. {                     /* Append byte position to message.                */
  41. LONG    pos,len;
  42.  
  43.     pos = position(BOTTOM_PLUS_ONE);
  44.     if (pos != NULL_POSITION) {
  45.         sprintf(message + strlen(message), " byte %d ", pos);
  46.         len = ch_length();
  47.         if (len > 0)
  48.             sprintf(message + strlen(message), "/%d ", len);
  49.     }
  50. }
  51.  
  52. static void ap_percent(must_print) /*====================================*/
  53. {                                  /* Append percentage into file.       */
  54. LONG    pos,len;
  55.     pos = position(BOTTOM_PLUS_ONE);
  56.     len = ch_length();
  57.     if ((len > 0) && (pos != NULL_POSITION))
  58.         sprintf(message + strlen(message), " (%d%%) ", (100 * pos) / len);
  59.     else if (must_print) ap_byte();
  60. }
  61.  
  62. static void ap_eof() /*==================================================*/
  63. {                    /* Append end to message.                           */
  64.     strcat(message, " END ");
  65.     if (curr_ac + 1 < ac)
  66.         sprintf(message+strlen(message)," - Next: %s ",wbArgs[curr_ac+1].wa_Name); /* av[curr_ac+1] */
  67. }
  68.  
  69. char    *eq_message() /*=================================================*/
  70. {                     /* Return message to '=' command.                  */
  71.     message[0] = 0;     /* Initialize string. */
  72.     ap_filename();      /* Add filename */
  73.     ap_of();            /* Add N of M stuff */
  74.     ap_byte();          /* Add byte position */
  75.     ap_percent(0);      /* Add percent. must_print = FALSE */
  76.  
  77.     return(message);    /* SetWindowTitles clips automatically */
  78. }
  79.  
  80. char    *pr_string() /*==================================================*/
  81. {                    /* Return prompt. If NULL, caller uses ':'.         */
  82.     message[0] = 0;
  83.     switch (pr_type) {
  84.         case (PR_SHORT):    ap_filename();
  85.                             if (new_file) ap_of();
  86.                             if (hit_eof) ap_eof();
  87.                             break;
  88.         case (PR_MEDIUM):   ap_filename();
  89.                             if (new_file) ap_of();
  90.                             if (hit_eof) ap_eof();
  91.                             else ap_percent(1);
  92.                             break;
  93.         case (PR_LONG):     ap_filename();
  94.                             if (new_file) ap_of();
  95.                             ap_byte();
  96.                             if (hit_eof) ap_eof();
  97.                             else ap_percent(0);
  98.                             break;
  99.         case (PR_ERROR):    strcpy(message,errmsg);
  100.                             pr_type = oldpr;
  101.                             break;      /* Used by error() when rw = 0 */
  102.     }
  103.     new_file = 0;
  104.     return(message);    /* SetWindowTitles clips automatically */
  105. }
  106.