~ubuntu-branches/ubuntu/saucy/ng/saucy

« back to all changes in this revision

Viewing changes to echo.c

  • Committer: Bazaar Package Importer
  • Author(s): Masayuki Hatta (mhatta)
  • Date: 2008-07-17 08:10:34 UTC
  • mfrom: (4.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080717081034-s7iitiihm9hl4jjg
Tags: 1.5~beta1-3
Bumped to Standards-Version: 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: echo.c,v 1.6.2.1 2000/12/01 09:59:44 amura Exp $ */
 
1
/* $Id: echo.c,v 1.8.2.1 2003/03/02 15:29:37 amura Exp $ */
2
2
/*
3
3
 *              Echo line reading and writing.
4
4
 *
14
14
 
15
15
/*
16
16
 * $Log: echo.c,v $
17
 
 * Revision 1.6.2.1  2000/12/01 09:59:44  amura
 
17
 * Revision 1.8.2.1  2003/03/02 15:29:37  amura
 
18
 * add minibuffer history (thanks to kakugawa)
 
19
 *
 
20
 * Revision 1.8  2001/01/05 14:07:01  amura
 
21
 * first implementation of Hojo Kanji support
 
22
 *
 
23
 * Revision 1.7  2000/11/19 18:15:11  amura
18
24
 * rename sput?() functions because HP-UX have sputl() function
19
25
 * in its library
20
26
 *
272
278
 
273
279
#ifdef MINIBUF_EDIT
274
280
/* Minibuffer hack from NGSCM by H.Kakugawa */
 
281
 
 
282
#define MB_NHISTS               10
 
283
#define MB_HIST_FUNC            0
 
284
#define MB_HIST_BUF             1
 
285
#define MB_HIST_FILE            2
 
286
#define MB_HIST_MISC            3
 
287
#define MB_HIST_NTYPES          4
 
288
/* Note: mb_hist_buf[*][0] plays a special role. */
 
289
static char *mb_hist_buf[MB_HIST_NTYPES][MB_NHISTS+1];
 
290
#define mb_get_hist_buf(flag)                                   \
 
291
        (((flag)&EFFUNC) ? mb_hist_buf[MB_HIST_FUNC] :          \
 
292
        (((flag)&EFBUF)  ? mb_hist_buf[MB_HIST_BUF] :           \
 
293
        (((flag)&EFFILE) ? mb_hist_buf[MB_HIST_FILE] :          \
 
294
                        mb_hist_buf[MB_HIST_MISC])))            \
 
295
 
275
296
extern int  refresh();
276
297
 
277
298
static int  mb_init();
323
344
static VOID mb_redisplay();
324
345
static VOID mb_refresh();
325
346
static VOID mb_flush();
 
347
static VOID mb_hist_save();
326
348
static char* sformat();
327
349
static int  s_put_i();
328
350
static int  s_put_l();
358
380
{
359
381
  int        MetaPrefix, CtluPrefix, nargs, cmp_msg_len, sign, ctluf;
360
382
  int        c;
 
383
  char       **hist_buf;
 
384
  int        hist_idx;
361
385
  
362
386
#ifdef  ADDFUNC
363
387
  /* If an extra argument exists, use it.                       */
397
421
  mb_cannamode  = FALSE;
398
422
  mbMode[0] = '\0';
399
423
#endif
 
424
  hist_buf    = mb_get_hist_buf(flag);
 
425
  hist_buf[0] = buf;
 
426
  hist_idx = 0;
400
427
 
401
428
  for (;;){
402
429
    ttflush();
445
472
          ctluf = 0;
446
473
          nargs = 0;
447
474
          break;
448
 
        } else
 
475
        } else {
 
476
          hist_buf[0] = NULL; /* reset top of history */
449
477
          return (ABORT);
 
478
        }
450
479
      default: 
451
480
        goto Cmd;
452
481
      }
493
522
          while (nargs++ < 0)
494
523
            complete_scroll_up();
495
524
        break;
 
525
      case 'p': case 'P':  /* History, prev */
 
