home *** CD-ROM | disk | FTP | other *** search
/ Der Mediaplex Sampler - Die 6 von Plex / 6_v_plex.zip / 6_v_plex / DISK5 / DOS_50 / PVIC.ZIP / MAIN.C < prev    next >
C/C++ Source or Header  |  1993-04-21  |  6KB  |  226 lines

  1. #include <stdio.h>
  2. #include "pvic.h"
  3. #include "locdefs.h"
  4.  
  5. int current_lines;
  6. int current_columns;
  7.  
  8. char *real_screen = NULL;    /* What's currently on the screen, a single */
  9. char *next_screen = NULL;    /* What's to be put on the screen. */
  10.  
  11. char *file_name = NULL;        /* Current file name */
  12.  
  13. LPTR *file_memory;        /* Pointer to the first line of the file */
  14.  
  15. LPTR *top_of_file;        /* Line 'above' the start of the file */
  16.  
  17. LPTR *end_of_file;        /* Pointer to the end of the file in 
  18.                 file_memory. (It points to the byte AFTER 
  19.                 the last byte.) */
  20.  
  21. LPTR *top_char;            /* Pointer to the byte in file_memory which 
  22.                 in the upper left corner of the screen. */
  23.  
  24. LPTR *bottom_char;        /* Pointer to the byte in file_memory which is
  25.                 just off the bottom of the screen. */
  26.  
  27. LPTR *cursor_char;        /* Pointer to byte in file_memory at which the 
  28.                 cursor is currently placed. */
  29.  
  30. int cursor_row, cursor_column;    /* Current position of cursor */
  31.  
  32. int cursor_virtual_column;    /* Current virtual column, the column 
  33.                 number of the file's actual line, as 
  34.                 opposed to the column number we're at on 
  35.                 the screen.  This makes a difference on 
  36.                 lines that span more than one screen line. */
  37.  
  38. int wanted_cursor_column = 0;    /* The column we'd like to be at. This is used 
  39.                 try to stay in the same column through up/down 
  40.                 cursor motions. */
  41.  
  42. int set_wanted_cursor_column;    /* If set, then update wanted_cursor_column 
  43.                 the next time through update_cursor() to 
  44.                 the current virtual column. */
  45.  
  46. int current_status = STATUS_NORMAL;    /* This is the current state of the 
  47.                     command interpreter. */
  48.  
  49. int prenum = 0;            /* The (optional) number before a command. */
  50.  
  51. LPTR *start_insert;        /* This is where the latest insert/append 
  52.                 mode started. */
  53.  
  54. int changed = 0;        /* Set to 1 if something in the file has been 
  55.                 changed and not written out. */
  56.  
  57. char redo_buffer[1024];        /* Each command should stuff characters into 
  58.                 this  buffer that will re-execute itself. */
  59.  
  60. char insert_buffer[1024];    /* Each insertion gets stuffed into this buffer. */
  61.  
  62. int insert_n = 0;        /* Number of characters in the current 
  63.                 insertion. */
  64. char *insert_pointer = NULL;
  65.  
  66. int interactive=0;        /* Set (1) when main() is ready to roll. */
  67.  
  68. char **files;            /* List of input files. */
  69. int  number_of_files;        /* Number of input files. */
  70. int  current_file;        /* Number of the current file. */
  71.  
  72.  
  73.  
  74.  
  75. static void usage()
  76. {
  77.     fprintf(stderr, "Usage: vi [file ...]\n");
  78.     fprintf(stderr, "       vi -t tag\n");
  79.     fprintf(stderr, "       vi +[num] file\n");
  80.     fprintf(stderr, "       vi +/pat  file\n");
  81.     exit(1);
  82. }
  83.  
  84.  
  85.  
  86.  
  87. main(argc,argv)
  88. int    argc;
  89. char    *argv[];
  90. {
  91.     char *initstr,*getenv();    /* init string from the environment */
  92.     char *tag=NULL;            /* tag from command line */
  93.     char *pat=NULL;            /* pattern from command line */
  94.     int line=-1;            /* line number from command line */
  95.  
  96.     /*
  97.      * Process the command line arguments.
  98.      */
  99.     if (argc > 1) {
  100.         switch (argv[1][0]) {
  101.  
  102.         case '-':            /* -t tag */
  103.             if (argv[1][1] != 't')
  104.                 usage();
  105.  
  106.             if (argv[2] == NULL)
  107.                 usage();
  108.  
  109.             file_name = NULL;
  110.             tag = argv[2];
  111.             number_of_files = 1;
  112.             break;
  113.  
  114.         case '+':            /* +n or +/pat */
  115.             if (argv[1][1] == '/') {
  116.                 if (argv[2] == NULL)
  117.                     usage();
  118.                 file_name = strsave(argv[2]);
  119.                 pat = &(argv[1][1]);
  120.                 number_of_files = 1;
  121.  
  122.             } else if (is_digit(argv[1][1]) || argv[1][1] == '\0') {
  123.                 if (argv[2] == NULL)
  124.                     usage();
  125.                 file_name = strsave(argv[2]);
  126.                 number_of_files = 1;
  127.  
  128.                 line = (is_digit(argv[1][1])) ?
  129.                     atoi(&(argv[1][1])) : 0;
  130.             } else
  131.                 usage();
  132.  
  133.             break;
  134.  
  135.         default:            /* must be a file name */
  136.             file_name = strsave(argv[1]);
  137.             files = &(argv[1]);
  138.             number_of_files = argc - 1;
  139.             break;
  140.         }
  141.     } else {
  142.         file_name = NULL;
  143.         number_of_files = 1;
  144.     }
  145.     current_file = 0;
  146.  
  147.      if (number_of_files > 1)
  148.          fprintf(stderr, "%d files to edit\n", number_of_files);
  149.  
  150.     pvic_init();
  151.  
  152.     /*
  153.      * Allocate LPTR structures for all the various position pointers
  154.      */
  155.      if ((file_memory = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  156.          (top_of_file = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  157.          (end_of_file = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  158.          (top_char = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  159.          (bottom_char = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  160.          (cursor_char = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  161.         (start_insert = (LPTR *) malloc(sizeof(LPTR))) == NULL ||
  162.         (alloc_screen() == -1) ) 
  163.     {
  164.         fprintf(stderr, "Can't allocate data structures\n");
  165.         pvic_exit(1);
  166.     }
  167.  
  168.     /* Initialize file_memory, top_of_file, and end_of_file */
  169.     file_alloc();
  170.  
  171.     clear_screen();
  172.  
  173.     if ((initstr = getenv("EXINIT")) != NULL) 
  174.     {
  175.         char *lp, buf[128];
  176.  
  177.         if ((lp = getenv("LINES")) != NULL) 
  178.         {
  179.             sprintf(buf, "%s lines=%s", initstr, lp);
  180.             do_command_line(buf);
  181.         }
  182.         else do_command_line(initstr);
  183.     }
  184.  
  185.     if (file_name != NULL) 
  186.     {
  187.         if (read_file(file_name, file_memory, (0)))
  188.             file_message("[new file]");
  189.     } 
  190.     else if (tag == NULL)msg("Empty buffer");
  191.  
  192.     set_pc_mark();
  193.  
  194.     if (tag) 
  195.     {
  196.         put_string_into_input_buffer(":ta ");
  197.         put_string_into_input_buffer(tag);
  198.         put_string_into_input_buffer("\n");
  199.  
  200.     }
  201.     else if (pat)
  202.     {
  203.         put_string_into_input_buffer(pat);
  204.         put_string_into_input_buffer("\n");
  205.  
  206.     }
  207.     else if (line >= 0) 
  208.     {
  209.         if (line > 0)put_int_into_input_buffer(line);
  210.         put_string_into_input_buffer("G");
  211.     }
  212.  
  213.     interactive=1;
  214.  
  215.     update_screen(1);
  216.     edit();
  217.  
  218.     pvic_exit(0);
  219.  
  220.     return 1;        /* shouldn't be reached */
  221. }
  222.  
  223.  
  224.  
  225.  
  226.