summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2003-09-17 19:00:01 +0000
committerStef Walter <stef@thewalter.net>2003-09-17 19:00:01 +0000
commit5f8963f606902518a0544bdb1639bdec9a0e4cdb (patch)
tree45f09928b953b7d7d58f900c528a3fee6d87d7a2
Initial ImportHEADmaster
-rw-r--r--.cvsignore5
-rw-r--r--Flip.dsp108
-rw-r--r--Flip.dsw29
-rw-r--r--Flip.rc72
-rw-r--r--flip.cpp328
-rw-r--r--icon1.icobin0 -> 766 bytes
-rw-r--r--resource.h16
7 files changed, 558 insertions, 0 deletions
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..8d16cea
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1,5 @@
+*.aps
+*.ncb
+*.opt
+*.plg
+Release \ No newline at end of file
diff --git a/Flip.dsp b/Flip.dsp
new file mode 100644
index 0000000..8a1dd54
--- /dev/null
+++ b/Flip.dsp
@@ -0,0 +1,108 @@
+# Microsoft Developer Studio Project File - Name="Flip" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=Flip - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "Flip.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "Flip.mak" CFG="Flip - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "Flip - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "Flip - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "Flip - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "Flip - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "Flip - Win32 Release"
+# Name "Flip - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\flip.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\flip.rc
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# Begin Source File
+
+SOURCE=.\icon1.ico
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/Flip.dsw b/Flip.dsw
new file mode 100644
index 0000000..49c3e9c
--- /dev/null
+++ b/Flip.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "Flip"=.\Flip.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/Flip.rc b/Flip.rc
new file mode 100644
index 0000000..54fb36a
--- /dev/null
+++ b/Flip.rc
@@ -0,0 +1,72 @@
+//Microsoft Developer Studio generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE DISCARDABLE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_MAIN ICON DISCARDABLE "icon1.ico"
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/flip.cpp b/flip.cpp
new file mode 100644
index 0000000..cfe8fe7
--- /dev/null
+++ b/flip.cpp
@@ -0,0 +1,328 @@
+//
+// Programmer: Stef
+// Last Modified: Tue Aug 31 22:34:27 GMT+0700 1999
+// $Smake: cc -ansi -m486 -O -o %b %f -lg++ && strip %b
+// $Smake-linux: g++ -ansi -m486 -O3 -o %b %f && strip %b
+//
+//
+// Original idea from Craig Stuart Sapp <craig@ccrma.stanford.edu>
+// Modified by Stef to support input of filenames from STDIN
+// And to ignore Binary Files
+//
+// Description: Utility program to convert text files between
+// UNIX newlines and DOS linefeed + newlines
+//
+// Unix uses the character 0x0a to start a new line
+// while DOS uses two characters: 0x0d 0x0a
+//
+// Options are:
+// -u make the file Unix/MAC conformant
+// -d make the file DOS conformant
+// -f force it to process binary files
+// -l read a list of files from STDIN
+//
+// Multiple files can be processed at once on the command line
+//
+
+#include <iostream.h>
+#include <fstream.h>
+#include <strstrea.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+// Added By Stef
+#define MAX_PATH 256
+
+void exit_usage(const char* command);
+int translate_to_unix(istream& in, ostream& out);
+int translate_to_dos(istream& in, ostream& out);
+void process_file(const char* filename);
+
+// Globals
+char g_cMode; // Current Mode
+bool g_bForce; // Force Binary Mode
+bool g_nRet; // ErrorLevel Return value
+
+
+int main(int argc, char* argv[])
+{
+ // Sanity Syntax Check
+ if (argc < 2)
+ exit_usage(argv[0]);
+ if (argv[1][0] != '-' && argv[1][0] != '/')
+ exit_usage(argv[0]);
+
+ // Set Defaults
+ g_cMode = '\0';
+ g_bForce = false;
+ g_nRet = 0;
+ bool bStdIn = true; // Should we read from STDIN
+ bool bFiles = false; // Read Files (not data) from STDIN
+
+ // Process Arguments
+ for(int nCnt = 1; nCnt < argc; nCnt++)
+ {
+ // Is it a parameter?
+ if(argv[nCnt][0] == '-' || argv[nCnt][0] == '/')
+ {
+ switch(argv[nCnt][1])
+ {
+ case 'u':
+ case 'd':
+ g_cMode = argv[nCnt][1];
+ break;
+ case 'l':
+ bFiles = true;
+ break;
+ case 'f':
+ g_bForce = true;
+ break;
+ default:
+ break;
+ }
+
+ continue;
+ }
+
+ // If no mode set yet then syntax prob
+ if(g_cMode == '\0')
+ exit_usage(argv[0]);
+
+ // Don't read from StdIn
+ bStdIn = false;
+ process_file(argv[nCnt]);
+ }
+
+ if(bStdIn)
+ {
+ // Read file list from stin
+ if(bFiles)
+ {
+ char szBuff[MAX_PATH];
+ while(!cin.eof())
+ {
+ // Get a line
+ cin.get(szBuff, MAX_PATH, '\n');
+ cin.get();
+
+ // Process it if there's something
+ if(strlen(szBuff))
+ process_file(szBuff);
+ }
+ }
+ else
+ // Just process the stdin raw
+ process_file(NULL);
+ }
+
+ return g_nRet;
+}
+
+////////////////////////////////
+//
+// process_file
+
+void process_file(const char* filename)
+{
+ char fileTemp[MAX_PATH]; // Backup Filename
+ int nRet = 0; // Return Value
+
+ // If filename is NULL means stdin -> stdout (below)
+ if(filename)
+ {
+ // Construct Backup File Name
+ strcpy(fileTemp, filename);
+ strcat(fileTemp, "._x");
+ strcat(fileTemp, &g_cMode);
+
+ // If it exists dump it
+ remove(fileTemp);
+
+ // Rename original to backup
+ if(rename(filename, fileTemp))
+ {
+ cerr << "Error: ";
+ perror(filename);
+ g_nRet++; return;
+ }
+
+ // Open original file
+ fstream infile(fileTemp, ios::in | ios::binary | ios::nocreate);
+ if (!infile) {
+ cerr << "Error: cannot find file " << fileTemp << endl;
+ g_nRet++; return;
+ }
+
+ // Open output file
+ fstream outfile(filename, ios::out | ios::binary);
+ if (!outfile) {
+ cerr << "Error: cannot write to file: " << filename << endl;
+ g_nRet++; return;
+ }
+
+ // Translate File
+ if (g_cMode == 'd')
+ nRet = translate_to_dos(infile, outfile);
+ else if (g_cMode == 'u')
+ nRet = translate_to_unix(infile, outfile);
+
+ // Clean Up
+ infile.close();
+ outfile.close();
+
+ // If errors then move everything back
+ if(nRet)
+ {
+ remove(filename);
+ rename(fileTemp, filename);
+ }
+ }
+ // stdin -> stdout
+ else
+ {
+
+ if (g_cMode == 'd')
+ nRet = translate_to_dos(cin, cout);
+ else if (g_cMode == 'u')
+ nRet = translate_to_unix(cin, cout);
+
+ }
+
+ // Put file name at end of conversion error message
+ if(nRet)
+ {
+ g_nRet++;
+ cerr << filename << endl;
+ }
+}
+
+
+//////////////////////////////
+//
+// translate_to_dos
+//
+
+int translate_to_dos(istream& in, ostream& out)
+{
+ char szBuff[1024]; // Read at most 1K at a time
+ int nLen = 0; // Length of current line
+
+ while (!in.eof())
+ {
+ in.getline(szBuff, 1024);
+
+ nLen = strlen(szBuff);
+
+ // Check for Binary characters for now that's ASCII 0 - 31
+ // excluding \n \r \t
+ if(!g_bForce)
+ {
+ char* psz = szBuff;
+ for(; psz < szBuff + nLen; psz++)
+ {
+ if(psz[0] < 0x20 && psz[0] > -1 &&
+ psz[0] != '\n' && psz[0] != '\t' && psz[0] != '\r')
+ {
+ cerr << "Error: File is Binary: "; // process_file puts filename
+ return 1;
+ }
+ }
+ }
+
+ // Remove Line ending
+ if(szBuff[nLen - 1] == 0x0a)
+ nLen--;
+ if(szBuff[nLen - 1] == 0x0d)
+ nLen--;
+
+ out.write(szBuff, nLen);
+
+ if (in.eof())
+ break;
+
+ // Add DOS ending
+ out.put((char)0x0d);
+ out.put((char)0x0a);
+ }
+
+ return 0;
+}
+
+
+
+//////////////////////////////
+//
+// translate_to_unix
+//
+
+int translate_to_unix(istream& in, ostream& out)
+{
+ char szBuff[1024]; // Read at most 1K at a time
+ int nLen = 0; // Length of current line
+
+ while (!in.eof())
+ {
+ in.getline(szBuff, 1024);
+
+ nLen = strlen(szBuff);
+
+ // Check for Binary characters for now that's ASCII 0 - 31
+ // excluding \n \r \t
+ if(!g_bForce)
+ {
+ char* psz = szBuff;
+ for(; psz < szBuff + nLen; psz++)
+ {
+ if(psz[0] < 0x20 && psz[0] > -1 &&
+ psz[0] != '\n' && psz[0] != '\t' && psz[0] != '\r')
+ {
+ cerr << "Error: File is Binary: "; // process_file puts filename
+ return 1;
+ }
+ }
+ }
+
+ // Remove ending
+ if(szBuff[nLen - 1] == 0x0a)
+ nLen--;
+ if(szBuff[nLen - 1] == 0x0d)
+ nLen--;
+
+ out.write(szBuff, nLen);
+
+ if (in.eof())
+ break;
+
+ // Add Unix Ending
+ out.put((char)0x0a);
+
+ }
+
+ return 0;
+}
+
+//////////////////////////////
+//
+// exit_usage
+//
+
+void exit_usage(const char* commandName)
+{
+ cout << endl;
+ cout << "Usage: " << commandName << " option filename[s]" << endl;
+ cout << " Converts ascii files to either unix or dos format" << endl;
+ cout << " If no file parameters reads from stdin" << endl;
+ cout << endl;
+ cout << " Options: " << endl;
+ cout << " -u = convert to unix format (newline)" << endl;
+ cout << " -d = convert to dos format (linefeed + newline)" << endl;
+ cout << " -f = force conversion even if binary found" << endl;
+ cout << " -l = read a list of filenames from stdin" << endl;
+ cout << endl;
+ cout << endl;
+
+ exit(1);
+}
+
+
diff --git a/icon1.ico b/icon1.ico
new file mode 100644
index 0000000..d2963e0
--- /dev/null
+++ b/icon1.ico
Binary files differ
diff --git a/resource.h b/resource.h
new file mode 100644
index 0000000..4a5f1ea
--- /dev/null
+++ b/resource.h
@@ -0,0 +1,16 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Developer Studio generated include file.
+// Used by Flip.rc
+//
+#define IDI_MAIN 101
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 102
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1000
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif