home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / xp / bin-to-pc.el < prev    next >
Encoding:
Text File  |  1998-04-08  |  1.9 KB  |  56 lines

  1. ;;; -*- Mode: Emacs-Lisp -*-
  2. ;;;
  3. ;;; The contents of this file are subject to the Netscape Public License
  4. ;;; Version 1.0 (the "NPL"); you may not use this file except in
  5. ;;; compliance with the NPL.  You may obtain a copy of the NPL at
  6. ;;; http://www.mozilla.org/NPL/
  7. ;;;
  8. ;;; Software distributed under the NPL is distributed on an "AS IS" basis,
  9. ;;; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10. ;;; for the specific language governing rights and limitations under the
  11. ;;; NPL.
  12. ;;;
  13. ;;; The Initial Developer of this code under the NPL is Netscape
  14. ;;; Communications Corporation.  Portions created by Netscape are
  15. ;;; Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16. ;;; Reserved.
  17. ;;;  
  18.  
  19. (defun bin-to-pc (input output)
  20.   (save-excursion
  21.     (set-buffer (let ((font-lock-mode nil))
  22.           (find-file-noselect output)))
  23.     (fundamental-mode)
  24.     (erase-buffer)
  25.     (insert-file-contents input)
  26.     (goto-char (point-min))
  27.     (let ((count 0))
  28.       (while (not (eobp))
  29.     (let ((c1 (or (char-after (point)) 0))
  30.           (c2 (or (char-after (1+ (point))) 0)))
  31.       (insert (format "0x%02x%02x, " c2 c1))
  32.       (or (eobp) (delete-char 1))
  33.       (or (eobp) (delete-char 1))
  34.       (cond ((> (setq count (1+ count)) 8)
  35.          (setq count 0)
  36.          (insert "\n")))
  37.       )))
  38.     (delete-char -2)
  39.     (insert "\n")
  40.     (save-buffer)
  41.     ))
  42.  
  43. (defun batch-bin-to-pc ()
  44.   (defvar command-line-args-left)    ;Avoid 'free variable' warning
  45.   (if (not noninteractive)
  46.       (error "batch-bin-to-pc is to be used only with -batch"))
  47.   (let ((in  (expand-file-name (nth 0 command-line-args-left)))
  48.     (out (expand-file-name (nth 1 command-line-args-left)))
  49.     (version-control 'never))
  50.     (or (and in out)
  51.     (error
  52.      "usage: emacs -batch -f batch-bin-to-pc input-file output-file"))
  53.     (setq command-line-args-left (cdr (cdr command-line-args-left)))
  54.     (let ((auto-mode-alist nil))
  55.       (bin-to-pc in out))))
  56.