home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume35 / ee / part02 < prev    next >
Encoding:
Text File  |  1993-02-21  |  55.2 KB  |  2,368 lines

  1. Newsgroups: comp.sources.misc
  2. From: hugh@nsmdserv.cnd.hp.com (Hugh F. Mahon)
  3. Subject: v35i081:  ee - Easy Editor, a simple editor for UNIX, Part02/05
  4. Message-ID: <1993Feb22.041259.15251@sparky.imd.sterling.com>
  5. X-Md4-Signature: 4e3f3e5eb3d6578e80dc03b5490bd572
  6. Date: Mon, 22 Feb 1993 04:12:59 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: hugh@nsmdserv.cnd.hp.com (Hugh F. Mahon)
  10. Posting-number: Volume 35, Issue 81
  11. Archive-name: ee/part02
  12. Environment: SYSV, SunOS, Curses
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  ee.c.B
  19. # Wrapped by kent@sparky on Sat Feb 20 21:31:18 1993
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 2 (of 5)."'
  23. if test -f 'ee.c.B' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'ee.c.B'\"
  25. else
  26.   echo shar: Extracting \"'ee.c.B'\" \(52272 characters\)
  27.   sed "s/^X//" >'ee.c.B' <<'END_OF_FILE'
  28. Xdraw_screen()        /* redraw the screen from current postion    */
  29. X{
  30. X    struct text *temp_line;
  31. X    char *line_out;
  32. X    int temp_vert;
  33. X
  34. X    temp_line = curr_line;
  35. X    temp_vert = scr_vert;
  36. X    wclrtobot(text_win);
  37. X    while ((temp_line != NULL) && (temp_vert <= last_line))
  38. X    {
  39. X        line_out = temp_line->line;
  40. X        draw_line(temp_vert, 0, line_out, 1, temp_line->line_length);
  41. X        temp_vert++;
  42. X        temp_line = temp_line->next_line;
  43. X    }
  44. X    wmove(text_win, temp_vert, 0);
  45. X    wmove(text_win, scr_vert, (scr_horz - horiz_offset));
  46. X}
  47. X
  48. Xfinish()    /* prepare to exit edit session    */
  49. X{
  50. X    char *file_name = in_file_name;
  51. X
  52. X    /*
  53. X     |    changes made here should be reflected in the 'save' 
  54. X     |    portion of file_op()
  55. X     */
  56. X
  57. X    if ((file_name == NULL) || (*file_name == NULL))
  58. X        file_name = get_string(save_file_name_prompt, TRUE);
  59. X
  60. X    if ((file_name == NULL) || (*file_name == NULL))
  61. X    {
  62. X        wmove(com_win, 0, 0);
  63. X        wprintw(com_win, file_not_saved_msg);
  64. X        wclrtoeol(com_win);
  65. X        wrefresh(com_win);
  66. X        clear_com_win = TRUE;
  67. X        return;
  68. X    }
  69. X
  70. X    tmp_file = resolve_name(file_name);
  71. X    if (tmp_file != file_name)
  72. X    {
  73. X        free(file_name);
  74. X        file_name = tmp_file;
  75. X    }
  76. X
  77. X    if (write_file(file_name))
  78. X    {
  79. X        text_changes = FALSE;
  80. X        quit(0);
  81. X    }
  82. X}
  83. X
  84. Xquit(noverify)        /* exit editor            */
  85. Xint noverify;
  86. X{
  87. X    char *ans;
  88. X
  89. X    touchwin(text_win);
  90. X    wrefresh(text_win);
  91. X    if ((text_changes) && (!noverify))
  92. X    {
  93. X        ans = get_string(changes_made_prompt, TRUE);
  94. X        if (toupper(*ans) == toupper(*yes_char))
  95. X            text_changes = FALSE;
  96. X        else
  97. X            return;
  98. X        free(ans);
  99. X    }
  100. X    if (top_of_stack == NULL)
  101. X    {
  102. X        if (info_window)
  103. X            wrefresh(info_win);
  104. X        wrefresh(com_win);
  105. X        resetty();
  106. X        endwin();
  107. X        putchar('\n');
  108. X        exit(0);
  109. X    }
  110. X    else
  111. X    {
  112. X        delete_text();
  113. X        recv_file = TRUE;
  114. X        input_file = TRUE;
  115. X        check_fp();
  116. X    }
  117. X}
  118. X
  119. Xabort()
  120. X{
  121. X    wrefresh(com_win);
  122. X    resetty();
  123. X    endwin();
  124. X    putchar('\n');
  125. X    exit(1);
  126. X}
  127. X
  128. Xdelete_text()
  129. X{
  130. X    while (curr_line->next_line != NULL)
  131. X        curr_line = curr_line->next_line;
  132. X    while (curr_line != first_line)
  133. X    {
  134. X        free(curr_line->line);
  135. X        curr_line = curr_line->prev_line;
  136. X        free(curr_line->next_line);
  137. X    }
  138. X    curr_line->next_line = NULL;
  139. X    curr_line->line = NULL;
  140. X    curr_line->line_length = 1;
  141. X    curr_line->line_number = 1;
  142. X    point = curr_line->line;
  143. X    scr_pos = scr_vert = scr_horz = 0;
  144. X    position = 1;
  145. X}
  146. X
  147. Xwrite_file(file_name)
  148. Xchar *file_name;
  149. X{
  150. X    char cr;
  151. X    char *tmp_point;
  152. X    struct text *out_line;
  153. X    int lines, charac;
  154. X    int temp_pos;
  155. X    int write_flag = TRUE;
  156. X
  157. X    charac = lines = 0;
  158. X    if (strcmp(in_file_name, file_name))
  159. X    {
  160. X        if (temp_fp = fopen(file_name, "r"))
  161. X        {
  162. X            tmp_point = get_string(file_exists_prompt, TRUE);
  163. X            if (toupper(*tmp_point) == toupper(*yes_char))
  164. X                write_flag = TRUE;
  165. X            else 
  166. X                write_flag = FALSE;
  167. X            fclose(temp_fp);
  168. X            free(tmp_point);
  169. X        }
  170. X    }
  171. X
  172. X    clear_com_win = TRUE;
  173. X
  174. X    if (write_flag)
  175. X    {
  176. X        if ((temp_fp = fopen(file_name, "w")) == NULL)
  177. X        {
  178. X            clear_com_win = TRUE;
  179. X            wmove(com_win,0,0);
  180. X            wclrtoeol(com_win);
  181. X            wprintw(com_win, create_file_fail_msg, file_name);
  182. X            wrefresh(com_win);
  183. X            return(FALSE);
  184. X        }
  185. X        else
  186. X        {
  187. X            wmove(com_win,0,0);
  188. X            wclrtoeol(com_win);
  189. X            wprintw(com_win, writing_file_msg, file_name);
  190. X            wrefresh(com_win);
  191. X            cr = '\n';
  192. X            out_line = first_line;
  193. X            while (out_line != NULL)
  194. X            {
  195. X                temp_pos = 1;
  196. X                tmp_point= out_line->line;
  197. X                while (temp_pos < out_line->line_length)
  198. X                {
  199. X                    putc(*tmp_point, temp_fp);
  200. X                    tmp_point++;
  201. X                    temp_pos++;
  202. X                }
  203. X                charac += out_line->line_length;
  204. X                out_line = out_line->next_line;
  205. X                putc(cr, temp_fp);
  206. X                lines++;
  207. X            }
  208. X            fclose(temp_fp);
  209. X            wmove(com_win,0,0);
  210. X            wclrtoeol(com_win);
  211. X            wprintw(com_win, file_written_msg, file_name, lines, charac);
  212. X            wrefresh(com_win);
  213. X            return(TRUE);
  214. X        }
  215. X    }
  216. X    else
  217. X        return(FALSE);
  218. X}
  219. X
  220. Xsearch(display_message)        /* search for string in srch_str    */
  221. Xint display_message;
  222. X{
  223. X    int lines_moved;
  224. X    int iter;
  225. X    int found;
  226. X
  227. X    if ((srch_str == NULL) || (*srch_str == NULL))
  228. X        return(FALSE);
  229. X    if (display_message)
  230. X    {
  231. X        wmove(com_win, 0, 0);
  232. X        wclrtoeol(com_win);
  233. X        wprintw(com_win, searching_msg);
  234. X        wrefresh(com_win);
  235. X        clear_com_win = TRUE;
  236. X    }
  237. X    lines_moved = 0;
  238. X    found = FALSE;
  239. X    srch_line = curr_line;
  240. X    srch_1 = point;
  241. X    if (position < curr_line->line_length)
  242. X        srch_1++;
  243. X    iter = position + 1;
  244. X    while ((!found) && (srch_line != NULL))
  245. X    {
  246. X        while ((iter < srch_line->line_length) && (!found))
  247. X        {
  248. X            srch_2 = srch_1;
  249. X            if (case_sen)    /* if case sensitive        */
  250. X            {
  251. X                srch_3 = srch_str;
  252. X            while ((*srch_2 == *srch_3) && (*srch_3 != NULL))
  253. X                {
  254. X                    found = TRUE;
  255. X                    srch_2++;
  256. X                    srch_3++;
  257. X                }    /* end while    */
  258. X            }
  259. X            else        /* if not case sensitive    */
  260. X            {
  261. X                srch_3 = u_srch_str;
  262. X            while ((toupper(*srch_2) == *srch_3) && (*srch_3 != NULL))
  263. X                {
  264. X                    found = TRUE;
  265. X                    srch_2++;
  266. X                    srch_3++;
  267. X                }
  268. X            }    /* end else    */
  269. X            if (!((*srch_3 == NULL) && (found)))
  270. X            {
  271. X                found = FALSE;
  272. X                if (iter < srch_line->line_length)
  273. X                    srch_1++;
  274. X                iter++;
  275. X            }
  276. X        }
  277. X        if (!found)
  278. X        {
  279. X            srch_line = srch_line->next_line;
  280. X            if (srch_line != NULL)
  281. X                srch_1 = srch_line->line;
  282. X            iter = 1;
  283. X            lines_moved++;
  284. X        }
  285. X    }
  286. X    if (found)
  287. X    {
  288. X        if (display_message)
  289. X        {
  290. X            wmove(com_win, 0, 0);
  291. X            wclrtoeol(com_win);
  292. X            wrefresh(com_win);
  293. X        }
  294. X        if (lines_moved == 0)
  295. X        {
  296. X            while (position < iter)
  297. X                right(TRUE);
  298. X        }
  299. X        else
  300. X        {
  301. X            if (lines_moved < 30)
  302. X            {
  303. X                move_rel("d", lines_moved);
  304. X                while (position < iter)
  305. X                    right(TRUE);
  306. X            }
  307. X            else 
  308. X            {
  309. X                curr_line = srch_line;
  310. X                point = srch_1;
  311. X                position = iter;
  312. X                scanline(point);
  313. X                scr_pos = scr_horz;
  314. X                midscreen((last_line / 2), point);
  315. X            }
  316. X        }
  317. X    }
  318. X    else
  319. X    {
  320. X        if (display_message)
  321. X        {
  322. X            wmove(com_win, 0, 0);
  323. X            wclrtoeol(com_win);
  324. X            wprintw(com_win, str_not_found_msg, srch_str);
  325. X            wrefresh(com_win);
  326. X        }
  327. X        wmove(text_win, scr_vert,(scr_horz - horiz_offset));
  328. X    }
  329. X    return(found);
  330. X}
  331. X
  332. Xsearch_prompt()        /* prompt and read search string (srch_str)    */
  333. X{
  334. X    if (srch_str != NULL)
  335. X        free(srch_str);
  336. X    if ((u_srch_str != NULL) && (*u_srch_str != NULL))
  337. X        free(u_srch_str);
  338. X    srch_str = get_string(search_prompt_str, FALSE);
  339. X    gold = FALSE;
  340. X    srch_3 = srch_str;
  341. X    srch_1 = u_srch_str = malloc(strlen(srch_str) + 1);
  342. X    while (*srch_3 != NULL)
  343. X    {
  344. X        *srch_1 = toupper(*srch_3);
  345. X        srch_1++;
  346. X        srch_3++;
  347. X    }
  348. X    *srch_1 = NULL;
  349. X    search(TRUE);
  350. X}
  351. X
  352. Xdel_char()            /* delete current character    */
  353. X{
  354. X    in = 8;  /* backspace */
  355. X    if (position < curr_line->line_length)    /* if not end of line    */
  356. X    {
  357. X        position++;
  358. X        point++;
  359. X        scanline(point);
  360. X        delete(TRUE);
  361. X    }
  362. X    else
  363. X    {
  364. X        right(FALSE);
  365. X        delete(FALSE);
  366. X    }
  367. X}
  368. X
  369. Xundel_char()            /* undelete last deleted character    */
  370. X{
  371. X    if (d_char == '\n')    /* insert line if last del_char deleted eol */
  372. X        insert_line(TRUE);
  373. X    else
  374. X    {
  375. X        in = d_char;
  376. X        insert(in);
  377. X    }
  378. X}
  379. X
  380. Xdel_word()            /* delete word in front of cursor    */
  381. X{
  382. X    int tposit;
  383. X    int difference;
  384. X    char *d_word2;
  385. X    char *d_word3;
  386. X    char tmp_char;
  387. X
  388. X    if (d_word != NULL)
  389. X        free(d_word);
  390. X    d_word = malloc(curr_line->line_length);
  391. X    tmp_char = d_char;
  392. X    d_word3 = point;
  393. X    d_word2 = d_word;
  394. X    tposit = position;
  395. X    while ((tposit < curr_line->line_length) && 
  396. X                ((*d_word3 != ' ') && (*d_word3 != '\t')))
  397. X    {
  398. X        tposit++;
  399. X        *d_word2 = *d_word3;
  400. X        d_word2++;
  401. X        d_word3++;
  402. X    }
  403. X    while ((tposit < curr_line->line_length) && 
  404. X                ((*d_word3 == ' ') || (*d_word3 == '\t')))
  405. X    {
  406. X        tposit++;
  407. X        *d_word2 = *d_word3;
  408. X        d_word2++;
  409. X        d_word3++;
  410. X    }
  411. X    *d_word2 = NULL;
  412. X    d_wrd_len = difference = d_word2 - d_word;
  413. X    d_word2 = point;
  414. X    while (tposit < curr_line->line_length)
  415. X    {
  416. X        tposit++;
  417. X        *d_word2 = *d_word3;
  418. X        d_word2++;
  419. X        d_word3++;
  420. X    }
  421. X    curr_line->line_length -= difference;
  422. X    *d_word2 = NULL;
  423. X    draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
  424. X    d_char = tmp_char;
  425. X    text_changes = TRUE;
  426. X    formatted = FALSE;
  427. X}
  428. X
  429. Xundel_word()        /* undelete last deleted word        */
  430. X{
  431. X    int temp;
  432. X    int tposit;
  433. X    char *tmp_old_ptr;
  434. X    char *tmp_space;
  435. X    char *tmp_ptr;
  436. X    char *d_word_ptr;
  437. X
  438. X    /*
  439. X     |    resize line to handle undeleted word
  440. X     */
  441. X    if ((curr_line->max_length - (curr_line->line_length + d_wrd_len)) < 5)
  442. X        point = resiz_line(d_wrd_len, curr_line, position);
  443. X    tmp_ptr = tmp_space = malloc(curr_line->line_length + d_wrd_len);
  444. X    d_word_ptr = d_word;
  445. X    temp = 1;
  446. X    /*
  447. X     |    copy d_word contents into temp space
  448. X     */
  449. X    while (temp <= d_wrd_len)
  450. X    {
  451. X        temp++;
  452. X        *tmp_ptr = *d_word_ptr;
  453. X        tmp_ptr++;
  454. X        d_word_ptr++;
  455. X    }
  456. X    tmp_old_ptr = point;
  457. X    tposit = position;
  458. X    /*
  459. X     |    copy contents of line from curent position to eol into 
  460. X     |    temp space
  461. X     */
  462. X    while (tposit < curr_line->line_length)
  463. X    {
  464. X        temp++;
  465. X        tposit++;
  466. X        *tmp_ptr = *tmp_old_ptr;
  467. X        tmp_ptr++;
  468. X        tmp_old_ptr++;
  469. X    }
  470. X    curr_line->line_length += d_wrd_len;
  471. X    tmp_old_ptr = point;
  472. X    *tmp_ptr = NULL;
  473. X    tmp_ptr = tmp_space;
  474. X    tposit = 1;
  475. X    /*
  476. X     |    now copy contents from temp space back to original line
  477. X     */
  478. X    while (tposit < temp)
  479. X    {
  480. X        tposit++;
  481. X        *tmp_old_ptr = *tmp_ptr;
  482. X        tmp_ptr++;
  483. X        tmp_old_ptr++;
  484. X    }
  485. X    *tmp_old_ptr = NULL;
  486. X    free(tmp_space);
  487. X    draw_line(scr_vert, scr_horz, point, position, curr_line->line_length);
  488. X}
  489. X
  490. Xdel_line()            /* delete from cursor to end of line    */
  491. X{
  492. X    char *dl1;
  493. X    char *dl2;
  494. X    int tposit;
  495. X
  496. X    if (d_line != NULL)
  497. X        free(d_line);
  498. X    d_line = malloc(curr_line->line_length);
  499. X    dl1 = d_line;
  500. X    dl2 = point;
  501. X    tposit = position;
  502. X    while (tposit < curr_line->line_length)
  503. X    {
  504. X        *dl1 = *dl2;
  505. X        dl1++;
  506. X        dl2++;
  507. X        tposit++;
  508. X    }
  509. X    dlt_line->line_length = 1 + tposit - position;
  510. X    *dl1 = NULL;
  511. X    *point = NULL;
  512. X    curr_line->line_length = position;
  513. X    wclrtoeol(text_win);
  514. X    if (curr_line->next_line != NULL)
  515. X    {
  516. X        right(FALSE);
  517. X        delete(FALSE);
  518. X    }
  519. X    text_changes = TRUE;
  520. X}
  521. X
  522. Xundel_line()            /* undelete last deleted line        */
  523. X{
  524. X    char *ud1;
  525. X    char *ud2;
  526. X    int tposit;
  527. X
  528. X    insert_line(TRUE);
  529. X    left(TRUE);
  530. X    point = resiz_line(dlt_line->line_length, curr_line, position);
  531. X    curr_line->line_length += dlt_line->line_length - 1;
  532. X    ud1 = point;
  533. X    ud2 = d_line;
  534. X    tposit = 1;
  535. X    while (tposit < dlt_line->line_length)
  536. X    {
  537. X        tposit++;
  538. X        *ud1 = *ud2;
  539. X        ud1++;
  540. X        ud2++;
  541. X    }
  542. X    *ud1 = NULL;
  543. X    draw_line(scr_vert, scr_horz,point,position,curr_line->line_length);
  544. X}
  545. X
  546. Xadv_word()            /* advance to next word        */
  547. X{
  548. Xwhile ((position < curr_line->line_length) && ((*point != 32) && (*point != 9)))
  549. X        right(TRUE);
  550. Xwhile ((position < curr_line->line_length) && ((*point == 32) || (*point == 9)))
  551. X        right(TRUE);
  552. X}
  553. X
  554. Xmove_rel(direction, lines)    /* move relative to current line    */
  555. Xchar *direction;
  556. Xint lines;
  557. X{
  558. X    int i;
  559. X    char *tmp;
  560. X
  561. X    if (*direction == 'u')
  562. X    {
  563. X        scr_pos = 0;
  564. X        while (position > 1)
  565. X            left(TRUE);
  566. X        for (i = 0; i < lines; i++)
  567. X        {
  568. X            up();
  569. X        }
  570. X        if ((last_line > 5) && ( scr_vert < 4))
  571. X        {
  572. X            tmp = point;
  573. X            tmp_line = curr_line;
  574. X            for (i= 0;(i<5)&&(curr_line->prev_line != NULL); i++)
  575. X            {
  576. X                up();
  577. X            }
  578. X            scr_vert = scr_vert + i;
  579. X            curr_line = tmp_line;
  580. X            point = tmp;
  581. X            scanline(point);
  582. X        }
  583. X    }
  584. X    else
  585. X    {
  586. X        if ((position != 1) && (curr_line->next_line != NULL))
  587. X        {
  588. X            nextline();
  589. X            scr_pos = scr_horz = 0;
  590. X            if (horiz_offset)
  591. X            {
  592. X                horiz_offset = 0;
  593. X                midscreen(scr_vert, point);
  594. X            }
  595. X        }
  596. X        else
  597. X            adv_line();
  598. X        for (i = 1; i < lines; i++)
  599. X        {
  600. X            down();
  601. X        }
  602. X        if ((last_line > 10) && (scr_vert > (last_line - 5)))
  603. X        {
  604. X            tmp = point;
  605. X            tmp_line = curr_line;
  606. X            for (i=0; (i<5) && (curr_line->next_line != NULL); i++)
  607. X            {
  608. X                down(TRUE);
  609. X            }
  610. X            scr_vert = scr_vert - i;
  611. X            curr_line = tmp_line;
  612. X            point = tmp;
  613. X            scanline(point);
  614. X        }
  615. X    }
  616. X    wmove(text_win, scr_vert, (scr_horz - horiz_offset));
  617. X}
  618. X
  619. Xeol()                /* go to end of line            */
  620. X{
  621. X    if (position < curr_line->line_length)
  622. X    {
  623. X        while (position < curr_line->line_length)
  624. X            right(TRUE);
  625. X    }
  626. X    else if (curr_line->next_line != NULL)
  627. X    {
  628. X        right(TRUE);
  629. X        while (position < curr_line->line_length)
  630. X            right(TRUE);
  631. X    }
  632. X}
  633. X
  634. Xbol()                /* move to beginning of line    */
  635. X{
  636. X    if (point != curr_line->line)
  637. X    {
  638. X        while (point != curr_line->line)
  639. X            left(TRUE);
  640. X    }
  641. X    else if (curr_line->prev_line != NULL)
  642. X    {
  643. X        scr_pos = 0;
  644. X        up(TRUE);
  645. X    }
  646. X}
  647. X
  648. Xadv_line()    /* advance to beginning of next line    */
  649. X{
  650. X    if ((point != curr_line->line) || (scr_pos > 0))
  651. X    {
  652. X        while (position < curr_line->line_length)
  653. X            right(TRUE);
  654. X        right(TRUE);
  655. X    }
  656. X    else if (curr_line->next_line != NULL)
  657. X    {
  658. X        scr_pos = 0;
  659. X        down(TRUE);
  660. X    }
  661. X}
  662. X
  663. Xsh_command(string)    /* execute shell command            */
  664. Xchar *string;        /* string containing user command        */
  665. X{
  666. X    char *temp_point;
  667. X    char *last_slash;
  668. X    char *path;        /* directory path to executable        */
  669. X    int parent;        /* zero if child, child's pid if parent    */
  670. X    int value;
  671. X    int return_val;
  672. X    struct text *line_holder;
  673. X
  674. X    if (restrict_mode())
  675. X    {
  676. X        return;
  677. X    }
  678. X
  679. X    if (!(path = getenv("SHELL")))
  680. X        path = "/bin/sh";
  681. X    last_slash = temp_point = path;
  682. X    while (*temp_point != NULL)
  683. X    {
  684. X        if (*temp_point == '/')
  685. X            last_slash = ++temp_point;
  686. X        else
  687. X            temp_point++;
  688. X    }
  689. X    keypad(com_win, FALSE);
  690. X    keypad(text_win, FALSE);
  691. X    echo();
  692. X    noraw();
  693. X    resetty();
  694. X
  695. X#ifndef NCURSE
  696. X    endwin();
  697. X#endif
  698. X
  699. X    if (in_pipe)
  700. X    {
  701. X        pipe(pipe_in);        /* create a pipe    */
  702. X        parent = fork();
  703. X        if (!parent)        /* if the child        */
  704. X        {
  705. X/*
  706. X |  child process which will fork and exec shell command (if shell output is
  707. X |  to be read by editor)
  708. X */
  709. X            in_pipe = FALSE;
  710. X/*
  711. X |  redirect stdout to pipe
  712. X */
  713. X            temp_stdout = dup(1);
  714. X            close(1);
  715. X            dup(pipe_in[1]);
  716. X/*
  717. X |  redirect stderr to pipe
  718. X */
  719. X            temp_stderr = dup(2);
  720. X            close(2);
  721. X            dup(pipe_in[1]);
  722. X            close(pipe_in[1]);
  723. X            /*
  724. X             |    child will now continue down 'if (!in_pipe)' 
  725. X             |    path below
  726. X             */
  727. X        }
  728. X        else  /* if the parent    */
  729. X        {
  730. X/*
  731. X |  prepare editor to read from the pipe
  732. X */
  733. X            signal(SIGCHLD, SIG_IGN);
  734. X            line_holder = curr_line;
  735. X            tmp_vert = scr_vert;
  736. X            close(pipe_in[1]);
  737. X            get_fd = pipe_in[0];
  738. X            get_file("");
  739. X            close(pipe_in[0]);
  740. X            scr_vert = tmp_vert;
  741. X            scr_horz = scr_pos = 0;
  742. X            position = 1;
  743. X            curr_line = line_holder;
  744. X            point = curr_line->line;
  745. X            out_pipe = FALSE;
  746. X            signal(SIGCHLD, SIG_DFL);
  747. X/*
  748. X |  since flag "in_pipe" is still TRUE, the path which waits for the child 
  749. X |  process to die will be avoided.
  750. X |  (the pipe is closed, no more output can be expected)
  751. X */
  752. X        }
  753. X    }
  754. X    if (!in_pipe)
  755. X    {
  756. X        signal(SIGINT, SIG_IGN);
  757. X        if (out_pipe)
  758. X        {
  759. X            pipe(pipe_out);
  760. X        }
  761. X/*
  762. X |  fork process which will exec command
  763. X */
  764. X        parent = fork();   
  765. X        if (!parent)        /* if the child    */
  766. X        {
  767. X            if (shell_fork)
  768. X                putchar('\n');
  769. X            if (out_pipe)
  770. X            {
  771. X/*
  772. X |  prepare the child process (soon to exec a shell command) to read from the 
  773. X |  pipe (which will be output from the editor's buffer)
  774. X */
  775. X                close(0);
  776. X                dup(pipe_out[0]);
  777. X                close(pipe_out[0]);
  778. X                close(pipe_out[1]);
  779. X            }
  780. X            for (value = 1; value < 24; value++)
  781. X                signal(value, SIG_DFL);
  782. X            execl(path, last_slash, "-c", string, NULL);
  783. X            printf(exec_err_msg, path);
  784. X            exit(-1);
  785. X        }
  786. X        else    /* if the parent    */
  787. X        {
  788. X            if (out_pipe)
  789. X            {
  790. X/*
  791. X |  output the contents of the buffer to the pipe (to be read by the 
  792. X |  process forked and exec'd above as stdin)
  793. X */
  794. X                close(pipe_out[0]);
  795. X                line_holder = first_line;
  796. X                while (line_holder != NULL)
  797. X                {
  798. X                    write(pipe_out[1], line_holder->line, (line_holder->line_length-1));
  799. X                    write(pipe_out[1], "\n", 1);
  800. X                    line_holder = line_holder->next_line;
  801. X                }
  802. X                close(pipe_out[1]);
  803. X                out_pipe = FALSE;
  804. X            }
  805. X            do
  806. X            {
  807. X                return_val = wait((int *) 0);
  808. X            }
  809. X            while (return_val != parent);
  810. X/*
  811. X |  if this process is actually the child of the editor, exit.  Here's how it 
  812. X |  works:
  813. X |  The editor forks a process.  If output must be sent to the command to be 
  814. X |  exec'd another process is forked, and that process (the child's child) 
  815. X |  will exec the command.  In this case, "shell_fork" will be FALSE.  If no 
  816. X |  output is to be performed to the shell command, "shell_fork" will be TRUE.
  817. X |  If this is the editor process, shell_fork will be true, otherwise this is 
  818. X |  the child of the edit process.
  819. X */
  820. X            if (!shell_fork)
  821. X                exit(0);
  822. X        }
  823. X        signal(SIGINT, abort);
  824. X    }
  825. X    if (shell_fork)
  826. X    {
  827. X        printf(continue_msg);
  828. X        fflush(stdout);
  829. X        while ((in = getchar()) != '\n')
  830. X            ;
  831. X    }
  832. X
  833. X#ifdef NCURSE
  834. X    fixterm();
  835. X    noecho();
  836. X    raw();
  837. X    keypad(text_win, TRUE);
  838. X    keypad(com_win, TRUE);
  839. X    if (info_window)
  840. X        clearok(info_win, TRUE);
  841. X#else
  842. X    set_up_term();
  843. X#endif
  844. X
  845. X    redraw();
  846. X}
  847. X
  848. Xset_up_term()        /* set up the terminal for operating with ae    */
  849. X{
  850. X    initscr();
  851. X    savetty();
  852. X    noecho();
  853. X    raw();
  854. X
  855. X    if (((LINES > 15) && (COLS >= 80)) && info_window)
  856. X        last_line = LINES - 8;
  857. X    else
  858. X    {
  859. X        info_window = FALSE;
  860. X        last_line = LINES - 2;
  861. X    }
  862. X
  863. X    idlok(stdscr, TRUE);
  864. X    com_win = newwin(1, COLS, (LINES - 1), 0);
  865. X    keypad(com_win, TRUE);
  866. X    idlok(com_win, TRUE);
  867. X    wrefresh(com_win);
  868. X    if (!info_window)
  869. X        text_win = newwin((LINES - 1), COLS, 0, 0);
  870. X    else
  871. X        text_win = newwin((LINES - 7), COLS, 6, 0);
  872. X    keypad(text_win, TRUE);
  873. X    idlok(text_win, TRUE);
  874. X    wrefresh(text_win);
  875. X    help_win = newwin((LINES - 1), COLS, 0, 0);
  876. X    keypad(help_win, TRUE);
  877. X    idlok(help_win, TRUE);
  878. X    if (info_window)
  879. X    {
  880. X        info_type = CONTROL_KEYS;
  881. X        info_win = newwin(6, COLS, 0, 0);
  882. X        werase(info_win);
  883. X        paint_info_win();
  884. X    }
  885. X
  886. X    last_col = COLS - 1;
  887. X}
  888. X
  889. Xmenu_op(menu_list)
  890. Xstruct menu_entries menu_list[];
  891. X{
  892. X    WINDOW *temp_win;
  893. X    int max_width, max_height;
  894. X    int x_off, y_off;
  895. X    int counter;
  896. X    int length;
  897. X    int input;
  898. X    int list_size;
  899. X    int top_offset;
  900. X    int temp_int;
  901. X    char *cancel_string = menu_cancel_msg;
  902. X
  903. X    /*
  904. X     |    determine number and width of menu items
  905. X     */
  906. X
  907. X    list_size = 1;
  908. X    while (menu_list[list_size + 1].item_string != NULL)
  909. X        list_size++;
  910. X    max_width = strlen(cancel_string);
  911. X    for (counter = 0; counter <= list_size; counter++)
  912. X    {
  913. X        if ((length = strlen(menu_list[counter].item_string)) > max_width)
  914. X            max_width = length;
  915. X    }
  916. X    max_width += 6;
  917. X
  918. X    /*
  919. X     |    make sure that window is large enough to handle menu
  920. X     |    if not, print error message and return to calling function
  921. X     */
  922. X
  923. X    if ((LINES < list_size) || (max_width > COLS))
  924. X    {
  925. X        wmove(com_win, 0, 0);
  926. X        werase(com_win);
  927. X        wprintw(com_win, menu_size_err_msg);
  928. X        clear_com_win = TRUE;
  929. X        return(0);
  930. X    }
  931. X
  932. X    top_offset = 0;
  933. X    max_height = list_size;
  934. X
  935. X    if (LINES >= (list_size + 8))
  936. X    {
  937. X        max_height = list_size + 8;
  938. X        top_offset = 4;
  939. X    }
  940. X    x_off = (COLS - max_width) / 2;
  941. X    y_off = (LINES - max_height - 1) / 2;
  942. X    temp_win = newwin(max_height, max_width, y_off, x_off);
  943. X    keypad(temp_win, TRUE);
  944. X    werase(temp_win);
  945. X
  946. X    /*
  947. X     |    output top and bottom portions of menu box only if window 
  948. X     |    large enough 
  949. X     */
  950. X
  951. X    if (max_height > list_size)
  952. X    {
  953. X        wmove(temp_win, 1, 1);
  954. X        if (!nohighlight)
  955. X            wstandout(temp_win);
  956. X        waddch(temp_win, '+');
  957. X        for (counter = 0; counter < (max_width - 4); counter++)
  958. X            waddch(temp_win, '-');
  959. X        waddch(temp_win, '+');
  960. X
  961. X        wmove(temp_win, (max_height - 2), 1);
  962. X        waddch(temp_win, '+');
  963. X        for (counter = 0; counter < (max_width - 4); counter++)
  964. X            waddch(temp_win, '-');
  965. X        waddch(temp_win, '+');
  966. X        wstandend(temp_win);
  967. X        wmove(temp_win, 2, 3);
  968. X        waddstr(temp_win, menu_list[0].item_string);
  969. X        wmove(temp_win, (max_height - 3), 3);
  970. X        waddstr(temp_win, cancel_string);
  971. X    }
  972. X    if (!nohighlight)
  973. X        wstandout(temp_win);
  974. X    for (counter = 0; counter < (list_size + top_offset); counter++)
  975. X    {
  976. X        if (top_offset == 4)
  977. X        {
  978. X            temp_int = counter + 2;
  979. X        }
  980. X        else
  981. X            temp_int = counter;
  982. X
  983. X        wmove(temp_win, temp_int, 1);
  984. X        waddch(temp_win, '|');
  985. X        wmove(temp_win, temp_int, (max_width - 2));
  986. X        waddch(temp_win, '|');
  987. X    }
  988. X    wstandend(temp_win);
  989. X    for (counter = 1; counter <= list_size; counter++)
  990. X    {
  991. X        wmove(temp_win, (top_offset + counter - 1), 3);
  992. X        waddstr(temp_win, menu_list[counter].item_string);
  993. X    }
  994. X    counter = 1;
  995. X    do
  996. X    {
  997. X        wmove(temp_win, (counter + top_offset - 1), 3);
  998. X        wrefresh(temp_win);
  999. X        input = wgetch(temp_win);
  1000. X        if (input == -1)
  1001. X            exit(0);
  1002. X        switch (input)
  1003. X        {
  1004. X            case ' ':    /* space    */
  1005. X            case '\022':    /* ^r, right    */
  1006. X            case '\004':    /* ^d, down    */
  1007. X            case KEY_RIGHT:
  1008. X            case KEY_DOWN:
  1009. X                counter++;
  1010. X                if (counter > list_size)
  1011. X                    counter = 1;
  1012. X                break;
  1013. X            case '\010':    /* ^h, backspace*/
  1014. X            case '\014':    /* ^l, left    */
  1015. X            case '\025':    /* ^u, up    */
  1016. X            case KEY_LEFT:
  1017. X            case KEY_UP:
  1018. X                counter--;
  1019. X                if (counter == 0)
  1020. X                    counter = list_size;
  1021. X                break;
  1022. X            case '\033':    /* escape key    */
  1023. X                counter = 0;
  1024. X                break;
  1025. X            default:
  1026. X                break;
  1027. X        }
  1028. X    }
  1029. X    while ((input != '\r') && (input != '\n') && (input != '\033'));
  1030. X
  1031. X    werase(temp_win);
  1032. X    wrefresh(temp_win);
  1033. X    delwin(temp_win);
  1034. X
  1035. X    if (menu_list[counter].procedure != NULL)
  1036. X    {
  1037. X        if (menu_list[counter].argument != -1)
  1038. X            (*menu_list[counter].procedure)(menu_list[counter].argument);
  1039. X        else
  1040. X            (*menu_list[counter].procedure)();
  1041. X    }
  1042. X
  1043. X    if (info_window)
  1044. X        paint_info_win();
  1045. X    midscreen(scr_vert, point);
  1046. X
  1047. X    return(counter);
  1048. X}
  1049. X
  1050. Xhelp()
  1051. X{
  1052. X    int counter;
  1053. X
  1054. X    werase(help_win);
  1055. X    clearok(help_win, TRUE);
  1056. X    for (counter = 0; counter < 22; counter++)
  1057. X    {
  1058. X        wmove(help_win, counter, 0);
  1059. X        wprintw(help_win, "%s", help_text[counter]);
  1060. X    }
  1061. X    wrefresh(help_win);
  1062. X    werase(com_win);
  1063. X    wmove(com_win, 0, 0);
  1064. X    wprintw(com_win, press_any_key_msg);
  1065. X    wrefresh(com_win);
  1066. X    counter = wgetch(com_win);
  1067. X    if (counter == -1)
  1068. X        exit(0);
  1069. X    werase(com_win);
  1070. X    wmove(com_win, 0, 0);
  1071. X    werase(help_win);
  1072. X    wrefresh(help_win);
  1073. X    wrefresh(com_win);
  1074. X    redraw();
  1075. X}
  1076. X
  1077. Xpaint_info_win()
  1078. X{
  1079. X    int counter;
  1080. X
  1081. X    if (!info_window)
  1082. X        return;
  1083. X
  1084. X    werase(info_win);
  1085. X    for (counter = 0; counter < 5; counter++)
  1086. X    {
  1087. X        wmove(info_win, counter, 0);
  1088. X        wclrtoeol(info_win);
  1089. X        if (info_type == CONTROL_KEYS)
  1090. X            waddstr(info_win, control_keys[counter]);
  1091. X        else if (info_type == COMMANDS)
  1092. X            waddstr(info_win, command_strings[counter]);
  1093. X    }
  1094. X    wmove(info_win, 5, 0);
  1095. X    if (!nohighlight)
  1096. X        wstandout(info_win);
  1097. X    waddstr(info_win, "===============================================================================");
  1098. X    wstandend(info_win);
  1099. X    wrefresh(info_win);
  1100. X}
  1101. X
  1102. Xno_info_window()
  1103. X{
  1104. X    if (!info_window)
  1105. X        return;
  1106. X    delwin(info_win);
  1107. X    delwin(text_win);
  1108. X    info_window = FALSE;
  1109. X    last_line = LINES - 2;
  1110. X    text_win = newwin((LINES - 1), COLS, 0, 0);
  1111. X    keypad(text_win, TRUE);
  1112. X    idlok(text_win, TRUE);
  1113. X    clearok(text_win, TRUE);
  1114. X    midscreen(scr_vert, point);
  1115. X    wrefresh(text_win);
  1116. X    clear_com_win = TRUE;
  1117. X}
  1118. X
  1119. Xcreate_info_window()
  1120. X{
  1121. X    if (info_window)
  1122. X        return;
  1123. X    last_line = LINES - 8;
  1124. X    delwin(text_win);
  1125. X    text_win = newwin((LINES - 7), COLS, 6, 0);
  1126. X    keypad(text_win, TRUE);
  1127. X    idlok(text_win, TRUE);
  1128. X    werase(text_win);
  1129. X    wrefresh(text_win);
  1130. X    info_window = TRUE;
  1131. X    info_win = newwin(6, COLS, 0, 0);
  1132. X    werase(info_win);
  1133. X    info_type = CONTROL_KEYS;
  1134. X    midscreen(min(scr_vert, last_line), point);
  1135. X    clearok(info_win, TRUE);
  1136. X    paint_info_win();
  1137. X    clear_com_win = TRUE;
  1138. X}
  1139. X
  1140. Xfile_op(arg)
  1141. Xint arg;
  1142. X{
  1143. X    char *string;
  1144. X    int flag;
  1145. X
  1146. X    if (restrict_mode())
  1147. X    {
  1148. X        return;
  1149. X    }
  1150. X
  1151. X    if (arg == READ_FILE)
  1152. X    {
  1153. X        string = get_string(file_read_prompt_str, TRUE);
  1154. X        recv_file = TRUE;
  1155. X        tmp_file = resolve_name(string);
  1156. X        check_fp();
  1157. X        if (tmp_file != string)
  1158. X            free(tmp_file);
  1159. X        free(string);
  1160. X    }
  1161. X    else if (arg == WRITE_FILE)
  1162. X    {
  1163. X        string = get_string(file_write_prompt_str, TRUE);
  1164. X        tmp_file = resolve_name(string);
  1165. X        write_file(tmp_file);
  1166. X        if (tmp_file != string)
  1167. X            free(tmp_file);
  1168. X        free(string);
  1169. X    }
  1170. X    else if (arg == SAVE_FILE)
  1171. X    {
  1172. X    /*
  1173. X     |    changes made here should be reflected in finish()
  1174. X     */
  1175. X
  1176. X        if (in_file_name)
  1177. X            flag = TRUE;
  1178. X        else
  1179. X            flag = FALSE;
  1180. X
  1181. X        string = in_file_name;
  1182. X        if ((string == NULL) || (*string == NULL))
  1183. X            string = get_string(save_file_name_prompt, TRUE);
  1184. X        if ((string == NULL) || (*string == NULL))
  1185. X        {
  1186. X            wmove(com_win, 0, 0);
  1187. X            wprintw(com_win, file_not_saved_msg);
  1188. X            wclrtoeol(com_win);
  1189. X            wrefresh(com_win);
  1190. X            clear_com_win = TRUE;
  1191. X            return;
  1192. X        }
  1193. X        if (!flag)
  1194. X        {
  1195. X            tmp_file = resolve_name(string);
  1196. X            if (tmp_file != string)
  1197. X            {
  1198. X                free(string);
  1199. X                string = tmp_file;
  1200. X            }
  1201. X        }
  1202. X        if (write_file(string))
  1203. X        {
  1204. X            in_file_name = string;
  1205. X            text_changes = FALSE;
  1206. X        }
  1207. X        else if (!flag)
  1208. X            free(string);
  1209. X    }
  1210. X}
  1211. X
  1212. Xshell_op()
  1213. X{
  1214. X    char *string;
  1215. X
  1216. X    if (((string = get_string(shell_prompt, TRUE)) != NULL) && 
  1217. X            (*string != NULL))
  1218. X    {
  1219. X        sh_command(string);
  1220. X        free(string);
  1221. X    }
  1222. X}
  1223. X
  1224. Xleave_op()
  1225. X{
  1226. X    if (text_changes)
  1227. X    {
  1228. X        menu_op(leave_menu);
  1229. X    }
  1230. X    else
  1231. X        quit(TRUE);
  1232. X}
  1233. X
  1234. Xredraw()
  1235. X{
  1236. X    if (info_window)
  1237. X        {
  1238. X                clearok(info_win, TRUE);
  1239. X            paint_info_win();
  1240. X        }
  1241. X        else
  1242. X        clearok(text_win, TRUE);
  1243. X    midscreen(scr_vert, point);
  1244. X}
  1245. X
  1246. X/*
  1247. X |    The following routines will "format" a paragraph (as defined by a 
  1248. X |    block of text with blank lines before and after the block).
  1249. X */
  1250. X
  1251. XBlank_Line(test_line)    /* test if line has any non-space characters    */
  1252. Xstruct text *test_line;
  1253. X{
  1254. X    char *line;
  1255. X    int length;
  1256. X    
  1257. X    if (test_line == NULL)
  1258. X        return(TRUE);
  1259. X
  1260. X    length = 1;
  1261. X    line = test_line->line;
  1262. X
  1263. X    /*
  1264. X     |    To handle troff/nroff documents, consider a line with a 
  1265. X     |    period ('.') in the first column to be blank.  To handle mail 
  1266. X     |    messages with included text, consider a line with a '>' blank.
  1267. X     */
  1268. X
  1269. X    if ((*line == '.') || (*line == '>'))
  1270. X        return(TRUE);
  1271. X
  1272. X    while (((*line == ' ') || (*line == '\t')) && (length < test_line->line_length))
  1273. X    {
  1274. X        length++;
  1275. X        line++;
  1276. X    }
  1277. X    if (length != test_line->line_length)
  1278. X        return(FALSE);
  1279. X    else
  1280. X        return(TRUE);
  1281. X}
  1282. X
  1283. XFormat()    /* format the paragraph according to set margins    */
  1284. X{
  1285. X    int string_count;
  1286. X    int offset;
  1287. X    int temp_case;
  1288. X    int status;
  1289. X    int tmp_af;
  1290. X    int counter;
  1291. X    char *line;
  1292. X    char *tmp_srchstr;
  1293. X    char *temp1, *temp2;
  1294. X    char *temp_dword;
  1295. X    char temp_d_char = d_char;
  1296. X
  1297. X/*
  1298. X |    if observ_margins is not set, or the current line is blank, 
  1299. X |    do not format the current paragraph
  1300. X */
  1301. X
  1302. X    if ((!observ_margins) || (Blank_Line(curr_line)))
  1303. X        return;
  1304. X
  1305. X/*
  1306. X |    save the currently set flags, and clear them
  1307. X */
  1308. X
  1309. X    wmove(com_win, 0, 0);
  1310. X    wclrtoeol(com_win);
  1311. X    wprintw(com_win, formatting_msg);
  1312. X    wrefresh(com_win);
  1313. X
  1314. X/*
  1315. X |    get current position in paragraph, so after formatting, the cursor 
  1316. X |    will be in the same relative position
  1317. X */
  1318. X
  1319. X    tmp_af = auto_format;
  1320. X    auto_format = FALSE;
  1321. X    offset = position;
  1322. X    if (position != 1)
  1323. X        prev_word();
  1324. X    temp_dword = d_word;
  1325. X    d_word = NULL;
  1326. X    temp_case = case_sen;
  1327. X    case_sen = TRUE;
  1328. X    tmp_srchstr = srch_str;
  1329. X    temp2 = srch_str = (char *) malloc(1 + curr_line->line_length - position);
  1330. X    if ((*point == ' ') || (*point == '\t'))
  1331. X        adv_word();
  1332. X    offset -= position;
  1333. X    counter = position;
  1334. X    line = temp1 = point;
  1335. X    while ((*temp1 != NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
  1336. X    {
  1337. X        *temp2 = *temp1;
  1338. X        temp2++;
  1339. X        temp1++;
  1340. X        counter++;
  1341. X    }
  1342. X    *temp2 = NULL;
  1343. X    if (position != 1)
  1344. X        bol();
  1345. X    while (!Blank_Line(curr_line->prev_line))
  1346. X        bol();
  1347. X    string_count = 0;
  1348. X    status = TRUE;
  1349. X    while ((line != point) && (status))
  1350. X    {
  1351. X        status = search(FALSE);
  1352. X        string_count++;
  1353. X    }
  1354. X
  1355. X    wmove(com_win, 0, 0);
  1356. X    wclrtoeol(com_win);
  1357. X    wprintw(com_win, formatting_msg);
  1358. X    wrefresh(com_win);
  1359. X
  1360. X/*
  1361. X |    now get back to the start of the paragraph to start formatting
  1362. X */
  1363. X
  1364. X    if (position != 1)
  1365. X        bol();
  1366. X    while (!Blank_Line(curr_line->prev_line))
  1367. X        bol();
  1368. X
  1369. X    observ_margins = FALSE;
  1370. X
  1371. X/*
  1372. X |    Start going through lines, putting spaces at end of lines if they do 
  1373. X |    not already exist.  Append lines together to get one long line, and 
  1374. X |    eliminate spacing at begin of lines.
  1375. X */
  1376. X
  1377. X    while (!Blank_Line(curr_line->next_line))
  1378. X    {
  1379. X        eol();
  1380. X        left(TRUE);
  1381. X        if (*point != ' ')
  1382. X        {
  1383. X            right(TRUE);
  1384. X            insert(' ');
  1385. X        }
  1386. X        else
  1387. X            right(TRUE);
  1388. X        del_char(FALSE);
  1389. X        if ((*point == ' ') || (*point == '\t'))
  1390. X            del_word(FALSE);
  1391. X    }
  1392. X
  1393. X/*
  1394. X |    Now there is one long line.  Eliminate extra spaces within the line
  1395. X |    after the first word (so as not to blow away any indenting the user 
  1396. X |    may have put in).
  1397. X */
  1398. X
  1399. X    bol();
  1400. X    adv_word();
  1401. X    while (position < curr_line->line_length)
  1402. X    {
  1403. X        if ((*point == ' ') && (*(point + 1) == ' '))
  1404. X            del_char(FALSE);
  1405. X        else
  1406. X            right(TRUE);
  1407. X    }
  1408. X
  1409. X/*
  1410. X |    Now make sure there are two spaces after a '.'.
  1411. X */
  1412. X
  1413. X    bol();
  1414. X    while (position < curr_line->line_length)
  1415. X    {
  1416. X        if ((*point == '.') && (*(point + 1) == ' '))
  1417. X        {
  1418. X            right(TRUE);
  1419. X            insert(' ');
  1420. X            insert(' ');
  1421. X            while (*point == ' ')
  1422. X                del_char(FALSE);
  1423. X        }
  1424. X        right(TRUE);
  1425. X    }
  1426. X
  1427. X    observ_margins = TRUE;
  1428. X    bol();
  1429. X
  1430. X    wmove(com_win, 0, 0);
  1431. X    wclrtoeol(com_win);
  1432. X    wprintw(com_win, formatting_msg);
  1433. X    wrefresh(com_win);
  1434. X
  1435. X/*
  1436. X |    create lines between margins
  1437. X */
  1438. X
  1439. X    while (position < curr_line->line_length)
  1440. X    {
  1441. X        while ((scr_pos < right_margin) && (position < curr_line->line_length))
  1442. X            right(TRUE);
  1443. X        if (position < curr_line->line_length)
  1444. X        {
  1445. X            prev_word();
  1446. X            if (position == 1)
  1447. X                adv_word();
  1448. X            insert_line(TRUE);
  1449. X        }
  1450. X    }
  1451. X
  1452. X/*
  1453. X |    go back to begin of paragraph, put cursor back to original position
  1454. X */
  1455. X
  1456. X    bol();
  1457. X    while (!Blank_Line(curr_line->prev_line))
  1458. X        bol();
  1459. X
  1460. X/*
  1461. X |    find word cursor was in
  1462. X */
  1463. X
  1464. X    while ((status) && (string_count > 0))
  1465. X    {
  1466. X        search(FALSE);
  1467. X        string_count--;
  1468. X    }
  1469. X
  1470. X/*
  1471. X |    offset the cursor to where it was before from the start of the word
  1472. X */
  1473. X
  1474. X    while (offset > 0)
  1475. X    {
  1476. X        offset--;
  1477. X        right(TRUE);
  1478. X    }
  1479. X
  1480. X/*
  1481. X |    reset flags and strings to what they were before formatting
  1482. X */
  1483. X
  1484. X    if (d_word != NULL)
  1485. X        free(d_word);
  1486. X    d_word = temp_dword;
  1487. X    case_sen = temp_case;
  1488. X    free(srch_str);
  1489. X    srch_str = tmp_srchstr;
  1490. X    d_char = temp_d_char;
  1491. X    auto_format = tmp_af;
  1492. X
  1493. X    midscreen(scr_vert, point);
  1494. X    werase(com_win);
  1495. X    wrefresh(com_win);
  1496. X}
  1497. X
  1498. Xchar *init_name[3] = {
  1499. X    "/usr/local/lib/init.ee", 
  1500. X    NULL, 
  1501. X    ".init.ee"
  1502. X    };
  1503. X
  1504. Xee_init()    /* check for init file and read it if it exists    */
  1505. X{
  1506. X    FILE *init_file;
  1507. X    char *string;
  1508. X    char *str1;
  1509. X    char *str2;
  1510. X    char *home;
  1511. X    int counter;
  1512. X    int temp_int;
  1513. X
  1514. X    string = getenv("HOME");
  1515. X    str1 = home = malloc(strlen(string)+10);
  1516. X    strcpy(home, string);
  1517. X    strcat(home, "/.init.ee");
  1518. X    init_name[1] = home;
  1519. X    string = malloc(512);
  1520. X
  1521. X    for (counter = 0; counter < 3; counter++)
  1522. X    {
  1523. X        if (!(access(init_name[counter], 4)))
  1524. X        {
  1525. X            init_file = fopen(init_name[counter], "r");
  1526. X            while ((str2 = fgets(string, 512, init_file)) != NULL)
  1527. X            {
  1528. X                if (unique_test(string, init_strings) != 1)
  1529. X                    continue;
  1530. X                str1 = str2 = string;
  1531. X                while (*str2 != '\n')
  1532. X                    str2++;
  1533. X                *str2 = NULL;
  1534. X                if (compare(str1, CASE, FALSE))
  1535. X                    case_sen = TRUE;
  1536. X                else if (compare(str1, NOCASE, FALSE))
  1537. X                    case_sen = FALSE;
  1538. X                else if (compare(str1, EXPAND, FALSE))
  1539. X                    expand_tabs = TRUE;
  1540. X                else if (compare(str1, NOEXPAND, FALSE))
  1541. X                    expand_tabs = FALSE;
  1542. X                else if (compare(str1, INFO, FALSE))
  1543. X                    info_window = TRUE;
  1544. X                else if (compare(str1, NOINFO, FALSE))
  1545. X                    info_window = FALSE;   
  1546. X                else if (compare(str1, MARGINS, FALSE))
  1547. X                    observ_margins = TRUE;
  1548. X                else if (compare(str1, NOMARGINS, FALSE))
  1549. X                    observ_margins = FALSE;
  1550. X                else if (compare(str1, AUTOFORMAT, FALSE))
  1551. X                {
  1552. X                    auto_format = TRUE;
  1553. X                    observ_margins = TRUE;
  1554. X                }
  1555. X                else if (compare(str1, NOAUTOFORMAT, FALSE))
  1556. X                    auto_format = FALSE;
  1557. X                else if (compare(str1, Echo, FALSE))
  1558. X                {
  1559. X                    str1 = next_word(str1);
  1560. X                    if (*str1 != NULL)
  1561. X                        echo_string(str1);
  1562. X                }
  1563. X                else if (compare(str1, PRINTCOMMAND, FALSE))
  1564. X                {
  1565. X                    str1 = next_word(str1);
  1566. X                    print_command = malloc(strlen(str1)+1);
  1567. X                    strcpy(print_command, str1);
  1568. X                }
  1569. X                else if (compare(str1, RIGHTMARGIN, FALSE))
  1570. X                {
  1571. X                    str1 = next_word(str1);
  1572. X                    if ((*str1 >= '0') && (*str1 <= '9'))
  1573. X                    {
  1574. X                        temp_int = atoi(str1);
  1575. X                        if (temp_int > 0)
  1576. X                            right_margin = temp_int;
  1577. X                    }
  1578. X                }
  1579. X                else if (compare(str1, HIGHLIGHT, FALSE))
  1580. X                    nohighlight = FALSE;
  1581. X                else if (compare(str1, NOHIGHLIGHT, FALSE))
  1582. X                    nohighlight = TRUE;
  1583. X                else if (compare(str1, EIGHTBIT, FALSE))
  1584. X                    eightbit = TRUE;
  1585. X                else if (compare(str1, NOEIGHTBIT, FALSE))
  1586. X                    eightbit = FALSE;
  1587. X            }
  1588. X            fclose(init_file);
  1589. X        }
  1590. X    }
  1591. X    free(string);
  1592. X    free(home);
  1593. X}
  1594. X
  1595. Xecho_string(string)    /* echo the given string    */
  1596. Xchar *string;
  1597. X{
  1598. X    char *temp;
  1599. X    int Counter;
  1600. X
  1601. X        temp = string;
  1602. X        while (*temp != NULL)
  1603. X        {
  1604. X            if (*temp == '\\')
  1605. X            {
  1606. X                temp++;
  1607. X                if (*temp == 'n')
  1608. X                    putchar('\n');
  1609. X                else if (*temp == 't')
  1610. X                    putchar('\t');
  1611. X                else if (*temp == 'b')
  1612. X                    putchar('\b');
  1613. X                else if (*temp == 'r')
  1614. X                    putchar('\r');
  1615. X                else if (*temp == 'f')
  1616. X                    putchar('\f');
  1617. X                else if ((*temp == 'e') || (*temp == 'E'))
  1618. X                    putchar('\033');    /* escape */
  1619. X                else if (*temp == '\\')
  1620. X                    putchar('\\');
  1621. X                else if (*temp == '\'')
  1622. X                    putchar('\'');
  1623. X                else if ((*temp >= '0') && (*temp <= '9'))
  1624. X                {
  1625. X                    Counter = 0;
  1626. X                    while ((*temp >= '0') && (*temp <= '9'))
  1627. X                    {
  1628. X                        Counter = (8 * Counter) + (*temp - '0');
  1629. X                        temp++;
  1630. X                    }
  1631. X                    putchar(Counter);
  1632. X                    temp--;
  1633. X                }
  1634. X                temp++;
  1635. X            }
  1636. X            else
  1637. X            {
  1638. X                putchar(*temp);
  1639. X                temp++;
  1640. X            }
  1641. X        }
  1642. X
  1643. X    fflush(stdout);
  1644. X}
  1645. X
  1646. Xspell_op()    /* check spelling of words in the editor    */
  1647. X{
  1648. X    if (restrict_mode())
  1649. X    {
  1650. X        return;
  1651. X    }
  1652. X    top();            /* go to top of file        */
  1653. X    insert_line(FALSE);    /* create two blank lines    */
  1654. X    insert_line(FALSE);
  1655. X    top();
  1656. X    command(shell_echo_msg);
  1657. X    adv_line();
  1658. X    wmove(com_win, 0, 0);
  1659. X    wprintw(com_win, spell_in_prog_msg);
  1660. X    wrefresh(com_win);
  1661. X    command("<>!spell");    /* send contents of buffer to command 'spell' 
  1662. X                   and read the results back into the editor */
  1663. X}
  1664. X
  1665. Xispell_op()
  1666. X{
  1667. X    char name[128];
  1668. X    char string[256];
  1669. X    int pid;
  1670. X
  1671. X    if (restrict_mode())
  1672. X    {
  1673. X        return;
  1674. X    }
  1675. X    pid = getpid();
  1676. X    sprintf(name, "/tmp/ee.%d", pid);
  1677. X    if (write_file(name))
  1678. X    {
  1679. X        sprintf(string, "ispell %s", name);
  1680. X        sh_command(string);
  1681. X        delete_text();
  1682. X        tmp_file = name;
  1683. X        recv_file = TRUE;
  1684. X        check_fp();
  1685. X        unlink(name);
  1686. X    }
  1687. X}
  1688. X
  1689. Xint
  1690. Xfirst_word_len(test_line)
  1691. Xstruct text *test_line;
  1692. X{
  1693. X    int counter;
  1694. X    char *pnt;
  1695. X
  1696. X    pnt = test_line->line;
  1697. X    if ((test_line == NULL) || (pnt == NULL) || (*pnt == NULL) || 
  1698. X        (*pnt == '.') || (*pnt == '>'))
  1699. X        return(0);
  1700. X
  1701. X    if ((*pnt == ' ') || (*pnt == '\t'))
  1702. X    {
  1703. X        pnt = next_word(pnt);
  1704. X    }
  1705. X
  1706. X    if (*pnt == NULL)
  1707. X        return(0);
  1708. X
  1709. X    counter = 0;
  1710. X    while ((*pnt != NULL) && ((*pnt != ' ') && (*pnt != '\t')))
  1711. X    {
  1712. X        pnt++;
  1713. X        counter++;
  1714. X    }
  1715. X    while ((*pnt != NULL) && ((*pnt == ' ') || (*pnt == '\t')))
  1716. X    {
  1717. X        pnt++;
  1718. X        counter++;
  1719. X    }
  1720. X    return(counter);
  1721. X}
  1722. X
  1723. XAuto_Format()    /* format the paragraph according to set margins    */
  1724. X{
  1725. X    int string_count;
  1726. X    int offset;
  1727. X    int temp_case;
  1728. X    int word_len;
  1729. X    int temp_dwl;
  1730. X    int tmp_d_line_length;
  1731. X    int leave_loop = FALSE;
  1732. X    int status;
  1733. X    int counter;
  1734. X    char *line;
  1735. X    char *tmp_srchstr;
  1736. X    char *temp1, *temp2;
  1737. X    char *temp_dword;
  1738. X    char temp_d_char = d_char;
  1739. X    char *tmp_d_line;
  1740. X
  1741. X/*
  1742. X |    if observ_margins is not set, or the current line is blank, 
  1743. X |    do not format the current paragraph
  1744. X */
  1745. X
  1746. X    if ((!observ_margins) || (Blank_Line(curr_line)))
  1747. X        return;
  1748. X
  1749. X/*
  1750. X |    get current position in paragraph, so after formatting, the cursor 
  1751. X |    will be in the same relative position
  1752. X */
  1753. X
  1754. X    tmp_d_line = d_line;
  1755. X    tmp_d_line_length = dlt_line->line_length;
  1756. X    d_line = NULL;
  1757. X    auto_format = FALSE;
  1758. X    offset = position;
  1759. X    if ((position != 1) && ((*point == ' ') || (*point == '\t') || (position == curr_line->line_length) || (*point == NULL)))
  1760. X        prev_word();
  1761. X    temp_dword = d_word;
  1762. X    temp_dwl = d_wrd_len;
  1763. X    d_wrd_len = 0;
  1764. X    d_word = NULL;
  1765. X    temp_case = case_sen;
  1766. X    case_sen = TRUE;
  1767. X    tmp_srchstr = srch_str;
  1768. X    temp2 = srch_str = (char *) malloc(1 + curr_line->line_length - position);
  1769. X    if ((*point == ' ') || (*point == '\t'))
  1770. X        adv_word();
  1771. X    offset -= position;
  1772. X    counter = position;
  1773. X    line = temp1 = point;
  1774. X    while ((*temp1 != NULL) && (*temp1 != ' ') && (*temp1 != '\t') && (counter < curr_line->line_length))
  1775. X    {
  1776. X        *temp2 = *temp1;
  1777. X        temp2++;
  1778. X        temp1++;
  1779. X        counter++;
  1780. X    }
  1781. X    *temp2 = NULL;
  1782. X    if (position != 1)
  1783. X        bol();
  1784. X    while (!Blank_Line(curr_line->prev_line))
  1785. X        bol();
  1786. X    string_count = 0;
  1787. X    status = TRUE;
  1788. X    while ((line != point) && (status))
  1789. X    {
  1790. X        status = search(FALSE);
  1791. X        string_count++;
  1792. X    }
  1793. X
  1794. X/*
  1795. X |    now get back to the start of the paragraph to start checking
  1796. X */
  1797. X
  1798. X    if (position != 1)
  1799. X        bol();
  1800. X    while (!Blank_Line(curr_line->prev_line))
  1801. X        bol();
  1802. X
  1803. X/*
  1804. X |    Start going through lines, putting spaces at end of lines if they do 
  1805. X |    not already exist.  Check line length, and move words to the next line 
  1806. X |    if they cross the margin.  Then get words from the next line if they 
  1807. X |    will fit in before the margin.  
  1808. X */
  1809. X
  1810. X    while (!leave_loop)
  1811. X    {
  1812. X        if (position != curr_line->line_length)
  1813. X            eol();
  1814. X        left(TRUE);
  1815. X        if (*point != ' ')
  1816. X        {
  1817. X            right(TRUE);
  1818. X            insert(' ');
  1819. X        }
  1820. X        else
  1821. X            right(TRUE);
  1822. X
  1823. X        /*
  1824. X         |    fill line if first word on next line will fit 
  1825. X         |    in the line without crossing the margin
  1826. X         */
  1827. X
  1828. X        while (((word_len = first_word_len(curr_line->next_line)) > 0) 
  1829. X            && ((scr_pos + word_len) < right_margin))
  1830. X        {
  1831. X            adv_line();
  1832. X            if ((*point == ' ') || (*point == '\t'))
  1833. X                adv_word();
  1834. X            del_word();
  1835. X            if (position != 1)
  1836. X                bol();
  1837. X            if (Blank_Line(curr_line))
  1838. X            {
  1839. X                del_line();
  1840. X            }
  1841. X            /*
  1842. X             |   go to end of previous line
  1843. X             */
  1844. X            left(TRUE);
  1845. X            undel_word();
  1846. X            eol();
  1847. X            /*
  1848. X             |   make sure there's a space at the end of the line
  1849. X             */
  1850. X            left(TRUE);
  1851. X            if (*point != ' ')
  1852. X            {
  1853. X                right(TRUE);
  1854. X                insert(' ');
  1855. X            }
  1856. X            else
  1857. X                right(TRUE);
  1858. X        }
  1859. X
  1860. X        /*
  1861. X         |    make sure line does not cross right margin
  1862. X         */
  1863. X
  1864. X        while (right_margin <= scr_pos)
  1865. X        {
  1866. X            prev_word();
  1867. X            if (position != 1)
  1868. X            {
  1869. X                del_word();
  1870. X                if (Blank_Line(curr_line->next_line))
  1871. X                    insert_line(TRUE);
  1872. X                else
  1873. X                    adv_line();
  1874. X                if ((*point == ' ') || (*point == '\t'))
  1875. X                    adv_word();
  1876. X                undel_word();
  1877. X                if (position != 1)
  1878. X                    bol();
  1879. X                left(TRUE);
  1880. X            }
  1881. X        }
  1882. X
  1883. X        if (!Blank_Line(curr_line->next_line))
  1884. X            adv_line();
  1885. X        else
  1886. X            leave_loop = TRUE;
  1887. X    }
  1888. X
  1889. X/*
  1890. X |    go back to begin of paragraph, put cursor back to original position
  1891. X */
  1892. X
  1893. X    bol();
  1894. X    while (!Blank_Line(curr_line->prev_line))
  1895. X        bol();
  1896. X
  1897. X/*
  1898. X |    find word cursor was in
  1899. X */
  1900. X
  1901. X    status = TRUE;
  1902. X    while ((status) && (string_count > 0))
  1903. X    {
  1904. X        status = search(FALSE);
  1905. X        string_count--;
  1906. X    }
  1907. X
  1908. X/*
  1909. X |    offset the cursor to where it was before from the start of the word
  1910. X */
  1911. X
  1912. X    while (offset > 0)
  1913. X    {
  1914. X        offset--;
  1915. X        right(TRUE);
  1916. X    }
  1917. X
  1918. X    if ((string_count > 0) && (offset < 0))
  1919. X    {
  1920. X        while (offset < 0)
  1921. X        {
  1922. X            offset++;
  1923. X            left(TRUE);
  1924. X        }
  1925. X    }
  1926. X
  1927. X/*
  1928. X |    reset flags and strings to what they were before formatting
  1929. X */
  1930. X
  1931. X    if (d_word != NULL)
  1932. X        free(d_word);
  1933. X    d_word = temp_dword;
  1934. X    d_wrd_len = temp_dwl;
  1935. X    case_sen = temp_case;
  1936. X    free(srch_str);
  1937. X    srch_str = tmp_srchstr;
  1938. X    d_char = temp_d_char;
  1939. X    auto_format = TRUE;
  1940. X    dlt_line->line_length = tmp_d_line_length;
  1941. X    d_line = tmp_d_line;
  1942. X
  1943. X    formatted = TRUE;
  1944. X    midscreen(scr_vert, point);
  1945. X}
  1946. X
  1947. Xmodes_op()
  1948. X{
  1949. X    int ret_value;
  1950. X    int counter;
  1951. X    char *string;
  1952. X
  1953. X    do
  1954. X    {
  1955. X        sprintf(modes_menu[1].item_string, "%s %s", mode_strings[1], 
  1956. X                    (expand_tabs ? ON : OFF));
  1957. X        sprintf(modes_menu[2].item_string, "%s %s", mode_strings[2], 
  1958. X                    (case_sen ? ON : OFF));
  1959. X        sprintf(modes_menu[3].item_string, "%s %s", mode_strings[3], 
  1960. X                    (observ_margins ? ON : OFF));
  1961. X        sprintf(modes_menu[4].item_string, "%s %s", mode_strings[4], 
  1962. X                    (auto_format ? ON : OFF));
  1963. X        sprintf(modes_menu[5].item_string, "%s %s", mode_strings[5], 
  1964. X                    (eightbit ? ON : OFF));
  1965. X        sprintf(modes_menu[6].item_string, "%s %s", mode_strings[6], 
  1966. X                    (info_window ? ON : OFF));
  1967. X        sprintf(modes_menu[7].item_string, "%s %d", mode_strings[7], 
  1968. X                    right_margin);
  1969. X
  1970. X        ret_value = menu_op(modes_menu);
  1971. X
  1972. X        switch (ret_value) 
  1973. X        {
  1974. X            case 1:
  1975. X                expand_tabs = !expand_tabs;
  1976. X                break;
  1977. X            case 2:
  1978. X                case_sen = !case_sen;
  1979. X                break;
  1980. X            case 3:
  1981. X                observ_margins = !observ_margins;
  1982. X                break;
  1983. X            case 4:
  1984. X                auto_format = !auto_format;
  1985. X                if (auto_format)
  1986. X                    observ_margins = TRUE;
  1987. X                break;
  1988. X            case 5:
  1989. X                eightbit = !eightbit;
  1990. X                redraw();
  1991. X                wnoutrefresh(text_win);
  1992. X                break;
  1993. X            case 6:
  1994. X                if (info_window)
  1995. X                    no_info_window();
  1996. X                else
  1997. X                    create_info_window();
  1998. X                break;
  1999. X            case 7:
  2000. X                string = get_string(margin_prompt, TRUE);
  2001. X                if (string != NULL)
  2002. X                {
  2003. X                    counter = atoi(string);
  2004. X                    if (counter > 0)
  2005. X                        right_margin = counter;
  2006. X                    free(string);
  2007. X                }
  2008. X                break;
  2009. X            default:
  2010. X                break;
  2011. X        }
  2012. X    }
  2013. X    while (ret_value != 0);
  2014. X}
  2015. X
  2016. X/*
  2017. X |    handle names of the form "~/file" or "~user/file"
  2018. X */
  2019. X
  2020. Xchar *
  2021. Xresolve_name(name)
  2022. Xchar *name;
  2023. X{
  2024. X    char *buffer;
  2025. X    char *slash;
  2026. X    int index;
  2027. X    struct passwd *user;
  2028. X
  2029. X    if (name[0] == '~') 
  2030. X    {
  2031. X        if (name[1] == '/')
  2032. X        {
  2033. X            index = getuid();
  2034. X            user = (struct passwd *) getpwuid(index);
  2035. X            slash = name + 1;
  2036. X        }
  2037. X        else
  2038. X        {
  2039. X            slash = strchr(name, '/');
  2040. X            if (slash == NULL) 
  2041. X                return(name);
  2042. X            *slash = NULL;
  2043. X            user = (struct passwd *) getpwnam((name + 1));
  2044. X            *slash = '/';
  2045. X        }
  2046. X        if (user == NULL) 
  2047. X        {
  2048. X            return(name);
  2049. X        }
  2050. X        buffer = malloc(strlen(user->pw_dir) + strlen(slash) + 1);
  2051. X        strcpy(buffer, user->pw_dir);
  2052. X        strcat(buffer, slash);
  2053. X        return(buffer);
  2054. X    }
  2055. X    return(name);
  2056. X}
  2057. X
  2058. Xint
  2059. Xrestrict_mode()
  2060. X{
  2061. X    if (!restricted)
  2062. X        return(FALSE);
  2063. X
  2064. X    wmove(com_win, 0, 0);
  2065. X    wprintw(com_win, restricted_msg);
  2066. X    wclrtoeol(com_win);
  2067. X    wrefresh(com_win);
  2068. X    clear_com_win = TRUE;
  2069. X    return(TRUE);
  2070. X}
  2071. X
  2072. X/*
  2073. X |    The following routine tests the input string against the list of 
  2074. X |    strings, to determine if the string is a unique match with one of the 
  2075. X |    valid values.
  2076. X */
  2077. X
  2078. Xint 
  2079. Xunique_test(string, list)
  2080. Xchar *string;
  2081. Xchar *list[];
  2082. X{
  2083. X    int counter;
  2084. X    int num_match;
  2085. X    int result;
  2086. X
  2087. X    num_match = 0;
  2088. X    counter = 0;
  2089. X    while (list[counter] != NULL)
  2090. X    {
  2091. X        result = compare(string, list[counter], FALSE);
  2092. X        if (result)
  2093. X            num_match++;
  2094. X        counter++;
  2095. X    }
  2096. X    return(num_match);
  2097. X}
  2098. X
  2099. X#ifndef NO_CATGETS
  2100. X/*
  2101. X |    Get the catalog entry, and if it got it from the catalog, 
  2102. X |    make a copy, since the buffer will be overwritten by the 
  2103. X |    next call to catgets().
  2104. X */
  2105. X
  2106. Xchar *
  2107. Xcatgetlocal(number, string)
  2108. Xint number;
  2109. Xchar *string;
  2110. X{
  2111. X    char *temp1;
  2112. X    char *temp2;
  2113. X
  2114. X    temp1 = catgets(catalog, 1, number, string);
  2115. X    if (temp1 != string)
  2116. X    {
  2117. X        temp2 = malloc(strlen(temp1) + 1);
  2118. X        strcpy(temp2, temp1);
  2119. X        temp1 = temp2;
  2120. X    }
  2121. X    return(temp1);
  2122. X}
  2123. X#endif /* NO_CATGETS */
  2124. X
  2125. X/*
  2126. X |    The following is to allow for using message catalogs which allow 
  2127. X |    the software to be 'localized', that is, to use different languages 
  2128. X |    all with the same binary.  For more information, see your system 
  2129. X |    documentation, or the X/Open Internationalization Guide.
  2130. X */
  2131. X
  2132. Xstrings_init()
  2133. X{
  2134. X#ifndef NO_CATGETS
  2135. X    setlocale(LC_ALL, "");
  2136. X    catalog = catopen("ee", 0);
  2137. X#endif /* NO_CATGETS */
  2138. X
  2139. X    modes_menu[0].item_string = catgetlocal( 1, "modes menu");
  2140. X    mode_strings[1]  = catgetlocal( 2, "tabs to spaces       "); 
  2141. X    mode_strings[2]  = catgetlocal( 3, "case sensitive search"); 
  2142. X    mode_strings[3]  = catgetlocal( 4, "margins observed     "); 
  2143. X    mode_strings[4]  = catgetlocal( 5, "auto-paragraph format"); 
  2144. X    mode_strings[5]  = catgetlocal( 6, "eightbit characters  "); 
  2145. X    mode_strings[6]  = catgetlocal( 7, "info window          "); 
  2146. X    mode_strings[7]  = catgetlocal( 8, "right margin         ");
  2147. X    leave_menu[0].item_string  = catgetlocal( 9, "leave menu");
  2148. X    leave_menu[1].item_string  = catgetlocal( 10, "save changes");
  2149. X    leave_menu[2].item_string  = catgetlocal( 11, "no save");
  2150. X    file_menu[0].item_string  = catgetlocal( 12, "file menu");
  2151. X    file_menu[1].item_string  = catgetlocal( 13, "read a file");
  2152. X    file_menu[2].item_string  = catgetlocal( 14, "write a file");
  2153. X    file_menu[3].item_string  = catgetlocal( 15, "save file");
  2154. X    file_menu[4].item_string  = catgetlocal( 16, "print editor contents");
  2155. X    search_menu[0].item_string = catgetlocal( 17, "search menu");
  2156. X    search_menu[1].item_string = catgetlocal( 18, "search for ...");
  2157. X    search_menu[2].item_string = catgetlocal( 19, "search");
  2158. X    spell_menu[0].item_string = catgetlocal( 20, "spell menu");
  2159. X    spell_menu[1].item_string = catgetlocal( 21, "use 'spell'");
  2160. X    spell_menu[2].item_string = catgetlocal( 22, "use 'ispell'");
  2161. X    misc_menu[0].item_string = catgetlocal( 23, "miscellaneous menu");
  2162. X    misc_menu[1].item_string = catgetlocal( 24, "format paragraph");
  2163. X    misc_menu[2].item_string = catgetlocal( 25, "shell command");
  2164. X    misc_menu[3].item_string = catgetlocal( 26, "check spelling");
  2165. X    main_menu[0].item_string  = catgetlocal( 27, "main menu");
  2166. X    main_menu[1].item_string  = catgetlocal( 28, "leave editor");
  2167. X    main_menu[2].item_string  = catgetlocal( 29, "help");
  2168. X    main_menu[3].item_string  = catgetlocal( 30, "file operations");
  2169. X    main_menu[4].item_string  = catgetlocal( 31, "redraw screen");
  2170. X    main_menu[5].item_string  = catgetlocal( 32, "settings");
  2171. X    main_menu[6].item_string  = catgetlocal( 33, "search");
  2172. X    main_menu[7].item_string  = catgetlocal( 34, "miscellaneous");
  2173. X    help_text[0] = catgetlocal( 35, "Control keys:                                                              "); 
  2174. X    help_text[1] = catgetlocal( 36, "^a ascii code           ^i tab                  ^r right                   ");
  2175. X    help_text[2] = catgetlocal( 37, "^b bottom of text       ^j newline              ^t top of text             ");
  2176. X    help_text[3] = catgetlocal( 38, "^c command              ^k delete char          ^u up                      ");
  2177. X    help_text[4] = catgetlocal( 39, "^d down                 ^l left                 ^v undelete word           ");
  2178. X    help_text[5] = catgetlocal( 40, "^e search prompt        ^m newline              ^w delete word             ");
  2179. X    help_text[6] = catgetlocal( 41, "^f undelete char        ^n next page            ^x search                  ");
  2180. X    help_text[7] = catgetlocal( 42, "^g begin of line        ^o end of line          ^y delete line             ");
  2181. X    help_text[8] = catgetlocal( 43, "^h backspace            ^p prev page            ^z undelete line           ");
  2182. X    help_text[9] = catgetlocal( 44, "^[ (escape) menu                                                           ");
  2183. X    help_text[10] = catgetlocal( 45, "                                                                           ");
  2184. X    help_text[11] = catgetlocal( 46, "Commands:                                                                  ");
  2185. X    help_text[12] = catgetlocal( 47, "help    : get this info                 file    : print file name          ");
  2186. X    help_text[13] = catgetlocal( 48, "read    : read a file                   char    : ascii code of char       ");
  2187. X    help_text[14] = catgetlocal( 49, "write   : write a file                  case    : case sensitive search    ");
  2188. X    help_text[15] = catgetlocal( 50, "exit    : leave and save                nocase  : case insensitive search  ");
  2189. X    help_text[16] = catgetlocal( 51, "quit    : leave, no save                !cmd    : execute \"cmd\" in shell   ");
  2190. X    help_text[17] = catgetlocal( 52, "line    : display line #                0-9     : go to line \"#\"           ");
  2191. X    help_text[18] = catgetlocal( 53, "expand  : expand tabs                   noexpand: do not expand tabs         ");
  2192. X    help_text[19] = catgetlocal( 54, "                                                                             ");
  2193. X    help_text[20] = catgetlocal( 55, "  ee [-i] [-e] [-h] [file(s)]                                                 ");
  2194. X    help_text[21] = catgetlocal( 56, "   -i : no information window  -e : do not expand tabs   -h : no highlight ");
  2195. X    control_keys[0] = catgetlocal( 57, "^[ (escape) menu  ^e search prompt  ^y delete line    ^u up     ^p prev page  ");
  2196. X    control_keys[1] = catgetlocal( 58, "^a ascii code     ^x search         ^z undelete line  ^d down   ^n next page  ");
  2197. X    control_keys[2] = catgetlocal( 59, "^b bottom of text ^g begin of line  ^w delete word    ^l left                 ");
  2198. X    control_keys[3] = catgetlocal( 60, "^t top of text    ^o end of line    ^v undelete word  ^r right                ");
  2199. X    control_keys[4] = catgetlocal( 61, "^c command        ^k delete char    ^f undelete char                          ");
  2200. X    command_strings[0] = catgetlocal( 62, "help : get help info  |file  : print file name         |line : print line # ");
  2201. X    command_strings[1] = catgetlocal( 63, "read : read a file    |char  : ascii code of char      |0-9 : go to line \"#\"");
  2202. X    command_strings[2] = catgetlocal( 64, "write: write a file   |case  : case sensitive search   |exit : leave and save ");
  2203. X    command_strings[3] = catgetlocal( 65, "!cmd : shell \"cmd\"    |nocase: ignore case in search   |quit : leave, no save");
  2204. X    command_strings[4] = catgetlocal( 66, "expand: expand tabs   |noexpand: do not expand tabs                           ");
  2205. X    com_win_message = catgetlocal( 67, "    press Escape (^[) for menu");
  2206. X    no_file_string = catgetlocal( 68, "no file");
  2207. X    ascii_code_str = catgetlocal( 69, "ascii code: ");
  2208. X    printer_msg_str = catgetlocal( 70, "sending contents of buffer to \"%s\" ");
  2209. X    command_str = catgetlocal( 71, "command: ");
  2210. X    file_write_prompt_str = catgetlocal( 72, "name of file to write: ");
  2211. X    file_read_prompt_str = catgetlocal( 73, "name of file to read: ");
  2212. X    char_str = catgetlocal( 74, "character = %d");
  2213. X    unkn_cmd_str = catgetlocal( 75, "unknown command \"%s\"");
  2214. X    non_unique_cmd_msg = catgetlocal( 76, "entered command is not unique");
  2215. X    line_num_str = catgetlocal( 77, "line %d  ");
  2216. X    line_len_str = catgetlocal( 78, "length = %d");
  2217. X    current_file_str = catgetlocal( 79, "current file is \"%s\" ");
  2218. X    usage0 = catgetlocal( 80, "usage: %s [-i] [-e] [-h] [file(s)]\n");
  2219. X    usage1 = catgetlocal( 81, "       -i   turn off info window\n");
  2220. X    usage2 = catgetlocal( 82, "       -e   do not convert tabs to spaces\n");
  2221. X    usage3 = catgetlocal( 83, "       -h   do not use highlighting\n");
  2222. X    file_is_dir_msg = catgetlocal( 84, "file \"%s\" is a directory");
  2223. X    new_file_msg = catgetlocal( 85, "new file \"%s\"");
  2224. X    cant_open_msg = catgetlocal( 86, "can't open \"%s\"");
  2225. X    open_file_msg = catgetlocal( 87, "file \"%s\", %d lines");
  2226. X    file_read_fin_msg = catgetlocal( 88, "finished reading file \"%s\"");
  2227. X    reading_file_msg = catgetlocal( 89, "reading file \"%s\"");
  2228. X    read_only_msg = catgetlocal( 90, ", read only");
  2229. X    file_read_lines_msg = catgetlocal( 91, "file \"%s\", %d lines");
  2230. X    save_file_name_prompt = catgetlocal( 92, "enter name of file: ");
  2231. X    file_not_saved_msg = catgetlocal( 93, "no filename entered: file not saved");
  2232. X    changes_made_prompt = catgetlocal( 94, "changes have been made, are you sure? (y/n [n]) ");
  2233. X    yes_char = catgetlocal( 95, "y");
  2234. X    file_exists_prompt = catgetlocal( 96, "file already exists, overwrite? (y/n) [n] ");
  2235. X    create_file_fail_msg = catgetlocal( 97, "unable to create file \"%s\"");
  2236. X    writing_file_msg = catgetlocal( 98, "writing file \"%s\"");
  2237. X    file_written_msg = catgetlocal( 99, "\"%s\" %d lines, %d characters");
  2238. X    searching_msg = catgetlocal( 100, "           ...searching");
  2239. X    str_not_found_msg = catgetlocal( 101, "string \"%s\" not found");
  2240. X    search_prompt_str = catgetlocal( 102, "search for: ");
  2241. X    exec_err_msg = catgetlocal( 103, "could not exec %s\n");
  2242. X    continue_msg = catgetlocal( 104, "press return to continue ");
  2243. X    menu_cancel_msg = catgetlocal( 105, "press Esc to cancel");
  2244. X    menu_size_err_msg = catgetlocal( 106, "menu too large for window");
  2245. X    press_any_key_msg = catgetlocal( 107, "press any key to continue ");
  2246. X    shell_prompt = catgetlocal( 108, "shell command: ");
  2247. X    formatting_msg = catgetlocal( 109, "...formatting paragraph...");
  2248. X    shell_echo_msg = catgetlocal( 110, "<!echo 'list of unrecognized words'; echo -=-=-=-=-=-");
  2249. X    spell_in_prog_msg = catgetlocal( 111, "sending contents of edit buffer to 'spell'");
  2250. X    margin_prompt = catgetlocal( 112, "right margin is: ");
  2251. X    restricted_msg = catgetlocal( 113, "restricted mode: unable to perform requested operation");
  2252. X    ON = catgetlocal( 114, "ON");
  2253. X    OFF = catgetlocal( 115, "OFF");
  2254. X    HELP = catgetlocal( 116, "HELP");
  2255. X    WRITE = catgetlocal( 117, "WRITE");
  2256. X    READ = catgetlocal( 118, "READ");
  2257. X    LINE = catgetlocal( 119, "LINE");
  2258. X    FILE_str = catgetlocal( 120, "FILE");
  2259. X    CHARACTER = catgetlocal( 121, "CHARACTER");
  2260. X    REDRAW = catgetlocal( 122, "REDRAW");
  2261. X    RESEQUENCE = catgetlocal( 123, "RESEQUENCE");
  2262. X    AUTHOR = catgetlocal( 124, "AUTHOR");
  2263. X    VERSION = catgetlocal( 125, "VERSION");
  2264. X    CASE = catgetlocal( 126, "CASE");
  2265. X    NOCASE = catgetlocal( 127, "NOCASE");
  2266. X    EXPAND = catgetlocal( 128, "EXPAND");
  2267. X    NOEXPAND = catgetlocal( 129, "NOEXPAND");
  2268. X    Exit_string = catgetlocal( 130, "EXIT");
  2269. X    QUIT_string = catgetlocal( 131, "QUIT");
  2270. X    INFO = catgetlocal( 132, "INFO");
  2271. X    NOINFO = catgetlocal( 133, "NOINFO");
  2272. X    MARGINS = catgetlocal( 134, "MARGINS");
  2273. X    NOMARGINS = catgetlocal( 135, "NOMARGINS");
  2274. X    AUTOFORMAT = catgetlocal( 136, "AUTOFORMAT");
  2275. X    NOAUTOFORMAT = catgetlocal( 137, "NOAUTOFORMAT");
  2276. X    Echo = catgetlocal( 138, "ECHO");
  2277. X    PRINTCOMMAND = catgetlocal( 139, "PRINTCOMMAND");
  2278. X    RIGHTMARGIN = catgetlocal( 140, "RIGHTMARGIN");
  2279. X    HIGHLIGHT = catgetlocal( 141, "HIGHLIGHT");
  2280. X    NOHIGHLIGHT = catgetlocal( 142, "NOHIGHLIGHT");
  2281. X    EIGHTBIT = catgetlocal( 143, "EIGHTBIT");
  2282. X    NOEIGHTBIT = catgetlocal( 144, "NOEIGHTBIT");
  2283. X    commands[0] = HELP;
  2284. X    commands[1] = WRITE;
  2285. X    commands[2] = READ;
  2286. X    commands[3] = LINE;
  2287. X    commands[4] = FILE_str;
  2288. X    commands[5] = REDRAW;
  2289. X    commands[6] = RESEQUENCE;
  2290. X    commands[7] = AUTHOR;
  2291. X    commands[8] = VERSION;
  2292. X    commands[9] = CASE;
  2293. X    commands[10] = NOCASE;
  2294. X    commands[11] = EXPAND;
  2295. X    commands[12] = NOEXPAND;
  2296. X    commands[13] = Exit_string;
  2297. X    commands[14] = QUIT_string;
  2298. X    commands[15] = "<";
  2299. X    commands[16] = ">";
  2300. X    commands[17] = "!";
  2301. X    commands[18] = "0";
  2302. X    commands[19] = "1";
  2303. X    commands[20] = "2";
  2304. X    commands[21] = "3";
  2305. X    commands[22] = "4";
  2306. X    commands[23] = "5";
  2307. X    commands[24] = "6";
  2308. X    commands[25] = "7";
  2309. X    commands[26] = "8";
  2310. X    commands[27] = "9";
  2311. X    commands[28] = CHARACTER;
  2312. X    commands[29] = NULL;
  2313. X    init_strings[0] = CASE;
  2314. X    init_strings[1] = NOCASE;
  2315. X    init_strings[2] = EXPAND;
  2316. X    init_strings[3] = NOEXPAND;
  2317. X    init_strings[4] = INFO;
  2318. X    init_strings[5] = NOINFO;
  2319. X    init_strings[6] = MARGINS;
  2320. X    init_strings[7] = NOMARGINS;
  2321. X    init_strings[8] = AUTOFORMAT;
  2322. X    init_strings[9] = NOAUTOFORMAT;
  2323. X    init_strings[10] = Echo;
  2324. X    init_strings[11] = PRINTCOMMAND;
  2325. X    init_strings[12] = RIGHTMARGIN;
  2326. X    init_strings[13] = HIGHLIGHT;
  2327. X    init_strings[14] = NOHIGHLIGHT;
  2328. X    init_strings[15] = EIGHTBIT;
  2329. X    init_strings[16] = NOEIGHTBIT;
  2330. X    init_strings[17] = NULL;
  2331. X
  2332. X#ifndef NO_CATGETS
  2333. X    catclose(catalog);
  2334. X#endif /* NO_CATGETS */
  2335. X}
  2336. X
  2337. END_OF_FILE
  2338.   if test 52272 -ne `wc -c <'ee.c.B'`; then
  2339.     echo shar: \"'ee.c.B'\" unpacked with wrong size!
  2340.   elif test -f 'ee.c.A'; then
  2341.     echo shar: Combining  \"'ee.c'\" \(97591 characters\)
  2342.     cat 'ee.c.A' 'ee.c.B' > 'ee.c'
  2343.     if test 97591 -ne `wc -c <'ee.c'`; then
  2344.       echo shar: \"'ee.c'\" combined with wrong size!
  2345.     else
  2346.       rm ee.c.A ee.c.B
  2347.     fi
  2348.   fi
  2349.   # end of 'ee.c.B'
  2350. fi
  2351. echo shar: End of archive 2 \(of 5\).
  2352. cp /dev/null ark2isdone
  2353. MISSING=""
  2354. for I in 1 2 3 4 5 ; do
  2355.     if test ! -f ark${I}isdone ; then
  2356.     MISSING="${MISSING} ${I}"
  2357.     fi
  2358. done
  2359. if test "${MISSING}" = "" ; then
  2360.     echo You have unpacked all 5 archives.
  2361.     rm -f ark[1-9]isdone
  2362. else
  2363.     echo You still must unpack the following archives:
  2364.     echo "        " ${MISSING}
  2365. fi
  2366. exit 0
  2367. exit 0 # Just in case...
  2368.