526
        if (hist_idx < MB_NHISTS && hist_buf[hist_idx+1] != NULL) {
 
527
          if (hist_idx == 0)
 
528
            mb_get_buffer(buf, nbuf);
 
529
          hist_idx++;
 
530
          mb_begl();
 
531
          mb_kill();
 
532
          mb_insertstr(hist_buf[hist_idx]);
 
533
          mb_begl();
 
534
        }
 
535
        else {
 
536
          message("Beginning of history; no preceding item");
 
537
          ttwait();
 
538
        }
 
539
        mb_redisplay();
 
540
        break;
 
541
      case 'n': case 'N':  /* History, next */
 
542
        if (hist_buf[1] == NULL) {
 
543
          message("End of history; no default available");
 
544
          ttwait();
 
545
        }
 
546
        else if (hist_idx == 0) {
 
547
          message("End of history; no next item");
 
548
          ttwait();
 
549
        }
 
550
        else {
 
551
            hist_idx--;
 
552
            mb_begl();
 
553
            mb_kill();
 
554
            mb_insertstr(hist_buf[hist_idx]);
 
555
            mb_begl();
 
556
        }
 
557
        mb_redisplay();
 
558
        break;
 
559
                    
496
560
      default:
497
561
        ttbeep();
498
562
      }
536
600
          ttputc(CCHR('M'));
537
601
          ttflush ();
538
602
        }
 
603
        hist_buf[0] = NULL; /* reset top of history */
539
604
#ifndef NO_MACRO
540
605
        if (macrodef){
541
606
          LINE *lp;
549
614
          bcopy(buf, lp->l_text, mb_bufsize());
550
615
        }
551
616
#endif
552
 
        return ((mb_bufsize() == 0) ? FALSE : TRUE);
 
617
        if (mb_bufsize() == 0)
 
618
          return FALSE;
 
619
        mb_hist_save(hist_buf, buf);
 
620
        return TRUE;
553
621
      case CCHR('G'):   /* Abort */
554
622
        (VOID) ctrlg(FFRAND, 0);
555
623
        mb_flush();
556
624
        complete_del_list();
 
625
        hist_buf[0] = NULL; /* reset top of history */
557
626
        return (ABORT);
558
627
      case CCHR('A'):     /* Beginning of line */
559
628
        mb_begl();
802
871
  for (i = _mb_prompt; i < _mb_point;){
803
872
    if (j >= nbuf-1){
804
873
#ifdef  KANJI
805
 
      if (ISKANJI(_mb_buf[i]))
 
874
      if (ISKANJI(_mb_buf[i])) {
 
875
#ifdef  HOJO_KANJI
 
876
        if (i>=1 && ISHOJO(_mb_buf[i-1])) buf[j-2] = '\0';
 
877
        else
 
878
#endif
806
879
        buf[j-1] = '\0';
807
 
      else
808
 
#endif
 
880
      } else
 
881
#endif  /* KANJI */
809
882
        buf[j] = '\0';
810
883
      return 0;
811
884
    }
814
887
  for (i = _mb_gapend; i < _mb_size;){
815
888
    if (j >= nbuf-1){
816
889
#ifdef  KANJI
817
 
      if (ISKANJI(_mb_buf[i]))
 
890
        if (ISKANJI(_mb_buf[i])) {
 
891
#ifdef  HOJO_KANJI
 
892
        if (i>=1 && ISHOJO(_mb_buf[i-1])) buf[j-2] = '\0';
 
893
        else
 
894
#endif
818
895
        buf[j-1] = '\0';
819
 
      else
 
896
    } else
820
897
#endif
821
898
        buf[j] = '\0';
822
899
      return 0;
905
982
  int  col, pt, ocol, opt;
906
983
#ifdef  KANJI
907
984
  static int  k1 = 0, nnn;
 
985
#ifdef  HOJO_KANJI
 
986
  static int  k2 = 0;
 
987
#endif
908
988
#endif
909
989
  struct _Line *lp;
910
990
 
932
1012
      mb_fixlines(ocol, lp, opt, &col, &pt);
933
1013
      mb_refresh(col, pt);
934
1014
    }
 
1015
#ifdef  HOJO_KANJI
 
1016
  } else if (ISHOJO(k1) && k2 == 0) {
 
1017
    if (ISKANJI(c)) {
 
1018
      k2 = c;
 
1019
      nnn = n;
 
1020
    } else {
 
1021
      ocol = _mb_ccol;
 
1022
      opt  = _mb_point;
 
1023
      lp   = CLine;
 
1024
      mb2_insert(n, c);
 
1025
      mb_fixlines(ocol, lp, opt, &col, &pt);
 
1026
      mb_refresh(col, pt);
 
1027
    }
 
1028
#endif  /* HOJO_KANJI */
935
1029
  } else {
936
1030
    ocol = _mb_ccol;
937
1031
    opt  = _mb_point;
938
1032
    lp   = CLine;
939
1033
    while (nnn-- > 0){
940
1034
      mb2_insert(1, k1);
 
1035
#ifdef  HOJO_KANJI
 
1036
      if (k2 != 0) mb2_insert(1, k2);
 
1037
#endif
941
1038
      mb2_insert(1, c);
942
1039
    }
943
1040
    mb_fixlines(ocol, lp, opt, &col, &pt);
944
1041
    mb_refresh(col, pt);
945
1042
    k1 = 0;
 
1043
#ifdef  HOJO_KANJI
 
1044
    k2 = 0;
 
1045
#endif
946
1046
  }
947
1047
#endif /* NOT KANJI */
948
1048
  return 0;
2064
2164
        if (c1==0) c1=1;
2065
2165
        else c1=0;
2066
2166
      } else c1=0;
