Thread: [subproc-cvs] subproc subproc,1.21,1.22
Status: Beta
Brought to you by:
cstroie
From: Costin S. <cs...@us...> - 2007-02-09 23:03:55
|
Update of /cvsroot/subproc/subproc In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv23771 Modified Files: subproc Log Message: New way of handling the processes. Added the help message. Index: subproc =================================================================== RCS file: /cvsroot/subproc/subproc/subproc,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- subproc 9 Feb 2007 22:08:29 -0000 1.21 +++ subproc 9 Feb 2007 23:03:49 -0000 1.22 @@ -37,7 +37,8 @@ delete osub # The output subtitles data delete subtitles # The subtitles array - delete proc # The processes chain + delete proc # The processes chain + proc_count = 0 # Number of processes # Program meta-data meta["name"] = "subproc" @@ -68,7 +69,7 @@ if (!isub["file"]) error(2, _"Please specify the input filename.") else - debug(_"Input file: " isub["file"]) + debug(sprintf(_"Input file: %s.", isub["file"])) # Detect and read the input file @@ -79,14 +80,14 @@ else if (isub["format"] == "subviewer") read_subviewer(isub["file"]) else - error(3, _"Detected but unsupported input format: " isub["format"]) + error(3, sprintf(_"Detected but unsupported input format: %s.", isub["format"])) } else error(4, _"Unknown input format.") # Show a message about input fps if (isub["fps"]) - debug(_"Input FPS: " isub["fps"]) + debug(sprintf(_"Input FPS: %s.", isub["fps"])) # Make sure the format remains the same or, at least, @@ -111,7 +112,7 @@ # If not specified, use the DOS eol type, for compatibility reasons if (!osub["eol"]) osub["eol"] = "dos" - debug(_"End of line format: " osub["eol"]) + debug(sprintf(_"End of line format: %s.", osub["eol"])) # Use a default filename, based on the input filename, if none specified # TODO output to STDOUT too @@ -131,7 +132,7 @@ } # If any processing is to be applied, run it - if (proc_count) + if (proc_count > 0) process() # Now convert from fps to time or vice-versa, if needed @@ -155,7 +156,7 @@ else if (osub["format"] == "subviewer") write_subviewer(osub["file"], isub["total"], eol[osub["eol"]]) else - error(8, _"Unsupported output format: " osub["format"]) + error(8, sprintf(_"Unsupported output format: %s.", osub["format"])) } function debug(message) @@ -176,7 +177,7 @@ function prog_ver() { # Return the program name and version - return sprintf(_"%s v%s\n", meta["name"], meta["version"]) + return sprintf(_"%s v%s", meta["name"], meta["version"]) } function parse_commandline( i, f) @@ -186,7 +187,7 @@ # Error if the input filename has already been set # TODO Use multiple input files and concatenate them in one big output file if (isub["file"]) - error(1, _"Unexpected option after the input file name: " ARGV[i]) + error(1, sprintf(_"Unexpected option after the input file name: %s.", ARGV[i])) # Start parsing the ARGV array # TODO Enable long format options (GNU format) @@ -203,10 +204,7 @@ osub["format"] = ARGV[i] if (osub["format"] == "help") { - # List the supported output formats - printf(_"Available output formats:\n") > "/dev/stderr" - for (f in sub_description) - printf(" %-10s: %s\n", f, sub_description[f]) > "/dev/stderr" + help_output_formats() exit 0 } else if (osub["format"] in sub_units) @@ -234,10 +232,7 @@ osub["eol"] = ARGV[i] if (osub["eol"] == "help") { - # List the supported eol formats - print _"Available End-of-line formats:" > "/dev/stderr" - for (f in eol) - printf(" %-5s\n", f) > "/dev/stderr" + help_eol() exit 0 } else if (!osub["eol"] in eol) @@ -251,25 +246,101 @@ else if (ARGV[i] == "-V") { # Print the version and exit - printf(prog_ver()) > "/dev/stderr" + print(prog_ver()) > "/dev/stderr" exit 0 } - else if (ARGV[i] == "-p") + else if (ARGV[i] == "-m") { - # The processing chain + # Process: move + proc_count++ i++ - proc_count = split(ARGV[i], proc, /,/) + proc[proc_count, "action"] = "move" + proc[proc_count, "param"] = ARGV[i] + } + else if (ARGV[i] == "-s") + { + # Process: scale + proc_count++ + i++ + proc[proc_count, "action"] = "scale" + proc[proc_count, "param"] = ARGV[i] + } + else if (ARGV[i] == "-d") + { + # Process: delete + proc_count++ + i++ + proc[proc_count, "action"] = "delete" + proc[proc_count, "param"] = ARGV[i] + } + else if (ARGV[i] == "-i") + { + # Process: insert + proc_count++ + i++ + proc[proc_count, "action"] = "insert" + proc[proc_count, "param"] = ARGV[i] + } + else if (ARGV[i] == "-h") + { + # Help + help() + exit 0 } else if (ARGV[i] ~ /^-./) { # Unrecognized option - error(10, _"Unrecognized option: " ARGV[i]) + error(10, sprintf(_"Unrecognized option: %s", ARGV[i])) } else isub["file"] = ARGV[i] } } +function help() +{ + # Show program usage + + print prog_ver() > "/dev/stderr" + print > "/dev/stderr" + printf(_"Usage: %s [options] filename", meta["name"]) > "/dev/stderr" + print > "/dev/stderr" + print _"Options:" > "/dev/stderr" + printf("%4s %s\n", "-o", _"Output file name") > "/dev/stderr" + printf("%4s %s\n", "-F", _"Output file format") > "/dev/stderr" + printf("%4s %s\n", "-f", _"Output file FPS") > "/dev/stderr" + printf("%4s %s\n", "-l", _"Output file End-Of-Line format") > "/dev/stderr" + printf("%4s m %s\n", "-m", _"Process: move with 'm'") > "/dev/stderr" + printf("%4s f %s\n", "-s", _"Process: scale by 'f'") > "/dev/stderr" + printf("%4s s:l %s\n", "-d", _"Process: delete 'l' from 's'") > "/dev/stderr" + printf("%4s s:l %s\n", "-i", _"Process: insert 'l' from 's'") > "/dev/stderr" + printf("%4s %s\n", "-V", _"Show detailed information") > "/dev/stderr" + printf("%4s %s\n", "-V", _"Show program name and version") > "/dev/stderr" + printf("%4s %s\n", "-h", _"Show this quick help") > "/dev/stderr" + print > "/dev/stderr" + help_output_formats() > "/dev/stderr" + print > "/dev/stderr" + help_eol() > "/dev/stderr" + print > "/dev/stderr" + print _"Filename: any supported input subtitle file." > "/dev/stderr" +} + +function help_output_formats( f) +{ + # Show the supported output formats + printf(_"Available output formats:\n") > "/dev/stderr" + for (f in sub_description) + printf(" %-10s: %s\n", f, sub_description[f]) > "/dev/stderr" +} + +function help_eol( f) +{ + # Show the supported eol formats + print _"Available End-of-line formats:" > "/dev/stderr" + for (f in eol) + printf(" %s\n", f) > "/dev/stderr" +} + function register_sub_formats() { # Register the supported subtitle formats @@ -343,7 +414,7 @@ j++ } isub["total"] = j - 1 - debug(_"Read subtitles: " isub["total"]) + debug(sprintf(_"Read subtitles: %s.", isub["total"])) } function write_microdvd(file, total, eol, j) @@ -366,7 +437,7 @@ # Then close the file close(file) - debug(_"Written subtitles: " isub["total"]) + debug(sprintf(_"Written subtitles: %s.", isub["total"])) } function read_subviewer(file, j, line) @@ -395,7 +466,7 @@ j++ } isub["total"] = j - 1 - debug(_"Read subtitles: " isub["total"]) + debug(sprintf(_"Read subtitles: %s.", isub["total"])) } function write_subviewer(file, total, eol, j, k) @@ -428,7 +499,7 @@ # Then close the file close(file) - debug(_"Written subtitles: " isub["total"]) + debug(sprintf(_"Written subtitles: %s.", isub["total"])) } function time_to_subviewer(t, m, s) @@ -445,20 +516,22 @@ { for (j = 1; j <= proc_count; j++) { - f = split(proc[j], p, /=/) - if (p[1] == "m" || p[1] == "move") proc_move(p[2]) - else if (p[1] == "s" || p[1] == "scale") proc_scale(p[2]) - else if (p[1] == "d" || p[1] == "delete") proc_delete(p[2]) - else if (p[1] == "i" || p[1] == "insert") proc_insert(p[2]) - else error(11, _"Unknown process.") + if (proc[j, "action"] == "m" || proc[j, "action"] == "move") + proc_move(proc[j, "param"]) + else if (proc[j, "action"] == "s" || proc[j, "action"] == "scale") + proc_scale(proc[j, "param"]) + else if (proc[j, "action"] == "d" || proc[j, "action"] == "delete") + proc_delete(proc[j, "param"]) + else if (proc[j, "action"] == "i" || proc[j, "action"] == "insert") + proc_insert(proc[j, "param"]) + else error(11, sprintf(_"Unknown process: %s.", proc[j, "action"])) } - delete p } function proc_move(t, j) { # TODO t can be specified in frames, secs, mins, hours, etc - debug(_"Process: move by " t) + debug(sprintf(_"Process: move by %s.", t)) for (j = 1; j <= isub["total"]; j++) { subtitles["begin", j] = subtitles["begin", j] + t @@ -476,7 +549,7 @@ } else r = x - debug(_"Process: scale by " x) + debug(sprintf(_"Process: scale by %s.", x)) for (j = 1; j <= isub["total"]; j++) { subtitles["begin", j] = subtitles["begin", j] * r @@ -495,7 +568,7 @@ else s = x - debug(sprintf(_"Process: delete %s starting from %s", l, s)) + debug(sprintf(_"Process: delete %s starting from %s.", l, s)) d = 0 for (j = 1; j <= isub["total"]; j++) { @@ -522,7 +595,7 @@ l = strtonum(substr(x, RSTART+RLENGTH)) } - debug(sprintf(_"Process: insert %s starting from %s", l, s)) + debug(sprintf(_"Process: insert %s starting from %s.", l, s)) for (j = 1; j <= isub["total"]; j++) { if (strtonum(subtitles["begin", j]) > s) |