home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / mkdoc.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  6.1 KB  |  252 lines

  1. % mkdoc.sl ---- load this file from JED_ROOT/lib!!!!
  2. %
  3. %  Extract documentation from .sl and .c files
  4. %  For this to work, a strict format must be followed.
  5. %  In .c files, add_intrinsic and add_variable statements are checked. The
  6. %  syntax prototype is:
  7. %
  8. %        MAKE_INTRINSIC("name", function, TYPE, n)%
  9. %        /* This is a function called name which returns TYPE
  10. %           and takes n arguments. */
  11. %
  12. %  Note that it is assummed that comments cannot be nested.
  13. %  For .sl files, the syntax follows:
  14. %
  15. %     %!% This function pops an integer n off the stack and an object s.
  16. %     %!% It returns n copies of s on the stack.
  17. %     define dupn (n, s)
  18. %     {
  19. %        loop (n) { s; } 
  20. %     }
  21. %
  22. %  Here I search for '%!%' in column 1 which make indicate a doc string and 
  23. %  then search for 'define' preceed by only whitespace.  The '%!%' must start in 
  24. %  column 1.
  25. %
  26. %  There is no ambiguity as long as the doc strings are placed BEFORE the 
  27. %  object they describe.
  28.  
  29.  
  30. %!% Extracts doc string from FILE and appends it to BUFFER.
  31. %!% Returns 0 upon failure.
  32. define mkdoc_process_sl_file (file, doc_buf)
  33. {
  34.    variable cbuf, doc_ind = "%!%", chars = "a-zA-Z0-9_$!";
  35.    variable c, ctrlm = 1, name;
  36.    variable has_proto;
  37.    
  38.    !if (read_file(file)) return 0;
  39.    cbuf = whatbuf ();
  40.  
  41.    bob ();
  42.  
  43.    while (bol_fsearch (doc_ind))
  44.      {
  45.     setbuf (doc_buf);
  46.     eob ();
  47.     !if (bolp()) newline ();
  48.     push_spot ();
  49.     setbuf (cbuf);
  50.  
  51.     go_right (3); push_mark ();
  52.     skip_white (); 
  53.     has_proto = looking_at ("Prototype: ");
  54.     while (down(1) and looking_at (doc_ind));
  55.     copy_region (doc_buf);
  56.  
  57.     
  58.     % now look for what this documents
  59.     forever 
  60.       {
  61.          bol (); skip_chars (" \t\n"); c = what_char ();
  62.          if (looking_at ("variable"))
  63.            {
  64.           go_right (strlen("variable"));
  65.           skip_white (); push_mark ();
  66.           skip_chars (chars);
  67.           name = Sprintf ("V%s ", bufsubstr(), 1);
  68.           break;
  69.            }
  70.          
  71.          if (looking_at ("define"))
  72.            {
  73.           go_right (strlen ("define"));
  74.           skip_white ();
  75.           push_mark ();
  76.           skip_chars (chars);
  77.           !if (has_proto) if (ffind (")")) go_right (1);
  78.           name = strcat ("F", bufsubstr ());
  79.           break;
  80.            }
  81.          
  82.  
  83.          !if (down (1)) error (strcat ("Error parsing ", file));
  84.       }
  85.     
  86.     %% now we have the name with the appropriate prefix.  Insert it and
  87.     %% replace newlines with ctrlm
  88.     setbuf (doc_buf);
  89.     pop_spot (); insert (name);
  90.     insert_char (ctrlm);
  91.     while (eol, not(eobp()))
  92.       {
  93.          del (); insert_char (ctrlm);
  94.       }
  95.     
  96.     newline ();
  97.     setbuf (cbuf);
  98.      }
  99.    1;
  100. }
  101.  
  102. . %% same routine for C files.  Looks for MAKE_INTRINSIC and MAKE_VARIABLE
  103. . %% macros.
  104. . (
  105. .   [file doc_buf cbuf] =doc_buf =file
  106. .   [f v name ctrlm c] 1 char =ctrlm
  107. .   
  108. .   file read_file {0 return} !if
  109. .   whatbuf =cbuf
  110. .   
  111. .   bob
  112. .   
  113. .   { 
  114. .     0 =f 0 =v
  115. .     "MAKE_" fsearch
  116. .       {
  117. .         "MAKE_INTRINSIC" looking_at =f
  118. .     "MAKE_VARIABLE" looking_at =v
  119. .       }{break} else
  120. .      
  121. .     POINT bol skip_white
  122. .     POINT - {eol continue} if %%continue if in middle of line
  123. .     %% found
  124. .     
  125. .     doc_buf setbuf 
  126. .     eob
  127. .     bolp {newline} !if
  128. .     cbuf setbuf 
  129. .     %% formats are MAKE_INTRINSIC(".fun", cfun, TYPE, n)
  130. .     %% and         MAKE_VARIABLE(".var", &c_var, TYPE, flag)
  131. .     %%   where the & may not be present for string variables
  132. .     
  133. .     "\"." ffind {"Corrupt file." error} !if
  134. .     2 right pop push_mark 
  135. .     "\"" ffind {"Corrupt file." error} !if
  136. .     bufsubstr " " strcat =name
  137. .     1 right pop
  138. .     
  139. .     %% if it is a function, get the c function info as well
  140. .     f { 
  141. .         "F" name strcat ":" strcat =name      %%Ffun:
  142. .         ",\t " skip_chars
  143. .         push_mark "$_A-Za-z0-9" skip_chars 
  144. .     name bufsubstr strcat ":" strcat      %%Ffun:cfun:
  145. .     ",\t " skip_chars 
  146. .     what_char char strcat ":" strcat      %%Ffun:cfun:T:
  147. .     "," ffind pop  %% assume ok
  148. .     ", \t" skip_chars push_mark "0-9" skip_chars
  149. .     bufsubstr strcat =name  %%Whew!!      %%Ffun:cfun:T:0
  150. .       }{
  151. .     "V" name strcat =name
  152. .       }
  153. .     else
  154. .     
  155. .     doc_buf setbuf name insert push_spot
  156. .     cbuf setbuf
  157. .     
  158. .     %% look for documentation
  159. .     {1 down}
  160. .     {
  161. .         bol skip_white eolp {continue} if
  162. .     "/*" looking_at {break} !if
  163. .     2 right pop
  164. .       what_column =c   
  165. .     push_mark
  166. .     "*/" fsearch pop  %% I assume it compiled 
  167. .     
  168. .     doc_buf copy_region
  169. .     doc_buf setbuf
  170. .     pop_spot 
  171. .       push_spot
  172.  
  173. .        {1 down}
  174. .        { 
  175. .           bol skip_white 
  176. .           "*" looking_at {del skip_white} if
  177. .           what_column bol trim c - {" " insert} loop 
  178. .        }
  179. .        while
  180.    
  181. .     pop_spot 
  182. .     ctrlm insert
  183.     
  184. .     {eol eobp not}
  185. .        {del ctrlm insert} while
  186. .     newline
  187. .     cbuf setbuf
  188. .     break
  189. .     } while
  190. .   } forever 
  191. .   1
  192. . ) mkdoc_process_c_file
  193. . %%% Make documentation for set of files.  Function takes as top argument
  194. . %%% the name of docfile to be produced followed by number n of files
  195. . %%% then followed by the n filenames.
  196. . (
  197. .   [docfile] =docfile
  198. .   [argc argv] =argc
  199. .   [docbuf cbuf]  whatbuf =cbuf
  200. .   [type]
  201. .   
  202. .   docfile setbuf erase_buffer
  203. .   whatbuf =docbuf
  204. .   cbuf setbuf
  205. .   
  206. .   argc 
  207. .     { 
  208. .       =argv
  209. .       argv file_type =type
  210. .       "processing " argv strcat flush
  211. .       type
  212. .         {"c" strcmp not type "C" strcmp not or 
  213. .      type "ci" strcmp not or : 
  214. .        argv docbuf mkdoc_process_c_file 
  215. .          { argv " could not be processed!" strcat error } !if
  216. .     }
  217. .         {"sl" strcmp not type "SL" strcmp not or : 
  218. .        argv docbuf mkdoc_process_sl_file 
  219. .          { argv " could not be processed!" strcat error } !if
  220. .     }
  221. .     {" File type not supported!" strcat error}
  222. .       switch
  223. .       whatbuf docbuf strcmp {whatbuf delbuf} if
  224. .     }
  225. .   loop
  226. .   
  227. .   
  228. .   docbuf setbuf 
  229. .   docfile write_buffer {"Unable to write doc file!" error} !if
  230. .   0 set_buffer_modified_flag docbuf delbuf
  231. .   cbuf setbuf
  232. . ) mkdoc
  233. . _stkdepth =$1
  234. . "site.sl" "buf.sl" "help.sl" "util.sl" "dired.sl" "most.sl" "fortran.sl"
  235. . "misc.sl" "tex.sl"
  236. . "../src/intrin.c" "../src/xterm.c"
  237. . "../../slang/src/slang.c"  "../../slang/src/slstd.c"  
  238. . "../../slang/src/slmath.c"
  239. #ifdef UNIX
  240. . "../../slang/src/slunix.c"
  241. #endif
  242. . _stkdepth $1 -
  243. .  % number of files listed above   
  244. .   
  245. . "jed_funs.hlp" mkdoc
  246. . exit_jed
  247.  
  248.