2067
 
      if (((c & 0xff) == SS2) && (c1 == 1))
 
2167
      if (ISHANKANA(c) && (c1 == 1))
2068
2168
        idx--;
2069
2169
    }
2070
2170
#endif  /* HANKANA */
2086
2186
    *mem  = 1;
2087
2187
#ifdef  KANJI
2088
2188
  } else if (ISKANJI(*s)){
2089
 
#ifdef HANKANA
2090
2189
    *mem  = 2;
2091
 
    if ((*s & 0xff) == SS2)
 
2190
#ifdef  HOJO_KANJI
 
2191
    if (ISHOJO(*s)) {
 
2192
      *mem = 3;
 
2193
      *visu = 2;
 
2194
    } else
 
2195
#endif  /* HOJO_KANJI */
 
2196
#ifdef  HANKANA
 
2197
    if (ISHANKANA(*s))
2092
2198
      *visu = 1;
2093
2199
    else 
2094
 
      *visu = 2;
2095
 
#else   /* HANKANA */
2096
 
    *visu = 2;
2097
 
    *mem  = 2;
2098
2200
#endif  /* HANKANA */
 
2201
    *visu = 2;
2099
2202
#endif  /* KANJI */
2100
2203
  } else {
2101
2204
    *visu = 1;
2113
2216
    *mem  = 1;
2114
2217
#ifdef  KANJI
2115
2218
  } else if (ISKANJI(*s)){
2116
 
#ifdef HANKANA
2117
2219
    *mem  = 2;
2118
 
    if ((*(s-1) & 0xff) == SS2)
 
2220
#ifdef  HOJO_KANJI
 
2221
    if (ISHOJO(*(s-2)) && ISKANJI(*(s-1))) {
 
2222
      *mem = 3;
 
2223
      *visu = 2;
 
2224
    } else
 
2225
#endif  /* HOJO_KANJI */
 
2226
#ifdef  HANKANA
 
2227
    if (ISHANKANA(*(s-1)))
2119
2228
      *visu = 1;
2120
2229
    else 
2121
 
      *visu = 2;
2122
 
#else   /* HANKANA */
2123
 
    *visu = 2;
2124
 
    *mem  = 2;
2125
2230
#endif  /* HANKANA */
 
2231
    *visu = 2;
2126
2232
#endif  /* KANJI */
2127
2233
  } else {
2128
2234
    *visu = 1;
2129
2235
    *mem  = 1;
2130
2236
  }
2131
2237
}
 
2238
 
 
2239
static VOID
 
2240
mb_hist_save(hist_buf, buf)
 
