home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume8 / smile / smile_main.c < prev    next >
C/C++ Source or Header  |  1989-10-01  |  3KB  |  105 lines

  1. /* SMiLE -- Simple MIni Line Editor
  2.    Copyright (C) 1989 By Alejandro Liu
  3.    You are given permission to Freely Copy and distribute this program
  4.    in its unmodifed form provided that this copyright notice is included.
  5.  */
  6.  
  7. #include "bsd_tty.h"
  8. #include "smile.h"
  9. #include <stdio.h>
  10.  
  11. main(argc,argv)
  12. int argc;
  13. char *argv[];
  14. {
  15.   int x;
  16.   extern int smile();
  17.   ed_line head, *basura;
  18.   char width, tk[256];
  19.   FILE *ants;
  20.  
  21.   init_tty();
  22.   if ((argc < 2)||(argc > 3)) {
  23.     fprintf(stderr, "Usage: %s file [line lenght]\n",argv[0]);
  24.     restore_tty();
  25.     exit(1);
  26.   }
  27.   width = 35;
  28.   if (argc == 3)
  29.     width = atoi(argv[2]);
  30.   if ((ants = fopen(argv[1],"r")) == NULL) {
  31.     head.previous = head.next = NULL;
  32.     head.data = (char *)malloc(2);
  33.     head.len = *(head.data) = 0;
  34.   }
  35.   else {
  36.     head.previous = NULL;
  37.     basura = &head;
  38.   loop:
  39.     if (fgets(tk, width, ants)) {
  40.       basura->len = strlen(tk);
  41.       tk[--(basura->len)] = 0;
  42.       basura->data = (char *)malloc(basura->len + 1);
  43.       strcpy(basura->data,tk);
  44.       basura->next = (ed_line *)malloc(sizeof(head));
  45.       (basura->next)->previous = basura;
  46.       basura = basura->next;
  47.       goto loop;
  48.     }
  49.     else {
  50.       basura->next = NULL;
  51.       basura->len = 0;
  52.       basura->data = (char *)malloc(2);
  53.       *(basura->data) = 0;
  54.     }
  55.     fclose(ants);
  56.   }
  57.   x = smile(&head, 1, width);
  58.   if (x == ABORT) {
  59.     prtstr("SMiLE Aborted... Changes Discarded\n");
  60.   }
  61.   else {
  62.     prtstr("SMiLE saving File\n");
  63.     if (ants = fopen(argv[1],"w")) {
  64.       basura = &head;
  65.       while (basura) {
  66.     fprintf(ants,"%s\n",basura->data);
  67.     basura = basura->next;
  68.       }
  69.       fclose(ants);
  70.     }
  71.     else
  72.       fprintf(stderr,"%s: can not write to file %s\n",argv[0],argv[1]);
  73.   }
  74.   restore_tty();
  75. }
  76. smile_help(wwst,width)
  77. char wwst,width;
  78. {
  79.   prtstr("SMiLE Help SubSystem\n\n");
  80.   prtstr("Current Screen Width = ");
  81.   printf("%2d",width);
  82.   prtstr("  Word Wrap is ");
  83.   if (wwst)
  84.     prtstr("enabled\n");
  85.   else
  86.     prtstr("disabled\n");
  87.   prtstr("SMiLE -- Simple MIni Line Editor\n\n");
  88.   prtstr("This   is a  simple   mini line editor, suitable for editing  messages for mail\n");
  89.   prtstr("or BBS  posts.  It  has  two integrated command  sets for maximum compatibilty.\n");
  90.   prtstr("First  Command set is the SMiLE command set,  that   supports  Easy Multi  line\n");
  91.   prtstr("editing  with easy cursor control,  and the other is a C-Net or Color  BBS, dot\n");
  92.   prtstr("command or slash command set.\n");
  93.   prtstr("The Slash and  Command Set of C-Net and Color BBS is  not completely  supported\n");
  94.   prtstr("except for the most common commands.\n");
  95.   pause();
  96.   prtstr("The  New  SMiLE commands that allow all the powerful SMiLE features are:\n");
  97.   prtstr("CTRL + N   Next Line                    CTRL + P   Previous Line\n");
  98.   prtstr("CTRL + B   Backward Char                CTRL + F   Forward Char\n");
  99.   prtstr("CTRL + K   Kill Line                    CTRL + L   List The Text\n");
  100.   prtstr("CTRL + A   Previews Text                CTRL + [   ESC Key, invokes SMiLE Menu\n");
  101.   prtstr("Typing   . or / at   the beggining of a Line enters  the QUICK Menu Mode.  i.e.\n");
  102.   prtstr("you will be prompted for a  option from the SMiLE  menu, but   no menu will  be\n");
  103.   prtstr("displayed.     (C-Net/Color         BBS Compatibility command)\n");
  104. }
  105.