If file = .cpp then print?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If file = .cpp then print?
# 1  
Old 10-07-2008
If file = .cpp then print?

I'm trying to develop a script that makes it so only .cpp programs can print. I'm doing it for my computer programming class because everyone keeps printing the executable instead of the source code and it's wasting a lot of paper. How can I accomplish this? Thanks for the help. Smilie
# 2  
Old 10-07-2008
Only hunch I got is that CUPS can do filtering. Maybe research docs like Dissecting The CUPS Filtering System (ch 4, "The CUPS-internal filtering system": the MIME part could be a clue) or SDB:Using Your Own Filters to Print with CUPS - openSUSE.
# 3  
Old 10-07-2008
Let me restate what I'd like to do. I want something like this:
Code:
if
file = .cpp
lp
else
print 'please only print the source file!'

What is the Unix shell translation? Thanks for the help thus far! It was my fault for not specifying.
# 4  
Old 10-14-2008
So...Is there any way someone could please help me? Smilie
# 5  
Old 10-14-2008
Are they calling it as "lp <file>"? If so, and if you have Bash 3.0+, just place this earlier in the path than the real lp (or alias it, or... etc.):

Code:
#!/bin/bash

if [[ x"$1" =~ '.*\.cpp$' ]]; then
    /usr/bin/lp $1
else
    echo "Can't print $1, as it does not appear to be a source file."
fi

# 6  
Old 10-14-2008
Amazing! Thanks! I'll try it!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error in compiling .cpp file

I get this error, defaults.cpp: In member function ‘int Defaults::GetIntDefault(const std::string&)’: defaults.cpp:68: error: ‘atoi’ was not declared in this scope defaults.cpp: In member function ‘real_t Defaults::GetRealDefault(const std::string&)’: defaults.cpp:76: error: ‘atof’ was not... (1 Reply)
Discussion started by: bstephens
1 Replies

2. Shell Programming and Scripting

Calling a function in cpp file inside shell script

Hi I need to call a function written in a cpp file with arguments inside the shell script..Can anyone help me how to do this:( (1 Reply)
Discussion started by: rkrish
1 Replies

3. Programming

.h or .cpp

I have the code below and cannot decide if to put it in a .h file or in a .cpp file #ifndef VERBOSE_H #define VERBOSE_H #include "sstring.h" enum Verbose { none = 0, low = 1, medium = 2, high = 3, diag = 4 }; bool GetVerbose(String& S, Verbose& V) { S.ToUpper(); if (S ==... (3 Replies)
Discussion started by: kristinu
3 Replies

4. Programming

dbx: couldn't read "file.cpp"

Anyone know why I might be getting these messages when I'm debugging in dbx? When it stops, I'll get messages like: stopped in get_smtp_line() at line 248 in file "" ($t1) couldn't read "mail_un.cpp" And then I can't list the contents of the file. (2 Replies)
Discussion started by: ctote
2 Replies

5. Emergency UNIX and Linux Support

Functions defined in header / cpp file behaves different

File: A.h class A { public: struct x X; int show() { x.member_variable ? 0: -1; } }; Now if A.cpp is complied which includes A.h (which is actually in a huge project space) we see that x.member_variable value is not as expected. But if remove the show() method and place... (4 Replies)
Discussion started by: uunniixx
4 Replies

6. Shell Programming and Scripting

want to find out a function name in a cpp file

I have an error in my logs as it shows some function name . 1. I dnt know where is the file.cpp located only i know the machine . 2. How to find out that the function name is loacated in which path and which file into that machine. Thanks . (1 Reply)
Discussion started by: madfox
1 Replies

7. Shell Programming and Scripting

CPP to PERL

Hi all, can we convert a cpp program to perl scripting ? (4 Replies)
Discussion started by: Shell_Learner
4 Replies

8. Shell Programming and Scripting

reading a cpp file

I need to find all the methods in a cpp file ... using shell script Pls guide me regarding the grep criteria for searching methods I mean what are the patterns to be grepped in *.cpp which match methods Hope i have made myself clear Thanks and Regards -- Ultimatix (2 Replies)
Discussion started by: ultimatix
2 Replies

9. AIX

[AIX] usages of lint for .cpp file?

Hi , I Want to apply AIX lint to my source code which all are *.cpp/*.h >lint test.cpp lint: 1286-332 File test.cpp must have a .c, .C or .ln extension. It is ignored. lint: 1286-334 There are no files to process. I am getting above error. -Ashok (3 Replies)
Discussion started by: ashokd001
3 Replies

10. Programming

cpp in unix

sir i am trying to compile and execute cpp file in unix the command cpp <filename > is not working do you suggest any other command? thanking you (5 Replies)
Discussion started by: sandhyapidugu
5 Replies
Login or Register to Ask a Question