home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / xp / bin-to-c.el < prev    next >
Encoding:
Text File  |  1998-04-08  |  2.3 KB  |  66 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-c (name 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.     (insert "static unsigned char " name "[] = {\n \"")
  28.     (while (not (eobp))
  29.       (cond ((or (< (following-char) 32)
  30.          (> (following-char) 126))
  31.          (insert ?\\
  32.              (+ ?0 (lsh (logand (following-char) ?\700) -6))
  33.              (+ ?0 (lsh (logand (following-char) ?\070) -3))
  34.              (+ ?0      (logand (following-char) ?\007)))
  35.          (delete-char 1))
  36.         ((or (= (following-char) ?\")
  37.          (= (following-char) ?\?)
  38.          (= (following-char) ?\\))
  39.          (insert ?\\)
  40.          (forward-char 1))
  41.         (t
  42.          (forward-char 1)))
  43.       (if (> (current-column) 70)
  44.       (insert "\"\n \""))
  45.       )
  46.     (insert "\"\n};\n")
  47.     (save-buffer)
  48.     ))
  49.  
  50. (defun batch-bin-to-c ()
  51.   (defvar command-line-args-left)    ;Avoid 'free variable' warning
  52.   (if (not noninteractive)
  53.       (error "batch-bin-to-c is to be used only with -batch"))
  54.   (let ((name (nth 0 command-line-args-left))
  55.     (in  (and (nth 1 command-line-args-left)
  56.           (expand-file-name (nth 1 command-line-args-left))))
  57.     (out (and (nth 2 command-line-args-left)
  58.           (expand-file-name (nth 2 command-line-args-left))))
  59.     (version-control 'never))
  60.     (or (and name in out)
  61.     (error
  62.      "usage: emacs -batch -f batch-bin-to-c name input-file output-file"))
  63.     (setq command-line-args-left (cdr (cdr command-line-args-left)))
  64.     (let ((auto-mode-alist nil))
  65.       (bin-to-c name in out))))
  66.