int main(int argc, char *argv[]) { printf("Dynamic linking test\n"); if (argc > 1) { if (argc > 2) { print_syntax(); return 1; } if (str_cmp(argv[1], "-n") == 0) { no_dlfcn = true; } else { print_syntax(); return 1; } } if (!no_dlfcn) { if (test_dlfcn() != 0) return 1; } #ifdef DLTEST_LINKED if (test_lnk() != 0) return 1; #endif printf("All passed.\n"); return 0; }
int main(int argc, char *argv[]) { int rc = inetcfg_init(); if (rc != EOK) { printf("%s: Failed connecting to inetcfg service (%d).\n", NAME, rc); return 1; } rc = dhcp_init(); if (rc != EOK) { printf("%s: Failed connecting to dhcp service (%d).\n", NAME, rc); return 1; } if (argc == 2) { if (!str_cmp(argv[1], "list")) return wifi_list(); } else if (argc > 2) { uint32_t index; rc = str_uint32_t(argv[2], NULL, 10, false, &index); if (rc != EOK) { printf("%s: Invalid argument.\n", NAME); print_syntax(); return EINVAL; } if (!str_cmp(argv[1], "scan")) { bool now = false; if (argc > 3) if (!str_cmp(argv[3], "-n")) now = true; return wifi_scan(index, now); } else if (!str_cmp(argv[1], "connect")) { char *pass = NULL; if (argc > 3) { if (argc > 4) pass = argv[4]; return wifi_connect(index, argv[3], pass); } } else if (!str_cmp(argv[1], "disconnect")) return wifi_disconnect(index); } print_syntax(); return EOK; }
/*************** MAIN PROGRAM ******************************/ int main(int arg_count, char **args) { char startpath[_MAX_PATH], *apu; char *defaultdir = "."; unsigned long disk_size,disk_free, summa; double slack; printf("\nDU/" VERSION_BITS "bit v" VERSION_NO " Copyright (c) Timo Kokkonen, OH6LXV " RELEASE_DATE "\n\n"); strcpy(startpath,"."); if (arg_count>1) { if (!strcmp(args[1],"/?")) { print_syntax(); exit(0); } if (args[arg_count-1][0]=='/') if (sscanf(&args[arg_count-1][1],"%d",&sublevels)!=1) { printf("\nInvalid parameter '%s'.\n",args[arg_count-1]); print_syntax(); exit(1); } } if ((arg_count>=2)&&(args[1][0]!='/')) apu=args[1]; else apu=defaultdir; if (!_fullpath(startpath,apu,_MAX_PATH)) { printf("Cannot convert '%s' to absolute path.\n",apu); exit(1); } if (startpath[strlen(startpath)-1]!='\\') strcat(startpath,"\\"); strcpy(startpath,SplitDir(startpath)); if (!getDiskSize(startpath[0]-64,&disk_size,&disk_free,&cluster_size)) { printf("Cannot read drive %c: \n",startpath[0]); exit(1); } summa=calc_dir(startpath); if (true_sum!=0) slack=(1-(double)summa/true_sum)*100.0; else slack=0; // printf(" %lu %lu %lu \n",disk_size-disk_free,summa,true_sum); printf("\n %lu bytes in %lu file(s), %1.1lf%% slack (%lu bytes).\n", true_sum, file_counter, slack, true_sum-summa); return 0; }
int main(int argc, char *argv[]) { kbd_event_t ev; int rc; if (argc != 3) { print_syntax(); return 1; } rc = conn_open(argv[1], argv[2]); if (rc != EOK) { printf("Error connecting.\n"); return 1; } printf("Connection established.\n"); con = console_init(stdin, stdout); done = false; while (!done) { console_get_kbd_event(con, &ev); if (ev.type == KEY_PRESS) key_handle(&ev); } return 0; }
/* * A simple program to test the System Timer driver ****************************************************************************** */ int main (int argc, char* argv[]) { const char *files[] = {"/dev/CS", "/dev/CLO", "/dev/CHI", "/dev/C0", "/dev/C1", "/dev/C2", "/dev/C3"} ; //const unsigned int file_count = sizeof (files) / sizeof (char*) ; /* */ if (argv[1] == NULL || argv[2] == NULL) { print_syntax () ; exit (1) ; } /* */ int device_number = atoi(argv[1]) ; unsigned int write_value ; sscanf (atoi(argv[2]), "%u", &write_value) ; /* */ for (int repeat = 1 ; repeat <= 1 ; repeat++) write_to_device (files[device_number], &value) ; /* Program exists cleanly */ return 0 ; } //main
/* * A simple program to test the System Timer driver ****************************************************************************** */ int main (int argc, char* argv[]) { /* */ unsigned int read_value ; const char *files[] = {"/dev/CS", "/dev/CLO", "/dev/CHI", "/dev/C0", "/dev/C1", "/dev/C2", "/dev/C3"} ; const unsigned int file_count = sizeof (files) / sizeof (char*) ; /* */ if (argv[1] == NULL) { print_syntax () ; exit (1) ; } if (strcmp(argv[1], "all") == 0) { for (int index = 0 ; index < file_count ; index++) for (int repeat = 1 ; repeat <= 1 ; repeat++) read_from_device (files[index], &read_value) ; } // if /* */ else { int index = atoi(argv[1]) ; read_from_device (files[index], &read_value) ; } /* Program exists cleanly */ return 0 ; } //main
int main(int argc, char **argv) { int opt; int flag_description = 0; const char *address; opt = getopt(argc, argv, "d"); if (opt == 'd') { argc--; argv++; flag_description = 1; } else if (opt != -1) { printf("\nUNKNOWN OPTION: -%c.\n\n", opt); print_syntax(); return 1; } address = (argc == 1) ? NULL : argv[1]; print_addr_info(address, flag_description); printf("\n"); return 0; }
static char *parse_arg(char *arg, int sw) { struct switch_s *s = &switches[sw]; if (s->parse) arg = s->parse(arg, s); else { switch(s->ID) { case SW_HELP: print_syntax(); exit(0); case SW_OLD: use_old_format_f = YES; break; case SW_ERASE: defined_format |= CLEAR_DISK; forced_format |= CLEAR_DISK; break; case SPACE_AVAILABLE: case FILE_SPACE: case FREE_MEMORY: { unsigned long ln; char *next; ln = parse_kilobyte(arg, &next); if (arg == next) syntax("Argument expected for switch /%s", s->sw); arg = next; if (ln > 0x3FFFFFL) syntax(s->ID == FREE_MEMORY ? "Invalid available memory size" : "Invalid available disk size"); *(dword *)s->loc = ln; defined_format |= s->ID; forced_format |= s->ID; break; } case SW_MINSIZE: *(dword *)s->loc = 0; defined_format |= SPACE_AVAILABLE; forced_format |= SPACE_AVAILABLE; break; case SW_MAXSIZE: *(dword *)s->loc = 0; defined_format |= FREE_MEMORY; forced_format |= FREE_MEMORY; break; default: assert(("Bad switch", 0)); } } return arg; }
int main(int argc, char *argv[]) { int rc; char *cmd; char *cat_name; category_id_t cat_id; if (argc <= 1) { rc = list_svcs_by_cat(); if (rc != EOK) return 1; return 0; } cmd = argv[1]; if (str_cmp(cmd, "show-cat") == 0) { if (argc < 3) { printf("Argument missing.\n"); print_syntax(); return 1; } cat_name = argv[2]; rc = loc_category_get_id(cat_name, &cat_id, 0); if (rc != EOK) { printf("Error looking up category '%s'.\n", cat_name); return 1; } rc = show_cat(cat_name, cat_id); if (rc != EOK) return 1; } else { printf("Invalid command '%s'\n", cmd); print_syntax(); return 1; } return 0; }
int main(int argc, char *argv[]) { int rc; rc = corecfg_init(); if (rc != EOK) { printf("Failed contacting corecfg service.\n"); return 1; } if ((argc < 2) || (str_cmp(argv[1], "get") == 0)) return corecfg_print(); else if (str_cmp(argv[1], "enable") == 0) return corecfg_set_enable(true); else if (str_cmp(argv[1], "disable") == 0) return corecfg_set_enable(false); else { printf("%s: Unknown command '%s'.\n", NAME, argv[1]); print_syntax(); return 1; } return 0; }
int main(int argc, char *argv[]) { if (argc < 2) { print_syntax(); exit(2); } // get_udid if ((argc == 2) && (strcmp(argv[1], "get_udid") == 0)) { command.type = GetUDID; } // get_bundle_id else if ((argc == 3) && (strcmp(argv[1], "get_bundle_id") == 0)) { CFStringRef bundle_id = get_bundle_id(argv[2]); if (bundle_id == NULL) { exit(1); } char *_bundle_id = create_cstr_from_cfstring(bundle_id); CFRelease(bundle_id); if (_bundle_id == NULL) { exit(1); } printf("%s\n", _bundle_id); free(_bundle_id); exit(0); } // install_app else if ((argc == 3) && (strcmp(argv[1], "install_app") == 0)) { command.type = InstallApp; command.app_path = argv[2]; } // uninstall_app else if ((argc == 3) && (strcmp(argv[1], "uninstall_app") == 0)) { command.type = UninstallApp; command.bundle_id = argv[2]; } // list_installed_apps else if (strcmp(argv[1], "list_installed_apps") == 0) { command.type = ListInstalledApps; if ((argc == 3) && (strcmp(argv[2], "-p") == 0)) { command.print_paths = 1; } else { command.print_paths = 0; } } // tunnel else if ((argc == 4) && (strcmp(argv[1], "tunnel") == 0)) { command.type = Tunnel; command.src_port = (uint16_t)atoi(argv[2]); command.dst_port = (uint16_t)atoi(argv[3]); } else { fprintf(stderr, "Unknown command\n"); print_syntax(); exit(1); } // wait for device register_device_notification(); return 1; }
int main(int argc, char *argv[]) { time_t start, end; int i = 1; float tmp; char string[64]; struct tm *loctime; int day = 0, oldday = 0; while (argc > i) { if (argv[i][0] == '-') { switch(argv[i][1]) { case 'd': debug = 1; dbg("Enable debugging\n"); break; case 'p': watt_hour = (int)atoi(argv[i+1]); dbg("Preset total used power: %.1fW/h\n", watt_hour); i++; break; case 'r': daily_watt_hour = (int)atoi(argv[i+1]); dbg("Preset daily used power: %.1fW/h\n", daily_watt_hour); i++; break; default: break; } i++; } else { print_syntax(); return -1; } } if (signal(SIGUSR1, sig_handler) == SIG_ERR) { printf("Failed to catch SIGUSR1\n"); return -1; } if (watt_hour == 0) { if (readfloatfromfile(TOTAL, &watt_hour) < 0) printf("No total usage data available\n"); else printf("Preset total data from file: %.1fW/h\n", watt_hour); } one_rotation_wh = 1000 / (float)ROTATIONS_PER_KWH; dbg("One rotation is %f Wh, interval is %d minutes\n", one_rotation_wh, INTERVAL); start = time(NULL); /* Prevent inital daily log to be written */ loctime = localtime(&start); oldday = loctime->tm_mday; while(1) { sleep(1); end = time(NULL); if (difftime(end, start) >= (INTERVAL * 60)) { tmp = interval_power * (60 / INTERVAL); dbg("\nCurrent power (%dmin avg): %.1fW (%f)\n", INTERVAL, tmp, interval_power); dbg("Total used power: %.1fW/h\n", watt_hour); dbg("Daily used power: %.1fW/h\n", daily_watt_hour); /* Create a small html file with total value */ sprintf(string, "<html><h2>Total: %.2fkWh</h2><html>", (watt_hour / 1000)); writestrtofile(TOTAL_HTML, string, "w"); /* Store total value in case of reboots etc */ sprintf(string, "%.1f", watt_hour); writestrtofile(TOTAL, string, "w"); /* Highcharts requires milliseconds sinds epoc */ sprintf(string, "%lu000,%u", time(NULL), (unsigned int)tmp); writestrtofile(DETAIL, string, "a"); interval_power = 0; start = time(NULL); /* Check for day change and store total */ loctime = localtime(&start); day = loctime->tm_mday; if (day != oldday) { dbg("Writing (previous day) daily used power to file"); sprintf(string, "%lu000,%.2f", (start - 3600), (daily_watt_hour / 1000)); writestrtofile(DAILY, string, "a"); daily_watt_hour = 0; } oldday = day; } } return 0; }
int main(int argc, char *memin[]) { int i, rc; int irc; int messages = true, #ifdef IBMPCCHARS box_chars = true; #else box_chars = false; #endif char indefsfnm[MAX_FILENM_SIZE], inloadfnm[MAX_FILENM_SIZE]; /* set global variables */ defssw = false; defsfnm = NULL; initmemsize = dfmemsize; quiet = false; expansion = true; quiet = false; nouserinterrupts = false; loadsw = false; triggered = true; debugging_on = true; diag_messages_on = false; interpreter_running = false; #ifdef HISTORY lasteval = -1; #endif #ifdef DEBUG debug = false; #endif #ifdef PROFILE profile = false; #endif /* Export the command line to the rest of the code */ #ifdef CMDLINE global_argv = memin; global_argc = argc; #endif /* MAJ: the following code is kept in case I decide to go back to having the console and cgi versions the same code. */ if (iscgiversion) { quiet = true; messages = false; box_chars = false; triggered = false; nouserinterrupts = true; } #ifdef UNIXSYS initunixsignals(); #endif /* process command arguments the allowed syntax is: [(+|-)size nnnn] [-defs filenm] [-q] [-m] [-b] [-s] [-d] [workspacename] */ if (iscgiversion) /* This code will allow the cgi version to accept *.nws, *.ndf or *.nfm files on the command line. No other parameters are available. */ { if (argc >= 2) { int offset = (memin[1][0] == '\"') ? -1 : 0; if (STRNCASECMP((strlen(memin[1]) + memin[1] - 4 + offset), ".NDF", 4) == 0) { /* arg is a Nial definition file name */ defssw = true; strcpy(indefsfnm, memin[1]); } else if (STRNCASECMP((strlen(memin[1]) + memin[1] - 4 + offset), ".NWS", 4) == 0) { /* arg is a Nial workspace file name */ loadsw = true; strcpy(inloadfnm, memin[1]); } } } else { i = 1; while (i < argc) { if (strcmp(memin[i], "-size") == 0) { /* set iniital size and allow expansion */ initmemsize = atol(memin[i + 1]); if (initmemsize < minmemsize) initmemsize = minmemsize; expansion = true; i += 2; } else if (strcmp(memin[i], "+size") == 0) { /* set iniital size and disallow expansion */ initmemsize = atol(memin[i + 1]); if (initmemsize < minmemsize) initmemsize = minmemsize; expansion = false; i += 2; } else if (strcmp(memin[i], "-defs") == 0) { if (i < argc) { /* explicit defs file name given */ defssw = true; strcpy(indefsfnm, memin[i + 1]); i += 2; } else { printf("missing definition file name after -defs option\n"); exit(1); } } else if (strcmp(memin[i], "-q") == 0) { /* inhibit all output */ quiet = true; i++; } else if (strcmp(memin[i], "-m") == 0) { /* do not display warning messages */ messages = false; i++; } else if (strcmp(memin[i], "-d") == 0) { /* disable Nial level debugging */ debugging_on = false; i++; } else #ifdef IBMPCCHARS if (strcmp(memin[i], "-b") == 0) { /* do not use the IMB PC box characters */ box_chars = false; i++; } else #endif if (strcmp(memin[i], "-s") == 0) { /* suppress fault triggering */ triggered = false; i++; } else if (strcmp(memin[i], "-h") == 0) { /* display the help syntax and exit */ print_syntax(); exit(1); } else if (memin[i][0] == '-') { /* invalid command line. display and exit. */ printf("invalid command line option: %s", memin[i]); exit(1); } else { /* assume rest of line is a workspace file name */ loadsw = true; strcpy(inloadfnm, memin[i]); i++; } } } /* end of code to process arguments */ /* code to check if we are running a console version under WINDOWS. If we are do not attempt to check for the keyboard, since it slows execution outrageously. This has been switched out for now. Not needed since DOS version no longer supported. */ #ifdef OMITTED checkkeyboard = (getenv("WINDIR") == NULL ? true : false); /* printf("checkkeyboard %d\n", checkkeyboard); */ #endif /* set the session variables */ sessionSettings = NC_CreateSessionSettings(); CheckErr(NC_SetSessionSetting(sessionSettings, NC_WORKSPACE_SIZE, initmemsize)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_EXPANSION, expansion)); if (loadsw) CheckErr(NC_SetSessionSetting(sessionSettings, NC_INITIAL_WORKSPACE, (int) inloadfnm)); if (defssw) CheckErr(NC_SetSessionSetting(sessionSettings, NC_INITIAL_DEFS, (int) indefsfnm)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_QUIET, quiet)); CheckErr(NC_SetSessionSetting(sessionSettings, NC_DEBUGGING_ON, debugging_on)); CheckErr(NC_SetCheckUserBreak(sessionSettings, myCheckUserBreak)); windSettings = NC_CreateWindowSettings(); if (iscgiversion) /* avoid output by having no prompt in CGINIAL */ CheckErr(NC_SetWindowSetting(windSettings, NC_PROMPT, (int) "")); /* The CGINIAL version is given a default 0 screen width setting, so no lines are broken. */ #ifdef WINDOWS_SYS /* The following code is added, so that we can accurately set the window's width. */ { CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : ((csbi.srWindow.Right - csbi.srWindow.Left))))); } #else CheckErr(NC_SetWindowSetting(windSettings, NC_SCREEN_WIDTH, (iscgiversion ? 0 : 79))); #endif CheckErr(NC_SetWindowSetting(windSettings, NC_TRIGGERED, triggered)); CheckErr(NC_SetWindowSetting(windSettings, NC_NOUSERINTERRUPTS, nouserinterrupts)); CheckErr(NC_SetWindowSetting(windSettings, NC_MESSAGES, messages)); CheckErr(NC_SetWindowSetting(windSettings, NC_BOX_CHARS, box_chars)); #ifdef INTERNAL_BUF_MODE theContext = NC_CreateIOContext(); CheckErr(NC_SetIOMode(theContext, NC_INTERNAL_BUFFER_MODE)); NC_SetBufferSize(5000, 1000); #endif #ifdef IO_MODE theContext = NC_CreateIOContext(); CheckErr(NC_SetIOMode(theContext, NC_IO_MODE)); CheckErr(NC_SetWriteCommand(theContext, myWrite, stdout)); CheckErr(NC_SetReadStringCommand(theContext, myReadString, stdin)); CheckErr(NC_SetReadCharCommand(theContext, myReadChar, stdin)); #endif /* get nialroot path from environment on console version */ { char *nroot; nialrootname[0] = '\0'; nroot = getenv("NIALROOT"); if (nroot != NULL) strcpy(nialrootname, nroot); } /* initialize the user break capability */ signal(SIGINT, controlCcatch); /* initialize the core routines */ irc = NC_InitNial(sessionSettings, windSettings, theContext); if (NC_IsTerminate(irc)) { /* initialization has signalled a termination */ exit(0); } else { CheckErr(irc); } #ifdef INTERNAL_BUF_MODE /* display the result in the internal buffer */ printf("%s", NC_GetBuffer()); #endif /* avoid the top level loop in a RUNTIME ONLY or CGINIAL version */ #ifdef RUNTIMEONLY goto cleanup; #endif #ifdef CGINIAL goto cleanup; #endif /* the top level loop */ do { retry: /* issue the prompt to the console */ myWrite(stdout, NC_GetPrompt(windSettings)); userbreakrequested = false; /* could have been set during latent call in * NC_InitNial() */ /* get the input string */ awaitinginput = true; myReadInput(); /* check if the input included a Control C press */ if (myCheckUserBreak(NC_CS_INPUT)) { /* printf("myCheckUserBreak returned true\n"); */ /* remove after testing in UNIX */ /* make sure workspace is clean */ cleanup_ws(); #ifdef HISTORY if (lasteval != -1) { decrrefcnt(lasteval); freeup(lasteval); } lasteval = (-1); #endif #ifdef DEBUG printf("userbreakrequested set during input at top level loop\n"); #endif userbreakrequested = false; goto retry; /* to go around to the prompt again */ } if (EOFsignalled) { /* the feof() code in Borland C returns nonzero if Ctrl-C has been pressed. This leads to a premature exit here. Removing the test causes nial.exe to loop forever if used as a filter. */ goto cleanup; } awaitinginput = false; /* interpret the input */ rc = NC_CommandInterpret(inputline, windSettings, theContext); /* check if there was a Control C press during CI execution */ if (myCheckUserBreak(NC_CS_NORMAL)) { cleanup_ws(); #ifdef DEBUG printf("userbreakrequested set during input at top level loop\n"); #endif userbreakrequested = false; goto retry; /* to go around to the prompt again */ } #ifdef INTERNAL_BUF_MODE /* display the output if buffered */ printf("%s\n", NC_GetBuffer()); #endif /* check the return code from CI */ if (!(NC_IsNoError(rc) || NC_IsWarning(rc) || NC_IsBreak(rc) || NC_IsTerminate(rc))) { /* display error information to console */ printf("Return Code: %s ErrorTypeName : %s\n", NC_ErrorTypeName(rc), NC_ErrorMessage(rc)); } } while (NC_IsWarning(rc) || NC_IsNoError(rc) || NC_IsBreak(rc)); /* end of top level loop code */ cleanup: /* stop the interpreter and clean up its resource usage */ NC_StopNial(); /* clean up the core interface resources */ CheckErr(NC_DestroyIOContext(theContext)); CheckErr(NC_DestroyWindowSettings(windSettings)); CheckErr(NC_DestroySessionSettings(sessionSettings)); /* return from the console version of Q'Nial */ /* getchar(); */ /* MAJ: put in the above getchar here to delay exit so that debug output can be seen when running from the Borland interface */ exit(0); return 1; /* to satisfy syntax error checking */ }
/* Main program. */ int main(int argc, char* argv[]) { const int verbose = 0; if ((argc < 2) || (argc > 6)) { print_syntax(argv[0]); return 1; } const char* infile = argv[1]; const char* out_pmusic = NULL; const char* out_labels = NULL; double sm_segment_min_dur = 4.0f; double b_segment_min_dur = 4.0f; if (argc >= 3) { out_pmusic = argv[2]; } if (argc >= 4) { out_labels = argv[3]; } if (argc >= 5) { sm_segment_min_dur = atof(argv[4]); } if (argc >= 6) { b_segment_min_dur = atof(argv[5]); } /* Load file */ WAVE* wave = open_wav(infile, verbose); if (wave == NULL) { return 1; } /* Init Opus encoder */ OpusSM* sm = init_opus(wave); if (sm == NULL) { wclose(wave); return 1; } /* Open output files */ FILE* ofp_pmusic = open_output_file(out_pmusic); if (ofp_pmusic == NULL) { wclose(wave); sm_destroy(sm); return 1; } FILE* ofp_labels = open_output_file(out_labels); if (ofp_labels == NULL) { wclose(wave); sm_destroy(sm); fclose(ofp_pmusic); return 1; } /* Processing */ int error = process(infile, wave, sm, ofp_pmusic, ofp_labels, sm_segment_min_dur, b_segment_min_dur ); /* Clean up */ sm = sm_destroy(sm); wave = wclose(wave); fclose(ofp_pmusic); fclose(ofp_labels); return error; }
/* * A simple program to test the System Timer driver ****************************************************************************** */ int main (int argc, char* argv[]) { /* */ unsigned int read_value ; unsigned int write_value = 0 ; const char *files[] = {"/dev/CS", "/dev/CLO", "/dev/CHI", "/dev/C0", "/dev/C1", "/dev/C2", "/dev/C3"} ; //const unsigned int file_count = sizeof (files) / sizeof (char*) ; /* */ if (argv[1] == NULL) { print_syntax () ; exit (1) ; } /* */ piHiPri (100) ; /* */ unsigned int interval ; sscanf (argv[1], "%u", &interval) ; /* */ read_from_device (files[1], &read_value) ; write_value = (read_value / 10000000 + 1) * 10000000 ; write_to_device (files[4], &write_value) ; /* */ sigset_t block_mask, oldmask ; /* Set up the mask of signals to temporarily block. */ sigemptyset (&block_mask) ; sigaddset (&block_mask, SIGUSR1) ; sigaddset (&block_mask, SIGUSR2) ; /* */ struct sigaction action ; /* Establish the signal handler. */ action.sa_handler = signal_handler ; action.sa_mask = block_mask ; action.sa_flags = 0 ; /* */ sigaction (SIGUSR1, &action, NULL) ; sigaction (SIGUSR2, &action, NULL) ; /* */ sigprocmask (SIG_BLOCK, &block_mask, &oldmask) ; /* Wait for a signal to arrive. */ while (1) sigsuspend (&oldmask) ; /* */ sigprocmask (SIG_UNBLOCK, &block_mask, NULL) ; /* Program exists cleanly */ return 0 ; } //main
int main (int argc, char *argv[]) { int i; char *file_tex; char *file_source; FILE *texid; FILE *srcid; if (DEBUG_MODE >= 10) { for (i=0;i<argc;i++) (void) printf(" seetex argument: %d is <%s>\n",i,argv[i]); (void) printf("\n"); } if (argc == 1) { (void) printf(" zero arguments: print usage/syntax only \n\n"); (void) print_syntax(); (void) usage(0); } for (i=0;i<argc;i++) { if (! strncmp(argv[i],"-h",(size_t) 2)) { (void) printf(" [-h|-help] flag found: print usage/syntax only\n\n"); (void) print_syntax(); (void) usage(0); } } file_tex = argv[(argc-1)]; if (DEBUG_MODE >= 10) (void) printf(" seetex output file <%s>\n\n",file_tex); if (is_tex_file(file_tex)) /* is file *.tex ? */ { /* check existance and/or permissions */ if (access(file_tex,F_OK)) {if (DEBUG_MODE >= 10) (void) printf("Creating %s\n",file_tex);} else {if (DEBUG_MODE >= 10) (void) printf("Appending to %s\n",file_tex);} texid = fopen(file_tex,"a"); } else (void) seetex_error("tex file not specified in proper order",-1); for(i=1;i<(argc-1);i++) { file_source = argv[i]; if (is_fortran_file(file_source) && (!access(file_source,R_OK))) { if (DEBUG_MODE >= 10) (void) printf("fortran or seetex include file %s is readable\n",file_source); srcid = fopen(file_source,"r"); } else (void) seetex_error (" fortran source or seetex include file does not exist or \n does not have the proper '.F', '.f', '.fh' suffix",-2); if (DEBUG_MODE >= 10) { if (is_fortran_file(file_source)) (void) printf("%s is a fortran or seetex include file\n",file_source); else (void) printf("%s is NOT a fortran or seetex include file\n",file_source); } (void) printf(" tex output from <%s> written to <<%s>>\n",file_source,file_tex); if (! seetex_process(srcid,texid)) (void) seetex_error(" error processing fortran source or seetex include file\n",1); (void) fflush(texid); (void) fclose(srcid); } (void) fflush(texid); (void) fclose(texid); /* return no error condition */ return FALSE; }
int main(int argc, char *argv[]) { int n, l, complete_type = 0, not_allowed = 0, argv_mode = 0; #ifdef USING_GLFTPD int gnum = 0, unum = 0; char myflags[20]; #endif char *ext, exec[4096], *complete_bar = 0, *inc_point[2]; unsigned int crc; struct stat fileinfo; uid_t f_uid; gid_t f_gid; double temp_time = 0; DIR *dir, *parent; struct dirent *dp; long loc; time_t timenow; #if (test_for_password || extract_nfo || zip_clean) off_t tempstream; #endif short rescan_quick = rescan_default_to_quick; char one_name[NAME_MAX]; char *temp_p = NULL; int chdir_allowed = 0, argnum = 0; GLOBAL g; #if (enable_rescan_script) char target[PATH_MAX+NAME_MAX]; #endif #if ( program_uid > 0 ) setegid(program_gid); seteuid(program_uid); #endif umask(0666 & 000); d_log("rescan: PZS-NG (rescan v2) %s debug log.\n", ng_version); d_log("rescan: Rescan executed by: (uid/gid) %d/%d\n", geteuid(), getegid()); #ifdef _ALT_MAX d_log("rescan: PATH_MAX not found - using predefined settings! Please report to the devs!\n"); #endif d_log("rescan: Allocating memory for variables\n"); g.ui = ng_realloc2(g.ui, sizeof(*g.ui) * 30, 1, 1, 1); g.gi = ng_realloc2(g.gi, sizeof(*g.gi) * 30, 1, 1, 1); bzero(one_name, NAME_MAX); #ifdef USING_GLFTPD if (getenv("FLAGS")) { strlcpy(myflags, getenv("FLAGS"), sizeof(myflags)); n = strlen(myflags); while (n > 0) { --n; l = strlen(rescan_chdir_flags); while(l > 0) { --l; if (myflags[n] == rescan_chdir_flags[l]) chdir_allowed = 1; } } } if (!geteuid()) chdir_allowed = 1; #endif /* With glftpd we can use env vars, rest of the world: commandline. */ #ifndef USING_GLFTPD if (argc < 7) { print_syntax(chdir_allowed); ng_free(g.ui); ng_free(g.gi); return 0; } argnum = 6; if (chdir(argv[5]) != 0) { printf("Could not chdir to <cwd = '%s'>, ftpd agnostic mode: %s\n", argv[5], strerror(errno)); d_log("rescan: Could not chdir to <cwd = '%s'>, ftpd agnostic mode: %s\n", argv[5], strerror(errno)); ng_free(g.ui); ng_free(g.gi); return 1; } #else argnum = 1; #endif while ((argnum < argc) && argc > 1) { if (!strncasecmp(argv[argnum], "--quick", 7)) rescan_quick = TRUE; else if (!strncasecmp(argv[argnum], "--normal", 8)) rescan_quick = FALSE; else if (!strncasecmp(argv[argnum], "--dir=", 6) && (strlen(argv[argnum]) > 7) && chdir_allowed) { temp_p = argv[argnum] + 6; if ((!matchpath(nocheck_dirs, temp_p)) && (matchpath(zip_dirs, temp_p) || matchpath(sfv_dirs, temp_p)) && !matchpath(group_dirs, temp_p)) { if (chdir(temp_p)) { d_log("rescan: Failed to chdir() to %s : %s\n", temp_p, strerror(errno)); not_allowed = 1; } } else { printf("Not allowed to chdir() to %s\n", temp_p); ng_free(g.ui); ng_free(g.gi); return 1; } printf("PZS-NG Rescan %s: Rescanning %s\n", ng_version, temp_p); argv_mode = 1; } else if (!strncasecmp(argv[argnum], "--chroot=", 9) && (strlen(argv[argnum]) > 10) && chdir_allowed) { if (temp_p == NULL) { temp_p = argv[argnum] + 9; if (chroot(temp_p) == -1) { d_log("rescan: Failed to chroot() to %s : %s\n", temp_p, strerror(errno)); not_allowed = 1; } } else { temp_p = argv[argnum] + 9; printf("Not allowed to chroot() to %s\n", temp_p); ng_free(g.ui); ng_free(g.gi); return 1; } printf("PZS-NG Rescan %s: Chroot'ing to %s\n", ng_version, temp_p); argv_mode = 1; } else if (!strncasecmp(argv[argnum], "--help", 6) || !strncasecmp(argv[argnum], "/?", 2) || !strncasecmp(argv[argnum], "--?", 3)) { print_syntax(chdir_allowed); ng_free(g.ui); ng_free(g.gi); return 0; } else { strlcpy(one_name, argv[argnum], sizeof(one_name)); rescan_quick = FALSE; printf("PZS-NG Rescan %s: Rescanning in FILE mode\n", ng_version); if (one_name[strlen(one_name) - 1] == '*') { one_name[strlen(one_name) - 1] = '\0'; } else if (!fileexists(one_name)) { d_log("PZS-NG Rescan: No file named '%s' exists.\n", one_name); one_name[0] = '\0'; not_allowed = 1; } argv_mode = 1; } argnum++; } if (one_name[0] == '\0') { if (rescan_quick == TRUE) { printf("PZS-NG Rescan %s: Rescanning in QUICK mode.\n", ng_version); } else { printf("PZS-NG Rescan %s: Rescanning in NORMAL mode.\n", ng_version); } } printf("PZS-NG Rescan %s: Use --help for options.\n\n", ng_version); if (not_allowed) { ng_free(g.ui); ng_free(g.gi); return 1; } if (!getcwd(g.l.path, PATH_MAX)) { d_log("rescan: getcwd() failed: %s\n", strerror(errno)); } if (subcomp(g.l.path, g.l.basepath) && (g.l.basepath[0] == '\0')) strlcpy(g.l.basepath, g.l.path, sizeof(g.l.basepath)); if (strncmp(g.l.path, g.l.basepath, PATH_MAX)) d_log("rescan: We are in subdir of %s\n", g.l.basepath); strlcpy(g.v.misc.current_path, g.l.path, sizeof(g.v.misc.current_path)); strlcpy(g.v.misc.basepath, g.l.basepath, sizeof(g.v.misc.basepath)); if ((matchpath(nocheck_dirs, g.l.path) && !rescan_nocheck_dirs_allowed) || (matchpath(group_dirs, g.l.path) && argv_mode) || (!matchpath(nocheck_dirs, g.l.path) && !matchpath(zip_dirs, g.l.path) && !matchpath(sfv_dirs, g.l.path) && !matchpath(group_dirs, g.l.path)) || insampledir(g.l.path)) { d_log("rescan: Dir matched with nocheck_dirs/sample_list, or is not in the zip/sfv/group-dirs.\n"); d_log("rescan: Freeing memory, and exiting.\n"); printf("Notice: Unable to rescan this dir - check config.\n\n"); ng_free(g.ui); ng_free(g.gi); return 0; } g.v.misc.slowest_user[0] = ULONG_MAX; bzero(&g.v.total, sizeof(struct race_total)); g.v.misc.fastest_user[0] = 0; g.v.misc.release_type = RTYPE_NULL; g.v.misc.write_log = 0; #ifdef USING_GLFTPD if (getenv("SECTION") == NULL) { sprintf(g.v.sectionname, "DEFAULT"); } else { snprintf(g.v.sectionname, sizeof(g.v.sectionname), "%s", getenv("SECTION")); } #else snprintf(g.v.sectionname, sizeof(g.v.sectionname), argv[4]); #endif g.l.length_path = (int)strlen(g.l.path); g.l.length_zipdatadir = sizeof(storage); n = g.l.length_path + g.l.length_zipdatadir + 11; g.l.race = ng_realloc2(g.l.race, n, 1, 1, 1); g.l.sfv = ng_realloc2(g.l.sfv, n - 1, 1, 1, 1); g.l.sfvbackup = ng_realloc2(g.l.sfvbackup, n + 1, 1, 1, 1); g.l.leader = ng_realloc2(g.l.leader, n - 2, 1, 1, 1); g.l.sfv_incomplete = 0; getrelname(&g); #ifdef USING_GLFTPD gnum = buffer_groups(GROUPFILE, 0); unum = buffer_users(PASSWDFILE, 0); #endif sprintf(g.l.sfv, storage "/%s/sfvdata", g.l.path); sprintf(g.l.sfvbackup, storage "/%s/sfvbackup", g.l.path); sprintf(g.l.leader, storage "/%s/leader", g.l.path); sprintf(g.l.race, storage "/%s/racedata", g.l.path); d_log("rescan: Creating directory to store racedata in\n"); maketempdir(g.l.path); d_log("rescan: Locking release\n"); while (1) { if ((l = create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 3, 0))) { d_log("rescan: Failed to lock release.\n"); if (l == 1) { d_log("rescan: version mismatch. Exiting.\n"); printf("Error. You need to rm -fR ftp-data/pzs-ng/* before rescan will work.\n"); /* */ ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif exit(EXIT_FAILURE); } if (l == PROGTYPE_POSTDEL) { n = (signed int)g.v.data_incrementor; d_log("rescan: Detected postdel running - sleeping for one second.\n"); if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue)) break; usleep(1000000); if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue)) break; if ( n == (signed int)g.v.data_incrementor) { d_log("rescan: Failed to get lock. Forcing unlock.\n"); if (create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 2, g.v.data_queue)) { d_log("rescan: Failed to force a lock.\n"); d_log("rescan: Exiting with error.\n"); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif exit(EXIT_FAILURE); } break; } } else { for (l = 0; l <= max_seconds_wait_for_lock * 10; ++l) { d_log("rescan: sleeping for .1 second before trying to get a lock (queue: %d).\n", g.v.data_queue); usleep(100000); if (!create_lock(&g.v, g.l.path, PROGTYPE_RESCAN, 0, g.v.data_queue)) break; } if (l >= max_seconds_wait_for_lock * 10) { d_log("rescan: Failed to get lock. Will not force unlock.\n"); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif exit(EXIT_FAILURE); } } } usleep(10000); if (update_lock(&g.v, 1, 0) != -1) break; } move_progress_bar(1, &g.v, g.ui, g.gi); if (g.l.incomplete) unlink(g.l.incomplete); if (del_completebar) removecomplete(); dir = opendir("."); parent = opendir(".."); if (!((rescan_quick && findfileext(dir, ".sfv")) || *one_name)) { if (g.l.sfv) unlink(g.l.sfv); if (g.l.race) unlink(g.l.race); } printf("Rescanning files...\n"); if (findfileext(dir, ".zip")) { if (!fileexists(unzip_bin)) { printf("rescan: ERROR! Not able to check zip-files - %s does not exist!\n", unzip_bin); closedir(dir); closedir(parent); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif remove_lock(&g.v); exit(EXIT_FAILURE); } else { crc = 0; rewinddir(dir); timenow = time(NULL); while ((dp = readdir(dir))) { ext = find_last_of(dp->d_name, "."); if (*ext == '.') ext++; if (!strcasecmp(ext, "zip")) { stat(dp->d_name, &fileinfo); f_uid = fileinfo.st_uid; f_gid = fileinfo.st_gid; if ((timenow == fileinfo.st_ctime) && (fileinfo.st_mode & 0111)) { d_log("rescan.c: Seems this file (%s) is in the process of being uploaded. Ignoring for now.\n", dp->d_name); continue; } #ifdef USING_GLFTPD strlcpy(g.v.user.name, get_u_name(f_uid), sizeof(g.v.user.name)); strlcpy(g.v.user.group, get_g_name(f_gid), sizeof(g.v.user.group)); #else strlcpy(g.v.user.name, argv[1], sizeof(g.v.user.name)); strlcpy(g.v.user.group, argv[2], sizeof(g.v.user.group)); #endif strlcpy(g.v.file.name, dp->d_name, sizeof(g.v.file.name)); g.v.file.speed = 2005 * 1024; g.v.file.size = fileinfo.st_size; g.v.total.start_time = 0; #if (test_for_password || extract_nfo) tempstream = telldir(dir); if ((!findfileextcount(dir, ".nfo") || findfileextcount(dir, ".zip")) && !mkdir(".unzipped", 0777)) snprintf(exec, sizeof(exec), "%s -qqjo \"%s\" -d .unzipped 2>.delme", unzip_bin, g.v.file.name); else snprintf(exec, sizeof(exec), "%s -qqt \"%s\" 2>.delme", unzip_bin, g.v.file.name); seekdir(dir, tempstream); #else snprintf(exec, sizeof(exec), "%s -qqt \"%s\" 2>.delme", unzip_bin, g.v.file.name); #endif if (system(exec) == 0 || (allow_error2_in_unzip == TRUE && errno < 3 )) { writerace(g.l.race, &g.v, crc, F_CHECKED); } else { writerace(g.l.race, &g.v, crc, F_BAD); if (g.v.file.name) unlink(g.v.file.name); removedir(".unzipped"); continue; } #if (test_for_password || extract_nfo || zip_clean) tempstream = telldir(dir); if ((!findfileextcount(dir, ".nfo") || findfileextcount(dir, ".zip")) && check_zipfile(".unzipped", g.v.file.name, findfileextcount(dir, ".nfo"))) { d_log("rescan: File %s is password protected.\n", g.v.file.name); writerace(g.l.race, &g.v, crc, F_BAD); if (g.v.file.name) unlink(g.v.file.name); seekdir(dir, tempstream); continue; } seekdir(dir, tempstream); #endif if (!fileexists("file_id.diz")) { snprintf(exec, sizeof(exec), "%s -qqjnCLL \"%s\" file_id.diz 2>.delme", unzip_bin, g.v.file.name); if (execute(exec) != 0) { d_log("rescan: No file_id.diz found (#%d): %s\n", errno, strerror(errno)); } else { if (fileexists("file_id.diz.bad")) { loc = findfile(dir, "file_id.diz.bad"); seekdir(dir, loc); dp = readdir(dir); unlink(dp->d_name); } if (chmod("file_id.diz", 0666)) d_log("rescan: Failed to chmod %s: %s\n", "file_id.diz", strerror(errno)); } } } } if (fileexists(".delme")) unlink(".delme"); g.v.total.files = read_diz(); if (!g.v.total.files) { g.v.total.files = 1; unlink("file_id.diz"); } g.v.total.files_missing = g.v.total.files; readrace(g.l.race, &g.v, g.ui, g.gi); sortstats(&g.v, g.ui, g.gi); if (g.v.total.files_missing < 0) { g.v.total.files -= g.v.total.files_missing; g.v.total.files_missing = 0; } buffer_progress_bar(&g.v); if (g.v.total.files_missing == 0) { complete(&g, complete_type); createstatusbar(convert(&g.v, g.ui, g.gi, zip_completebar)); #if (chmod_completebar) if (!matchpath(group_dirs, g.l.path)) { if (chmod_each(convert(&g.v, g.ui, g.gi, zip_completebar), 0222)) d_log("rescan: Failed to chmod a statusbar: %s\n", strerror(errno)); } #endif } else { if (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) { if (create_incomplete()) { d_log("rescan: create_incomplete() returned something\n"); } } move_progress_bar(0, &g.v, g.ui, g.gi); } if (g.l.nfo_incomplete) { if (findfileext(dir, ".nfo")) { d_log("rescan: Removing missing-nfo indicator (if any)\n"); remove_nfo_indicator(&g); } else if (matchpath(check_for_missing_nfo_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) { if (!g.l.in_cd_dir) { d_log("rescan: Creating missing-nfo indicator %s.\n", g.l.nfo_incomplete); if (create_incomplete_nfo()) { d_log("rescan: create_incomplete_nfo() returned something\n"); } } else { if (findfileextparent(parent, ".nfo")) { d_log("rescan: Removing missing-nfo indicator (if any)\n"); remove_nfo_indicator(&g); } else { d_log("rescan: Creating missing-nfo indicator (base) %s.\n", g.l.nfo_incomplete); if (create_incomplete_nfo()) { d_log("rescan: create_incomplete_nfo() returned something\n"); } } } } } } } else if ((temp_p = findfileext(dir, ".sfv")) || (create_missing_sfv && file_count(dir))) { if (!temp_p && create_missing_sfv && file_count(dir)) { d_log("rescan: No sfv found - creating one.\n"); make_sfv(g.l.path); if (!(temp_p = findfileext(dir, ".sfv"))) { d_log("rescan: Freeing memory, removing lock and exiting.\n"); unlink(g.l.sfv); if (fileexists(g.l.sfvbackup)) unlink(g.l.sfvbackup); unlink(g.l.race); closedir(dir); closedir(parent); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif remove_lock(&g.v); return 0; } } #if ( create_missing_sfv_link == TRUE ) d_log("rescan: Removing missing-sfv indicator (if any)\n"); unlink(g.l.sfv_incomplete); #endif strlcpy(g.v.file.name, temp_p, sizeof(g.v.file.name)); maketempdir(g.l.path); stat(g.v.file.name, &fileinfo); if (copysfv(g.v.file.name, g.l.sfv, &g.v)) { printf("Found invalid entries in SFV - Exiting.\n"); while ((dp = readdir(dir))) { ext = find_last_of(dp->d_name, "-"); if (!strcasecmp(ext, "-missing")) unlink(dp->d_name); } d_log("rescan: Freeing memory, removing lock and exiting\n"); unlink(g.l.sfv); if (fileexists(g.l.sfvbackup)) unlink(g.l.sfvbackup); unlink(g.l.race); closedir(dir); closedir(parent); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif remove_lock(&g.v); return 0; } g.v.total.start_time = 0; rewinddir(dir); while ((dp = readdir(dir))) { if (*one_name && strncasecmp(one_name, dp->d_name, strlen(one_name))) continue; l = (int)strlen(dp->d_name); ext = find_last_of(dp->d_name, ".-"); if (*ext == '.') ext++; if (!update_lock(&g.v, 1, 0)) { d_log("rescan: Another process wants the lock - will comply and remove lock, then exit.\n"); closedir(dir); closedir(parent); ng_free(g.ui); ng_free(g.gi); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); ng_free(g.l.race); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif remove_lock(&g.v); exit(EXIT_FAILURE); } if ( !strcomp(ignored_types, ext) && (!(strcomp(allowed_types, ext) && !matchpath(allowed_types_exemption_dirs, g.l.path))) && strcasecmp("sfv", ext) && strcasecmp("nfo", ext) && strcasecmp("bad", ext) && strcasecmp("-missing", ext) && strncmp(dp->d_name, ".", 1) ) { stat(dp->d_name, &fileinfo); if (S_ISDIR(fileinfo.st_mode)) continue; if (ignore_zero_sized_on_rescan && !fileinfo.st_size) continue; f_uid = fileinfo.st_uid; f_gid = fileinfo.st_gid; #ifdef USING_GLFTPD strlcpy(g.v.user.name, get_u_name(f_uid), sizeof(g.v.user.name)); strlcpy(g.v.user.group, get_g_name(f_gid), sizeof(g.v.user.group)); #else strlcpy(g.v.user.name, argv[1], sizeof(g.v.user.name)); strlcpy(g.v.user.group, argv[2], sizeof(g.v.user.group)); #endif strlcpy(g.v.file.name, dp->d_name, sizeof(g.v.file.name)); g.v.file.speed = 2005 * 1024; g.v.file.size = fileinfo.st_size; temp_time = fileinfo.st_mtime; if (g.v.total.start_time == 0) g.v.total.start_time = temp_time; else g.v.total.start_time = (g.v.total.start_time < temp_time ? g.v.total.start_time : temp_time); g.v.total.stop_time = (temp_time > g.v.total.stop_time ? temp_time : g.v.total.stop_time); /* Hide users in group_dirs */ if (matchpath(group_dirs, g.l.path) && (hide_group_uploaders == TRUE)) { d_log("rescan: Hiding user in group-dir:\n"); if ((int)strlen(hide_gname) > 0) { snprintf(g.v.user.group, sizeof(g.v.user.group), "%s", hide_gname); d_log("rescan: Changing groupname\n"); } if ((int)strlen(hide_uname) > 0) { snprintf(g.v.user.name, sizeof(g.v.user.name), "%s", hide_uname); d_log("rescan: Changing username\n"); } #if (show_users_in_group_dirs == FALSE) if ((int)strlen(hide_uname) == 0) { d_log("rescan: Making username = groupname\n"); snprintf(g.v.user.name, sizeof(g.v.user.name), "%s", g.v.user.group); } #endif } if (!rescan_quick || (g.l.race && !match_file(g.l.race, dp->d_name))) crc = calc_crc32(dp->d_name); else crc = 1; if (!S_ISDIR(fileinfo.st_mode)) { if (g.v.file.name) unlink_missing(g.v.file.name); if (l > 44) { if (crc == 1) printf("\nFile: %s CHECKED", dp->d_name + l - 44); else printf("\nFile: %s %.8x", dp->d_name + l - 44, crc); } else { if (crc == 1) printf("\nFile: %-44s CHECKED", dp->d_name); else printf("\nFile: %-44s %.8x", dp->d_name, crc); } } if(fflush(stdout)) d_log("rescan: ERROR: %s\n", strerror(errno)); if (!rescan_quick || (g.l.race && !match_file(g.l.race, dp->d_name)) || !fileexists(dp->d_name)) writerace(g.l.race, &g.v, crc, F_NOTCHECKED); } } printf("\n"); testfiles(&g.l, &g.v, 1); printf("\n"); readsfv(g.l.sfv, &g.v, 0); readrace(g.l.race, &g.v, g.ui, g.gi); sortstats(&g.v, g.ui, g.gi); buffer_progress_bar(&g.v); if (g.l.nfo_incomplete) { if (findfileext(dir, ".nfo")) { d_log("rescan: Removing missing-nfo indicator (if any)\n"); remove_nfo_indicator(&g); } else if (matchpath(check_for_missing_nfo_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) { if (!g.l.in_cd_dir) { d_log("rescan: Creating missing-nfo indicator %s.\n", g.l.nfo_incomplete); if (create_incomplete_nfo()) { d_log("rescan: create_incomplete_nfo() returned something\n"); } } else { if (findfileextparent(parent, ".nfo")) { d_log("rescan: Removing missing-nfo indicator (if any)\n"); remove_nfo_indicator(&g); } else { d_log("rescan: Creating missing-nfo indicator (base) %s.\n", g.l.nfo_incomplete); /* This is not pretty, but should be functional. */ if ((inc_point[0] = find_last_of(g.l.path, "/")) != g.l.path) *inc_point[0] = '\0'; if ((inc_point[1] = find_last_of(g.v.misc.release_name, "/")) != g.v.misc.release_name) *inc_point[1] = '\0'; if (create_incomplete_nfo()) { d_log("rescan: create_incomplete_nfo() returned something\n"); } if (*inc_point[0] == '\0') *inc_point[0] = '/'; if (*inc_point[1] == '\0') *inc_point[1] = '/'; } } } } #if (create_missing_sample_link) if (g.l.sample_incomplete) { if (findfileextsub(dir) || matchpartialdirname(missing_sample_check_ignore_list, g.v.misc.release_name, missing_sample_check_ignore_dividers)) { d_log("rescan: Removing missing-sample indicator (if any)\n"); remove_sample_indicator(&g); } else if (matchpath(check_for_missing_sample_dirs, g.l.path) && (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs)) { if (!g.l.in_cd_dir) { d_log("rescan: Creating missing-sample indicator %s.\n", g.l.sample_incomplete); if (create_incomplete_sample()) { d_log("rescan: create_incomplete_sample() returned something\n"); } } else { if (findfileextsubp(dir)) { d_log("rescan: Removing missing-sample indicator (if any)\n"); remove_sample_indicator(&g); } else { d_log("rescan: Creating missing-sample indicator (base) %s.\n", g.l.sample_incomplete); /* This is not pretty, but should be functional. */ if ((inc_point[0] = find_last_of(g.l.path, "/")) != g.l.path) *inc_point[0] = '\0'; if ((inc_point[1] = find_last_of(g.v.misc.release_name, "/")) != g.v.misc.release_name) *inc_point[1] = '\0'; if (create_incomplete_sample()) { d_log("rescan: create_incomplete_sample() returned something\n"); } if (*inc_point[0] == '\0') *inc_point[0] = '/'; if (*inc_point[1] == '\0') *inc_point[1] = '/'; } } } } #endif if (g.v.misc.release_type == RTYPE_AUDIO) { get_audio_info(findfileextfromlist(dir, audio_types), &g.v.audio); /* Sort if we're not in a group-dir/nosort-dir. */ if (!matchpath(group_dirs, g.l.path) && !matchpath(audio_nosort_dirs, g.l.path)) { printf(" Resorting release.\n"); audioSort(&g.v.audio, g.l.link_source, g.l.link_target); } } if ((g.v.total.files_missing == 0) && (g.v.total.files > 0)) { switch (g.v.misc.release_type) { case RTYPE_RAR: complete_bar = rar_completebar; break; case RTYPE_OTHER: complete_bar = other_completebar; break; case RTYPE_AUDIO: complete_bar = audio_completebar; #if ( create_m3u == TRUE ) n = snprintf(exec, sizeof(exec), "%s", findfileext(dir, ".sfv")); strcpy(exec + n - 3, "m3u"); create_indexfile(g.l.race, &g.v, exec); #endif break; case RTYPE_VIDEO: complete_bar = video_completebar; break; } complete(&g, complete_type); if (complete_bar) { createstatusbar(convert(&g.v, g.ui, g.gi, complete_bar)); #if (chmod_completebar) if (!matchpath(group_dirs, g.l.path)) { if (chmod_each(convert(&g.v, g.ui, g.gi, complete_bar), 0222)) d_log("rescan: Failed to chmod a statusbar: %s\n", strerror(errno)); } #endif } #if (enable_rescan_script) d_log("rescan: Executing rescan_script script\n"); if (!fileexists(rescan_script)) { d_log("rescan: Warning - rescan_script (%s) - file does not exist!\n", rescan_script); } else { snprintf(target, sizeof(target), rescan_script " \"%s\"", g.v.file.name); if (execute(target) != 0) d_log("rescan: Failed to execute rescan_script: %s\n", strerror(errno)); } #endif } else { if (!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) { if (create_incomplete()) { d_log("rescan: create_incomplete() returned something\n"); } } move_progress_bar(0, &g.v, g.ui, g.gi); } } else { int empty = 1; #if (create_missing_sfv_link == TRUE) if ((!matchpath(group_dirs, g.l.path) || create_incomplete_links_in_group_dirs) && g.l.sfv_incomplete && !matchpath(nocheck_dirs, g.l.path) && !matchpath(allowed_types_exemption_dirs, g.l.path)) { rewinddir(dir); while ((dp = readdir(dir))) { stat(dp->d_name, &fileinfo); if (S_ISREG(fileinfo.st_mode)) { ext = find_last_of(dp->d_name, "."); if (*ext == '.') ext++; if (*ext && get_filetype(&g, ext) == 3) { d_log("rescan: Creating missing-sfv indicator %s.\n", g.l.sfv_incomplete); if (create_incomplete_sfv()) d_log("rescan: create_incomplete_sfv() returned something.\n"); empty = 0; break; } } } } #endif if (empty && mark_empty_dirs_as_incomplete_on_rescan) { if (create_incomplete()) { d_log("rescan: create_incomplete() returned something\n"); } printf(" Empty dir - marking as incomplete.\n"); } } printf(" Passed : %i\n", (int)g.v.total.files - (int)g.v.total.files_missing); printf(" Failed : %i\n", (int)g.v.total.files_bad); printf(" Missing: %i\n", (int)g.v.total.files_missing); printf(" Total : %i\n", (int)g.v.total.files); if (g.v.total.files && !g.v.total.files_missing) { g.v.misc.data_completed = 1; } else { g.v.misc.data_completed = 0; } d_log("rescan: Freeing memory and removing lock.\n"); closedir(dir); closedir(parent); ng_free(g.l.race); ng_free(g.l.sfv); ng_free(g.l.sfvbackup); ng_free(g.l.leader); remove_lock(&g.v); updatestats_free(&g); #ifdef USING_GLFTPD buffer_groups(GROUPFILE, gnum); buffer_users(PASSWDFILE, unum); #endif exit(0); }
void import_m3u_playlist(netmd_dev_handle* devh, const char *file) { FILE *fp; char buffer[M3U_LINE_MAX + 1]; char *s; uint8_t track; int discard; if( file == NULL ) { printf( "No filename specified\n" ); print_syntax(); return; } if( (fp = fopen( file, "r" )) == NULL ) { printf( "Unable to open file %s: %s\n", file, strerror( errno )); return; } if( ! fgets( buffer, M3U_LINE_MAX, fp )) { printf( "File Read error\n" ); return; } if( strcmp( buffer, "#EXTM3U\n" )) { printf( "Invalid M3U playlist\n" ); return; } track = 0; discard = 0; while( fgets( buffer, M3U_LINE_MAX, fp) != NULL ) { /* Chomp newlines */ s = strchr( buffer, '\n' ); if( s ) *s = '\0'; if( buffer[0] == '#' ) { /* comment, ext3inf etc... we only care about ext3inf */ if( strncmp( buffer, "#EXTINF:", 8 )) { printf( "Skip: %s\n", buffer ); } else { s = strchr( buffer, ',' ); if( !s ) { printf( "M3U Syntax error! %s\n", buffer ); } else { s++; printf( "Title track %d - %s\n", track, s ); netmd_set_title(devh, track, s); /* XXX Handle errors */ discard = 1; /* don't fallback to titling by filename */ } } } else { /* Filename line */ if( discard ) { /* printf( "Discard: %s\n", buffer ); */ discard = 0; } else { /* Try and generate a title from the track name */ s = strrchr( buffer, '.' ); /* Isolate extension */ if( s ) *s = 0; s = strrchr( buffer, '/' ); /* Isolate basename */ if( !s ) s = strrchr( buffer, '\\' ); /* Handle DOS paths? */ if( !s ) s = buffer; else s++; printf( "Title track %d - %s\n", track, s ); netmd_set_title(devh, track, s); /* XXX Handle errors */ } track++; } } }
int main(int argc, char* argv[]) { netmd_dev_handle* devh; minidisc my_minidisc, *md = &my_minidisc; netmd_device *device_list, *netmd; unsigned int i = 0; unsigned int j = 0; char name[16]; uint16_t track, playmode; int c; netmd_time time; netmd_error error; FILE *f; error = netmd_init(&device_list); if (error != NETMD_NO_ERROR) { printf("Error initializing netmd\n%s\n", netmd_strerror(error)); return -1; } if (device_list == NULL) { puts("Found no NetMD device(s)."); return -1; } /* pick first available device */ netmd = device_list; error = netmd_open(netmd, &devh); if(error != NETMD_NO_ERROR) { printf("Error opening netmd\n%s\n", netmd_strerror(error)); return -1; } error = netmd_get_devname(devh, name, 16); if (error != NETMD_NO_ERROR) { printf("Could not get device name\n%s\n", netmd_strerror(error)); return -1; } printf("%s\n", name); netmd_initialize_disc_info(devh, md); printf("Disc Title: %s\n\n", md->groups[0].name); /* by default, log only errors */ netmd_set_log_level(NETMD_LOG_ERROR); /* parse options */ while (1) { c = getopt(argc, argv, "t"); if (c == -1) { break; } switch (c) { case 't': netmd_set_log_level(NETMD_LOG_ALL); break; default: fprintf(stderr, "Unknown option '%c'\n", c); break; } } /* update argv and argc after parsing options */ argv = &argv[optind - 1]; argc -= (optind - 1); /* parse commands */ if(argc > 1) { if(strcmp("rename", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); netmd_cache_toc(devh); netmd_set_title(devh, i & 0xffff, argv[3]); netmd_sync_toc(devh); } else if(strcmp("move", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); j = strtoul(argv[3], NULL, 10); netmd_move_track(devh, i & 0xffff, j & 0xffff); } else if(strcmp("groupmove", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); j = strtoul(argv[3], NULL, 10); netmd_move_group(devh, md, j & 0xffff, i & 0xffff); } else if(strcmp("write", argv[1]) == 0) { if(netmd_write_track(devh, argv[2]) < 0) { fprintf(stderr, "Error writing track %i\n", errno); } } else if(strcmp("newgroup", argv[1]) == 0) { netmd_create_group(devh, md, argv[2]); } else if(strcmp("settitle", argv[1]) == 0) { netmd_cache_toc(devh); netmd_set_disc_title(devh, argv[2], strlen(argv[2])); netmd_sync_toc(devh); } else if(strcmp("group", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); j = strtoul(argv[3], NULL, 10); if(!netmd_put_track_in_group(devh, md, i & 0xffff, j & 0xffff)) { printf("Something screwy happened\n"); } } else if(strcmp("retitle", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); netmd_set_group_title(devh, md, i, argv[3]); } else if(strcmp("play", argv[1]) == 0) { if( argc > 2 ) { i = strtoul(argv[2],NULL, 10); netmd_set_track( devh, i & 0xffff ); } netmd_play(devh); } else if(strcmp("stop", argv[1]) == 0) { netmd_stop(devh); } else if(strcmp("pause", argv[1]) == 0) { netmd_pause(devh); } else if(strcmp("fforward", argv[1]) == 0) { netmd_fast_forward(devh); } else if(strcmp("rewind", argv[1]) == 0) { netmd_rewind(devh); } else if(strcmp("next", argv[1]) == 0) { netmd_track_next(devh); } else if(strcmp("previous", argv[1]) == 0) { netmd_track_previous(devh); } else if(strcmp("restart", argv[1]) == 0) { netmd_track_restart(devh); } else if(strcmp("settime", argv[1]) == 0) { track = strtoul(argv[2], (char **) NULL, 10) & 0xffff; if (argc > 6) { time.hour = strtoul(argv[3], (char **) NULL, 10) & 0xffff; time.minute = strtoul(argv[4], (char **) NULL, 10) & 0xff; time.second = strtoul(argv[5], (char **) NULL, 10) & 0xff; time.frame = strtoul(argv[6], (char **) NULL, 10) & 0xff; } else { time.hour = 0; time.minute = strtoul(argv[3], (char **) NULL, 10) & 0xff; time.second = strtoul(argv[4], (char **) NULL, 10) & 0xff; if (argc > 5) { time.frame = strtoul(argv[5], (char **) NULL, 10) & 0xff;; } else { time.frame = 0; } } netmd_set_time(devh, track, &time); } else if(strcmp("m3uimport", argv[1]) == 0) { import_m3u_playlist(devh, argv[2]); } else if(strcmp("delete", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); netmd_delete_track(devh, i & 0xffff); } else if(strcmp("deletegroup", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); netmd_delete_group(devh, md, i & 0xffff); } else if(strcmp("status", argv[1]) == 0) { print_current_track_info(devh); } else if (strcmp("raw", argv[1]) == 0) { send_raw_message(devh, argv[2]); } else if (strcmp("setplaymode", argv[1]) == 0) { playmode = 0; int i; for (i = 2; i < argc; i++) { if (strcmp(argv[i], "single") == 0) { playmode |= NETMD_PLAYMODE_SINGLE; } else if (strcmp(argv[i], "repeat") == 0) { playmode |= NETMD_PLAYMODE_REPEAT; } else if (strcmp(argv[i], "shuffle") == 0) { playmode |= NETMD_PLAYMODE_SHUFFLE; } } printf("%x\n", playmode); netmd_set_playmode(devh, playmode); } else if (strcmp("capacity", argv[1]) == 0) { netmd_disc_capacity capacity; netmd_get_disc_capacity(devh, &capacity); printf("Recorded: "); print_time(&capacity.recorded); printf("\nTotal: "); print_time(&capacity.total); printf("\nAvailable: "); print_time(&capacity.available); printf("\n"); } else if (strcmp("recv", argv[1]) == 0) { i = strtoul(argv[2], NULL, 10); f = fopen(argv[3], "wb"); netmd_secure_recv_track(devh, i & 0xffff, f); fclose(f); } else if (strcmp("send", argv[1]) == 0) { netmd_error error; netmd_ekb ekb; unsigned char chain[] = {0x25, 0x45, 0x06, 0x4d, 0xea, 0xca, 0x14, 0xf9, 0x96, 0xbd, 0xc8, 0xa4, 0x06, 0xc2, 0x2b, 0x81, 0x49, 0xba, 0xf0, 0xdf, 0x26, 0x9d, 0xb7, 0x1d, 0x49, 0xba, 0xf0, 0xdf, 0x26, 0x9d, 0xb7, 0x1d}; unsigned char signature[] = {0xe8, 0xef, 0x73, 0x45, 0x8d, 0x5b, 0x8b, 0xf8, 0xe8, 0xef, 0x73, 0x45, 0x8d, 0x5b, 0x8b, 0xf8, 0x38, 0x5b, 0x49, 0x36, 0x7b, 0x42, 0x0c, 0x58}; unsigned char rootkey[] = {0x13, 0x37, 0x13, 0x37, 0x13, 0x37, 0x13, 0x37, 0x13, 0x37, 0x13, 0x37, 0x13, 0x37, 0x13, 0x37}; netmd_keychain *keychain; netmd_keychain *next; size_t done; unsigned char hostnonce[8] = { 0 }; unsigned char devnonce[8] = { 0 }; unsigned char sessionkey[8] = { 0 }; unsigned char kek[] = { 0x14, 0xe3, 0x83, 0x4e, 0xe2, 0xd3, 0xcc, 0xa5 }; unsigned char contentid[] = { 0x01, 0x0F, 0x50, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x48, 0xA2, 0x8D, 0x3E, 0x1A, 0x3B, 0x0C, 0x44, 0xAF, 0x2f, 0xa0 }; netmd_track_packets *packets = NULL; size_t packet_count = 0; struct stat stat_buf; unsigned char *data; size_t data_size; uint16_t track; unsigned char uuid[8] = { 0 }; unsigned char new_contentid[20] = { 0 }; error = netmd_secure_leave_session(devh); puts(netmd_strerror(error)); error = netmd_secure_set_track_protection(devh, 0x01); puts(netmd_strerror(error)); error = netmd_secure_enter_session(devh); puts(netmd_strerror(error)); /* build ekb */ ekb.id = 0x26422642; ekb.depth = 9; ekb.signature = malloc(sizeof(signature)); memcpy(ekb.signature, signature, sizeof(signature)); /* build ekb key chain */ ekb.chain = NULL; for (done = 0; done < sizeof(chain); done+=16U) { next = malloc(sizeof(netmd_keychain)); if (ekb.chain == NULL) { ekb.chain = next; } else { keychain->next = next; } next->next = NULL; next->key = malloc(16); memcpy(next->key, chain + done, 16); keychain = next; } error = netmd_secure_send_key_data(devh, &ekb); puts(netmd_strerror(error)); /* cleanup */ free(ekb.signature); keychain = ekb.chain; while (keychain != NULL) { next = keychain->next; free(keychain->key); free(keychain); keychain = next; } /* exchange nonces */ gcry_create_nonce(hostnonce, sizeof(hostnonce)); error = netmd_secure_session_key_exchange(devh, hostnonce, devnonce); puts(netmd_strerror(error)); /* calculate session key */ retailmac(rootkey, hostnonce, devnonce, sessionkey); error = netmd_secure_setup_download(devh, contentid, kek, sessionkey); puts(netmd_strerror(error)); /* read source */ stat(argv[2], &stat_buf); data_size = (size_t)stat_buf.st_size; data = malloc(data_size); f = fopen(argv[2], "rb"); fseek(f, 60, SEEK_CUR); fread(data, data_size - 60, 1, f); fclose(f); error = netmd_prepare_packets(data, data_size-60, &packets, &packet_count, kek); puts(netmd_strerror(error)); /* send to device */ error = netmd_secure_send_track(devh, NETMD_WIREFORMAT_LP2, NETMD_DISKFORMAT_LP2, (data_size - 60) / 192, packets, packet_count, sessionkey, &track, uuid, new_contentid); puts(netmd_strerror(error)); /* cleanup */ netmd_cleanup_packets(&packets); /* set title */ netmd_log(NETMD_LOG_DEBUG, "New Track: %d\n", track); netmd_cache_toc(devh); netmd_set_title(devh, track, "test"); netmd_sync_toc(devh); /* commit track */ error = netmd_secure_commit_track(devh, track, sessionkey); puts(netmd_strerror(error)); /* forget key */ error = netmd_secure_session_key_forget(devh); puts(netmd_strerror(error)); /* leave session */ error = netmd_secure_leave_session(devh); puts(netmd_strerror(error)); } else if(strcmp("help", argv[1]) == 0) { print_syntax(); } else { print_disc_info(devh, md); print_syntax(); } } else print_disc_info(devh, md); netmd_clean_disc_info(md); netmd_close(devh); netmd_clean(&device_list); return 0; }
int main(int argc, char *argv[]) { int rc; int argi; rc = inetping_init(&ev_ops); if (rc != EOK) { printf(NAME ": Failed connecting to internet ping service " "(%d).\n", rc); return 1; } argi = 1; if (argi < argc && str_cmp(argv[argi], "-r") == 0) { ping_repeat = true; ++argi; } else { ping_repeat = false; } if (argc - argi != 1) { print_syntax(); return 1; } /* Parse destination address */ rc = addr_parse(argv[argi], &dest_addr); if (rc != EOK) { printf(NAME ": Invalid address format.\n"); print_syntax(); return 1; } /* Determine source address */ rc = inetping_get_srcaddr(&dest_addr, &src_addr); if (rc != EOK) { printf(NAME ": Failed determining source address.\n"); return 1; } fid_t fid; if (ping_repeat) { fid = fibril_create(transmit_fibril, NULL); if (fid == 0) { printf(NAME ": Failed creating transmit fibril.\n"); return 1; } fibril_add_ready(fid); fid = fibril_create(input_fibril, NULL); if (fid == 0) { printf(NAME ": Failed creating input fibril.\n"); return 1; } fibril_add_ready(fid); } else { ping_send(1); } fibril_mutex_lock(&done_lock); rc = EOK; while (!done && rc != ETIMEOUT) { rc = fibril_condvar_wait_timeout(&done_cv, &done_lock, ping_repeat ? 0 : PING_TIMEOUT); } fibril_mutex_unlock(&done_lock); if (rc == ETIMEOUT) { printf(NAME ": Echo request timed out.\n"); return 1; } return 0; }