home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / progs / hotedit.icn < prev    next >
Text File  |  2000-07-29  |  4KB  |  102 lines

  1. ############################################################################
  2. #
  3. #    File:     hotedit.icn
  4. #
  5. #    Subject:  Program to edit a Mosaic hotlist
  6. #
  7. #    Author:   Gregg M. Townsend
  8. #
  9. #    Date:     June 23, 2000
  10. #
  11. ############################################################################
  12. #
  13. #   This file is in the public domain.
  14. #
  15. ############################################################################
  16. #
  17. #  ===> IMPORTANT NOTE:  This program was written for "NCSA Mosaic 2.4"
  18. #  ===> and is incompatible with the current version of Mosaic.
  19. #
  20. #  Hotedit makes it easy to edit the "hotlist" used with NCSA Mosaic,
  21. #  a program for grazing the Wide World Web (WWW).  The Mosaic hotlist
  22. #  is a text file, and it can be edited directly, but this is difficult
  23. #  and error-prone.  Pairs of lines must be kept together, and the long
  24. #  "Uniform Record Locator" (URL) lines make it hard to pick out the
  25. #  title lines, which are of more interest.
  26. #
  27. #  Hotedit works by extracting the titles, bringing up an editor of the
  28. #  user's choice, then processing the results when the editor exits.
  29. #  The user can reorder, retitle, or delete lines; adding new entries
  30. #  is best done within NCSA Mosaic.  It is vital that any editing 
  31. #  preserve the three-digit number at the front of each line; hotedit
  32. #  uses this to reconnect the titles with the corresponding URLs.
  33. #
  34. #  The editor is determined by the environment variable VISUAL (or, if
  35. #  that is missing, EDITOR).  The hotlist file is assumed to be in the
  36. #  usual place, $HOME/.mosaic-hotlist-default.  Because not all editors
  37. #  return a reasonable exit status, the hotlist is *always* rewritten;
  38. #  the previous edition is saved in $HOME/.mosaic-hotlist-backup.
  39. #
  40. #  Hotedit shouldn't be run while NCSA Mosaic is running; when Mosaic
  41. #  exits, it is likely to overwrite the edited hotlist.
  42. #
  43. ############################################################################
  44. #
  45. #  Requires:  Unix, NCSA Mosaic
  46. #
  47. ############################################################################
  48.  
  49. $define TMPFILE "hotlist.tmp"
  50. $define HOTFILE ".mosaic-hotlist-default"
  51. $define HOTOLD ".mosaic-hotlist-backup"
  52. $define HOTNEW ".mosaic-hotlist-revised"
  53. $define HOTFORMAT "ncsa-xmosaic-hotlist-format-1"
  54.  
  55. procedure main()
  56.    local home, f, t, line, n, editor, command, urllist
  57.  
  58.    home := getenv("HOME")    | stop("no $HOME value")
  59.    chdir(home)            | stop("can't chdir to ", home)
  60.  
  61.    f := open(HOTFILE)        | stop("can't open ", HOTFILE)
  62.    line := read(f)        | stop("empty hotlist file")
  63.    line == HOTFORMAT        | stop("unrecognized hotlist format")
  64.    line := read(f)        | stop("truncated hotlist file")
  65.    line == "Default"        | stop("unrecognized hotlist format")
  66.  
  67.    t := open(TMPFILE, "w")    | stop("can't write ", TMPFILE)
  68.  
  69.    urllist := []
  70.    while put(urllist, read(f)) do {
  71.       line := read(f)        | stop("ill-formated hotlist file")
  72.       if *urllist < 1000 then
  73.          n := right(*urllist, 3, "0")
  74.       else
  75.          n := *urllist
  76.       write(t, n, " ", line)
  77.       }
  78.    close(f)
  79.    close(t)
  80.  
  81.    f := open(HOTNEW, "w")    | stop("can't write ", HOTNEW)
  82.  
  83.    editor := getenv("VISUAL") | getenv("EDITOR") | "/bin/vi"
  84.    command := editor || " " || TMPFILE
  85.  
  86.    system(command)
  87.  
  88.    t := open(TMPFILE)        | stop("can't reopen ", TMPFILE)
  89.    write(f, HOTFORMAT)
  90.    write(f, "Default")
  91.    while line := read(t) do line ? {
  92.       if write(f, urllist[tab(many(&digits))]) then
  93.          write(f, move(1) & tab(0))
  94.       else 
  95.          write(&errout, "invalid index: ", line)
  96.       }
  97.  
  98.    remove(HOTOLD)
  99.    (rename(HOTFILE, HOTOLD) & rename(HOTNEW, HOTFILE)) |
  100.       stop("couldn't rename files; new file left in ", HOTNEW)
  101. end
  102.