home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / textinfo / ng2asc.arj / NG2ASC.C next >
Encoding:
Text File  |  1989-09-28  |  6.0 KB  |  417 lines

  1. /*
  2. The following program will reverse assemble a Nortons Guide
  3. database or .ngo file.
  4.  
  5. After reverse assembling the output will require some
  6. attention as I have not completed the work due to lack of
  7. time and the ouptut from this program sufficed my need.
  8.  
  9. The program was written due to the loss of a large text file
  10. input to a database going astray and, not being a masochist,
  11. I did not want to type the whole thing in again.
  12.  
  13. All I have done is reverse the character translation performed by the NG program, why they do this I do not know.
  14.  
  15. There are one or two problems in the > 128 character set but
  16. I have not the time to work them out.
  17.  
  18. There are some control blocks embedded in the guides that I
  19. have not yet touched though I have a rough idea as to how
  20. they are interpreted.
  21. */
  22.  
  23. #include    <stdio.h>
  24. #include    <dos.h>
  25.  
  26. char    Table[] =
  27. {
  28. 0x1A,    //    0x00
  29. '',    //    0x01
  30. '',    //    0x02
  31. '',    //    0x03
  32. '',    //    0x04
  33. '',    //    0x05
  34. '',    //    0x06
  35. '',    //    0x07
  36. '',    //    0x08
  37. '',    //    0x09
  38. '',    //    0x0A
  39. '',    //    0x0B
  40. '',    //    0x0C
  41. '',    //    0x0D
  42. '',    //    0x0E
  43. '',    //    0x0F
  44. '',    //    0x10
  45. 0x0B,    //    0x11
  46. 0x0C,    //    0x12
  47. '',    //    0x13
  48. '',    //    0x14
  49. '',    //    0x15
  50. '',    //    0x16
  51. 0x0D,    //    0x17
  52. '',    //    0x18
  53. '',    //    0x19
  54. 0x1A,    //    0x1A
  55. '',    //    0x1B
  56. '',    //    0x1C
  57. '',    //    0x1D
  58. '',    //    0x1E
  59. '',    //    0x1F
  60. ':',    //    SPACE
  61. ';',    //    !
  62. '8',    //    "
  63. '9',    //    #
  64. '>',    //    $
  65. '?',    //    %
  66. '<',    //    &
  67. '=',    //    '
  68. '2',    //    (
  69. '3',    //    )
  70. '0',    //    *
  71. '1',    //    +
  72. '6',    //    ,
  73. '7',    //    -
  74. '4',    //    .
  75. '5',    //    /
  76. '*',    //    0
  77. '+',    //    1
  78. '(',    //    2
  79. ')',    //    3
  80. '.',    //    4
  81. '/',    //    5
  82. ',',    //    6
  83. '-',    //    7
  84. '"',    //    8
  85. '#',    //    9
  86. ' ',    //    :
  87. '!',    //    ;
  88. '&',    //    <
  89. '\'',    //    =
  90. '$',    //    >
  91. '%',    //    ?
  92. 'Z',    //    @
  93. 'A',    //    A
  94. 'X',    //    B
  95. 'Y',    //    C
  96. '^',    //    D
  97. 'E',    //    E
  98. 'F',    //    F
  99. 'G',    //    G
  100. 'R',    //    H
  101. 'S',    //    I
  102. 'P',    //    J
  103. 'Q',    //    K
  104. 'V',    //    L
  105. 'W',    //    M
  106. 'T',    //    N
  107. 'U',    //    O
  108. 'J',    //    P
  109. 'K',    //    Q
  110. 'H',    //    R
  111. 'I',    //    S
  112. 'N',    //    T
  113. 'O',    //    U
  114. 'L',    //    V
  115. 'M',    //    W
  116. 'B',    //    X
  117. 'C',    //    Y
  118. 'Z',    //    Z
  119. 'A',    //    [
  120. 'F',    //    \    
  121. 'G',    //    ]
  122. 'D',    //    ^
  123. 'E',    //    _
  124. 'z',    //    `
  125. 'a',    //    a
  126. 'x',    //    b
  127. 'y',    //    c
  128. 'd',    //    d
  129. 'e',    //    e
  130. 'f',    //    f
  131. 'g',    //    g
  132. 'r',    //    h
  133. 's',    //    i
  134. 'p',    //    j
  135. 'q',    //    k
  136. 'v',    //    l
  137. 'w',    //    m
  138. 't',    //    n
  139. 'u',    //    o
  140. 'j',    //    p
  141. 'k',    //    q
  142. 'h',    //    r
  143. 'i',    //    s
  144. 'n',    //    t
  145. 'o',    //    u
  146. 'l',    //    v
  147. 'm',    //    w
  148. 'b',    //    x
  149. 'c',    //    y
  150. 'z',    //    z
  151. 'a',    //    {
  152. 'f',    //    |
  153. 'g',    //    }
  154. 'd',    //    ~
  155. 'e',    //    
  156. 'Ü',    //    128
  157. '¢',    //    129
  158. 'ÿ',    //    130
  159. 'Ö',    //    1
  160. '₧',    //    2
  161. 'ƒ',    //    3
  162. '£',    //    4
  163. '¥',    //    5
  164. 'Æ',    //    6
  165. 'ô',    //    7
  166. 'É',    //    8
  167. 'æ',    //    9
  168. 'û',    //    140
  169. 'ù',    //    1
  170. 'ö',    //    2
  171. 'ò',    //    3
  172. 'è',    //    4
  173. 'ï',    //    5
  174. 'ê',    //    6
  175. 'ë',    //    7
  176. 'Ä',    //    8
  177. 'Å',    //    9
  178. 'î',    //    150
  179. 'ì',    //    1
  180. 'é',    //    2
  181. 'â',    //    3
  182. 'Ç',    //    4
  183. 'ü',    //    5
  184. 'å',    //    6
  185. 'ç',    //    7
  186. 'ä',    //    8
  187. 'ç',    //    9
  188. '║',    //    160
  189. '╗',    //    1
  190. '╕',    //    2
  191. '╣',    //    3
  192. '╛',    //    4
  193. '┐',    //    5
  194. '╝',    //    6
  195. '╜',    //    7
  196. '▓',    //    8
  197. '│',    //    9
  198. '░',    //    170
  199. '▒',    //    1
  200. '╢',    //    2
  201. '╖',    //    3
  202. '┤',    //    4
  203. '╡',    //    5
  204. '¬',    //    6
  205. '½',    //    7
  206. '¿',    //    8
  207. '⌐',    //    9
  208. '«',    //    180
  209. '»',    //    1
  210. '¼',    //    2
  211. '¡',    //    3
  212. 'ó',    //    4
  213. 'ú',    //    5
  214. 'á',    //    6
  215. 'í',    //    7
  216. 'ª',    //    8
  217. 'º',    //    9
  218. 'ñ',    //    190
  219. 'Ñ',    //    1
  220. '┌',    //    2
  221. '█',    //    3
  222. '╪',    //    4
  223. '┘',    //    5
  224. '▐',    //    6
  225. '▀',    //    7
  226. '▄',    //    8
  227. '▌',    //    9
  228. '╥',    //    200
  229. '╙',    //    1
  230. '╨',    //    2
  231. '╤',    //    3
  232. '╓',    //    4
  233. '╫',    //    5
  234. '╘',    //    6
  235. '╒',    //    7
  236. '╩',    //    8
  237. '╦',    //    9
  238. '╚',    //    210
  239. '╔',    //    1
  240. '╬',    //    2
  241. '╧',    //    3
  242. '╠',    //    4
  243. '╫',    //    5
  244. '┬',    //    6
  245. '├',    //    7
  246. '└',    //    8
  247. '┴',    //    9
  248. '╞',    //    220
  249. '╟',    //    1
  250. '─',    //    2
  251. '┼',    //    3
  252. '·',    //    4
  253. '√',    //    5
  254. '°',    //    6
  255. '∙',    //    7
  256. '■',    //    8
  257. '\t',    //    9
  258. 'ⁿ',    //    230
  259. '²',    //    1
  260. '≥',    //    2
  261. '≤',    //    3
  262. '≡',    //    4
  263. '±',    //    5
  264. '÷',    //    6
  265. '≈',    //    7
  266. '⌠',    //    8
  267. '⌡',    //    9
  268. 'Ω',    //    240
  269. 'δ',    //    1
  270. 'Φ',    //    2
  271. 'Θ',    //    3
  272. 'ε',    //    4
  273. '∩',    //    5
  274. '∞',    //    6
  275. 'φ',    //    7
  276. 'Γ',    //    8
  277. 'π',    //    9
  278. 'α',    //    250
  279. 'ß',    //    1
  280. 'µ',    //    2
  281. 'τ',    //    3
  282. 'Σ',    //    4
  283. 'σ'    //    5
  284. };
  285.  
  286.  
  287. char    Output[1024];
  288. char    Path[100];
  289. char    OPath[100];
  290. FILE    *fp;
  291. FILE    *ot;
  292. struct    find_t    DTA;
  293.  
  294. void    strmfe ( char *, char * );
  295. void    NGHeader ( void );
  296.  
  297. void    main ( argc, argv )
  298. int    argc;
  299. char    **argv;
  300. {
  301. register    char    *p;
  302. register    int    c;
  303. int    att;
  304.  
  305.     while ( *++argv )
  306.     {
  307.         verpat ( *argv, Path );    // Builds Path From Spec
  308.  
  309.         verpat ( "X.X", OPath );    // Get Current Path For Output
  310.  
  311.         if ( _dos_findfirst ( *argv, 0xFF, &DTA ) == 0 )
  312.             do
  313.             {
  314.                 sprintf ( Output, "%s%s", Path, DTA.name );
  315.  
  316.                 printf ( "\nFile          : %s\n", Output );
  317.  
  318.                 if ( ( fp = fopen ( Output, "rb" ) ) != NULL )
  319.                 {
  320.                     sprintf ( Output, "%s%s", OPath, DTA.name );
  321.  
  322.                     strmfe ( Output, "TXT" );
  323.  
  324.                     ot = fopen ( Output, "w" );
  325.  
  326.                     p = Output;
  327.  
  328.                     NGHeader ( );
  329.  
  330.                     while ( DTA.size-- > 0L )
  331.                     {
  332.                         c = getc ( fp );
  333.  
  334.                         c = Table[c];    // Convert Character
  335.  
  336.                         if ( c == 0x1A )    /* 1A = CR/LF */
  337.                         {
  338.                             *p = '\0';
  339.  
  340.                             fprintf ( ot, "%s\n", Output );
  341.  
  342.                             p = Output;
  343.  
  344.                             fprintf ( stderr, "%ld \r", DTA.size );
  345.  
  346.                             memset ( Output, '\0', sizeof ( Output ) );
  347.                         }
  348.                         else
  349.                             if ( c == '\t' )
  350.                             {
  351.                                 c = getc ( fp );    // Get Tab Position
  352.  
  353.                                 c = Table[c];    // Convert It
  354.  
  355.                                 DTA.size -= 1L;
  356.  
  357.                                 for ( ; c > 0; c-- )    // Insert Spaces
  358.                                     *p++ = ' ';
  359.                             }
  360.                             else
  361.                                 if ( c >= ' ' )    // Only Print Space & Above
  362.                                     *p++ = c;
  363.                     }
  364.  
  365.                     fprintf ( stderr, "%-20s \r", " " );
  366.                 }
  367.             }
  368.             while ( _dos_findnext ( &DTA ) == 0 );
  369.     }
  370. }
  371.  
  372.  
  373. void    NGHeader ( void )
  374. {
  375. int    c;
  376.  
  377.     fread ( Output, 2, 1, fp );
  378.  
  379.     if ( Output[0] == 'N' && Output[1] == 'G' )
  380.     {
  381.         fread ( &c, 2, 1, fp );
  382.  
  383.         printf ( "I Dont Know   : %d\n", c );
  384.  
  385.         fread ( &c, 2, 1, fp );
  386.  
  387.         printf ( "I Dont Know   : %d\n", c );
  388.  
  389.         fread ( &c, 2, 1, fp );
  390.  
  391.         printf ( "Menu Count    : %d\n", c );
  392.  
  393.         fread ( Output, 40, 1, fp );
  394.  
  395.         printf ( "Database Name : %s\n", Output );
  396.  
  397.         fprintf ( ot, "!name : %s\n", Output );
  398.  
  399.         printf ( "Credits :\n" );
  400.  
  401.         fprintf ( ot, "!credits:\n" );
  402.  
  403.         DTA.size -= 46L;
  404.  
  405.         for ( c = 0; c != 5; c++ )
  406.         {
  407.             fread ( Output, 66, 1, fp );
  408.  
  409.             printf ( "%s\n", Output );
  410.  
  411.             fprintf ( ot, "%s\n", Output );
  412.  
  413.             DTA.size -= 66L;
  414.         }
  415.     }
  416. }
  417.