/* * Humax HMT Tool * af123, 2011 */ #include #include #include #include #include #include #include #include #include #include #include #include #include "lint.h" int debug = 0; const char *version = "2.5"; unsigned long sysopts = 0; int syntax() { fprintf(stderr, "Humax HMT Tool v%s, by af123, 2012.\n", version); fprintf(stderr, "Modified for Foxsat HDR by adrianf36 2012 and MofTot 2018-20.\n\n"); fprintf(stderr, "Syntax: hmt [command] [filename] ...\n"); fprintf(stderr, " Commands:\n" " -p Read HMT and produce parseable output for use by the WebIf\n" " -f Read HMT and return path and filename (without extension) to TS file\n" " +/-new Mark/unmark recording as new.\n" " +/-lock Mark/unmark recording as locked.\n" ); #ifdef HMT_PROTECT fprintf(stderr, " +/-protect Mark/unmark recording as protected.\n" ); #endif fprintf(stderr, " +settitle=\n" " +setsynopsis=\n" " +setfilename=\n" " where = Full Path and filename of related TS file\n" " WITHOUT the .TS extension. e.g. /mnt/hd3/Video/File123\n" " Note. File paths MUST be /mnt/hd3/... and NOT /media/...\n" ); fprintf(stderr, "\n"); return 0; } int main(int argc, char **argv) { int iFileOpenMode = O_RDONLY; enum { CMD_LIST = 0, CMD_NEW, CMD_LOCK, #ifdef HMT_PROTECT CMD_PROTECT, #endif CMD_SETTITLE, CMD_SETSYNOPSIS, CMD_SETFILENAME, CMD_GETPATHANDFILENAME } cmd = CMD_LIST; char *newstr; int i, toggle; if (argc > 1 && !strncmp(argv[1], "-d", 2)) { if (argv[1][2] == '\0') debug = 1; else debug = atoi(argv[1] + 2); printf("Set debug level to %d\n", debug); argc--, argv++; } if (argc > 1 && !strcmp(argv[1], "-p")) { sysopts |= SYSOPT_PARSABLE; argc--, argv++; } if (argc > 1 && !strcmp(argv[1], "-f")) { cmd = CMD_GETPATHANDFILENAME; argc--, argv++; } if (argc < 2) return syntax(); toggle = 0; switch (*argv[1]) { case '+': toggle = 1; /* Fall-through */ case '-': if (debug) printf("argv[1] = \"%s\"\n", argv[1]); if (!strcmp(argv[1] + 1, "new")) { cmd = CMD_NEW; iFileOpenMode = O_RDWR; } else if (!strcmp(argv[1] + 1, "lock")) { cmd = CMD_LOCK; iFileOpenMode = O_RDWR; } #ifdef HMT_PROTECT else if (!strcmp(argv[1] + 1, "protect")) { cmd = CMD_PROTECT; iFileOpenMode = O_RDWR; } #endif else if (!strncmp(argv[1], "+settitle=", 10)) { newstr = argv[1] + 10; if (strlen(newstr) >= HMT_TITLE_LEN) { fprintf(stderr, "New title too long.\n"); return 0; } cmd = CMD_SETTITLE; iFileOpenMode = O_RDWR; } else if (!strncmp(argv[1], "+setsynopsis=", 13)) { newstr = argv[1] + 13; if (strlen(newstr) >= HMT_SYNOPSIS_LEN) { fprintf(stderr, "New synopsis too long.\n"); return 0; } cmd = CMD_SETSYNOPSIS; iFileOpenMode = O_RDWR; } else if (!strncmp(argv[1], "+setfilename=", 13)) { newstr = argv[1] + 13; if (strlen(newstr) >= HMT_FILENAME_LEN) { fprintf(stderr, "New filename too long.\n"); return 0; } cmd = CMD_SETFILENAME; iFileOpenMode = O_RDWR; } else { printf("Unknown command, %s\n", argv[1] + 1); return syntax(); } argc--, argv++; break; } if (debug) { printf("Command %d\n", cmd); printf("File open mode %d\n", iFileOpenMode); } for (i = 1; i < argc; i++) { struct hmt *hmt; if (strlen(argv[i]) > 4 && ( !strcmp(argv[i] + strlen(argv[i]) - 4, ".hmt") || !strcmp(argv[i] + strlen(argv[i]) - 3, ".ts") )) { if (!(hmt = open_file(argv[i], iFileOpenMode))) continue; } else continue; switch (cmd) { case CMD_NEW: cmd_new(hmt, toggle); break; case CMD_LOCK: cmd_lock(hmt, toggle); break; #ifdef HMT_PROTECT case CMD_PROTECT: cmd_protect(hmt, toggle); break; #endif case CMD_SETTITLE: patch_string(hmt, HMT_TITLE, newstr,1); patch_string(hmt, (hmt->epgstart - hmt->bin) + HMT_EPG_TITLE, newstr,0); break; case CMD_SETSYNOPSIS: if (!hmt->epgstart || hmt->binsize < HMT_WITH_EPG_BLOCK_MIN_SIZE) { hmt = extend_file(hmt, HMT_WITH_EPG_BLOCK_MIN_SIZE - hmt->binsize); init_hmt_epg_block(hmt); } patch_string(hmt, (hmt->epgstart - hmt->bin) + HMT_EPG_SYNOPSIS, newstr, 1 /*0*/); break; case CMD_SETFILENAME: patch_string(hmt, HMT_FILENAME, newstr,1); break; case CMD_GETPATHANDFILENAME: cmd_getstring(hmt, HMT_FILENAME); break; default: display_hmt(hmt); } close_file(hmt); } return 0; }