file sub_fifo(file f, client c){ assert(!(file_is_empty(f))); aff_client(f.client[f.first]); f.first++; return f; }
static int test_file_is_empty() { int e; e = file_is_empty(""); assert(e == -1); e = file_is_empty("/dev/null"); assert(e == 1); e = file_is_empty("/tmp"); assert(e == 0); e = file_is_empty(NULL); assert(e == -1); return 0; }
void CRASHREPORTER_send_assert_message(Crash_Type crash_type, const char *fmt,...){ static bool is_currently_sending = false; #if 0 static int last_time = -10000; if ( last_time < (running_time.elapsed()-(30*1000))) return; last_time = running_time.elapsed(); #endif if (is_currently_sending) return; char message[1000]; va_list argp; va_start(argp,fmt); /* vfprintf(stderr,fmt,argp); */ vsprintf(message,fmt,argp); va_end(argp); if (g_crashreporter_file!=NULL) { if (!g_crashreporter_file->open()){ SYSTEM_show_message("Unable to create temprary file. Disk may be full"); send_crash_message_to_server(message, get_plugin_names(), NOEMERGENCYSAVE, crash_type); goto exit; } if (false==file_is_empty(g_crashreporter_file)) { g_crashreporter_file->close(); goto exit; } g_crashreporter_file->close(); } is_currently_sending = true; RT_request_to_stop_playing(); RT_pause_plugins(); CRASHREPORTER_send_message_with_backtrace(message, crash_type); #if 0 if (may_do_blocking && THREADING_is_main_thread()) send_crash_message_to_server(message, g_plugin_name, false); else{ const char *messages[1] = {message}; CRASHREPORTER_send_message(messages, 1, false); } #endif exit: is_currently_sending = false; }
/* For the case that we have given a filename on the commandline that doesn't exist, we'll create it, if we exit without saving anything in it, or abort the creation of an index file for it, then we bluntly remove the file we didn't care to use, during the exit. */ void remove_unwanted_file( void ) { char * dbfileinUse = getFullDbName() ; if (file_is_empty(dbfileinUse) ) { if (justCreated() && (!labelFileIsJustCreated())) { unlink(dbfileinUse) ; /* TODO: this is too easy really has to probe the operation. */ } } dbfileinUse = NULL ; }
/* Removes any empty lines to avoid "invisible labels", the users comfort, Returns 1 if the file still has contents,after "linting". We don't remove any white space if the line has other contents before or after text. It is called from: */ int labelFileOkAfterLinting(char *labelfn) { const char procname[]="labelFileOkAfterLinting" ; char buf[BUFSIZ]; /* 1024 characters per line on Mac Os X */ FILE *fin=NULL, *fout=NULL; char *lblBckFname = makeBackupName(labelfn ) ; int ret = rename(labelfn, lblBckFname); if (ret) { yerror(YFILE_RENMV_ERR,procname,lblBckFname,YX_EXTERNAL_CAUSE ) ; } /* open the backup file for reading */ if ((fin = fopen(lblBckFname, "r")) == NULL ) { yerror(YFILE_OREAD_ERR,procname,lblBckFname,YX_EXTERNAL_CAUSE ) ; } /* reopen the label file for writing */ if ((fout = fopen(labelfn, "w")) == NULL ) { yerror(YFILE_CREAT_ERR,procname,labelfn,YX_EXTERNAL_CAUSE ) ; } while (!feof(fin) ) { /* read it line by line */ if (fgets(buf, (int)BUFSIZ , fin )== NULL ) { if (ferror(fin)) { yerror(YFILE_FREAD_ERR,procname,lblBckFname,YX_EXTERNAL_CAUSE ) ; } break ; } /* check if the line contains anything but whitespace */ if (!onlyspaces(buf)) { if ( fputs(buf,fout) == EOF ) { /* compatibility */ yerror(YFILE_FWRITE_ERR,procname,labelfn,YX_EXTERNAL_CAUSE ) ; } } } fclose(fin) ; fclose(fout ) ; if ( file_is_empty(labelfn ) ) { return 0 ; } else { return 1 ; } }
/* * Trenger begrenset lengde på feltnavn: 100 tegn * 6 for multibyte. * Dette skal la oss ende på 100 widechar tegn. * * Så vidt jeg har skjønt er sammenhengene slik: * * http://www.unicode.org/faq/utf_bom.html * utf8: 1-4 bytes * utf16: 2-4 bytes ( to 16 bit verdier) * utf32 4 bytes ( 1 32 bit verdi) widechar. ncurses jobber bra med widechars på 32 bit. * * Dette betyr at: jeg trenger 400 bytes satt av for å lagre hva som helst på 100 tegn. * New business rules, in the advent of ability of creation of db files from the commandline. This is the entry point for that functionality. if the databasefile, is merely specified, AND the file doesn't yet exist, AND we don't find any label file. (open_label_file() returns NULL ), THEN we create a new label file for the non-existant db file. Of course, should we be so happy to find one along the path then we'll use this one? * */ void read_labelfile(void) { const char procname[]="read_labelfile" ; FILE *fp; register int len; char buf[BUFSIZ]; /* 1024 characters per line on Mac Os X */ /* we have gotten the name when we come here */ fp = open_label_file() ; if ((fp == NULL ) && (!hasPattern()) && (shouldCreateMissingLabelFile()|| dbFileHasNoPath())) { newLabelFilePath() ; create_db() ; char *labelfn = getFullLabelFileName() ; if ( file_is_empty(labelfn) || (!labelFileOkAfterLinting(labelfn))) { ysimpleError("Index: User redecided creating a new database and thereby quitted.",YX_ALL_WELL) ; } /* we remove any trailing line-endings here */ setLabelFileCreated() ; fp = fopen(labelfn,"r") ; /* if (dbFileHasNoPath() ) { } */ } else if (fp == NULL ) { char *labelfn = getFullLabelFileName() ; yerror(YFILE_FINDF_ERR,procname,labelfn,YX_EXTERNAL_CAUSE ) ; } /* Zero out structure. */ memset(&idx,(int)0, sizeof(idxfile) ) ; /* Read lines from file. */ while (idx.idx_nlines < MAXDBLINES) { /* End of file. */ if (fgets(buf, (int)BUFSIZ , fp) == NULL) break; /* Strip newline. replace with a colon */ len = strlen(buf) - 1; if (!len) { buf[len] = '\0'; } else { /* check for a colon! */ if (buf[(len - 1)] == ':') { buf[len] = '\0'; } else { /* no colon, so we insert one! */ buf[len] = ':'; } } /* If first char is '!', then this line should not */ /* participate in searches. Save stuff after the '!'. */ /* Otherwise this line does participate in searches, */ /* save the whole line. */ if (*buf == '!') { idx.idx_lines[idx.idx_nlines] = mbstowcs_alloc(&buf[1]); idx.idx_search[idx.idx_nlines] = 0; len--; } else { idx.idx_lines[idx.idx_nlines] = mbstowcs_alloc(buf); idx.idx_search[idx.idx_nlines] = 1; } /* Increment number of lines. */ idx.idx_nlines++; /* Save the length of the longest field name. */ if (len > idx.idx_maxlen) idx.idx_maxlen = len; } /* Close file. */ fclose(fp); }