home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / utilsr / scbank23 / src / makehelp < prev    next >
Text File  |  1994-12-21  |  3KB  |  171 lines

  1.  
  2. titlelength=0
  3. headers=0
  4. for dummy in `echo "for(i=1;i<=2;i++)i" | bc`
  5. do
  6. #Find all menu numbers
  7. for menu in `cat $1 | nawk '/^\+[0-9][0-9]/ {printf("%s\n",substr($0,2,2))}'`
  8. do
  9.   cat $1 | nawk -F, '
  10. {
  11.   for (i=1; i<=NF; i++)
  12.   {
  13.     if ($i=="*" thismenu)
  14.       many++
  15.   }
  16. }
  17. { if (substr($0,1,3)=="+" thismenu)
  18.   {
  19.     for (i=1; i<=NF; i++)
  20.     {
  21.       if ((substr($i,1,1)!="+")&&(substr($i,1,1)!="*"))
  22.       {
  23.     outstr=""
  24.     for (j=i; j<=NF; j++)
  25.     {
  26.       if (j!=NF)
  27.       {
  28.         outstr=outstr $j ", "
  29.       }
  30.       else
  31.       {
  32.         outstr=outstr $j
  33.       }
  34.     }
  35.     next
  36.       }
  37.     }
  38.   }
  39. }
  40. END {
  41.   printf("%s,%s,%s\n","#" thismenu,many,outstr)
  42. }' thismenu=$menu
  43.  
  44.  
  45.   cat $1 | nawk -F, '
  46. BEGIN {
  47.   reduce=0
  48. }
  49. {
  50.   if (substr($0,1,1)=="+")
  51.   {
  52.     reduce++
  53.     header=1
  54.     thisheader=$1
  55.   }
  56.   else
  57.   {
  58.     header=0
  59.   }
  60.   for (i=1; i<=NF; i++)
  61.   {
  62.     if ($i=="*" thismenu)
  63.     {
  64.       for (j=i; j<=NF; j++)
  65.       {
  66.     if ((substr($j,1,1)!="+")&&(substr($j,1,1)!="*"))
  67.     {
  68.       outstr=""
  69.       for (k=j; k<=NF; k++)
  70.       {
  71.         if (k!=NF)
  72.         {
  73.           outstr=outstr $k ", "
  74.         }
  75.         else
  76.         {
  77.           outstr=outstr $k
  78.         }
  79.       }
  80.       if (header==0)
  81.       {
  82.         printf("%s,%s\n",NR+titlelength-reduce,outstr)
  83.       }
  84.       else
  85.       {
  86.         printf("%s,%s\n",thisheader,outstr)
  87.       }
  88.       next
  89.     }
  90.       }
  91.     }
  92.   }
  93. }
  94. ' thismenu=$menu headers=$headers titlelength=$titlelength
  95. done > /tmp/menu_headers
  96.  
  97. titlelength=`wc -l /tmp/menu_headers | awk '{print $1}'`
  98. done
  99.  
  100. #Fix submenus
  101. for menu in `cat $1 | nawk '/^\+[0-9][0-9]/ {printf("%s\n",substr($0,2,2))}'`
  102. do
  103.   row=`cat /tmp/menu_headers | nawk -F, '
  104. {
  105.   if ($1=="#" thismenu)
  106.   {
  107.     print NR
  108.   }
  109. }' thismenu=$menu`
  110.   cat /tmp/menu_headers | nawk -F, '
  111. {
  112.   if ($1=="#" thismenu)
  113.   {
  114.     printf("%s\n",substr($0,5,length($0)-4))
  115.   }
  116.   else if ($1=="+" thismenu)
  117.   {
  118.     printf("%s,%s\n",where,substr($0,5,length($0)-4))
  119.   }
  120.   else
  121.   {
  122.     print $0
  123.   }
  124. }' thismenu=$menu where=$row > /tmp/menu_headers1
  125.   cp /tmp/menu_headers1 /tmp/menu_headers
  126. done
  127. #lose line with titiles
  128. cat $1 | grep -v '^\+' > /tmp/titleless
  129. cat /tmp/titleless | nawk 'BEGIN {
  130.   i=0
  131.   first=0
  132. }
  133.  
  134. /^\*/ {
  135.   if (first!=0)
  136.   {
  137.     doit()
  138.     i=0
  139.   }
  140.   title=$0
  141.   first=1
  142. }
  143.  
  144. !/^\*/{
  145.   if (first!=0)
  146.   {
  147.     aline[i]=$0
  148.     i++
  149.   }
  150. }
  151.  
  152. END {
  153.   doit()
  154. }
  155.  
  156. function doit()
  157. {
  158.   last=1
  159.   do
  160.   {
  161.     pos=index(substr(title,last,length(title)-last),",")
  162.     last=last+pos
  163.   } while (substr(title,last,1)=="*")
  164.   printf("%d,%s\n",i,substr(title,last,length(title)-last+1))
  165.   for (k=0; k<i; k++)
  166.   {
  167.     printf("-1,%s\n",aline[k])
  168.   }
  169. }' > /tmp/menutext
  170. cat /tmp/menu_headers /tmp/menutext
  171.