1 ! mkskel.tpu 2 ! usage: 3 ! edit/TPU/noDisplay/noSection/Command=mkskel.tpu flex.skl /Output=skel.c 4 ! 5 ! Create a C source file from the flex skeleton data. Copy the file, 6 ! changing backslash (\) to doubled backslash (\\) and quote (") 7 ! to backslash quote (\"). For each line, insert space+space+quote 8 ! at the beginning and quote+comma at the end. Bracket the updated 9 ! text with several lines of prologue and epilogue. 10 ! 11 skelfile := CREATE_BUFFER("file", GET_INFO(COMMAND_LINE, "file_name")); 12 SET(NO_WRITE, skelfile); 13 target := '"' | '\'; !do this once, outside loops 14 POSITION(BEGINNING_OF(skelfile)); !start here 15 rest_of_line := CREATE_RANGE(MARK(NONE), MARK(NONE)); !also outside loops 16 LOOP 17 EXITIF MARK(NONE) = END_OF(skelfile); !are we done yet? 18 COPY_TEXT(' "'); start_pos := MARK(NONE); 19 POSITION(LINE_END); end_pos := MARK(NONE); 20 MODIFY_RANGE(rest_of_line, start_pos, end_pos); 21 LOOP 22 next_match := SEARCH_QUIETLY(target, FORWARD, EXACT, rest_of_line); 23 EXITIF next_match = 0; 24 POSITION(BEGINNING_OF(next_match)); 25 COPY_TEXT('\'); MOVE_HORIZONTAL(1); !past the matched character 26 MODIFY_RANGE(rest_of_line, MARK(NONE), end_pos); 27 ENDLOOP; 28 POSITION(LINE_END); COPY_TEXT('",'); 29 MOVE_VERTICAL(1); POSITION(LINE_BEGIN); !go to next line 30 ENDLOOP; 31 32 POSITION(BEGINNING_OF(skelfile)); !insert five line prologue 33 COPY_TEXT('/* File created from flex.skl via mkskel.tpu */'); SPLIT_LINE; 34 SPLIT_LINE; 35 COPY_TEXT('#include "flexdef.h"'); SPLIT_LINE; 36 SPLIT_LINE; 37 COPY_TEXT('const char *skel[] = {'); SPLIT_LINE; 38 39 POSITION(END_OF(skelfile)); !append two line epilogue 40 COPY_TEXT(' 0'); SPLIT_LINE; 41 COPY_TEXT('};'); !! SPLIT_LINE; 42 43 WRITE_FILE(skelfile, GET_INFO(COMMAND_LINE, "output_file")); 44 QUIT 45 !--<eof>-- 46