home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume18 / ftptool-4.3 / part08 < prev    next >
Text File  |  1992-08-18  |  51KB  |  1,974 lines

  1. Newsgroups: comp.sources.x
  2. Path: uunet!decwrl!mips!msi!dcmartin
  3. From: Mike.Sullivan@EBay.Sun.COM (Mike Sullivan {AKA Simon BarSinister})
  4. Subject: v18i090: Ftptool 4.3 (XVIEW), Part08/12
  5. Message-ID: <1992Aug18.153717.28965@msi.com>
  6. Originator: dcmartin@fascet
  7. Sender: dcmartin@msi.com (David C. Martin - Moderator)
  8. Organization: Molecular Simulations, Inc.
  9. References: <csx-18i083-ftptool-4.3@uunet.UU.NET>
  10. Date: Tue, 18 Aug 1992 15:37:17 GMT
  11. Approved: dcmartin@msi.com
  12. Lines: 1960
  13.  
  14. Submitted-by: Mike.Sullivan@EBay.Sun.COM (Mike Sullivan {AKA Simon BarSinister})
  15. Posting-number: Volume 18, Issue 90
  16. Archive-name: ftptool-4.3/part08
  17.  
  18. #!/bin/sh
  19. # this is part.08 (part 8 of a multipart archive)
  20. # do not concatenate these parts, unpack them in order with /bin/sh
  21. # file misc.c continued
  22. #
  23. if test ! -r _shar_seq_.tmp; then
  24.     echo 'Please unpack part 1 first!'
  25.     exit 1
  26. fi
  27. (read Scheck
  28.  if test "$Scheck" != 8; then
  29.     echo Please unpack part "$Scheck" next!
  30.     exit 1
  31.  else
  32.     exit 0
  33.  fi
  34. ) < _shar_seq_.tmp || exit 1
  35. if test ! -f _shar_wnt_.tmp; then
  36.     echo 'x - still skipping misc.c'
  37. else
  38. echo 'x - continuing file misc.c'
  39. sed 's/^X//' << 'SHAR_EOF' >> 'misc.c' &&
  40. int make_dirs(char *s, int make_last)
  41. #else
  42. int make_dirs(s, make_last)
  43. char    *s;
  44. int        make_last;
  45. #endif
  46. {
  47. X    int    rval = 0;
  48. X    char    *slash;
  49. X    char    *lastslash;
  50. X    char    ch;
  51. X    char    *dir;
  52. X
  53. X    dir = expand_dirname(s);
  54. X    if (dir == NULL)
  55. X        return ENOMEM;
  56. X    slash = dir;
  57. X    for (;;) {
  58. X        lastslash = slash;
  59. X        slash = index(lastslash + 1, '/');
  60. X        if (slash) {
  61. X            ch = *slash;
  62. X            *slash = '\0';
  63. X            if (mkdir(dir, 0777) == -1) {
  64. X                rval = errno;
  65. X                if (rval != EEXIST)
  66. X                    goto out;
  67. X                rval = 0;
  68. X            }
  69. X            *slash = ch;
  70. X        } else {
  71. X            if (make_last && mkdir(dir, 0777) == -1) {
  72. X                if (errno == EEXIST)
  73. X                    rval = 0;
  74. X                else
  75. X                    rval = errno;
  76. X            }
  77. X            goto out;
  78. X        }
  79. X    }
  80. out:
  81. X    free(dir);
  82. X    return rval;
  83. }
  84. X
  85. #ifdef USE_PROTOTYPES
  86. int ask_make_remote_dir(char *s)
  87. #else
  88. int ask_make_remote_dir(s)
  89. char    *s;
  90. #endif
  91. {
  92. X    int        answer;
  93. #ifdef XVIEW3
  94. X    Xv_notice notice;
  95. #endif
  96. X
  97. X    sprintf(scratch, "%s does not exist.", s);
  98. #ifdef XVIEW3
  99. X    notice = xv_create(base_window.panel, NOTICE,
  100. X        NOTICE_MESSAGE_STRINGS,
  101. X            scratch,
  102. X            "You can:",
  103. X            NULL,
  104. X        NOTICE_BUTTON,         "Cancel", 4,
  105. X        NOTICE_BUTTON,      "Try to create it", 3,
  106. X        NOTICE_STATUS, &answer,
  107. X        XV_SHOW, TRUE,
  108. X        NULL);
  109. X    xv_destroy_safe(notice);
  110. #else
  111. X    answer = notice_prompt(base_window.panel, NULL,
  112. X        NOTICE_MESSAGE_STRINGS,
  113. X            scratch,
  114. X            "You can:",
  115. X            NULL,
  116. X        NOTICE_BUTTON,         "Cancel", 4,
  117. X        NOTICE_BUTTON,      "Try to create it", 3,
  118. X        NULL);
  119. #endif
  120. X    if (answer == 4) 
  121. X        return -1;
  122. X
  123. X    return make_remote_dirs(s, 1);
  124. }
  125. X
  126. #ifdef USE_PROTOTYPES
  127. int make_remote_dirs(char *s, int make_last)
  128. #else
  129. int make_remote_dirs(s, make_last)
  130. char    *s;
  131. int        make_last;
  132. #endif
  133. {
  134. X    int    rval = 0;
  135. X    char    *slash;
  136. X    char    *lastslash;
  137. X    char    *colon;
  138. X    char    ch;
  139. X    char    *dir;
  140. X    char    *ftperr;
  141. X
  142. X    dir = strdup(s);
  143. X    if (dir == NULL)
  144. X        return ENOMEM;
  145. X    slash = dir;
  146. X    for (;;) {
  147. X        lastslash = slash;
  148. X        slash = index(lastslash + 1, '/');
  149. X        if (slash) {
  150. X            ch = *slash;
  151. X            *slash = '\0';
  152. X
  153. X            if (command("MKD %s", dir) == ERROR) {
  154. X                /* 550 file: File exists */
  155. X                colon = index(response_line, ':');
  156. X                if (!colon || strncmp(colon + 1, " File", 5)) {
  157. X                    /* permission denied or file exists */
  158. X                    sprintf(scratch, "Remote mkdir of %s failed.", dir);
  159. X                    ftperr = ftp_error(' ', scratch);
  160. X                    footer_message(ftperr, (char *)NULL);
  161. X                    return 1;
  162. X                }
  163. X            }
  164. X
  165. X            *slash = ch;
  166. X        } else {
  167. X            if (make_last) {
  168. X                if (command("MKD %s", dir) == ERROR) {
  169. X                    colon = index(response_line, ':');
  170. X                    if (!colon || strncmp(colon + 1, " File", 5)) {
  171. X                        /* permission denied or file exists */
  172. X                        sprintf(scratch, "Remote mkdir of %s failed.", dir);
  173. X                        ftperr = ftp_error(' ', scratch);
  174. X                        footer_message(ftperr, (char *)NULL);
  175. X                        return 1;
  176. X                    }
  177. X                }
  178. X
  179. X            }
  180. X            goto out;
  181. X        }
  182. X    }
  183. out:
  184. X    free(dir);
  185. X    return rval;
  186. }
  187. X
  188. /* geometry = widthxheight+x+y */
  189. #ifdef USE_PROTOTYPES
  190. void set_geometry(char *s, Frame frame, int def_width, int def_height, 
  191. X    int def_x, int def_y)
  192. #else
  193. void set_geometry(s, frame, def_width, def_height, def_x, def_y)
  194. char    *s;
  195. Frame    frame;
  196. int        def_width;
  197. int        def_height;
  198. int        def_x;
  199. int        def_y;
  200. #endif
  201. {
  202. X    int        width;
  203. X    int        height;
  204. X    int        x;
  205. X    int        y;
  206. X    Rect    rect;
  207. X
  208. X    if (strlen(s)==0 || sscanf(s,"%dx%d+%d+%d",&width, &height, &x, &y) != 4) {
  209. X        width = def_width;
  210. X        height = def_height;
  211. X        x = def_x;
  212. X        y = def_y;
  213. X    }
  214. X    if (x < 0 || x >= display_width)
  215. X        x = 0;
  216. X    if (y < 0 || y >= display_height)
  217. X        y = 0;
  218. X    rect.r_left = x;
  219. X    rect.r_top = y;
  220. X    if (width < def_width)
  221. X        rect.r_width = def_width;
  222. X    else
  223. X        rect.r_width = width;
  224. X    if (height < def_height)
  225. X        rect.r_height = def_height;
  226. X    else
  227. X        rect.r_height = height;
  228. X    frame_set_rect(frame, &rect);
  229. }
  230. X
  231. #ifdef USE_PROTOTYPES
  232. void save_geometry(char *s, Frame frame)
  233. #else
  234. void save_geometry(s, frame)
  235. char    *s;
  236. Frame    frame;
  237. #endif
  238. {
  239. X    Rect    rect;
  240. X
  241. X    frame_get_rect(frame, &rect);
  242. X    sprintf(s, "%dx%d+%d+%d", rect.r_width, rect.r_height, 
  243. X        rect.r_left, rect.r_top);
  244. }
  245. X
  246. #ifdef USE_PROTOTYPES
  247. void justify_items(Panel panel, int resize)
  248. #else
  249. void justify_items(panel, resize)
  250. Panel    panel;
  251. int    resize;        /* TRUE to resize text fields */
  252. #endif
  253. {
  254. X    register Panel_item    item;
  255. X    register int        value_x;
  256. X    register Panel_item_type class;
  257. X    Xv_Font            font = XV_NULL;
  258. X    Font_string_dims    font_size;
  259. X    int            longest = 0;
  260. X    char            *string;
  261. X
  262. X    if (panel == XV_NULL)
  263. X        return;
  264. X
  265. X    /*
  266. X     * Compute the longest label excluding all panel buttons
  267. X     */
  268. X    PANEL_EACH_ITEM(panel, item) {
  269. X        if ((int)xv_get(item, PANEL_SHOW_ITEM) && ((Panel_item_type)
  270. X            xv_get(item, PANEL_ITEM_CLASS) != PANEL_BUTTON_ITEM)) {
  271. X            font = (Xv_Font)xv_get(item, PANEL_LABEL_FONT);
  272. X            string = (char *)xv_get(item, PANEL_LABEL_STRING);
  273. X            xv_get(font,FONT_STRING_DIMS, string, &font_size);
  274. X            if (font_size.width > longest)  {
  275. X                longest = font_size.width;
  276. X            }
  277. X        }
  278. X    } PANEL_END_EACH;
  279. X
  280. X    value_x = longest + 2 * (int)xv_get(panel, PANEL_ITEM_X_GAP);
  281. X
  282. X    /* Layout each item (except buttons) on the panel */
  283. X    PANEL_EACH_ITEM(panel, item) {
  284. X        if ((int)xv_get(item, PANEL_SHOW_ITEM) &&
  285. X            ((class = (Panel_item_type)xv_get(item, PANEL_ITEM_CLASS))
  286. X                    != PANEL_BUTTON_ITEM)) {
  287. X            xv_set(item, 
  288. X                PANEL_VALUE_X, value_x, 
  289. X                NULL);
  290. X            if (resize && class == PANEL_TEXT_ITEM) {
  291. X                resize_text_item(panel, item);
  292. X            }
  293. X        }
  294. X    }
  295. X    PANEL_END_EACH;
  296. X
  297. X    return;
  298. }
  299. X
  300. #ifdef USE_PROTOTYPES
  301. void resize_text_item(Panel panel, Panel_item text_item)
  302. #else
  303. void resize_text_item(panel, text_item)
  304. Panel        panel;
  305. Panel_item    text_item;
  306. #endif
  307. {
  308. X    Xv_Font    font;
  309. X    int    width;
  310. X    int    n;
  311. X
  312. X    if (panel == XV_NULL || text_item == XV_NULL)
  313. X        return;
  314. X
  315. X    /*
  316. X     * Set the display width of the fillin field to extend to the
  317. X     * right edge of the panel. 
  318. X     */
  319. X    width = (int)xv_get(panel, XV_WIDTH) -
  320. X        (int)xv_get(text_item, PANEL_VALUE_X) -
  321. X        (int)xv_get(panel, PANEL_ITEM_X_GAP);
  322. X
  323. X    font = (Xv_Font)xv_get(panel, XV_FONT);
  324. X    n = width / (int)xv_get(font, FONT_DEFAULT_CHAR_WIDTH);
  325. X
  326. X    /*
  327. X     * Make sure it gets no smaller than 5 characters and no larger
  328. X     * than the stored length.
  329. X     */
  330. X    if (n < 5)
  331. X        n = 5;
  332. X    else if (n > (int)xv_get(text_item, PANEL_VALUE_STORED_LENGTH))
  333. X        n = (int)xv_get(text_item, PANEL_VALUE_STORED_LENGTH);
  334. X
  335. X    xv_set(text_item, 
  336. X        PANEL_VALUE_DISPLAY_LENGTH, n,
  337. X        NULL);
  338. X
  339. X    return;
  340. }
  341. X
  342. #ifdef USE_PROTOTYPES
  343. char *linkval(char *string)
  344. #else
  345. char *linkval(string)
  346. char    *string;
  347. #endif
  348. {
  349. X    char    *tmp;
  350. X
  351. X    /* string is of the form */
  352. X    /* name -> value */
  353. X    /* be somewhat sure we find the ->, not just one or the other, */
  354. X    /* since those _are_ legal filename characters */
  355. X    tmp = string;
  356. X
  357. X    while ((tmp = index(tmp, '-')) != NULL) {
  358. X        if (tmp[1] == '>' && tmp[2] == ' ')
  359. X            return strdup(&tmp[3]);
  360. X        tmp++; /* skip '-', since we didn't find -> */
  361. X    }
  362. X    fprintf(stderr, "linkval: malformed link entry\n");
  363. X    return NULL;
  364. }
  365. X
  366. #ifdef USE_PROTOTYPES
  367. char *linkname(char *string)
  368. #else
  369. char *linkname(string)
  370. char    *string;
  371. #endif
  372. {
  373. X    char    *str, *tmp;
  374. X
  375. X    /* string is of the form */
  376. X    /* name -> value */
  377. X    /* be somewhat sure we find the ->, not just one or the other, */
  378. X    /* since those _are_ legal filename characters */
  379. X    str = strdup(string);
  380. X    if (str == NULL) {
  381. X        fprintf(stderr, "linkname: Out of memory.\n");
  382. X        return NULL;
  383. X    }
  384. X    tmp = str;
  385. X
  386. X    while ((tmp = index(tmp, '-')) != NULL) {
  387. X        if (tmp[1] == '>' && tmp[2] == ' ' && tmp > str && tmp[-1] == ' ') {
  388. X            tmp[-1] = '\0';
  389. X            return str;
  390. X        }
  391. X        tmp++; /* skip '-', since we didn't find -> */
  392. X    }
  393. X    /*
  394. X    fprintf(stderr, "linkval: malformed link entry\n");
  395. X    free(str);
  396. X    */
  397. X    return str;
  398. }
  399. X
  400. #ifdef USE_PROTOTYPES
  401. void add_dismiss(Panel panel, Panel_item first, Panel_item dismiss)
  402. #else
  403. void add_dismiss(panel, first, dismiss)
  404. Panel    panel;
  405. Panel_item    first;
  406. Panel_item    dismiss;
  407. #endif
  408. {
  409. X    Rect    *first_rect;
  410. X    Rect    *dismiss_rect;
  411. X    int    width,space,pos;
  412. X
  413. X    width = xv_get(panel, XV_WIDTH);
  414. X    first_rect = (Rect *)xv_get(first, XV_RECT);
  415. X    if (openlook_mode) {
  416. X        xv_set(dismiss,
  417. X            XV_SHOW, FALSE,
  418. X            NULL);
  419. X        xv_set(first,
  420. X            XV_X, width/2 - first_rect->r_width/2,
  421. X            XV_SHOW, TRUE,
  422. X            NULL);
  423. X    } else {
  424. X        dismiss_rect = (Rect *)xv_get(dismiss, XV_RECT);
  425. X        space = xv_col(panel, 1);
  426. X        pos = (width-(first_rect->r_width+space+dismiss_rect->r_width))/2;
  427. X        xv_set(first,
  428. X            XV_X, pos,
  429. X            XV_SHOW, TRUE,
  430. X            NULL);
  431. X        xv_set(dismiss,
  432. X            XV_X, pos + first_rect->r_width + space,
  433. X            XV_SHOW, TRUE,
  434. X            NULL);
  435. X    }
  436. X
  437. }
  438. X
  439. #ifdef USE_PROTOTYPES
  440. void update_date(int doscheddefault)
  441. #else
  442. void update_date(doscheddefault)
  443. int    doscheddefault;
  444. #endif
  445. {
  446. X    time_t    t;
  447. X    struct tm *tm;
  448. X    static char date[30];
  449. X
  450. X    t = time((time_t *)NULL);
  451. X    tm = localtime(&t);
  452. X    current_year = tm->tm_year;
  453. X    current_month = tm->tm_mon;
  454. X    strftime(date, sizeof(date), "%R %b %e %Y", tm);
  455. X    xv_set(schedule_window.current_time,
  456. X        PANEL_LABEL_STRING, date,
  457. X        NULL);
  458. X    if (doscheddefault) {
  459. X        xv_set(schedule_window.hour,
  460. X            PANEL_VALUE, tm->tm_hour,
  461. X            NULL);
  462. X        xv_set(schedule_window.minute,
  463. X            PANEL_VALUE, tm->tm_min,
  464. X            NULL);
  465. X        xv_set(schedule_window.month,
  466. X            PANEL_VALUE, tm->tm_mon,
  467. X            NULL);
  468. X        xv_set(schedule_window.day,
  469. X            PANEL_VALUE, tm->tm_mday,
  470. X            NULL);
  471. X        xv_set(schedule_window.year,
  472. X            PANEL_VALUE, tm->tm_year + 1900,
  473. X            NULL);
  474. X    }
  475. }
  476. X
  477. #ifdef USE_PROTOTYPES
  478. Notify_value date_wrapper(void)
  479. #else
  480. Notify_value date_wrapper()
  481. #endif
  482. {
  483. X    update_date(0);
  484. X    return NOTIFY_DONE;
  485. }
  486. X
  487. #ifdef USE_PROTOTYPES
  488. void local_show_items(void)
  489. #else
  490. void local_show_items()
  491. #endif
  492. {
  493. X    int    nitems =  (int)xv_get(local_window.list, PANEL_LIST_NROWS);
  494. X
  495. X    if (nitems == 1) {
  496. X        local_right_footer_message("1 item, %d selected", 
  497. X            local_list_nfiles + local_list_ndirs + local_list_nothers);
  498. X    } else {
  499. X        local_right_footer_message("%d items, %d selected", nitems,
  500. X            local_list_nfiles + local_list_ndirs + local_list_nothers);
  501. X    }
  502. }
  503. X
  504. #ifdef USE_PROTOTYPES
  505. void remote_show_items(void)
  506. #else
  507. void remote_show_items()
  508. #endif
  509. {
  510. X    int    nitems = (int)xv_get(base_window.list, PANEL_LIST_NROWS);
  511. X
  512. X    if (nitems == 1) {
  513. X        right_footer_message("1 item, %d selected", 
  514. X            remote_list_nfiles + remote_list_ndirs + remote_list_nothers);
  515. X    } else {
  516. X        right_footer_message("%d items, %d selected", nitems,
  517. X            remote_list_nfiles + remote_list_ndirs + remote_list_nothers);
  518. X    }
  519. }
  520. X
  521. #ifdef USE_PROTOTYPES
  522. int ping_server(void)
  523. #else
  524. int ping_server()
  525. #endif
  526. {
  527. X    (void)command("NOOP");
  528. X    if (code == 421) {
  529. X        timedout++;
  530. X        return ETIMEDOUT;
  531. X    }
  532. X    return 0;
  533. }
  534. X
  535. #ifdef NEED_STRCASECMP
  536. X
  537. /* A quick and dirty version of strcasecmp(), which seems to work */
  538. X
  539. #ifdef USE_PROTOTYPES
  540. int strcasecmp(const char *s1, const char *s2)
  541. #else
  542. int strcasecmp(s1, s2)
  543. char *s1, *s2;
  544. #endif
  545. {
  546. X    char    c1, c2;
  547. X
  548. X    while(*s1 && *s2) {
  549. X        if (isupper(*s1))
  550. X            c1 = tolower(*s1);
  551. X        else
  552. X            c1 = *s1;
  553. X        if (isupper(*s2))
  554. X            c2 = tolower(*s2);
  555. X        else
  556. X            c2 = *s2;
  557. X        if (c1 == c2) {
  558. X            s1++;
  559. X            s2++;
  560. X            continue;
  561. X        }
  562. X        else if (c1 > c2)
  563. X            return 1;
  564. X        else
  565. X            return -1;
  566. X    }
  567. X    if (*s1 == '\0' && *s2 == '\0')
  568. X        return 0;
  569. X    
  570. X    if (*s1 == '\0')
  571. X        return -1;
  572. X    
  573. X    return 1;
  574. X
  575. }
  576. X
  577. #endif
  578. SHAR_EOF
  579. echo 'File misc.c is complete' &&
  580. chmod 0644 misc.c ||
  581. echo 'restore of misc.c failed'
  582. Wc_c="`wc -c < 'misc.c'`"
  583. test 23290 -eq "$Wc_c" ||
  584.     echo 'misc.c: original size 23290, current size' "$Wc_c"
  585. rm -f _shar_wnt_.tmp
  586. fi
  587. # ============= create_main.c ==============
  588. if test -f 'create_main.c' -a X"$1" != X"-c"; then
  589.     echo 'x - skipping create_main.c (File already exists)'
  590.     rm -f _shar_wnt_.tmp
  591. else
  592. > _shar_wnt_.tmp
  593. echo 'x - extracting create_main.c (Text)'
  594. sed 's/^X//' << 'SHAR_EOF' > 'create_main.c' &&
  595. #include "ftptool.h"
  596. X
  597. #ifdef USE_PROTOTYPES
  598. void create_base_window(void)
  599. #else
  600. void create_base_window()
  601. #endif
  602. {
  603. X    Menu file_menu;
  604. X    Menu copy_menu;
  605. X    Menu delete_menu;
  606. X    Menu dir_menu;
  607. X    Menu view_menu;
  608. X    Menu props_menu;
  609. X    Menu remote_list_menu;
  610. X    Xv_Screen    screen;
  611. X    int        screen_no;
  612. X    int    width, height, x, y;
  613. X
  614. X    base_window.frame = xv_create(XV_NULL, FRAME,
  615. X        XV_X, 350,
  616. X        XV_Y, 100,
  617. X        XV_LABEL, header_name,
  618. X        FRAME_SHOW_FOOTER, TRUE,
  619. X        FRAME_LEFT_FOOTER, NULL,
  620. X        NULL);
  621. X
  622. X    base_window.panel = xv_create(base_window.frame, PANEL,
  623. X        XV_X, 0,
  624. X        XV_Y, 0,
  625. X        XV_WIDTH, WIN_EXTEND_TO_EDGE,
  626. X        WIN_BORDER, FALSE,
  627. X        NULL);
  628. X
  629. X    list_label = "                 Date                     Size   Filename";
  630. X
  631. X    list_font = (Xv_font)xv_find(base_window.panel, FONT,
  632. X        FONT_FAMILY, FONT_FAMILY_DEFAULT_FIXEDWIDTH,
  633. X        FONT_STYLE, FONT_STYLE_NORMAL,
  634. X        NULL);
  635. X
  636. X    if (list_font == XV_NULL) {
  637. X        fprintf(stderr, "could not find default fixed font.\n");
  638. X    } else {
  639. X        switch((int)xv_get(list_font, FONT_SCALE)) {
  640. X        case WIN_SCALE_SMALL:
  641. X            list_label = "                     Date                        Size    Filename";
  642. X            break;
  643. X        case WIN_SCALE_MEDIUM:
  644. X        default:
  645. X            /* this seems to be the default */
  646. X            list_label = "                 Date                     Size   Filename";
  647. X            break;
  648. X        case WIN_SCALE_LARGE:
  649. X            list_label = "                     Date                            Size    Filename";
  650. X            break;
  651. X        case WIN_SCALE_EXTRALARGE:
  652. X            list_label = "            Date                    Size   Filename";
  653. X            break;
  654. X        }
  655. X    }
  656. X
  657. X    bold_list_font = (Xv_font)xv_find(base_window.panel, FONT,
  658. X        FONT_FAMILY, FONT_FAMILY_DEFAULT_FIXEDWIDTH,
  659. X        FONT_STYLE, FONT_STYLE_BOLD,
  660. X        NULL);
  661. X
  662. X    if (bold_list_font == XV_NULL)
  663. X        fprintf(stderr, "could not find default bold fixed font.\n");
  664. X
  665. X    xv_set(base_window.panel, 
  666. X        PANEL_LAYOUT, 
  667. X        PANEL_HORIZONTAL,
  668. X        NULL);
  669. X
  670. X
  671. X    copy_menu = xv_create(XV_NULL, MENU,
  672. X        MENU_GEN_PROC, file_copy_menu_gen,
  673. X        MENU_ITEM,
  674. X            MENU_STRING, "Remote to Local",
  675. X            MENU_NOTIFY_PROC, get_proc,
  676. X            XV_HELP_DATA, "ftptool:FileCopyRemote",
  677. X            NULL,
  678. X        MENU_ITEM,
  679. X            MENU_STRING, "Local to Remote",
  680. X            MENU_NOTIFY_PROC, put_proc,
  681. X            XV_HELP_DATA, "ftptool:FileCopyLocal",
  682. X            NULL,
  683. X        MENU_ITEM,
  684. X            MENU_STRING, "Remote to Local (Batch)",
  685. X            MENU_NOTIFY_PROC, batchget_proc,
  686. X            XV_HELP_DATA, "ftptool:BatchReceiveCopy",
  687. X            NULL,
  688. X        MENU_ITEM,
  689. X            MENU_STRING, "Local to Remote (Batch)",
  690. X            MENU_NOTIFY_PROC, batchput_proc,
  691. X            XV_HELP_DATA, "ftptool:BatchSendCopy",
  692. X            NULL,
  693. X        NULL);
  694. X
  695. X    delete_menu = xv_create(XV_NULL, MENU,
  696. X        MENU_GEN_PROC, file_delete_menu_gen,
  697. X        MENU_ITEM,
  698. X            MENU_STRING, "Remote File",
  699. X            MENU_NOTIFY_PROC, remote_delete_proc,
  700. X            XV_HELP_DATA, "ftptool:FileDeleteRemote",
  701. X            NULL,
  702. X        MENU_ITEM,
  703. X            MENU_STRING, "Local File",
  704. X            MENU_NOTIFY_PROC, local_delete_proc,
  705. X            XV_HELP_DATA, "ftptool:FileLocalRemote",
  706. X            NULL,
  707. X        NULL);
  708. X
  709. X    dir_menu = xv_create(XV_NULL, MENU,
  710. X        MENU_ITEM,
  711. X            MENU_STRING, "DIR",
  712. X            MENU_NOTIFY_PROC, dir_list_proc,
  713. X            XV_HELP_DATA, "ftptool:FileDir",
  714. X            NULL,
  715. X        MENU_ITEM,
  716. X            MENU_STRING, "LS",
  717. X            MENU_NOTIFY_PROC, ls_list_proc,
  718. X            XV_HELP_DATA, "ftptool:FileLS",
  719. X            NULL,
  720. X        NULL);
  721. X
  722. #ifdef LINT
  723. X    file_menu = NULL;
  724. X    file_menu = file_menu;
  725. X    copy_menu = copy_menu;
  726. X    delete_menu = delete_menu;
  727. X    dir_menu = dir_menu;
  728. #else
  729. X    file_menu = xv_create(XV_NULL, MENU,
  730. X        MENU_GEN_PROC, file_menu_gen,
  731. X        MENU_PULLRIGHT_ITEM, "Copy", copy_menu,
  732. X        MENU_PULLRIGHT_ITEM, "Delete", delete_menu,
  733. X        MENU_PULLRIGHT_ITEM, "List Directory", dir_menu,
  734. X        MENU_ITEM,
  735. X            MENU_STRING, "Compress File",
  736. X            MENU_NOTIFY_PROC, compress_proc,
  737. X            XV_HELP_DATA, "ftptool:FileCompress",
  738. X            NULL,
  739. X        MENU_ITEM,
  740. X            MENU_STRING, "Uncompress File",
  741. X            MENU_NOTIFY_PROC, uncompress_proc,
  742. X            XV_HELP_DATA, "ftptool:FileUncompress",
  743. X            NULL,
  744. X        MENU_ITEM,
  745. X            MENU_STRING, "Create Tar File",
  746. X            MENU_NOTIFY_PROC, tar_proc,
  747. X            XV_HELP_DATA, "ftptool:FileCreateTar",
  748. X            NULL,
  749. X        MENU_ITEM,
  750. X            MENU_STRING, "Extract Tar File",
  751. X            MENU_NOTIFY_PROC, extract_proc,
  752. X            XV_HELP_DATA, "ftptool:FileExtractTar",
  753. X            NULL,
  754. X        NULL);
  755. #endif
  756. X
  757. X    base_window.file = xv_create(base_window.panel, PANEL_BUTTON,
  758. X        PANEL_LABEL_STRING, "File",
  759. X        PANEL_ITEM_MENU, file_menu, 
  760. X        XV_HELP_DATA, "ftptool:FileButton",
  761. X        NULL);
  762. X
  763. #ifdef LINT
  764. X    view_menu = NULL;
  765. X    view_menu = view_menu;
  766. #else
  767. X    view_menu = xv_create(XV_NULL, MENU,
  768. X        MENU_GEN_PROC, view_menu_gen,
  769. X        MENU_ITEM,
  770. X            MENU_STRING, "Remote File",
  771. X            MENU_NOTIFY_PROC, remote_view,
  772. X            XV_HELP_DATA, "ftptool:ViewRemote",
  773. X            NULL,
  774. X        MENU_ITEM,
  775. X            MENU_STRING, "Local File",
  776. X            MENU_NOTIFY_PROC, local_view,
  777. X            XV_HELP_DATA, "ftptool:ViewLocal",
  778. X            NULL,
  779. X        MENU_ITEM,
  780. X            MENU_STRING, "Local Directory List...",
  781. X            MENU_NOTIFY_PROC, local_dir_view,
  782. X            XV_HELP_DATA, "ftptool:ViewLocalDirectory",
  783. X            NULL,
  784. X        MENU_ITEM,
  785. X            MENU_STRING, "Session Log...",
  786. X            MENU_NOTIFY_PROC, session_view,
  787. X            XV_HELP_DATA, "ftptool:ViewSessionLog",
  788. X            NULL,
  789. X        MENU_ITEM,
  790. X            MENU_STRING, "Host Information...",
  791. X            MENU_NOTIFY_PROC, host_view,
  792. X            XV_HELP_DATA, "ftptool:ViewCurrentHost",
  793. X            NULL,
  794. X        MENU_ITEM,
  795. X            MENU_STRING, "Transfer Status...",
  796. X            MENU_NOTIFY_PROC, status_view,
  797. X            XV_HELP_DATA, "ftptool:ViewStatus",
  798. X            NULL,
  799. X        MENU_ITEM,
  800. X            MENU_STRING, "Batch Schedule...",
  801. X            MENU_NOTIFY_PROC, schedule_view,
  802. X            XV_HELP_DATA, "ftptool:ViewSchedule",
  803. X            NULL,
  804. X        MENU_ITEM,
  805. X            MENU_STRING, "About Ftptool...",
  806. X            MENU_NOTIFY_PROC, about_proc,
  807. X            XV_HELP_DATA, "ftptool:FileAbout",
  808. X            NULL,
  809. X        NULL);
  810. #endif
  811. X
  812. X    base_window.view = xv_create(base_window.panel, PANEL_BUTTON,
  813. X        PANEL_LABEL_STRING, "View",
  814. X        PANEL_ITEM_MENU, view_menu,
  815. X        XV_HELP_DATA, "ftptool:ViewButton",
  816. X        NULL);
  817. X
  818. X
  819. X    props_menu = xv_create(XV_NULL, MENU,
  820. X        MENU_GEN_PROC, props_menu_gen,
  821. X        MENU_ITEM,
  822. X            MENU_STRING, "Tool...",
  823. X            MENU_NOTIFY_PROC, props_proc,
  824. X            XV_HELP_DATA, "ftptool:PropertiesTool",
  825. X            NULL,
  826. X        MENU_ITEM,
  827. X            MENU_STRING, "Local File...",
  828. X            MENU_NOTIFY_PROC, local_properties,
  829. X            XV_HELP_DATA, "ftptool:PropertiesLocal",
  830. X            NULL,
  831. X        MENU_ITEM,
  832. X            MENU_STRING, "Remote File...",
  833. X            MENU_NOTIFY_PROC, remote_properties,
  834. X            XV_HELP_DATA, "ftptool:PropertiesRemote",
  835. X            NULL,
  836. X        MENU_ITEM,
  837. X            MENU_STRING, "Save Layout",
  838. X            MENU_NOTIFY_PROC, save_layout_func,
  839. X            XV_HELP_DATA, "ftptool:PropertiesSaveLayout",
  840. X            NULL,
  841. X        NULL);
  842. X
  843. X    base_window.props = xv_create(base_window.panel, PANEL_BUTTON,
  844. X        PANEL_ITEM_X_GAP, 3 * (int)xv_get(base_window.panel, PANEL_ITEM_X_GAP),
  845. X        PANEL_LABEL_STRING, "Properties",
  846. X        PANEL_ITEM_MENU, props_menu,
  847. X        XV_HELP_DATA, "ftptool:PropertiesButton",
  848. X        NULL);
  849. X
  850. X    base_window.connect = xv_create(base_window.panel, PANEL_BUTTON,
  851. X        PANEL_ITEM_X_GAP, 3 * (int)xv_get(base_window.panel, PANEL_ITEM_X_GAP),
  852. X        PANEL_LABEL_STRING, " Connect... ",
  853. X        PANEL_NOTIFY_PROC, connect_proc,
  854. X        XV_HELP_DATA, "ftptool:ConnectButton",
  855. X        NULL);
  856. X
  857. X    base_window.abort = xv_create(base_window.panel, PANEL_BUTTON,
  858. X        PANEL_LABEL_STRING, "Abort",
  859. X        PANEL_NOTIFY_PROC, abort_proc,
  860. X        PANEL_INACTIVE, TRUE,
  861. X        XV_HELP_DATA, "ftptool:AbortButton",
  862. X        NULL);
  863. X
  864. X    base_window.quit = xv_create(base_window.panel, PANEL_BUTTON,
  865. X        PANEL_LABEL_STRING, "Quit",
  866. X        PANEL_NOTIFY_PROC, quit_proc,
  867. X        XV_HELP_DATA, "ftptool:QuitButton",
  868. X        XV_SHOW, openlook_mode ? FALSE : TRUE,
  869. X        NULL);
  870. X
  871. X    xv_set(base_window.panel, 
  872. X        PANEL_LAYOUT, PANEL_VERTICAL, 
  873. X        NULL);
  874. X
  875. X    base_window.directory = xv_create(base_window.panel, PANEL_TEXT,
  876. X        PANEL_ITEM_X, 0,
  877. X        PANEL_VALUE_DISPLAY_LENGTH, 42,
  878. X        PANEL_VALUE_STORED_LENGTH, MAXPATHLEN,
  879. X        PANEL_LABEL_STRING, "Remote Directory:",
  880. X        PANEL_LAYOUT, PANEL_HORIZONTAL,
  881. X        PANEL_READ_ONLY, FALSE,
  882. X        PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
  883. X        PANEL_NOTIFY_PROC, remote_cd_text,
  884. X        PANEL_INACTIVE, TRUE,
  885. X        XV_HELP_DATA, "ftptool:RemoteDirectory",
  886. X        NULL);
  887. X
  888. X    base_window.list = xv_create(base_window.panel, PANEL_LIST,
  889. X        PANEL_ITEM_X, 2,
  890. X        PANEL_NEXT_ROW, xv_row(base_window.panel, 1),
  891. X        PANEL_LIST_DISPLAY_ROWS, 8,
  892. X        PANEL_LABEL_STRING, list_label,
  893. X        PANEL_FONT, bold_list_font,
  894. X        PANEL_LAYOUT, PANEL_VERTICAL,
  895. X        PANEL_READ_ONLY, TRUE,
  896. X        PANEL_CHOOSE_ONE, FALSE,
  897. X        PANEL_CHOOSE_NONE, TRUE,
  898. X        PANEL_NOTIFY_PROC, remote_list_proc,
  899. X        XV_HELP_DATA, "ftptool:RemoteList",
  900. X        NULL);
  901. X
  902. X    remote_list_menu = xv_get(base_window.list, PANEL_ITEM_MENU);
  903. #ifdef LINT
  904. X    remote_list_menu = remote_list_menu;
  905. #else
  906. X    xv_set(remote_list_menu, 
  907. X        MENU_GEN_PIN_WINDOW, base_window.frame, "Remote File List",
  908. X        MENU_TITLE_ITEM, "Remote File List",
  909. X        MENU_ITEM,
  910. X            MENU_STRING, "",
  911. X            MENU_FEEDBACK, FALSE,
  912. X            NULL,
  913. X        MENU_ITEM,
  914. X            MENU_STRING, "CD to Selection",
  915. X            MENU_NOTIFY_PROC, remote_cd_select,
  916. X            XV_HELP_DATA, "ftptool:RemoteMenuCDSelection",
  917. X            NULL,
  918. X        MENU_ITEM,
  919. X            MENU_STRING, "Up One Level",
  920. X            MENU_NOTIFY_PROC, remote_cd_dotdot,
  921. X            XV_HELP_DATA, "ftptool:RemoteMenuCDUp",
  922. X            NULL,
  923. X        MENU_ITEM,
  924. X            MENU_STRING, "Copy to Local",
  925. X            MENU_NOTIFY_PROC, get_proc,
  926. X            XV_HELP_DATA, "ftptool:RemoteMenuCopyLocal",
  927. X            NULL,
  928. X        MENU_ITEM,
  929. X            MENU_STRING, "Add to Batch Receive List",
  930. X            MENU_NOTIFY_PROC, add_batch_receive_proc,
  931. X            XV_HELP_DATA, "ftptool:BatchReceiveAdd",
  932. X            NULL,
  933. X        MENU_ITEM,
  934. X            MENU_STRING, "View File",
  935. X            MENU_NOTIFY_PROC, remote_view,
  936. X            XV_HELP_DATA, "ftptool:RemoteMenuView",
  937. X            NULL,
  938. X        MENU_ITEM,
  939. X            MENU_STRING, "Delete",
  940. X            MENU_NOTIFY_PROC, remote_delete_proc,
  941. X            XV_HELP_DATA, "ftptool:FileDeleteRemote",
  942. X            NULL,
  943. X        MENU_ITEM,
  944. X            MENU_STRING, "Properties...",
  945. X            MENU_NOTIFY_PROC, remote_properties,
  946. X            XV_HELP_DATA, "ftptool:RemoteMenuProperties",
  947. X            NULL,
  948. X        NULL);
  949. #endif
  950. X
  951. X    change_remote_list_menu();
  952. X    xv_set(base_window.panel, 
  953. X        PANEL_LAYOUT, PANEL_HORIZONTAL, 
  954. X        NULL);
  955. X
  956. X    window_fit(base_window.panel);
  957. X    window_fit(base_window.frame);
  958. X
  959. X    dpy = (Display *)xv_get(base_window.frame, XV_DISPLAY);
  960. X    screen = (Xv_Screen)xv_get(base_window.frame, XV_SCREEN);
  961. X    screen_no = (int)xv_get(screen, SCREEN_NUMBER);
  962. X
  963. X    display_width = DisplayWidth(dpy, screen_no);
  964. X    display_height = DisplayHeight(dpy, screen_no);
  965. X
  966. X    width = xv_get(base_window.frame, XV_WIDTH);
  967. X    height = xv_get(base_window.frame, XV_HEIGHT);
  968. X    x = xv_get(base_window.frame, XV_X);
  969. X    y = xv_get(base_window.frame, XV_Y);
  970. X
  971. X    set_geometry(base_window.geometry, base_window.frame, width, height, x, y);
  972. X    
  973. X    XSync(dpy, False);
  974. X
  975. X    xv_set(base_window.frame,
  976. X        WIN_EVENT_PROC, base_event_proc,
  977. X        NULL);
  978. X
  979. X    xv_set(base_window.panel,
  980. X        PANEL_BACKGROUND_PROC, props_event_proc,
  981. X        PANEL_ACCEPT_KEYSTROKE, TRUE,
  982. X        NULL);
  983. }
  984. X
  985. #ifdef USE_PROTOTYPES
  986. void create_property_window(void)
  987. #else
  988. void create_property_window()
  989. #endif
  990. {
  991. X    Rect    *butrect;
  992. X    int        options;
  993. X    int        x, y;
  994. X
  995. X    tool_property_window.frame = xv_create(base_window.frame, FRAME_PROPS,
  996. X        XV_LABEL, "Ftptool: Properties",
  997. X        NULL);
  998. X
  999. X    tool_property_window.panel = (Panel)xv_get(tool_property_window.frame, 
  1000. X        FRAME_PROPS_PANEL);
  1001. X
  1002. X    tool_property_window.category = xv_create(tool_property_window.panel, 
  1003. X        PANEL_CHOICE_STACK,
  1004. X        PANEL_LAYOUT, PANEL_HORIZONTAL,
  1005. X        PANEL_LABEL_STRING, "Category:",
  1006. X        PANEL_CHOICE_STRINGS,
  1007. X            "Ftptool",
  1008. X            "Directory Lists",
  1009. X            "Viewers",
  1010. X            NULL,
  1011. X        PANEL_VALUE, 0,
  1012. X        PANEL_NOTIFY_PROC, category_proc,
  1013. X        NULL);
  1014. X
  1015. X    xv_set(tool_property_window.panel, 
  1016. X        PANEL_LAYOUT, PANEL_VERTICAL, 
  1017. X        NULL);
  1018. X        
  1019. X    window_fit_height(tool_property_window.panel);
  1020. X
  1021. X    /* ftptool panel */
  1022. X
  1023. X    tool_property_window.ftptool.panel = xv_create(tool_property_window.frame, 
  1024. X        PANEL,
  1025. X        PANEL_LAYOUT, PANEL_VERTICAL,
  1026. X        WIN_BORDER, TRUE,
  1027. X        NULL);
  1028. X
  1029. X    x = xv_get(tool_property_window.ftptool.panel, XV_X);
  1030. X    y = xv_get(tool_property_window.ftptool.panel, XV_Y);
  1031. X
  1032. X    options = logging | keepalive;
  1033. X    tool_property_window.ftptool.options =
  1034. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHOICE,
  1035. X        PANEL_LABEL_STRING, "FTP options:",
  1036. X        PANEL_CHOOSE_ONE, FALSE,
  1037. X        PANEL_CHOOSE_NONE, TRUE,
  1038. X        PANEL_CHOICE_STRINGS,
  1039. X            "Log Session",
  1040. X            "Keep Connection Alive",
  1041. X            NULL,
  1042. X        PANEL_VALUE, options,
  1043. X        XV_HELP_DATA, "ftptool:PropertyOptions",
  1044. X        NULL);
  1045. X
  1046. X    options = unique_local_names | unique_remote_names;
  1047. X    tool_property_window.ftptool.unique =
  1048. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHOICE,
  1049. X        PANEL_LABEL_STRING, "Generate unique:",
  1050. X        PANEL_CHOOSE_ONE, FALSE,
  1051. X        PANEL_CHOOSE_NONE, TRUE,
  1052. X        PANEL_CHOICE_STRINGS,
  1053. X            "Local Filenames",
  1054. X            "Remote Filenames",
  1055. X            NULL,
  1056. X        PANEL_VALUE, options,
  1057. X        XV_HELP_DATA, "ftptool:PropertyUnique",
  1058. X        NULL);
  1059. X
  1060. X    options = auto_connect | show_status | try_proxy;
  1061. X    tool_property_window.ftptool.automatic =
  1062. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHOICE,
  1063. X        PANEL_LABEL_STRING, "Automatically:",
  1064. X        PANEL_CHOOSE_ONE, FALSE,
  1065. X        PANEL_CHOOSE_NONE, TRUE,
  1066. X        PANEL_CHOICE_STRINGS,
  1067. X            "Connect",
  1068. X            "Show Status",
  1069. X            "Try Sun Proxy FTP",
  1070. X            NULL,
  1071. X        PANEL_VALUE, options,
  1072. X        XV_HELP_DATA, "ftptool:PropertyAuto",
  1073. X        NULL);
  1074. X
  1075. X    tool_property_window.ftptool.openlook = 
  1076. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHECK_BOX,
  1077. X        PANEL_LABEL_STRING, "Window manager:",
  1078. X        PANEL_CHOICE_STRINGS,
  1079. X            "OPEN LOOK",
  1080. X            NULL,
  1081. X        PANEL_VALUE, openlook_mode,
  1082. X        XV_HELP_DATA, "ftptool:PropertyOpenLook",
  1083. X        NULL);
  1084. X
  1085. X    tool_property_window.ftptool.anonftp = 
  1086. X        xv_create(tool_property_window.ftptool.panel, PANEL_TEXT,
  1087. X        PANEL_LABEL_STRING, "Initial password:",
  1088. X        PANEL_VALUE_DISPLAY_LENGTH, 40,
  1089. X        PANEL_VALUE_STORED_LENGTH, MAXPASSWORDLEN,
  1090. X        PANEL_VALUE, anonftp_password,
  1091. X        XV_HELP_DATA, "ftptool:PropertyPassword",
  1092. X        NULL);
  1093. X
  1094. X    tool_property_window.ftptool.ignore_case = 
  1095. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHECK_BOX,
  1096. X        PANEL_LABEL_STRING, "Case sensitivity:",
  1097. X        PANEL_CHOICE_STRINGS,
  1098. X            "Ignore case",
  1099. X            NULL,
  1100. X        PANEL_VALUE, ignore_case,
  1101. X        XV_HELP_DATA, "ftptool:PropertyIgnoreCase",
  1102. X        NULL);
  1103. X
  1104. X    tool_property_window.ftptool.confirm = 
  1105. X        xv_create(tool_property_window.ftptool.panel, PANEL_CHECK_BOX,
  1106. X        PANEL_LABEL_STRING, "Deletions:",
  1107. X        PANEL_CHOICE_STRINGS,
  1108. X            "Confirm",
  1109. X            NULL,
  1110. X        PANEL_VALUE, confirmdeletes,
  1111. X        XV_HELP_DATA, "ftptool:PropertyConfirm",
  1112. X        NULL);
  1113. X
  1114. X    justify_items(tool_property_window.ftptool.panel, FALSE);
  1115. X
  1116. X    tool_property_window.ftptool.apply = 
  1117. X        xv_create(tool_property_window.ftptool.panel, PANEL_BUTTON,
  1118. X        PANEL_LABEL_STRING, "Apply",
  1119. X        PANEL_NOTIFY_PROC, ftptool_props_apply_proc,
  1120. X        XV_HELP_DATA, "ftptool:PropertyApply",
  1121. X        NULL);
  1122. X
  1123. X
  1124. X    window_fit_width(tool_property_window.ftptool.panel);
  1125. X
  1126. X    xv_set(tool_property_window.ftptool.panel, 
  1127. X        PANEL_LAYOUT, PANEL_HORIZONTAL, 
  1128. X        NULL);
  1129. X
  1130. X    butrect = (Rect *)xv_get(tool_property_window.ftptool.apply,XV_RECT);
  1131. X    xv_set(tool_property_window.ftptool.apply,
  1132. X        XV_X, (int)xv_get(tool_property_window.ftptool.panel, XV_WIDTH)/2 
  1133. X            - butrect->r_width,
  1134. X        NULL);
  1135. X
  1136. X    xv_create(tool_property_window.ftptool.panel, PANEL_BUTTON,
  1137. X        PANEL_LABEL_STRING, "Reset",
  1138. X        PANEL_NOTIFY_PROC, ftptool_props_reset_proc,
  1139. X        XV_HELP_DATA, "ftptool:PropertyReset",
  1140. X        NULL);
  1141. X    xv_set(tool_property_window.ftptool.panel, 
  1142. X        PANEL_DEFAULT_ITEM, tool_property_window.ftptool.apply, 
  1143. X        NULL); 
  1144. X
  1145. X    window_fit_height(tool_property_window.ftptool.panel);
  1146. X
  1147. X    /* directory lists panel */
  1148. X
  1149. X    tool_property_window.directory_lists.panel = 
  1150. X        xv_create(tool_property_window.frame, PANEL,
  1151. X        PANEL_LAYOUT, PANEL_VERTICAL,
  1152. X        WIN_BORDER, TRUE,
  1153. X        XV_X, x,
  1154. X        XV_Y, y,
  1155. X        NULL);
  1156. X
  1157. X    tool_property_window.directory_lists.cache = 
  1158. X        xv_create(tool_property_window.directory_lists.panel, PANEL_SLIDER,
  1159. X        PANEL_LABEL_STRING, "Directory Cache Size:",
  1160. X        PANEL_MIN_VALUE, 1,
  1161. X        PANEL_MAX_VALUE, 20,
  1162. X        PANEL_SLIDER_WIDTH, 200,
  1163. X        PANEL_TICKS, 5,
  1164. X        PANEL_VALUE, dircache_size,
  1165. X        PANEL_INACTIVE, dircache_size == 0,
  1166. X        XV_HELP_DATA, "ftptool:PropertyCacheSize",
  1167. X        NULL);
  1168. X
  1169. X    tool_property_window.directory_lists.cache_inf = 
  1170. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHECK_BOX,
  1171. X        PANEL_CHOICE_STRINGS,
  1172. X            "Unlimit Cache Size",
  1173. X            NULL,
  1174. X        PANEL_VALUE, dircache_size == 0,
  1175. X        PANEL_NOTIFY_PROC, props_inf_check_box,
  1176. X        PANEL_ITEM_Y, xv_get(tool_property_window.directory_lists.cache, XV_X)
  1177. X            +xv_get(tool_property_window.directory_lists.cache, XV_HEIGHT),
  1178. X        XV_HELP_DATA, "ftptool:PropertyCacheInf",
  1179. X        NULL);
  1180. X
  1181. X
  1182. X    tool_property_window.directory_lists.remote_sort = 
  1183. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1184. X        PANEL_NEXT_ROW, xv_row(tool_property_window.directory_lists.panel, 1),
  1185. X        PANEL_LABEL_STRING, "Sort remote files by:",
  1186. X        PANEL_CHOOSE_ONE, TRUE,
  1187. X        PANEL_CHOOSE_NONE, FALSE,
  1188. X        PANEL_NOTIFY_PROC, remote_sort_choice_proc,
  1189. X        PANEL_CHOICE_STRINGS,
  1190. X            "Name",
  1191. X            "Date",
  1192. X            "Size",
  1193. X            NULL,
  1194. X        PANEL_VALUE, remote_sort_mode,
  1195. X        XV_HELP_DATA, "ftptool:PropertySortChoice",
  1196. X        NULL);
  1197. X
  1198. X    tool_property_window.directory_lists.remote_sortdir = 
  1199. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1200. X        PANEL_LABEL_STRING, "Sort order:",
  1201. X        PANEL_CHOOSE_ONE, TRUE,
  1202. X        PANEL_CHOOSE_NONE, FALSE,
  1203. X        PANEL_CHOICE_STRINGS,
  1204. X            "Least Recently Changed",
  1205. X            "Most Recently Changed",
  1206. X            NULL,
  1207. X        PANEL_VALUE, remote_sort_direction,
  1208. X        XV_HELP_DATA, "ftptool:PropertySortDirection",
  1209. X        NULL);
  1210. X
  1211. X    tool_property_window.directory_lists.remote_dotfiles = 
  1212. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1213. X        PANEL_LABEL_STRING, "Hidden files:",
  1214. X        PANEL_CHOOSE_ONE, TRUE,
  1215. X        PANEL_CHOOSE_NONE, FALSE,
  1216. X        PANEL_CHOICE_STRINGS,
  1217. X            "Hide",
  1218. X            "Show",
  1219. X            NULL,
  1220. X        PANEL_VALUE, remote_showdotfiles,
  1221. X        XV_HELP_DATA, "ftptool:PropertyHidden",
  1222. X        NULL);
  1223. X
  1224. X    tool_property_window.directory_lists.remote_group = 
  1225. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHECK_BOX,
  1226. X        PANEL_CHOICE_STRINGS, 
  1227. X            "Group files by type",
  1228. X            NULL,
  1229. X        PANEL_VALUE, group_remote_files,
  1230. X        XV_HELP_DATA, "ftptool:PropertySortGrouping",
  1231. X        NULL);
  1232. X
  1233. X    tool_property_window.directory_lists.local_sort = 
  1234. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1235. X        PANEL_NEXT_ROW, xv_row(tool_property_window.directory_lists.panel, 1),
  1236. X        PANEL_LABEL_STRING, "Sort local files by:",
  1237. X        PANEL_CHOOSE_ONE, TRUE,
  1238. X        PANEL_CHOOSE_NONE, FALSE,
  1239. X        PANEL_NOTIFY_PROC, local_sort_choice_proc,
  1240. X        PANEL_CHOICE_STRINGS,
  1241. X            "Name",
  1242. X            "Date",
  1243. X            "Size",
  1244. X            NULL,
  1245. X        PANEL_VALUE, local_sort_mode,
  1246. X        XV_HELP_DATA, "ftptool:PropertyLocalSortChoice",
  1247. X        NULL);
  1248. X
  1249. X    tool_property_window.directory_lists.local_sortdir = 
  1250. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1251. X        PANEL_LABEL_STRING, "Sort order:",
  1252. X        PANEL_CHOOSE_ONE, TRUE,
  1253. X        PANEL_CHOOSE_NONE, FALSE,
  1254. X        PANEL_CHOICE_STRINGS,
  1255. X            "Least Recently Changed",
  1256. X            "Most Recently Changed",
  1257. X            NULL,
  1258. X        PANEL_VALUE, local_sort_direction,
  1259. X        XV_HELP_DATA, "ftptool:PropertySortDirection",
  1260. X        NULL);
  1261. X
  1262. X    tool_property_window.directory_lists.local_dotfiles = 
  1263. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHOICE,
  1264. X        PANEL_LABEL_STRING, "Hidden files:",
  1265. X        PANEL_CHOOSE_ONE, TRUE,
  1266. X        PANEL_CHOOSE_NONE, FALSE,
  1267. X        PANEL_CHOICE_STRINGS,
  1268. X            "Hide",
  1269. X            "Show",
  1270. X            NULL,
  1271. X        PANEL_VALUE, local_showdotfiles,
  1272. X        XV_HELP_DATA, "ftptool:PropertyHidden",
  1273. X        NULL);
  1274. X
  1275. X    tool_property_window.directory_lists.local_group = 
  1276. X        xv_create(tool_property_window.directory_lists.panel, PANEL_CHECK_BOX,
  1277. X        PANEL_CHOICE_STRINGS,
  1278. X            "Group files by type",
  1279. X            NULL,
  1280. X        PANEL_VALUE, group_local_files,
  1281. X        XV_HELP_DATA, "ftptool:PropertyLocalSortGrouping",
  1282. X        NULL);
  1283. X
  1284. X    justify_items(tool_property_window.directory_lists.panel, FALSE);
  1285. X
  1286. X    tool_property_window.directory_lists.apply = 
  1287. X        xv_create(tool_property_window.directory_lists.panel, PANEL_BUTTON,
  1288. X        PANEL_LABEL_STRING, "Apply",
  1289. X        PANEL_NOTIFY_PROC, directory_lists_props_apply_proc,
  1290. X        XV_HELP_DATA, "ftptool:PropertyApply",
  1291. X        NULL);
  1292. X
  1293. X
  1294. X    window_fit_width(tool_property_window.directory_lists.panel);
  1295. X
  1296. X    xv_set(tool_property_window.directory_lists.panel, 
  1297. X        PANEL_LAYOUT, PANEL_HORIZONTAL, 
  1298. X        NULL);
  1299. X
  1300. X    butrect = (Rect *)xv_get(tool_property_window.directory_lists.apply,
  1301. X        XV_RECT);
  1302. X    xv_set(tool_property_window.directory_lists.apply,
  1303. X        XV_X, (int)xv_get(tool_property_window.directory_lists.panel, 
  1304. X            XV_WIDTH)/2 - butrect->r_width,
  1305. X        NULL);
  1306. X
  1307. X    xv_create(tool_property_window.directory_lists.panel, PANEL_BUTTON,
  1308. X        PANEL_LABEL_STRING, "Reset",
  1309. X        PANEL_NOTIFY_PROC, directory_lists_props_reset_proc,
  1310. X        XV_HELP_DATA, "ftptool:PropertyReset",
  1311. X        NULL);
  1312. X
  1313. X    xv_set(tool_property_window.directory_lists.panel, 
  1314. X        PANEL_DEFAULT_ITEM, tool_property_window.directory_lists.apply, 
  1315. X        NULL); 
  1316. X
  1317. X    window_fit_height(tool_property_window.directory_lists.panel);
  1318. X
  1319. X    /* viewers panel */
  1320. X
  1321. X    tool_property_window.viewers.panel = xv_create(tool_property_window.frame, 
  1322. X        PANEL,
  1323. X        PANEL_LAYOUT, PANEL_VERTICAL,
  1324. X        WIN_BORDER, TRUE,
  1325. X        XV_X, x,
  1326. X        XV_Y, y,
  1327. X        NULL);
  1328. X
  1329. X    tool_property_window.viewers.viewer = 
  1330. X        xv_create(tool_property_window.viewers.panel, PANEL_TEXT,
  1331. X        PANEL_LABEL_STRING, "File viewer:",
  1332. X        PANEL_VALUE_DISPLAY_LENGTH, 40,
  1333. X        PANEL_VALUE_STORED_LENGTH, MAXPATHLEN,
  1334. X        PANEL_VALUE, default_viewer,
  1335. X        XV_HELP_DATA, "ftptool:PropertyViewer",
  1336. X        NULL);
  1337. X
  1338. X    tool_property_window.viewers.archive = 
  1339. X        xv_create(tool_property_window.viewers.panel, PANEL_TEXT,
  1340. X        PANEL_LABEL_STRING, "Archive viewer:",
  1341. X        PANEL_VALUE_DISPLAY_LENGTH, 40,
  1342. X        PANEL_VALUE_STORED_LENGTH, MAXPATHLEN,
  1343. X        PANEL_VALUE, archive_viewer,
  1344. X        XV_HELP_DATA, "ftptool:PropertyArchiveViewer",
  1345. X        NULL);
  1346. X
  1347. X    tool_property_window.viewers.postscript = 
  1348. X        xv_create(tool_property_window.viewers.panel, PANEL_TEXT,
  1349. X        PANEL_LABEL_STRING, "PostScript viewer:",
  1350. X        PANEL_VALUE_DISPLAY_LENGTH, 40,
  1351. X        PANEL_VALUE_STORED_LENGTH, MAXPATHLEN,
  1352. X        PANEL_VALUE, postscript_viewer,
  1353. X        XV_HELP_DATA, "ftptool:PropertyPostScriptViewer",
  1354. X        NULL);
  1355. X
  1356. X    justify_items(tool_property_window.viewers.panel, FALSE);
  1357. X    
  1358. X    tool_property_window.viewers.apply = 
  1359. X        xv_create(tool_property_window.viewers.panel, PANEL_BUTTON,
  1360. X        PANEL_LABEL_STRING, "Apply",
  1361. X        PANEL_NOTIFY_PROC, viewers_props_apply_proc,
  1362. X        XV_HELP_DATA, "ftptool:PropertyApply",
  1363. X        NULL);
  1364. X
  1365. X
  1366. X    window_fit_width(tool_property_window.viewers.panel);
  1367. X
  1368. X    xv_set(tool_property_window.viewers.panel, 
  1369. X        PANEL_LAYOUT, PANEL_HORIZONTAL, 
  1370. X        NULL);
  1371. X
  1372. X    butrect = (Rect *)xv_get(tool_property_window.viewers.apply,XV_RECT);
  1373. X    xv_set(tool_property_window.viewers.apply,
  1374. X        XV_X, (int)xv_get(tool_property_window.viewers.panel, XV_WIDTH)/2 
  1375. X            - butrect->r_width,
  1376. X        NULL);
  1377. X
  1378. X    xv_create(tool_property_window.viewers.panel, PANEL_BUTTON,
  1379. X        PANEL_LABEL_STRING,     "Reset",
  1380. X        PANEL_NOTIFY_PROC, viewers_props_reset_proc,
  1381. X        XV_HELP_DATA, "ftptool:PropertyReset",
  1382. X        NULL);
  1383. X
  1384. X    xv_set(tool_property_window.viewers.panel, 
  1385. X        PANEL_DEFAULT_ITEM, tool_property_window.viewers.apply, 
  1386. X        NULL); 
  1387. X
  1388. X    window_fit_height(tool_property_window.viewers.panel);
  1389. X
  1390. X    /* end panels */
  1391. X    xv_set(tool_property_window.viewers.panel, 
  1392. X        XV_SHOW, FALSE, 
  1393. X        NULL);
  1394. X    xv_set(tool_property_window.directory_lists.panel, 
  1395. X        XV_SHOW, FALSE, 
  1396. X        NULL);
  1397. X    xv_set(tool_property_window.ftptool.panel, 
  1398. X        XV_SHOW, TRUE, 
  1399. X        NULL);
  1400. X
  1401. X    switch_category(0, TRUE);
  1402. X    set_remote_sort_order(remote_sort_mode);
  1403. X    set_local_sort_order(local_sort_mode);
  1404. }
  1405. X
  1406. #ifdef USE_PROTOTYPES
  1407. void create_local_window(void)
  1408. #else
  1409. void create_local_window()
  1410. #endif
  1411. {
  1412. X    Menu local_list_menu;
  1413. X    Rect    rect;
  1414. X    int        width, height, x, y;
  1415. X    Panel_item    message;
  1416. X
  1417. X    if (gethostname(myhostname, MAXHOSTNAMELEN) == -1) {
  1418. X        fprintf(stderr, "What host is this?\n");
  1419. X        strcpy(myhostname, "unknown");
  1420. X    }
  1421. X
  1422. X    sprintf(scratch, "Ftptool: Local Host - %s", myhostname);
  1423. X
  1424. X    local_window.frame = xv_create(base_window.frame, FRAME_CMD,
  1425. #ifdef XVIEW3
  1426. X        FRAME_CMD_PIN_STATE, FRAME_CMD_PIN_IN,
  1427. #else
  1428. X        FRAME_CMD_PUSHPIN_IN, TRUE,
  1429. #endif
  1430. X        XV_LABEL, scratch,
  1431. X        FRAME_SHOW_RESIZE_CORNER, TRUE,
  1432. X        FRAME_SHOW_FOOTER, TRUE,
  1433. X        FRAME_LEFT_FOOTER, NULL,
  1434. X        NULL);
  1435. X
  1436. X    local_window.panel = xv_get(local_window.frame, FRAME_CMD_PANEL);
  1437. X
  1438. X    xv_set(local_window.panel, 
  1439. X        PANEL_LAYOUT, PANEL_VERTICAL, 
  1440. X        NULL);
  1441. X
  1442. X    local_window.directory = xv_create(local_window.panel, PANEL_TEXT,
  1443. X        PANEL_VALUE_DISPLAY_LENGTH, 44,
  1444. X        PANEL_VALUE_STORED_LENGTH, MAXPATHLEN,
  1445. X        PANEL_LABEL_STRING, "Local Directory:",
  1446. X        PANEL_LAYOUT, PANEL_HORIZONTAL,
  1447. X        PANEL_READ_ONLY, FALSE,
  1448. X        PANEL_NOTIFY_LEVEL, PANEL_SPECIFIED,
  1449. X        PANEL_NOTIFY_PROC, local_cd_text,
  1450. X        XV_HELP_DATA, "ftptool:LocalDirectory",
  1451. X        NULL);
  1452. X
  1453. X    xv_set(local_window.panel, 
  1454. X        PANEL_LAYOUT, PANEL_HORIZONTAL,
  1455. X        NULL);
  1456. X
  1457. X    xv_set(local_window.panel, 
  1458. X        PANEL_LAYOUT, PANEL_VERTICAL,
  1459. X        NULL);
  1460. X
  1461. X    message = xv_create(local_window.panel, PANEL_MESSAGE,
  1462. X        PANEL_LABEL_STRING, "Free Space:",
  1463. X        PANEL_LABEL_BOLD, TRUE,
  1464. X        NULL);
  1465. X
  1466. X    justify_items(local_window.panel, FALSE);
  1467. X
  1468. X    local_window.list = xv_create(local_window.panel, PANEL_LIST,
  1469. X        PANEL_LIST_DISPLAY_ROWS, 8,
  1470. X        PANEL_LABEL_STRING, list_label,
  1471. X        PANEL_FONT, bold_list_font,
  1472. X        PANEL_LAYOUT, PANEL_VERTICAL,
  1473. X        PANEL_CHOOSE_ONE, FALSE,
  1474. X        PANEL_CHOOSE_NONE, TRUE,
  1475. X        PANEL_READ_ONLY, TRUE,
  1476. X        PANEL_NOTIFY_PROC, local_list_proc,
  1477. X        XV_HELP_DATA, "ftptool:LocalList",
  1478. X        NULL);
  1479. X
  1480. X    local_list_menu = xv_get(local_window.list, PANEL_ITEM_MENU);
  1481. #ifdef LINT
  1482. X    local_list_menu = local_list_menu;
  1483. #else
  1484. X    xv_set(local_list_menu,
  1485. X        MENU_GEN_PIN_WINDOW, base_window.frame, "Local File List",
  1486. X        MENU_TITLE_ITEM, "Local File List",
  1487. X        MENU_ITEM,
  1488. X            MENU_STRING, "",
  1489. X            MENU_FEEDBACK, FALSE,
  1490. X            NULL,
  1491. X        MENU_ITEM,
  1492. X            MENU_STRING, "CD to Selection",
  1493. X            MENU_NOTIFY_PROC, local_cd_select,
  1494. X            XV_HELP_DATA, "ftptool:LocalMenuCDSelection",
  1495. X            NULL,
  1496. X        MENU_ITEM,
  1497. X            MENU_STRING, "Up One Level",
  1498. X            MENU_NOTIFY_PROC, local_cd_dotdot,
  1499. X            XV_HELP_DATA, "ftptool:LocalMenuCDUp",
  1500. X            NULL,
  1501. X        MENU_ITEM,
  1502. X            MENU_STRING, "Copy to Remote",
  1503. X            MENU_NOTIFY_PROC, put_proc,
  1504. X            XV_HELP_DATA, "ftptool:LocalMenuCopyRemote",
  1505. X            NULL,
  1506. X        MENU_ITEM,
  1507. X            MENU_STRING, "Add to Batch Send List",
  1508. X            MENU_NOTIFY_PROC, add_batch_send_proc,
  1509. X            XV_HELP_DATA, "ftptool:BatchSendAdd",
  1510. X            NULL,
  1511. X        MENU_ITEM,
  1512. X            MENU_STRING, "View File",
  1513. X            MENU_NOTIFY_PROC, local_view,
  1514. X            XV_HELP_DATA, "ftptool:LocalMenuView",
  1515. X            NULL,
  1516. X        MENU_ITEM,
  1517. X            MENU_STRING, "Delete",
  1518. X            MENU_NOTIFY_PROC, local_delete_proc,
  1519. X            XV_HELP_DATA, "ftptool:FileLocalRemote",
  1520. X            NULL,
  1521. X        MENU_ITEM,
  1522. X            MENU_STRING, "Properties...",
  1523. X            MENU_NOTIFY_PROC, local_properties,
  1524. X            XV_HELP_DATA, "ftptool:LocalMenuProperties",
  1525. X            NULL,
  1526. X        NULL);
  1527. #endif
  1528. X
  1529. X    change_local_list_menu();
  1530. X
  1531. X    local_window.space = xv_create(local_window.panel, PANEL_MESSAGE,
  1532. X        PANEL_LABEL_STRING, "",
  1533. X        PANEL_ITEM_X, xv_get(message, XV_X) + xv_get(message, XV_WIDTH)
  1534. X                + xv_col(local_window.panel, 1),
  1535. X        PANEL_ITEM_Y, xv_get(message, XV_Y),
  1536. X        NULL);
  1537. X
  1538. X    local_window.dismiss = xv_create(local_window.panel, PANEL_BUTTON,
  1539. X        PANEL_LABEL_STRING, "Dismiss",
  1540. X        PANEL_NOTIFY_PROC, dismiss_local_window,
  1541. X        XV_SHOW, openlook_mode ? FALSE : TRUE,
  1542. X        XV_HELP_DATA, "ftptool:DismissButton",
  1543. X        NULL);
  1544. X
  1545. X    window_fit(local_window.panel);
  1546. X    window_fit(local_window.frame);
  1547. X
  1548. X    XSync(dpy, False);
  1549. X
  1550. X
  1551. X    frame_get_rect(base_window.frame, &rect);
  1552. X
  1553. X    x = rect.r_left;
  1554. X    y = rect.r_top + rect.r_height;
  1555. X
  1556. X    width = xv_get(local_window.frame, XV_WIDTH);
  1557. X    height = xv_get(local_window.frame, XV_HEIGHT);
  1558. X
  1559. X    rect.r_left = x;
  1560. X    rect.r_top = y;
  1561. X    rect.r_height = height;
  1562. X
  1563. X    frame_set_rect(local_window.frame, &rect);
  1564. X    frame_set_rect(local_window.panel, &rect);
  1565. X
  1566. X    set_geometry(local_window.geometry,local_window.frame,width,height,x,y);
  1567. X
  1568. X    resize_window(local_window.panel, local_window.list, 
  1569. X        local_window.dismiss);
  1570. X
  1571. X    xv_set(local_window.frame, 
  1572. X        WIN_EVENT_PROC, local_event_proc,
  1573. X        NULL);
  1574. }
  1575. SHAR_EOF
  1576. chmod 0644 create_main.c ||
  1577. echo 'restore of create_main.c failed'
  1578. Wc_c="`wc -c < 'create_main.c'`"
  1579. test 27153 -eq "$Wc_c" ||
  1580.     echo 'create_main.c: original size 27153, current size' "$Wc_c"
  1581. rm -f _shar_wnt_.tmp
  1582. fi
  1583. # ============= ftp.c ==============
  1584. if test -f 'ftp.c' -a X"$1" != X"-c"; then
  1585.     echo 'x - skipping ftp.c (File already exists)'
  1586.     rm -f _shar_wnt_.tmp
  1587. else
  1588. > _shar_wnt_.tmp
  1589. echo 'x - extracting ftp.c (Text)'
  1590. sed 's/^X//' << 'SHAR_EOF' > 'ftp.c' &&
  1591. /*
  1592. X * Copyright (c) 1985, 1989 Regents of the University of California.
  1593. X * All rights reserved.
  1594. X *
  1595. X * Redistribution and use in source and binary forms, with or without
  1596. X * modification, are permitted provided that the following conditions
  1597. X * are met:
  1598. X * 1. Redistributions of source code must retain the above copyright
  1599. X *    notice, this list of conditions and the following disclaimer.
  1600. X * 2. Redistributions in binary form must reproduce the above copyright
  1601. X *    notice, this list of conditions and the following disclaimer in the
  1602. X *    documentation and/or other materials provided with the distribution.
  1603. X * 3. All advertising materials mentioning features or use of this software
  1604. X *    must display the following acknowledgement:
  1605. X *    This product includes software developed by the University of
  1606. X *    California, Berkeley and its contributors.
  1607. X * 4. Neither the name of the University nor the names of its contributors
  1608. X *    may be used to endorse or promote products derived from this software
  1609. X *    without specific prior written permission.
  1610. X *
  1611. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1612. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1613. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1614. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1615. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1616. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1617. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1618. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1619. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1620. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1621. X * SUCH DAMAGE.
  1622. X */
  1623. X
  1624. #ifndef lint
  1625. static char sccsid[] = "@(#)ftp.c    5.38 (Berkeley) 4/22/91";
  1626. #endif /* not lint */
  1627. X
  1628. #include "ftptool.h"
  1629. #include "ftp_var.h"
  1630. X
  1631. #ifdef USE_PROTOTYPES
  1632. int ftp_hookup(char *host, int port)
  1633. #else
  1634. int ftp_hookup(host, port)
  1635. char    *host;
  1636. int     port;
  1637. #endif
  1638. {
  1639. X    register struct hostent *hp = 0;
  1640. X    int s, len;
  1641. X    static char hostnamebuf[80];
  1642. X    char    *ftperr;
  1643. X
  1644. X    bzero((char *)&hisctladdr, sizeof (hisctladdr));
  1645. X    hisctladdr.sin_addr.s_addr = inet_addr(host);
  1646. X    if (hisctladdr.sin_addr.s_addr != -1) {
  1647. X        hisctladdr.sin_family = AF_INET;
  1648. X        (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf));
  1649. X    } else {
  1650. X        hp = gethostbyname(host);
  1651. X        if (hp == NULL) {
  1652. X            if (try_proxy)
  1653. X                footer_message("%s unknown. Trying proxy.", host, (char *)NULL);
  1654. X            else
  1655. X                footer_message("%s: unknown host", host, (char *)NULL);
  1656. X            code = -1;
  1657. X            return(1);
  1658. X        }
  1659. X        hisctladdr.sin_family = hp->h_addrtype;
  1660. X        bcopy(hp->h_addr_list[0],
  1661. X            (caddr_t)&hisctladdr.sin_addr, hp->h_length);
  1662. X        (void) strncpy(hostnamebuf, hp->h_name, sizeof(hostnamebuf));
  1663. X    }
  1664. X    s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
  1665. X    if (s < 0) {
  1666. X        perror("ftptool: socket");
  1667. X        code = -1;
  1668. X        return (0);
  1669. X    }
  1670. X    hisctladdr.sin_port = port;
  1671. X    while (connect(s, (struct sockaddr *)&hisctladdr, sizeof (hisctladdr)) < 0) {
  1672. X        if (hp && hp->h_addr_list[1]) {
  1673. X            extern char *inet_ntoa();
  1674. X
  1675. X            sprintf(scratch, "connect to address %s: %s",
  1676. X                inet_ntoa(hisctladdr.sin_addr), strerror(errno));
  1677. X            log_message(scratch);
  1678. X            hp->h_addr_list++;
  1679. X            bcopy(hp->h_addr_list[0],
  1680. X                 (caddr_t)&hisctladdr.sin_addr, hp->h_length);
  1681. X            sprintf(scratch, "Trying %s...", inet_ntoa(hisctladdr.sin_addr));
  1682. X            log_message(scratch);
  1683. X            footer_message(scratch, (char *)NULL);
  1684. X            (void) close(s);
  1685. X            s = socket(hisctladdr.sin_family, SOCK_STREAM, 0);
  1686. X            if (s < 0) {
  1687. X                perror("ftptool: socket");
  1688. X                code = -1;
  1689. X                return (0);
  1690. X            }
  1691. X            continue;
  1692. X        }
  1693. X        code = -1;
  1694. X        if (errno == ENETUNREACH) {
  1695. X            if (try_proxy)
  1696. X                footer_message("%s unreachable. Trying proxy.", host, (char *)NULL);
  1697. X            (void)close(s);
  1698. X            return 1;
  1699. X        }
  1700. X        sprintf(scratch, "connect: %s: %s", host, strerror(errno));
  1701. X        footer_message(scratch, (char *)NULL);
  1702. X        goto bad;
  1703. X    }
  1704. X    len = sizeof (myctladdr);
  1705. X    if (getsockname(s, (struct sockaddr *)&myctladdr, &len) < 0) {
  1706. X        perror("ftptool: getsockname");
  1707. X        code = -1;
  1708. X        goto bad;
  1709. X    }
  1710. #if 1
  1711. X    hp = gethostbyname(myhostname);
  1712. X    myctladdr.sin_family = hp->h_addrtype;
  1713. X    bcopy(hp->h_addr_list[0], (caddr_t)&myctladdr.sin_addr, hp->h_length);
  1714. #endif
  1715. X    responsefp = fdopen(s, "r");
  1716. X    commandfp = fdopen(s, "w");
  1717. X    if (responsefp == NULL || commandfp == NULL) {
  1718. X        fprintf(stderr, "ftptool: fdopen failed.\n");
  1719. X        close_files();
  1720. X        code = -1;
  1721. X        goto bad;
  1722. X    }
  1723. X    if (verbose) {
  1724. X        sprintf(scratch, "Connected to %s.\n", hostnamebuf);
  1725. X        log_message(scratch);
  1726. X    }
  1727. X    if (getreply(0) > 2) {     /* read startup message from server */
  1728. X        close_files();
  1729. X        code = -1;
  1730. X        ftperr = ftp_error(' ', "Service not available.");
  1731. X        footer_message(ftperr, (char *)NULL);
  1732. X        goto bad;
  1733. X    }
  1734. X
  1735. X    /* could get
  1736. X     Connected to sun-barr.ebay.sun.com.
  1737. X     The Internet FTP relay is down for system maintenance.
  1738. X     Please try again later this weekend.
  1739. X     Sorry for any inconvenience.
  1740. X     Network Operations
  1741. X     421 Service not available, remote server has closed connection
  1742. X     */
  1743. X    if (!strncmp(response_line, "The Internet", 12)) {
  1744. X        footer_message("The proxy FTP relay is down. Try again later.",
  1745. X            (char *)NULL);
  1746. X        close_files();
  1747. X        code = -1;
  1748. X        goto bad;
  1749. X    }
  1750. #ifdef SO_OOBINLINE
  1751. X    {
  1752. X    int on = 1;
  1753. X
  1754. X    if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&on, sizeof(on))
  1755. X        < 0 && debug) {
  1756. X            perror("ftptool: setsockopt");
  1757. X        }
  1758. X    }
  1759. #endif /* SO_OOBINLINE */
  1760. X
  1761. X    return 2;
  1762. bad:
  1763. X    (void) close(s);
  1764. X    return 0;
  1765. }
  1766. X
  1767. #ifdef USE_PROTOTYPES
  1768. int ftp_login(char *user, char *pass)
  1769. #else
  1770. int ftp_login(user, pass)
  1771. char    *user;
  1772. char    *pass;
  1773. #endif
  1774. {
  1775. X    int n;
  1776. X    char    *ftperr;
  1777. X
  1778. X    n = command("USER %s", user);
  1779. X    /* We may have just consumed some startup messages from a server */
  1780. X    /* that spews them at connection, but we only grabbed the sun-barr one */
  1781. X    if (code == 220) {
  1782. X        cpend = 1;
  1783. X        n = getreply(0);
  1784. X    } else if (code == 0) {
  1785. X        /* for nic.ddn.mil */
  1786. X        while (code == 0 || code == 220) {
  1787. X            cpend = 1;
  1788. X            n = getreply(0);
  1789. X        }
  1790. X    }
  1791. X    if (code == 500) {
  1792. X        /* sun-barr.ebay doesn't recognize host */
  1793. X        /* 500 yavin: unknown host */
  1794. X        /* 500 connect: connection timed out */
  1795. X        ftperr = ftp_error(' ', "Connect failed.");
  1796. X        footer_message(ftperr, (char *)NULL);
  1797. X        quit_ftp();
  1798. X    } else if (code == 530) {
  1799. X        /* XXX login unknown */
  1800. X        /* login failed */
  1801. X        ftperr = ftp_error(' ', "Connect failed. Login unknown.");
  1802. X        footer_message(ftperr, (char *)NULL);
  1803. X        quit_ftp();
  1804. X    } else if (code == 421) {
  1805. X        footer_message("Service not available.", (char *)NULL);
  1806. X        quit_ftp();
  1807. X    } 
  1808. X
  1809. X    /* Contact line is in the Sorry line */
  1810. X    /* 421 Service not available  (for Iftp ) */
  1811. X    if (!strncmp(response_line, "Sorry", 5)) {
  1812. X        ftperr = "Connect failed. This host is directly reachable.";
  1813. X        footer_message(ftperr, (char *)NULL);
  1814. X        quit_ftp();
  1815. X        return 0;
  1816. X    }
  1817. X    if (n == CONTINUE) {
  1818. X        code = 0;
  1819. X        n = command("PASS %s", pass);
  1820. X        if (n == ERROR || code == 421) {
  1821. X            if (code == 421)
  1822. X                ftperr = &response_line[4];
  1823. X            else
  1824. X                ftperr = ftp_error(' ', "Connect failed.");
  1825. X            footer_message(ftperr, (char *)NULL);
  1826. X            quit_ftp();
  1827. X            return 0;
  1828. X        }
  1829. X    }
  1830. X    if (n != COMPLETE) {
  1831. X        return (0);
  1832. X    }
  1833. X    return (1);
  1834. }
  1835. X
  1836. #ifdef USE_PROTOTYPES
  1837. int command(char *fmt, ...)
  1838. #else
  1839. /*VARARGS*/
  1840. int command(va_alist)
  1841. va_dcl
  1842. #endif
  1843. {
  1844. #ifndef USE_PROTOTYPES
  1845. X    char *fmt;
  1846. #endif
  1847. X    va_list ap;
  1848. X    int r;
  1849. X
  1850. X    notify_do_dispatch();
  1851. X    abrtflag = 0;
  1852. X    if (commandfp == NULL) {
  1853. X        /*
  1854. X        perror ("No control connection for command");
  1855. X         */
  1856. X        code = 421;
  1857. X        return (0);
  1858. X    }
  1859. #ifdef USE_PROTOTYPES
  1860. X    va_start(ap, format);
  1861. #else
  1862. X    va_start(ap);
  1863. X    fmt = (char *)va_arg(ap, char *);
  1864. #endif
  1865. X    vfprintf(commandfp, fmt, ap);
  1866. X    va_end(ap);
  1867. X    fprintf(commandfp, "\r\n");
  1868. X    (void) fflush(commandfp);
  1869. X    cpend = 1;
  1870. X    notify_do_dispatch();
  1871. X    r = getreply(!strcmp(fmt, "QUIT"));
  1872. X    return(r);
  1873. }
  1874. X
  1875. #ifdef USE_PROTOTYPES
  1876. int command_dataconn(FILE **a_file, char *lmode, char *fmt, ...)
  1877. #else
  1878. /*VARARGS2*/
  1879. int command_dataconn(a_file, lmode, va_alist)
  1880. FILE    **a_file;
  1881. char    *lmode;
  1882. va_dcl
  1883. #endif
  1884. {
  1885. #ifndef USE_PROTOTYPES
  1886. X    char *fmt;
  1887. #endif
  1888. X    va_list ap;
  1889. X    int r;
  1890. X
  1891. X    notify_do_dispatch();
  1892. X    abrtflag = 0;
  1893. X    if (commandfp == NULL) {
  1894. X        /*
  1895. X        perror ("No control connection for command");
  1896. X        */
  1897. X        code = 421;
  1898. X        return 0;
  1899. X    }
  1900. #ifdef USE_PROTOTYPES
  1901. X    va_start(ap, format);
  1902. #else
  1903. X    va_start(ap);
  1904. X    fmt = (char *)va_arg(ap, char *);
  1905. #endif
  1906. X    vfprintf(commandfp, fmt, ap);
  1907. X    va_end(ap);
  1908. X    fprintf(commandfp, "\r\n");
  1909. X    (void) fflush(commandfp);
  1910. #ifdef SYSV386
  1911. X    *a_file = dataconn(lmode);
  1912. #endif
  1913. X    cpend = 1;
  1914. X    notify_do_dispatch();
  1915. X    r = getreply(!strcmp(fmt, "QUIT"));
  1916. #ifndef SYSV386
  1917. X    if (r == PRELIM)
  1918. X        *a_file = dataconn(lmode);
  1919. #endif
  1920. X    return r;
  1921. }
  1922. X
  1923. #include <ctype.h>
  1924. X
  1925. #ifdef USE_PROTOTYPES
  1926. int getreply(int expecteof)
  1927. #else
  1928. int getreply(expecteof)
  1929. int expecteof;
  1930. #endif
  1931. {
  1932. X    register int c, n;
  1933. X    register int dig;
  1934. X    register char *cp;
  1935. X    int originalcode = 0, continuation = 0;
  1936. X    int pflag = 0;
  1937. X
  1938. X    for (;;) {
  1939. X        dig = n = code = 0;
  1940. X        cp = response_line;
  1941. X        notify_do_dispatch();
  1942. X        while ((c = getc(responsefp)) != '\n') {
  1943. X            if (c == IAC) {     /* handle telnet commands */
  1944. X                switch (c = getc(responsefp)) {
  1945. X                case WILL:
  1946. X                case WONT:
  1947. X                    c = getc(responsefp);
  1948. X                    fprintf(commandfp, "%c%c%c", IAC, DONT, c);
  1949. X                    (void) fflush(commandfp);
  1950. X                    break;
  1951. X                case DO:
  1952. X                case DONT:
  1953. X                    c = getc(responsefp);
  1954. X                    fprintf(commandfp, "%c%c%c", IAC, WONT, c);
  1955. X                    (void) fflush(commandfp);
  1956. X                    break;
  1957. X                default:
  1958. X                    break;
  1959. X                }
  1960. X                continue;
  1961. X            }
  1962. SHAR_EOF
  1963. true || echo 'restore of ftp.c failed'
  1964. fi
  1965. echo 'End of  part 8'
  1966. echo 'File ftp.c is continued in part 9'
  1967. echo 9 > _shar_seq_.tmp
  1968. exit 0
  1969. -- 
  1970. Senior Systems Scientist        mail: dcmartin@msi.com
  1971. Molecular Simulations, Inc.        uucp: uunet!dcmartin
  1972. 796 North Pastoria Avenue        at&t: 408/522-9236
  1973. Sunnyvale, California 94086        fax: 408/732-0831
  1974.