2241
char *hist_buf[];
 
2242
char *buf;
 
2243
{
 
2244
    int i;
 
2245
    if (hist_buf[MB_NHISTS] != NULL)
 
2246
        free(hist_buf[MB_NHISTS]);
 
2247
    /* rotate history */
 
2248
    for (i = MB_NHISTS; i > 1; i--)
 
2249
        hist_buf[i] = hist_buf[i-1];
 
2250
    /* and insert new history to head */
 
2251
    hist_buf[1] = malloc(strlen(buf)+1);
 
2252
    strcpy(hist_buf[1], buf);
 
2253
}
2132
2254
#else   /* NOT MINIBUF_EDIT */
2133
2255
static int veread_del_char ();
2134
2256
static int veread_complete ();
2330
2452
    else if (ISKANJI(buf[cpos]))
2331
2453
      {
2332
2454
#ifdef HANKANA  /* 92.11.21  by S.Sasaki */
2333
 
        if ( (buf[--cpos] & 0xff) != SS2 ) {
 
2455
        if (!ISHANKANA(buf[--cpos])) {
2334
2456
            ttputc('\b');
2335
2457
            ttputc(' ');
2336
2458
            ttputc('\b');
2523
2645
#ifdef  KANJI   /* 90.01.29  by S.Yoshida */
2524
2646
                                else if (ISKANJI(buf[cpos])) {
2525
2647
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
2526
 
                                        if ( (buf[--cpos] & 0xff) != SS2 ) {
 
2648
                                        if (!ISHANKANA(buf[--cpos])) {
2527
2649
                                        ttputc('\b');
2528
2650
                                        ttputc(' ');
2529
2651
                                        ttputc('\b');
2559
2681
#ifdef  KANJI   /* 90.01.29  by S.Yoshida */
2560
2682
                                else if (ISKANJI(buf[cpos])) {
2561
2683
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
2562
 
                                        if ( (buf[--cpos] & 0xff) != SS2 ) {
 
2684
                                        if (!ISHANKANA(buf[--cpos])) {
2563
2685
                                            ttputc('\b');
2564
2686
                                            ttputc(' ');
2565
2687
                                            ttputc('\b');
2616
2738
#ifdef  KANJI   /* 90.01.29  by S.Yoshida */
2617
2739
                                else if (ISKANJI(buf[cpos])) {
2618
2740
#ifdef HANKANA  /* 92.11.21  by S.Sasaki  */
2619
 
                                        if ( (buf[--cpos] & 0xff) == SS2 ) {
 
2741
                                        if (ISHANKANA(buf[--cpos])) {
2620
2742
                                            ttputc('\b');
2621
2743
                                            ttputc(' ');
2622
2744
                                            ttputc('\b');
2994
3116
                        c = CCHR(c);
2995
3117
                }
2996
3118
#ifdef  KANJI   /* 90.01.29  by S.Yoshida */
2997
 
#ifdef HANKANA  /* 92.11.21  by S.Sasaki */
 
3119
#ifdef  SS_SUPPORT /* 92.11.21  by S.Sasaki */
2998
3120
                {
2999
3121
                    static int c1=0;
3000
3122
 
3001
3123
                    if (ISKANJI(c)) {
 
3124
#ifdef  HOJO_KANJI
 
3125
                        if (ISHOJO(c)) {
 
3126
                            c1 = 2;
 
3127
                            ttcol--;
 
3128
                        } else
 
3129
#endif
3002
3130
                        if (c1==0) c1=1;
3003
 
                        else c1=0;
 
3131
                        else c1--;
3004
3132
                    } else c1=0;
3005
 
                    if ( (c & 0xff) == SS2 && c1 == 1)
 
3133
#ifdef  HANKANA
 
3134
                    if (ISHANKANA(c) && c1 == 1)
3006
3135
                        ttcol--;
 
3136
#endif
3007
3137
                }
3008
 
#endif  /* HANKANA */
 
3138
#endif  /* SS_SUPPORT */
3009
3139
                kttputc(c);
3010
3140
#else   /* NOT KANJI */
3011
3141
                ttputc(c);